Module: Gosu

Defined in:
lib/gosu_android/graphics/color.rb,
lib/gosu_android/math.rb,
lib/gosu_android/timing.rb,
lib/gosu_android/version.rb,
lib/gosu_android/audio/audio.rb,
lib/gosu_android/description.rb,
lib/gosu_android/input/input.rb,
lib/gosu_android/main-window.rb,
lib/gosu_android/commands/base.rb,
lib/gosu_android/graphics/font.rb,
lib/gosu_android/input/buttons.rb,
lib/gosu_android/graphics/image.rb,
lib/gosu_android/graphics/bitmap.rb,
lib/gosu_android/graphics/common.rb,
lib/gosu_android/graphics/drawOp.rb,
lib/gosu_android/graphics/texture.rb,
lib/gosu_android/graphics/graphics.rb,
lib/gosu_android/graphics/texChunk.rb,
lib/gosu_android/graphics/imageData.rb,
lib/gosu_android/graphics/bitmapUtils.rb,
lib/gosu_android/graphics/drawOpQueue.rb,
lib/gosu_android/graphics/renderState.rb,
lib/gosu_android/graphics/graphicsBase.rb,
lib/gosu_android/graphics/blockAllocator.rb,
lib/gosu_android/graphics/largeImageData.rb

Overview

require ‘math.rb’

Defined Under Namespace

Modules: Commands Classes: AndroidInitializer, AudioCompletionListener, AudioErrorListener, AudioFocusListener, AudioInfoListener, BlockAllocator, Button, Color, DrawOpQueue, Font, FontsManager, GLTexInfo, GosuSurfaceView, Graphics, HSV, Image, ImageData, Input, LargeImageData, Sample, SampleInstance, Song, TexChunk, Texture, Touch, Window

Constant Summary collapse

VERSION =
'0.0.5'
MAX_SAMPLES =
10
DESCRIPTION =
<<EOF
Gosu-Android is an implementation for Android devices of the multiplatform Gosu library.
EOF
Kb0 =
JavaImports::KeyEvent::KEYCODE_0
Kb1 =
JavaImports::KeyEvent::KEYCODE_1
Kb2 =
JavaImports::KeyEvent::KEYCODE_2
Kb3 =
JavaImports::KeyEvent::KEYCODE_3
Kb4 =
JavaImports::KeyEvent::KEYCODE_4
Kb5 =
JavaImports::KeyEvent::KEYCODE_5
Kb6 =
JavaImports::KeyEvent::KEYCODE_6
Kb7 =
JavaImports::KeyEvent::KEYCODE_7
Kb8 =
JavaImports::KeyEvent::KEYCODE_8
Kb9 =
JavaImports::KeyEvent::KEYCODE_9
KbA =
JavaImports::KeyEvent::KEYCODE_A
KbB =
JavaImports::KeyEvent::KEYCODE_B
KbC =
JavaImports::KeyEvent::KEYCODE_C
KbD =
JavaImports::KeyEvent::KEYCODE_D
KbE =
JavaImports::KeyEvent::KEYCODE_E
KbF =
JavaImports::KeyEvent::KEYCODE_F
KbG =
JavaImports::KeyEvent::KEYCODE_G
KbH =
JavaImports::KeyEvent::KEYCODE_H
KbI =
JavaImports::KeyEvent::KEYCODE_I
KbJ =
JavaImports::KeyEvent::KEYCODE_J
KbK =
JavaImports::KeyEvent::KEYCODE_K
KbL =
JavaImports::KeyEvent::KEYCODE_L
KbM =
JavaImports::KeyEvent::KEYCODE_M
KbN =
JavaImports::KeyEvent::KEYCODE_N
KbO =
JavaImports::KeyEvent::KEYCODE_O
KbP =
JavaImports::KeyEvent::KEYCODE_P
KbQ =
JavaImports::KeyEvent::KEYCODE_Q
KbR =
JavaImports::KeyEvent::KEYCODE_R
KbS =
JavaImports::KeyEvent::KEYCODE_S
KbT =
JavaImports::KeyEvent::KEYCODE_T
KbU =
JavaImports::KeyEvent::KEYCODE_U
KbV =
JavaImports::KeyEvent::KEYCODE_V
KbW =
JavaImports::KeyEvent::KEYCODE_W
KbX =
JavaImports::KeyEvent::KEYCODE_X
KbY =
JavaImports::KeyEvent::KEYCODE_Y
KbZ =
JavaImports::KeyEvent::KEYCODE_Z
KbBackspace =
JavaImports::KeyEvent::KEYCODE_DEL
KbDelete =
JavaImports::KeyEvent::KEYCODE_DEL
KbDown =
JavaImports::KeyEvent::KEYCODE_DPAD_DOWN
KbHome =

