tung-tea 0.0.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/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/README.rdoc +99 -0
- data/doc/example/bitmap_draw.rb +21 -0
- data/doc/example/bitmap_load.rb +14 -0
- data/doc/example/circles.rb +24 -0
- data/doc/example/event_app.rb +45 -0
- data/doc/example/event_keyboard.rb +43 -0
- data/doc/example/event_mouse.rb +85 -0
- data/doc/example/init.rb +10 -0
- data/doc/example/lines.rb +49 -0
- data/doc/example/point.rb +26 -0
- data/doc/example/rect.rb +15 -0
- data/doc/example/screen_set_mode.rb +18 -0
- data/doc/example/screen_update.rb +14 -0
- data/doc/example/smile.png +0 -0
- data/doc/example/smile_bounce.rb +44 -0
- data/doc/example/smile_move.rb +56 -0
- data/doc/example/state_app.rb +33 -0
- data/doc/example/state_keyboard.rb +23 -0
- data/doc/example/state_mouse.rb +60 -0
- data/lib/tea/c_bitmap.rb +55 -0
- data/lib/tea/c_error.rb +10 -0
- data/lib/tea/m_blitting.rb +31 -0
- data/lib/tea/m_event.rb +65 -0
- data/lib/tea/m_event_app.rb +91 -0
- data/lib/tea/m_event_keyboard.rb +299 -0
- data/lib/tea/m_event_mouse.rb +190 -0
- data/lib/tea/m_primitive_drawing.rb +79 -0
- data/lib/tea/screen.rb +59 -0
- data/lib/tea.rb +29 -0
- metadata +92 -0
data/COPYING.LESSER
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.rdoc
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
= tea
|
2
|
+
|
3
|
+
<i>For simpler games from a simpler age.</i>
|
4
|
+
|
5
|
+
Tea is a simple 2D game development library for Ruby. It's designed with these
|
6
|
+
things in mind:
|
7
|
+
|
8
|
+
* 0 is better than 1, and 1 is better than 2.
|
9
|
+
* Simplicity beats speed.
|
10
|
+
* Value and convenience can sometimes beat simplicity.
|
11
|
+
* Procedural beats object-oriented in a dead-heat.
|
12
|
+
|
13
|
+
The aim of Tea is to bring back some of the grass roots game development that
|
14
|
+
things like QBASIC fostered. By staying unobtrusive and out of the way, Tea
|
15
|
+
lets you focus on your game or demo, and not the pointy bits that are part of
|
16
|
+
many game engines and APIs.
|
17
|
+
|
18
|
+
|
19
|
+
== Installing
|
20
|
+
|
21
|
+
TODO
|
22
|
+
|
23
|
+
|
24
|
+
== Using Tea
|
25
|
+
|
26
|
+
First, require 'tea'. This allows you to start using the rest of the Tea API.
|
27
|
+
|
28
|
+
From there, you have access to all of Tea's modules, objects and methods.
|
29
|
+
Below is a simple bouncing circle demo.
|
30
|
+
|
31
|
+
require 'tea'
|
32
|
+
|
33
|
+
Tea.init
|
34
|
+
Tea::Screen.set_mode 640, 480
|
35
|
+
|
36
|
+
x, y = 320, 240
|
37
|
+
dx, dy = rand() * 2 - 1, rand() * 2 - 1
|
38
|
+
r = 20
|
39
|
+
|
40
|
+
loop do
|
41
|
+
if e = Tea::Event.get
|
42
|
+
break if e.class == Tea::App::Exit
|
43
|
+
end
|
44
|
+
|
45
|
+
x += dx
|
46
|
+
y += dy
|
47
|
+
dx = -dx if x - r < 0 || x + r >= Tea::Screen.w
|
48
|
+
dy = -dy if y - r < 0 || y + r >= Tea::Screen.h
|
49
|
+
|
50
|
+
Tea::Screen.clear
|
51
|
+
Tea::Screen.circle x, y, r, 0xff00ffff
|
52
|
+
Tea::Screen.update
|
53
|
+
|
54
|
+
sleep 0.001
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
== Status
|
59
|
+
|
60
|
+
What's done:
|
61
|
+
|
62
|
+
* Graphics
|
63
|
+
- Tea::Screen
|
64
|
+
- Tea::Bitmap (loaded from PNGs)
|
65
|
+
- Drawing of bitmaps on the screen/other bitmaps.
|
66
|
+
- Drawing of primitive shapes (rects, lines, circles).
|
67
|
+
* Events
|
68
|
+
- Tea::Event.get.
|
69
|
+
- Tea::App::Minimized, Restored.
|
70
|
+
- Tea::Kbd::Down, Up.
|
71
|
+
- Tea::Mouse::Move, Down, Up, Scroll.
|
72
|
+
- State checking of App, Kbd, Mouse.
|
73
|
+
|
74
|
+
What isn't done yet:
|
75
|
+
|
76
|
+
* Sound
|
77
|
+
* Screen resizing
|
78
|
+
* Handling of alpha in colours for primitives
|
79
|
+
|
80
|
+
What's still on the drawing board:
|
81
|
+
|
82
|
+
* Timed game loop code
|
83
|
+
* Resource management
|
84
|
+
|
85
|
+
|
86
|
+
== License
|
87
|
+
|
88
|
+
Tea is free software: you can redistribute it and/or modify it under the terms
|
89
|
+
of the GNU Lesser General Public License as published by the Free Software
|
90
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
91
|
+
version. Tea is distributed in the hope that it will be useful, but WITHOUT
|
92
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
93
|
+
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
94
|
+
details.
|
95
|
+
|
96
|
+
You should have received a copy of the GNU Lesser General Public License along
|
97
|
+
with Tea. If not, see <http://www.gnu.org/licenses/>.
|
98
|
+
|
99
|
+
Copyright (c) 2009 Tung Nguyen.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Test if an image can be loaded and drawn to the screen.
|
2
|
+
# Expected result is a 320x240 display with a smile in the middle for 2
|
3
|
+
# seconds.
|
4
|
+
|
5
|
+
require 'tea'
|
6
|
+
|
7
|
+
puts <<TEST
|
8
|
+
You should see a 320x240 window with a smile in the centre.
|
9
|
+
TEST
|
10
|
+
|
11
|
+
Tea.init
|
12
|
+
Tea::Screen.set_mode 320, 240
|
13
|
+
|
14
|
+
image = Tea::Bitmap.new('smile.png')
|
15
|
+
x = (Tea::Screen.w - image.w) / 2
|
16
|
+
y = (Tea::Screen.h - image.h) / 2
|
17
|
+
|
18
|
+
Tea::Screen.blit image, x, y
|
19
|
+
Tea::Screen.update
|
20
|
+
|
21
|
+
sleep 2
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Test if a bitmap can be loaded.
|
2
|
+
# Expected result
|
3
|
+
#
|
4
|
+
# image size is 32x32
|
5
|
+
|
6
|
+
require 'tea'
|
7
|
+
|
8
|
+
puts <<TEST
|
9
|
+
The following line should read "image size is 32x32"
|
10
|
+
TEST
|
11
|
+
|
12
|
+
Tea.init
|
13
|
+
image = Tea::Bitmap.new('smile.png')
|
14
|
+
puts "image size is #{image.w}x#{image.h}"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Test circle drawing.
|
2
|
+
# Expected results are a large white circle behind 2 smaller green and red
|
3
|
+
# circles, in a 400x300 window for 3 seconds.
|
4
|
+
|
5
|
+
require 'tea'
|
6
|
+
|
7
|
+
puts <<TEST
|
8
|
+
You should see a 400x300 window for 3 seconds with:
|
9
|
+
|
10
|
+
* A large white circle
|
11
|
+
* A small green circle on the left, antialiased
|
12
|
+
* A small red circle on the right, outlined
|
13
|
+
TEST
|
14
|
+
|
15
|
+
Tea.init
|
16
|
+
Tea::Screen.set_mode 400, 300
|
17
|
+
|
18
|
+
Tea::Screen.circle 200, 150, 100, 0xffffffff
|
19
|
+
Tea::Screen.circle 100, 150, 50, 0x00ff00ff, :antialias => true
|
20
|
+
Tea::Screen.circle 300, 150, 50, 0xff0000ff, :outline => true
|
21
|
+
|
22
|
+
Tea::Screen.update
|
23
|
+
|
24
|
+
sleep 3
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Test that app events are being picked up.
|
2
|
+
# This test is interactive, and should display messages for:
|
3
|
+
#
|
4
|
+
# * Gaining and losing mouse focus
|
5
|
+
# * Gaining and losing keyboard focus
|
6
|
+
# * Minimising and restoring the screen window
|
7
|
+
# * App exit
|
8
|
+
|
9
|
+
require 'tea'
|
10
|
+
|
11
|
+
puts <<TEST
|
12
|
+
This is an interactive event test. It should display messages for:
|
13
|
+
|
14
|
+
* Gaining and losing mouse focus
|
15
|
+
* Gaining and losing keyboard focus
|
16
|
+
* Minimising and restoring the screen window
|
17
|
+
* App exit
|
18
|
+
|
19
|
+
Go ahead and start doing things like changing focus.
|
20
|
+
|
21
|
+
TEST
|
22
|
+
|
23
|
+
Tea.init
|
24
|
+
Tea::Screen.set_mode 320, 240
|
25
|
+
|
26
|
+
loop do
|
27
|
+
case (e = Tea::Event.get)
|
28
|
+
when Tea::Mouse::Gained
|
29
|
+
puts 'Mouse::Gained event received'
|
30
|
+
when Tea::Mouse::Lost
|
31
|
+
puts 'Mouse::Lost event received'
|
32
|
+
when Tea::Kbd::Gained
|
33
|
+
puts 'Kbd::Gained event received'
|
34
|
+
when Tea::Kbd::Lost
|
35
|
+
puts 'Kbd::Lost event received'
|
36
|
+
when Tea::App::Restored
|
37
|
+
puts 'App::Restored event received'
|
38
|
+
when Tea::App::Minimized
|
39
|
+
puts 'App::Minimized event received'
|
40
|
+
when Tea::App::Exit
|
41
|
+
puts 'App::Exit event received'
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
sleep 0.01
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Test that keyboard events are being picked up.
|
2
|
+
# Expected results are messages responding to key presses.
|
3
|
+
|
4
|
+
require 'tea'
|
5
|
+
|
6
|
+
puts <<TEST
|
7
|
+
You should see a small window. Try pressing some keys, or Esc to exit.
|
8
|
+
TEST
|
9
|
+
|
10
|
+
Tea.init
|
11
|
+
Tea::Screen.set_mode 320, 240
|
12
|
+
|
13
|
+
loop do
|
14
|
+
e = Tea::Event.get(true)
|
15
|
+
|
16
|
+
break if e.class == Tea::App::Exit
|
17
|
+
next unless e.class == Tea::Kbd::Down || e.class == Tea::Kbd::Up
|
18
|
+
break if e.key == Tea::Kbd::ESCAPE
|
19
|
+
|
20
|
+
out = []
|
21
|
+
|
22
|
+
if e.class == Tea::Kbd::Down
|
23
|
+
out << 'down:'
|
24
|
+
else
|
25
|
+
out << ' up:'
|
26
|
+
end
|
27
|
+
|
28
|
+
out << '(' << e.key.to_s << ')'
|
29
|
+
|
30
|
+
if RUBY_VERSION =~ /1\.8/
|
31
|
+
mods = (e.mods.select { |mod, down| down }).map { |pair| pair[0] }
|
32
|
+
else
|
33
|
+
mods = (e.mods.select { |mod, down| down }).keys
|
34
|
+
end
|
35
|
+
out << "++ #{mods.join(' + ')}" if mods.length > 0
|
36
|
+
|
37
|
+
if e.respond_to?(:char)
|
38
|
+
out << '='
|
39
|
+
out << "\"#{e.char}\""
|
40
|
+
end
|
41
|
+
|
42
|
+
puts out.join(' ')
|
43
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Test that mouse events are being picked up.
|
2
|
+
# Expected output is reporting of mouse move/down/up/scroll events, with
|
3
|
+
# position and relevant buttons.
|
4
|
+
|
5
|
+
require 'tea'
|
6
|
+
|
7
|
+
puts <<TEST
|
8
|
+
Move the mouse in the window. Mouse move/down/up events should be reported,
|
9
|
+
with position and relevant buttons. Mouse wheel scrolling should also be
|
10
|
+
picked up, with at least the cursor position.
|
11
|
+
TEST
|
12
|
+
|
13
|
+
##############################################################################
|
14
|
+
|
15
|
+
# We can avoid flooding the terminal with VT100 codes. Sorry Windows.
|
16
|
+
$windows = RUBY_PLATFORM =~ /w(?:in)?32/
|
17
|
+
SAVE_POSITION = "\x1b[s"
|
18
|
+
RESTORE_POSITION = "\x1b[u"
|
19
|
+
HIDE_CURSOR = "\x1b[?25l"
|
20
|
+
UNHIDE_CURSOR = "\x1b[?25h"
|
21
|
+
CLEAR_TO_LINE_END = "\x1b[K"
|
22
|
+
|
23
|
+
# VT100-enhanced printing function that overwrites the current terminal line.
|
24
|
+
def pr(*args)
|
25
|
+
print HIDE_CURSOR, SAVE_POSITION if !$windows
|
26
|
+
print *args
|
27
|
+
if $windows
|
28
|
+
puts
|
29
|
+
else
|
30
|
+
print CLEAR_TO_LINE_END, RESTORE_POSITION, UNHIDE_CURSOR
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
##############################################################################
|
35
|
+
|
36
|
+
Tea.init
|
37
|
+
Tea::Screen.set_mode 400, 300
|
38
|
+
|
39
|
+
# Event tracking to only put newlines when the event class changes.
|
40
|
+
mouse_events = [Tea::Mouse::Move,
|
41
|
+
Tea::Mouse::Down,
|
42
|
+
Tea::Mouse::Up,
|
43
|
+
Tea::Mouse::Scroll]
|
44
|
+
handled = false
|
45
|
+
last_event_class = Tea::Mouse::Move
|
46
|
+
|
47
|
+
# Track repeated scrolling in the same direction.
|
48
|
+
scroll_pos = 0
|
49
|
+
|
50
|
+
loop do
|
51
|
+
e = Tea::Event.get(true)
|
52
|
+
|
53
|
+
if e.class == Tea::App::Exit
|
54
|
+
puts
|
55
|
+
break
|
56
|
+
end
|
57
|
+
|
58
|
+
# Put a newline when the event class changes.
|
59
|
+
if handled && mouse_events.include?(e.class) && e.class != last_event_class
|
60
|
+
puts
|
61
|
+
last_event_class = e.class
|
62
|
+
scroll_pos = 0
|
63
|
+
end
|
64
|
+
|
65
|
+
handled = true
|
66
|
+
case e
|
67
|
+
when Tea::Mouse::Move
|
68
|
+
if RUBY_VERSION =~ /1\.8/
|
69
|
+
buttons = (e.buttons.select { |button, down| down }).map { |pair| pair[0] }
|
70
|
+
else
|
71
|
+
buttons = (e.buttons.select { |button, down| down }).keys
|
72
|
+
end
|
73
|
+
pr "mouse move : x = #{e.x}, y = #{e.y}, buttons = #{buttons.join(',')}"
|
74
|
+
when Tea::Mouse::Down
|
75
|
+
pr "mouse down : x = #{e.x}, y = #{e.y}, button = #{e.button}"
|
76
|
+
when Tea::Mouse::Up
|
77
|
+
pr "mouse up : x = #{e.x}, y = #{e.y}, button = #{e.button}"
|
78
|
+
when Tea::Mouse::Scroll
|
79
|
+
dir = e.delta == 1 ? 'down' : 'up '
|
80
|
+
scroll_pos += e.delta
|
81
|
+
pr "scroll #{dir}: x = #{e.x}, y = #{e.y}, position = #{scroll_pos} (#{e.delta})"
|
82
|
+
else
|
83
|
+
handled = false
|
84
|
+
end
|
85
|
+
end
|
data/doc/example/init.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Test that lines of various colours can be drawn.
|
2
|
+
# Expected results are a 400x300 for 5 seconds with:
|
3
|
+
#
|
4
|
+
# * 3 vertical lines on the left: red, green, blue
|
5
|
+
# * 3 horizontal lines at the top-right: yellow, magenta, cyan
|
6
|
+
# * 2 diagonal lines at the bottom-right: white and grey
|
7
|
+
#
|
8
|
+
# The white line should be antialiased.
|
9
|
+
|
10
|
+
require 'tea'
|
11
|
+
|
12
|
+
puts <<TEST
|
13
|
+
You should see a 400x300 window for 5 seconds with:
|
14
|
+
|
15
|
+
* 3 vertical lines on the left: red, green, blue
|
16
|
+
* 3 horizontal lines at the top-right: yellow, magenta, cyan
|
17
|
+
* 2 diagonal lines at the bottom-right: white and grey
|
18
|
+
|
19
|
+
The white line should be antialiased.
|
20
|
+
TEST
|
21
|
+
|
22
|
+
Tea.init
|
23
|
+
Tea::Screen.set_mode 400, 300
|
24
|
+
|
25
|
+
grid_x = Tea::Screen.w / 10
|
26
|
+
grid_y = Tea::Screen.h / 10
|
27
|
+
|
28
|
+
lines = [[1, 1, 1, 9, 0xff0000ff],
|
29
|
+
[2, 1, 2, 9, 0x00ff00ff],
|
30
|
+
[3, 1, 3, 9, 0x0000ffff],
|
31
|
+
[6, 1, 9, 1, 0xffff00ff],
|
32
|
+
[6, 2, 9, 2, 0xff00ffff],
|
33
|
+
[6, 3, 9, 3, 0x00ffffff],
|
34
|
+
[6, 9, 9, 6, 0x808080ff]]
|
35
|
+
|
36
|
+
lines.each do |line|
|
37
|
+
Tea::Screen.line grid_x * line[0], grid_y * line[1],
|
38
|
+
grid_x * line[2], grid_y * line[3],
|
39
|
+
line[4]
|
40
|
+
end
|
41
|
+
|
42
|
+
Tea::Screen.line grid_x * 6, grid_y * 6,
|
43
|
+
grid_x * 9, grid_y * 9,
|
44
|
+
0xffffffff,
|
45
|
+
:antialias => true
|
46
|
+
|
47
|
+
Tea::Screen.update
|
48
|
+
|
49
|
+
sleep 5
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Test that Tea can plot points on bitmaps, e.g. the screen.
|
2
|
+
# Expected result is 4 points drawn as a rectangle in a 400x300 window for 2
|
3
|
+
# seconds.
|
4
|
+
|
5
|
+
require 'tea'
|
6
|
+
|
7
|
+
puts <<TEST
|
8
|
+
4 coloured points should appear in a rectangle formation, in a 400x300 window
|
9
|
+
for 2 seconds. Point formation:
|
10
|
+
|
11
|
+
red --- green
|
12
|
+
| |
|
13
|
+
blue -- white
|
14
|
+
TEST
|
15
|
+
|
16
|
+
Tea.init
|
17
|
+
Tea::Screen.set_mode 400, 300
|
18
|
+
|
19
|
+
Tea::Screen.point 100, 75, 0xff0000ff
|
20
|
+
Tea::Screen.point 300, 75, 0x00ff00ff
|
21
|
+
Tea::Screen.point 100, 225, 0x0000ffff
|
22
|
+
Tea::Screen.point 300, 225, 0xffffffff
|
23
|
+
|
24
|
+
Tea::Screen.update
|
25
|
+
|
26
|
+
sleep 2
|
data/doc/example/rect.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Test that filled rectangles can be drawn.
|
2
|
+
# Expected results are a 400x300 window, with a filled yellow rectangle in it.
|
3
|
+
|
4
|
+
require 'tea'
|
5
|
+
|
6
|
+
puts <<TEST
|
7
|
+
A 400x300 window should appear with a yellow rectangle for 2 seconds.
|
8
|
+
TEST
|
9
|
+
|
10
|
+
Tea.init
|
11
|
+
Tea::Screen.set_mode 400, 300
|
12
|
+
Tea::Screen.rect 50, 50, 300, 200, 0xffff00ff
|
13
|
+
Tea::Screen.update
|
14
|
+
|
15
|
+
sleep 2
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Test if the screen can initialise.
|
2
|
+
# Expected results:
|
3
|
+
#
|
4
|
+
# * output of "screen size is 320x240"
|
5
|
+
# * a blank 320x240 display window for 2 seconds.
|
6
|
+
|
7
|
+
require 'tea'
|
8
|
+
|
9
|
+
puts <<TEST
|
10
|
+
You should see a 320x240 window for 2 seconds, and the text "screen size is 320x240"
|
11
|
+
TEST
|
12
|
+
|
13
|
+
Tea.init
|
14
|
+
Tea::Screen.set_mode 320, 240
|
15
|
+
|
16
|
+
puts "screen size is #{Tea::Screen.w}x#{Tea::Screen.h}"
|
17
|
+
|
18
|
+
sleep 2
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Test if the screen can be updated without problems.
|
2
|
+
# Expected result is a 320x240 graphical window shown for 2 seconds.
|
3
|
+
|
4
|
+
require 'tea'
|
5
|
+
|
6
|
+
puts <<TEST
|
7
|
+
You should see a 320x240 window appear for 2 seconds.
|
8
|
+
TEST
|
9
|
+
|
10
|
+
Tea.init
|
11
|
+
Tea::Screen.set_mode 320, 240
|
12
|
+
Tea::Screen.update
|
13
|
+
|
14
|
+
sleep 2
|
Binary file
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# This is a demo of 5 smiley faces bouncing around a small screen.
|
2
|
+
|
3
|
+
require 'tea'
|
4
|
+
|
5
|
+
puts <<TEST
|
6
|
+
You should see 5 smiley faces bouncing around on a 320x240 screen for 5 seconds.
|
7
|
+
TEST
|
8
|
+
|
9
|
+
class Smiley
|
10
|
+
def initialize(bitmap, start_x=0, start_y=0)
|
11
|
+
@bitmap = bitmap
|
12
|
+
@x = start_x
|
13
|
+
@y = start_y
|
14
|
+
@dx = rand() * 2 - 1
|
15
|
+
@dy = rand() * 2 - 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
@x += @dx
|
20
|
+
@y += @dy
|
21
|
+
@dx = -@dx if @x < 0 || @x + @bitmap.w >= Tea::Screen.w
|
22
|
+
@dy = -@dy if @y < 0 || @y + @bitmap.h >= Tea::Screen.h
|
23
|
+
end
|
24
|
+
|
25
|
+
def draw
|
26
|
+
Tea::Screen.blit @bitmap, @x, @y
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Tea.init
|
31
|
+
Tea::Screen.set_mode 320, 240
|
32
|
+
|
33
|
+
smile_bitmap = Tea::Bitmap.new('smile.png')
|
34
|
+
smiles = []
|
35
|
+
5.times { smiles << Smiley.new(smile_bitmap, rand(288), rand(208)) }
|
36
|
+
|
37
|
+
start = Time.now
|
38
|
+
until Time.now >= start + 5
|
39
|
+
smiles.each { |s| s.update }
|
40
|
+
Tea::Screen.clear
|
41
|
+
smiles.each { |s| s.draw }
|
42
|
+
Tea::Screen.update
|
43
|
+
sleep 0.001
|
44
|
+
end
|