class Gosu::Input

Manages initialization and shutdown of the input system. Only one Input instance can exist per application.

Public Class Methods

new(display, window) click to toggle source
# 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

Public Instance Methods

accelerometerX() click to toggle source

Accelerometer positions in all three dimensions (smoothened).

# File lib/gosu_android/input/input.rb, line 111
def accelerometerX; end
accelerometerY() click to toggle source
# File lib/gosu_android/input/input.rb, line 112
def accelerometerY; end
accelerometerZ() click to toggle source
# File lib/gosu_android/input/input.rb, line 113
def accelerometerZ; end
button_down() click to toggle source

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.

# File lib/gosu_android/input/input.rb, line 150
def button_down; end
button_down?(id) click to toggle source

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

# File lib/gosu_android/input/input.rb, line 87
def button_down?(id)
  return @key_event_list_down.include? id
end
button_up() click to toggle source
# File lib/gosu_android/input/input.rb, line 151
def button_up; end
char_to_id(ch) click to toggle source

Returns the button that has to be pressed to produce the given character, or noButton.

# File lib/gosu_android/input/input.rb, line 83
def char_to_id(ch); end
clear() click to toggle source
# 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() click to toggle source

Currently known touches.

# File lib/gosu_android/input/input.rb, line 108
def currentTouches; end
feed_key_event_down(keyCode) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/gosu_android/input/input.rb, line 58
def feed_touch_event(event)
  @touch_event_list.push event
end
id_to_char(btn) click to toggle source

Returns the character a button usually produces, or 0.

# File lib/gosu_android/input/input.rb, line 79
def id_to_char(btn); end
mouseX() click to toggle source

Returns the horizontal position of the mouse relative to the top left corner of the window given to Input’s constructor.

# File lib/gosu_android/input/input.rb, line 93
def mouseX; end
mouseY() click to toggle source

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

# File lib/gosu_android/input/input.rb, line 97
def mouseY; end
set_mouse_factors(factorX, factorY) click to toggle source

Undocumented for the moment. Also applies to currentTouches().

# File lib/gosu_android/input/input.rb, line 105
def set_mouse_factors(factorX,  factorY); end
set_mouse_position(x, y) click to toggle source

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.

# File lib/gosu_android/input/input.rb, line 102
def set_mouse_position(x,  y); end
set_text_input(input) click to toggle source

Sets the currently active TextInput, or clears it (input = 0).

# File lib/gosu_android/input/input.rb, line 156
def set_text_input(input); end
text_input() click to toggle source

Returns the currently active TextInput instance, or 0.

# File lib/gosu_android/input/input.rb, line 154
def text_input; end
update() click to toggle source

Collects new information about which buttons are pressed, where the mouse is and calls onButtonUp/onButtonDown, if assigned.

# 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