tea 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/COPYING +674 -0
  2. data/COPYING.LESSER +165 -0
  3. data/README.rdoc +93 -0
  4. data/doc/example/bitmap_draw.rb +21 -0
  5. data/doc/example/bitmap_load.rb +14 -0
  6. data/doc/example/bitmap_new.rb +19 -0
  7. data/doc/example/circle.rb +24 -0
  8. data/doc/example/circle_alpha.rb +45 -0
  9. data/doc/example/circle_alpha_bitmap.rb +51 -0
  10. data/doc/example/circle_bitmap.rb +18 -0
  11. data/doc/example/clip.rb +46 -0
  12. data/doc/example/event_app.rb +45 -0
  13. data/doc/example/event_keyboard.rb +43 -0
  14. data/doc/example/event_mouse.rb +85 -0
  15. data/doc/example/font_hello.rb +22 -0
  16. data/doc/example/font_word_wrap.rb +44 -0
  17. data/doc/example/grab.rb +28 -0
  18. data/doc/example/init.rb +10 -0
  19. data/doc/example/lines.rb +49 -0
  20. data/doc/example/lines_aa.rb +44 -0
  21. data/doc/example/lines_alpha.rb +33 -0
  22. data/doc/example/point.rb +26 -0
  23. data/doc/example/rect.rb +15 -0
  24. data/doc/example/rect_alpha.rb +75 -0
  25. data/doc/example/screen_set_mode.rb +18 -0
  26. data/doc/example/screen_update.rb +14 -0
  27. data/doc/example/sfont_hello.rb +22 -0
  28. data/doc/example/smile.png +0 -0
  29. data/doc/example/smile_bounce.rb +44 -0
  30. data/doc/example/smile_move.rb +58 -0
  31. data/doc/example/smile_move_2.rb +78 -0
  32. data/doc/example/sound.rb +101 -0
  33. data/doc/example/state_app.rb +33 -0
  34. data/doc/example/state_keyboard.rb +23 -0
  35. data/doc/example/state_mouse.rb +60 -0
  36. data/doc/key_constants.textile +129 -0
  37. data/doc/key_modifiers.textile +19 -0
  38. data/doc/reference.textile +421 -0
  39. data/lib/tea.rb +34 -0
  40. data/lib/tea/c_bitmap.rb +122 -0
  41. data/lib/tea/c_error.rb +11 -0
  42. data/lib/tea/c_font.rb +302 -0
  43. data/lib/tea/c_sound.rb +144 -0
  44. data/lib/tea/m_color.rb +50 -0
  45. data/lib/tea/m_event.rb +65 -0
  46. data/lib/tea/m_event_app.rb +96 -0
  47. data/lib/tea/m_event_dispatch.rb +54 -0
  48. data/lib/tea/m_event_keyboard.rb +311 -0
  49. data/lib/tea/m_event_mouse.rb +189 -0
  50. data/lib/tea/mix_blitting.rb +31 -0
  51. data/lib/tea/mix_clipping.rb +71 -0
  52. data/lib/tea/mix_grabbing.rb +86 -0
  53. data/lib/tea/mix_image_saving.rb +70 -0
  54. data/lib/tea/mix_primitive.rb +613 -0
  55. data/lib/tea/o_screen.rb +98 -0
  56. metadata +137 -0