On Numpad

JavaImports::KeyEvent::KEYCODE_HOME
KbLeft =
JavaImports::KeyEvent::KEYCODE_DPAD_LEFT
KbLeftAlt =
JavaImports::KeyEvent::KEYCODE_ALT_LEFT
KbLeftShift =
JavaImports::KeyEvent::KEYCODE_SHIFT_LEFT
KbPageDown =
JavaImports::KeyEvent::KEYCODE_PAGE_DOWN
KbPageUp =
JavaImports::KeyEvent::KEYCODE_PAGE_UP
KbReturn =

Above the right shift key

JavaImports::KeyEvent::KEYCODE_ENTER
KbRight =
JavaImports::KeyEvent::KEYCODE_DPAD_RIGHT
KbRightAlt =
JavaImports::KeyEvent::KEYCODE_ALT_RIGHT
KbRightShift =

KbRightControl = JavaImports::KeyEvent::KEYCODE_CTRL_RIGHT

JavaImports::KeyEvent::KEYCODE_SHIFT_RIGHT
KbSpace =
JavaImports::KeyEvent::KEYCODE_SPACE
KbTab =
JavaImports::KeyEvent::KEYCODE_TAB
KbUp =
JavaImports::KeyEvent::KEYCODE_DPAD_UP
NoButton =

TODO Fix mouse buttons, Mouse access to motion event MsLeft = JavaImports::MotionEvent::BUTTON_PRIMARY MsMiddle = JavaImports::MotionEvent::BUTTON_TERTIARY MsRight = JavaImports::MotionEvent::BUTTON_SECONDARY TODO Axis wheel is not right MsWheelDown = JavaImports::MotionEvent::AXIS_WHEEL MsWheelUp = JavaImports::MotionEvent::AXIS_WHEEL

0xffffffff
KbEnd =
JavaImports::KeyEvent::KEYCODE_MOVE_END
KbEnter =

On Numpad

JavaImports::KeyEvent::KEYCODE_NUMPAD_ENTER
KbEscape =
JavaImports::KeyEvent::KEYCODE_ESCAPE
KbF1 =
JavaImports::KeyEvent::KEYCODE_F1
KbF10 =
JavaImports::KeyEvent::KEYCODE_F10
KbF11 =
JavaImports::KeyEvent::KEYCODE_F11
KbF12 =
JavaImports::KeyEvent::KEYCODE_F12
KbF2 =
JavaImports::KeyEvent::KEYCODE_F2
KbF3 =
JavaImports::KeyEvent::KEYCODE_F3
KbF4 =
JavaImports::KeyEvent::KEYCODE_F4
KbF5 =
JavaImports::KeyEvent::KEYCODE_F5
KbF6 =
JavaImports::KeyEvent::KEYCODE_F6
KbF7 =
JavaImports::KeyEvent::KEYCODE_F7
KbF8 =
JavaImports::KeyEvent::KEYCODE_F8
KbF9 =
JavaImports::KeyEvent::KEYCODE_F9
KbInsert =
JavaImports::KeyEvent::KEYCODE_INSERT
KbLeftControl =
JavaImports::KeyEvent::KEYCODE_CTRL_LEFT
KbNumpad0 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_0
KbNumpad1 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_1
KbNumpad2 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_2
KbNumpad3 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_3
KbNumpad4 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_4
KbNumpad5 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_5
KbNumpad6 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_6
KbNumpad7 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_7
KbNumpad8 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_8
KbNumpad9 =
JavaImports::KeyEvent::KEYCODE_NUMPAD_9
KbNumpadAdd =
JavaImports::KeyEvent::KEYCODE_NUMPAD_ADD
KbNumpadDivide =
JavaImports::KeyEvent::KEYCODE_NUMPAD_DIVIDE
KbNumpadMultiply =
JavaImports::KeyEvent::KEYCODE_NUMPAD_MULTIPLY
KbNumpadSubtract =
JavaImports::KeyEvent::KEYCODE_NUMPAD_SUBTRACT
KbRightControl =

