SDLRuby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +12 -0
- data/lib/SDLRuby/audio.rb +65 -0
- data/lib/SDLRuby/cursor.rb +46 -0
- data/lib/SDLRuby/display.rb +79 -0
- data/lib/SDLRuby/event/accessor.rb +127 -0
- data/lib/SDLRuby/event/type.rb +75 -0
- data/lib/SDLRuby/event.rb +80 -0
- data/lib/SDLRuby/font.rb +227 -0
- data/lib/SDLRuby/hint.rb +36 -0
- data/lib/SDLRuby/image/image.rb +23 -0
- data/lib/SDLRuby/image/include/SDL_image.h.rb +61 -0
- data/lib/SDLRuby/image.rb +69 -0
- data/lib/SDLRuby/keyboard.rb +58 -0
- data/lib/SDLRuby/mixer/channel.rb +43 -0
- data/lib/SDLRuby/mixer/chunk.rb +49 -0
- data/lib/SDLRuby/mixer/controller.rb +44 -0
- data/lib/SDLRuby/mixer/include/SDL_mixer.h.rb +95 -0
- data/lib/SDLRuby/mixer/sdl_mixer.rb +60 -0
- data/lib/SDLRuby/mixer.rb +87 -0
- data/lib/SDLRuby/mouse.rb +52 -0
- data/lib/SDLRuby/music.rb +158 -0
- data/lib/SDLRuby/palette.rb +49 -0
- data/lib/SDLRuby/pixel_formatter.rb +67 -0
- data/lib/SDLRuby/rect.rb +11 -0
- data/lib/SDLRuby/renderer/accessor.rb +70 -0
- data/lib/SDLRuby/renderer/drawer.rb +107 -0
- data/lib/SDLRuby/renderer/renderer_info.rb +27 -0
- data/lib/SDLRuby/renderer.rb +101 -0
- data/lib/SDLRuby/rw_ops/rw_object.rb +128 -0
- data/lib/SDLRuby/rw_ops.rb +216 -0
- data/lib/SDLRuby/sdl/include/SDL.h.rb +33 -0
- data/lib/SDLRuby/sdl/include/SDL_audio.h.rb +49 -0
- data/lib/SDLRuby/sdl/include/SDL_blendmode.h.rb +6 -0
- data/lib/SDLRuby/sdl/include/SDL_clipboard.h.rb +10 -0
- data/lib/SDLRuby/sdl/include/SDL_config.h.rb +13 -0
- data/lib/SDLRuby/sdl/include/SDL_cpuinfo.h.rb +27 -0
- data/lib/SDLRuby/sdl/include/SDL_endian.h.rb +3 -0
- data/lib/SDLRuby/sdl/include/SDL_error.h.rb +9 -0
- data/lib/SDLRuby/sdl/include/SDL_events.h.rb +32 -0
- data/lib/SDLRuby/sdl/include/SDL_filesystem.h.rb +6 -0
- data/lib/SDLRuby/sdl/include/SDL_gamecontroller.h.rb +66 -0
- data/lib/SDLRuby/sdl/include/SDL_gesture.h.rb +12 -0
- data/lib/SDLRuby/sdl/include/SDL_guid.h.rb +7 -0
- data/lib/SDLRuby/sdl/include/SDL_hints.h.rb +14 -0
- data/lib/SDLRuby/sdl/include/SDL_joystick.h.rb +69 -0
- data/lib/SDLRuby/sdl/include/SDL_keyboard.h.rb +26 -0
- data/lib/SDLRuby/sdl/include/SDL_keycode.h.rb +7 -0
- data/lib/SDLRuby/sdl/include/SDL_locale.h.rb +6 -0
- data/lib/SDLRuby/sdl/include/SDL_main.h.rb +3 -0
- data/lib/SDLRuby/sdl/include/SDL_messagebox.h.rb +10 -0
- data/lib/SDLRuby/sdl/include/SDL_misc.h.rb +5 -0
- data/lib/SDLRuby/sdl/include/SDL_mouse.h.rb +26 -0
- data/lib/SDLRuby/sdl/include/SDL_pixels.h.rb +25 -0
- data/lib/SDLRuby/sdl/include/SDL_platform.h.rb +3 -0
- data/lib/SDLRuby/sdl/include/SDL_power.h.rb +6 -0
- data/lib/SDLRuby/sdl/include/SDL_rect.h.rb +17 -0
- data/lib/SDLRuby/sdl/include/SDL_render.h.rb +94 -0
- data/lib/SDLRuby/sdl/include/SDL_revision.h.rb +2 -0
- data/lib/SDLRuby/sdl/include/SDL_rwops.h.rb +34 -0
- data/lib/SDLRuby/sdl/include/SDL_scancode.h.rb +5 -0
- data/lib/SDLRuby/sdl/include/SDL_sensor.h.rb +25 -0
- data/lib/SDLRuby/sdl/include/SDL_shape.h.rb +13 -0
- data/lib/SDLRuby/sdl/include/SDL_stdinc.h.rb +24 -0
- data/lib/SDLRuby/sdl/include/SDL_surface.h.rb +37 -0
- data/lib/SDLRuby/sdl/include/SDL_system.h.rb +6 -0
- data/lib/SDLRuby/sdl/include/SDL_syswm.h.rb +16 -0
- data/lib/SDLRuby/sdl/include/SDL_timer.h.rb +13 -0
- data/lib/SDLRuby/sdl/include/SDL_touch.h.rb +15 -0
- data/lib/SDLRuby/sdl/include/SDL_types.h.rb +3 -0
- data/lib/SDLRuby/sdl/include/SDL_version.h.rb +6 -0
- data/lib/SDLRuby/sdl/include/SDL_video.h.rb +117 -0
- data/lib/SDLRuby/sdl/sdl.rb +55 -0
- data/lib/SDLRuby/sdl/sdl_audio.rb +75 -0
- data/lib/SDLRuby/sdl/sdl_blendmode.rb +10 -0
- data/lib/SDLRuby/sdl/sdl_error.rb +5 -0
- data/lib/SDLRuby/sdl/sdl_events.rb +470 -0
- data/lib/SDLRuby/sdl/sdl_hints.rb +9 -0
- data/lib/SDLRuby/sdl/sdl_keyboard.rb +12 -0
- data/lib/SDLRuby/sdl/sdl_locale.rb +8 -0
- data/lib/SDLRuby/sdl/sdl_message_box.rb +7 -0
- data/lib/SDLRuby/sdl/sdl_mouse.rb +32 -0
- data/lib/SDLRuby/sdl/sdl_palette.rb +12 -0
- data/lib/SDLRuby/sdl/sdl_pixels.rb +138 -0
- data/lib/SDLRuby/sdl/sdl_rect.rb +11 -0
- data/lib/SDLRuby/sdl/sdl_render.rb +35 -0
- data/lib/SDLRuby/sdl/sdl_rw_ops.rb +29 -0
- data/lib/SDLRuby/sdl/sdl_scancode.rb +255 -0
- data/lib/SDLRuby/sdl/sdl_surface.rb +27 -0
- data/lib/SDLRuby/sdl/sdl_version.rb +5 -0
- data/lib/SDLRuby/sdl/sdl_video.rb +104 -0
- data/lib/SDLRuby/sdl.rb +192 -0
- data/lib/SDLRuby/sdl_error.rb +8 -0
- data/lib/SDLRuby/surface/pixel_format.rb +51 -0
- data/lib/SDLRuby/surface/surface_renderer.rb +26 -0
- data/lib/SDLRuby/surface.rb +179 -0
- data/lib/SDLRuby/text_input.rb +38 -0
- data/lib/SDLRuby/texture.rb +93 -0
- data/lib/SDLRuby/ttf/include/SDL_ttf.h.rb +54 -0
- data/lib/SDLRuby/ttf/ttf.rb +41 -0
- data/lib/SDLRuby/ttf.rb +54 -0
- data/lib/SDLRuby/version.rb +5 -0
- data/lib/SDLRuby/window/accessor.rb +125 -0
- data/lib/SDLRuby/window/controller.rb +53 -0
- data/lib/SDLRuby/window/display_info.rb +48 -0
- data/lib/SDLRuby/window/flag.rb +42 -0
- data/lib/SDLRuby/window/hit_tester.rb +61 -0
- data/lib/SDLRuby/window/input.rb +68 -0
- data/lib/SDLRuby/window/shaper.rb +68 -0
- data/lib/SDLRuby/window/surfacer.rb +37 -0
- data/lib/SDLRuby/window/window_renderer.rb +31 -0
- data/lib/SDLRuby/window.rb +90 -0
- data/lib/SDLRuby.rb +16 -0
- data/sig/SDLRuby/event.rbs +104 -0
- data/sig/SDLRuby/pixel_formmater.rbs +24 -0
- data/sig/SDLRuby/rect.rbs +5 -0
- data/sig/SDLRuby/sdl.rbs +606 -0
- data/sig/SDLRuby.rbs +4 -0
- metadata +168 -0
data/lib/SDLRuby/font.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
require_relative 'ttf'
|
2
|
+
|
3
|
+
module SDLRuby
|
4
|
+
class Font
|
5
|
+
include TTF
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def open(file, pt, face: nil, dpi: nil)
|
9
|
+
TTF.init
|
10
|
+
|
11
|
+
if String === file
|
12
|
+
rw = SDL.SDL_RWFromFile(file, "rb")
|
13
|
+
free = 1
|
14
|
+
elsif file.respond_to?(:to_path)
|
15
|
+
rw = SDL.SDL_RWFromFile(file.to_path, "rb")
|
16
|
+
free = 1
|
17
|
+
else
|
18
|
+
rw = RWOps[file]
|
19
|
+
free = 0
|
20
|
+
end
|
21
|
+
|
22
|
+
index = face ? face : 0
|
23
|
+
hdpi, vdpi = *(dpi ? dpi : [0, 0])
|
24
|
+
|
25
|
+
ptr = TTF.TTF_OpenFontIndexDPIRW(rw, free, pt, index, hdpi, vdpi)
|
26
|
+
raise SDLError if ptr.null?
|
27
|
+
|
28
|
+
new(ptr)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(ptr)
|
33
|
+
ptr.free = TTF_CLOSE_FONT
|
34
|
+
@ptr = ptr
|
35
|
+
end
|
36
|
+
|
37
|
+
def align
|
38
|
+
case TTF.TTF_GetFontWrappedAlign(self)
|
39
|
+
when TTF_WRAPPED_ALIGN_LEFT then "left"
|
40
|
+
when TTF_WRAPPED_ALIGN_CENTER then "center"
|
41
|
+
when TTF_WRAPPED_ALIGN_RIGHT then "right"
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def align=(s)
|
48
|
+
case s
|
49
|
+
when "left" then TTF_WRAPPED_ALIGN_LEFT
|
50
|
+
when "center" then TTF_WRAPPED_ALIGN_CENTER
|
51
|
+
when "right" then TTF_WRAPPED_ALIGN_RIGHT
|
52
|
+
else
|
53
|
+
raise ArgumentError
|
54
|
+
end => align
|
55
|
+
|
56
|
+
TTF.TTF_SetFontWrappedAlign(self, align)
|
57
|
+
end
|
58
|
+
|
59
|
+
def ascent = TTF.TTF_FontAscent(self)
|
60
|
+
|
61
|
+
def descent = TTF.TTF_FontDescent(self)
|
62
|
+
|
63
|
+
def direction=(s)
|
64
|
+
case s
|
65
|
+
when "left" then TTF_DIRECTION_LTR
|
66
|
+
when "right" then TTF_DIRECTION_RTL
|
67
|
+
when "top" then TTF_DIRECTION_TTB
|
68
|
+
when "bottom" then TTF_DIRECTION_BTT
|
69
|
+
else
|
70
|
+
raise ArgumentError
|
71
|
+
end => direction
|
72
|
+
|
73
|
+
err = TTF.TTF_SetFontDirection(self, direction)
|
74
|
+
raise SDLError if err < 0
|
75
|
+
end
|
76
|
+
|
77
|
+
def draw(text, alpha: nil, color: nil, width: nil)
|
78
|
+
t = text.encode("UTF-8")
|
79
|
+
c = SDL_Color.malloc(Fiddle::RUBY_FREE)
|
80
|
+
c.r, c.g, c.b, c.a = color
|
81
|
+
w = width || 0
|
82
|
+
|
83
|
+
if alpha
|
84
|
+
TTF.TTF_RenderUTF8_Blended_Wrapped(self, t, c, w)
|
85
|
+
else
|
86
|
+
TTF.TTF_RenderUTF8_Solid_Wrapped(self, t, c, w)
|
87
|
+
end => ptr
|
88
|
+
|
89
|
+
raise SDLError if ptr.null?
|
90
|
+
|
91
|
+
Surface.new(ptr)
|
92
|
+
end
|
93
|
+
|
94
|
+
def drew_size(text)
|
95
|
+
t = text.encode("UTF-8")
|
96
|
+
w, h = SDL.tmp_value("int", "int")
|
97
|
+
err = TTF.TTF_SizeUTF8(self, t, w, h)
|
98
|
+
raise SDLError if err < 0
|
99
|
+
|
100
|
+
[w.value, h.value]
|
101
|
+
end
|
102
|
+
|
103
|
+
def face_count = TTF.TTF_FontFaces(self)
|
104
|
+
|
105
|
+
def family_name = TTF.TTF_FontFaceFamilyName(self).to_s
|
106
|
+
|
107
|
+
def fixed_width? = TTF.TTF_FontFaceIsFixedWidth(self) == 0
|
108
|
+
|
109
|
+
def glyph?(s)
|
110
|
+
raise ArgumentError if s.empty? || s.size > 1
|
111
|
+
|
112
|
+
uint32 = s[0].encode("UTF-32LE").unpack1("L")
|
113
|
+
|
114
|
+
TTF.TTF_GlyphIsProvided32(self, uint32) != 0
|
115
|
+
end
|
116
|
+
|
117
|
+
def glyph_metrics(s)
|
118
|
+
raise ArgumentError if s.empty? || s.size > 1
|
119
|
+
|
120
|
+
uint32 = s[0].encode("UTF-32LE").unpack1("L")
|
121
|
+
|
122
|
+
minx, maxx, miny, maxy, advance =
|
123
|
+
SDL.tmp_value("int", "int", "int", "int", "int")
|
124
|
+
|
125
|
+
TTF.TTF_GlyphMetrics32(self, uint32, minx, maxx, miny, maxy, advance)
|
126
|
+
|
127
|
+
[minx.value, maxx.value, miny.value, maxy.value, advance.value]
|
128
|
+
end
|
129
|
+
|
130
|
+
def height = TTF.TTF_FontHeight(self)
|
131
|
+
|
132
|
+
alias h height
|
133
|
+
|
134
|
+
def hinting
|
135
|
+
case TTF.TTF_GetFontHinting(self)
|
136
|
+
when TTF_HINTING_NORMAL then "normal"
|
137
|
+
when TTF_HINTING_LIGHT then "light"
|
138
|
+
when TTF_HINTING_MONO then "mono"
|
139
|
+
when TTF_HINTING_NONE then "none"
|
140
|
+
when TTF_HINTING_LIGHT_SUBPIXEL then "light_subpixel"
|
141
|
+
else
|
142
|
+
nil
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def hinting=(s)
|
147
|
+
case s
|
148
|
+
when "normal" then TTF_HINTING_NORMAL
|
149
|
+
when "light" then TTF_HINTING_LIGHT
|
150
|
+
when "mono" then TTF_HINTING_MONO
|
151
|
+
when "none" then TTF_HINTING_NONE
|
152
|
+
when "light_subpixel" then TTF_HINTING_LIGHT_SUBPIXEL
|
153
|
+
else
|
154
|
+
raise ArgumentError
|
155
|
+
end => hinting
|
156
|
+
|
157
|
+
TTF.TTF_SetFontHinting(self, hinting)
|
158
|
+
end
|
159
|
+
|
160
|
+
def kerning? = TTF.TTF_GetFontKerning(self) == 0
|
161
|
+
|
162
|
+
def kerning=(b)
|
163
|
+
TTF.TTF_SetFontKerning(self, b ? 1 : 0)
|
164
|
+
end
|
165
|
+
|
166
|
+
def line_skip = TTF.TTF_FontLineSkip(self)
|
167
|
+
|
168
|
+
def measure(text, width)
|
169
|
+
t = text.encode("UTF-8")
|
170
|
+
extent, count = SDL.tmp_value("int", "int")
|
171
|
+
err = TTF.TTF_MeasureUTF8(self, t, width, extent, count)
|
172
|
+
raise SDLError if err < 0
|
173
|
+
|
174
|
+
[extent.value, count.value]
|
175
|
+
end
|
176
|
+
|
177
|
+
def outline = TTF.TTF_GetFontOutline(self)
|
178
|
+
|
179
|
+
def outline=(n)
|
180
|
+
TTF.TTF_SetFontOutline(self, n)
|
181
|
+
end
|
182
|
+
|
183
|
+
def pt=(v)
|
184
|
+
err = TTF.TTF_SetFontSize(self, v)
|
185
|
+
raise SDLError if err < 0
|
186
|
+
end
|
187
|
+
|
188
|
+
# see also ISO 15924
|
189
|
+
#
|
190
|
+
def script_name=(four_characters)
|
191
|
+
err = TTF.TTF_SetFontScriptName(self, four_characters)
|
192
|
+
raise SDLError if err < 0
|
193
|
+
end
|
194
|
+
|
195
|
+
def size_pt(pt, hdpi, vdpi)
|
196
|
+
err = TTF.TTF_SetFontSizeDPI(self, pt, hdpi, vdpi)
|
197
|
+
raise SDLError if err < 0
|
198
|
+
end
|
199
|
+
|
200
|
+
def style
|
201
|
+
num = TTF.TTF_GetFontStyle(self)
|
202
|
+
|
203
|
+
a = []
|
204
|
+
a << "normal" if num & TTF_STYLE_NORMAL != 0
|
205
|
+
a << "bold" if num & TTF_STYLE_BOLD != 0
|
206
|
+
a << "italic" if num & TTF_STYLE_ITALIC != 0
|
207
|
+
a << "underline" if num & TTF_STYLE_UNDERLINE != 0
|
208
|
+
a << "strike" if num & TTF_STYLE_STRIKETHROUGH != 0
|
209
|
+
a
|
210
|
+
end
|
211
|
+
|
212
|
+
def style=(a)
|
213
|
+
num = 0 |
|
214
|
+
(a.include?("normal") ? TTF_STYLE_NORMAL : 0) |
|
215
|
+
(a.include?("bold") ? TTF_STYLE_BOLD : 0) |
|
216
|
+
(a.include?("italic") ? TTF_STYLE_ITALIC : 0) |
|
217
|
+
(a.include?("underline") ? TTF_STYLE_UNDERLINE : 0) |
|
218
|
+
(a.include?("strike") ? TTF_STYLE_STRIKETHROUGH : 0)
|
219
|
+
|
220
|
+
TTF.TTF_SetFontStyle(self, num)
|
221
|
+
end
|
222
|
+
|
223
|
+
def style_name = TTF.TTF_FontFaceStyleName(self).to_s
|
224
|
+
|
225
|
+
def to_ptr = @ptr
|
226
|
+
end
|
227
|
+
end
|
data/lib/SDLRuby/hint.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module Hint
|
3
|
+
class << self
|
4
|
+
include SDL
|
5
|
+
|
6
|
+
def [](name) = SDL.SDL_GetHint(name.to_s).to_s
|
7
|
+
|
8
|
+
# value が nil の場合はヒントの値はNULLに設定される。
|
9
|
+
#
|
10
|
+
def []=(name, value)
|
11
|
+
s = name.to_s
|
12
|
+
if value
|
13
|
+
SDL.SDL_SetHintWithPriority(s, value.to_s, SDL_HINT_OVERRIDE)
|
14
|
+
else
|
15
|
+
SDL.SDL_SetHintWithPriority(s, nil, SDL_HINT_OVERRIDE)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# 全てのヒントを関連付けられた環境変数の値,
|
20
|
+
# または環境変数がない場合はNULLにリセットする.
|
21
|
+
#
|
22
|
+
def clear = SDL.SDL_ResetHints
|
23
|
+
|
24
|
+
def freeze = raise(TypeError, "cannot freeze Hint")
|
25
|
+
|
26
|
+
def include?(name) = SDL.SDL_GetHintBoolean(name.to_s, -1) != -1
|
27
|
+
alias has_key? include?
|
28
|
+
alias member? include?
|
29
|
+
alias key? include?
|
30
|
+
|
31
|
+
# ヒントを環境変数の値にリセットする。
|
32
|
+
#
|
33
|
+
def reset(s) = SDL.SDL_ResetHint(s)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module Image
|
3
|
+
IMG_INIT_JPG = 0x00000001
|
4
|
+
IMG_INIT_PNG = 0x00000002
|
5
|
+
IMG_INIT_TIF = 0x00000004
|
6
|
+
IMG_INIT_WEBP = 0x00000008
|
7
|
+
IMG_INIT_JXL = 0x00000010
|
8
|
+
IMG_INIT_AVIF = 0x00000020
|
9
|
+
typealias "IMG_InitFlags", "int"
|
10
|
+
|
11
|
+
IMG_Animation = struct(
|
12
|
+
[
|
13
|
+
"int w",
|
14
|
+
"int h",
|
15
|
+
"int count",
|
16
|
+
"SDL_Surface **frames",
|
17
|
+
"int *delays"
|
18
|
+
]
|
19
|
+
)
|
20
|
+
|
21
|
+
IMG_FREE_ANIMATION = import_symbol("IMG_FreeAnimation").to_int
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module SDLRuby::Image
|
2
|
+
typealias "IMG_InitFlags", "int"
|
3
|
+
extern "const SDL_version * IMG_Linked_Version(void)"
|
4
|
+
extern "int IMG_Init(int flags)"
|
5
|
+
extern "void IMG_Quit(void)"
|
6
|
+
extern "SDL_Surface * IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type)"
|
7
|
+
extern "SDL_Surface * IMG_Load(const char *file)"
|
8
|
+
extern "SDL_Surface * IMG_Load_RW(SDL_RWops *src, int freesrc)"
|
9
|
+
extern "SDL_Texture * IMG_LoadTexture(SDL_Renderer *renderer, const char *file)"
|
10
|
+
extern "SDL_Texture * IMG_LoadTexture_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc)"
|
11
|
+
extern "SDL_Texture * IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type)"
|
12
|
+
extern "int IMG_isAVIF(SDL_RWops *src)"
|
13
|
+
extern "int IMG_isICO(SDL_RWops *src)"
|
14
|
+
extern "int IMG_isCUR(SDL_RWops *src)"
|
15
|
+
extern "int IMG_isBMP(SDL_RWops *src)"
|
16
|
+
extern "int IMG_isGIF(SDL_RWops *src)"
|
17
|
+
extern "int IMG_isJPG(SDL_RWops *src)"
|
18
|
+
extern "int IMG_isJXL(SDL_RWops *src)"
|
19
|
+
extern "int IMG_isLBM(SDL_RWops *src)"
|
20
|
+
extern "int IMG_isPCX(SDL_RWops *src)"
|
21
|
+
extern "int IMG_isPNG(SDL_RWops *src)"
|
22
|
+
extern "int IMG_isPNM(SDL_RWops *src)"
|
23
|
+
extern "int IMG_isSVG(SDL_RWops *src)"
|
24
|
+
extern "int IMG_isQOI(SDL_RWops *src)"
|
25
|
+
extern "int IMG_isTIF(SDL_RWops *src)"
|
26
|
+
extern "int IMG_isXCF(SDL_RWops *src)"
|
27
|
+
extern "int IMG_isXPM(SDL_RWops *src)"
|
28
|
+
extern "int IMG_isXV(SDL_RWops *src)"
|
29
|
+
extern "int IMG_isWEBP(SDL_RWops *src)"
|
30
|
+
extern "SDL_Surface * IMG_LoadAVIF_RW(SDL_RWops *src)"
|
31
|
+
extern "SDL_Surface * IMG_LoadICO_RW(SDL_RWops *src)"
|
32
|
+
extern "SDL_Surface * IMG_LoadCUR_RW(SDL_RWops *src)"
|
33
|
+
extern "SDL_Surface * IMG_LoadBMP_RW(SDL_RWops *src)"
|
34
|
+
extern "SDL_Surface * IMG_LoadGIF_RW(SDL_RWops *src)"
|
35
|
+
extern "SDL_Surface * IMG_LoadJPG_RW(SDL_RWops *src)"
|
36
|
+
extern "SDL_Surface * IMG_LoadJXL_RW(SDL_RWops *src)"
|
37
|
+
extern "SDL_Surface * IMG_LoadLBM_RW(SDL_RWops *src)"
|
38
|
+
extern "SDL_Surface * IMG_LoadPCX_RW(SDL_RWops *src)"
|
39
|
+
extern "SDL_Surface * IMG_LoadPNG_RW(SDL_RWops *src)"
|
40
|
+
extern "SDL_Surface * IMG_LoadPNM_RW(SDL_RWops *src)"
|
41
|
+
extern "SDL_Surface * IMG_LoadSVG_RW(SDL_RWops *src)"
|
42
|
+
extern "SDL_Surface * IMG_LoadQOI_RW(SDL_RWops *src)"
|
43
|
+
extern "SDL_Surface * IMG_LoadTGA_RW(SDL_RWops *src)"
|
44
|
+
extern "SDL_Surface * IMG_LoadTIF_RW(SDL_RWops *src)"
|
45
|
+
extern "SDL_Surface * IMG_LoadXCF_RW(SDL_RWops *src)"
|
46
|
+
extern "SDL_Surface * IMG_LoadXPM_RW(SDL_RWops *src)"
|
47
|
+
extern "SDL_Surface * IMG_LoadXV_RW(SDL_RWops *src)"
|
48
|
+
extern "SDL_Surface * IMG_LoadWEBP_RW(SDL_RWops *src)"
|
49
|
+
extern "SDL_Surface * IMG_LoadSizedSVG_RW(SDL_RWops *src, int width, int height)"
|
50
|
+
extern "SDL_Surface * IMG_ReadXPMFromArray(char **xpm)"
|
51
|
+
extern "SDL_Surface * IMG_ReadXPMFromArrayToRGB888(char **xpm)"
|
52
|
+
extern "int IMG_SavePNG(SDL_Surface *surface, const char *file)"
|
53
|
+
extern "int IMG_SavePNG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst)"
|
54
|
+
extern "int IMG_SaveJPG(SDL_Surface *surface, const char *file, int quality)"
|
55
|
+
extern "int IMG_SaveJPG_RW(SDL_Surface *surface, SDL_RWops *dst, int freedst, int quality)"
|
56
|
+
extern "IMG_Animation * IMG_LoadAnimation(const char *file)"
|
57
|
+
extern "IMG_Animation * IMG_LoadAnimation_RW(SDL_RWops *src, int freesrc)"
|
58
|
+
extern "IMG_Animation * IMG_LoadAnimationTyped_RW(SDL_RWops *src, int freesrc, const char *type)"
|
59
|
+
extern "void IMG_FreeAnimation(IMG_Animation *anim)"
|
60
|
+
extern "IMG_Animation * IMG_LoadGIFAnimation_RW(SDL_RWops *src)"
|
61
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'fiddle/import'
|
2
|
+
|
3
|
+
module SDLRuby
|
4
|
+
# Supported formats
|
5
|
+
# AVIF, BMP, CUR, GIF, ICO, JPG, JXL, LBM, PCX, PNG, PNM, QOI, SVG, TGA,
|
6
|
+
# TIF, WEBP, XCF, XPM, XV
|
7
|
+
module Image
|
8
|
+
extend Fiddle::Importer
|
9
|
+
|
10
|
+
dlload "SDL2_image"
|
11
|
+
|
12
|
+
require_relative 'image/include/SDL_image.h'
|
13
|
+
require_relative 'image/image'
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def init(flags = nil)
|
17
|
+
num = flags || 0 |
|
18
|
+
IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF |
|
19
|
+
IMG_INIT_WEBP | IMG_INIT_JXL | IMG_INIT_AVIF
|
20
|
+
|
21
|
+
err = Image.IMG_Init(num)
|
22
|
+
raise SDLError if err == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def load(file, type: nil)
|
26
|
+
if String === file
|
27
|
+
rw = SDL.SDL_RWFromFile(file, "rb")
|
28
|
+
free = 1
|
29
|
+
elsif file.respond_to?(:to_path)
|
30
|
+
rw = SDL.SDL_RWFromFile(file.to_path, "rb")
|
31
|
+
free = 1
|
32
|
+
else
|
33
|
+
rw = RWOps[file]
|
34
|
+
free = 0
|
35
|
+
end
|
36
|
+
|
37
|
+
ptr = Image.IMG_LoadTyped_RW(rw, free, type)
|
38
|
+
raise SDLError if ptr.null?
|
39
|
+
|
40
|
+
Surface.new(ptr)
|
41
|
+
end
|
42
|
+
|
43
|
+
def save(file, surface, type: nil, quality: 85)
|
44
|
+
if String === file
|
45
|
+
rw = SDL.SDL_RWFromFile(file, "wb")
|
46
|
+
free = 1
|
47
|
+
elsif file.respond_to?(:to_path)
|
48
|
+
rw = SDL.SDL_RWFromFile(file.to_path, "wb")
|
49
|
+
free = 1
|
50
|
+
else
|
51
|
+
rw = RWOps[file]
|
52
|
+
free = 0
|
53
|
+
end
|
54
|
+
|
55
|
+
err = if type == "PNG"
|
56
|
+
Image.IMG_SavePNG_RW(surface, rw, free)
|
57
|
+
else
|
58
|
+
Image.IMG_SaveJPG_RW(surface, rw, free, quality)
|
59
|
+
end
|
60
|
+
|
61
|
+
raise SDLError if err != 0
|
62
|
+
end
|
63
|
+
|
64
|
+
def quit = Image.IMG_Quit
|
65
|
+
|
66
|
+
def version = SDL::SDL_version.new(Image.IMG_Linked_Version).to_a.join(".")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module Keyboard
|
3
|
+
module_eval do
|
4
|
+
num_keys = SDL.tmp_value("int")
|
5
|
+
|
6
|
+
# SDL_GetKeyboardState() が戻すポインターはSDLがロードされた時点で作成されている。
|
7
|
+
# この関数は SDL_Init() より前に呼ぶことができる。
|
8
|
+
ptr = SDL.SDL_GetKeyboardState(num_keys)
|
9
|
+
|
10
|
+
# エラーになるのはnum_keysにNULLを渡したとき。
|
11
|
+
raise SDLError if ptr.null?
|
12
|
+
|
13
|
+
ptr.size = num_keys.value
|
14
|
+
@state = ptr
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def [](idx)
|
19
|
+
raise IndexError if idx < 0 || @state.size <= idx
|
20
|
+
@state[idx] != 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def any? = to_a.any?
|
24
|
+
|
25
|
+
def clear = SDL.SDL_ResetKeyboard
|
26
|
+
|
27
|
+
# キー名からキーコードを得る
|
28
|
+
def keycode(s) = SDL.GetKeyFromName(s).nonzero?
|
29
|
+
|
30
|
+
# キーコードからキー名を得る
|
31
|
+
def keycode_name(num)
|
32
|
+
(s = SDL.GetKeyName(num).to_s).empty? ? nil : s
|
33
|
+
end
|
34
|
+
|
35
|
+
# 修飾キーの状態を得る
|
36
|
+
def mod
|
37
|
+
SDL.SDL_GetModState #=> integer
|
38
|
+
end
|
39
|
+
|
40
|
+
# 修飾キーを設定する
|
41
|
+
def mod=(modstate)
|
42
|
+
SDL.SDL_SetModState(modstate)
|
43
|
+
end
|
44
|
+
|
45
|
+
# キー名からスキャンコードを得る
|
46
|
+
def scancode(s) = SDL.GetScancodeFromName(s).nonzero?
|
47
|
+
|
48
|
+
# スキャンコードからキー名を得る
|
49
|
+
def scancode_name(num)
|
50
|
+
(s = SDL.GetScancodeName(num).to_s).empty? ? nil : s
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_a = to_str.unpack("C*").map(&:nonzero?)
|
54
|
+
|
55
|
+
def to_str = @state.to_str
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative 'controller'
|
2
|
+
|
3
|
+
module SDLRuby
|
4
|
+
module Mixer
|
5
|
+
class Channel
|
6
|
+
include Controller
|
7
|
+
|
8
|
+
def initialize(ch)
|
9
|
+
@ch = ch
|
10
|
+
end
|
11
|
+
|
12
|
+
def __chank_id__ = Mixer.Mix_GetChunk(self).to_i
|
13
|
+
|
14
|
+
def to_int = @ch
|
15
|
+
|
16
|
+
# Effect
|
17
|
+
#
|
18
|
+
# Mix_RegisterEffect - エフェクト関数を登録する
|
19
|
+
# Mix_UnregisterEffect - エフェクト関数を解除する
|
20
|
+
# Mix_UnregisterAllEffects - 全てのエフェクト関数を解除する
|
21
|
+
|
22
|
+
def distance(distance)
|
23
|
+
err = Mixer.Mix_SetDistance(self, distance)
|
24
|
+
raise SDLError if err == 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def panning(left, right)
|
28
|
+
err = Mixer.Mix_SetPanning(self, left, right)
|
29
|
+
raise SDLError if err == 0
|
30
|
+
end
|
31
|
+
|
32
|
+
def position(angle, distance)
|
33
|
+
err = Mixer.Mix_SetPosition(self, angle, distance)
|
34
|
+
raise SDLError if err == 0
|
35
|
+
end
|
36
|
+
|
37
|
+
def reverse_stereo(flip)
|
38
|
+
err = Mixer.Mix_SetReverseStereo(self, flip ? 1 : 0)
|
39
|
+
raise SDLError if err == 0
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module Mixer
|
3
|
+
class Chunk
|
4
|
+
include Mixer
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def decoders
|
8
|
+
Mixer.Mix_GetNumChunkDecoders.times.map do |idx|
|
9
|
+
ptr = Mixer.Mix_GetChunkDecoder(idx)
|
10
|
+
ptr.null? ? nil : ptr.to_s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def load(file)
|
15
|
+
if String === file
|
16
|
+
rw = SDL.SDL_RWFromFile(file, "rb")
|
17
|
+
free = 1
|
18
|
+
elsif file.respond_to?(:to_path)
|
19
|
+
rw = SDL.SDL_RWFromFile(file.to_path, "rb")
|
20
|
+
free = 1
|
21
|
+
else
|
22
|
+
rw = RWOps[file]
|
23
|
+
free = 0
|
24
|
+
end
|
25
|
+
|
26
|
+
ptr = Mixer.Mix_LoadWAV_RW(rw, free)
|
27
|
+
raise SDLError if ptr.null?
|
28
|
+
|
29
|
+
new(ptr)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(ptr)
|
34
|
+
ptr.free = MIX_FREE_CHUNK
|
35
|
+
@ptr = ptr
|
36
|
+
end
|
37
|
+
|
38
|
+
def play(...) = Mixer.play(self, ...)
|
39
|
+
|
40
|
+
def volume = Mixer.Mix_VolumeChunk(self, -1)
|
41
|
+
|
42
|
+
def volume=(v)
|
43
|
+
Mixer.Mix_VolumeChunk(self, v)
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_ptr = @ptr
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module Mixer
|
3
|
+
module Controller
|
4
|
+
def expire(sec) = Mixer.Mix_ExpireChannel(sec * 1000)
|
5
|
+
|
6
|
+
def fade_out(sec) = Mixer.Mix_FadeOutChannel(-1, sec * 1000)
|
7
|
+
|
8
|
+
def fading? = Mixer.Mix_FadingChanne(self) != MIX_NO_FADING
|
9
|
+
|
10
|
+
def fading_in? = Mixer.Mix_FadingChanne(self) == MIX_FADING_IN
|
11
|
+
|
12
|
+
def fading_out? = Mixer.Mix_FadingChanne(self) == MIX_FADING_OUT
|
13
|
+
|
14
|
+
def halt = Mixer.Mix_HaltChannel(self)
|
15
|
+
|
16
|
+
def pause = Mixer.Mix_Pause(self)
|
17
|
+
|
18
|
+
def paused? = Mixer.Mix_Paused(self).nonzero?
|
19
|
+
|
20
|
+
def play(chunk, fade_in_time: nil, loops: nil, time: nil)
|
21
|
+
l = loops ? loops - 1 : 0
|
22
|
+
t = time ? time * 1000 : -1
|
23
|
+
|
24
|
+
if fade_in_time
|
25
|
+
Mixer.Mix_FadeInChannelTimed(self, chunk, l, fade_in_time * 1000, t)
|
26
|
+
else
|
27
|
+
Mixer.Mix_PlayChannelTimed(self, chunk, l, t)
|
28
|
+
end => err
|
29
|
+
|
30
|
+
raise SDLError if err < 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def playing? = Mixer.Mix_Playing(self).nonzero?
|
34
|
+
|
35
|
+
def resume = Mixer.Mix_Resume(self)
|
36
|
+
|
37
|
+
def volume = Mixer.Mix_Volume(self, -1)
|
38
|
+
|
39
|
+
def volume=(v)
|
40
|
+
Mixer.Mix_Volume(self, v)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|