class Gosu::Window

Attributes

activity[R]
caption[RW]
fonts_manager[R]
fullscreen[R]
height[R]
internal_update_interval[R]
media_player[RW]
mouse_x[RW]
mouse_y[RW]
text_input[RW]
update_interval[R]
width[R]

Public Class Methods

button_id_to_char(id) click to toggle source

Returns the character a button usually produces, or nil. To implement real text-input facilities, look at the TextInput class instead.

# File lib/gosu_android/main-window.rb, line 299
def self.button_id_to_char(id); end
char_to_button_id(char) click to toggle source

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

# File lib/gosu_android/main-window.rb, line 302
def self.char_to_button_id(char); end
new(width, height, fullscreen, update_interval=16.666666) click to toggle source
update_interval

Interval in milliseconds between two calls

to the update member function. The default means the game will run at 60 FPS, which is ideal on standard 60 Hz TFT screens.

# File lib/gosu_android/main-window.rb, line 75
def initialize(width, height, fullscreen, update_interval=16.666666)
  android_initializer = AndroidInitializer.instance
  @fullscreen = fullscreen
  @showing = false
  @activity = android_initializer.activity
  @display = @activity.getWindowManager.getDefaultDisplay
  @width = width
  @height= height
  @internal_update_interval = update_interval/1000.0
  @update_interval = update_interval
  #@surface_view = GosuSurfaceView.new(@activity)
  @surface_view = android_initializer.surface_view
  @input = Input.new(@display, self)
  @surface_view.atributes(self, @input)
  #@graphics = Graphics.new(@width, @height, @fullscreen, self)
  @graphics = android_initializer.graphics
  @graphics.initialize_window(@width, @height, @fullscreen, self)
  #@surface_view.renderer =  @graphics
  @surface_view.set_render_mode(JavaImports::GLSurfaceView::RENDERMODE_WHEN_DIRTY)
  @fonts_manager = FontsManager.new self
  @media_player = nil
  add_key_event_listener
  @activity.input = @input
  @showing_keyboard = false
end

Public Instance Methods

add_key_event_listener() click to toggle source

TODO At least check if the methods were already defined, if so called them after/before this methods

# File lib/gosu_android/main-window.rb, line 107
def add_key_event_listener
  # Get the class of the object.
  @activity.class.class_eval do
    
    attr_accessor :input
    
    def on_destroy
      super
      #Release audio resources
      Song.release_resources         
    end
    
    def onKeyDown(keyCode, event)      
      if @input.feed_key_event_down(keyCode)
        return true
      else
        return super keyCode, event
      end
    end

    def onKeyUp(keyCode, event)        
      if @input.feed_key_event_up(keyCode)
        return true
      else
        return super keyCode, event
      end
    end

    #TODO It does never get called, it does not matter how long
    #the press was
    def onKeyLongPress(keyCode, event) 
      if @input.feed_key_event_up(keyCode)
        return true
      else
        return super keyCode, event
      end
    end
    
  end
end
button_down(id) click to toggle source

Called before update when the user pressed a button while the window had the focus.

# File lib/gosu_android/main-window.rb, line 214
def button_down(id); end
button_down?(id) click to toggle source

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

# File lib/gosu_android/main-window.rb, line 219
def button_down?(id)
  return @input.button_down? id
end
button_up(id) click to toggle source

Same as buttonDown. Called then the user released a button.

# File lib/gosu_android/main-window.rb, line 216
def button_up(id); end
caption=(value) click to toggle source
# File lib/gosu_android/main-window.rb, line 307
def caption= value
  @caption = value
  if @showing and not @fullscreen
    p = Proc.new do
      @activity.setTitle @caption
    end
    @activity.runOnUiThread(p)
  end
end
clip_to(x, y, w, h, &rendering_code) click to toggle source

Limits the drawing area to a given rectangle while evaluating the code inside of the block.

# File lib/gosu_android/main-window.rb, line 269
def clip_to(x, y, w, h, &rendering_code); end
close() click to toggle source

Tells the window to end the current show loop as soon as possible.

# File lib/gosu_android/main-window.rb, line 184
def close     
  #Self trigger window lost focus, since we are going to home
  focus_changed false, @screen_width, @screen_height
  @showing = false
  @activity.moveTaskToBack(true)
end
create_image(source, src_x, src_y, src_width, src_height, tileable) click to toggle source
# File lib/gosu_android/main-window.rb, line 373
def create_image(source, src_x, src_y, src_width, src_height, tileable)
  @graphics.create_image(source, src_x, src_y, src_width, src_height, tileable)