Above the right shift key

JavaImports::KeyEvent::KEYCODE_CTRL_RIGHT
GpButton0 =

Game pad

JavaImports::KeyEvent::KEYCODE_BUTTON_1
GpButton1 =
JavaImports::KeyEvent::KEYCODE_BUTTON_2
GpButton10 =
JavaImports::KeyEvent::KEYCODE_BUTTON_11
GpButton11 =
JavaImports::KeyEvent::KEYCODE_BUTTON_12
GpButton12 =
JavaImports::KeyEvent::KEYCODE_BUTTON_13
GpButton13 =
JavaImports::KeyEvent::KEYCODE_BUTTON_14
GpButton14 =
JavaImports::KeyEvent::KEYCODE_BUTTON_15
GpButton15 =
JavaImports::KeyEvent::KEYCODE_BUTTON_16
GpButton2 =
JavaImports::KeyEvent::KEYCODE_BUTTON_3
GpButton3 =
JavaImports::KeyEvent::KEYCODE_BUTTON_4
GpButton4 =
JavaImports::KeyEvent::KEYCODE_BUTTON_5
GpButton5 =
JavaImports::KeyEvent::KEYCODE_BUTTON_6
GpButton6 =
JavaImports::KeyEvent::KEYCODE_BUTTON_7
GpButton7 =
JavaImports::KeyEvent::KEYCODE_BUTTON_8
GpButton8 =
JavaImports::KeyEvent::KEYCODE_BUTTON_9
GpButton9 =
JavaImports::KeyEvent::KEYCODE_BUTTON_10
NO_TEXTURE =
-1
NO_CLIPPING =
0xffffffff
AM_MODES =

amMultiply -> The color’s channels will be multiplied with each other.

{ :default => 0, :add => 1, :additive => 1, :multiply => 2 }
FF_BOLD =
1
FF_ITALIC =
2
FF_UNDERLINE =
4
FF_COMBINATIONS =
8
BF_SMOOTH =

Flags that affect the tileability of an image

0
BF_TILEABLE_LEFT =
1
BF_TILEABLE_TOP =
2
BF_TILEABLE_RIGHT =
4
BF_TILEABLE_BOTTOM =
8
BF_TILEABLE =
BF_TILEABLE_LEFT | BF_TILEABLE_TOP | BF_TILEABLE_RIGHT | BF_TILEABLE_BOTTOM

Class Method Summary collapse

Class Method Details

.apply_border_flags(dest, source, src_x, src_y, src_width, src_height, border_flags) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gosu_android/graphics/bitmapUtils.rb', line 4

