rubygame 2.2.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/CREDITS +60 -0
  2. data/LICENSE +504 -0
  3. data/NEWS +201 -0
  4. data/README +139 -0
  5. data/ROADMAP +43 -0
  6. data/Rakefile +409 -0
  7. data/doc/extended_readme.rdoc +49 -0
  8. data/doc/getting_started.rdoc +47 -0
  9. data/doc/macosx_install.rdoc +70 -0
  10. data/doc/windows_install.rdoc +127 -0
  11. data/ext/rubygame/MANIFEST +25 -0
  12. data/ext/rubygame/rubygame_core.so +0 -0
  13. data/ext/rubygame/rubygame_event.c +644 -0
  14. data/ext/rubygame/rubygame_event.h +48 -0
  15. data/ext/rubygame/rubygame_event.obj +0 -0
  16. data/ext/rubygame/rubygame_gfx.c +942 -0
  17. data/ext/rubygame/rubygame_gfx.h +101 -0
  18. data/ext/rubygame/rubygame_gfx.obj +0 -0
  19. data/ext/rubygame/rubygame_gfx.so +0 -0
  20. data/ext/rubygame/rubygame_gl.c +154 -0
  21. data/ext/rubygame/rubygame_gl.h +32 -0
  22. data/ext/rubygame/rubygame_gl.obj +0 -0
  23. data/ext/rubygame/rubygame_image.c +108 -0
  24. data/ext/rubygame/rubygame_image.h +41 -0
  25. data/ext/rubygame/rubygame_image.obj +0 -0
  26. data/ext/rubygame/rubygame_image.so +0 -0
  27. data/ext/rubygame/rubygame_joystick.c +247 -0
  28. data/ext/rubygame/rubygame_joystick.h +41 -0
  29. data/ext/rubygame/rubygame_joystick.obj +0 -0
  30. data/ext/rubygame/rubygame_main.c +155 -0
  31. data/ext/rubygame/rubygame_main.h +33 -0
  32. data/ext/rubygame/rubygame_main.obj +0 -0
  33. data/ext/rubygame/rubygame_mixer.c +764 -0
  34. data/ext/rubygame/rubygame_mixer.h +62 -0
  35. data/ext/rubygame/rubygame_mixer.obj +0 -0
  36. data/ext/rubygame/rubygame_mixer.so +0 -0
  37. data/ext/rubygame/rubygame_screen.c +448 -0
  38. data/ext/rubygame/rubygame_screen.h +43 -0
  39. data/ext/rubygame/rubygame_screen.obj +0 -0
  40. data/ext/rubygame/rubygame_shared.c +209 -0
  41. data/ext/rubygame/rubygame_shared.h +60 -0
  42. data/ext/rubygame/rubygame_shared.obj +0 -0
  43. data/ext/rubygame/rubygame_surface.c +1147 -0
  44. data/ext/rubygame/rubygame_surface.h +62 -0
  45. data/ext/rubygame/rubygame_surface.obj +0 -0
  46. data/ext/rubygame/rubygame_time.c +183 -0
  47. data/ext/rubygame/rubygame_time.h +32 -0
  48. data/ext/rubygame/rubygame_time.obj +0 -0
  49. data/ext/rubygame/rubygame_ttf.c +599 -0
  50. data/ext/rubygame/rubygame_ttf.h +69 -0
  51. data/ext/rubygame/rubygame_ttf.obj +0 -0
  52. data/ext/rubygame/rubygame_ttf.so +0 -0
  53. data/lib/rubygame.rb +41 -0
  54. data/lib/rubygame/MANIFEST +12 -0
  55. data/lib/rubygame/clock.rb +128 -0
  56. data/lib/rubygame/color.rb +79 -0
  57. data/lib/rubygame/color/models/base.rb +106 -0
  58. data/lib/rubygame/color/models/hsl.rb +153 -0
  59. data/lib/rubygame/color/models/hsv.rb +149 -0
  60. data/lib/rubygame/color/models/rgb.rb +78 -0
  61. data/lib/rubygame/color/palettes/css.rb +49 -0
  62. data/lib/rubygame/color/palettes/palette.rb +100 -0
  63. data/lib/rubygame/color/palettes/x11.rb +177 -0
  64. data/lib/rubygame/constants.rb +238 -0
  65. data/lib/rubygame/event.rb +313 -0
  66. data/lib/rubygame/ftor.rb +370 -0
  67. data/lib/rubygame/hotspot.rb +265 -0
  68. data/lib/rubygame/keyconstants.rb +237 -0
  69. data/lib/rubygame/mediabag.rb +94 -0
  70. data/lib/rubygame/queue.rb +288 -0
  71. data/lib/rubygame/rect.rb +612 -0
  72. data/lib/rubygame/sfont.rb +223 -0
  73. data/lib/rubygame/sprite.rb +511 -0
  74. data/samples/FreeSans.ttf +0 -0
  75. data/samples/GPL.txt +340 -0
  76. data/samples/README +40 -0
  77. data/samples/chimp.bmp +0 -0
  78. data/samples/chimp.rb +313 -0
  79. data/samples/demo_gl.rb +151 -0
  80. data/samples/demo_gl_tex.rb +197 -0
  81. data/samples/demo_music.rb +75 -0
  82. data/samples/demo_rubygame.rb +284 -0
  83. data/samples/demo_sfont.rb +52 -0
  84. data/samples/demo_ttf.rb +193 -0
  85. data/samples/demo_utf8.rb +53 -0
  86. data/samples/fist.bmp +0 -0
  87. data/samples/load_and_blit.rb +22 -0
  88. data/samples/panda.png +0 -0
  89. data/samples/punch.wav +0 -0
  90. data/samples/ruby.png +0 -0
  91. data/samples/song.ogg +0 -0
  92. data/samples/term16.png +0 -0
  93. data/samples/whiff.wav +0 -0
  94. metadata +152 -0