end
do_show() click to toggle source
# File lib/gosu_android/main-window.rb, line 173
def do_show
  @start_time = Time.now
  do_tick
  #TODO gosu dark side
  @end_time = Time.now
  if (@start_time <= @end_time and (@end_time - @start_time) < @internal_update_interval)
      sleep(@internal_update_interval - (@end_time - @start_time))
  end
end
do_tick() click to toggle source
# File lib/gosu_android/main-window.rb, line 317
def do_tick
  @input.update
  self.update
  @input.clear
  @graphics.begin(Color::BLACK)
  self.draw
  @graphics.end
  @surface_view.request_render
end
draw() click to toggle source

Called after every update and when the OS wants the window to repaint itself. Your application’s rendering code goes here.

# File lib/gosu_android/main-window.rb, line 197
def draw; end
draw_line(x1, y1, c1, x2, y2, c2, z=0, mode=:default) click to toggle source

Draws a line from one point to another (last pixel exclusive). Note: OpenGL lines are not reliable at all and may have a missing pixel at the start or end point. Please only use this for debugging purposes. Otherwise, use a quad or image to simulate lines, or contribute a better draw_line to Gosu.

# File lib/gosu_android/main-window.rb, line 237
def draw_line(x1, y1, c1, x2, y2, c2, z=0, mode=:default)
  @graphics.draw_line(x1, y1, c1, x2, y2, c2, z, AM_MODES[mode])
end
draw_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z=0, mode=:default) click to toggle source

Draws a rectangle (two triangles) with given corners and corresponding colors. The points can be in clockwise order, or in a Z shape.

# File lib/gosu_android/main-window.rb, line 248
def draw_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z=0, mode=:default)
  @graphics.draw_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, AM_MODES[mode])
end
draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z=0, mode=:default) click to toggle source
# File lib/gosu_android/main-window.rb, line 241
def draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z=0, mode=:default)
  @graphics.draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z, AM_MODES[mode])
end
flush() click to toggle source

Flushes all drawing operations to OpenGL so that Z-ordering can start anew. This is useful when drawing several parts of code on top of each other that use conflicting z positions.

# File lib/gosu_android/main-window.rb, line 255
def flush; end
focus_changed(has_focus, width, height) click to toggle source

TODO On screen rotation the app breaks down

# File lib/gosu_android/main-window.rb, line 328
def focus_changed has_focus, width, height
  @screen_width = width
  @screen_height = height
  
  if has_focus
           
    if @showing and @media_player != nil
        @media_player.start
    end

    #TODO Keyboard does not appears again
    if @showing_keyboard
      show_soft_keyboard
    end
   
  else
    #Hide keyboard but mark it so it will be shown later
    if @showing_keyboard
      hide_soft_keyboard
      @showing_keyboard = true
    end
    
    if @showing and @media_player != nil
        @media_player.pause
    end
    
  end   
  return true  
end
gl(z=nil, &custom_gl_code) click to toggle source

For custom OpenGL calls. Executes the given block in a clean OpenGL environment. Use the ruby-opengl gem to access OpenGL function (if you manage to get it to work). IF no z position is given, it will execute the given block immediately, otherwise, the code will be scheduled to be called between Gosu drawing operations.

Note: You cannot call Gosu rendering functions within this block, and you can only call the gl function in the call tree of Window#draw.

See examples/OpenGLIntegration.rb for an example.

# File lib/gosu_android/main-window.rb, line 266
def gl(z=nil, &custom_gl_code); end
hide_soft_keyboard() click to toggle source
# File lib/gosu_android/main-window.rb, line 366
def hide_soft_keyboard
  context = @activity.getApplicationContext
  imm = context.getSystemService(Context::INPUT_METHOD_SERVICE)
  imm.toggleSoftInput(JavaImports::InputMethodManager::HIDE_IMPLICIT_ONLY,0)    
  @showing_keyboard = false
end
needs_cursor?() click to toggle source

Can be overriden to show the system cursor when necessary, e.g. in level editors or other situations where introducing a custom cursor is not desired.

# File lib/gosu_android/main-window.rb, line 210
def needs_cursor?; end
needs_redraw?() click to toggle source

Can be overriden to give the game a chance to say no to being redrawn. This is not a definitive answer. The operating system can still cause redraws for one reason or another.

