rubygame 2.2.0-i586-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 +201 -0
- data/README +139 -0
- data/ROADMAP +43 -0
- data/Rakefile +409 -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/MANIFEST +25 -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 +108 -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 +33 -0
- data/ext/rubygame/rubygame_main.o +0 -0
- data/ext/rubygame/rubygame_mixer.c +764 -0
- data/ext/rubygame/rubygame_mixer.h +62 -0
- data/ext/rubygame/rubygame_mixer.o +0 -0
- data/ext/rubygame/rubygame_mixer.so +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 +209 -0
- data/ext/rubygame/rubygame_shared.h +60 -0
- data/ext/rubygame/rubygame_shared.o +0 -0
- data/ext/rubygame/rubygame_surface.c +1147 -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/MANIFEST +12 -0
- data/lib/rubygame/clock.rb +128 -0
- data/lib/rubygame/color/models/base.rb +106 -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/color.rb +79 -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/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/lib/rubygame.rb +41 -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 +313 -0
- data/samples/demo_gl.rb +151 -0
- data/samples/demo_gl_tex.rb +197 -0
- data/samples/demo_music.rb +75 -0
- data/samples/demo_rubygame.rb +284 -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
- metadata +152 -0
@@ -0,0 +1,223 @@
|
|
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
|
+
# *NOTE*: you must require 'rubygame/sfont' manually to gain access to
|
23
|
+
# Rubygame::SFont. It is not imported with Rubygame by default!
|
24
|
+
#
|
25
|
+
# SFont is a type of bitmapped font, which is loaded from an image file
|
26
|
+
# with a meaningful top row of pixels, and the font itself below that. The
|
27
|
+
# top row provides information about what parts of of the lower area
|
28
|
+
# contains font data, and which parts are empty.
|
29
|
+
#
|
30
|
+
# The image file should contain all of the glyphs on one row, with the
|
31
|
+
# colorkey color at the bottom-left pixel and the "skip" color at the
|
32
|
+
# top-left pixel.
|
33
|
+
#
|
34
|
+
# The colorkey color is applied to the image file when it is loaded, so
|
35
|
+
# that all pixels of that color appear transparent. Alternatively, if the
|
36
|
+
# alpha value of pixel [0,0] is 0 (that is, if it is fully transparent),
|
37
|
+
# the image file is assumed to have a proper alpha channel, and no colorkey
|
38
|
+
# is applied. The skip color is used in the top row of pixels to indicate
|
39
|
+
# that all the pixels below it contain empty space, and that the next
|
40
|
+
# pixel that is not the skip color marks the beginning of the next glyph.
|
41
|
+
#
|
42
|
+
# The official SFont homepage, with information on SFont and sample font
|
43
|
+
# files, can be found at http://www.linux-games.com/sfont/. More
|
44
|
+
# information on SFont, and a useful utility for automatically generating
|
45
|
+
# the top row for a font, can be found at: http://www.nostatic.org/sfont/
|
46
|
+
|
47
|
+
class SFont
|
48
|
+
@@default_glyphs = [\
|
49
|
+
"!",'"',"#","$","%","&","'","(",")","*","+",",","-",".","/","0",
|
50
|
+
"1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@",
|
51
|
+
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
|
52
|
+
"Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`",
|
53
|
+
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
|
54
|
+
"q","r","s","t","u","v","w","x","y","z","{","|","}","~"]
|
55
|
+
|
56
|
+
# Returns an array of strings, each string a single ASCII character
|
57
|
+
# from ! (33) to ~ (126). This is the default set of characters in a
|
58
|
+
# SFont. The full set is as follows:
|
59
|
+
#
|
60
|
+
# ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @
|
61
|
+
# 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 [ \ ] ^ _ `
|
62
|
+
# 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 { | } ~
|
63
|
+
def SFont.default_glyphs
|
64
|
+
@@default_glyphs
|
65
|
+
end
|
66
|
+
|
67
|
+
# Create a now SFont instance.
|
68
|
+
#
|
69
|
+
# This function takes these arguments:
|
70
|
+
# filename:: the name of the image file from which the font should be
|
71
|
+
# loaded. Or, a Surface with a font image on it. The
|
72
|
+
# Surface will be copied onto separate Surfaces for each
|
73
|
+
# glyph, so the original Surface can be recycled.
|
74
|
+
# glyphs:: array of strings, one for each glyph, in the order they
|
75
|
+
# are found in the image file. If glyphs is not provided,
|
76
|
+
# or is nil, it is assumed to be the normal SFont order;
|
77
|
+
# that is, ASCII characters ! (33) to ~ (126). See
|
78
|
+
# SFont.default_glyphs for a full list.
|
79
|
+
# spacew:: represents the width of a space character ( ). You can
|
80
|
+
# either specify the width in pixels, or specify a
|
81
|
+
# character whose width, as found in the image, should be
|
82
|
+
# used. Alternatively, you could add a space character to
|
83
|
+
# the list of glyphs, and to the image file. If +spacew+
|
84
|
+
# is not given or is nil, and the space character is not
|
85
|
+
# in the list of glyphs, it will have the same width as
|
86
|
+
# the double-quote character (").
|
87
|
+
def initialize(filename,glyphs=nil,spacew=nil)
|
88
|
+
# load the surface containing all the glyphs
|
89
|
+
surface = nil
|
90
|
+
if filename.is_a? String
|
91
|
+
surface = Surface.load_image(filename)
|
92
|
+
elsif filename.is_a? Surface
|
93
|
+
surface = filename
|
94
|
+
end
|
95
|
+
@height = surface.height
|
96
|
+
colorkey = surface.get_at(0,@height-1)
|
97
|
+
|
98
|
+
# set colorkey if "transparent" color is not actually transparent
|
99
|
+
if colorkey[3] != 0
|
100
|
+
surface.set_colorkey(colorkey[0..2])
|
101
|
+
end
|
102
|
+
|
103
|
+
@glyphs = {}
|
104
|
+
@skip = surface.get_at(0,0)[0..2]
|
105
|
+
|
106
|
+
# split the glyphs into separate surfaces
|
107
|
+
glyphs = (glyphs or @@default_glyphs)
|
108
|
+
start_x = 2
|
109
|
+
glyphs.each{ |glyph| start_x = load_glyph(surface,glyph,start_x) }
|
110
|
+
|
111
|
+
if not glyphs.include?(" ")
|
112
|
+
if spacew == nil
|
113
|
+
spacew = @glyphs['"'].width
|
114
|
+
elsif spacew.kind_of? Numeric
|
115
|
+
spacew = spacew.to_i
|
116
|
+
elsif spacew.kind_of? String
|
117
|
+
if glyphs.include? spacew
|
118
|
+
spacew = @glyphs[spacew].width
|
119
|
+
else
|
120
|
+
spacew = @glyphs['"'].width
|
121
|
+
end
|
122
|
+
else
|
123
|
+
raise(ArgumentError,"spacew must be Numeric, String, \
|
124
|
+
or nil (got %s)"%[spacew.class])
|
125
|
+
end
|
126
|
+
@glyphs[" "] = Surface.new([spacew,@height])
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Return the height of the font, in pixels. This is the same as the
|
131
|
+
# height of the image file (all glyphs are the same height).
|
132
|
+
attr_reader :height
|
133
|
+
|
134
|
+
# This is a private function which is used to parse the font image.
|
135
|
+
#
|
136
|
+
# Create a Surface for a single glyph, and store it as a value in the
|
137
|
+
# +@glyphs+ hash, indexed by the glyph (string) it represents.
|
138
|
+
#
|
139
|
+
# Starting at a pixel in the "skip" region to the left of the glyph.
|
140
|
+
# Scans to the right along the top row until it finds a non-skip pixel
|
141
|
+
# (this is where the glyph starts) and then scans until it finds a skip
|
142
|
+
# pixel (this is where the glyph ends.
|
143
|
+
#
|
144
|
+
# Returns the x value it stops at, plus 1. This should be fed back in
|
145
|
+
# for the +start_x+ of the next glyph.
|
146
|
+
#
|
147
|
+
# This _private_ method takes these arguments:
|
148
|
+
# surface:: the Surface containing all glyph image data.
|
149
|
+
# glyph:: a string containing the current glyph
|
150
|
+
# start_x:: the x position to start scanning at.
|
151
|
+
def load_glyph(surface,glyph,start_x) # :doc:
|
152
|
+
# find where this glyph starts
|
153
|
+
begin
|
154
|
+
while(surface.get_at(start_x,0)[0..2] == @skip)
|
155
|
+
start_x += 1
|
156
|
+
end
|
157
|
+
rescue IndexError
|
158
|
+
return -1
|
159
|
+
end
|
160
|
+
|
161
|
+
end_x = start_x
|
162
|
+
|
163
|
+
# find how wide this glyph is
|
164
|
+
begin
|
165
|
+
while(surface.get_at(end_x,0)[0..2] != @skip)
|
166
|
+
end_x += 1
|
167
|
+
end
|
168
|
+
rescue IndexError
|
169
|
+
return -1
|
170
|
+
end
|
171
|
+
|
172
|
+
# make a new surface for the glyph and blit the image onto it
|
173
|
+
rect = Rect.new(start_x, 0, end_x-start_x, surface.h)
|
174
|
+
@glyphs[glyph] = Surface.new(rect.size)
|
175
|
+
surface.blit(@glyphs[glyph],[0,0],rect)
|
176
|
+
|
177
|
+
return end_x+1
|
178
|
+
end
|
179
|
+
private :load_glyph
|
180
|
+
|
181
|
+
# This is a private function which is used to render a string.
|
182
|
+
#
|
183
|
+
# Blit a single glyph to a Surface at the given position.
|
184
|
+
#
|
185
|
+
# This _private_ method takes these arguments:
|
186
|
+
# glyph:: a string containing the glyph to blit.
|
187
|
+
# surface:: the target surface to blit onto.
|
188
|
+
# pos:: an Array of the x and y values to blit the glyph to.
|
189
|
+
def blit_glyph(glyph,surface,pos) # :doc:
|
190
|
+
@glyphs[glyph].blit(surface,pos)
|
191
|
+
end
|
192
|
+
private :blit_glyph
|
193
|
+
|
194
|
+
# Pretends to render the given string, and returns the width in pixels
|
195
|
+
# of the surface that would be created if it were rendered using
|
196
|
+
# SFont#render. If you want the height too, you can get it with
|
197
|
+
# SFont#height (the height is contant).
|
198
|
+
#
|
199
|
+
# This method takes this argument:
|
200
|
+
# string:: the string to pretend to render.
|
201
|
+
def string_width(string)
|
202
|
+
w = 0
|
203
|
+
string.each_byte { |glyph| w += @glyphs["%c"%[glyph]].width }
|
204
|
+
return w
|
205
|
+
end
|
206
|
+
|
207
|
+
# Renders the given string to a Surface, and returns that surface.
|
208
|
+
#
|
209
|
+
# This method takes this argument:
|
210
|
+
# string:: the text string to render.
|
211
|
+
def render(string)
|
212
|
+
size = [self.string_width(string),self.height]
|
213
|
+
render = Surface.new(size)
|
214
|
+
x = 0
|
215
|
+
string.each_byte { |glyph|
|
216
|
+
blit_glyph("%c"%[glyph],render,[x,0])
|
217
|
+
x += @glyphs["%c"%[glyph]].width
|
218
|
+
}
|
219
|
+
return render
|
220
|
+
end
|
221
|
+
end # class SFont
|
222
|
+
|
223
|
+
end # module Rubygame
|