@@ -0,0 +1,177 @@
1
+ #--
2
+ # Rubygame -- Ruby code and bindings to SDL to facilitate game creation
3
+ # Copyright (C) 2007 John Croisant
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ #++
19
+
20
+ require 'rubygame/color'
21
+ require 'rubygame/color/palettes/palette'
22
+
23
+ module Rubygame
24
+ module Color
25
+
26
+ # :enddoc:
27
+
28
+ # The X11 module contains all the colors in the X11 palette
29
+ # by symbol name, e.g. :alice_blue, :dark_olive_green, etc.
30
+ #
31
+ # The list of colors is derived from
32
+ # http://en.wikipedia.org/wiki/X11_color_names
33
+ # as accessed on 2007-12-17.
34
+ X11 = Palette.new({
35
+ :alice_blue => ColorRGB.new( [0.94117, 0.97254, 1.00000] ),
36
+ :antique_white => ColorRGB.new( [0.98039, 0.92156, 0.84313] ),
37
+ :aqua => ColorRGB.new( [0.00000, 1.00000, 1.00000] ),
38
+ :aquamarine => ColorRGB.new( [0.49803, 1.00000, 0.83137] ),
39
+ :azure => ColorRGB.new( [0.94117, 1.00000, 1.00000] ),
40
+ :beige => ColorRGB.new( [0.96078, 0.96078, 0.86274] ),
41
+ :bisque => ColorRGB.new( [1.00000, 0.89411, 0.76862] ),
42
+ :black => ColorRGB.new( [0.00000, 0.00000, 0.00000] ),
43
+ :blanched_almond => ColorRGB.new( [1.00000, 0.92156, 0.80392] ),
44
+ :blue => ColorRGB.new( [0.00000, 0.00000, 1.00000] ),
45
+ :blue_violet => ColorRGB.new( [0.54117, 0.16862, 0.88627] ),
46
+ :brown => ColorRGB.new( [0.64705, 0.16470, 0.16470] ),
47
+ :burly_wood => ColorRGB.new( [0.87058, 0.72156, 0.52941] ),
48
+ :cadet_blue => ColorRGB.new( [0.37254, 0.61960, 0.62745] ),
49
+ :chartreuse => ColorRGB.new( [0.49803, 1.00000, 0.00000] ),
50
+ :chocolate => ColorRGB.new( [0.82352, 0.41176, 0.11764] ),
51
+ :coral => ColorRGB.new( [1.00000, 0.49803, 0.31372] ),
52
+ :cornflower_blue => ColorRGB.new( [0.39215, 0.58431, 0.92941] ),
53
+ :cornsilk => ColorRGB.new( [1.00000, 0.97254, 0.86274] ),
54
+ :crimson => ColorRGB.new( [0.86274, 0.07843, 0.23529] ),
55
+ :cyan => ColorRGB.new( [0.00000, 1.00000, 1.00000] ),
56
+ :dark_blue => ColorRGB.new( [0.00000, 0.00000, 0.54509] ),
57
+ :dark_cyan => ColorRGB.new( [0.00000, 0.54509, 0.54509] ),
58
+ :dark_goldenrod => ColorRGB.new( [0.72156, 0.52549, 0.04313] ),
59
+ :dark_gray => ColorRGB.new( [0.66274, 0.66274, 0.66274] ),
60
+ :dark_green => ColorRGB.new( [0.00000, 0.39215, 0.00000] ),
61
+ :dark_khaki => ColorRGB.new( [0.74117, 0.71764, 0.41960] ),
62
+ :dark_magenta => ColorRGB.new( [0.54509, 0.00000, 0.54509] ),
63
+ :dark_olive_green => ColorRGB.new( [0.33333, 0.41960, 0.18431] ),
64
+ :dark_orange => ColorRGB.new( [1.00000, 0.54901, 0.00000] ),
65
+ :dark_orchid => ColorRGB.new( [0.60000, 0.19607, 0.80000] ),
66
+ :dark_red => ColorRGB.new( [0.54509, 0.00000, 0.00000] ),
67
+ :dark_salmon => ColorRGB.new( [0.91372, 0.58823, 0.47843] ),
68
+ :dark_sea_green => ColorRGB.new( [0.56078, 0.73725, 0.56078] ),
69
+ :dark_slate_blue => ColorRGB.new( [0.28235, 0.23921, 0.54509] ),
70
+ :dark_slate_gray => ColorRGB.new( [0.18431, 0.30980, 0.30980] ),
71
+ :dark_turquoise => ColorRGB.new( [0.00000, 0.80784, 0.81960] ),
72
+ :dark_violet => ColorRGB.new( [0.58039, 0.00000, 0.82745] ),
73
+ :deep_pink => ColorRGB.new( [1.00000, 0.07843, 0.57647] ),
74
+ :deep_sky_blue => ColorRGB.new( [0.00000, 0.74901, 1.00000] ),
75
+ :dim_gray => ColorRGB.new( [0.41176, 0.41176, 0.41176] ),
76
+ :dodger_blue => ColorRGB.new( [0.11764, 0.56470, 1.00000] ),
77
+ :fire_brick => ColorRGB.new( [0.69803, 0.13333, 0.13333] ),
78
+ :floral_white => ColorRGB.new( [1.00000, 0.98039, 0.94117] ),
79
+ :forest_green => ColorRGB.new( [0.13333, 0.54509, 0.13333] ),
80
+ :fuchsia => ColorRGB.new( [1.00000, 0.00000, 1.00000] ),
81
+ :gainsboro => ColorRGB.new( [0.86274, 0.86274, 0.86274] ),
82
+ :ghost_white => ColorRGB.new( [0.97254, 0.97254, 1.00000] ),
83
+ :gold => ColorRGB.new( [1.00000, 0.84313, 0.00000] ),
84
+ :goldenrod => ColorRGB.new( [0.85490, 0.64705, 0.12549] ),
85
+ :gray => ColorRGB.new( [0.50196, 0.50196, 0.50196] ),
86
+ :green => ColorRGB.new( [0.00000, 0.50196, 0.00000] ),
87
+ :green_yellow => ColorRGB.new( [0.67843, 1.00000, 0.18431] ),
88
+ :honeydew => ColorRGB.new( [0.94117, 1.00000, 0.94117] ),
89
+ :hot_pink => ColorRGB.new( [1.00000, 0.41176, 0.70588] ),
90
+ :indian_red => ColorRGB.new( [0.80392, 0.36078, 0.36078] ),
91
+ :indigo => ColorRGB.new( [0.29411, 0.00000, 0.50980] ),
92
+ :ivory => ColorRGB.new( [1.00000, 1.00000, 0.94117] ),
93
+ :khaki => ColorRGB.new( [0.94117, 0.90196, 0.54901] ),
94
+ :lavender => ColorRGB.new( [0.90196, 0.90196, 0.98039] ),
95
+ :lavender_blush => ColorRGB.new( [1.00000, 0.94117, 0.96078] ),
96
+ :lawn_green => ColorRGB.new( [0.48627, 0.98823, 0.00000] ),
97
+ :lemon_chiffon => ColorRGB.new( [1.00000, 0.98039, 0.80392] ),
98
+ :light_blue => ColorRGB.new( [0.67843, 0.84705, 0.90196] ),
99
+ :light_coral => ColorRGB.new( [0.94117, 0.50196, 0.50196] ),
100
+ :light_cyan => ColorRGB.new( [0.87843, 1.00000, 1.00000] ),
101
+ :light_goldenrod_yellow => ColorRGB.new( [0.98039, 0.98039, 0.82352] ),
102
+ :light_green => ColorRGB.new( [0.56470, 0.93333, 0.56470] ),
103
+ :light_grey => ColorRGB.new( [0.82745, 0.82745, 0.82745] ),
104
+ :light_pink => ColorRGB.new( [1.00000, 0.71372, 0.75686] ),
105
+ :light_salmon => ColorRGB.new( [1.00000, 0.62745, 0.47843] ),
106
+ :light_sea_green => ColorRGB.new( [0.12549, 0.69803, 0.66666] ),
107
+ :light_sky_blue => ColorRGB.new( [0.52941, 0.80784, 0.98039] ),
108
+ :light_slate_gray => ColorRGB.new( [0.46666, 0.53333, 0.60000] ),
109
+ :light_steel_blue => ColorRGB.new( [0.69019, 0.76862, 0.87058] ),
110
+ :light_yellow => ColorRGB.new( [1.00000, 1.00000, 0.87843] ),
111
+ :lime => ColorRGB.new( [0.00000, 1.00000, 0.00000] ),
112
+ :lime_green => ColorRGB.new( [0.19607, 0.80392, 0.19607] ),
113
+ :linen => ColorRGB.new( [0.98039, 0.94117, 0.90196] ),
114
+ :magenta => ColorRGB.new( [1.00000, 0.00000, 1.00000] ),
115
+ :maroon => ColorRGB.new( [0.50196, 0.00000, 0.00000] ),
116
+ :medium_aquamarine => ColorRGB.new( [0.40000, 0.80392, 0.66666] ),
117
+ :medium_blue => ColorRGB.new( [0.00000, 0.00000, 0.80392] ),
118
+ :medium_orchid => ColorRGB.new( [0.72941, 0.33333, 0.82745] ),
119
+ :medium_purple => ColorRGB.new( [0.57647, 0.43921, 0.85882] ),
120
+ :medium_sea_green => ColorRGB.new( [0.23529, 0.70196, 0.44313] ),
121
+ :medium_slate_blue => ColorRGB.new( [0.48235, 0.40784, 0.93333] ),
122
+ :medium_spring_green => ColorRGB.new( [0.00000, 0.98039, 0.60392] ),
123
+ :medium_turquoise => ColorRGB.new( [0.28235, 0.81960, 0.80000] ),
124
+ :medium_violet_red => ColorRGB.new( [0.78039, 0.08235, 0.52156] ),
125
+ :midnight_blue => ColorRGB.new( [0.09803, 0.09803, 0.43921] ),
126
+ :mint_cream => ColorRGB.new( [0.96078, 1.00000, 0.98039] ),
127
+ :misty_rose => ColorRGB.new( [1.00000, 0.89411, 0.88235] ),
128
+ :moccasin => ColorRGB.new( [1.00000, 0.89411, 0.70980] ),
129
+ :navajo_white => ColorRGB.new( [1.00000, 0.87058, 0.67843] ),
130
+ :navy => ColorRGB.new( [0.00000, 0.00000, 0.50196] ),
131
+ :old_lace => ColorRGB.new( [0.99215, 0.96078, 0.90196] ),
132
+ :olive => ColorRGB.new( [0.50196, 0.50196, 0.00000] ),
133
+ :olive_drab => ColorRGB.new( [0.41960, 0.55686, 0.13725] ),
134
+ :orange => ColorRGB.new( [1.00000, 0.64705, 0.00000] ),
135
+ :orange_red => ColorRGB.new( [1.00000, 0.27058, 0.00000] ),
136
+ :orchid => ColorRGB.new( [0.85490, 0.43921, 0.83921] ),
137
+ :pale_goldenrod => ColorRGB.new( [0.93333, 0.90980, 0.66666] ),
138
+ :pale_green => ColorRGB.new( [0.59607, 0.98431, 0.59607] ),
139
+ :pale_turquoise => ColorRGB.new( [0.68627, 0.93333, 0.93333] ),
140
+ :pale_violet_red => ColorRGB.new( [0.85882, 0.43921, 0.57647] ),
141
+ :papaya_whip => ColorRGB.new( [1.00000, 0.93725, 0.83529] ),
142
+ :peach_puff => ColorRGB.new( [1.00000, 0.85490, 0.72549] ),
143
+ :peru => ColorRGB.new( [0.80392, 0.52156, 0.24705] ),
144
+ :pink => ColorRGB.new( [1.00000, 0.75294, 0.79607] ),
145
+ :plum => ColorRGB.new( [0.86666, 0.62745, 0.86666] ),
146
+ :powder_blue => ColorRGB.new( [0.69019, 0.87843, 0.90196] ),
147
+ :purple => ColorRGB.new( [0.50196, 0.00000, 0.50196] ),
148
+ :red => ColorRGB.new( [1.00000, 0.00000, 0.00000] ),
149
+ :rosy_brown => ColorRGB.new( [0.73725, 0.56078, 0.56078] ),
150
+ :royal_blue => ColorRGB.new( [0.25490, 0.41176, 0.88235] ),
151
+ :saddle_brown => ColorRGB.new( [0.54509, 0.27058, 0.07450] ),
152
+ :salmon => ColorRGB.new( [0.98039, 0.50196, 0.44705] ),
153
+ :sandy_brown => ColorRGB.new( [0.95686, 0.64313, 0.37647] ),
154
+ :sea_green => ColorRGB.new( [0.18039, 0.54509, 0.34117] ),
155
+ :seashell => ColorRGB.new( [1.00000, 0.96078, 0.93333] ),
156
+ :sienna => ColorRGB.new( [0.62745, 0.32156, 0.17647] ),
157
+ :silver => ColorRGB.new( [0.75294, 0.75294, 0.75294] ),
158
+ :sky_blue => ColorRGB.new( [0.52941, 0.80784, 0.92156] ),
159
+ :slate_blue => ColorRGB.new( [0.41568, 0.35294, 0.80392] ),
160
+ :slate_gray => ColorRGB.new( [0.43921, 0.50196, 0.56470] ),
161
+ :snow => ColorRGB.new( [1.00000, 0.98039, 0.98039] ),
162
+ :spring_green => ColorRGB.new( [0.00000, 1.00000, 0.49803] ),
163
+ :steel_blue => ColorRGB.new( [0.27450, 0.50980, 0.70588] ),
164
+ :tan => ColorRGB.new( [0.82352, 0.70588, 0.54901] ),
165
+ :teal => ColorRGB.new( [0.00000, 0.50196, 0.50196] ),
166
+ :thistle => ColorRGB.new( [0.84705, 0.74901, 0.84705] ),
167
+ :tomato => ColorRGB.new( [1.00000, 0.38823, 0.27843] ),
168
+ :turquoise => ColorRGB.new( [0.25098, 0.87843, 0.81568] ),
169
+ :violet => ColorRGB.new( [0.93333, 0.50980, 0.93333] ),
170
+ :wheat => ColorRGB.new( [0.96078, 0.87058, 0.70196] ),
171
+ :white => ColorRGB.new( [1.00000, 1.00000, 1.00000] ),
172
+ :white_smoke => ColorRGB.new( [0.96078, 0.96078, 0.96078] ),
173
+ :yellow => ColorRGB.new( [1.00000, 1.00000, 0.00000] ),
174
+ :yellow_green => ColorRGB.new( [0.60392, 0.80392, 0.19607] )
175
+ })
176
+ end
177
+ end
@@ -0,0 +1,238 @@
1
+ #--
2
+ # Rubygame -- Ruby code and bindings to SDL to facilitate game creation
3
+ # Copyright (C) 2004-2007 John Croisant
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ #++
19
+
20
+ module Rubygame
21
+
22
+ module Mouse
23
+ # Hash to translate mouse button sym to string
24
+ MOUSE2STR = {
25
+ MOUSE_LEFT => "left",
26
+ MOUSE_MIDDLE => "middle",
27
+ MOUSE_RIGHT => "right"
28
+ }
29
+ # And to translate the other way...
30
+ STR2MOUSE = MOUSE2STR.invert()
31
+ # And allow numbers too (1 = left, so on)...
32
+ STR2MOUSE[1] = MOUSE_LEFT
33
+ STR2MOUSE[2] = MOUSE_MIDDLE
34
+ STR2MOUSE[3] = MOUSE_RIGHT
35
+ end # module Mouse
36
+
37
+ module Key
38
+ # All the keys which have ASCII print values
39
+ # It is 87 lines from here to the closing }, if you want to skip it...
40
+ KEY2ASCII = {
41
+ K_BACKSPACE => "\b",
42
+ K_TAB => "\t",
43
+ K_RETURN => "\n", #SDL docs: "\r". Win vs *nix? What about Mac?
44
+ K_ESCAPE => "^[",
45
+ K_SPACE => " ",
46
+ K_EXCLAIM => "!",
47
+ K_QUOTEDBL => "\"",
48
+ K_HASH => "#",
49
+ K_DOLLAR => "$",
50
+ K_AMPERSAND => "&",
51
+ K_QUOTE => "\'",
52
+ K_LEFTPAREN => "(",
53
+ K_RIGHTPAREN => ")",
54
+ K_ASTERISK => "*",
55
+ K_PLUS => "+",
56
+ K_COMMA => ",",
57
+ K_MINUS => "-",
58
+ K_PERIOD => ".",
59
+ K_SLASH => "/",
60
+ K_0 => "0",
61
+ K_1 => "1",
62
+ K_2 => "2",
63
+ K_3 => "3",
64
+ K_4 => "4",
65
+ K_5 => "5",
66
+ K_6 => "6",
67
+ K_7 => "7",
68
+ K_8 => "8",
69
+ K_9 => "9",
70
+ K_COLON => ":",
71
+ K_SEMICOLON => ";",
72
+ K_LESS => "<",
73
+ K_EQUALS => "=",
74
+ K_GREATER => ">",
75
+ K_QUESTION => "?",
76
+ K_AT => "@",
77
+ K_LEFTBRACKET => "[",
78
+ K_BACKSLASH => "\\",
79
+ K_RIGHTBRACKET => "]",
80
+ K_CARET => "^",
81
+ K_UNDERSCORE => "_",
82
+ K_BACKQUOTE => "`",
83
+ K_A => "a",
84
+ K_B => "b",
85
+ K_C => "c",
86
+ K_D => "d",
87
+ K_E => "e",
88
+ K_F => "f",
89
+ K_G => "g",
90
+ K_H => "h",
91
+ K_I => "i",
92
+ K_J => "j",
93
+ K_K => "k",
94
+ K_L => "l",
95
+ K_M => "m",
96
+ K_N => "n",
97
+ K_O => "o",
98
+ K_P => "p",
99
+ K_Q => "q",
100
+ K_R => "r",
101
+ K_S => "s",
102
+ K_T => "t",
103
+ K_U => "u",
104
+ K_V => "v",
105
+ K_W => "w",
106
+ K_X => "x",
107
+ K_Y => "y",
108
+ K_Z => "z",
109
+ K_KP0 => "0",
110
+ K_KP1 => "1",
111
+ K_KP2 => "2",
112
+ K_KP3 => "3",
113
+ K_KP4 => "4",
114
+ K_KP5 => "5",
115
+ K_KP6 => "6",
116
+ K_KP7 => "7",
117
+ K_KP8 => "8",
118
+ K_KP9 => "9",
119
+ K_KP_PERIOD => ".",
120
+ K_KP_DIVIDE => "/",
121
+ K_KP_MULTIPLY => "*",
122
+ K_KP_MINUS => "-",
123
+ K_KP_PLUS => "+",
124
+ K_KP_ENTER => "\n", #again, SDL docs say "\r"
125
+ K_KP_EQUALS => "=",
126
+ }
127
+
128
+ # And to translate the other way...
129
+ ASCII2KEY = KEY2ASCII.invert()
130
+ # accept uppercase letters too, return same as lowercase version:
131
+ ("a".."z").each{ |letter| ASCII2KEY[letter.upcase] = ASCII2KEY[letter] }
132
+
133
+ # All the keys that are affected by the Shift key, in lower case
134
+ # 49 lines from here to the end of the hash
135
+ KEY2LOWER = {
136
+ K_QUOTE => "\'",
137
+ K_COMMA => ",",
138
+ K_MINUS => "-",
139
+ K_PERIOD => ".",
140
+ K_SLASH => "/",
141
+ K_0 => "0",
142
+ K_1 => "1",
143
+ K_2 => "2",
144
+ K_3 => "3",
145
+ K_4 => "4",
146
+ K_5 => "5",
147
+ K_6 => "6",
148
+ K_7 => "7",
149
+ K_8 => "8",
150
+ K_9 => "9",
151
+ K_SEMICOLON => ";",
152
+ K_EQUALS => "=",
153
+ K_LEFTBRACKET => "[",
154
+ K_BACKSLASH => "\\",
155
+ K_RIGHTBRACKET => "]",
156
+ K_BACKQUOTE => "`",
157
+ K_A => "a",
158
+ K_B => "b",
159
+ K_C => "c",
160
+ K_D => "d",
161
+ K_E => "e",
162
+ K_F => "f",
163
+ K_G => "g",
164
+ K_H => "h",
165
+ K_I => "i",
166
+ K_J => "j",
167
+ K_K => "k",
168
+ K_L => "l",
169
+ K_M => "m",
170
+ K_N => "n",
171
+ K_O => "o",
172
+ K_P => "p",
173
+ K_Q => "q",
174
+ K_R => "r",
175
+ K_S => "s",
176
+ K_T => "t",
177
+ K_U => "u",
178
+ K_V => "v",
179
+ K_W => "w",
180
+ K_X => "x",
181
+ K_Y => "y",
182
+ K_Z => "z",
183
+ }
184
+
185
+ # All the keys that are affected by the Shift key, in UPPER case
186
+ # 49 lines from here to the end of the hash
187
+ KEY2UPPER = {
188
+ K_QUOTE => "\"",
189
+ K_COMMA => "<",
190
+ K_MINUS => "_",
191
+ K_PERIOD => ">",
192
+ K_SLASH => "?",
193
+ K_0 => ")",
194
+ K_1 => "!",
195
+ K_2 => "@",
196
+ K_3 => "#",
197
+ K_4 => "$",
198
+ K_5 => "%",
199
+ K_6 => "^",
200
+ K_7 => "&",
201
+ K_8 => "*",
202
+ K_9 => "(",
203
+ K_SEMICOLON => ":",
204
+ K_EQUALS => "+",
205
+ K_LEFTBRACKET => "{",
206
+ K_BACKSLASH => "|",
207
+ K_RIGHTBRACKET => "}",
208
+ K_BACKQUOTE => "~",
209
+ K_A => "A",
210
+ K_B => "B",
211
+ K_C => "C",
212
+ K_D => "D",
213
+ K_E => "E",
214
+ K_F => "F",
215
+ K_G => "G",
216
+ K_H => "H",
217
+ K_I => "I",
218
+ K_J => "J",
219
+ K_K => "K",
220
+ K_L => "L",
221
+ K_M => "M",
222
+ K_N => "N",
223
+ K_O => "O",
224
+ K_P => "P",
225
+ K_Q => "Q",
226
+ K_R => "R",
227
+ K_S => "S",
228
+ K_T => "T",
229
+ K_U => "U",
230
+ K_V => "V",
231
+ K_W => "W",
232
+ K_X => "X",
233
+ K_Y => "Y",
234
+ K_Z => "Z",
235
+ }
236
+ end #module Key
237
+
238
+ end # module Rubygame
@@ -0,0 +1,313 @@
1
+ #--
2
+ # Rubygame -- Ruby code and bindings to SDL to facilitate game creation
3
+ # Copyright (C) 2004-2007 John Croisant
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ #++
19
+
20
+ module Rubygame
21
+
22
+ # List of all Rubygame hardware event classes. *Do not modify!*
23
+ SDL_EVENTS = [ActiveEvent, KeyDownEvent, KeyUpEvent,\
24
+ MouseMotionEvent,MouseDownEvent,MouseUpEvent,JoyAxisEvent,\
25
+ JoyBallEvent, JoyHatEvent,JoyDownEvent, JoyUpEvent,\
26
+ ResizeEvent, QuitEvent]
27
+
28
+ # Converts a keyboard symbol (keysym) into a human-readable text string.
29
+ # If either Shift key was being pressed, alphanumeric or punctuation keys
30
+ # will be made uppercase or alternate, based on U.S. keyboard layout.
31
+ # E.g. "a" becomes "A", "1" becomes "!", and "/" becomes "?".
32
+ def Rubygame.key2str( sym, mods )
33
+ if (mods.include? K_LSHIFT) or (mods.include? K_RSHIFT)
34
+ return (Rubygame::Key::KEY2UPPER[sym]\
35
+ or Rubygame::Key::KEY2ASCII[sym] or "")
36
+ else
37
+ return (Rubygame::Key::KEY2LOWER[sym]\
38
+ or Rubygame::Key::KEY2ASCII[sym] or "")
39
+ end
40
+ end
41
+
42
+ # The parent class for all event classes. You can make custom event classes,
43
+ # if desired; inheriting this class is not necessary, but makes it easier
44
+ # to check if an object is an event or not.
45
+ class Event
46
+ end
47
+
48
+ # Indicates that the Rubygame window has gained or lost focus from the
49
+ # window manager.
50
+ #
51
+ # This event has these attributes:
52
+ # gain:: true if the window gained focus, and false if it lost focus.
53
+ # state:: string indicating what type of focus was gained or lost:
54
+ # "mouse":: the mouse entered/exited the window
55
+ # "keyboard":: the window gained or lost input focus
56
+ # "active":: the window was minimized/iconified.
57
+ class ActiveEvent < Event
58
+ attr_accessor :gain, :state
59
+ def initialize(gain,state)
60
+ @gain = gain
61
+ @state = state
62
+ end
63
+ end
64
+
65
+ # Indicates that a keyboard key was pressed.
66
+ #
67
+ # This event has these attributes:
68
+ # string:: a human-readable string telling what key was pressed, or nil.
69
+ # See #key2str.
70
+ # key:: the integer keysym for the key. These can be compared with the
71
+ # K_* constants in the Rubygame module, e.g. Rubygame::K_A.
72
+ # mods:: an Array of zero or more keysyms indicating which modifier keys
73
+ # were being pressed when the key was pressed. You can compare
74
+ # with these constants in the Rubygame module:
75
+ # K_RSHIFT:: shift key (right side)
76
+ # K_LSHIFT:: shift key (left side)
77
+ # K_RCTRL:: ctrl key (right side)
78
+ # K_LCTRL:: ctrl key (left side)
79
+ # K_RALT:: alt key (right side)
80
+ # K_LALT:: alt key (left side)
81
+ # K_RMETA:: meta key (right side)
82
+ # K_LMETA:: meta key (left side)
83
+ # K_RSUPER:: super key, aka. Windows key (right side)
84
+ # K_LSUPER:: super key, aka. Windows key (left side)
85
+ # K_RALT:: alt key (right side)
86
+ # K_NUMLOCK:: num lock
87
+ # K_CAPSLOCK:: caps lock
88
+ # K_MODE:: mode key
89
+ #
90
+ #
91
+ class KeyDownEvent < Event
92
+ attr_accessor :string,:key,:mods
93
+
94
+ # Create a new KeyDownEvent.
95
+ #
96
+ # key:: either an integer keysym (e.g. Rubygame::K_A) or string (e.g. "a")
97
+ # mods:: array of modifier keysyms
98
+ def initialize(key,mods)
99
+ if key.kind_of? Integer
100
+ @key = key
101
+ @string = Rubygame.key2str(key, mods) #a string or nil
102
+ elsif key.kind_of? String
103
+ @key = Rubygame::Key::ASCII2KEY[key]
104
+ if @key != nil
105
+ @string = key
106
+ else
107
+ raise(ArgumentError,"First argument of KeyDownEvent.new() must be an Integer KeySym (like K_A) or a ASCII-like String (like \"a\" or \"A\"). Got %s (%s)"%[key,key.class])
108
+ end
109
+ end
110
+ @mods = mods
111
+ end
112
+ end
113
+
114
+ # Indicates that a keyboard key was released.
115
+ #
116
+ # See KeyDownEvent.
117
+ class KeyUpEvent < Event
118
+ attr_accessor :string,:key,:mods
119
+ def initialize(key,mods)
120
+ if key.kind_of? Integer
121
+ @key = key
122
+ @string = Rubygame.key2str(key, mods) #a string or nil
123
+ elsif key.kind_of? String
124
+ @key = Rubygame::Key::ASCII2KEY[key]
125
+ if @key != nil
126
+ @string = key
127
+ else
128
+ raise(ArgumentError,"First argument of KeyUpEvent.new() must be an Integer KeySym (like K_A) or a ASCII-like String (like \"a\" or \"A\"). Got %s (%s)"%[key,key.class])
129
+ end
130
+ end
131
+ @mods = mods
132
+ end
133
+ end
134
+
135
+ # Indicates that the mouse cursor moved.
136
+ #
137
+ # This event has these attributes:
138
+ # pos:: the new position of the cursor, in the form [x,y].
139
+ # rel:: the relative movement of the cursor since the last update, [x,y].
140
+ # buttons:: the mouse buttons that were being held during the movement,
141
+ # an Array of zero or more of these constants in module Rubygame
142
+ # (or the corresponding button number):
143
+ # MOUSE_LEFT:: 1; left mouse button
144
+ # MOUSE_MIDDLE:: 2; middle mouse button
145
+ # MOUSE_RIGHT:: 3; right mouse button
146
+ class MouseMotionEvent < Event
147
+ attr_accessor :pos,:rel,:buttons
148
+ def initialize(pos,rel,buttons)
149
+ @pos, @rel, @buttons = pos, rel, buttons
150
+ end
151
+ end
152
+
153
+ # Indicates that a mouse button was pressed.
154
+ #
155
+ # This event has these attributes:
156
+ # string:: string indicating the button that was pressed ("left","middle", or
157
+ # "right").
158
+ # pos:: the position of the mouse cursor when the button was pressed,
159
+ # in the form [x,y].
160
+ # button:: the mouse button that was pressed; one of these constants in
161
+ # module Rubygame (or the corresponding button number):
162
+ # MOUSE_LEFT:: 1; left mouse button
163
+ # MOUSE_MIDDLE:: 2; middle mouse button
164
+ # MOUSE_RIGHT:: 3; right mouse button
165
+ class MouseDownEvent < Event
166
+ attr_accessor :string,:pos,:button
167
+ def initialize(pos,button)
168
+ @pos = pos
169
+ if button.kind_of? Integer
170
+ @button = button
171
+ @string = Rubygame::Mouse::MOUSE2STR[button] #a string or nil
172
+ elsif key.kind_of? String
173
+ @button = Rubygame::Mouse::STR2MOUSE[key]
174
+ if @button != nil
175
+ @string = button
176
+ else
177
+ raise(ArgumentError,"First argument of MouseDownEvent.new() must be an Integer Mouse button indentifier (like MOUSE_LEFT) or a String (like \"left\"). Got %s (%s)"%[button,button.class])
178
+ end
179
+ end
180
+ end
181
+ end
182
+
183
+ # Indicates that a mouse button was released.
184
+ #
185
+ # See MouseDownEvent.
186
+ class MouseUpEvent < Event
187
+ attr_accessor :string,:pos,:button
188
+ def initialize(pos,button)
189
+ @pos = pos
190
+ if button.kind_of? Integer
191
+ @button = button
192
+ @string = Rubygame::Mouse::MOUSE2STR[button] #a string or nil
193
+ elsif key.kind_of? String
194
+ @button = Rubygame::Mouse::STR2MOUSE[key]
195
+ if @button != nil
196
+ @string = button
197
+ else
198
+ raise(ArgumentError,"First argument of MouseUpEvent.new() must be an Integer Mouse button indentifier (like MOUSE_LEFT) or a String (like \"left\"). Got %s (%s)"%[button,button.class])
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ # Indicates that a Joystick axis was moved.
205
+ #
206
+ # This event has these attributes:
207
+ # joynum:: the identifier number of the affected Joystick.
208
+ # axis:: the identifier number of the axis.
209
+ # value:: the new value of the axis, between -32768 and 32767
210
+ class JoyAxisEvent < Event
211
+ attr_accessor :joynum,:axis,:value
212
+ def initialize(joy,axis,value)
213
+ # eventually, joy could be int OR a Rubygame::Joystick instance,
214
+ # which would be stored as joy or maybe joyinstance?
215
+ @joynum = joy
216
+ @axis, @value = axis, value
217
+ end
218
+ end
219
+
220
+ # Indicates that a Joystick trackball was moved.
221
+ #
222
+ # This event has these attributes:
223
+ # joynum:: the identifier number of the affected Joystick.
224
+ # ball:: the identifier number of the trackball.
225
+ # rel:: the relative movement of the trackball, [x,y].
226
+ class JoyBallEvent < Event
227
+ attr_accessor :joynum,:ball,:rel
228
+ def initialize(joy,ball,rel)
229
+ # eventually, joy could be int OR a Rubygame::Joystick instance,
230
+ # which would be stored as joy or maybe joyinstance?
231
+ @joynum = joy
232
+ @ball, @rel = ball, rel
233
+ end
234
+ end
235
+
236
+ # Indicates that a Joystick POV hat was moved.
237
+ #
238
+ # This event has these attributes:
239
+ # joynum:: the identifier number of the affected Joystick.
240
+ # hat:: the identifier number of the hat.
241
+ # value:: the new direction of the hat, one of these constants in module
242
+ # Rubygame (or the corresponding number):
243
+ # HAT_CENTERED:: 0
244
+ # HAT_UP:: 1
245
+ # HAT_RIGHT:: 2
246
+ # HAT_DOWN:: 4
247
+ # HAT_LEFT:: 8
248
+ # HAT_RIGHTUP:: 3
249
+ # HAT_RIGHTDOWN:: 6
250
+ # HAT_LEFTUP:: 9
251
+ # HAT_LEFTDOWN:: 12
252
+ class JoyHatEvent < Event
253
+ attr_accessor :joynum,:hat,:value
254
+ def initialize(joy,hat,value)
255
+ # eventually, joy could be int OR a Rubygame::Joystick instance,
256
+ # which would be stored as joy or maybe joyinstance?
257
+ @joynum = joy
258
+ @hat, @value = hat, value
259
+ end
260
+ end
261
+
262
+ # Indicates that a Joystick button was pressed.
263
+ #
264
+ # This event has these attributes:
265
+ # joynum:: the identifier number of the affected Joystick.
266
+ # hat:: the identifier number of the button.
267
+ class JoyDownEvent < Event
268
+ attr_accessor :joynum, :button
269
+ def initialize(joy,button)
270
+ # eventually, joy could be int OR a Rubygame::Joystick instance,
271
+ # which would be stored as joy or maybe joyinstance?
272
+ @joynum = joy
273
+ @button = button
274
+ end
275
+ end
276
+
277
+ # Indicates that a Joystick button was released.
278
+ #
279
+ # See JoyDownEvent.
280
+ class JoyUpEvent < Event
281
+ attr_accessor :joynum, :button
282
+ def initialize(joy,button)
283
+ # eventually, joy could be int OR a Rubygame::Joystick instance,
284
+ # which would be stored as joy or maybe joyinstance?
285
+ @joynum = joy
286
+ @button = button
287
+ end
288
+ end
289
+
290
+ # Indicates that the application window was resized. (After this event
291
+ # occurs, you should use Screen#set_mode to change the display surface to
292
+ # the new size.)
293
+ #
294
+ # This event has these attributes:
295
+ # size:: the new size of the window, in pixels [w,h].
296
+ class ResizeEvent < Event
297
+ attr_accessor :size
298
+ def initialize(new_size)
299
+ @size = new_size
300
+ end
301
+ end
302
+
303
+ # Indicates that part of the application window was exposed or otherwise
304
+ # changed, and perhaps the window needs to be refreshed. This event occurs,
305
+ # for example, when an OpenGL display should be updated.
306
+ class ExposeEvent < Event
307
+ end
308
+
309
+ # Indicates that the application has been signaled to quit. (E.g. the user
310
+ # pressed the close button.)
311
+ class QuitEvent < Event
312
+ end
313
+ end # module Rubygame