sdl2_ffi 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile +6 -0
- data/Guardfile +47 -25
- data/Rakefile +6 -0
- data/bin/approvals +16 -0
- data/bin/autospec +16 -0
- data/bin/htmldiff +16 -0
- data/bin/ldiff +16 -0
- data/bin/nokogiri +16 -0
- data/bin/rspec +16 -0
- data/lib/enumerable_constants.rb +23 -8
- data/lib/sdl2.rb +116 -39
- data/lib/sdl2/color.rb +19 -7
- data/lib/sdl2/events.rb +184 -85
- data/lib/sdl2/gamecontroller.rb +1 -1
- data/lib/sdl2/gem_version.rb +1 -1
- data/lib/sdl2/joystick.rb +1 -1
- data/lib/sdl2/keyboard.rb +3 -0
- data/lib/sdl2/mouse.rb +5 -5
- data/lib/sdl2/pixel_format.rb +11 -3
- data/lib/sdl2/pixels.rb +40 -40
- data/lib/sdl2/point.rb +17 -1
- data/lib/sdl2/power.rb +12 -3
- data/lib/sdl2/rect.rb +19 -0
- data/lib/sdl2/render.rb +3 -3
- data/lib/sdl2/scancode.rb +7 -0
- data/lib/sdl2/stdinc.rb +2 -0
- data/lib/sdl2/surface.rb +64 -12
- data/lib/sdl2/ttf.rb +52 -66
- data/lib/sdl2/ttf/font.rb +115 -0
- data/lib/sdl2/video.rb +23 -23
- data/lib/sdl2/window.rb +15 -15
- data/sdl2_ffi.gemspec +5 -2
- data/spec/fixtures/approvals/lazyfoonet_lesson_01_hello_world/draws_hello_to_the_window_surface.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_01_hello_world/loaded_and_optimizes_hello_bitmap.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_02_optimized_images/draws_the_message_and_background.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_03_extension_libraries/should_blit_a_png_to_screen.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_04_event_driven_programming/draws_something_to_the_screen.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_05_color_keying/draws_the_sprite_using_a_color_key.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_06_clip_blitting_and_sprite_sheets/draws_the_clipped_sprites_to_the_screen.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/draws_the_message_to_the_screen.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/writes_a_message_to_a_surface.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_08_key_presses/rendered_the_down_message.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_08_key_presses/rendered_the_left_message.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_08_key_presses/rendered_the_right_message.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_08_key_presses/rendered_the_up_message.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_color/looks_blue_when_it_should.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_color/looks_green_when_it_should.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_color/looks_red_when_it_should.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_color/should_cast_arrays_properly.approved.png +0 -0
- data/spec/fixtures/approvals/sdl2_color/should_cast_hashes_properly.approved.png +0 -0
- data/spec/fixtures/fonts/FreeMono.ttf +0 -0
- data/spec/fixtures/fonts/GaroaHackerClubeBold.otf +0 -0
- data/spec/fixtures/fonts/GaroaHackerClubeBold.otf.credits.yaml +4 -0
- data/spec/fixtures/images/an_example.png +0 -0
- data/spec/fixtures/images/background.bmp +0 -0
- data/spec/fixtures/images/background.jpg +0 -0
- data/spec/fixtures/images/background.png +0 -0
- data/spec/fixtures/images/foo.jpg +0 -0
- data/spec/fixtures/images/hello.bmp +0 -0
- data/spec/fixtures/images/sprites.jpg +0 -0
- data/spec/fixtures/images/tile.png +0 -0
- data/spec/fixtures/images/x.png +0 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +39 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_02_optimized_images_spec.rb +51 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +31 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +55 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_05_color_keying_spec.rb +41 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_06_clip_blitting_and_sprite_sheets_spec.rb +41 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +56 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +120 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_helper.rb +6 -0
- data/spec/png_writer.rb +21 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/unit/sdl2/color_spec.rb +46 -0
- data/spec/unit/unit_helper.rb +3 -0
- data/test/approvals/clip_blitting_and_sprite_sheets.received.bmp +0 -0
- data/test/approvals/color_keying_example.approved.png +0 -0
- data/test/approvals/hello_world_example_hello.approved.png +0 -0
- data/test/approvals/hello_world_example_screen.approved.png +0 -0
- data/test/approvals/optimized_surface_loading.approved.png +0 -0
- data/test/fixtures/background.jpg +0 -0
- data/test/fixtures/foo.jpg +0 -0
- data/test/fixtures/sprites.jpg +0 -0
- data/test/fixtures/x.png +0 -0
- data/test/functional/examples/lazyfoo.net_s/test_clip_blitting_and_sprite_sheets.rb +50 -0
- data/test/functional/examples/lazyfoo.net_s/test_color_keying.rb +42 -0
- data/test/functional/examples/test_lazy_foo_examples.rb +120 -48
- data/test/test_helper.rb +9 -0
- metadata +138 -4
- data/graph +0 -566
data/lib/sdl2/gamecontroller.rb
CHANGED
@@ -31,7 +31,7 @@ module SDL2
|
|
31
31
|
end#GameController
|
32
32
|
|
33
33
|
api :SDL_GameControllerAddMapping, [:string], :int
|
34
|
-
api :SDL_GameControllerMappingForGUID, [JoystickGUID], :string
|
34
|
+
api :SDL_GameControllerMappingForGUID, [JoystickGUID.by_value], :string
|
35
35
|
api :SDL_GameControllerMapping, [GameController.by_ref], :string
|
36
36
|
api :SDL_IsGameController, [:joystick_index], :bool
|
37
37
|
api :SDL_GameControllerNameForIndex, [:joystick_index], :string
|
data/lib/sdl2/gem_version.rb
CHANGED
data/lib/sdl2/joystick.rb
CHANGED
@@ -28,7 +28,7 @@ module SDL2
|
|
28
28
|
api :SDL_JoystickName, [Joystick.by_ref], :string
|
29
29
|
api :SDL_JoystickGetDeviceGUID, [:int], JoystickGUID
|
30
30
|
api :SDL_JoystickGetGUID, [Joystick.by_ref], JoystickGUID
|
31
|
-
api :SDL_JoystickGetGUIDString, [JoystickGUID, :pointer, :int], :void
|
31
|
+
api :SDL_JoystickGetGUIDString, [JoystickGUID.by_value, :pointer, :int], :void
|
32
32
|
api :SDL_JoystickGetGUIDFromString, [:string], JoystickGUID
|
33
33
|
api :SDL_JoystickGetAttached, [Joystick.by_ref], :bool
|
34
34
|
api :SDL_JoystickInstanceID, [Joystick.by_ref], :joystick_id
|
data/lib/sdl2/keyboard.rb
CHANGED
data/lib/sdl2/mouse.rb
CHANGED
@@ -35,11 +35,11 @@ module SDL2
|
|
35
35
|
|
36
36
|
module BUTTON
|
37
37
|
include EnumerableConstants
|
38
|
-
LEFT
|
39
|
-
MIDDLE
|
40
|
-
RIGHT
|
41
|
-
X1
|
42
|
-
X2
|
38
|
+
LEFT
|
39
|
+
MIDDLE
|
40
|
+
RIGHT
|
41
|
+
X1
|
42
|
+
X2
|
43
43
|
end
|
44
44
|
|
45
45
|
module BUTTONMASK
|
data/lib/sdl2/pixel_format.rb
CHANGED
@@ -5,9 +5,9 @@ module SDL2
|
|
5
5
|
|
6
6
|
# SDL_pixels.h:272~293:typdef struct SDL_PixelFormat
|
7
7
|
# \note Everything in the pixel format structure is read-only.
|
8
|
-
class PixelFormat <
|
8
|
+
class PixelFormat < Struct
|
9
9
|
|
10
|
-
|
10
|
+
protected :[] # see note
|
11
11
|
|
12
12
|
layout :format, :pixel_format,
|
13
13
|
:palette, Palette.by_ref,
|
@@ -79,6 +79,13 @@ module SDL2
|
|
79
79
|
|
80
80
|
alias_method :palette=, :set_palette
|
81
81
|
|
82
|
+
# Maps a color struct to a pixel value.
|
83
|
+
def map(color)
|
84
|
+
#binding.pry
|
85
|
+
c = Color.cast(color)
|
86
|
+
map_rgba(c.to_a)
|
87
|
+
end
|
88
|
+
|
82
89
|
# Maps an RGB triple (array) to an opaque pixel value
|
83
90
|
def map_rgb(rgb)
|
84
91
|
r, g, b = *rgb
|
@@ -87,7 +94,8 @@ module SDL2
|
|
87
94
|
|
88
95
|
# Maps an RGBA quadruple (array) to a pixel value
|
89
96
|
def map_rgba(rgba)
|
90
|
-
r, g, b, a =
|
97
|
+
r, g, b, a = rgba
|
98
|
+
a = 0 if a.nil?
|
91
99
|
SDL2.map_rgba(self, r, g, b, a)
|
92
100
|
end
|
93
101
|
|
data/lib/sdl2/pixels.rb
CHANGED
@@ -10,27 +10,27 @@ module SDL2
|
|
10
10
|
# Predefined pixel types.
|
11
11
|
module PIXELTYPE
|
12
12
|
include EnumerableConstants
|
13
|
-
UNKNOWN
|
14
|
-
INDEX1
|
15
|
-
INDEX4
|
16
|
-
INDEX8
|
17
|
-
PACKED8
|
18
|
-
PACKED16
|
19
|
-
PACKED32
|
20
|
-
ARRAYU8
|
21
|
-
ARRAYU16
|
22
|
-
ARRAYU32
|
23
|
-
ARRAYF16
|
24
|
-
ARRAYF32
|
13
|
+
UNKNOWN
|
14
|
+
INDEX1
|
15
|
+
INDEX4
|
16
|
+
INDEX8
|
17
|
+
PACKED8
|
18
|
+
PACKED16
|
19
|
+
PACKED32
|
20
|
+
ARRAYU8
|
21
|
+
ARRAYU16
|
22
|
+
ARRAYU32
|
23
|
+
ARRAYF16
|
24
|
+
ARRAYF32
|
25
25
|
end
|
26
26
|
enum :pixeltype, PIXELTYPE.flatten_consts
|
27
27
|
|
28
28
|
# Bitmap pixel order, high bit -> low bit
|
29
29
|
module BITMAPORDER
|
30
30
|
include EnumerableConstants
|
31
|
-
NONE
|
32
|
-
N4321
|
33
|
-
N1234
|
31
|
+
NONE
|
32
|
+
N4321
|
33
|
+
N1234
|
34
34
|
end
|
35
35
|
|
36
36
|
enum :bitmaporder, BITMAPORDER.flatten_consts
|
@@ -38,15 +38,15 @@ module SDL2
|
|
38
38
|
# Packed component order, high bit -> low bit
|
39
39
|
module PACKEDORDER
|
40
40
|
include EnumerableConstants
|
41
|
-
NONE
|
42
|
-
XRGB
|
43
|
-
RGBX
|
44
|
-
ARGB
|
45
|
-
RGBA
|
46
|
-
XBGR
|
47
|
-
BGRX
|
48
|
-
ABGR
|
49
|
-
BGRA
|
41
|
+
NONE
|
42
|
+
XRGB
|
43
|
+
RGBX
|
44
|
+
ARGB
|
45
|
+
RGBA
|
46
|
+
XBGR
|
47
|
+
BGRX
|
48
|
+
ABGR
|
49
|
+
BGRA
|
50
50
|
end
|
51
51
|
|
52
52
|
enum :packedorder, PACKEDORDER.flatten_consts
|
@@ -54,13 +54,13 @@ module SDL2
|
|
54
54
|
# Array component order, low byte -> hight byte
|
55
55
|
module ARRAYORDER
|
56
56
|
include EnumerableConstants
|
57
|
-
NONE
|
58
|
-
RGB
|
59
|
-
RGBA
|
60
|
-
ARGB
|
61
|
-
BGR
|
62
|
-
BGRA
|
63
|
-
ABGR
|
57
|
+
NONE
|
58
|
+
RGB
|
59
|
+
RGBA
|
60
|
+
ARGB
|
61
|
+
BGR
|
62
|
+
BGRA
|
63
|
+
ABGR
|
64
64
|
end
|
65
65
|
|
66
66
|
enum :arrayorder, ARRAYORDER.flatten_consts
|
@@ -68,15 +68,15 @@ module SDL2
|
|
68
68
|
# Packed component layout
|
69
69
|
module PACKEDLAYOUT
|
70
70
|
include EnumerableConstants
|
71
|
-
NONE
|
72
|
-
N332
|
73
|
-
N4444
|
74
|
-
N1555
|
75
|
-
N5551
|
76
|
-
N565
|
77
|
-
N8888
|
78
|
-
N2101010
|
79
|
-
N1010102
|
71
|
+
NONE
|
72
|
+
N332
|
73
|
+
N4444
|
74
|
+
N1555
|
75
|
+
N5551
|
76
|
+
N565
|
77
|
+
N8888
|
78
|
+
N2101010
|
79
|
+
N1010102
|
80
80
|
end
|
81
81
|
|
82
82
|
enum :packedlayout, PACKEDLAYOUT.flatten_consts
|
data/lib/sdl2/point.rb
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
require 'sdl2'
|
2
2
|
|
3
3
|
module SDL2
|
4
|
-
class Point <
|
4
|
+
class Point < Struct
|
5
5
|
layout :x, :int, :y, :int
|
6
|
+
|
7
|
+
member_readers *members
|
8
|
+
member_writers *members
|
9
|
+
|
10
|
+
def self.cast(something)
|
11
|
+
if something.kind_of?(Array) and something.count == 2
|
12
|
+
something.map!(&:to_i)
|
13
|
+
result = Point.new
|
14
|
+
result.x, result.y = something
|
15
|
+
return result
|
16
|
+
else
|
17
|
+
return super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
6
22
|
end
|
7
23
|
end
|
data/lib/sdl2/power.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
require 'sdl2'
|
2
2
|
|
3
3
|
module SDL2
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
module POWERSTATE
|
6
|
+
include EnumerableConstants
|
7
|
+
UNKOWN
|
8
|
+
ON_BATTERY
|
9
|
+
NO_BATTERY
|
10
|
+
CHARGING
|
11
|
+
CHARGED
|
12
|
+
end
|
13
|
+
enum :powerstate, POWERSTATE.flatten_consts
|
14
|
+
|
6
15
|
|
7
16
|
api :SDL_GetPowerInfo, [IntStruct.by_ref, IntStruct.by_ref], :powerstate
|
8
|
-
|
17
|
+
|
9
18
|
end
|
data/lib/sdl2/rect.rb
CHANGED
@@ -11,6 +11,25 @@ module SDL2
|
|
11
11
|
member_readers *members
|
12
12
|
member_writers *members
|
13
13
|
|
14
|
+
def self.cast(something)
|
15
|
+
|
16
|
+
if something.kind_of?(Array)
|
17
|
+
something.map!(&:to_i)
|
18
|
+
result = Rect.new
|
19
|
+
case something.count
|
20
|
+
when 4
|
21
|
+
result.x, result.y, result.w, result.h = something
|
22
|
+
when 2
|
23
|
+
result.x, result.y = something
|
24
|
+
else
|
25
|
+
raise "#{self}#cast cannot convert array length #{something.count} of: #{something.inspect}"
|
26
|
+
end
|
27
|
+
return result
|
28
|
+
else
|
29
|
+
return super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
14
33
|
def empty
|
15
34
|
return ((!self.null?) || (self[:w] <= 0) || (self[:h] <= 0))
|
16
35
|
end
|
data/lib/sdl2/render.rb
CHANGED
@@ -10,9 +10,9 @@ module SDL2
|
|
10
10
|
# The access pattern allowed for a texture
|
11
11
|
module TEXTUREACCESS
|
12
12
|
include EnumerableConstants
|
13
|
-
STATIC
|
14
|
-
STREAMING
|
15
|
-
TARGET
|
13
|
+
STATIC
|
14
|
+
STREAMING
|
15
|
+
TARGET
|
16
16
|
end
|
17
17
|
enum :texture_access, TEXTUREACCESS.flatten_consts
|
18
18
|
|
data/lib/sdl2/scancode.rb
CHANGED
@@ -2,10 +2,17 @@ require 'sdl2'
|
|
2
2
|
|
3
3
|
|
4
4
|
module SDL2
|
5
|
+
# Not a key, just marks the number of scancodes for array bounds
|
5
6
|
NUM_SCANCODES = 512
|
6
7
|
|
8
|
+
# The SDL keyboard scancode representation.
|
9
|
+
#
|
10
|
+
# Values of this type are used to represent keyboard keys, among other places
|
11
|
+
# in the Keysym#scancode field of the Event structure.
|
7
12
|
module SCANCODE
|
8
13
|
include EnumerableConstants
|
14
|
+
UNKOWN = 0
|
15
|
+
|
9
16
|
A = 4
|
10
17
|
B = 5
|
11
18
|
C = 6
|
data/lib/sdl2/stdinc.rb
CHANGED
data/lib/sdl2/surface.rb
CHANGED
@@ -28,7 +28,7 @@ module SDL2
|
|
28
28
|
:clip_rect, Rect,
|
29
29
|
:map, :pointer,
|
30
30
|
:refcount, :int
|
31
|
-
|
31
|
+
|
32
32
|
member_readers(*members)
|
33
33
|
|
34
34
|
[:flags, :format, :w, :h, :pixels, :userdata, :locked, :lock_data, :clip_rect, :map, :refcount].each do |field|
|
@@ -104,14 +104,21 @@ module SDL2
|
|
104
104
|
self[:flags] & RLEACCEL != 0
|
105
105
|
end
|
106
106
|
|
107
|
-
# Blit from source to this surface
|
107
|
+
# Blit from source to this surface
|
108
108
|
def blit_in(src, src_rect = nil, dst_rect = nil)
|
109
|
+
|
110
|
+
|
111
|
+
src_rect = Rect.cast(src_rect)
|
112
|
+
dst_rect = Rect.cast(dst_rect)
|
113
|
+
|
109
114
|
SDL2.blit_surface!(src, src_rect, self, dst_rect)
|
110
115
|
end
|
111
116
|
|
112
117
|
# Blit from this surface to dest
|
113
|
-
def blit_out(dest,
|
114
|
-
|
118
|
+
def blit_out(dest, dst_rect = nil, src_rect = nil)
|
119
|
+
src_rect = Rect.cast(src_rect)
|
120
|
+
dst_rect = Rect.cast(dst_rect)
|
121
|
+
SDL2.blit_surface!(self, src_rect, dest, dst_rect)
|
115
122
|
end
|
116
123
|
|
117
124
|
def set_rle(flag)
|
@@ -120,20 +127,62 @@ module SDL2
|
|
120
127
|
|
121
128
|
alias_method :rle=, :set_rle
|
122
129
|
|
123
|
-
|
124
|
-
|
130
|
+
# Sets the color key for this surface.
|
131
|
+
# @param key may be 1) A pixel value encoded for this surface's format
|
132
|
+
# 2) Anything that Color::cast can handle.
|
133
|
+
# 3) Nil, which will disable the color key for this surface.
|
134
|
+
def set_color_key(key)
|
135
|
+
if key.kind_of? Integer
|
136
|
+
pixel_value = key
|
137
|
+
else
|
138
|
+
pixel_value = format.map_rgb(Color.cast(key))
|
139
|
+
end
|
140
|
+
|
141
|
+
if key.nil?#then disable color keying
|
142
|
+
SDL2.set_color_key(self, false, 0)
|
143
|
+
else# Enable color key by value
|
144
|
+
SDL2.set_color_key(self, true, pixel_value)
|
145
|
+
end
|
125
146
|
end
|
126
147
|
|
148
|
+
# Gets the color key for this surface.
|
149
|
+
# @returns Nil, indicating no color keying, or the encoded pixel value used.
|
127
150
|
def get_color_key()
|
128
151
|
key_s = UInt32Struct.new
|
129
|
-
SDL2.get_color_key
|
130
|
-
|
152
|
+
if SDL2.get_color_key?(self, key_s)
|
153
|
+
result = key_s[:value]
|
154
|
+
else
|
155
|
+
result = nil
|
156
|
+
end
|
157
|
+
key_s.free
|
158
|
+
return result
|
131
159
|
end
|
132
160
|
|
161
|
+
alias_method :color_key, :get_color_key
|
162
|
+
alias_method :color_key=, :set_color_key
|
163
|
+
|
133
164
|
# Convert existing surface into this surface's format
|
134
165
|
def convert(surface, flags = 0)
|
135
166
|
SDL2.convert_surface!(surface, self.format, flags)
|
136
167
|
end
|
168
|
+
|
169
|
+
def fill_rect(rect, color)
|
170
|
+
|
171
|
+
if color.kind_of? Integer
|
172
|
+
pixel_value = color
|
173
|
+
else
|
174
|
+
|
175
|
+
pixel_value = format.map(Color.cast(color))
|
176
|
+
end
|
177
|
+
rect = Rect.cast(rect)
|
178
|
+
SDL2.fill_rect!(self, rect, pixel_value)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns a RECT for the whole surface:
|
182
|
+
def rect
|
183
|
+
Rect.cast(x: 0, y: 0, w: self.w, h: self.h)
|
184
|
+
end
|
185
|
+
|
137
186
|
end
|
138
187
|
|
139
188
|
callback :blit, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
|
@@ -154,13 +203,15 @@ module SDL2
|
|
154
203
|
|
155
204
|
api :SDL_SaveBMP_RW, [Surface.by_ref, RWops.by_ref, :int], :int
|
156
205
|
|
157
|
-
def self.save_bmp(file)
|
158
|
-
SDL2.save_bmp_rw(RWops.from_file(file, 'wb'), 1)
|
206
|
+
def self.save_bmp(surface, file)
|
207
|
+
SDL2.save_bmp_rw(surface, RWops.from_file(file, 'wb'), 1)
|
159
208
|
end
|
160
209
|
|
161
210
|
api :SDL_SetSurfaceRLE, [Surface.by_ref, :int], :int
|
162
|
-
api :SDL_SetColorKey, [Surface.by_ref, :
|
163
|
-
api :SDL_GetColorKey, [Surface.by_ref, UInt32Struct.by_ref], :int
|
211
|
+
api :SDL_SetColorKey, [Surface.by_ref, :bool, :int], :int, {error: true}
|
212
|
+
api :SDL_GetColorKey, [Surface.by_ref, UInt32Struct.by_ref], :int, {error: true}
|
213
|
+
# Could mean an SDL error... or maybe not?
|
214
|
+
boolean? :get_color_key, TRUE_WHEN_ZERO
|
164
215
|
api :SDL_SetSurfaceColorMod, [Surface.by_ref, :uint8, :uint8, :uint8], :int
|
165
216
|
api :SDL_GetSurfaceColorMod, [Surface.by_ref, UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref], :int
|
166
217
|
api :SDL_SetSurfaceAlphaMod, [Surface.by_ref, :uint8], :int, {error: true}
|
@@ -178,6 +229,7 @@ module SDL2
|
|
178
229
|
|
179
230
|
# using upper_blit
|
180
231
|
def self.blit_surface(src, srcrect, dst, dstrect)
|
232
|
+
|
181
233
|
upper_blit(src, srcrect, dst, dstrect)
|
182
234
|
end
|
183
235
|
|
data/lib/sdl2/ttf.rb
CHANGED
@@ -3,44 +3,31 @@ require 'sdl2/version'
|
|
3
3
|
require 'sdl2/rwops'
|
4
4
|
require 'sdl2/color'
|
5
5
|
require 'sdl2/ttf/sdl_ttf_module'
|
6
|
+
require 'sdl2/ttf/font'
|
6
7
|
require 'active_support/inflector'
|
7
8
|
|
8
|
-
|
9
9
|
module SDL2
|
10
|
+
|
10
11
|
# The SDL_ttf interface. API prototypes are linked to this module.
|
11
12
|
module TTF
|
12
|
-
|
13
|
+
|
13
14
|
extend FFI::Library
|
15
|
+
extend SDL2::Library
|
14
16
|
ffi_lib SDL_TTF_MODULE
|
15
|
-
|
16
|
-
def self.api(func_name, args, type)
|
17
|
-
camelCaseName = func_name.to_s.gsub('TTF_','')
|
18
|
-
methodName = ActiveSupport::Inflector.underscore(camelCaseName).to_sym
|
19
|
-
self.attach_function methodName, func_name, args, type
|
20
|
-
return methodName
|
21
|
-
end
|
22
|
-
|
17
|
+
|
23
18
|
api :TTF_Linked_Version, [], Version.auto_ptr
|
24
|
-
|
19
|
+
|
25
20
|
UNICODE_BOM_NATIVE = 0xFEFF
|
26
21
|
UNICODE_BOM_SWAPPED = 0xFFFE
|
27
|
-
|
22
|
+
|
28
23
|
api :TTF_ByteSwappedUNICODE, [:int], :void
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def self.release(pointer)
|
33
|
-
close_font(pointer)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
api :TTF_Init, [], :int
|
39
|
-
api :TTF_OpenFont, [:string, :int], Font.auto_ptr
|
24
|
+
|
25
|
+
api :TTF_Init, [], :int, {error: true, filter: TRUE_WHEN_ZERO}
|
26
|
+
api :TTF_OpenFont, [:string, :int], Font.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
40
27
|
api :TTF_OpenFontIndex, [:string, :int, :long], Font.auto_ptr
|
41
28
|
api :TTF_OpenFontRW, [RWops.by_ref, :int, :int], Font.auto_ptr
|
42
29
|
api :TTF_OpenFontIndexRW, [RWops.by_ref, :int, :int, :long], Font.auto_ptr
|
43
|
-
|
30
|
+
|
44
31
|
module STYLE
|
45
32
|
include EnumerableConstants
|
46
33
|
NORMAL = 0x00
|
@@ -49,15 +36,15 @@ module SDL2
|
|
49
36
|
UNDERLINE = 0x04
|
50
37
|
STRIKETHROUGH = 0x08
|
51
38
|
end
|
52
|
-
|
39
|
+
|
53
40
|
enum :font_style, STYLE.flatten_consts
|
54
|
-
|
41
|
+
|
55
42
|
api :TTF_GetFontStyle, [Font.by_ref], :int
|
56
43
|
api :TTF_SetFontStyle, [Font.by_ref, :int], :void
|
57
44
|
api :TTF_GetFontOutline, [Font.by_ref], :int
|
58
45
|
api :TTF_SetFontOutline, [Font.by_ref, :int], :void
|
59
|
-
|
60
|
-
module HINTING
|
46
|
+
|
47
|
+
module HINTING
|
61
48
|
include EnumerableConstants
|
62
49
|
NORMAL = 0
|
63
50
|
LIGHT = 1
|
@@ -65,10 +52,10 @@ module SDL2
|
|
65
52
|
NONE = 3
|
66
53
|
end
|
67
54
|
enum :hinting, HINTING.flatten_consts
|
68
|
-
|
55
|
+
|
69
56
|
api :TTF_GetFontHinting, [Font.by_ref], :hinting
|
70
57
|
api :TTF_SetFontHinting, [Font.by_ref, :int], :void
|
71
|
-
|
58
|
+
|
72
59
|
api :TTF_FontHeight, [Font.by_ref], :int
|
73
60
|
api :TTF_FontAscent, [Font.by_ref], :int
|
74
61
|
api :TTF_FontDescent, [Font.by_ref], :int
|
@@ -79,51 +66,50 @@ module SDL2
|
|
79
66
|
api :TTF_FontFaceIsFixedWidth, [Font.by_ref], :int
|
80
67
|
api :TTF_FontFaceFamilyName, [Font.by_ref], :string
|
81
68
|
api :TTF_FontFaceStyleName, [Font.by_ref], :string
|
82
|
-
|
69
|
+
|
83
70
|
api :TTF_GlyphIsProvided, [Font.by_ref, :uint16], :int
|
84
|
-
|
71
|
+
|
85
72
|
api :TTF_GlyphMetrics, [
|
86
|
-
Font.by_ref,
|
87
|
-
:uint16,
|
88
|
-
IntStruct.by_ref,
|
89
|
-
IntStruct.by_ref,
|
90
|
-
IntStruct.by_ref,
|
91
|
-
IntStruct.by_ref,
|
73
|
+
Font.by_ref,
|
74
|
+
:uint16,
|
75
|
+
IntStruct.by_ref,
|
76
|
+
IntStruct.by_ref,
|
77
|
+
IntStruct.by_ref,
|
78
|
+
IntStruct.by_ref,
|
92
79
|
IntStruct.by_ref
|
93
|
-
], :int
|
94
|
-
|
95
|
-
|
80
|
+
], :int
|
81
|
+
|
96
82
|
api :TTF_SizeText, [Font.by_ref, :string, IntStruct.by_ref, IntStruct.by_ref], :int
|
97
83
|
api :TTF_SizeUTF8, [Font.by_ref, :string, IntStruct.by_ref, IntStruct.by_ref], :int
|
98
84
|
api :TTF_SizeUNICODE, [Font.by_ref, :string, IntStruct.by_ref, IntStruct.by_ref], :int
|
99
|
-
|
100
|
-
api :TTF_RenderText_Solid, [Font.by_ref, :string, Color], Surface.auto_ptr
|
101
|
-
api :TTF_RenderUTF8_Solid, [Font.by_ref, :string, Color], Surface.auto_ptr
|
102
|
-
api :TTF_RenderUNICODE_Solid, [Font.by_ref, :string, Color], Surface.auto_ptr
|
103
|
-
|
104
|
-
api :TTF_RenderGlyph_Solid, [Font.by_ref, :uint16, Color], Surface.auto_ptr
|
105
|
-
|
106
|
-
api :TTF_RenderText_Shaded, [Font.by_ref, :string, Color, Color], Surface.auto_ptr
|
107
|
-
api :TTF_RenderUTF8_Shaded, [Font.by_ref, :string, Color, Color], Surface.auto_ptr
|
108
|
-
api :TTF_RenderUNICODE_Shaded, [Font.by_ref, :string, Color, Color], Surface.auto_ptr
|
109
|
-
|
110
|
-
api :TTF_RenderGlyph_Shaded, [Font.by_ref, :uint16, Color, Color], Surface.auto_ptr
|
111
|
-
|
112
|
-
api :TTF_RenderText_Blended, [Font.by_ref, :string, Color], Surface.auto_ptr
|
113
|
-
api :TTF_RenderUTF8_Blended, [Font.by_ref, :string, Color], Surface.auto_ptr
|
114
|
-
api :TTF_RenderUNICODE_Blended, [Font.by_ref, :string, Color], Surface.auto_ptr
|
115
|
-
|
116
|
-
api :TTF_RenderText_Blended_Wrapped, [Font.by_ref, :string, Color, :uint32], Surface.auto_ptr
|
117
|
-
api :TTF_RenderUTF8_Blended_Wrapped, [Font.by_ref, :string, Color, :uint32], Surface.auto_ptr
|
118
|
-
api :TTF_RenderUNICODE_Blended_Wrapped, [Font.by_ref, :string, Color, :uint32], Surface.auto_ptr
|
119
|
-
|
120
|
-
api :TTF_RenderGlyph_Blended, [Font.by_ref, :uint16, Color], Surface.auto_ptr
|
121
|
-
|
85
|
+
|
86
|
+
api :TTF_RenderText_Solid, [Font.by_ref, :string, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
87
|
+
api :TTF_RenderUTF8_Solid, [Font.by_ref, :string, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
88
|
+
api :TTF_RenderUNICODE_Solid, [Font.by_ref, :string, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
89
|
+
|
90
|
+
api :TTF_RenderGlyph_Solid, [Font.by_ref, :uint16, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
91
|
+
|
92
|
+
api :TTF_RenderText_Shaded, [Font.by_ref, :string, Color.by_value, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
93
|
+
api :TTF_RenderUTF8_Shaded, [Font.by_ref, :string, Color.by_value, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
94
|
+
api :TTF_RenderUNICODE_Shaded, [Font.by_ref, :string, Color.by_value, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
95
|
+
|
96
|
+
api :TTF_RenderGlyph_Shaded, [Font.by_ref, :uint16, Color.by_value, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
97
|
+
|
98
|
+
api :TTF_RenderText_Blended, [Font.by_ref, :string, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
99
|
+
api :TTF_RenderUTF8_Blended, [Font.by_ref, :string, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
100
|
+
api :TTF_RenderUNICODE_Blended, [Font.by_ref, :string, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
101
|
+
|
102
|
+
api :TTF_RenderText_Blended_Wrapped, [Font.by_ref, :string, Color.by_value, :uint32], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
103
|
+
api :TTF_RenderUTF8_Blended_Wrapped, [Font.by_ref, :string, Color.by_value, :uint32], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
104
|
+
api :TTF_RenderUNICODE_Blended_Wrapped, [Font.by_ref, :string, Color.by_value, :uint32], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
105
|
+
|
106
|
+
api :TTF_RenderGlyph_Blended, [Font.by_ref, :uint16, Color.by_value], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
|
107
|
+
|
122
108
|
api :TTF_CloseFont, [Font.by_ref], :void
|
123
109
|
api :TTF_Quit, [], :void
|
124
110
|
api :TTF_WasInit, [], :int
|
125
111
|
api :TTF_GetFontKerningSize, [Font.by_ref, :int, :int], :int
|
126
|
-
|
112
|
+
|
127
113
|
end
|
128
|
-
|
114
|
+
|
129
115
|
end
|