tung-tea 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/doc/reference.textile +2 -2
- data/lib/tea/c_bitmap.rb +5 -5
- data/lib/tea/c_error.rb +2 -1
- data/lib/tea/m_event_app.rb +17 -8
- data/lib/tea/m_event_keyboard.rb +198 -183
- data/lib/tea/m_event_mouse.rb +9 -6
- data/lib/tea/{m_blitting.rb → mix_blitting.rb} +4 -4
- data/lib/tea/{m_clipping.rb → mix_clipping.rb} +3 -1
- data/lib/tea/{m_primitive_drawing.rb → mix_primitive.rb} +2 -4
- data/lib/tea/{screen.rb → o_screen.rb} +22 -10
- data/lib/tea.rb +1 -1
- metadata +6 -6
data/doc/reference.textile
CHANGED
@@ -32,7 +32,7 @@ Tea::Clipping:
|
|
32
32
|
|
33
33
|
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.
|
34
34
|
|
35
|
-
Tea::
|
35
|
+
Tea::Primitive:
|
36
36
|
* clear()
|
37
37
|
* point(x, y, color)
|
38
38
|
* rect(x, y, w, h, color[, {:mix => :blend (alt. :replace)}])
|
@@ -76,7 +76,7 @@ Tea::Clipping:
|
|
76
76
|
|
77
77
|
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.
|
78
78
|
|
79
|
-
Tea::
|
79
|
+
Tea::Primitive:
|
80
80
|
* clear()
|
81
81
|
* point(x, y, color)
|
82
82
|
* rect(x, y, w, h, color[, {:mix => :blend (alt. :replace)}])
|
data/lib/tea/c_bitmap.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
|
4
4
|
require 'sdl'
|
5
5
|
|
6
|
-
require 'tea/
|
7
|
-
require 'tea/
|
8
|
-
require 'tea/
|
6
|
+
require 'tea/mix_blitting'
|
7
|
+
require 'tea/mix_clipping'
|
8
|
+
require 'tea/mix_primitive'
|
9
9
|
|
10
10
|
#
|
11
11
|
module Tea
|
@@ -40,7 +40,7 @@ module Tea
|
|
40
40
|
end
|
41
41
|
|
42
42
|
include Tea::Blitting
|
43
|
-
def
|
43
|
+
def blitting_buffer
|
44
44
|
@buffer
|
45
45
|
end
|
46
46
|
|
@@ -49,7 +49,7 @@ module Tea
|
|
49
49
|
@buffer
|
50
50
|
end
|
51
51
|
|
52
|
-
include Tea::
|
52
|
+
include Tea::Primitive
|
53
53
|
def primitive_buffer
|
54
54
|
@buffer
|
55
55
|
end
|
data/lib/tea/c_error.rb
CHANGED
data/lib/tea/m_event_app.rb
CHANGED
@@ -7,34 +7,43 @@ module Tea
|
|
7
7
|
|
8
8
|
module Mouse
|
9
9
|
# Event generated when mouse focus is gained.
|
10
|
-
class Gained
|
10
|
+
class Gained
|
11
|
+
end
|
11
12
|
|
12
13
|
# Event generated when mouse focus is lost.
|
13
|
-
class Lost
|
14
|
+
class Lost
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
module Kbd
|
17
19
|
# Event generated when keyboard input focus is gained.
|
18
|
-
class Gained
|
20
|
+
class Gained
|
21
|
+
end
|
19
22
|
|
20
23
|
# Event generated when keyboard input focus is lost.
|
21
|
-
class Lost
|
24
|
+
class Lost
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
module App
|
25
29
|
# Event generated when the player acts to close the screen window.
|
26
|
-
class Exit
|
30
|
+
class Exit
|
31
|
+
end
|
27
32
|
|
28
33
|
# Event generated when the screen window is minimised.
|
29
|
-
class Minimized
|
34
|
+
class Minimized
|
35
|
+
end
|
30
36
|
|
31
37
|
# Event generated when the screen window is restored from being minimised.
|
32
|
-
class Restored
|
38
|
+
class Restored
|
39
|
+
end
|
40
|
+
|
41
|
+
# Default for App.visible?.
|
42
|
+
@visible = true
|
33
43
|
|
34
44
|
# Returns true if the screen window has not been minimised, otherwise
|
35
45
|
# false.
|
36
46
|
def App.visible?
|
37
|
-
@visible = true if !instance_variable_defined?(:@visible)
|
38
47
|
@visible
|
39
48
|
end
|
40
49
|
|
data/lib/tea/m_event_keyboard.rb
CHANGED
@@ -6,6 +6,181 @@ require 'sdl'
|
|
6
6
|
module Tea
|
7
7
|
|
8
8
|
module Kbd
|
9
|
+
|
10
|
+
# Superclass for all Kbd events.
|
11
|
+
class Event
|
12
|
+
@@sdl_key_table = {
|
13
|
+
SDL::Key::BACKSPACE => :BACKSPACE,
|
14
|
+
SDL::Key::TAB => :TAB,
|
15
|
+
#SDL::Key::CLEAR => clear, # ???
|
16
|
+
SDL::Key::RETURN => :ENTER,
|
17
|
+
SDL::Key::PAUSE => :PAUSE,
|
18
|
+
SDL::Key::ESCAPE => :ESCAPE,
|
19
|
+
SDL::Key::SPACE => :SPACE,
|
20
|
+
SDL::Key::EXCLAIM => :EXCLAMATION_MARK,
|
21
|
+
SDL::Key::QUOTEDBL => :DOUBLE_QUOTE,
|
22
|
+
SDL::Key::HASH => :HASH,
|
23
|
+
SDL::Key::DOLLAR => :DOLLAR,
|
24
|
+
SDL::Key::AMPERSAND => :AMPERSAND,
|
25
|
+
SDL::Key::QUOTE => :QUOTE,
|
26
|
+
SDL::Key::LEFTPAREN => :OPEN_PAREN,
|
27
|
+
SDL::Key::RIGHTPAREN => :CLOSE_PAREN,
|
28
|
+
SDL::Key::ASTERISK => :ASTERISK,
|
29
|
+
SDL::Key::PLUS => :PLUS,
|
30
|
+
SDL::Key::COMMA => :COMMA,
|
31
|
+
SDL::Key::MINUS => :MINUS,
|
32
|
+
SDL::Key::PERIOD => :PERIOD,
|
33
|
+
SDL::Key::SLASH => :SLASH,
|
34
|
+
SDL::Key::K0 => :K0,
|
35
|
+
SDL::Key::K1 => :K1,
|
36
|
+
SDL::Key::K2 => :K2,
|
37
|
+
SDL::Key::K3 => :K3,
|
38
|
+
SDL::Key::K4 => :K4,
|
39
|
+
SDL::Key::K5 => :K5,
|
40
|
+
SDL::Key::K6 => :K6,
|
41
|
+
SDL::Key::K7 => :K7,
|
42
|
+
SDL::Key::K8 => :K8,
|
43
|
+
SDL::Key::K9 => :K9,
|
44
|
+
SDL::Key::COLON => :COLON,
|
45
|
+
SDL::Key::SEMICOLON => :SEMICOLON,
|
46
|
+
SDL::Key::LESS => :LESS_THAN,
|
47
|
+
SDL::Key::EQUALS => :EQUALS,
|
48
|
+
SDL::Key::GREATER => :GREATER_THAN,
|
49
|
+
SDL::Key::QUESTION => :QUESTION_MARK,
|
50
|
+
SDL::Key::AT => :AT,
|
51
|
+
SDL::Key::LEFTBRACKET => :OPEN_SQUARE_BRACKET,
|
52
|
+
SDL::Key::BACKSLASH => :BACKSLASH,
|
53
|
+
SDL::Key::RIGHTBRACKET => :CLOSE_SQUARE_BRACKET,
|
54
|
+
SDL::Key::CARET => :CARET,
|
55
|
+
SDL::Key::UNDERSCORE => :UNDERSCORE,
|
56
|
+
SDL::Key::BACKQUOTE => :BACKTICK,
|
57
|
+
SDL::Key::A => :A,
|
58
|
+
SDL::Key::B => :B,
|
59
|
+
SDL::Key::C => :C,
|
60
|
+
SDL::Key::D => :D,
|
61
|
+
SDL::Key::E => :E,
|
62
|
+
SDL::Key::F => :F,
|
63
|
+
SDL::Key::G => :G,
|
64
|
+
SDL::Key::H => :H,
|
65
|
+
SDL::Key::I => :I,
|
66
|
+
SDL::Key::J => :J,
|
67
|
+
SDL::Key::K => :K,
|
68
|
+
SDL::Key::L => :L,
|
69
|
+
SDL::Key::M => :M,
|
70
|
+
SDL::Key::N => :N,
|
71
|
+
SDL::Key::O => :O,
|
72
|
+
SDL::Key::P => :P,
|
73
|
+
SDL::Key::Q => :Q,
|
74
|
+
SDL::Key::R => :R,
|
75
|
+
SDL::Key::S => :S,
|
76
|
+
SDL::Key::T => :T,
|
77
|
+
SDL::Key::U => :U,
|
78
|
+
SDL::Key::V => :V,
|
79
|
+
SDL::Key::W => :W,
|
80
|
+
SDL::Key::X => :X,
|
81
|
+
SDL::Key::Y => :Y,
|
82
|
+
SDL::Key::Z => :Z,
|
83
|
+
SDL::Key::DELETE => :DELETE,
|
84
|
+
SDL::Key::KP0 => :NP0,
|
85
|
+
SDL::Key::KP1 => :NP1,
|
86
|
+
SDL::Key::KP2 => :NP2,
|
87
|
+
SDL::Key::KP3 => :NP3,
|
88
|
+
SDL::Key::KP4 => :NP4,
|
89
|
+
SDL::Key::KP5 => :NP5,
|
90
|
+
SDL::Key::KP6 => :NP6,
|
91
|
+
SDL::Key::KP7 => :NP7,
|
92
|
+
SDL::Key::KP8 => :NP8,
|
93
|
+
SDL::Key::KP9 => :NP9,
|
94
|
+
SDL::Key::KP_PERIOD => :NP_PERIOD,
|
95
|
+
SDL::Key::KP_DIVIDE => :NP_DIVIDE,
|
96
|
+
SDL::Key::KP_MULTIPLY => :NP_MULTIPLY,
|
97
|
+
SDL::Key::KP_MINUS => :NP_MINUS,
|
98
|
+
SDL::Key::KP_PLUS => :NP_PLUS,
|
99
|
+
SDL::Key::KP_ENTER => :NP_ENTER,
|
100
|
+
SDL::Key::KP_EQUALS => :NP_EQUALS,
|
101
|
+
SDL::Key::UP => :UP,
|
102
|
+
SDL::Key::DOWN => :DOWN,
|
103
|
+
SDL::Key::RIGHT => :RIGHT,
|
104
|
+
SDL::Key::LEFT => :LEFT,
|
105
|
+
SDL::Key::INSERT => :INSERT,
|
106
|
+
SDL::Key::HOME => :HOME,
|
107
|
+
SDL::Key::END => :END,
|
108
|
+
SDL::Key::PAGEUP => :PAGE_UP,
|
109
|
+
SDL::Key::PAGEDOWN => :PAGE_DOWN,
|
110
|
+
SDL::Key::F1 => :F1,
|
111
|
+
SDL::Key::F2 => :F2,
|
112
|
+
SDL::Key::F3 => :F3,
|
113
|
+
SDL::Key::F4 => :F4,
|
114
|
+
SDL::Key::F5 => :F5,
|
115
|
+
SDL::Key::F6 => :F6,
|
116
|
+
SDL::Key::F7 => :F7,
|
117
|
+
SDL::Key::F8 => :F8,
|
118
|
+
SDL::Key::F9 => :F9,
|
119
|
+
SDL::Key::F10 => :F10,
|
120
|
+
SDL::Key::F11 => :F11,
|
121
|
+
SDL::Key::F12 => :F12,
|
122
|
+
#SDL::Key::F13 => F13, # Who
|
123
|
+
#SDL::Key::F14 => F14, # has
|
124
|
+
#SDL::Key::F15 => F15, # these?
|
125
|
+
SDL::Key::NUMLOCK => :NUM_LOCK,
|
126
|
+
SDL::Key::CAPSLOCK => :CAPS_LOCK,
|
127
|
+
SDL::Key::SCROLLOCK => :SCROLL_LOCK,
|
128
|
+
SDL::Key::RSHIFT => :R_SHIFT,
|
129
|
+
SDL::Key::LSHIFT => :L_SHIFT,
|
130
|
+
SDL::Key::RCTRL => :R_CTRL,
|
131
|
+
SDL::Key::LCTRL => :L_CTRL,
|
132
|
+
SDL::Key::RALT => :R_ALT,
|
133
|
+
SDL::Key::LALT => :L_ALT,
|
134
|
+
#SDL::Key::RMETA => right meta, # 'meta' should
|
135
|
+
#SDL::Key::LMETA => left meta, # be 'alt'?
|
136
|
+
SDL::Key::LSUPER => :L_SUPER,
|
137
|
+
SDL::Key::RSUPER => :R_SUPER,
|
138
|
+
SDL::Key::MODE => :ALT_GR,
|
139
|
+
#SDL::Key::HELP => help, # Rare enough to cause problems.
|
140
|
+
SDL::Key::PRINT => :PRINT_SCREEN,
|
141
|
+
SDL::Key::SYSREQ => :SYS_REQ,
|
142
|
+
SDL::Key::BREAK => :BREAK,
|
143
|
+
SDL::Key::MENU => :MENU,
|
144
|
+
#SDL::Key::POWER => power, # "Power Macintosh" power key
|
145
|
+
SDL::Key::EURO => :EURO, # Some European keyboards need this.
|
146
|
+
}
|
147
|
+
|
148
|
+
# Call a block for each defined Tea key constant.
|
149
|
+
def Event.each_key
|
150
|
+
@@sdl_key_table.each_value { |key_const| yield key_const }
|
151
|
+
end
|
152
|
+
|
153
|
+
protected
|
154
|
+
|
155
|
+
# Convert an SDL keysym to a Tea key constant
|
156
|
+
def sdl_keysym_to_key(sdl_keysym)
|
157
|
+
@@sdl_key_table[sdl_keysym]
|
158
|
+
end
|
159
|
+
|
160
|
+
# Convert SDL key modifier info into an array of active key modifiers.
|
161
|
+
def sdl_keymod_to_mods(sdl_keymod)
|
162
|
+
mods = {}
|
163
|
+
|
164
|
+
mods[:L_SHIFT] = (sdl_keymod & SDL::Key::MOD_LSHIFT) != 0
|
165
|
+
mods[:R_SHIFT] = (sdl_keymod & SDL::Key::MOD_RSHIFT) != 0
|
166
|
+
mods[:SHIFT] = mods[:L_SHIFT] || mods[:R_SHIFT]
|
167
|
+
|
168
|
+
mods[:L_CTRL] = (sdl_keymod & SDL::Key::MOD_LCTRL) != 0
|
169
|
+
mods[:R_CTRL] = (sdl_keymod & SDL::Key::MOD_RCTRL) != 0
|
170
|
+
mods[:CTRL] = mods[:L_CTRL] || mods[:R_CTRL]
|
171
|
+
|
172
|
+
mods[:L_ALT] = (sdl_keymod & SDL::Key::MOD_LALT) != 0
|
173
|
+
mods[:R_ALT] = (sdl_keymod & SDL::Key::MOD_RALT) != 0
|
174
|
+
mods[:ALT] = mods[:L_ALT] || mods[:R_ALT]
|
175
|
+
|
176
|
+
mods[:NUM_LOCK] = (sdl_keymod & SDL::Key::MOD_NUM) != 0
|
177
|
+
mods[:CAPS_LOCK] = (sdl_keymod & SDL::Key::MOD_CAPS) != 0
|
178
|
+
mods[:ALT_GR] = (sdl_keymod & SDL::Key::MOD_MODE) != 0
|
179
|
+
|
180
|
+
mods
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
9
184
|
# Event generated when a key is pressed down.
|
10
185
|
#
|
11
186
|
# +key+:: Physical key that was pressed, as a symbol (see key reference).
|
@@ -18,11 +193,11 @@ module Tea
|
|
18
193
|
# +char+:: String character generated by that key and those modifiers.
|
19
194
|
# With Ruby >= 1.9, the encoding of this character is UTF-8,
|
20
195
|
# otherwise it varies with the running environment.
|
21
|
-
class Down
|
196
|
+
class Down < Event
|
22
197
|
attr_reader :key, :mods, :char
|
23
198
|
def initialize(sdl_event)
|
24
|
-
@key =
|
25
|
-
@mods =
|
199
|
+
@key = sdl_keysym_to_key(sdl_event.sym)
|
200
|
+
@mods = sdl_keymod_to_mods(sdl_event.mod)
|
26
201
|
|
27
202
|
# Ruby 1.9 uses UTF-8 Unicode encoding. Below this, who knows how
|
28
203
|
# Unicode code points are interpreted?
|
@@ -49,14 +224,27 @@ module Tea
|
|
49
224
|
# +:CAPS_LOCK+, +:ALT_GR+. Also, +:SHIFT+, +:CTRL+ and +:ALT+
|
50
225
|
# are provided for convenience, and Tea key constants with the
|
51
226
|
# same names can be used instead.
|
52
|
-
class Up
|
227
|
+
class Up < Event
|
53
228
|
attr_reader :key, :mods
|
54
229
|
def initialize(sdl_event)
|
55
|
-
@key =
|
56
|
-
@mods =
|
230
|
+
@key = sdl_keysym_to_key(sdl_event.sym)
|
231
|
+
@mods = sdl_keymod_to_mods(sdl_event.mod)
|
57
232
|
end
|
58
233
|
end
|
59
234
|
|
235
|
+
# Defaults for Kbd.key_down?, Kbd.mod_active? and Kbd.in_app?.
|
236
|
+
@key_states = {}
|
237
|
+
Event.each_key { |key| @key_states[key] = false }
|
238
|
+
|
239
|
+
@mod_states = { :L_SHIFT => false, :R_SHIFT => false, :SHIFT => false,
|
240
|
+
:L_CTRL => false, :R_CTRL => false, :CTRL => false,
|
241
|
+
:L_ALT => false, :R_ALT => false, :ALT => false,
|
242
|
+
:NUM_LOCK => false,
|
243
|
+
:CAPS_LOCK => false,
|
244
|
+
:ALT_GR => false }
|
245
|
+
|
246
|
+
@in_app = true
|
247
|
+
|
60
248
|
# Returns +true+ if +key+ is being pressed down.
|
61
249
|
def Kbd.key_down?(key)
|
62
250
|
if (down = @key_states[key]) == nil
|
@@ -78,7 +266,6 @@ module Tea
|
|
78
266
|
|
79
267
|
# Returns true if the keyboard is focused in the screen window.
|
80
268
|
def Kbd.in_app?
|
81
|
-
@in_app = true if !instance_variable_defined?(:@in_app)
|
82
269
|
@in_app
|
83
270
|
end
|
84
271
|
|
@@ -94,186 +281,14 @@ module Tea
|
|
94
281
|
end
|
95
282
|
end
|
96
283
|
|
97
|
-
# Decode the SDL key event mod into a hash of easily consulted key modifier
|
98
|
-
# symbols. For internal use only.
|
99
|
-
def Kbd.decode_modifiers(sdl_key_event_mod)
|
100
|
-
mods = {}
|
101
|
-
|
102
|
-
mods[:L_SHIFT] = (sdl_key_event_mod & SDL::Key::MOD_LSHIFT) != 0
|
103
|
-
mods[:R_SHIFT] = (sdl_key_event_mod & SDL::Key::MOD_RSHIFT) != 0
|
104
|
-
mods[:SHIFT] = mods[:L_SHIFT] || mods[:R_SHIFT]
|
105
|
-
|
106
|
-
mods[:L_CTRL] = (sdl_key_event_mod & SDL::Key::MOD_LCTRL) != 0
|
107
|
-
mods[:R_CTRL] = (sdl_key_event_mod & SDL::Key::MOD_RCTRL) != 0
|
108
|
-
mods[:CTRL] = mods[:L_CTRL] || mods[:R_CTRL]
|
109
|
-
|
110
|
-
mods[:L_ALT] = (sdl_key_event_mod & SDL::Key::MOD_LALT) != 0
|
111
|
-
mods[:R_ALT] = (sdl_key_event_mod & SDL::Key::MOD_RALT) != 0
|
112
|
-
mods[:ALT] = mods[:L_ALT] || mods[:R_ALT]
|
113
|
-
|
114
|
-
mods[:NUM_LOCK] = (sdl_key_event_mod & SDL::Key::MOD_NUM) != 0
|
115
|
-
mods[:CAPS_LOCK] = (sdl_key_event_mod & SDL::Key::MOD_CAPS) != 0
|
116
|
-
mods[:ALT_GR] = (sdl_key_event_mod & SDL::Key::MOD_MODE) != 0
|
117
|
-
|
118
|
-
mods
|
119
|
-
end
|
120
|
-
private_class_method :decode_modifiers
|
121
|
-
|
122
|
-
# Big fat table of SDL keys to Ruby strings. For internal use only.
|
123
|
-
@sdl_key_table = { SDL::Key::BACKSPACE => :BACKSPACE,
|
124
|
-
SDL::Key::TAB => :TAB,
|
125
|
-
#SDL::Key::CLEAR => clear, # ???
|
126
|
-
SDL::Key::RETURN => :ENTER,
|
127
|
-
SDL::Key::PAUSE => :PAUSE,
|
128
|
-
SDL::Key::ESCAPE => :ESCAPE,
|
129
|
-
SDL::Key::SPACE => :SPACE,
|
130
|
-
SDL::Key::EXCLAIM => :EXCLAMATION_MARK,
|
131
|
-
SDL::Key::QUOTEDBL => :DOUBLE_QUOTE,
|
132
|
-
SDL::Key::HASH => :HASH,
|
133
|
-
SDL::Key::DOLLAR => :DOLLAR,
|
134
|
-
SDL::Key::AMPERSAND => :AMPERSAND,
|
135
|
-
SDL::Key::QUOTE => :QUOTE,
|
136
|
-
SDL::Key::LEFTPAREN => :OPEN_PAREN,
|
137
|
-
SDL::Key::RIGHTPAREN => :CLOSE_PAREN,
|
138
|
-
SDL::Key::ASTERISK => :ASTERISK,
|
139
|
-
SDL::Key::PLUS => :PLUS,
|
140
|
-
SDL::Key::COMMA => :COMMA,
|
141
|
-
SDL::Key::MINUS => :MINUS,
|
142
|
-
SDL::Key::PERIOD => :PERIOD,
|
143
|
-
SDL::Key::SLASH => :SLASH,
|
144
|
-
SDL::Key::K0 => :K0,
|
145
|
-
SDL::Key::K1 => :K1,
|
146
|
-
SDL::Key::K2 => :K2,
|
147
|
-
SDL::Key::K3 => :K3,
|
148
|
-
SDL::Key::K4 => :K4,
|
149
|
-
SDL::Key::K5 => :K5,
|
150
|
-
SDL::Key::K6 => :K6,
|
151
|
-
SDL::Key::K7 => :K7,
|
152
|
-
SDL::Key::K8 => :K8,
|
153
|
-
SDL::Key::K9 => :K9,
|
154
|
-
SDL::Key::COLON => :COLON,
|
155
|
-
SDL::Key::SEMICOLON => :SEMICOLON,
|
156
|
-
SDL::Key::LESS => :LESS_THAN,
|
157
|
-
SDL::Key::EQUALS => :EQUALS,
|
158
|
-
SDL::Key::GREATER => :GREATER_THAN,
|
159
|
-
SDL::Key::QUESTION => :QUESTION_MARK,
|
160
|
-
SDL::Key::AT => :AT,
|
161
|
-
SDL::Key::LEFTBRACKET => :OPEN_SQUARE_BRACKET,
|
162
|
-
SDL::Key::BACKSLASH => :BACKSLASH,
|
163
|
-
SDL::Key::RIGHTBRACKET => :CLOSE_SQUARE_BRACKET,
|
164
|
-
SDL::Key::CARET => :CARET,
|
165
|
-
SDL::Key::UNDERSCORE => :UNDERSCORE,
|
166
|
-
SDL::Key::BACKQUOTE => :BACKTICK,
|
167
|
-
SDL::Key::A => :A,
|
168
|
-
SDL::Key::B => :B,
|
169
|
-
SDL::Key::C => :C,
|
170
|
-
SDL::Key::D => :D,
|
171
|
-
SDL::Key::E => :E,
|
172
|
-
SDL::Key::F => :F,
|
173
|
-
SDL::Key::G => :G,
|
174
|
-
SDL::Key::H => :H,
|
175
|
-
SDL::Key::I => :I,
|
176
|
-
SDL::Key::J => :J,
|
177
|
-
SDL::Key::K => :K,
|
178
|
-
SDL::Key::L => :L,
|
179
|
-
SDL::Key::M => :M,
|
180
|
-
SDL::Key::N => :N,
|
181
|
-
SDL::Key::O => :O,
|
182
|
-
SDL::Key::P => :P,
|
183
|
-
SDL::Key::Q => :Q,
|
184
|
-
SDL::Key::R => :R,
|
185
|
-
SDL::Key::S => :S,
|
186
|
-
SDL::Key::T => :T,
|
187
|
-
SDL::Key::U => :U,
|
188
|
-
SDL::Key::V => :V,
|
189
|
-
SDL::Key::W => :W,
|
190
|
-
SDL::Key::X => :X,
|
191
|
-
SDL::Key::Y => :Y,
|
192
|
-
SDL::Key::Z => :Z,
|
193
|
-
SDL::Key::DELETE => :DELETE,
|
194
|
-
SDL::Key::KP0 => :NP0,
|
195
|
-
SDL::Key::KP1 => :NP1,
|
196
|
-
SDL::Key::KP2 => :NP2,
|
197
|
-
SDL::Key::KP3 => :NP3,
|
198
|
-
SDL::Key::KP4 => :NP4,
|
199
|
-
SDL::Key::KP5 => :NP5,
|
200
|
-
SDL::Key::KP6 => :NP6,
|
201
|
-
SDL::Key::KP7 => :NP7,
|
202
|
-
SDL::Key::KP8 => :NP8,
|
203
|
-
SDL::Key::KP9 => :NP9,
|
204
|
-
SDL::Key::KP_PERIOD => :NP_PERIOD,
|
205
|
-
SDL::Key::KP_DIVIDE => :NP_DIVIDE,
|
206
|
-
SDL::Key::KP_MULTIPLY => :NP_MULTIPLY,
|
207
|
-
SDL::Key::KP_MINUS => :NP_MINUS,
|
208
|
-
SDL::Key::KP_PLUS => :NP_PLUS,
|
209
|
-
SDL::Key::KP_ENTER => :NP_ENTER,
|
210
|
-
SDL::Key::KP_EQUALS => :NP_EQUALS,
|
211
|
-
SDL::Key::UP => :UP,
|
212
|
-
SDL::Key::DOWN => :DOWN,
|
213
|
-
SDL::Key::RIGHT => :RIGHT,
|
214
|
-
SDL::Key::LEFT => :LEFT,
|
215
|
-
SDL::Key::INSERT => :INSERT,
|
216
|
-
SDL::Key::HOME => :HOME,
|
217
|
-
SDL::Key::END => :END,
|
218
|
-
SDL::Key::PAGEUP => :PAGE_UP,
|
219
|
-
SDL::Key::PAGEDOWN => :PAGE_DOWN,
|
220
|
-
SDL::Key::F1 => :F1,
|
221
|
-
SDL::Key::F2 => :F2,
|
222
|
-
SDL::Key::F3 => :F3,
|
223
|
-
SDL::Key::F4 => :F4,
|
224
|
-
SDL::Key::F5 => :F5,
|
225
|
-
SDL::Key::F6 => :F6,
|
226
|
-
SDL::Key::F7 => :F7,
|
227
|
-
SDL::Key::F8 => :F8,
|
228
|
-
SDL::Key::F9 => :F9,
|
229
|
-
SDL::Key::F10 => :F10,
|
230
|
-
SDL::Key::F11 => :F11,
|
231
|
-
SDL::Key::F12 => :F12,
|
232
|
-
#SDL::Key::F13 => F13, # Who
|
233
|
-
#SDL::Key::F14 => F14, # has
|
234
|
-
#SDL::Key::F15 => F15, # these?
|
235
|
-
SDL::Key::NUMLOCK => :NUM_LOCK,
|
236
|
-
SDL::Key::CAPSLOCK => :CAPS_LOCK,
|
237
|
-
SDL::Key::SCROLLOCK => :SCROLL_LOCK,
|
238
|
-
SDL::Key::RSHIFT => :R_SHIFT,
|
239
|
-
SDL::Key::LSHIFT => :L_SHIFT,
|
240
|
-
SDL::Key::RCTRL => :R_CTRL,
|
241
|
-
SDL::Key::LCTRL => :L_CTRL,
|
242
|
-
SDL::Key::RALT => :R_ALT,
|
243
|
-
SDL::Key::LALT => :L_ALT,
|
244
|
-
#SDL::Key::RMETA => right meta, # 'meta' should
|
245
|
-
#SDL::Key::LMETA => left meta, # be 'alt'?
|
246
|
-
SDL::Key::LSUPER => :L_SUPER,
|
247
|
-
SDL::Key::RSUPER => :R_SUPER,
|
248
|
-
SDL::Key::MODE => :ALT_GR,
|
249
|
-
#SDL::Key::HELP => help, # Rare enough to cause problems.
|
250
|
-
SDL::Key::PRINT => :PRINT_SCREEN,
|
251
|
-
SDL::Key::SYSREQ => :SYS_REQ,
|
252
|
-
SDL::Key::BREAK => :BREAK,
|
253
|
-
SDL::Key::MENU => :MENU,
|
254
|
-
#SDL::Key::POWER => power, # "Power Macintosh" power key
|
255
|
-
SDL::Key::EURO => :EURO, # Some European keyboards need this.
|
256
|
-
}
|
257
|
-
|
258
284
|
# Define Tea key symbols as constants to avoid typo errors.
|
259
|
-
|
285
|
+
Event.each_key { |key| const_set(key, key) }
|
260
286
|
|
261
287
|
# Extra modifier constants for making modifier detection more consistent.
|
262
|
-
SHIFT = :
|
263
|
-
CTRL = :
|
264
|
-
ALT = :
|
288
|
+
SHIFT = :SHIFT
|
289
|
+
CTRL = :CTRL
|
290
|
+
ALT = :ALT
|
265
291
|
|
266
|
-
# Initialise key states to false, as opposed to nil.
|
267
|
-
@key_states = {}
|
268
|
-
@sdl_key_table.each_value { |sym| @key_states[sym] = false }
|
269
|
-
|
270
|
-
# Modifier states, same deal.
|
271
|
-
@mod_states = { :L_SHIFT => false, :R_SHIFT => false, :SHIFT => false,
|
272
|
-
:L_CTRL => false, :R_CTRL => false, :CTRL => false,
|
273
|
-
:L_ALT => false, :R_ALT => false, :ALT => false,
|
274
|
-
:NUM_LOCK => false,
|
275
|
-
:CAPS_LOCK => false,
|
276
|
-
:ALT_GR => false }
|
277
292
|
end
|
278
293
|
|
279
294
|
module Event
|
data/lib/tea/m_event_mouse.rb
CHANGED
@@ -81,44 +81,47 @@ module Tea
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
# Defaults for Mouse.x, Mouse.y, Mouse.left?, Mouse.middle?, Mouse.right?
|
85
|
+
# and Mouse.in_app?
|
86
|
+
@x = 0
|
87
|
+
@y = 0
|
88
|
+
@left = false
|
89
|
+
@middle = false
|
90
|
+
@right = false
|
91
|
+
@in_app = false
|
92
|
+
|
84
93
|
# Report the x position of the mouse in the screen window. Updated when
|
85
94
|
# Event.get is called.
|
86
95
|
def Mouse.x
|
87
|
-
@x = 0 if !instance_variable_defined?(:@x)
|
88
96
|
@x
|
89
97
|
end
|
90
98
|
|
91
99
|
# Report the y position of the mouse in the screen window. Updated when
|
92
100
|
# Event.get is called.
|
93
101
|
def Mouse.y
|
94
|
-
@y = 0 if !instance_variable_defined?(:@y)
|
95
102
|
@y
|
96
103
|
end
|
97
104
|
|
98
105
|
# Returns true if the left mouse button is down. Updated when Event.get is
|
99
106
|
# called.
|
100
107
|
def Mouse.left?
|
101
|
-
@left = false if !instance_variable_defined?(:@left)
|
102
108
|
@left
|
103
109
|
end
|
104
110
|
|
105
111
|
# Returns true if the middle mouse button is down. Updated when Event.get
|
106
112
|
# is called.
|
107
113
|
def Mouse.middle?
|
108
|
-
@middle = false if !instance_variable_defined?(:@middle)
|
109
114
|
@middle
|
110
115
|
end
|
111
116
|
|
112
117
|
# Returns true if the right mouse button is down. Updated when Event.get
|
113
118
|
# is called.
|
114
119
|
def Mouse.right?
|
115
|
-
@right = false if !instance_variable_defined?(:@right)
|
116
120
|
@right
|
117
121
|
end
|
118
122
|
|
119
123
|
# Returns true if the mouse is in the screen window
|
120
124
|
def Mouse.in_app?
|
121
|
-
@in_app = true if !instance_variable_defined?(:@in_app)
|
122
125
|
@in_app
|
123
126
|
end
|
124
127
|
|
@@ -8,11 +8,11 @@ module Tea
|
|
8
8
|
# The Blitting mixin allows objects with SDL::Surface to draw or 'blit' onto
|
9
9
|
# each other.
|
10
10
|
#
|
11
|
-
# To use this mixin, include it and write/alias a
|
11
|
+
# To use this mixin, include it and write/alias a blitting_buffer method
|
12
12
|
# that gets the SDL::Surface.
|
13
13
|
#
|
14
14
|
# include Blitting
|
15
|
-
# def
|
15
|
+
# def blitting_buffer
|
16
16
|
# @my_sdl_surface
|
17
17
|
# end
|
18
18
|
module Blitting
|
@@ -21,8 +21,8 @@ module Tea
|
|
21
21
|
#
|
22
22
|
# source_blittable needs to include the Blitting mixin too.
|
23
23
|
def blit(source_blittable, x, y)
|
24
|
-
src = source_blittable.
|
25
|
-
dest =
|
24
|
+
src = source_blittable.blitting_buffer
|
25
|
+
dest = blitting_buffer
|
26
26
|
SDL::Surface.blit src, 0, 0, src.w, src.h, dest, x, y
|
27
27
|
end
|
28
28
|
|
@@ -12,7 +12,9 @@ module Tea
|
|
12
12
|
# that returns the buffer to be clipped.
|
13
13
|
#
|
14
14
|
# include Tea::Clipping
|
15
|
-
# def clipping_buffer
|
15
|
+
# def clipping_buffer
|
16
|
+
# @sdl_buffer
|
17
|
+
# end
|
16
18
|
module Clipping
|
17
19
|
|
18
20
|
# Get, set or run a block with a clipping rectangle that restricts where
|
@@ -5,19 +5,17 @@ require 'sdl'
|
|
5
5
|
#
|
6
6
|
module Tea
|
7
7
|
|
8
|
-
private
|
9
|
-
|
10
8
|
# The PrimitiveDrawing mixin enables primitive shapes to be drawn to classes
|
11
9
|
# with an internal SDL::Surface.
|
12
10
|
#
|
13
11
|
# To use this mixin, include it and implement/alias a +primitive_buffer+
|
14
12
|
# method that gets the object's SDL::Surface.
|
15
13
|
#
|
16
|
-
# include '
|
14
|
+
# include 'Primitive'
|
17
15
|
# def primitive_buffer
|
18
16
|
# @internal_sdl_buffer
|
19
17
|
# end
|
20
|
-
module
|
18
|
+
module Primitive
|
21
19
|
|
22
20
|
# Clear the drawing buffer. This is the same as drawing a completely black
|
23
21
|
# rectangle over the whole buffer.
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'sdl'
|
4
4
|
|
5
|
-
require 'tea/
|
6
|
-
require 'tea/
|
7
|
-
require 'tea/
|
5
|
+
require 'tea/mix_blitting'
|
6
|
+
require 'tea/mix_clipping'
|
7
|
+
require 'tea/mix_primitive'
|
8
8
|
|
9
9
|
#
|
10
10
|
module Tea
|
@@ -41,22 +41,34 @@ module Tea
|
|
41
41
|
@set_mode_callbacks = []
|
42
42
|
|
43
43
|
# Get the screen width in pixels.
|
44
|
-
def Screen.w
|
44
|
+
def Screen.w
|
45
|
+
@screen.w
|
46
|
+
end
|
45
47
|
|
46
48
|
# Get the screen height in pixels.
|
47
|
-
def Screen.h
|
49
|
+
def Screen.h
|
50
|
+
@screen.h
|
51
|
+
end
|
48
52
|
|
49
53
|
# Update the screen so that things drawn on it are displayed.
|
50
|
-
def Screen.update
|
54
|
+
def Screen.update
|
55
|
+
@screen.flip
|
56
|
+
end
|
51
57
|
|
52
58
|
extend Blitting
|
53
|
-
def Screen.
|
59
|
+
def Screen.blitting_buffer
|
60
|
+
@screen
|
61
|
+
end
|
54
62
|
|
55
63
|
extend Clipping
|
56
|
-
def Screen.clipping_buffer
|
64
|
+
def Screen.clipping_buffer
|
65
|
+
@screen
|
66
|
+
end
|
57
67
|
|
58
|
-
extend
|
59
|
-
def Screen.primitive_buffer
|
68
|
+
extend Primitive
|
69
|
+
def Screen.primitive_buffer
|
70
|
+
@screen
|
71
|
+
end
|
60
72
|
|
61
73
|
end
|
62
74
|
|
data/lib/tea.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tung-tea
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -67,15 +67,15 @@ files:
|
|
67
67
|
- lib/tea.rb
|
68
68
|
- lib/tea/c_bitmap.rb
|
69
69
|
- lib/tea/c_error.rb
|
70
|
-
- lib/tea/m_blitting.rb
|
71
|
-
- lib/tea/m_clipping.rb
|
72
70
|
- lib/tea/m_event.rb
|
73
71
|
- lib/tea/m_event_app.rb
|
74
72
|
- lib/tea/m_event_dispatch.rb
|
75
73
|
- lib/tea/m_event_keyboard.rb
|
76
74
|
- lib/tea/m_event_mouse.rb
|
77
|
-
- lib/tea/
|
78
|
-
- lib/tea/
|
75
|
+
- lib/tea/mix_blitting.rb
|
76
|
+
- lib/tea/mix_clipping.rb
|
77
|
+
- lib/tea/mix_primitive.rb
|
78
|
+
- lib/tea/o_screen.rb
|
79
79
|
has_rdoc: false
|
80
80
|
homepage: http://github.com/tung/tea
|
81
81
|
licenses:
|