#================================================= ==============================
# * Mouse Input Module by Dervvulfman
# * Mouse.mouse_in_area? added by Crazyninjaguy
#================================================= ==============================
# Left-Clicking Control---
# 0 = single click action
# 1 = double-click action
MOUSE_LEFT_ACTION = 0
# Right-Clicking Control--
# 0 = Menu / 'B' pressed
# 1 = Stop Movement
MOUSE_RIGHT_ACTION = 0
module Mouse
@cursor_pos_get = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
@cursor_pos_set = Win32API.new('user32', 'SetCursorPos', 'ii', 'i')
@cursor_show = Win32API.new('user32', 'ShowCursor', 'L', 'i')
@window_find = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
@window_c_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
@window_scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
@readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
@key = Win32API.new("user32", "GetAsyncKeyState", 'i', 'i')
Left_Click = 1
Right_Click = 2
Middle_Click = 4
MOUSE_BUTTONS = { Left_Click => 1,
Right_Click => 2,
Middle_Click => 4 }
MOUSE_REPEAT = MOUSE_BUTTONS.clone
MOUSE_REPEAT.keys.each { |k| MOUSE_REPEAT[k] = [false, false, 10]}
@game_window = nil # Set game handle to nil
@cursor_show.call(0) # Turn off system mouse
def Mouse.click?(button)
MOUSE_REPEAT[button][1] >= 1
end
def Mouse.dbclick?(button)
MOUSE_REPEAT[button][1] == 2
end
def Mouse.pos(catch_anywhere = true)
x, y = screen_to_client(screen_x, screen_y)
width, height = client_size
if catch_anywhere or (x >= 0 and y >= 0 and x < width and y < height)
return x, y
else
return 0, 0
end
end
def Mouse.pos_set(x, y)
x = [[x, 0].max, 640].min
y = [[y, 0].max, 480].min
x, y = client_to_screen(x, y)
@cursor_pos_set.call(x, y)
end
def Mouse.pos_x
x, y = pos
return x
end
def Mouse.pos_y
x, y = pos
return y
end
def Mouse.screen
pos = [0, 0].pack('ll')
@cursor_pos_get.call(pos)
return pos.unpack('ll')
end
def Mouse.screen_x
pos = [0, 0].pack('ll')
@cursor_pos_get.call(pos)
return pos.unpack('ll')[0]
end
def Mouse.screen_y
pos = [0, 0].pack('ll')
@cursor_pos_get.call(pos)
return pos.unpack('ll')[1]
end
def Mouse.client_size
rect = [0, 0, 0, 0].pack('l4')
@window_c_rect.call(Mouse.hwnd, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end
def Mouse.hwnd
if @game_window.nil?
game_name = "\0" * 256
@readini.call('Game','Title','',game_name,255,".\\ Game.ini")
game_name.delete!("\0")
@game_window = @window_find.call('RGSS Player',game_name)
end
return @game_window
end
def Mouse.screen_to_client(x, y)
return nil unless x and y
pos = [x, y].pack('ll')
if @window_scr2cli.call(hwnd, pos) != 0
return pos.unpack('ll')
else
return nil
end
end
def Mouse.update
MOUSE_BUTTONS.keys.each do |key|
temp = MOUSE_REPEAT[key][0]
key_pres = @key.call(MOUSE_BUTTONS[key]) != 0
key_trig = temp == key_pres ? 0 : (key_pres ? (MOUSE_REPEAT[key][2].between?(1, 9) ? 2 : 1) : -1)
count = key_trig > 0 ? 0 : [MOUSE_REPEAT[key][2]+1, 20].min
MOUSE_REPEAT[key] = [key_pres, key_trig, count]
end
end
def Mouse.visible?(visible=true)
if visible
@cursor_show.call(-1)
else
@cursor_show.call(0)
end
end
def Mouse.mouse_in_area?(*args)
return false if Mouse.pos_x.nil?
if args[0].is_a?(Rect)
Mouse.pos_x >= args[0].x and
Mouse.pos_y >= args[0].y and
Mouse.pos_x <= args[0].x + args[0].width and
Mouse.pos_y <= args[0].y + args[0].height
else
Mouse.pos_x >= args[0] and
Mouse.pos_y >= args[1] and
Mouse.pos_x <= args[0] + args[2] and
Mouse.pos_y <= args[1] + args[3]
end
end
end
$mouse=IconSprite.new
$mouse.setBitmap("Graphics/Icons/Arrow")
$mouse.z = 999999999