Module: Mouse

Defined in:
scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb

Overview

Module responsive of giving global state of mouse Inputs

The buttons of the mouse are : :LEFT, :MIDDLE, :RIGHT, :X1, :X2

Constant Summary collapse

BUTTON_MAPPING =

Mapping between button & symbols

{
  Sf::Mouse::LEFT => :LEFT,
  Sf::Mouse::RIGHT => :RIGHT,
  Sf::Mouse::Middle => :MIDDLE,
  Sf::Mouse::XButton1 => :X1,
  Sf::Mouse::XButton2 => :X2
}
BUTTON_ALIAS =

List of alias button

{
  left: :LEFT,
  right: :RIGHT,
  middle: :MIDDLE
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.movedBoolean (readonly)

Get if the mouse moved since last frame

Returns:

  • (Boolean)


59
60
61
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 59

def moved
  @moved
end

.wheelInteger

Mouse wheel position

Returns:



47
48
49
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 47

def wheel
  @wheel
end

.wheel_deltaInteger (readonly)

Mouse wheel delta

Returns:



50
51
52
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 50

def wheel_delta
  @wheel_delta
end

.xInteger (readonly)

Get the mouse x position

Returns:



53
54
55
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 53

def x
  @x
end

.yInteger (readonly)

Get the mouse y position

Returns:



56
57
58
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 56

def y
  @y
end

Class Method Details

.in?Boolean

Tell if the mouse is in the screen

Returns:

  • (Boolean)


87
88
89
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 87

def in?
  return @in_screen
end

.press?(button) ⇒ Boolean

Tell if a button is pressed on the mouse

Parameters:

  • button (Symbol)

Returns:

  • (Boolean)


64
65
66
67
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 64

def press?(button)
  button = BUTTON_ALIAS[button] || button
  return @current_state[button]
end

.register_events(window)

Register event related to the mouse

Parameters:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 100

def register_events(window)
  return if Configs.devices.is_mouse_disabled

  window.on_touch_began = proc { |finger_id, x, y|
    on_mouse_entered
    on_mouse_moved(x, y)
    on_button_pressed(Sf::Mouse::LEFT)
  }
  window.on_touch_moved = proc { |finger, x, y| on_mouse_moved(x, y) }
  window.on_touch_ended = proc { |finger_id, x, y|
    on_button_released(Sf::Mouse::LEFT)
    on_mouse_moved(x, y)
    on_mouse_left
  }
  window.on_mouse_wheel_scrolled = proc { |wheel, delta| on_wheel_scrolled(wheel, delta) }
  window.on_mouse_button_pressed = proc { |button| on_button_pressed(button) }
  window.on_mouse_button_released = proc { |button| on_button_released(button) }
  window.on_mouse_moved = proc { |x, y| on_mouse_moved(x, y) }
  window.on_mouse_entered = proc { on_mouse_entered }
  window.on_mouse_left = proc { on_mouse_left }
end

.released?(button) ⇒ Boolean

Tell if a button was released on the mouse

Parameters:

  • button (Symbol)

Returns:

  • (Boolean)


80
81
82
83
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 80

def released?(button)
  button = BUTTON_ALIAS[button] || button
  return @last_state[button] && !@current_state[button]
end

.swap_states

Swap the state of the mouse



92
93
94
95
96
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 92

def swap_states
  @last_state.merge!(@current_state)
  @moved = false
  @wheel_delta = 0
end

.trigger?(button) ⇒ Boolean

Tell if a button was triggered on the mouse

Parameters:

  • button (Symbol)

Returns:

  • (Boolean)


72
73
74
75
# File 'scripts/00000 Dependencies/00001 LiteRGSS2/00001 Mouse.rb', line 72

def trigger?(button)
  button = BUTTON_ALIAS[button] || button
  return @current_state[button] && !@last_state[button]
end