Class: Gosu::Input

Inherits:
Object
  • Object
show all
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

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

#accelerometerXObject

Accelerometer positions in all three dimensions (smoothened).



111
# File 'lib/gosu_android/input/input.rb', line 111

def accelerometerX; end

#accelerometerYObject



112
# File 'lib/gosu_android/input/input.rb', line 112

def accelerometerY; end

#accelerometerZObject



113
# File 'lib/gosu_android/input/input.rb', line 113

def accelerometerZ; end

#button_downObject

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 button_down; end

#button_down?(id) ⇒ Boolean

Returns true if a button is currently pressed. Updated every tick.

Returns:

  • (Boolean)


87
88
89
# File 'lib/gosu_android/input/input.rb', line 87

def button_down?(id)
  return @key_event_list_down.include? id
end

#button_upObject



151
# File 'lib/gosu_android/input/input.rb', line 151

def button_up; 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

#clearObject



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

#currentTouchesObject

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

#mouseXObject

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

#mouseYObject

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_inputObject

Returns the currently active TextInput instance, or 0.



154
# File 'lib/gosu_android/input/input.rb', line 154

def text_input; end

#updateObject

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.button_down key_event
  end
  
  @key_event_list_up.each do |key_event|
    @window.button_up key_event
  end       

end