module SFML::Mouse
Global mouse state โ peer to SFML::Keyboard. Use it for โis this button held right now?โ and for current pointer coordinates outside of the event loop.
SFML::Mouse.button_pressed?(:left) #=> true while LMB is held SFML::Mouse.position #=> Vector2 โ desktop coords SFML::Mouse.position(window) #=> Vector2 โ relative to window SFML::Mouse.set_position([400, 300], window)
Buttons are addressed by symbol; the raw sfMouseButton enum order is exposed via BUTTONS for users who need it.
Constants
- ALIASES
-
Friendly aliases โ
SFML2 used โX-buttonโ terminology; some users still reach for it. - BUTTONS
-
Recognised button symbols.
- BUTTON_INDEX
-
Symbol โ integer index for each button.
Public Instance Methods
Source
# File lib/sfml/window/mouse.rb, line 64 def _code(button) sym = ALIASES.fetch(button, button) BUTTON_INDEX.fetch(sym) do raise ArgumentError, "Unknown mouse button: #{button.inspect}. " \ "Expected one of: #{BUTTONS.inspect}" end end
@!visibility private
Source
# File lib/sfml/window/mouse.rb, line 38 def position(window = nil) vec = if window C::Graphics.sfMouse_getPositionRenderWindow(window.handle) else C::Window.sfMouse_getPosition(nil) end Vector2.new(vec[:x], vec[:y]) end
Pointer position. With no argument, returns desktop-relative coordinates. With a RenderWindow, returns coordinates relative to that windowโs client area (top-left = 0, 0).
Source
# File lib/sfml/window/mouse.rb, line 50 def set_position(point, window = nil) px, py = point.is_a?(Vector2) ? [point.x, point.y] : point vec = C::System::Vector2i.new vec[:x] = Integer(px) vec[:y] = Integer(py) if window C::Graphics.sfMouse_setPositionRenderWindow(vec, window.handle) else C::Window.sfMouse_setPosition(vec, nil) end end
Move the OS pointer. Without window, the coordinates are desktop- relative. Useful for FPS-style mouse-look (warp the cursor back to screen centre each frame).