@@ -0,0 +1,33 @@
1
+ # Test that the app state is correctly reported.
2
+ # Expected results: minimized app state, keybord and mouse focus is correctly
3
+ # reported.
4
+
5
+ require 'tea'
6
+
7
+ puts <<TEST
8
+ Try...
9
+
10
+ * minimising/restoring the window
11
+ * moving the mouse in/out of the window
12
+ * changing focus in/out of the window
13
+
14
+ The app visibility, mouse and keyboard focus will be reported below.
15
+ TEST
16
+
17
+ Tea.init
18
+ Tea::Screen.set_mode 320, 240
19
+ e = nil
20
+ puts '%19s %20s%20s%20s' % ['EVENT', 'APP VISIBILITY', 'KEYBOARD', 'MOUSE']
21
+ puts '-' * 80
22
+ loop do
23
+ visible = Tea::App.visible? ? 'visible' : 'not visible'
24
+ kbd = Tea::Kbd.in_app? ? 'keyboard in' : 'keyboard not in'
25
+ mouse = Tea::Mouse.in_app? ? 'mouse in' : 'mouse not in'
26
+ puts '%19s:%20s%20s%20s' % [e.class, visible, kbd, mouse]
27
+ begin
28
+ e = Tea::Event.get(true)
29
+ exit if e.class == Tea::App::Exit
30
+ end until [Tea::App::Minimized, Tea::App::Restored,
31
+ Tea::Kbd::Lost, Tea::Kbd::Gained,
32
+ Tea::Mouse::Lost, Tea::Mouse::Gained].include?(e.class)
33
+ end
@@ -0,0 +1,23 @@
1
+ # Test that the keyboard state is being picked up.
2
+ # Expected output is that all keyboard events will print if the 'A' key is
3
+ # being pressed, and if Num Lock is active.
4
+
5
+ require 'tea'
6
+
7
+ puts <<TEST
8
+ Press some keys. Printed lines will tell if 'A' is being pressed,
9
+ and if Num Lock is active.
10
+ TEST
11
+
12
+ Tea.init
13
+ Tea::Screen.set_mode 320, 240
14
+ loop do
15
+ a_down = Tea::Kbd.key_down?(Tea::Kbd::A) ? 'DOWN' : 'UP'
16
+ num_lock_active = Tea::Kbd.mod_active?(Tea::Kbd::NUM_LOCK) ? 'ON' : 'OFF'
17
+ puts "'A' is #{a_down}; Num Lock is #{num_lock_active}"
18
+ begin
19
+ e = Tea::Event.get(true)
20
+ exit if e.class == Tea::App::Exit
21
+ end until e.class == Tea::Kbd::Down || e.class == Tea::Kbd::Up
22
+ print "(#{e.key}); "
23
+ end
@@ -0,0 +1,60 @@
1
+ # Test that the mouse status is correctly reported.
2
+ # Expected results include the mouse x, y, left, middle and right button down
3
+ # status, printed whenever the mouse is used in the 400x300 screen window.
4
+
5
+ require 'tea'
6
+
7
+ puts <<TEST
8
+ Move the mouse in the window. Mouse x, y, and left/middle/right button down
9
+ status should be reported here.
10
+ TEST
11
+
12
+ ##############################################################################
13
+ # Swiped from event_mouse.rb. I'd make a module, but I don't want to clutter
14
+ # this demo directory.
15
+
16
+ # We can avoid flooding the terminal with VT100 codes. Sorry Windows.
17
+ $windows = RUBY_PLATFORM =~ /w(?:in)?32/
18
+ SAVE_POSITION = "\x1b[s"
19
+ RESTORE_POSITION = "\x1b[u"
20
+ HIDE_CURSOR = "\x1b[?25l"
21
+ UNHIDE_CURSOR = "\x1b[?25h"
22
+ CLEAR_TO_LINE_END = "\x1b[K"
23
+
24
+ # VT100-enhanced printing function that overwrites the current terminal line.
25
+ def pr(*args)
26
+ print HIDE_CURSOR, SAVE_POSITION if !$windows
27
+ print *args
28
+ if $windows
29
+ puts
30
+ else
31
+ print CLEAR_TO_LINE_END, RESTORE_POSITION, UNHIDE_CURSOR
32
+ end
33
+ end
34
+
35
+ ##############################################################################
36
+
37
+ Tea.init
38
+ Tea::Screen.set_mode 400, 300
39
+ have_mouse = true
40
+ loop do
41
+ begin
42
+ e = Tea::Event.get(true)
43
+ exit if e.class == Tea::App::Exit
44
+ end until [Tea::Mouse::Move,
45
+ Tea::Mouse::Down,
46
+ Tea::Mouse::Up,
47
+ Tea::Mouse::Gained,
48
+ Tea::Mouse::Lost].include?(e.class)
49
+
50
+ case e
51
+ when Tea::Mouse::Gained then have_mouse = true
52
+ when Tea::Mouse::Lost then have_mouse = false
53
+ end
54
+
55
+ if have_mouse
56
+ pr "Mouse (#{Tea::Mouse.x}, #{Tea::Mouse.y}), [#{Tea::Mouse.left?}|#{Tea::Mouse.middle?}|#{Tea::Mouse.right?}]"
57
+ else
58
+ pr "Mouse is out of the house"
59
+ end
60
+ end
@@ -0,0 +1,129 @@
1
+ These key constants are returned by key events and can be passed into keyboard status checking methods. The all live in Tea::Kbd, so the 'A' key on your keyboard would be Tea::Kbd::A, for example.
2
+
3
+ The value of each constant is a Ruby symbol with the same name, which should make debugging easier.
4
+
5
+ BACKSPACE
6
+ TAB
7
+ ENTER
8
+ PAUSE
9
+ ESCAPE
10
+ SPACE
11
+ EXCLAMATION_MARK
12
+ DOUBLE_QUOTE
13
+ HASH
14
+ DOLLAR
15
+ AMPERSAND
16
+ QUOTE
17
+ OPEN_PAREN
18
+ CLOSE_PAREN
19
+ ASTERISK
20
+ PLUS
21
+ COMMA
22
+ MINUS
23
+ PERIOD
24
+ SLASH
25
+ K0
26
+ K1
27
+ K2
28
+ K3
29
+ K4
30
+ K5
31
+ K6
32
+ K7
33
+ K8
34
+ K9
35
+ COLON
36
+ SEMICOLON
37
+ LESS_THAN
38
+ EQUALS
39
+ GREATER_THAN
40
+ QUESTION_MARK
41
+ AT
42
+ OPEN_SQUARE_BRACKET
43
+ BACKSLASH
44
+ CLOSE_SQUARE_BRACKET
45
+ CARET
46
+ UNDERSCORE
47
+ BACKTICK
48
+ A
49
+ B
50
+ C
51
+ D
52
+ E
53
+ F
54
+ G
55
+ H
56
+ I
57
+ J
58
+ K
59
+ L
60
+ M
61
+ N
62
+ O
63
+ P
64
+ Q
65
+ R
66
+ S
67
+ T
68
+ U
69
+ V
70
+ W
71
+ X
72
+ Y
73
+ Z
74
+ DELETE
75
+ NP0
76
+ NP1
77
+ NP2
78
+ NP3
79
+ NP4
80
+ NP5
81
+ NP6
82
+ NP7
83
+ NP8
84
+ NP9
85
+ NP_PERIOD
86
+ NP_DIVIDE
87
+ NP_MULTIPLY
88
+ NP_MINUS
89
+ NP_PLUS
90
+ NP_ENTER
91
+ NP_EQUALS
92
+ UP
93
+ DOWN
94
+ RIGHT
95
+ LEFT
96
+ INSERT
97
+ HOME
98
+ END
99
+ PAGE_UP
100
+ PAGE_DOWN
101
+ F1
102
+ F2
103
+ F3
104
+ F4
105
+ F5
106
+ F6
107
+ F7
108
+ F8
109
+ F9
110
+ F10
111
+ F11
112
+ F12
113
+ NUM_LOCK
114
+ CAPS_LOCK
115
+ SCROLL_LOCK
116
+ R_SHIFT
117
+ L_SHIFT
118
+ R_CTRL
119
+ L_CTRL
120
+ R_ALT
121
+ L_ALT
122
+ L_SUPER
123
+ R_SUPER
124
+ ALT_GR
125
+ PRINT_SCREEN
126
+ SYS_REQ
127
+ BREAK
128
+ MENU
129
+ EURO
@@ -0,0 +1,19 @@
1
+ Key modifiers are things like Shift or Num Lock that change the meaning of some keys when they're held down or toggled on. Tea::Kbd::Down and Tea::Kbd::Up events provide modifier information.
2
+
3
+ The following constants are valid modifiers that also happen to match their keys. Like the [[Key Constants]], they also live in Tea::Kbd, so the left Shift key would be Tea::Kbd::L_SHIFT.
4
+
5
+ L_SHIFT
6
+ R_SHIFT
7
+ L_CTRL
8
+ R_CTRL
9
+ L_ALT
10
+ R_ALT
11
+ NUM_LOCK
12
+ CAPS_LOCK
13
+ ALT_GR
14
+
15
+ These extra constants can used for convenience. They also live in Tea::Kbd, but aren't physical keys.
16
+
17
+ SHIFT
18
+ CTRL
19
+ ALT
@@ -0,0 +1,421 @@
1
+ This page is manually assembled, so parts of it may become out of date. If something's missing or doesn't exist, let me know.
2
+
3
+
4
+ h1. Tea
5
+
6
+ h2. Tea.init()
7
+
8
+ Intialise Tea. This needs to be called before using any of Tea's objects or methods. May throw Tea::Error if initialisation fails.
9
+
10
+ h2. Tea::Error
11
+
12
+ This is the exception class raised when Bad Things happen in any of Tea's objects or methods.
13
+
14
+
15
+ h1. Graphics
16
+
17
+ h2. Tea::Color
18
+
19
+ This module holds utility methods for working with colours. It exists for convenience; colours can still be passed around in the form 0xRRGGBBAA.
20
+
21
+ There are some pre-mixed colour constants available in it:
22
+
23
+ |_. Color |_. Red |_. Green |_. Blue |_. Alpha |
24
+ | CLEAR |>. 0 |>. 0 |>. 0 |>. 0 |
25
+ | BLACK |>. 0 |>. 0 |>. 0 |>. 255 |
26
+ | DARK_RED |>. 128 |>. 0 |>. 0 |>. 255 |
27
+ | DARK_GREEN |>. 0 |>. 128 |>. 0 |>. 255 |
28
+ | DARK_YELLOW |>. 128 |>. 128 |>. 0 |>. 255 |
29
+ | DARK_BLUE |>. 0 |>. 0 |>. 128 |>. 255 |
30
+ | DARK_MAGENTA |>. 128 |>. 0 |>. 128 |>. 255 |
31
+ | DARK_CYAN |>. 0 |>. 128 |>. 128 |>. 255 |
32
+ | DARK_GRAY |>. 128 |>. 128 |>. 128 |>. 255 |
33
+ | GRAY |>. 192 |>. 192 |>. 192 |>. 255 |
34
+ | RED |>. 255 |>. 0 |>. 0 |>. 255 |
35
+ | GREEN |>. 0 |>. 255 |>. 0 |>. 255 |
36
+ | YELLOW |>. 255 |>. 255 |>. 0 |>. 255 |
37
+ | BLUE |>. 0 |>. 0 |>. 255 |>. 255 |
38
+ | MAGENTA |>. 255 |>. 0 |>. 255 |>. 255 |
39
+ | CYAN |>. 0 |>. 255 |>. 255 |>. 255 |
40
+ | WHITE |>. 255 |>. 255 |>. 255 |>. 255 |
41
+
42
+ h3. Tea::Color.mix(red, green, blue, alpha=255)
43
+
44
+ Create a colour of the form 0xRRGGBBAA. Each argument should be an integer between 0..255 inclusive. The colours returned by this method can be used throughout the graphics API.
45
+
46
+ h3. Tea::Color.split(color)
47
+
48
+ Split a colour of the form 0xRRGGBBAA into its red, green, blue and alpha parts. A 4-element array is returned, of the form [red, green, blue, alpha], where each element is between 0..255 inclusive.
49
+
50
+ h2. Tea::Bitmap
51
+
52
+ A Bitmap is a grid of pixels that holds graphics. It can be drawn onto and drawn with.
53
+
54
+ h3. Tea::Bitmap included mixins
55
+
56
+ Instances of Tea::Bitmap share methods from the following modules:
57
+
58
+ Tea::Blitting:
59
+ * blit(source_blittable, x, y)
60
+
61
+ Tea::Clipping:
62
+ * clip
63
+ * clip(x, y, w, h)
64
+ * clip(x, y, w, h) { ... }
65
+
66
+ These clip methods get, set and run a block with a clipping rectangle respectively. While a clipping rectangle is set, drawing will be clipped inside it.
67
+
68
+ Tea::Grabbing:
69
+ * grab([x, y, w, h])
70
+
71
+ This grab method copies a sub-section of the Bitmap (or all of it if no arguments are given) and returns it as a new Bitmap object.
72
+
73
+ Tea::ImageSaving:
74
+ * save(path)
75
+
76
+ The save method saves the Bitmap as an image file. Supported formats: BMP, PNG.
77
+
78
+ Tea::Primitive:
79
+ * clear()
80
+ * [x, y]
81
+ * [x, y] = color
82
+ * rect(x, y, w, h, color[, {:mix => :blend (alt. :replace)}])
83
+ * line(x1, y1, x2, y2, color[, {:antialias => false, :mix => :blend (alt. :replace)}])
84
+ * circle(x, y, radius, color[, {:outline => false, :antialias => false, :mix => :blend (alt. :replace)}])
85
+
86
+ Note that colours are of the form 0xRRGGBBAA, and can be conveniently made using Tea::Color.mix().
87
+
88
+ h3. Tea::Bitmap.new(*args)
89
+
90
+ Create a new Bitmap. This can be done in 2 ways:
91
+
92
+ 1. Tea::Bitmap.new(image_path): load from an image file.
93
+ 2. Tea::Bitmap.new(width, height, color): create with the given size and colour.
94
+
95
+ ArgumentError is raised if you don't call it in one of these ways. Tea::Error may be raised if one of these initialisations fail.
96
+
97
+ h3. Tea::Bitmap#w()
98
+
99
+ The width of the Bitmap in pixels.
100
+
101
+ h3. Tea::Bitmap#h()
102
+
103
+ The height of the Bitmap in pixels.
104
+
105
+ h2. Tea::Screen
106
+
107
+ Tea::Screen acts much like a Bitmap, except things drawn to it will be displayed on the screen once Tea::Screen.update() is called.
108
+
109
+ h3. Tea::Screen mixins
110
+
111
+ Since Tea::Screen is an object and not a class, its mixins add methods to Tea::Screen itself.
112
+
113
+ Tea::Blitting:
114
+ * blit(source_blittable, x, y)
115
+
116
+ Tea::Clipping:
117
+ * clip
118
+ * clip(x, y, w, h)
119
+ * clip(x, y, w, h) { ... }
120
+
121
+ These clip methods get, set and run a block with a clipping rectangle respectively. While a clipping rectangle is set, drawing will be clipped inside it.
122
+
123
+ Tea::Grabbing:
124
+ * grab([x, y, w, h])
125
+
126
+ This grab method copies a sub-section of the screen (or all of it if no arguments are given) and returns it as a new Bitmap object.
127
+
128
+ Tea::ImageSaving:
129
+ * save(path)
130
+
131
+ The save method saves the Screen as an image file. Supported formats: BMP, PNG.
132
+
133
+ Tea::Primitive:
134
+ * clear()
135
+ * [x, y]
136
+ * [x, y] = color
137
+ * rect(x, y, w, h, color[, {:mix => :blend (alt. :replace)}])
138
+ * line(x1, y1, x2, y2, color[, {:antialias => false, :mix => :blend (alt. :replace)}])
139
+ * circle(x, y, radius, color[, {:outline => false, :antialias => false, :mix => :blend (alt. :replace)}])
140
+
141
+ Note that colours are of the form 0xRRGGBBAA, and can be conveniently made with Tea::Color.mix().
142
+
143
+ h3. Tea::Screen.set_mode(width, height)
144
+
145
+ Create a screen window with the given dimensions. After this, you can start drawing on the screen. May raise Tea::Error if it fails.
146
+
147
+ h3. Tea::Screen.update()
148
+
149
+ Make what has been drawn on the screen visible.
150
+
151
+ h3. Tea::Screen.w()
152
+
153
+ The width of the screen in pixels.
154
+
155
+ h3. Tea::Screen.h()
156
+
157
+ The height of the screen in pixels.
158
+
159
+
160
+ h1. Input and other events
161
+
162
+ Event handling is the heart and soul of most games, so this subsystem is quite important.
163
+
164
+ h2. Tea::Event
165
+
166
+ The Event module allows access to the event queue, and the classes of events that come out.
167
+
168
+ Events rely on having a screen window, so call Tea::Screen.set_mode before using any of these.
169
+
170
+ h3. Tea::Event.get(wait=false)
171
+
172
+ Get the next event in the event queue. If wait is true and there are no events to return, this method will wait until there is one and return it. Otherwise, an empty event queue will return nil. The events that can be returned include:
173
+
174
+ * *Tea::App::Exit*
175
+ * *Tea::App::Minimized*
176
+ * *Tea::App::Restored*
177
+
178
+ * *Tea::Kbd::Lost*
179
+ - i.e. keyboard input focus lost
180
+ * *Tea::Kbd::Gained*
181
+ - i.e. keyboard input focus gained
182
+ * *Tea::Kbd::Down*
183
+ - key - keyboard key that was pressed (see [[Key Constants]])
184
+ - mods - a hash of modifiers active when key was pressed (see [[Key Modifiers]])
185
+ - char - character generated when the key is typed
186
+ * *Tea::Kbd::Up*
187
+ - key - keyboard key that was released (see [[Key Constants]])
188
+ - mods - modifiers active when the key was released (see [[Key Modifiers]])
189
+
190
+ * *Tea::Mouse::Move*
191
+ - x, y - coordinates of the mouse
192
+ - buttons - a hash of mouse buttons to true/false: Tea::Mouse::LEFT, MIDDLE and RIGHT
193
+ * *Tea::Mouse::Lost*
194
+ - i.e. mouse is no longer in the screen window
195
+ * *Tea::Mouse::Gained*
196
+ - i.e. mouse is within the screen window
197
+ * *Tea::Mouse::Down*
198
+ - x, y - coordinates of the mouse when the button was pressed
199
+ - button - one of Tea::Mouse::LEFT, MIDDLE or RIGHT
200
+ * *Tea::Mouse::Up*
201
+ - x, y - coordinates of the mouse when the button was released
202
+ - button - mouse button constant, same as for Tea::Mouse::Down#button
203
+ * *Tea::Mouse::Scroll*
204
+ - x, y - coordinates of the mouse when the scroll wheel was used
205
+ - delta - 1 for a downward scroll, -1 for an upward scroll
206
+
207
+ These returned event objects may have methods that give extra information about the event itself.
208
+
209
+ May raise Tea::Error if getting an event fails.
210
+
211
+ h2. Tea::Event::Dispatch mixin
212
+
213
+ This mixin gives the class a dispatch_event method that, when called, will call a specially-named method that matches the event's class name.
214
+
215
+ <pre>
216
+ require 'tea'
217
+
218
+ class MyEventHandler
219
+ attr_reader :done
220
+ def initialize
221
+ @done = false
222
+ end
223
+
224
+ include Tea::Event::Dispatch
225
+
226
+ def kbd_down(e)
227
+ puts "You typed: #{e.char}"
228
+ if e.key == Tea::Kbd::ESCAPE
229
+ puts 'Bye bye!'
230
+ @done = true
231
+ end
232
+ end
233
+ end
234
+
235
+ Tea.init
236
+ Tea::Screen.set_mode 400, 300
237
+
238
+ handler = MyEventHandler.new
239
+ until handler.done
240
+ handler.dispatch_event Tea::Event.get(true)
241
+ end
242
+ </pre>
243
+
244
+ This example shows:
245
+
246
+ 1. the Tea::Event::Dispatch mixin being included in a class,
247
+ 2. a sample event handling function kbd_down, matching Tea::Kbd::Down, and
248
+ 3. dispatch_event being called with an event passed into it.
249
+
250
+ Event names are matched to method names as follows:
251
+
252
+ 1. Get the original class name, e.g. Tea::Kbd::Down.
253
+ 2. Get rid of the 'Tea::' part, e.g. Kbd::Down.
254
+ 3. Substitute the '::' for '_', e.g. Kbd_Down.
255
+ 4. Convert to all lower case, e.g. kbd_down.
256
+
257
+ This mixin may not be needed for simpler games, but it can help when using classes to organise game code.
258
+
259
+ h2. Tea::App
260
+
261
+ As well as the app-related events that spawn from here, this module also provides some app-related status checking.
262
+
263
+ The methods below will only return different values when Tea::Event.get() is called.
264
+
265
+ h3. Tea::App.visible?
266
+
267
+ Returns true if the screen window is visible, i.e. not minimised.
268
+
269
+ h2. Tea::Kbd
270
+
271
+ As well as the keyboard-related events that spawn from here, this module also lets you check the status of keys and modifiers.
272
+
273
+ The methods below will only return different values when Tea::Event.get() is called.
274
+
275
+ h3. Tea::Kbd.in_app?()
276
+
277
+ Returns true if the keyboard focus is within the screen window. Most of the time, this means the screen window is in the foreground.
278
+
279
+ h3. Tea::Kbd.key_down?(key)
280
+
281
+ Returns true if the key given is being pressed. See [[Key Constants]].
282
+
283
+ h3. Tea::Kbd.mod_active?(mod)
284
+
285
+ Returns true if the modifier is 'active'.
286
+
287
+ For Shift, Ctrl, Alt and AltGr (not sure on the last one) this means they're being held down.
288
+
289
+ For Num Lock and Caps Lock, this means their toggle is on.
290
+
291
+ Tea::Kbd::SHIFT, CTRL and ALT can be passed in for convenience. See [[Key Modifiers]].
292
+
293
+ h2. Tea::Mouse
294
+
295
+ As well as the mouse-related events that spawn from here, this module also lets you check the state of the mouse.
296
+
297
+ The methods below will only return different values when Tea::Event.get() is called.
298
+
299
+ h3. Tea::Mouse.in_app?()
300
+
301
+ Returns true if the mouse cursor is over the screen window. If there are other windows in front of the screen window, this can still return true, depending on your environment.
302
+
303
+ h3. Tea::Mouse.x()
304
+
305
+ Get the x part of the mouse coordinates.
306
+
307
+ h3. Tea::Mouse.y()
308
+
309
+ Get the y part of the mouse coordinates.
310
+
311
+ h3. Tea::Mouse.left?()
312
+
313
+ Returns true when the left mouse button is held down.
314
+
315
+ h3. Tea::Mouse.middle?()
316
+
317
+ Returns true when the middle mouse button is held down.
318
+
319
+ h3. Tea::Mouse.right?()
320
+
321
+ Returns true when the right mouse button is held down.
322
+
323
+
324
+ h1. Sound
325
+
326
+ h2. Tea::Sound
327
+
328
+ A Sound represents a loaded audio file that can be played through the computer's speakers.
329
+
330
+ For now, the supported formats are: OGG, WAV, AIFF, RIFF, VOC.
331
+
332
+ h3. Tea::Sound.volume()
333
+
334
+ Get the master volume. Returns a value between 0 (min) and 128 (max) inclusive.
335
+
336
+ h3. Tea::Sound.volume=(new_volume)
337
+
338
+ Set the master volume. new_volume should be between 0 (min) and 128 (max) inclusive.
339
+
340
+ h3. Tea::Sound.pause_all()
341
+
342
+ Pause all playing sounds.
343
+
344
+ h3. Tea::Sound.resume_all()
345
+
346
+ Resume all paused sounds.
347
+
348
+ h3. Tea::Sound.stop_all()
349
+
350
+ Stop all playing and paused sounds.
351
+
352
+ h3. Tea::Sound.new(path)
353
+
354
+ Load a new sound from an audio file.
355
+
356
+ h3. Tea::Sound#volume()
357
+
358
+ Get the volume of the sound. Returns a value between 0 (min) and 128 (max) inclusive.
359
+
360
+ h3. Tea::Sound#volume=(new_volume)
361
+
362
+ Set the volume of the sound. new_volume should be between 0 (min) and 128 (max) inclusive.
363
+
364
+ h3. Tea::Sound#play(loops=0)
365
+
366
+ Play the sound. If it's already playing, cut it off and start over. loops should be the number of times to repeat the sound; use -1 to repeat it forever.
367
+
368
+ h3. Tea::Sound#pause()
369
+
370
+ Pause the sound if it's playing, otherwise do nothing.
371
+
372
+ h3. Tea::Sound#resume()
373
+
374
+ Resume playing the sound if it was paused, otherwise do nothing.
375
+
376
+ h3. Tea::Sound#stop()
377
+
378
+ Stop the sound if it's playing, otherwise do nothing.
379
+
380
+ h3. Tea::Sound#state()
381
+
382
+ Check if the sound is stopped, playing or paused. Returns one of Tea::Sound::STOPPED, Tea::Sound::PLAYING or Tea::Sound::PAUSED.
383
+
384
+
385
+ h1. Fonts
386
+
387
+ h2. Tea::Font
388
+
389
+ A font is a set of images (glyphs) that controls how text appears when it is drawn.
390
+
391
+ Currently, bitmap fonts and Karl Bartel's SFont formats are supported.
392
+
393
+ Bitmap fonts are 256 character images in a row, in a single BMP or PNG, in ASCII order.
394
+
395
+ SFont files are 94 character images in a row, also in a single BMP or PNG, in ASCII order, starting with ASCII code 33. Letters are variable width, and are separated with magenta gaps (255, 0, 255) in the top row. The SFont alphabet is as follows:
396
+
397
+ <pre>
398
+ ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @
399
+ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ `
400
+ a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
401
+ </pre>
402
+
403
+ h3. Tea::Font.new(path, type[, {:transparent_color => Tea::Color::MAGENTA}])
404
+
405
+ Load a font from a file. Type may be Tea::Font::BITMAP_FONT or Tea::Font::SFONT. Setting transparent_color will cause that color to be treated as transparent when the font is loaded.
406
+
407
+ h3. Tea::Font#string_w(string)
408
+
409
+ Get the width of a string rendered with the font, in pixels.
410
+
411
+ h3. Tea::Font#h()
412
+
413
+ Get the height of the font's characters, in pixels.
414
+
415
+ h3. Tea::Font#word_wrap(string, width, initial_left_margin=0)
416
+
417
+ Split the string into lines that, when drawn with this font, do not exceed width. Setting initial_left_margin will treat the string as starting that many pixels away from the left "edge" of wrapping. Returns an instance of WrappedLines, which is an Array in all ways except that it also has the position of the end of the final line from the left "edge", accessible as end_x.
418
+
419
+ h3. Tea::Font#draw_to(dest_blittable, x, y, string)
420
+
421
+ Render the string using the font onto dest_blittable (a Bitmap or the Screen), with the top-left corner at (x, y).