def self.apply_border_flags(dest, source, src_x, src_y, src_width, src_height, border_flags)
  dest.resize(src_width + 2, src_height + 2)

  #The borders are made "harder" by duplicating the original bitmap's
  #borders.

  #Top.
  if (border_flags & BF_TILEABLE_TOP)
      dest.insert(source, 1, 0, src_x, src_y, src_width, 1)
  end
  #Bottom.
  if (border_flags & BF_TILEABLE_BOTTOM)
      dest.insert(source, 1, dest.height - 1,
          src_x, src_y + src_height - 1, src_width, 1)
  end
  #Left.
  if (border_flags & BF_TILEABLE_LEFT)
      dest.insert(source, 0, 1, src_x, src_y, 1, src_height)
  end
  #Right.
  if (border_flags & BF_TILEABLE_RIGHT)
      dest.insert(source, dest.width - 1, 1,
          src_x + src_width - 1, src_y, 1, src_height)
  end
  #Top left.
  if ((border_flags & BF_TILEABLE_TOP) and (border_flags & BF_TILEABLE_LEFT))
      dest.set_pixel(0, 0,
          source.get_pixel(src_x, src_y))
  end
  #Top right.
  if ((border_flags & BF_TILEABLE_TOP) and (border_flags & BF_TILEABLE_RIGHT))
      dest.set_pixel(dest.width - 1, 0,
          source.get_pixel(src_x + src_width - 1, src_y))
  end
  #Bottom left.
  if ((border_flags & BF_TILEABLE_BOTTOM) and (border_flags & BF_TILEABLE_LEFT))
      dest.set_pixel(0, dest.height - 1,
          source.get_pixel(src_x, src_y + src_height - 1))
  end
  #Bottom right.
  if ((border_flags & BF_TILEABLE_BOTTOM) and (border_flags & BF_TILEABLE_RIGHT))
      dest.set_pixel(dest.width - 1, dest.height - 1,
          source.get_pixel(src_x + src_width - 1, src_y + src_height - 1))
  end
  #Now put the final image into the prepared borders.
  dest.insert(source, 1, 1, src_x, src_y, src_width, src_height)
end

.default_font_nameObject



57
58
59
# File 'lib/gosu_android/graphics/font.rb', line 57

def self.default_font_name
  JavaImports::Typeface::MONOSPACE
end

.distance(x1, y1, x2, y2) ⇒ Object

Returns the distance between two points.



17
18
19
# File 'lib/gosu_android/math.rb', line 17

def self.distance(x1, y1, x2, y2)
  Math::sqrt((x1 - x2)**2 + (y1 - y2)**2)
end

.distance_sqr(x1, y1, x2, y2) ⇒ Object

Returns the square of the distance between two points.



12
13
14
# File 'lib/gosu_android/math.rb', line 12

def self.distance_sqr(x1, y1, x2, y2)
  (x1 - x2)**2 + (y1 - y2)**2
end

.is_p_to_the_left_of_ab(xa, ya, xb, yb, xp, yp) ⇒ Object



8
9
10
# File 'lib/gosu_android/graphics/common.rb', line 8

def self.is_p_to_the_left_of_ab(xa, ya, xb, yb, xp, yp)
  ((xb - xa) * (yp - ya) - (xp - xa) * (yb - ya)) > 0
end

.load_image_file(window, file_name) ⇒ Object

TODO define load_image with reader argument



9
10
11
# File 'lib/gosu_android/graphics/bitmap.rb', line 9

def self.load_image_file(window, file_name)
  Gosu::Bitmap.new(window.activity.getApplicationContext, file_name)
end

.millisecondsObject



3
4
5
6
# File 'lib/gosu_android/timing.rb', line 3

def self.milliseconds
  tp = Time.now.to_f
  (tp*1000).to_i
end

.offset_x(angle, radius) ⇒ Object



3
4
5
# File 'lib/gosu_android/math.rb', line 3

def self.offset_x(angle, radius)
  Math::sin(angle / 180 * Math::PI) * radius
end

.offset_y(angle, radius) ⇒ Object



7
8
9
# File 'lib/gosu_android/math.rb', line 7

def self.offset_y(angle, radius)
  Math::cos(angle / 180 * Math::PI) * radius
end

.reorder_coordinates_if_necessary(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/gosu_android/graphics/common.rb', line 12

def self.reorder_coordinates_if_necessary(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4)
  if (Gosu::is_p_to_the_left_of_ab(x1, y1, x2, y2, x3, y3) ==
    Gosu::is_p_to_the_left_of_ab(x2, y2, x3, y3, x4, y4))
    true
  else
    false
  end    
end