Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=============================================================================
- # *** AWorks Input Module: Mouse Plugin(AIM:M)
- #=============================================================================
- # Created by AWorks
- # Version: 1.00
- # Last Modification: 26/01/2009 (day/month/year)
- # Compatible with RMXP & RMVX
- #=============================================================================
- #==== Description ====
- # This script adds mouse input detecting proccess to the Input module.
- #=============================================================================
- #==== Requeriments ====
- # * ALibrary (AWorks Library)
- # - Version: 1.03
- # * AIM (AWorks Input Module)
- # - Version: 3.00
- #=============================================================================
- #==== Version History ====
- # * Version 1.00
- # - Creation of the script
- #=============================================================================
- #==== Features ====
- # * Configuration
- # - @mouse_double_click_time
- # Sets up the max amount of frames that may occur between the first and
- # second click of a double-click. If nil, it will be used computer default.
- # - @mouse_double_click_pix
- # Sets up the max area in pixels that may have the cursor coordinates
- # between the first click and the second click of a double-click. By default
- # is 4.
- # - @mouse_drag_pix
- # Sets up the amount of pixels the cursor has to move between the dragging
- # proccess starts. Its default is 4.
- #
- # * Input.mouse_doubleclick?([vk])
- # - Determines whether the key vk is being double clicked. Only works with
- # mouse keys. If vk is not given, it will be the mouse primary button.
- #
- # * Input.mouse_in_screen?
- # - Returns TRUE if the mouse cursor is on the game screen.
- #
- # * Input.mouse_pos
- # - Returns both X and Y cursor coordinates in an Array. If the cursor is not
- # over the game screen, their values are nil.
- #
- # * Input.mouse_x?
- # - Returns the X cursor coordinate of the game screen. If the cursor is not
- # over the game screen, it returns nil.
- #
- # * Input.mouse_y?
- # - Returns the Y cursor coordinate of the game screen. If the cursor is not
- # over the game screen, it returns nil.
- #
- # * Input.mouse_dragging?
- # - Returns TRUE if the player is dragging.
- #
- # * Input.mouse_drag_rect?
- # - Returns the drag rectangle area in a Rect object.
- #
- # * Input.mouse_drag_coor?
- # - Returns the drag rectangle area in an Array.
- #
- # * Input.mouse_in_area?(x, y, width, height)
- # - Returns true if the cursor is over the given area.
- #
- # * Input.mouse_in_area?(rect)
- # - Returns true if the cursor is over the given rect area.
- #
- # * Input.mouse_visible=(flag)
- # - Shows or hides the cursor.
- #
- # * Input.mouse_visible?
- # - Returns TRUE if the cursor is visible.
- #=============================================================================
- #==== Notes ====
- # * There is some difference between the mouse left and right button and the
- # mouse primary and second button. The first ones refers always to the
- # physical left and right keys of a mouse, but the second ones may vary
- # depending on the user's settings. If the Swap Buttons Flag is activated
- # the primary and secondary buttons are swapped, but the left and right
- # buttons stay the same. This script detects this Swap Buttons Flag, and
- # assigns the real values to the MOUSE_PRIMARY and MOUSE_SECONDARY constants,
- # which belongs to the Input module. So, insteand of using Keys::MOUSE_LEFT
- # and Keys::MOUSE_RIGHT, use Input::MOUSE_PRIMARY and Input::MOUSE_SECONDARY
- # respectively.
- #=============================================================================
- #=============================================================================
- # ** Module Input
- #=============================================================================
- module Input
- #---------------------------------------------------------------------------
- # * Configuration
- #---------------------------------------------------------------------------
- @mouse_double_click_time = nil
- @mouse_double_click_pix = 4
- @mouse_drag_pix = 4
- #---------------------------------------------------------------------------
- # * Variables declaration
- #---------------------------------------------------------------------------
- MOUSE_SWAP_BUTTONS = AWorks.get_mouse_swap_buttons_flag
- MOUSE_PRIMARY = 1 + MOUSE_SWAP_BUTTONS
- MOUSE_SECONDARY = 2 - MOUSE_SWAP_BUTTONS
- @mouse_pos = [0, 0]
- @mouse_drag = [false, 0, 0, 0, 0, 0, 0]
- @mouse_doubleclick = [nil, false, false, false, false, false]
- if @mouse_double_click_time.nil?
- @mouse_double_click_time = Graphics.frame_rate *
- (AWorks::API::GetDoubleClickTime.call / 10) / 100
- end
- #---------------------------------------------------------------------------
- # * Initialize Mouse Input
- #---------------------------------------------------------------------------
- AWorks::API::InputMouseIni.call(@mouse_pos.object_id, @mouse_drag.object_id,
- @mouse_doubleclick.object_id)
- AWorks::API::InputMouseConfig.call(MOUSE_SWAP_BUTTONS, @mouse_drag_pix,
- @mouse_double_click_time, @mouse_double_click_pix)
- #---------------------------------------------------------------------------
- # * Updates mouse configuration
- #---------------------------------------------------------------------------
- def Input.update_mouse_configuration
- @mouse_double_click_time = Graphics.frame_rate *
- (AWorks::API::GetDoubleClickTime.call / 10) / 100
- AWorks::API::InputMouseConfig.call(MOUSE_SWAP_BUTTONS, @mouse_drag_pix,
- @mouse_double_click_time, @mouse_double_click_pix)
- end
- #---------------------------------------------------------------------------
- # * Mouse double click?
- #---------------------------------------------------------------------------
- def Input.mouse_doubleclick?(vk = MOUSE_PRIMARY)
- @mouse_doubleclick[vk]
- end
- #---------------------------------------------------------------------------
- # * Mouse in screen?
- #---------------------------------------------------------------------------
- def Input.mouse_in_screen?
- !@mouse_pos[0].nil?
- end
- #---------------------------------------------------------------------------
- # * Get Mouse Pos
- #---------------------------------------------------------------------------
- def Input.mouse_pos
- @mouse_pos
- end
- #---------------------------------------------------------------------------
- # * Mouse X Coordinate
- #---------------------------------------------------------------------------
- def Input.mouse_x?
- @mouse_pos[0]
- end
- #---------------------------------------------------------------------------
- # * Mouse Y Coordinate
- #---------------------------------------------------------------------------
- def Input.mouse_y?
- @mouse_pos[1]
- end
- #---------------------------------------------------------------------------
- # * Mouse Dragging?
- #---------------------------------------------------------------------------
- def Input.mouse_dragging?
- @mouse_drag[0].nil? ? false : @mouse_drag[0]
- end
- #---------------------------------------------------------------------------
- # * Mouse Drag Rect
- #---------------------------------------------------------------------------
- def Input.mouse_drag_rect?
- Rect.new(*@mouse_drag[3, 4]) if @mouse_drag[0]
- end
- #---------------------------------------------------------------------------
- # * Mouse Drag Coordinates
- #---------------------------------------------------------------------------
- def Input.mouse_drag_coor?
- @mouse_drag[3, 4] if @mouse_drag[0]
- end
- #---------------------------------------------------------------------------
- # * Mouse in Area?
- #---------------------------------------------------------------------------
- def Input.mouse_in_area?(*args)
- return false if @mouse_pos[0].nil?
- if args[0].is_a?(Rect)
- @mouse_pos[0] >= args[0].x and
- @mouse_pos[1] >= args[0].y and
- @mouse_pos[0] <= args[0].x + args[0].width and
- @mouse_pos[1] <= args[0].y + args[0].height
- else
- @mouse_pos[0] >= args[0] and
- @mouse_pos[1] >= args[1] and
- @mouse_pos[0] <= args[0] + args[2] and
- @mouse_pos[1] <= args[1] + args[3]
- end
- end
- #---------------------------------------------------------------------------
- # * Change mouse visibility
- #---------------------------------------------------------------------------
- def Input.mouse_visible=(flag)
- val, result = flag ? 1 : 0, nil
- until result == (val - 1)
- result = AWorks::API::ShowCursor.call(val)
- end
- end
- #---------------------------------------------------------------------------
- # * Mouse visible?
- #---------------------------------------------------------------------------
- def Input.mouse_visible?
- AWorks::API::ShowCursor.call(1)
- AWorks::API::ShowCursor.call(0) >= 0
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment