frusdl 0.0.1
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/README +51 -0
- data/lib/frusdl.rb +145 -0
- data/lib/frusdl/low.rb +30 -0
- data/lib/frusdl/low/gfx.rb +95 -0
- data/lib/frusdl/low/img.rb +10 -0
- data/lib/frusdl/low/mix.rb +138 -0
- data/lib/frusdl/low/sdl.rb +881 -0
- data/lib/frusdl/low/sge.rb +100 -0
- data/lib/frusdl/low/ttf.rb +95 -0
- data/lib/frusdl/sdl.rb +425 -0
- data/lib/frusdl/sdl/pixelformat.rb +78 -0
- data/lib/frusdl/sdl/screen.rb +199 -0
- data/lib/frusdl/sdl/surface.rb +0 -0
- data/lib/frusdl/sdl/videoinfo.rb +23 -0
- data/lib/frusdl/wrap.rb +49 -0
- metadata +79 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
module Frusdl
|
2
|
+
module SDL
|
3
|
+
class PixelFormat
|
4
|
+
include Frusdl::Wrap
|
5
|
+
|
6
|
+
extend Frusdl::Low::SDL
|
7
|
+
include Frusdl::Low::SDL
|
8
|
+
|
9
|
+
attr_reader :pointer
|
10
|
+
|
11
|
+
def initialize(ptr)
|
12
|
+
initialize_pointer(ptr, Frusdl::Low::SDL::SDL_PixelFormat)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Map a RGB color value to a pixel format.
|
16
|
+
def map_rgb(r, g, b)
|
17
|
+
return SDL_MapRGB(@pointer, r, g, b)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Map a RGBA color value to a pixel format.
|
21
|
+
def map_rgba(r, g, b, a)
|
22
|
+
return SDL_MapRGBA(@pointer, r, g, b, a)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get RGB values from a pixel in the specified pixel format.
|
26
|
+
# XXX: not implemented
|
27
|
+
def get_rgb()
|
28
|
+
return [-1, -1, -1, -1]
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Get RGBA values from a pixel in the specified pixel format.
|
33
|
+
# XXX: not implemented
|
34
|
+
def get_rgba()
|
35
|
+
return [-1, -1, -1, -1]
|
36
|
+
end
|
37
|
+
|
38
|
+
struct_accessor :Rmask , :rmask
|
39
|
+
struct_accessor :Gmask , :gmask
|
40
|
+
struct_accessor :Bmask , :bmask
|
41
|
+
struct_accessor :Amask , :amask
|
42
|
+
struct_accessor :Rloss , :rloss
|
43
|
+
struct_accessor :Gloss , :gloss
|
44
|
+
struct_accessor :Bloss , :bloss
|
45
|
+
struct_accessor :Aloss , :aloss
|
46
|
+
struct_accessor :Rshift , :rshift
|
47
|
+
struct_accessor :Gshift , :gshift
|
48
|
+
struct_accessor :Bshift , :bshift
|
49
|
+
struct_accessor :Ashift , :ashift
|
50
|
+
struct_accessor :colorkey , :colorkey
|
51
|
+
struct_accessor :alpha , :alpha
|
52
|
+
struct_accessor :bpp , :bitsperpixel
|
53
|
+
|
54
|
+
|
55
|
+
=begin
|
56
|
+
o SDL::PixelFormat#map_rgb -- RGB Map a RGB color value to a pixel format.
|
57
|
+
o SDL::PixelFormat#map_rgba -- Map a RGBA color value to a pixel format.
|
58
|
+
o SDL::PixelFormat#get_rgb -- Get RGB values from a pixel in the specified pixel format.
|
59
|
+
o SDL::PixelFormat#get_rgba -- Get RGBA values from a pixel in the specified pixel format.
|
60
|
+
o SDL::PixelFormat#Rmask -- Get binary mask used to retrieve red color value
|
61
|
+
o SDL::PixelFormat#Gmask -- Get binary mask used to retrieve green color value
|
62
|
+
o SDL::PixelFormat#Bmask -- Get binary mask used to retrieve blue color value
|
63
|
+
o SDL::PixelFormat#Amask -- Get binary mask used to retrieve alpla value
|
64
|
+
o SDL::PixelFormat#Rloss -- Precision loss of red component
|
65
|
+
o SDL::PixelFormat#Gloss -- Precision loss of green component
|
66
|
+
o SDL::PixelFormat#Bloss -- Precision loss of blue component
|
67
|
+
o SDL::PixelFormat#Aloss -- Precision loss of alpha component
|
68
|
+
o SDL::PixelFormat#Rshift -- Binary left shift of red component in the pixel value
|
69
|
+
o SDL::PixelFormat#Gshift -- Binary left shift of green component in the pixel value
|
70
|
+
o SDL::PixelFormat#Bshift -- Binary left shift of blue component in the pixel value
|
71
|
+
o SDL::PixelFormat#Ashift -- Binary left shift of alpha component in the pixel value
|
72
|
+
o SDL::PixelFormat#colorkey -- Pixel value of transparent pixels.
|
73
|
+
o SDL::PixelFormat#alpha -- Overall surface alpha value
|
74
|
+
o SDL::PixelFormat#bpp -- The number of bits used to represent each pixel in a surface
|
75
|
+
=end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
module Frusdl
|
2
|
+
module SDL
|
3
|
+
class Screen
|
4
|
+
include Frusdl::Wrap
|
5
|
+
include Frusdl::Low::SDL
|
6
|
+
extend Frusdl::Low::SDL
|
7
|
+
|
8
|
+
|
9
|
+
struct_accessor :w
|
10
|
+
struct_accessor :h
|
11
|
+
|
12
|
+
attr_reader :pointer
|
13
|
+
|
14
|
+
def initialize(ptr)
|
15
|
+
initialize_pointer(ptr, Frusdl::Low::SDL::SDL_Surface)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Wraps a low level ponter in a higher level struct
|
19
|
+
def self.wrap(ptr)
|
20
|
+
return Frusdl::Low::SDL::SDL_Surface.new(ptr)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the current display surface
|
24
|
+
def self.get
|
25
|
+
ptr = SDL_GetVideoSurface()
|
26
|
+
self.new(ptr)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns information about the video hardware
|
30
|
+
def self.info
|
31
|
+
ptr = SDL_GetVideoInfo()
|
32
|
+
Frusdl::SDL::VideoInfo.new(ptr)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Set up a video mode with the specified width, height and bits-per-pixel.
|
36
|
+
def self.open(width, height, bbp, flags)
|
37
|
+
ptr = SDL_SetVideoMode(width, height, bbp, flags)
|
38
|
+
self.new(ptr)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Obtain the name of the video driver
|
42
|
+
def self.driver_name
|
43
|
+
size = 256
|
44
|
+
cstr = FFI::MemoryPointer.new(size)
|
45
|
+
SDL_VideoDriverName(cstr, size)
|
46
|
+
str = cstr.read_string
|
47
|
+
return str
|
48
|
+
end
|
49
|
+
|
50
|
+
# Check to see if a particular video mode is supported.
|
51
|
+
# Returns supported bbp, or 0 if unsupported
|
52
|
+
def self.check_mode(width, height, depth, flags)
|
53
|
+
return SDL_VideoModeOK(width, height, depth, flags)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns an array of available screen dimensions for the given format and video flags
|
57
|
+
def self.list_modes(format, flags)
|
58
|
+
formptr = format ? format.pointer : nil
|
59
|
+
rectptrptr = SDL_ListModes(formptr, flags)
|
60
|
+
return nil if rectptrptr.null?
|
61
|
+
return true if rectptrptr.address == 4294967295
|
62
|
+
# This address means "all sizes allowed". Gotta love C! >_<
|
63
|
+
aid = rectptrptr.get_int(0)
|
64
|
+
return nil if aid == 0
|
65
|
+
return true if aid == -1
|
66
|
+
index = 0
|
67
|
+
result = []
|
68
|
+
ptrsize = FFI.type_size(:pointer)
|
69
|
+
rectptr = rectptrptr.get_pointer(index * ptrsize)
|
70
|
+
until rectptr.null? do
|
71
|
+
rect = Frusdl::Low::SDL::SDL_Rect.new(rectptr)
|
72
|
+
result << [ rect[:w], rect[:h] ]
|
73
|
+
index += 1
|
74
|
+
rectptr = rectptrptr.get_pointer(index * ptrsize)
|
75
|
+
end
|
76
|
+
return result
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
# Swaps screen buffers
|
81
|
+
def flip
|
82
|
+
SDL_Flip(@pointer)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Makes sure the given area is updated on the given screen.
|
86
|
+
def update_rect(x, y, w, h)
|
87
|
+
SDL_UpdateRect(@pointer, x, y, w, h)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Makes sure the given list of rectangles is updated on the given screen
|
91
|
+
def update_rects(*rects)
|
92
|
+
count = rects.size
|
93
|
+
rectptr = MemoryPointer.new(:pointer, count)
|
94
|
+
index = 0
|
95
|
+
for rect in rects do
|
96
|
+
rectptr.set_pointer(index, rect.pointer)
|
97
|
+
index += 1
|
98
|
+
end
|
99
|
+
SDL_UpdateRects(@pointer, index, rectptr)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Sets the color gamma function for the display
|
103
|
+
def self.set_gamma(rgamma, ggamma, bgammma)
|
104
|
+
res = SDL_SetGamma(rgamma, ggamma, bgamma)
|
105
|
+
raise_error if res < 0
|
106
|
+
end
|
107
|
+
|
108
|
+
# Gets the color gamma lookup tables for the display
|
109
|
+
# XXX: doesn't work
|
110
|
+
def self.get_gamma_ramp
|
111
|
+
res = SDL_SetGammaRamp(rgammas, ggammas, bgammas)
|
112
|
+
raise_error if res < 0
|
113
|
+
return rgammas, ggammas, bgammas
|
114
|
+
end
|
115
|
+
|
116
|
+
# Sets the color gamma lookup tables for the display
|
117
|
+
# XXX: doesn't work like this
|
118
|
+
def self.set_gamma_ramp(rgammas, ggammas, bgammas)
|
119
|
+
res = SDL_SetGammaRamp(rgammas, ggammas, bgammas)
|
120
|
+
raise_error if res < 0
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
=begin
|
127
|
+
* Video Subsystem Outline
|
128
|
+
* SDL::Screen
|
129
|
+
* SDL::Surface
|
130
|
+
* SDL::VideoInfo
|
131
|
+
* Color, PixelFormat and Pixel value
|
132
|
+
* Methods
|
133
|
+
o SDL::PixelFormat#map_rgb -- RGB Map a RGB color value to a pixel format.
|
134
|
+
o SDL::PixelFormat#map_rgba -- Map a RGBA color value to a pixel format.
|
135
|
+
o SDL::PixelFormat#get_rgb -- Get RGB values from a pixel in the specified pixel format.
|
136
|
+
o SDL::PixelFormat#get_rgba -- Get RGBA values from a pixel in the specified pixel format.
|
137
|
+
o SDL::PixelFormat#Rmask -- Get binary mask used to retrieve red color value
|
138
|
+
o SDL::PixelFormat#Gmask -- Get binary mask used to retrieve green color value
|
139
|
+
o SDL::PixelFormat#Bmask -- Get binary mask used to retrieve blue color value
|
140
|
+
o SDL::PixelFormat#Amask -- Get binary mask used to retrieve alpla value
|
141
|
+
o SDL::PixelFormat#Rloss -- Precision loss of red component
|
142
|
+
o SDL::PixelFormat#Gloss -- Precision loss of green component
|
143
|
+
o SDL::PixelFormat#Bloss -- Precision loss of blue component
|
144
|
+
o SDL::PixelFormat#Aloss -- Precision loss of alpha component
|
145
|
+
o SDL::PixelFormat#Rshift -- Binary left shift of red component in the pixel value
|
146
|
+
o SDL::PixelFormat#Gshift -- Binary left shift of green component in the pixel value
|
147
|
+
o SDL::PixelFormat#Bshift -- Binary left shift of blue component in the pixel value
|
148
|
+
o SDL::PixelFormat#Ashift -- Binary left shift of alpha component in the pixel value
|
149
|
+
o SDL::PixelFormat#colorkey -- Pixel value of transparent pixels.
|
150
|
+
o SDL::PixelFormat#alpha -- Overall surface alpha value
|
151
|
+
o SDL::PixelFormat#bpp -- The number of bits used to represent each pixel in a surface
|
152
|
+
|
153
|
+
|
154
|
+
o SDL::Surface#set_colors -- Sets a portion of the colormap for the given 8-bit surface.
|
155
|
+
o SDL::Surface#set_palette -- Sets the colors in the palette of an 8-bit surface
|
156
|
+
o SDL::Surface.new -- Create an empty SDL::Surface
|
157
|
+
o SDL::Surface.new_from -- Create an SDL::Surface object from pixel data
|
158
|
+
o SDL::Surface#lock -- Lock a surface for directly access.
|
159
|
+
o SDL::Surface#unlock -- Unlocks a previously locked surface.
|
160
|
+
o SDL::Surface#must_lock? -- Get whether the surface require locking or not.
|
161
|
+
o SDL::Surface.load_bmp -- Load a Windows BMP file into an SDL_Surface.
|
162
|
+
o SDL::Surface.load_bmp_from_io -- Load a Windows BMP file into an Surface from IO object.
|
163
|
+
o SDL::Surface#save_bmp -- Save an SDL_Surface as a Windows BMP file.
|
164
|
+
o SDL::Surface#set_color_key -- Sets the color key (transparent pixel) in a blittable surface and RLE acceleration.
|
165
|
+
o SDL::Surface#set_alpha -- Adjust the alpha properties of a surface
|
166
|
+
o SDL::Surface#set_clip_rect -- Sets the clipping rectangle for a surface.
|
167
|
+
o SDL::Surface#get_clip_rect -- Gets the clipping rectangle for a surface.
|
168
|
+
o SDL::Surface.blit -- This performs a fast blit from the source surface to the destination surface.
|
169
|
+
o SDL::Surface#fill_rect -- This function performs a fast fill of the given rectangle with some color
|
170
|
+
o SDL::Surface#display_format -- Convert a surface to the display format
|
171
|
+
o SDL::Surface#display_format_alpha -- Convert a surface to the display format
|
172
|
+
o SDL::Surface#flags -- Get surface flags
|
173
|
+
o SDL::Surface#format -- Get surface pixel format
|
174
|
+
o SDL::Surface#w -- Get surface width
|
175
|
+
o SDL::Surface#h -- Get surface height
|
176
|
+
o SDL::Surface#pixels -- Get the actual pixel data
|
177
|
+
o SDL::Surface#colorkey -- Pixel value of transparent pixels
|
178
|
+
o SDL::Surface#alpha -- Overall surface alpha value
|
179
|
+
o SDL::Surface.load -- Load image into an surface
|
180
|
+
o SDL::Surface.load_from_io -- Load a image file into an Surface from IO object.
|
181
|
+
o SDL::Surface#put_pixel -- Writes a pixel to the specified position
|
182
|
+
o SDL::Surface#get_pixel -- Gets the color of the specified pixel.
|
183
|
+
o SDL::Surface#put -- Performs a fast blit from entire surface.
|
184
|
+
o SDL::Surface#copy_rect -- Copies a part of surface.
|
185
|
+
o SDL::Surface.auto_lock? -- Get whether surface is automatically locked
|
186
|
+
o SDL::Surface.auto_lock_on -- Switch on auto locking
|
187
|
+
o SDL::Surface.auto_lock_off -- Switch off auto locking.
|
188
|
+
o SDL::Surface.transform_draw -- Draw a rotated and scaled image.
|
189
|
+
o SDL::Surface.transform_blit -- Draw a rotated and scaled image with colorkey and blending
|
190
|
+
o SDL::Surface#draw_line -- Draw a line
|
191
|
+
o SDL::Surface#draw_rect -- Draws a rect
|
192
|
+
o SDL::Surface#draw_circle -- Draws a circle
|
193
|
+
o SDL::Surface#draw_ellipse -- Draws an ellipse.
|
194
|
+
o SDL::Surface#draw_bezier -- Draws a bezier curve
|
195
|
+
o SDL::Surface#transform_surface -- Creates an rotated an scaled surface
|
196
|
+
=end
|
197
|
+
end # class Screen
|
198
|
+
end # module SDL
|
199
|
+
end # module Frusdl
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Frusdl
|
2
|
+
module SDL
|
3
|
+
class VideoInfo
|
4
|
+
attr_reader :pointer
|
5
|
+
|
6
|
+
include Frusdl::Wrap
|
7
|
+
include Frusdl::Low::SDL
|
8
|
+
extend Frusdl::Low::SDL
|
9
|
+
|
10
|
+
def initialize(ptr)
|
11
|
+
initialize_pointer(ptr, Frusdl::Low::SDL::SDL_VideoInfo)
|
12
|
+
end
|
13
|
+
|
14
|
+
def pixel_format
|
15
|
+
return Frusdl::SDL::PixelFormat.new(@struct[:vfmt])
|
16
|
+
end
|
17
|
+
|
18
|
+
struct_reader :video_mem
|
19
|
+
struct_reader :current_w
|
20
|
+
struct_reader :current_h
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/frusdl/wrap.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Frusdl
|
2
|
+
module Wrap
|
3
|
+
module ClassMethods
|
4
|
+
def make_struct_reader(name, sname = nil)
|
5
|
+
method_name = name.to_sym
|
6
|
+
struct_name = sname ? sname.to_sym : method_name
|
7
|
+
define_method(method_name) do
|
8
|
+
return @struct[struct_name]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def make_struct_writer(name, sname = nil)
|
13
|
+
method_name = "#{name}=".to_sym
|
14
|
+
struct_name = sname ? sname.to_sym : name.to_sym
|
15
|
+
define_method(method_name) do | value |
|
16
|
+
return @struct[struct_name] = value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def struct_accessor(name, sname = nil)
|
21
|
+
make_struct_reader name, sname
|
22
|
+
make_struct_writer name, sname
|
23
|
+
end
|
24
|
+
|
25
|
+
def struct_reader(name, sname = nil)
|
26
|
+
make_struct_reader name, sname
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# From here it's instance methods
|
31
|
+
|
32
|
+
# Initializes the pointer and struct members
|
33
|
+
def initialize_pointer(ptr, klass)
|
34
|
+
@pointer = ptr
|
35
|
+
@struct = klass.new(ptr)
|
36
|
+
# define an accessor when this is called
|
37
|
+
unless self.respond_to? :pointer
|
38
|
+
self.klass.attr_reader(:pointer)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.included(base)
|
43
|
+
base.extend(Frusdl::Wrap::ClassMethods)
|
44
|
+
# Also extend with class methods
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: frusdl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bjorn De Meyer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-05 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ffi
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.0
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: beoran@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
files:
|
34
|
+
- lib/frusdl
|
35
|
+
- lib/frusdl/sdl
|
36
|
+
- lib/frusdl/sdl/pixelformat.rb
|
37
|
+
- lib/frusdl/sdl/surface.rb
|
38
|
+
- lib/frusdl/sdl/screen.rb
|
39
|
+
- lib/frusdl/sdl/videoinfo.rb
|
40
|
+
- lib/frusdl/wrap.rb
|
41
|
+
- lib/frusdl/low
|
42
|
+
- lib/frusdl/low/sge.rb
|
43
|
+
- lib/frusdl/low/ttf.rb
|
44
|
+
- lib/frusdl/low/gfx.rb
|
45
|
+
- lib/frusdl/low/mix.rb
|
46
|
+
- lib/frusdl/low/img.rb
|
47
|
+
- lib/frusdl/low/sdl.rb
|
48
|
+
- lib/frusdl/low.rb
|
49
|
+
- lib/frusdl/sdl.rb
|
50
|
+
- lib/frusdl.rb
|
51
|
+
- README
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://frusdl.rubyforge.org
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project: frusdl
|
74
|
+
rubygems_version: 1.3.1
|
75
|
+
signing_key:
|
76
|
+
specification_version: 2
|
77
|
+
summary: FFI bindings to SDL, SDL_image, SDL_ttf, SDL_mixer, SGE and SFL_gfx
|
78
|
+
test_files: []
|
79
|
+
|