rubygame 2.6.3 → 2.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +16 -0
- data/doc/surface_palettes.rdoc +8 -0
- data/lib/rubygame/color.rb +3 -13
- data/lib/rubygame/color/models/hsl.rb +0 -8
- data/lib/rubygame/color/models/hsv.rb +0 -8
- data/lib/rubygame/color/models/rgb.rb +0 -8
- data/lib/rubygame/color/palettes/palette.rb +0 -3
- data/lib/rubygame/deprecated_mixer.rb +2 -2
- data/lib/rubygame/image.rb +1 -1
- data/lib/rubygame/main.rb +1 -1
- data/lib/rubygame/music.rb +1 -1
- data/lib/rubygame/screen.rb +2 -96
- data/lib/rubygame/sound.rb +1 -1
- data/lib/rubygame/surface.rb +8 -124
- data/lib/rubygame/ttf.rb +1 -1
- data/samples/demo_curve.rb +177 -0
- data/samples/demo_gl.rb +1 -1
- data/samples/demo_gl_tex.rb +1 -1
- metadata +6 -4
data/NEWS
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
= NEWS
|
2
2
|
|
3
|
+
== Rubygame 2.6.4
|
4
|
+
|
5
|
+
Release focus: Bug fix.
|
6
|
+
|
7
|
+
=== Fixes
|
8
|
+
|
9
|
+
- Fixed: Rubygame's "require_path" setting in the gem spec was
|
10
|
+
interfering with ruby-opengl (and potentially others). [#43]
|
11
|
+
|
12
|
+
If you have problems loading ruby-opengl when Rubygame 2.6.* is
|
13
|
+
installed via RubyGems, you should uninstall all versions of the
|
14
|
+
Rubygame gem, then reinstall version 2.6.4 (or later).
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
3
19
|
== Rubygame 2.6.3
|
4
20
|
|
5
21
|
Release focus: Bug fixes.
|
data/lib/rubygame/color.rb
CHANGED
@@ -102,19 +102,9 @@ module Rubygame
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def self.make_sdl_rgba( color ) # :nodoc:
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
r,g,b,a = convert_color(color).collect!{ |c| c.to_i }[0,4]
|
109
|
-
a ||= 255
|
110
|
-
[r,g,b,a].freeze
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
def self.remove_from_cache( color_name )
|
116
|
-
@rgba_cache ||= {}
|
117
|
-
@rgba_cache.delete( color_name )
|
105
|
+
r,g,b,a = convert_color(color).collect!{ |c| c.to_i }[0,4]
|
106
|
+
a = 255 if a.nil?
|
107
|
+
[r,g,b,a]
|
118
108
|
end
|
119
109
|
|
120
110
|
end
|
@@ -48,9 +48,6 @@ class Rubygame::Color::Palette
|
|
48
48
|
|
49
49
|
# Store a color by name in this palette. See #sanitize_name
|
50
50
|
def []=( name, color )
|
51
|
-
# Uncache colors with this name, to avoid using obsolete value.
|
52
|
-
Rubygame::Color.remove_from_cache( name )
|
53
|
-
|
54
51
|
name = sanitize_name( name )
|
55
52
|
@colors[name] = color
|
56
53
|
end
|
@@ -257,7 +257,7 @@ class Rubygame::Mixer::Sample
|
|
257
257
|
def self.load_audio( filename )
|
258
258
|
Rubygame.deprecated( "Rubygame::Mixer::Sample", "3.0" )
|
259
259
|
|
260
|
-
chunk = SDL::Mixer.LoadWAV( filename
|
260
|
+
chunk = SDL::Mixer.LoadWAV( filename )
|
261
261
|
|
262
262
|
if( chunk.pointer.null? )
|
263
263
|
raise( Rubygame::SDLError,
|
@@ -331,7 +331,7 @@ class Rubygame::Mixer::Music
|
|
331
331
|
def self.load_audio
|
332
332
|
Rubygame.deprecated( "Rubygame::Mixer::Music", "3.0" )
|
333
333
|
|
334
|
-
music = SDL::Mixer.LoadMUS( filename
|
334
|
+
music = SDL::Mixer.LoadMUS( filename )
|
335
335
|
|
336
336
|
if( music.pointer.null? )
|
337
337
|
raise( Rubygame::SDLError,
|
data/lib/rubygame/image.rb
CHANGED
data/lib/rubygame/main.rb
CHANGED
data/lib/rubygame/music.rb
CHANGED
@@ -76,7 +76,7 @@ class Rubygame::Music
|
|
76
76
|
def load( filename )
|
77
77
|
Rubygame.open_audio
|
78
78
|
|
79
|
-
music = SDL::Mixer.LoadMUS( filename
|
79
|
+
music = SDL::Mixer.LoadMUS( filename )
|
80
80
|
|
81
81
|
if( music.pointer.null? )
|
82
82
|
raise( Rubygame::SDLError, "Could not load Music file '%s': %s"%
|
data/lib/rubygame/screen.rb
CHANGED
@@ -153,73 +153,12 @@ class Rubygame::Screen < Rubygame::Surface
|
|
153
153
|
|
154
154
|
|
155
155
|
|
156
|
-
# call-seq:
|
157
|
-
# new( size, opts={} )
|
158
|
-
# new( size, depth=0, flags=[] ) # DEPRECATED
|
159
|
-
#
|
160
156
|
# Create a new Rubygame window if there is none, or modify the
|
161
157
|
# existing one. You cannot create more than one Screen; the existing
|
162
158
|
# one will be replaced. (This is a limitation of SDL.)
|
163
159
|
#
|
164
160
|
# Returns the resulting Screen.
|
165
161
|
#
|
166
|
-
# size:: Screen size to create, [width, height] (in pixels).
|
167
|
-
#
|
168
|
-
# opts::
|
169
|
-
# Hash of options. The possible options are:
|
170
|
-
#
|
171
|
-
# :depth:: Requested color depth (in bits per pixel). If this
|
172
|
-
# is 0 or unspecified, Rubygame automatically
|
173
|
-
# chooses the depth based on the system depth.
|
174
|
-
# Possible values: 0, 8, 15, 16, 24, 32. Default: 0.
|
175
|
-
#
|
176
|
-
# :fullscreen:: If true, use fullscreen mode. If a hardware
|
177
|
-
# resolution change is not possible (for whatever
|
178
|
-
# reason), the next higher resolution will be used
|
179
|
-
# and the display window centered on a black
|
180
|
-
# background. Default: false.
|
181
|
-
#
|
182
|
-
# :resizable:: If true, the user will be able to resize the
|
183
|
-
# Rubygame window. When the window is resized, a
|
184
|
-
# ResizeEvent or Events::WindowResized event is
|
185
|
-
# generated. You should then use Screen.open to
|
186
|
-
# re-create the display surface at the new size.
|
187
|
-
# Default: false.
|
188
|
-
#
|
189
|
-
# :noframe:: If true, try to create a window with no title bar
|
190
|
-
# or frame decoration. This is automatically true
|
191
|
-
# when :fullscreen is true. Default: false.
|
192
|
-
#
|
193
|
-
# :hardware:: If true, try to create a hardware accelerated
|
194
|
-
# Surface (using a graphics card), which may be very
|
195
|
-
# fast to blit onto other hardware accelerated
|
196
|
-
# Surfaces, but somewhat slower to access in other
|
197
|
-
# ways. Creates a normal, non-accelerated Surface if
|
198
|
-
# hardware Surfaces are not available. Default:
|
199
|
-
# false.
|
200
|
-
#
|
201
|
-
# :doublebuf:: If true, enable hardware double buffering; only
|
202
|
-
# valid when :hardware is true. Calling #flip will
|
203
|
-
# switch the buffers and update the screen. All
|
204
|
-
# drawing will take place on the surface that is not
|
205
|
-
# displayed at the moment. If double buffering could
|
206
|
-
# not be enabled then #flip will just update the
|
207
|
-
# entire screen. Default: false.
|
208
|
-
#
|
209
|
-
# :opengl:: If true, create an OpenGL rendering context
|
210
|
-
# instead of a normal SDL display. You must set
|
211
|
-
# proper OpenGL video attributes with GL#set_attrib
|
212
|
-
# before calling this method with this flag. You can
|
213
|
-
# then use an OpenGL library (e.g. ruby-opengl) to
|
214
|
-
# do all OpenGL-related functions. Please note that
|
215
|
-
# you can't blit or draw regular SDL Surfaces onto
|
216
|
-
# an OpenGL-mode screen; you must use OpenGL
|
217
|
-
# functions. Default: false.
|
218
|
-
#
|
219
|
-
# For backwards compatibility, you can provide the following
|
220
|
-
# arguments instead of the ones above. However, this form is
|
221
|
-
# DEPRECATED and will be removed in Rubygame 3.0:
|
222
|
-
#
|
223
162
|
# size:: requested window size (in pixels), in the form [width,height]
|
224
163
|
# depth:: requested color depth (in bits per pixel). If 0 (default), the
|
225
164
|
# current system color depth.
|
@@ -265,7 +204,7 @@ class Rubygame::Screen < Rubygame::Surface
|
|
265
204
|
# frame decoration.
|
266
205
|
# Fullscreen modes automatically have this flag set.
|
267
206
|
#
|
268
|
-
def initialize(
|
207
|
+
def initialize( size, depth=0, flags=[Rubygame::SWSURFACE] )
|
269
208
|
|
270
209
|
# Cheating a bit. First arg can be a SDL::Surface to wrap it.
|
271
210
|
#
|
@@ -281,41 +220,7 @@ class Rubygame::Screen < Rubygame::Surface
|
|
281
220
|
return
|
282
221
|
end
|
283
222
|
|
284
|
-
# Support old argument style for backwards compatibility.
|
285
|
-
if args.size > 1 or not args[0].is_a? Hash
|
286
|
-
_initialize_old( size, *args )
|
287
|
-
return
|
288
|
-
end
|
289
|
-
|
290
|
-
args = _parse_args( size, args[0] )
|
291
223
|
|
292
|
-
@struct = SDL.SetVideoMode( args[:width], args[:height],
|
293
|
-
args[:depth], args[:flags] )
|
294
|
-
|
295
|
-
if( @struct.pointer.null? )
|
296
|
-
@struct = nil
|
297
|
-
raise( Rubygame::SDLError,
|
298
|
-
"Couldn't set [%d x %d] %d bpp video mode: %s"%\
|
299
|
-
[args[:width], args[:height], args[:depth], SDL.GetError()] )
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
|
304
|
-
def _parse_args( size, options ) # :nodoc:
|
305
|
-
args = super
|
306
|
-
|
307
|
-
flags = args[:flags]
|
308
|
-
|
309
|
-
flags |= SDL::FULLSCREEN if options[:fullscreen]
|
310
|
-
flags |= SDL::RESIZABLE if options[:resizable]
|
311
|
-
flags |= SDL::NOFRAME if options[:noframe]
|
312
|
-
flags |= SDL::DOUBLEBUF if options[:doublebuf]
|
313
|
-
flags |= SDL::OPENGL if options[:opengl]
|
314
|
-
|
315
|
-
args.merge( :flags => flags )
|
316
|
-
end
|
317
|
-
|
318
|
-
def _initialize_old( size, depth=0, flags=[] ) # :nodoc:
|
319
224
|
w,h = size
|
320
225
|
flags = Rubygame.collapse_flags(flags)
|
321
226
|
|
@@ -327,6 +232,7 @@ class Rubygame::Screen < Rubygame::Surface
|
|
327
232
|
"Couldn't set [%d x %d] %d bpp video mode: %s"%\
|
328
233
|
[w, h, depth, SDL.GetError()] )
|
329
234
|
end
|
235
|
+
|
330
236
|
end
|
331
237
|
|
332
238
|
|
data/lib/rubygame/sound.rb
CHANGED
@@ -73,7 +73,7 @@ class Rubygame::Sound
|
|
73
73
|
def load( filename )
|
74
74
|
Rubygame.open_audio
|
75
75
|
|
76
|
-
sound = SDL::Mixer.LoadWAV( filename
|
76
|
+
sound = SDL::Mixer.LoadWAV( filename )
|
77
77
|
|
78
78
|
if( sound.pointer.null? )
|
79
79
|
raise( Rubygame::SDLError, "Could not load Sound file '%s': %s"%
|
data/lib/rubygame/surface.rb
CHANGED
@@ -48,53 +48,18 @@ class Rubygame::Surface
|
|
48
48
|
protected :struct
|
49
49
|
|
50
50
|
|
51
|
-
#
|
52
|
-
# new( size, opts={} )
|
53
|
-
# new( size, depth=0, flags=[] ) # DEPRECATED
|
54
|
-
#
|
55
|
-
# Create and initialize a new Surface.
|
51
|
+
# Create and initialize a new Surface object.
|
56
52
|
#
|
57
|
-
# A Surface is a grid of image data which you blit (i.e. copy) onto
|
58
|
-
#
|
59
|
-
# be blit to the screen; this is the most common way
|
60
|
-
# images on the screen.
|
53
|
+
# A Surface is a grid of image data which you blit (i.e. copy) onto other
|
54
|
+
# Surfaces. Since the Rubygame display is also a Surface (see the Screen
|
55
|
+
# class), Surfaces can be blit to the screen; this is the most common way
|
56
|
+
# to display images on the screen.
|
61
57
|
#
|
62
58
|
# This method may raise SDLError if the SDL video subsystem could
|
63
59
|
# not be initialized for some reason.
|
64
60
|
#
|
65
61
|
# This function takes these arguments:
|
66
|
-
#
|
67
|
-
# size:: Surface size to create, [width, height] (in pixels).
|
68
|
-
#
|
69
|
-
# opts::
|
70
|
-
# Hash of options. The possible options are:
|
71
|
-
#
|
72
|
-
# :depth:: Requested color depth (in bits per pixel). If this
|
73
|
-
# is 0 or unspecified, Rubygame automatically chooses
|
74
|
-
# the depth based on the Screen mode or system depth.
|
75
|
-
# Possible values: 0, 8, 15, 16, 24, 32. Default: 0.
|
76
|
-
#
|
77
|
-
# :alpha:: If true, Surfaces with depth 32 will have an alpha
|
78
|
-
# channel (per-pixel transparency). Default: true.
|
79
|
-
# (Note: Other depths cannot have an alpha channel.)
|
80
|
-
#
|
81
|
-
# :hardware:: If true, try to create a hardware accelerated
|
82
|
-
# Surface (using a graphics card), which may be very
|
83
|
-
# fast to blit onto other hardware accelerated
|
84
|
-
# Surfaces, but somewhat slower to access in other
|
85
|
-
# ways. Creates a normal, non-accelerated Surface if
|
86
|
-
# hardware Surfaces are not available. Default: false.
|
87
|
-
#
|
88
|
-
# :masks:: For advanced users. Set the Surface's color masks
|
89
|
-
# manually, as [r,g,b,a]. If this is nil or
|
90
|
-
# unspecified, the color masks are calculated
|
91
|
-
# automatically.
|
92
|
-
#
|
93
|
-
# For backwards compatibility, you can provide the following
|
94
|
-
# arguments instead of the ones above. However, this form is
|
95
|
-
# DEPRECATED and will be removed in Rubygame 3.0:
|
96
|
-
#
|
97
|
-
# size:: Surface size to create, [width, height] (in pixels).
|
62
|
+
# size:: requested surface size; an array of the form [width, height].
|
98
63
|
# depth:: requested color depth (in bits per pixel). If depth is 0 (default),
|
99
64
|
# automatically choose a color depth: either the depth of the Screen
|
100
65
|
# mode (if one has been set), or the greatest color depth available
|
@@ -115,7 +80,7 @@ class Rubygame::Surface
|
|
115
80
|
# also enable alpha. as needed. For a description
|
116
81
|
# of alpha, see #alpha.
|
117
82
|
#
|
118
|
-
def initialize( size,
|
83
|
+
def initialize( size, depth=0, flags=[] )
|
119
84
|
|
120
85
|
# Cheating a bit. First arg can be a SDL::Surface to wrap it.
|
121
86
|
#
|
@@ -129,85 +94,6 @@ class Rubygame::Surface
|
|
129
94
|
return
|
130
95
|
end
|
131
96
|
|
132
|
-
# Support old argument style for backwards compatibility.
|
133
|
-
if args.size > 1 or not args[0].is_a? Hash
|
134
|
-
_initialize_old( size, *args )
|
135
|
-
return
|
136
|
-
end
|
137
|
-
|
138
|
-
args = _parse_args( size, args[0] )
|
139
|
-
|
140
|
-
@struct = SDL.CreateRGBSurface( args[:flags],
|
141
|
-
args[:width], args[:height],
|
142
|
-
args[:depth], *args[:masks] )
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
private
|
147
|
-
|
148
|
-
|
149
|
-
def _parse_args( size, options )
|
150
|
-
unless size.is_a?(Array) and size.size == 2 and
|
151
|
-
size.all?{ |i| i.is_a?(Integer) and i > 0 }
|
152
|
-
raise( TypeError, "Invalid size: " + size.inspect +
|
153
|
-
" (expected [width,height] array of integers >= 0)" )
|
154
|
-
end
|
155
|
-
|
156
|
-
depth = options[:depth] || 0
|
157
|
-
unless depth.is_a?(Integer) and depth >= 0
|
158
|
-
raise( TypeError, "Invalid depth: " + depth.inspect +
|
159
|
-
" (expected integer >= 0)" )
|
160
|
-
end
|
161
|
-
|
162
|
-
alpha = options.has_key?(:alpha) ? options[:alpha] : true
|
163
|
-
|
164
|
-
masks = options[:masks]
|
165
|
-
if masks.nil?
|
166
|
-
masks = _make_masks( depth, alpha )
|
167
|
-
else
|
168
|
-
unless masks.size == 4 and masks.all?{|m| m.is_a?(Integer) and m >= 0}
|
169
|
-
raise( TypeError, "Invalid masks: " + masks.inspect +
|
170
|
-
" (expected [r,g,b,a] array of integers >= 0)" )
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
flags = 0
|
175
|
-
flags |= SDL::HWSURFACE if options[:hardware]
|
176
|
-
|
177
|
-
{ :width => size[0],
|
178
|
-
:height => size[1],
|
179
|
-
:depth => depth,
|
180
|
-
:masks => masks,
|
181
|
-
:flags => flags,
|
182
|
-
}
|
183
|
-
end
|
184
|
-
|
185
|
-
|
186
|
-
# Calculate color masks based on requested depth and (for 32 bit)
|
187
|
-
# whether or not to have an alpha channel.
|
188
|
-
def _make_masks( depth, alpha ) # :nodoc:
|
189
|
-
a = alpha ? 0xff000000 : 0
|
190
|
-
|
191
|
-
masks = case depth
|
192
|
-
when 32; [0xff0000, 0x00ff00, 0x0000ff, a]
|
193
|
-
when 24; [0xff0000, 0x00ff00, 0x0000ff, 0]
|
194
|
-
when 16; [0x00f800, 0x0007e0, 0x00001f, 0]
|
195
|
-
when 15; [0x007c00, 0x0003e0, 0x00001f, 0]
|
196
|
-
else [ 0, 0, 0, 0]
|
197
|
-
end
|
198
|
-
|
199
|
-
if FFI::Platform::BYTE_ORDER == FFI::Platform::BIG_ENDIAN
|
200
|
-
masks[0,3] = masks[0,3].reverse
|
201
|
-
end
|
202
|
-
|
203
|
-
masks
|
204
|
-
end
|
205
|
-
|
206
|
-
|
207
|
-
# Initialize the Surface in the deprecated (pre-2.7) way.
|
208
|
-
def _initialize_old( size, depth=0, flags=[] ) # :nodoc:
|
209
|
-
Rubygame.deprecated("Old Surface#new arguments style", "3.0")
|
210
|
-
|
211
97
|
unless size.kind_of? Array
|
212
98
|
raise TypeError, "Surface size is not an Array: #{size.inspect}"
|
213
99
|
end
|
@@ -253,8 +139,6 @@ class Rubygame::Surface
|
|
253
139
|
end
|
254
140
|
|
255
141
|
|
256
|
-
public
|
257
|
-
|
258
142
|
|
259
143
|
# Return the width (in pixels) of the surface.
|
260
144
|
#
|
@@ -717,7 +601,7 @@ class Rubygame::Surface
|
|
717
601
|
# May raise SDLError if a problem occurs.
|
718
602
|
#
|
719
603
|
def savebmp( filename )
|
720
|
-
result = SDL.SaveBMP( @struct, filename
|
604
|
+
result = SDL.SaveBMP( @struct, filename )
|
721
605
|
if(result != 0)
|
722
606
|
raise( Rubygame::SDLError, "Couldn't save surface to file %s: %s"%\
|
723
607
|
[filename, SDL.GetError()] )
|
data/lib/rubygame/ttf.rb
CHANGED
@@ -75,7 +75,7 @@ class Rubygame::TTF
|
|
75
75
|
"You must call TTF.setup before opening a font." )
|
76
76
|
end
|
77
77
|
|
78
|
-
@struct = SDL::TTF.OpenFont( file
|
78
|
+
@struct = SDL::TTF.OpenFont( file, size )
|
79
79
|
|
80
80
|
if( @struct.pointer.null? )
|
81
81
|
raise Rubygame::SDLError, "Could not open font: #{SDL.GetError()}"
|
@@ -0,0 +1,177 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygame"
|
4
|
+
require "rubygame/ftor"
|
5
|
+
|
6
|
+
|
7
|
+
include Rubygame
|
8
|
+
include Rubygame::Events
|
9
|
+
include Rubygame::EventActions
|
10
|
+
include Rubygame::EventTriggers
|
11
|
+
|
12
|
+
|
13
|
+
# Represents a modifiable Bézier curve.
|
14
|
+
class Curve
|
15
|
+
|
16
|
+
def initialize( points, color=:white )
|
17
|
+
@points = []
|
18
|
+
points.each { |point| add_point( point ) }
|
19
|
+
@color = :white
|
20
|
+
@steps = 10
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
attr_accessor :points, :color, :steps
|
25
|
+
|
26
|
+
|
27
|
+
# Draw the curve on the given Surface.
|
28
|
+
def draw( surface )
|
29
|
+
unless @points.empty?
|
30
|
+
surface.draw_curve( @points, @color, @steps )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# Draw the curve's control points on the given Surface,
|
36
|
+
# as squares of the given color and size (even numbers work best).
|
37
|
+
#
|
38
|
+
def draw_points( surface, color=:red, size=2 )
|
39
|
+
rect = Rect.new(0,0,size,size)
|
40
|
+
@points.each do |point|
|
41
|
+
rect.center = point.to_a
|
42
|
+
surface.fill( color, rect )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# Appends the given point to the list of control points.
|
48
|
+
# +point+ must be an [x,y] array, Ftor, vector, or similar.
|
49
|
+
#
|
50
|
+
def add_point( point )
|
51
|
+
@points << _make_point(point)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# Replaces the control point at the given index with the new point.
|
56
|
+
# E.g. if index is 2, it sets @points[2] = new_point.
|
57
|
+
#
|
58
|
+
def replace_point( index, new_point )
|
59
|
+
@points[index] = _make_point( new_point )
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
# Returns the index and coordinates of the control point nearest to
|
64
|
+
# +pos+. +pos+ must be an [x,y] array, Ftor, vector, or similar.
|
65
|
+
#
|
66
|
+
def nearest_point( pos )
|
67
|
+
pos = Ftor.new(pos[0], pos[1])
|
68
|
+
pts = @points.to_enum(:each_with_index).collect{ |p,i| [i,p] }
|
69
|
+
return pts.sort_by{ |index_and_point|
|
70
|
+
point = index_and_point[1]
|
71
|
+
(pos - point).magnitude
|
72
|
+
}.first
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
|
79
|
+
# Construct an integer Ftor version of the point.
|
80
|
+
def _make_point( point )
|
81
|
+
begin
|
82
|
+
Ftor.new(point[0].round, point[1].round)
|
83
|
+
rescue NoMethodError
|
84
|
+
raise ArgumentError, "Invalid point: #{point.inspect}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
class App
|
93
|
+
include EventHandler::HasEventHandler
|
94
|
+
|
95
|
+
attr_reader :screen, :clock, :queue
|
96
|
+
|
97
|
+
|
98
|
+
def initialize
|
99
|
+
@screen = Screen.new([640,480])
|
100
|
+
|
101
|
+
@queue = EventQueue.new
|
102
|
+
@queue.enable_new_style_events
|
103
|
+
|
104
|
+
setup_clock
|
105
|
+
setup_hooks
|
106
|
+
|
107
|
+
@curve = Curve.new( [[5,5], [320,240], [635,4]], :white )
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def go
|
113
|
+
catch(:quit) do
|
114
|
+
loop do
|
115
|
+
step
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
|
124
|
+
# Do everything needed for one frame.
|
125
|
+
def step
|
126
|
+
@queue.fetch_sdl_events
|
127
|
+
@queue << @clock.tick
|
128
|
+
@queue.each do |event|
|
129
|
+
handle( event )
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
def setup_clock
|
135
|
+
@clock = Clock.new
|
136
|
+
@clock.target_framerate = 30
|
137
|
+
@clock.calibrate
|
138
|
+
@clock.enable_tick_events
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
def setup_hooks
|
143
|
+
hooks = {
|
144
|
+
:escape => :quit,
|
145
|
+
:q => :quit,
|
146
|
+
QuitRequested => :quit,
|
147
|
+
|
148
|
+
InputFocusGained => :update_screen,
|
149
|
+
WindowUnminimized => :update_screen,
|
150
|
+
WindowExposed => :update_screen,
|
151
|
+
|
152
|
+
MousePressed => :handle_mouse,
|
153
|
+
MouseReleased => :handle_mouse,
|
154
|
+
}
|
155
|
+
|
156
|
+
make_magic_hooks( hooks )
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
# Quit the app
|
161
|
+
def quit
|
162
|
+
throw :quit
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
# Refresh the whole screen.
|
167
|
+
def update_screen
|
168
|
+
@screen.update()
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
def handle_mouse( event )
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
end
|
data/samples/demo_gl.rb
CHANGED
@@ -27,7 +27,7 @@ Rubygame::GL.set_attrib(Rubygame::GL::BLUE_SIZE, 5)
|
|
27
27
|
Rubygame::GL.set_attrib(Rubygame::GL::DEPTH_SIZE, 16)
|
28
28
|
Rubygame::GL.set_attrib(Rubygame::GL::DOUBLEBUFFER, 1)
|
29
29
|
|
30
|
-
Rubygame::Screen.open([WIDE,HIGH],
|
30
|
+
Rubygame::Screen.open([WIDE,HIGH], 16, [Rubygame::OPENGL])
|
31
31
|
queue = Rubygame::EventQueue.new()
|
32
32
|
clock = Rubygame::Clock.new { |c| c.target_framerate = 60 }
|
33
33
|
|
data/samples/demo_gl_tex.rb
CHANGED
@@ -31,7 +31,7 @@ Rubygame::GL.set_attrib(Rubygame::GL::BLUE_SIZE, 5)
|
|
31
31
|
Rubygame::GL.set_attrib(Rubygame::GL::DEPTH_SIZE, 16)
|
32
32
|
Rubygame::GL.set_attrib(Rubygame::GL::DOUBLEBUFFER, 1)
|
33
33
|
|
34
|
-
Rubygame::Screen.open([WIDE,HIGH],
|
34
|
+
Rubygame::Screen.open([WIDE,HIGH], 16, [Rubygame::OPENGL])
|
35
35
|
queue = Rubygame::EventQueue.new()
|
36
36
|
clock = Rubygame::Clock.new { |c| c.target_framerate = 60 }
|
37
37
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 2.6.
|
8
|
+
- 4
|
9
|
+
version: 2.6.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Croisant
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-16 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -57,6 +57,7 @@ extra_rdoc_files:
|
|
57
57
|
- doc/keyboard_symbols.rdoc
|
58
58
|
- doc/macosx_install.rdoc
|
59
59
|
- doc/managing_framerate.rdoc
|
60
|
+
- doc/surface_palettes.rdoc
|
60
61
|
- doc/getting_started.rdoc
|
61
62
|
- README
|
62
63
|
- LICENSE
|
@@ -133,12 +134,14 @@ files:
|
|
133
134
|
- samples/demo_gl_tex.rb
|
134
135
|
- samples/ruby.png
|
135
136
|
- samples/load_and_blit.rb
|
137
|
+
- samples/demo_curve.rb
|
136
138
|
- samples/fist.bmp
|
137
139
|
- doc/windows_install.rdoc
|
138
140
|
- doc/custom_sdl_load_paths.rdoc
|
139
141
|
- doc/keyboard_symbols.rdoc
|
140
142
|
- doc/macosx_install.rdoc
|
141
143
|
- doc/managing_framerate.rdoc
|
144
|
+
- doc/surface_palettes.rdoc
|
142
145
|
- doc/getting_started.rdoc
|
143
146
|
- README
|
144
147
|
- LICENSE
|
@@ -154,7 +157,6 @@ rdoc_options: []
|
|
154
157
|
|
155
158
|
require_paths:
|
156
159
|
- lib
|
157
|
-
- lib/rubygame/
|
158
160
|
required_ruby_version: !ruby/object:Gem::Requirement
|
159
161
|
requirements:
|
160
162
|
- - ">="
|