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_down?(id) ⇒ Boolean
Returns true if a button is currently pressed.
- #button_up ⇒ Object
-
#char_to_id(ch) ⇒ Object
Returns the button that has to be pressed to produce the given character, or noButton.
- #clear ⇒ Object
-
#currentTouches ⇒ Object
Currently known touches.
- #feed_key_event_down(keyCode) ⇒ Object
- #feed_key_event_up(keyCode) ⇒ 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 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gosu_android/input/input.rb', line 40 def initialize(display, window) @display = display @window = window @touch_event_list = [] @key_event_list_up = [] @key_event_list_down = [] @id = 0 @ingnore_buttons = [JavaImports::KeyEvent::KEYCODE_VOLUME_DOWN, JavaImports::KeyEvent::KEYCODE_VOLUME_MUTE, JavaImports::KeyEvent::KEYCODE_VOLUME_UP, JavaImports::KeyEvent::KEYCODE_BACK, JavaImports::KeyEvent::KEYCODE_HOME, JavaImports::KeyEvent::KEYCODE_MENU, JavaImports::KeyEvent::KEYCODE_POWER, JavaImports::KeyEvent::KEYCODE_APP_SWITCH, JavaImports::KeyEvent::KEYCODE_UNKNOWN] end |
Instance Method Details
#accelerometerX ⇒ Object
Accelerometer positions in all three dimensions (smoothened).
111 |
# File 'lib/gosu_android/input/input.rb', line 111 def accelerometerX; end |
#accelerometerY ⇒ Object
112 |
# File 'lib/gosu_android/input/input.rb', line 112 def accelerometerY; end |
#accelerometerZ ⇒ Object
113 |
# File 'lib/gosu_android/input/input.rb', line 113 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.
150 |
# File 'lib/gosu_android/input/input.rb', line 150 def ; end |
#button_down?(id) ⇒ Boolean
Returns true if a button is currently pressed. Updated every tick.
87 88 89 |
# File 'lib/gosu_android/input/input.rb', line 87 def (id) return @key_event_list_down.include? id end |
#button_up ⇒ Object
151 |
# File 'lib/gosu_android/input/input.rb', line 151 def ; end |
#char_to_id(ch) ⇒ Object
Returns the button that has to be pressed to produce the given character, or noButton.
83 |
# File 'lib/gosu_android/input/input.rb', line 83 def char_to_id(ch); end |
#clear ⇒ Object
142 143 144 145 146 |
# File 'lib/gosu_android/input/input.rb', line 142 def clear @touch_event_list.clear @key_event_list_down.clear @key_event_list_up.clear end |
#currentTouches ⇒ Object
Currently known touches.
108 |
# File 'lib/gosu_android/input/input.rb', line 108 def currentTouches; end |
#feed_key_event_down(keyCode) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/gosu_android/input/input.rb', line 62 def feed_key_event_down(keyCode) if @ingnore_buttons.include? keyCode return false end @key_event_list_down.push keyCode return true end |
#feed_key_event_up(keyCode) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/gosu_android/input/input.rb', line 70 def feed_key_event_up(keyCode) if @ingnore_buttons.include? keyCode return false end @key_event_list_up.push keyCode return true end |
#feed_touch_event(event) ⇒ Object
58 59 60 |
# File 'lib/gosu_android/input/input.rb', line 58 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.
79 |
# File 'lib/gosu_android/input/input.rb', line 79 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.
93 |
# File 'lib/gosu_android/input/input.rb', line 93 def mouseX; end |
#mouseY ⇒ Object
Returns true if a button is currently pressed. Updated every tick.
97 |
# File 'lib/gosu_android/input/input.rb', line 97 def mouseY; end |
#set_mouse_factors(factorX, factorY) ⇒ Object
Undocumented for the moment. Also applies to currentTouches().
105 |
# File 'lib/gosu_android/input/input.rb', line 105 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.
102 |
# File 'lib/gosu_android/input/input.rb', line 102 def set_mouse_position(x, y); end |
#set_text_input(input) ⇒ Object
Sets the currently active TextInput, or clears it (input = 0).
156 |
# File 'lib/gosu_android/input/input.rb', line 156 def set_text_input(input); end |
#text_input ⇒ Object
Returns the currently active TextInput instance, or 0.
154 |
# File 'lib/gosu_android/input/input.rb', line 154 def text_input; end |
#update ⇒ Object
Collects new information about which buttons are pressed, where the mouse is and calls onButtonUp/onButtonDown, if assigned.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/gosu_android/input/input.rb', line 117 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 @key_event_list_down.each do |key_event| @window. key_event end @key_event_list_up.each do |key_event| @window. key_event end end |