Module: SFML::Touch
- Defined in:
- lib/sfml/window/touch.rb
Overview
Polling API for touchscreen input. Each finger is identified by an
integer (0 = first contact, 1 = second, etc.). The same fingers
also surface through the event loop as :touch_began,
:touch_moved, :touch_ended events with finger: and
position: fields.
if SFML::Touch.down?(0)
pos = SFML::Touch.position(0, relative_to: window)
...
end
On desktop platforms without touchscreen hardware these always
return false / [0, 0].
Class Method Summary collapse
-
.down?(finger = 0) ⇒ Boolean
True while finger
nis currently in contact with the screen. -
.position(finger = 0, relative_to: nil) ⇒ Object
Position of finger
n.
Class Method Details
.down?(finger = 0) ⇒ Boolean
True while finger n is currently in contact with the screen.
19 20 21 |
# File 'lib/sfml/window/touch.rb', line 19 def down?(finger = 0) C::Window.sfTouch_isDown(Integer(finger)) end |
.position(finger = 0, relative_to: nil) ⇒ Object
Position of finger n. Without relative_to:, returns
desktop-relative coordinates; pass a Window or RenderWindow to
get window-local coordinates.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sfml/window/touch.rb', line 26 def position(finger = 0, relative_to: nil) f = Integer(finger) vec = case relative_to when nil then C::Window.sfTouch_getPosition(f, nil) when RenderWindow then C::Graphics.sfTouch_getPositionRenderWindow(f, relative_to.handle) when Window then C::Window.sfTouch_getPosition(f, relative_to.handle) else raise ArgumentError, "relative_to: must be SFML::Window, SFML::RenderWindow, or nil" end Vector2.new(vec[:x], vec[:y]) end |