Class: Gosu::Input
- Inherits:
-
Object
- Object
- Gosu::Input
- Defined in:
- lib/gosu_android/input/input.rb
Overview
Manages initialization and shutdown of the input system. Only one Input instance can exist per application.
Instance Method Summary collapse
-
#accelerometerX ⇒ Object
Accelerometer positions in all three dimensions (smoothened).
- #accelerometerY ⇒ Object
- #accelerometerZ ⇒ Object
-
#button_down ⇒ Object
Assignable events that are called by update.
- #button_up ⇒ Object
-
#char_to_id(ch) ⇒ Object
Returns the button that has to be pressed to produce the given character, or noButton.
-
#currentTouches ⇒ Object
Currently known touches.
-
#down(btn) ⇒ Object
Returns true if a button is currently pressed.
- #feed_key_event(keyCode, event) ⇒ Object
- #feed_touch_event(event) ⇒ Object
-
#id_to_char(btn) ⇒ Object
Returns the character a button usually produces, or 0.
-
#initialize(display, window) ⇒ Input
constructor
A new instance of Input.
-
#mouseX ⇒ Object
Returns the horizontal position of the mouse relative to the top left corner of the window given to Input’s constructor.
-
#mouseY ⇒ Object
Returns true if a button is currently pressed.
-
#set_mouse_factors(factorX, factorY) ⇒ Object
Undocumented for the moment.
-
#set_mouse_position(x, y) ⇒ Object
Immediately moves the mouse as far towards the desired position as possible.
-
#set_text_input(input) ⇒ Object
Sets the currently active TextInput, or clears it (input = 0).
-
#text_input ⇒ Object
Returns the currently active TextInput instance, or 0.
-
#update ⇒ Object
Collects new information about which buttons are pressed, where the mouse is and calls onButtonUp/onButtonDown, if assigned.
Constructor Details
#initialize(display, window) ⇒ Input
Returns a new instance of Input.
40 41 42 43 44 45 46 |
# File 'lib/gosu_android/input/input.rb', line 40 def initialize(display, window) @display = display @window = window @touch_event_list = [] @key_event_list = [] @id = 0 end |
Instance Method Details
#accelerometerX ⇒ Object
Accelerometer positions in all three dimensions (smoothened).
87 |
# File 'lib/gosu_android/input/input.rb', line 87 def accelerometerX; end |
#accelerometerY ⇒ Object
88 |
# File 'lib/gosu_android/input/input.rb', line 88 def accelerometerY; end |
#accelerometerZ ⇒ Object
89 |
# File 'lib/gosu_android/input/input.rb', line 89 def accelerometerZ; end |
#button_down ⇒ Object
Assignable events that are called by update. You can bind these to your own functions. If you use the Window class, it will assign forward these to its own methods.
112 |
# File 'lib/gosu_android/input/input.rb', line 112 def ; end |
#button_up ⇒ Object
113 |
# File 'lib/gosu_android/input/input.rb', line 113 def ; end |
#char_to_id(ch) ⇒ Object
Returns the button that has to be pressed to produce the given character, or noButton.
61 |
# File 'lib/gosu_android/input/input.rb', line 61 def char_to_id(ch); end |
#currentTouches ⇒ Object
Currently known touches.
84 |
# File 'lib/gosu_android/input/input.rb', line 84 def currentTouches; end |
#down(btn) ⇒ Object
Returns true if a button is currently pressed. Updated every tick.
65 |
# File 'lib/gosu_android/input/input.rb', line 65 def down(btn); end |
#feed_key_event(keyCode, event) ⇒ Object
52 53 54 |
# File 'lib/gosu_android/input/input.rb', line 52 def feed_key_event(keyCode, event) @key_event_list.push [keyCode, event] end |
#feed_touch_event(event) ⇒ Object
48 49 50 |
# File 'lib/gosu_android/input/input.rb', line 48 def feed_touch_event(event) @touch_event_list.push event end |
#id_to_char(btn) ⇒ Object
Returns the character a button usually produces, or 0.
57 |
# File 'lib/gosu_android/input/input.rb', line 57 def id_to_char(btn); end |
#mouseX ⇒ Object
Returns the horizontal position of the mouse relative to the top left corner of the window given to Input’s constructor.
69 |
# File 'lib/gosu_android/input/input.rb', line 69 def mouseX; end |
#mouseY ⇒ Object
Returns true if a button is currently pressed. Updated every tick.
73 |
# File 'lib/gosu_android/input/input.rb', line 73 def mouseY; end |
#set_mouse_factors(factorX, factorY) ⇒ Object
Undocumented for the moment. Also applies to currentTouches().
81 |
# File 'lib/gosu_android/input/input.rb', line 81 def set_mouse_factors(factorX, factorY); end |
#set_mouse_position(x, y) ⇒ Object
Immediately moves the mouse as far towards the desired position as possible. x and y are relative to the window just as in the mouse position accessors.
78 |
# File 'lib/gosu_android/input/input.rb', line 78 def set_mouse_position(x, y); end |
#set_text_input(input) ⇒ Object
Sets the currently active TextInput, or clears it (input = 0).
118 |
# File 'lib/gosu_android/input/input.rb', line 118 def set_text_input(input); end |
#text_input ⇒ Object
Returns the currently active TextInput instance, or 0.
116 |
# File 'lib/gosu_android/input/input.rb', line 116 def text_input; end |
#update ⇒ Object
Collects new information about which buttons are pressed, where the mouse is and calls onButtonUp/onButtonDown, if assigned.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/gosu_android/input/input.rb', line 93 def update @touch_event_list.each do |touch_event| touch_event.getPointerCount.times do |index| touch = Touch.new(touch_event. getPointerId(index), touch_event.getX(index), touch_event.getY(index)) case touch_event.getAction when JavaImports::MotionEvent::ACTION_DOWN @window.touch_began(touch) when JavaImports::MotionEvent::ACTION_MOVE @window.touch_moved(touch) when JavaImports::MotionEvent::ACTION_UP @window.touch_ended(touch) end end end @touch_event_list = [] end |