gosu_android 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/LICENSE +19 -0
  2. data/README.md +35 -0
  3. data/bin/gosu_android +11 -0
  4. data/examples/arkanoid.rb +105 -0
  5. data/examples/pong_activity.rb +99 -0
  6. data/examples/test-game.rb +114 -0
  7. data/lib/gosu.java.jar +0 -0
  8. data/lib/gosu_android.rb +1 -0
  9. data/lib/gosu_android/audio/audio.rb +159 -0
  10. data/lib/gosu_android/commands/base.rb +200 -0
  11. data/lib/gosu_android/description.rb +5 -0
  12. data/lib/gosu_android/graphics/bitmap.rb +12 -0
  13. data/lib/gosu_android/graphics/bitmapUtils.rb +51 -0
  14. data/lib/gosu_android/graphics/blockAllocator.rb +107 -0
  15. data/lib/gosu_android/graphics/color.rb +27 -0
  16. data/lib/gosu_android/graphics/common.rb +21 -0
  17. data/lib/gosu_android/graphics/drawOp.rb +6 -0
  18. data/lib/gosu_android/graphics/drawOpQueue.rb +39 -0
  19. data/lib/gosu_android/graphics/font.rb +61 -0
  20. data/lib/gosu_android/graphics/graphics.rb +227 -0
  21. data/lib/gosu_android/graphics/graphicsBase.rb +27 -0
  22. data/lib/gosu_android/graphics/image.rb +151 -0
  23. data/lib/gosu_android/graphics/imageData.rb +23 -0
  24. data/lib/gosu_android/graphics/largeImageData.rb +116 -0
  25. data/lib/gosu_android/graphics/renderState.rb +5 -0
  26. data/lib/gosu_android/graphics/texChunk.rb +68 -0
  27. data/lib/gosu_android/graphics/texture.rb +86 -0
  28. data/lib/gosu_android/input/buttons.rb +128 -0
  29. data/lib/gosu_android/input/input.rb +120 -0
  30. data/lib/gosu_android/main-window.rb +314 -0
  31. data/lib/gosu_android/math.rb +21 -0
  32. data/lib/gosu_android/physics/physicsManager.rb +57 -0
  33. data/lib/gosu_android/physics/physicsObject.rb +113 -0
  34. data/lib/gosu_android/requires.rb +40 -0
  35. data/lib/gosu_android/timing.rb +8 -0
  36. data/lib/gosu_android/version.rb +3 -0
  37. data/res/drawable-nodpi/ball.png +0 -0
  38. data/res/drawable-nodpi/bar.png +0 -0
  39. data/res/drawable-nodpi/bar_hor.png +0 -0
  40. data/res/drawable-nodpi/character_atlas8.png +0 -0
  41. data/res/drawable-nodpi/ship.png +0 -0
  42. data/res/drawable-nodpi/space.png +0 -0
  43. data/res/drawable-nodpi/star.png +0 -0
  44. data/res/raw/beep.wav +0 -0
  45. data/res/raw/chriss_onac_tempo_red.mp3 +0 -0
  46. metadata +127 -0
