rubygame 2.3.0-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/CREDITS +60 -0
- data/LICENSE +504 -0
- data/NEWS +252 -0
- data/README +123 -0
- data/ROADMAP +109 -0
- data/Rakefile +438 -0
- data/doc/extended_readme.rdoc +49 -0
- data/doc/getting_started.rdoc +47 -0
- data/doc/macosx_install.rdoc +70 -0
- data/doc/windows_install.rdoc +123 -0
- data/ext/rubygame/rubygame_core.so +0 -0
- data/ext/rubygame/rubygame_event.c +644 -0
- data/ext/rubygame/rubygame_event.h +48 -0
- data/ext/rubygame/rubygame_event.o +0 -0
- data/ext/rubygame/rubygame_gfx.c +942 -0
- data/ext/rubygame/rubygame_gfx.h +101 -0
- data/ext/rubygame/rubygame_gfx.o +0 -0
- data/ext/rubygame/rubygame_gfx.so +0 -0
- data/ext/rubygame/rubygame_gl.c +154 -0
- data/ext/rubygame/rubygame_gl.h +32 -0
- data/ext/rubygame/rubygame_gl.o +0 -0
- data/ext/rubygame/rubygame_image.c +252 -0
- data/ext/rubygame/rubygame_image.h +41 -0
- data/ext/rubygame/rubygame_image.o +0 -0
- data/ext/rubygame/rubygame_image.so +0 -0
- data/ext/rubygame/rubygame_joystick.c +247 -0
- data/ext/rubygame/rubygame_joystick.h +41 -0
- data/ext/rubygame/rubygame_joystick.o +0 -0
- data/ext/rubygame/rubygame_main.c +155 -0
- data/ext/rubygame/rubygame_main.h +36 -0
- data/ext/rubygame/rubygame_main.o +0 -0
- data/ext/rubygame/rubygame_mixer.c +1024 -0
- data/ext/rubygame/rubygame_mixer.h +36 -0
- data/ext/rubygame/rubygame_mixer.o +0 -0
- data/ext/rubygame/rubygame_mixer.so +0 -0
- data/ext/rubygame/rubygame_music.c +1017 -0
- data/ext/rubygame/rubygame_music.h +29 -0
- data/ext/rubygame/rubygame_music.o +0 -0
- data/ext/rubygame/rubygame_screen.c +448 -0
- data/ext/rubygame/rubygame_screen.h +43 -0
- data/ext/rubygame/rubygame_screen.o +0 -0
- data/ext/rubygame/rubygame_shared.c +272 -0
- data/ext/rubygame/rubygame_shared.h +68 -0
- data/ext/rubygame/rubygame_shared.o +0 -0
- data/ext/rubygame/rubygame_sound.c +863 -0
- data/ext/rubygame/rubygame_sound.h +29 -0
- data/ext/rubygame/rubygame_sound.o +0 -0
- data/ext/rubygame/rubygame_surface.c +1151 -0
- data/ext/rubygame/rubygame_surface.h +62 -0
- data/ext/rubygame/rubygame_surface.o +0 -0
- data/ext/rubygame/rubygame_time.c +183 -0
- data/ext/rubygame/rubygame_time.h +32 -0
- data/ext/rubygame/rubygame_time.o +0 -0
- data/ext/rubygame/rubygame_ttf.c +599 -0
- data/ext/rubygame/rubygame_ttf.h +69 -0
- data/ext/rubygame/rubygame_ttf.o +0 -0
- data/ext/rubygame/rubygame_ttf.so +0 -0
- data/lib/rubygame.rb +41 -0
- data/lib/rubygame/clock.rb +128 -0
- data/lib/rubygame/color.rb +79 -0
- data/lib/rubygame/color/models/base.rb +111 -0
- data/lib/rubygame/color/models/hsl.rb +153 -0
- data/lib/rubygame/color/models/hsv.rb +149 -0
- data/lib/rubygame/color/models/rgb.rb +78 -0
- data/lib/rubygame/color/palettes/css.rb +49 -0
- data/lib/rubygame/color/palettes/palette.rb +100 -0
- data/lib/rubygame/color/palettes/x11.rb +177 -0
- data/lib/rubygame/constants.rb +238 -0
- data/lib/rubygame/event.rb +313 -0
- data/lib/rubygame/ftor.rb +370 -0
- data/lib/rubygame/hotspot.rb +265 -0
- data/lib/rubygame/keyconstants.rb +237 -0
- data/lib/rubygame/mediabag.rb +94 -0
- data/lib/rubygame/named_resource.rb +254 -0
- data/lib/rubygame/queue.rb +288 -0
- data/lib/rubygame/rect.rb +612 -0
- data/lib/rubygame/sfont.rb +223 -0
- data/lib/rubygame/sprite.rb +511 -0
- data/samples/FreeSans.ttf +0 -0
- data/samples/GPL.txt +340 -0
- data/samples/README +40 -0
- data/samples/chimp.bmp +0 -0
- data/samples/chimp.rb +302 -0
- data/samples/demo_gl.rb +151 -0
- data/samples/demo_gl_tex.rb +197 -0
- data/samples/demo_music.rb +77 -0
- data/samples/demo_rubygame.rb +296 -0
- data/samples/demo_sfont.rb +52 -0
- data/samples/demo_ttf.rb +193 -0
- data/samples/demo_utf8.rb +53 -0
- data/samples/fist.bmp +0 -0
- data/samples/load_and_blit.rb +22 -0
- data/samples/panda.png +0 -0
- data/samples/punch.wav +0 -0
- data/samples/ruby.png +0 -0
- data/samples/song.ogg +0 -0
- data/samples/term16.png +0 -0
- data/samples/whiff.wav +0 -0
- data/test/audio_spec.rb +236 -0
- data/test/color_spec.rb +544 -0
- data/test/image.png +0 -0
- data/test/music_spec.rb +727 -0
- data/test/named_resource_spec.rb +211 -0
- data/test/short.ogg +0 -0
- data/test/sound_spec.rb +564 -0
- data/test/surface_spec.rb +219 -0
- data/test/test_crop.rb +45 -0
- data/test/test_rect.rb +841 -0
- metadata +174 -0
@@ -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
|