mcgluszak

[Author: Aleworks] AIM Mouse Plugin v1.00

Sep 1st, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.88 KB | None | 0 0
  1. #=============================================================================
  2. # *** AWorks Input Module: Mouse Plugin(AIM:M)
  3. #=============================================================================
  4. # Created by AWorks
  5. # Version: 1.00
  6. # Last Modification: 26/01/2009 (day/month/year)
  7. # Compatible with RMXP & RMVX
  8. #=============================================================================
  9. #==== Description ====
  10. # This script adds mouse input detecting proccess to the Input module.
  11. #=============================================================================
  12. #==== Requeriments ====
  13. # * ALibrary (AWorks Library)
  14. #   - Version: 1.03
  15. # * AIM (AWorks Input Module)
  16. #   - Version: 3.00
  17. #=============================================================================
  18. #==== Version History ====
  19. # * Version 1.00
  20. #   - Creation of the script
  21. #=============================================================================
  22. #==== Features ====
  23. # * Configuration
  24. #   - @mouse_double_click_time
  25. #     Sets up the max amount of frames that may occur between the first and
  26. #     second click of a double-click. If nil, it will be used computer default.
  27. #   - @mouse_double_click_pix
  28. #     Sets up the max area in pixels that may have the cursor coordinates
  29. #     between the first click and the second click of a double-click. By default
  30. #     is 4.
  31. #   - @mouse_drag_pix
  32. #     Sets up the amount of pixels the cursor has to move between the dragging
  33. #     proccess starts. Its default is 4.
  34. #
  35. # * Input.mouse_doubleclick?([vk])
  36. #   - Determines whether the key vk is being double clicked. Only works with
  37. #     mouse keys. If vk is not given, it will be the mouse primary button.
  38. #
  39. # * Input.mouse_in_screen?
  40. #   - Returns TRUE if the mouse cursor is on the game screen.
  41. #
  42. # * Input.mouse_pos
  43. #   - Returns both X and Y cursor coordinates in an Array. If the cursor is not
  44. #     over the game screen, their values are nil.
  45. #
  46. # * Input.mouse_x?
  47. #   - Returns the X cursor coordinate of the game screen. If the cursor is not
  48. #     over the game screen, it returns nil.
  49. #
  50. # * Input.mouse_y?
  51. #   - Returns the Y cursor coordinate of the game screen. If the cursor is not
  52. #     over the game screen, it returns  nil.
  53. #
  54. # * Input.mouse_dragging?
  55. #   - Returns TRUE if the player is dragging.
  56. #
  57. # * Input.mouse_drag_rect?
  58. #   - Returns the drag rectangle area in a Rect object.
  59. #
  60. # * Input.mouse_drag_coor?
  61. #   - Returns the drag rectangle area in an Array.
  62. #
  63. # * Input.mouse_in_area?(x, y, width, height)
  64. #   - Returns true if the cursor is over the given area.
  65. #
  66. # * Input.mouse_in_area?(rect)
  67. #   - Returns true if the cursor is over the given rect area.
  68. #
  69. # * Input.mouse_visible=(flag)
  70. #   - Shows or hides the cursor.
  71. #
  72. # * Input.mouse_visible?
  73. #   - Returns TRUE if the cursor is visible.
  74. #=============================================================================
  75. #==== Notes ====
  76. # * There is some difference between the mouse left and right button and the
  77. #   mouse primary and second button. The first ones refers always to the
  78. #   physical left and right keys of a mouse, but the second ones may vary
  79. #   depending on the user's settings. If the Swap Buttons Flag is activated
  80. #   the primary and secondary buttons are swapped, but the left and right
  81. #   buttons stay the same. This script detects this Swap Buttons Flag, and
  82. #   assigns the real values to the MOUSE_PRIMARY and MOUSE_SECONDARY constants,
  83. #   which belongs to the Input module. So, insteand of using Keys::MOUSE_LEFT
  84. #   and Keys::MOUSE_RIGHT, use Input::MOUSE_PRIMARY and Input::MOUSE_SECONDARY
  85. #   respectively.
  86. #=============================================================================
  87.  
  88. #=============================================================================
  89. # ** Module Input
  90. #=============================================================================
  91. module Input
  92.   #---------------------------------------------------------------------------
  93.   # * Configuration
  94.   #---------------------------------------------------------------------------
  95.   @mouse_double_click_time = nil
  96.   @mouse_double_click_pix = 4
  97.   @mouse_drag_pix = 4
  98.   #---------------------------------------------------------------------------
  99.   # * Variables declaration
  100.   #---------------------------------------------------------------------------
  101.   MOUSE_SWAP_BUTTONS = AWorks.get_mouse_swap_buttons_flag
  102.   MOUSE_PRIMARY = 1 + MOUSE_SWAP_BUTTONS
  103.   MOUSE_SECONDARY = 2 - MOUSE_SWAP_BUTTONS
  104.   @mouse_pos = [0, 0]
  105.   @mouse_drag = [false, 0, 0, 0, 0, 0, 0]
  106.   @mouse_doubleclick = [nil, false, false, false, false, false]
  107.   if @mouse_double_click_time.nil?
  108.     @mouse_double_click_time = Graphics.frame_rate *
  109.     (AWorks::API::GetDoubleClickTime.call / 10) / 100
  110.   end
  111.   #---------------------------------------------------------------------------
  112.   # * Initialize Mouse Input
  113.   #---------------------------------------------------------------------------
  114.   AWorks::API::InputMouseIni.call(@mouse_pos.object_id, @mouse_drag.object_id,
  115.     @mouse_doubleclick.object_id)
  116.   AWorks::API::InputMouseConfig.call(MOUSE_SWAP_BUTTONS, @mouse_drag_pix,
  117.     @mouse_double_click_time, @mouse_double_click_pix)
  118.   #---------------------------------------------------------------------------
  119.   # * Updates mouse configuration
  120.   #---------------------------------------------------------------------------
  121.   def Input.update_mouse_configuration
  122.     @mouse_double_click_time = Graphics.frame_rate *
  123.       (AWorks::API::GetDoubleClickTime.call / 10) / 100
  124.     AWorks::API::InputMouseConfig.call(MOUSE_SWAP_BUTTONS, @mouse_drag_pix,
  125.     @mouse_double_click_time, @mouse_double_click_pix)
  126.   end
  127.   #---------------------------------------------------------------------------
  128.   # * Mouse double click?
  129.   #---------------------------------------------------------------------------
  130.   def Input.mouse_doubleclick?(vk = MOUSE_PRIMARY)
  131.     @mouse_doubleclick[vk]
  132.   end
  133.   #---------------------------------------------------------------------------
  134.   # * Mouse in screen?
  135.   #---------------------------------------------------------------------------
  136.   def Input.mouse_in_screen?
  137.     !@mouse_pos[0].nil?
  138.   end
  139.   #---------------------------------------------------------------------------
  140.   # * Get Mouse Pos
  141.   #---------------------------------------------------------------------------
  142.   def Input.mouse_pos
  143.     @mouse_pos
  144.   end
  145.   #---------------------------------------------------------------------------
  146.   # * Mouse X Coordinate
  147.   #---------------------------------------------------------------------------
  148.   def Input.mouse_x?
  149.     @mouse_pos[0]
  150.   end
  151.   #---------------------------------------------------------------------------
  152.   # * Mouse Y Coordinate
  153.   #---------------------------------------------------------------------------
  154.   def Input.mouse_y?
  155.     @mouse_pos[1]
  156.   end
  157.   #---------------------------------------------------------------------------
  158.   # * Mouse Dragging?
  159.   #---------------------------------------------------------------------------
  160.   def Input.mouse_dragging?
  161.     @mouse_drag[0].nil? ? false : @mouse_drag[0]
  162.   end
  163.   #---------------------------------------------------------------------------
  164.   # * Mouse Drag Rect
  165.   #---------------------------------------------------------------------------
  166.   def Input.mouse_drag_rect?
  167.     Rect.new(*@mouse_drag[3, 4]) if @mouse_drag[0]
  168.   end
  169.   #---------------------------------------------------------------------------
  170.   # * Mouse Drag Coordinates
  171.   #---------------------------------------------------------------------------
  172.   def Input.mouse_drag_coor?
  173.     @mouse_drag[3, 4] if @mouse_drag[0]
  174.   end
  175.   #---------------------------------------------------------------------------
  176.   # * Mouse in Area?
  177.   #---------------------------------------------------------------------------
  178.   def Input.mouse_in_area?(*args)
  179.     return false if @mouse_pos[0].nil?
  180.     if args[0].is_a?(Rect)
  181.       @mouse_pos[0] >= args[0].x and
  182.       @mouse_pos[1] >= args[0].y and
  183.       @mouse_pos[0] <= args[0].x + args[0].width and
  184.       @mouse_pos[1] <= args[0].y + args[0].height
  185.     else
  186.       @mouse_pos[0] >= args[0] and
  187.       @mouse_pos[1] >= args[1] and
  188.       @mouse_pos[0] <= args[0] + args[2] and
  189.       @mouse_pos[1] <= args[1] + args[3]
  190.     end
  191.   end
  192.   #---------------------------------------------------------------------------
  193.   # * Change mouse visibility
  194.   #---------------------------------------------------------------------------
  195.   def Input.mouse_visible=(flag)
  196.     val, result = flag ? 1 : 0, nil
  197.     until result == (val - 1)
  198.       result = AWorks::API::ShowCursor.call(val)
  199.     end
  200.   end
  201.   #---------------------------------------------------------------------------
  202.   # * Mouse visible?
  203.   #---------------------------------------------------------------------------
  204.   def Input.mouse_visible?
  205.     AWorks::API::ShowCursor.call(1)
  206.     AWorks::API::ShowCursor.call(0) >= 0
  207.   end
  208. end
Advertisement
Add Comment
Please, Sign In to add comment