@@ -0,0 +1,23 @@
1
+ module Gosu
2
+ #Contains information about the underlying OpenGL texture and the
3
+ #u/v space used for image data. Can be retrieved from some images
4
+ #to use them in OpenGL operations.
5
+ class GLTexInfo < Struct.new(:tex_name, :left, :right, :top, :bottom); end
6
+
7
+ #The ImageData class is an abstract base class for drawable images.
8
+ #Instances of classes derived by ImageData are usually returned by
9
+ #Graphics::createImage and usually only used to implement drawing
10
+ #primitives like Image, which then provide a more specialized and
11
+ #intuitive drawing interface.
12
+ class ImageData
13
+ def width; end
14
+ def height; end
15
+
16
+ def draw( x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode);
17
+ end
18
+
19
+ def gl_tex_info; end
20
+ def to_bitmap; end
21
+ end
22
+
23
+ end
@@ -0,0 +1,116 @@
1
+ require 'gosu_android/graphics/imageData'
2
+
3
+ module Gosu
4
+
5
+ class LargeImageData < ImageData
6
+ def initilialize(graphics, source, part_width, part_height, border_flags)
7
+ @full_width = source.width()
8
+ @full_height = source.height()
9
+ @parts_x = (1.0 * source.width() / @part_width).ceil.truncate
10
+ @parts_y = (1.0 * source.height() / @part_height).ceil.truncate
11
+ @part_width = part_width
12
+ @part_height = part_height
13
+ @graphics = graphics
14
+
15
+ @parts = Array.new(@parts_x * @parts_y)
16
+
17
+ @parts_y.times do |y|
18
+ @parts_x.times do |x|
19
+ #The right-most parts don't necessarily have the full width.
20
+ src_width = @part_width
21
+ if (x == @parts_x - 1 and source.width() % @part_width != 0)
22
+ src_width = source.width() % @part_width
23
+ end
24
+ #Same for the parts on the bottom.
25
+ src_height = @part_height
26
+ if (y == @parts_y - 1 and source.height() % @part_height != 0)
27
+ src_height = source.height() % @part_height
28
+ end
29
+ localBorderFlags = BF_TILEABLE
30
+ if (x == 0)
31
+ localBorderFlags = (localBorderFlags & ~BF_TILEABLE_LEFT) | (borderFlags & BF_TILEABLE_LEFT)
32
+ end
33
+ if (x == @parts_x - 1)
34
+ localBorderFlags = (localBorderFlags & ~BF_TILEABLE_RIGHT) | (borderFlags & BF_TILEABLE_RIGHT)
35
+ end
36
+ if (y == 0)
37
+ localBorderFlags = (localBorderFlags & ~BF_TILEABLE_TOP) | (borderFlags & BF_TILEABLE_TOP)
38
+ end
39
+ if (y == @parts_y - 1)
40
+ localBorderFlags = (localBorderFlags & ~BF_TILEABLE_BOTTOM) | (borderFlags & BF_TILEABLE_BOTTOM)
41
+ end
42
+
43
+ @parts[y * @parts_x + x] = @graphics.create_image(source, x * @part_width, y * @part_height, src_width, src_height, localBorderFlags)
44
+ end
45
+ end
46
+ end
47
+
48
+ def width
49
+ @full_width
50
+ end
51
+
52
+ def height
53
+ @full_height
54
+ end
55
+
56
+ def ipl(a,b,ratio)
57
+ a+(b-a)*ratio
58
+ end
59
+
60
+ def draw( x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode)
61
+
62
+ if Gosu::reorder_coordinates_if_necessary(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4)
63
+ x3, y3, c3, x4, y4, c4 = x4, y4,c4, x3, y3, c3
64
+ end
65
+
66
+ c = Color::NONE
67
+
68
+ @parts_y.times do |py|
69
+ @parts_x.times do |px|
70
+ part = @parts[py * @parts_x + px];
71
+
72
+ rel_xl = (px.to_f * @part_width) / width
73
+ rel_xr = (px.to_f * @part_width + part.width) / width
74
+ rel_yt = (py.to_f * @part_height) / height
75
+ rel_yb = (py.to_f * @part_height + part.height) / height
76
+
77
+ abs_xtl = ipl(ipl(x1, x3, rel_yt), ipl(x2, x4, rel_yt), rel_xl)
78
+ abs_xtr = ipl(ipl(x1, x3, rel_yt), ipl(x2, x4, rel_yt), rel_xr)
79
+ abs_xbl = ipl(ipl(x1, x3, rel_yb), ipl(x2, x4, rel_yb), rel_xl)
80
+ abs_xbr = ipl(ipl(x1, x3, rel_yb), ipl(x2, x4, rel_yb), rel_xr)
81
+
82
+ abs_ytl = ipl(ipl(y1, y3, rel_yt), ipl(y2, y4, rel_yt), rel_xl)
83
+ abs_ytr = ipl(ipl(y1, y3, rel_yt), ipl(y2, y4, rel_yt), rel_xr)
84
+ abs_ybl = ipl(ipl(y1, y3, rel_yb), ipl(y2, y4, rel_yb), rel_xl)
85
+ abs_ybr = ipl(ipl(y1, y3, rel_yb), ipl(y2, y4, rel_yb), rel_xr)
86
+
87
+ part.draw(abs_xtl, abs_ytl, c, abs_xtr, abs_ytr, c,
88
+ abs_xbl, abs_ybl, c, abs_xbr, abs_ybr, c, z, mode)
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ def gl_tex_info
95
+ 0
96
+ end
97
+
98
+ def to_bitmap()
99
+ bitmap = Bitmap.new(width, height)
100
+ @parts_y.times do |y|
101
+ @parts_x.times do |x|
102
+ bitmap.insert(@parts[y * @parts_x + x].to_bitmap, x * @part_width, y * @part_height)
103
+ end
104
+ end
105
+ bitmap
106
+ end
107
+
108
+ def insert(bitmap, at_x, at_y)
109
+ @parts_y.times do |y|
110
+ @parts_x.times do |x|
111
+ @parts[y * @parts_x + x].insert(bitmap, at_x - x* @part_width, at_y -y * part_height)
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,5 @@
1
+ module Gosu
2
+ java_import 'gosu.java.RenderState'
3
+ java_import 'gosu.java.RenderStateManager'
4
+ end
5
+
@@ -0,0 +1,68 @@
1
+ require 'gosu_android/graphics/imageData'
2
+ require 'gosu_android/graphics/common'
3
+
4
+ module Gosu
5
+ class TexChunk < ImageData
6
+ def initialize(graphics, queues, texture, x, y, w, h, padding)
7
+ #Define object destructor
8
+ ObjectSpace.define_finalizer(self,
9
+ self.class.method(:finalize).to_proc)
10
+ @graphics = graphics
11
+ @queues = queues
12
+ @texture = texture
13
+ @x = x
14
+ @y = y
15
+ @w = w
16
+ @h = h
17
+ @padding = padding
18
+ @info = GLTexInfo.new
19
+ @info.tex_name = @texture.tex_name
20
+ #Force float division
21
+ @info.left = @x.to_f / @texture.size
22
+ @info.top = @y.to_f / @texture.size
23
+ @info.right = (@x.to_f + @w) / @texture.size
24
+ @info.bottom = (@y.to_f + @h) / @texture.size
25
+ end
26
+
27
+ def TexChunk.finalize(id)
28
+ @texture.free(@x - @padding, @y - @padding)
29
+ end
30
+
31
+ def width
32
+ @w
33
+ end
34
+
35
+ def height
36
+ @h
37
+ end
38
+
39
+ def draw( x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z, mode)
40
+ op = @queues.op_pool.newDrawOp
41
+ op.render_state.tex_name = @info.tex_name
42
+ op.render_state.mode = mode
43
+
44
+ if Gosu::reorder_coordinates_if_necessary(x1, y1, x2, y2, x3, y3, c3, x4, y4, c4)
45
+ x3, y3, c3, x4, y4, c4 = x4, y4,c4, x3, y3, c3
46
+ end
47
+ op.vertices_or_block_index = 4
48
+ op.vertices[0].set(x1, y1, c1)
49
+ op.vertices[1].set(x2, y2, c2)
50
+ op.vertices[2].set(x3, y3, c3)
51
+ op.vertices[3].set(x4, y4, c4)
52
+
53
+ op.left = @info.left
54
+ op.top = @info.top
55
+ op.right = @info.right
56
+ op.bottom = @info.bottom
57
+
58
+ op.z = z
59
+ @queues.schedule_draw_op(op)
60
+ end
61
+
62
+ def glTexInfo
63
+ @info
64
+ end
65
+
66
+ def to_bitmap; end
67
+ end
68
+ end
@@ -0,0 +1,86 @@
1
+ require 'gosu_android/graphics/blockAllocator'
2
+ require 'gosu_android/graphics/texChunk'
3
+ require 'gosu_android/requires'
4
+
5
+ module Gosu
6
+ class Texture
7
+
8
+ def initialize(size, gl)
9
+ #Set finalize
10
+ ObjectSpace.define_finalizer(self,
11
+ self.class.method(:finalize).to_proc)
12
+ @size = size
13
+ @allocator = BlockAllocator.new(@size, @size)
14
+ @num = 0
15
+ @gl = gl
16
+ @name = [0].to_java(:int)
17
+ @gl.glGenTextures(1, @name, 0)
18
+ if @name[0] == -1
19
+ raise "Couldn't create OpenGL texture"
20
+ end
21
+ @gl.glBindTexture(JavaImports::GL10::GL_TEXTURE_2D, @name[0])
22
+
23
+ @gl.glTexImage2D(JavaImports::GL10::GL_TEXTURE_2D, 0, JavaImports::GL10::GL_RGBA, @allocator.width,
24
+ @allocator.height, 0, JavaImports::GL10::GL_RGBA, JavaImports::GL10::GL_UNSIGNED_BYTE, nil)
25
+ =begin
26
+ #TODO Should create an empty texture to be filled later
27
+ pixel = [0]
28
+ pbb = JavaImports::ByteBuffer.allocateDirect(pixel.length*4)
29
+ pbb.order(JavaImports::ByteOrder.nativeOrder)
30
+ pixel_buffer = pbb.asIntBuffer
31
+ pixel_buffer.put(pixel.to_java(:int))
32
+ pixel_buffer.position(0)
33
+ JavaImports::GLUtils.texImage2D(JavaImports::GL10::GL_TEXTURE_2D, 0, 4, @allocator.width, @allocator.height, 0,
34
+ JavaImports::GL10::GL_RGBA, JavaImports::GL10::GL_UNSIGNED_BYTE, pixel_buffer)
35
+
36
+ @gl.glTexImage2D(JavaImports::GL10::GL_TEXTURE_2D, 0, 4, @allocator.width, @allocator.height, 0,
37
+ JavaImports::GL10::GL_RGBA, JavaImports::GL10::GL_UNSIGNED_BYTE, pixel_buffer)
38
+
39
+ @gl.glTexParameterf(JavaImports::GL10::GL_TEXTURE_2D,
40
+ JavaImports::GL10::GL_TEXTURE_MIN_FILTER, JavaImports::GL10::GL_LINEAR)
41
+ @gl.glTexParameteri(JavaImports::GL10::GL_TEXTURE_2D,
42
+ JavaImports::GL10::GL_TEXTURE_WRAP_S, JavaImports::GL10::GL_CLAMP_TO_EDGE)
43
+ @gl.glTexParameteri(JavaImports::GL10::GL_TEXTURE_2D,
44
+ JavaImports::GL10::GL_TEXTURE_WRAP_T, JavaImports::GL10::GL_CLAMP_TO_EDGE)
45
+ =end
46
+ @gl.glTexParameterf(JavaImports::GL10::GL_TEXTURE_2D, JavaImports::GL10::GL_TEXTURE_MIN_FILTER, JavaImports::GL10::GL_NEAREST)
47
+ @gl.glTexParameterf(JavaImports::GL10::GL_TEXTURE_2D, JavaImports::GL10::GL_TEXTURE_MAG_FILTER, JavaImports::GL10::GL_LINEAR)
48
+ end
49
+
50
+ def Texture.finalize(id)
51
+ @gl.glDeleteTextures(1, @name)
52
+ end
53
+
54
+ def tex_name
55
+ @name[0]
56
+ end
57
+
58
+ def size
59
+ @allocator.width
60
+ end
61
+
62
+ def try_alloc(graphics, queues, ptr, bmp, padding)
63
+ alloc_info = @allocator.alloc(bmp.width, bmp.height)
64
+ if (not alloc_info[0])
65
+ return nil
66
+ end
67
+ block = alloc_info[1]
68
+ result = TexChunk.new(graphics, queues, ptr, block.left + padding, block.top + padding,
69
+ block.width - 2 * padding, block.height - 2 * padding, padding)
70
+
71
+ @gl.glTexSubImage2D(JavaImports::GL10::GL_TEXTURE_2D, 0, block.left, block.top, block.width, block.height,
72
+ Color::GL_FORMAT, JavaImports::GL10::GL_UNSIGNED_BYTE, bmp.data_java)
73
+ #@gl.glBindTexture(JavaImports::GL10::GL_TEXTURE_2D, @name[0])
74
+ #JavaImports::GLUtils.texImage2D(JavaImports::GL10::GL_TEXTURE_2D, 0, bmp.to_open_gl, 0)
75
+
76
+ @num += 1
77
+ result
78
+ end
79
+
80
+ def free(x, y)
81
+ @allocator.free(x, y)
82
+ @num -= 1
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,128 @@
1
+ require 'gosu_android/requires'
2
+
3
+
4
+ module Gosu
5
+ Kb0 = JavaImports::KeyEvent::KEYCODE_0
6
+ Kb1 = JavaImports::KeyEvent::KEYCODE_1
7
+ Kb2 = JavaImports::KeyEvent::KEYCODE_2
8
+ Kb3 = JavaImports::KeyEvent::KEYCODE_3
9
+ Kb4 = JavaImports::KeyEvent::KEYCODE_4
10
+ Kb5 = JavaImports::KeyEvent::KEYCODE_5
11
+ Kb6 = JavaImports::KeyEvent::KEYCODE_6
12
+ Kb7 = JavaImports::KeyEvent::KEYCODE_7
13
+ Kb8 = JavaImports::KeyEvent::KEYCODE_8
14
+ Kb9 = JavaImports::KeyEvent::KEYCODE_9
15
+ KbA = JavaImports::KeyEvent::KEYCODE_A
16
+ KbB = JavaImports::KeyEvent::KEYCODE_B
17
+ KbC = JavaImports::KeyEvent::KEYCODE_C
18
+ KbD = JavaImports::KeyEvent::KEYCODE_D
19
+ KbE = JavaImports::KeyEvent::KEYCODE_E
20
+ KbF = JavaImports::KeyEvent::KEYCODE_F
21
+ KbG = JavaImports::KeyEvent::KEYCODE_G
22
+ KbH = JavaImports::KeyEvent::KEYCODE_H
23
+ KbI = JavaImports::KeyEvent::KEYCODE_I
24
+ KbJ = JavaImports::KeyEvent::KEYCODE_J
25
+ KbK = JavaImports::KeyEvent::KEYCODE_K
26
+ KbL = JavaImports::KeyEvent::KEYCODE_L
27
+ KbM = JavaImports::KeyEvent::KEYCODE_M
28
+ KbN = JavaImports::KeyEvent::KEYCODE_N
29
+ KbO = JavaImports::KeyEvent::KEYCODE_O
30
+ KbP = JavaImports::KeyEvent::KEYCODE_P
31
+ KbQ = JavaImports::KeyEvent::KEYCODE_Q
32
+ KbR = JavaImports::KeyEvent::KEYCODE_R
33
+ KbS = JavaImports::KeyEvent::KEYCODE_S
34
+ KbT = JavaImports::KeyEvent::KEYCODE_T
35
+ KbU = JavaImports::KeyEvent::KEYCODE_U
36
+ KbV = JavaImports::KeyEvent::KEYCODE_V
37
+ KbW = JavaImports::KeyEvent::KEYCODE_W
38
+ KbX = JavaImports::KeyEvent::KEYCODE_X
39
+ KbY = JavaImports::KeyEvent::KEYCODE_Y
40
+ KbZ = JavaImports::KeyEvent::KEYCODE_Z
41
+ KbBackspace = JavaImports::KeyEvent::KEYCODE_DEL
42
+ KbDelete = JavaImports::KeyEvent::KEYCODE_DEL
43
+ KbDown = JavaImports::KeyEvent::KEYCODE_DPAD_DOWN
44
+ # On Numpad
45
+ KbHome = JavaImports::KeyEvent::KEYCODE_HOME
46
+ KbLeft = JavaImports::KeyEvent::KEYCODE_DPAD_LEFT
47
+ KbLeftAlt = JavaImports::KeyEvent::KEYCODE_ALT_LEFT
48
+ KbLeftShift = JavaImports::KeyEvent::KEYCODE_SHIFT_LEFT
49
+ KbPageDown = JavaImports::KeyEvent::KEYCODE_PAGE_DOWN
50
+ KbPageUp = JavaImports::KeyEvent::KEYCODE_PAGE_UP
51
+ # Above the right shift key
52
+ KbReturn = JavaImports::KeyEvent::KEYCODE_ENTER
53
+ KbRight = JavaImports::KeyEvent::KEYCODE_DPAD_RIGHT
54
+ KbRightAlt = JavaImports::KeyEvent::KEYCODE_ALT_RIGHT
55
+ #KbRightControl = JavaImports::KeyEvent::KEYCODE_CTRL_RIGHT
56
+ KbRightShift = JavaImports::KeyEvent::KEYCODE_SHIFT_RIGHT
57
+ KbSpace = JavaImports::KeyEvent::KEYCODE_SPACE
58
+ KbTab = JavaImports::KeyEvent::KEYCODE_TAB
59
+ KbUp = JavaImports::KeyEvent::KEYCODE_DPAD_UP
60
+ #TODO Fix mouse buttons, Mouse access to motion event
61
+ #MsLeft = JavaImports::MotionEvent::BUTTON_PRIMARY
62
+ #MsMiddle = JavaImports::MotionEvent::BUTTON_TERTIARY
63
+ #MsRight = JavaImports::MotionEvent::BUTTON_SECONDARY
64
+ #TODO Axis wheel is not right
65
+ #MsWheelDown = JavaImports::MotionEvent::AXIS_WHEEL
66
+ #MsWheelUp = JavaImports::MotionEvent::AXIS_WHEEL
67
+ NoButton = 0xffffffff
68
+ #Not Supported GpDown, GpLeft, GpRight, GpUp
69
+
70
+ #Load supported buttons on android above 3.0.0
71
+ if android.os.Build::VERSION::SDK_INT >= 11
72
+ KbEnd = JavaImports::KeyEvent::KEYCODE_MOVE_END
73
+ # On Numpad
74
+ KbEnter = JavaImports::KeyEvent::KEYCODE_NUMPAD_ENTER
75
+ KbEscape = JavaImports::KeyEvent::KEYCODE_ESCAPE
76
+ KbF1 = JavaImports::KeyEvent::KEYCODE_F1
77
+ KbF10 = JavaImports::KeyEvent::KEYCODE_F10
78
+ KbF11 = JavaImports::KeyEvent::KEYCODE_F11
79
+ KbF12 = JavaImports::KeyEvent::KEYCODE_F12
80
+ KbF2 = JavaImports::KeyEvent::KEYCODE_F2
81
+ KbF3 = JavaImports::KeyEvent::KEYCODE_F3
82
+ KbF4 = JavaImports::KeyEvent::KEYCODE_F4
83
+ KbF5 = JavaImports::KeyEvent::KEYCODE_F5
84
+ KbF6 = JavaImports::KeyEvent::KEYCODE_F6
85
+ KbF7 = JavaImports::KeyEvent::KEYCODE_F7
86
+ KbF8 = JavaImports::KeyEvent::KEYCODE_F8
87
+ KbF9 = JavaImports::KeyEvent::KEYCODE_F9
88
+ KbInsert = JavaImports::KeyEvent::KEYCODE_INSERT
89
+ KbLeftControl = JavaImports::KeyEvent::KEYCODE_CTRL_LEFT
90
+ KbNumpad0 = JavaImports::KeyEvent::KEYCODE_NUMPAD_0
91
+ KbNumpad1 = JavaImports::KeyEvent::KEYCODE_NUMPAD_1
92
+ KbNumpad2 = JavaImports::KeyEvent::KEYCODE_NUMPAD_2
93
+ KbNumpad3 = JavaImports::KeyEvent::KEYCODE_NUMPAD_3
94
+ KbNumpad4 = JavaImports::KeyEvent::KEYCODE_NUMPAD_4
95
+ KbNumpad5 = JavaImports::KeyEvent::KEYCODE_NUMPAD_5
96
+ KbNumpad6 = JavaImports::KeyEvent::KEYCODE_NUMPAD_6
97
+ KbNumpad7 = JavaImports::KeyEvent::KEYCODE_NUMPAD_7
98
+ KbNumpad8 = JavaImports::KeyEvent::KEYCODE_NUMPAD_8
99
+ KbNumpad9 = JavaImports::KeyEvent::KEYCODE_NUMPAD_9
100
+ KbNumpadAdd = JavaImports::KeyEvent::KEYCODE_NUMPAD_ADD
101
+ KbNumpadDivide = JavaImports::KeyEvent::KEYCODE_NUMPAD_DIVIDE
102
+ KbNumpadMultiply = JavaImports::KeyEvent::KEYCODE_NUMPAD_MULTIPLY
103
+ KbNumpadSubtract = JavaImports::KeyEvent::KEYCODE_NUMPAD_SUBTRACT
104
+ # Above the right shift key
105
+ KbRightControl = JavaImports::KeyEvent::KEYCODE_CTRL_RIGHT
106
+ end
107
+
108
+ #Load supported buttons on android above 4.0.0
109
+ if android.os.Build::VERSION::SDK_INT >= 15
110
+ Game pad
111
+ GpButton0 = JavaImports::KeyEvent::KEYCODE_BUTTON_1
112
+ GpButton1 = JavaImports::KeyEvent::KEYCODE_BUTTON_2
113
+ GpButton10 = JavaImports::KeyEvent::KEYCODE_BUTTON_11
114
+ GpButton11 = JavaImports::KeyEvent::KEYCODE_BUTTON_12
115
+ GpButton12 = JavaImports::KeyEvent::KEYCODE_BUTTON_13
116
+ GpButton13 = JavaImports::KeyEvent::KEYCODE_BUTTON_14
117
+ GpButton14 = JavaImports::KeyEvent::KEYCODE_BUTTON_15
118
+ GpButton15 = JavaImports::KeyEvent::KEYCODE_BUTTON_16
119
+ GpButton2 = JavaImports::KeyEvent::KEYCODE_BUTTON_3
120
+ GpButton3 = JavaImports::KeyEvent::KEYCODE_BUTTON_4
121
+ GpButton4 = JavaImports::KeyEvent::KEYCODE_BUTTON_5
122
+ GpButton5 = JavaImports::KeyEvent::KEYCODE_BUTTON_6
123
+ GpButton6 = JavaImports::KeyEvent::KEYCODE_BUTTON_7
124
+ GpButton7 = JavaImports::KeyEvent::KEYCODE_BUTTON_8
125
+ GpButton8 = JavaImports::KeyEvent::KEYCODE_BUTTON_9
126
+ GpButton9 = JavaImports::KeyEvent::KEYCODE_BUTTON_10
127
+ end
128
+ end
@@ -0,0 +1,120 @@
1
+ require 'gosu_android/input/buttons'
2
+
3
+ module Gosu
4
+ class Button
5
+ attr_reader :id
6
+ def initialize(*args)
7
+ case args.length
8
+ when 0
9
+ @id = NoButton
10
+ when 1
11
+ @id = args[0]
12
+ else
13
+ raise ArgumentError
14
+ end
15
+ end
16
+
17
+ # Tests whether two Buttons identify the same physical button.
18
+ def == other
19
+ self.id == other.id
20
+ end
21
+
22
+ def > other
23
+ self.id > other.id
24
+ end
25
+
26
+ def < other
27
+ self.id < other.id
28
+ end
29
+ end
30
+
31
+ # Struct that saves information about a touch on the surface of a multi-
32
+ # touch device.
33
+ class Touch < Struct.new(:id, :x, :y); end
34
+
35
+
36
+ # Manages initialization and shutdown of the input system. Only one Input
37
+ # instance can exist per application.
38
+ class Input
39
+
40
+ def initialize(display, window)
41
+ @display = display
42
+ @window = window
43
+ @touch_event_list = []
44
+ @key_event_list = []
45
+ @id = 0
46
+ end
47
+
48
+ def feed_touch_event(event)
49
+ @touch_event_list.push event
50
+ end
51
+
52
+ def feed_key_event(keyCode, event)
53
+ @key_event_list.push [keyCode, event]
54
+ end
55
+
56
+ # Returns the character a button usually produces, or 0.
57
+ def id_to_char(btn); end
58
+
59
+ # Returns the button that has to be pressed to produce the
60
+ # given character, or noButton.
61
+ def char_to_id(ch); end
62
+
63
+ # Returns true if a button is currently pressed.
64
+ # Updated every tick.
65
+ def down(btn); end
66
+
67
+ # Returns the horizontal position of the mouse relative to the top
68
+ # left corner of the window given to Input's constructor.
69
+ def mouseX; end
70
+
71
+ # Returns true if a button is currently pressed.
72
+ # Updated every tick.
73
+ def mouseY; end
74
+
75
+ # Immediately moves the mouse as far towards the desired position
76
+ # as possible. x and y are relative to the window just as in the mouse
77
+ # position accessors.
78
+ def set_mouse_position(x, y); end
79
+
80
+ # Undocumented for the moment. Also applies to currentTouches().
81
+ def set_mouse_factors(factorX, factorY); end
82
+
83
+ # Currently known touches.
84
+ def currentTouches; end
85
+
86
+ # Accelerometer positions in all three dimensions (smoothened).
87
+ def accelerometerX; end
88
+ def accelerometerY; end
89
+ def accelerometerZ; end
90
+
91
+ # Collects new information about which buttons are pressed, where the
92
+ # mouse is and calls onButtonUp/onButtonDown, if assigned.
93
+ def update
94
+ @touch_event_list.each do |touch_event|
95
+ touch_event.getPointerCount.times do |index|
96
+ touch = Touch.new(touch_event. getPointerId(index), touch_event.getX(index), touch_event.getY(index))
97
+ case touch_event.getAction
98
+ when JavaImports::MotionEvent::ACTION_DOWN
99
+ @window.touch_began(touch)
100
+ when JavaImports::MotionEvent::ACTION_MOVE
101
+ @window.touch_moved(touch)
102
+ when JavaImports::MotionEvent::ACTION_UP
103
+ @window.touch_ended(touch)
104
+ end
105
+ end
106
+ end
107
+ @touch_event_list = []
108
+ end
109
+
110
+ # Assignable events that are called by update. You can bind these to your own functions.
111
+ # If you use the Window class, it will assign forward these to its own methods.
112
+ def button_down; end
113
+ def button_up; end
114
+
115
+ # Returns the currently active TextInput instance, or 0.
116
+ def text_input; end
117
+ # Sets the currently active TextInput, or clears it (input = 0).
118
+ def set_text_input(input); end
119
+ end
120
+ end