By default, the window is redrawn all the time (i.e. Window#needs_redraw? always returns true.)

# File lib/gosu_android/main-window.rb, line 205
def needs_redraw?; end
object_collided(x, y, object) click to toggle source

Called when and object collides with another object

# File lib/gosu_android/main-window.rb, line 231
def object_collided(x, y, object); end
onKeyDown(keyCode, event) click to toggle source
Calls superclass method
# File lib/gosu_android/main-window.rb, line 119
def onKeyDown(keyCode, event)      
  if @input.feed_key_event_down(keyCode)
    return true
  else
    return super keyCode, event
  end
end
onKeyLongPress(keyCode, event) click to toggle source

TODO It does never get called, it does not matter how long the press was

Calls superclass method
# File lib/gosu_android/main-window.rb, line 137
def onKeyLongPress(keyCode, event) 
  if @input.feed_key_event_up(keyCode)
    return true
  else
    return super keyCode, event
  end
end
onKeyUp(keyCode, event) click to toggle source
Calls superclass method
# File lib/gosu_android/main-window.rb, line 127
def onKeyUp(keyCode, event)        
  if @input.feed_key_event_up(keyCode)
    return true
  else
    return super keyCode, event
  end
end
on_destroy() click to toggle source
Calls superclass method
# File lib/gosu_android/main-window.rb, line 113
def on_destroy
  super
  #Release audio resources
  Song.release_resources         
end
record(width, height, &rendering_code) click to toggle source

Returns a Gosu::Image that containes everything rendered within the given block. It can be used to optimize rendering of many static images, e.g. the map. There are still several restrictions that you will be informed about via exceptions.

The returned Gosu::Image will have the width and height you pass as arguments, regardless of how the area you draw on. It is important to pass accurate values if you plan on using Gosu::Image#draw_as_quad or Gosu::Image#draw_rot with the result later.

@return [Gosu::Image]

# File lib/gosu_android/main-window.rb, line 280
def record(width, height, &rendering_code); end
rotate(angle, around_x=0, around_y=0, &rendering_code) click to toggle source

Rotates everything drawn in the block around (around_x, around_y).

# File lib/gosu_android/main-window.rb, line 283
def rotate(angle, around_x=0, around_y=0, &rendering_code); end
scale(factor_x, factor_y=factor_x, &rendering_code) click to toggle source

Scales everything drawn in the block by a factor.

# File lib/gosu_android/main-window.rb, line 286
def scale(factor_x, factor_y=factor_x, &rendering_code); end
set_mouse_position(x, y) click to toggle source

@deprecated Use Window#mouse_x= and Window#mouse_y= instead.

# File lib/gosu_android/main-window.rb, line 305
def set_mouse_position(x, y); end
show() click to toggle source

Enters a modal loop where the Window is visible on screen and receives calls to draw, update etc.

# File lib/gosu_android/main-window.rb, line 149
def show
  @showing = true
  if @fullscreen
    #Use full java path for Window, since there is a Gosu::Window
    @activity.request_window_feature(JavaImports::Window::FEATURE_NO_TITLE)
    @activity.get_window.set_flags(JavaImports::WindowManager::LayoutParams::FLAG_FULLSCREEN,
        JavaImports::WindowManager::LayoutParams::FLAG_FULLSCREEN)
    #@activity.content_view = @surface_view
    @window = @activity.getWindow
    #Replace position and size with gosu metrics
  else
    @window = @activity.getWindow
    #Only the thread that created the view can change it, so setLayout
    #and setTitle cannot be executed here
    p = Proc.new do
      @window.setLayout(@width, @height)
      @activity.setTitle @caption
    end
    @activity.runOnUiThread(p)
  end
  @screen_width = @surface_view.get_width
  @screen_height = @surface_view.get_height
end
show_soft_keyboard() click to toggle source

TODO It would be nice that the keyboard was transparent

# File lib/gosu_android/main-window.rb, line 359
def show_soft_keyboard             
  context = @activity.getApplicationContext
  imm = context.getSystemService(Context::INPUT_METHOD_SERVICE)
  imm.toggleSoftInput(JavaImports::InputMethodManager::SHOW_FORCED,0)
  @showing_keyboard = true
end
touch_began(touch) click to toggle source

Called when the user started a touch on the screen

# File lib/gosu_android/main-window.rb, line 224
def touch_began(touch); end
touch_ended(touch) click to toggle source

Called when the user finished a touch on the screen

# File lib/gosu_android/main-window.rb, line 228
def touch_ended(touch); end
touch_moved(touch) click to toggle source

Called when the user continue a touch on the screen

# File lib/gosu_android/main-window.rb, line 226
def touch_moved(touch); end
transform(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, &rendering_code) click to toggle source

Applies a free-form matrix rotation to everything drawn in the block.

# File lib/gosu_android/main-window.rb, line 295
def transform(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, &rendering_code); end
translate(x, y, &rendering_code) click to toggle source

Moves everything drawn in the block by an offset in each dimension.

# File lib/gosu_android/main-window.rb, line 292
def translate(x, y, &rendering_code); end
update() click to toggle source

Called every update_interval milliseconds while the window is being shown. Your application’s main game logic goes here.

# File lib/gosu_android/main-window.rb, line 193
def update; end