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
@@ -0,0 +1,26 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class Surface
|
3
|
+
module SurfaceRenderer
|
4
|
+
include SDL
|
5
|
+
|
6
|
+
# サーフェス用のレンダラーは複数作ることができる。
|
7
|
+
# また、サーフェス側からはそれが見えない。
|
8
|
+
# サーフェスのインスタンスごとにレンダラーを保持する。
|
9
|
+
# そのためテクスチャーの共有ができない。
|
10
|
+
# このケースはサーフェスインスタンスをdup, cloneした時のみだろう。
|
11
|
+
# この分離が認められない場合は、サーフェス側のポインターの中にレンダラーを埋め込む。
|
12
|
+
#
|
13
|
+
|
14
|
+
def init_renderer(*)
|
15
|
+
ptr = SDL.SDL_CreateSoftwareRenderer(self)
|
16
|
+
raise SDLError if ptr.null?
|
17
|
+
ptr.free = SDL_DESTROY_RENDERER
|
18
|
+
@renderer = ptr
|
19
|
+
end
|
20
|
+
|
21
|
+
private def renderer = @renderer ||= init_renderer
|
22
|
+
|
23
|
+
def destroy_renderer = @renderer = @renderer.call_free
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require_relative 'palette'
|
2
|
+
require_relative 'pixel_formatter'
|
3
|
+
require_relative 'renderer'
|
4
|
+
require_relative 'surface/pixel_format'
|
5
|
+
require_relative 'surface/surface_renderer'
|
6
|
+
|
7
|
+
module SDLRuby
|
8
|
+
class Surface
|
9
|
+
include PixelFormatter, Renderer, SDL, SurfaceRenderer
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
class << self
|
13
|
+
include SDL
|
14
|
+
|
15
|
+
def load(src)
|
16
|
+
ptr = SDL.SDL_LoadBMP_RW(SDL.SDL_RWFromFile(src, "rb"), 1)
|
17
|
+
raise SDLError if ptr.null?
|
18
|
+
|
19
|
+
new(ptr)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(width, height, format = SDL_PIXELFORMAT_ARGB8888)
|
23
|
+
ptr = SDL.SDL_CreateRGBSurfaceWithFormat(0, width, height, 0, format)
|
24
|
+
raise SDLError if ptr.null?
|
25
|
+
|
26
|
+
new(ptr)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(ptr, add_ref: nil)
|
31
|
+
@st = SDL_Surface.new(ptr, SDL_FREE_SURFACE)
|
32
|
+
@st.refcount += 1 if add_ref
|
33
|
+
|
34
|
+
@format = PixelFormat.new(@st.format, add_ref: true)
|
35
|
+
end
|
36
|
+
|
37
|
+
def_delegators :@st, :h, :pitch, :refcount, :to_ptr, :w
|
38
|
+
def_delegators :@format, :format, :palette
|
39
|
+
|
40
|
+
def palette=(pal)
|
41
|
+
@format.palette = pal
|
42
|
+
end
|
43
|
+
|
44
|
+
def ==(other) = other.respond_to?(:to_ptr) && @st.to_ptr == other.to_ptr
|
45
|
+
|
46
|
+
def alpha_mod
|
47
|
+
a = SDL.tmp_value("Uint8")
|
48
|
+
err = SDL.SDL_GetSurfaceAlphaMod(self, a)
|
49
|
+
raise SDLError if err < 0
|
50
|
+
a.value
|
51
|
+
end
|
52
|
+
|
53
|
+
def alpha_mod=(n)
|
54
|
+
err = SDL.SDL_SetSurfaceAlphaMod(self, n)
|
55
|
+
raise SDLError if err < 0
|
56
|
+
end
|
57
|
+
|
58
|
+
def blend_mode
|
59
|
+
a = SDL.tmp_value("int")
|
60
|
+
err = SDL.SDL_GetSurfaceBlendMode(self, a)
|
61
|
+
raise SDLError if err < 0
|
62
|
+
a.value
|
63
|
+
end
|
64
|
+
|
65
|
+
def blend_mode=(blend)
|
66
|
+
err = SDL.SDL_SetSurfaceBlendMode(self, blend)
|
67
|
+
raise SDLError if err < 0
|
68
|
+
end
|
69
|
+
|
70
|
+
def blit(src, src_rect: nil, dst_rect: nil)
|
71
|
+
src_r &&= Rect[*src_rect]
|
72
|
+
dst_r &&= Rect[*dst_rect]
|
73
|
+
|
74
|
+
# src, dstのrectサイズが一致している場合、内部でSDL_BlitSurfaceを呼び出している。
|
75
|
+
# Blit, BlitScaled 呼び出しの分岐は不要。
|
76
|
+
#
|
77
|
+
err = SDL.SDL_UpperBlitScaled(src, src_r, self, dst_r)
|
78
|
+
raise SDLError if err < 0
|
79
|
+
end
|
80
|
+
|
81
|
+
def clear(color)
|
82
|
+
err = SDL.SDL_FillRect(self, nil, @format.to_pixel(color))
|
83
|
+
raise SDLError if err < 0
|
84
|
+
end
|
85
|
+
|
86
|
+
def clip
|
87
|
+
r = Rect[]
|
88
|
+
SDL.SDL_GetClipRect(self, r)
|
89
|
+
r.to_a
|
90
|
+
end
|
91
|
+
|
92
|
+
def clip=(rect)
|
93
|
+
SDL.SDL_SetClipRect(self, Rect[*rect])
|
94
|
+
end
|
95
|
+
|
96
|
+
def color_key
|
97
|
+
v = SDL.tmp_value("Uint32")
|
98
|
+
err = SDL.SDL_GetColorKey(self, v)
|
99
|
+
raise SDLError if err < 0
|
100
|
+
|
101
|
+
@format.to_color(v.value)
|
102
|
+
end
|
103
|
+
|
104
|
+
def color_key=(color)
|
105
|
+
err = if color
|
106
|
+
SDL.SDL_SetColorKey(self, 1, @format.to_pixel(color))
|
107
|
+
else
|
108
|
+
SDL.SDL_SetColorKey(self, 0, 0)
|
109
|
+
end
|
110
|
+
raise SDLError if err < 0
|
111
|
+
end
|
112
|
+
|
113
|
+
def color_key? = SDL.SDL_HasColorKey(self) == 1
|
114
|
+
|
115
|
+
def color_mod
|
116
|
+
r, g, b = SDL.tmp_value("Uint8", "Uint8", "Uint8")
|
117
|
+
err = SDL.SDL_GetSurfaceColorMod(self, r, g, b)
|
118
|
+
raise SDLError if err < 0
|
119
|
+
|
120
|
+
[r.value, g.value, b.value]
|
121
|
+
end
|
122
|
+
|
123
|
+
def color_mod=(color)
|
124
|
+
r, g, b = *color
|
125
|
+
err = SDL.SDL_SetSurfaceColorMod(self, r, g, b)
|
126
|
+
raise SDLError if err < 0
|
127
|
+
end
|
128
|
+
|
129
|
+
def fill(color, *i)
|
130
|
+
size = f.count
|
131
|
+
count = size / 4
|
132
|
+
raise ArgumentError if count.zero? || (size % 4).nonzero?
|
133
|
+
ptr = i.pack("i*")
|
134
|
+
|
135
|
+
err = SDL.SDL_FillRects(self, ptr, count, @format.to_pixel(color))
|
136
|
+
raise SDLError if err < 0
|
137
|
+
end
|
138
|
+
|
139
|
+
def lock
|
140
|
+
err = SDL.SDL_LockSurface(self)
|
141
|
+
raise SDLError if err < 0
|
142
|
+
end
|
143
|
+
|
144
|
+
def rle? = SDL.SDL_HasSurfaceRLE(self) != 0
|
145
|
+
|
146
|
+
def rle=(b)
|
147
|
+
err = SDL.SDL_SetSurfaceRLE(self, b ? 1 : 0)
|
148
|
+
raise SDLError if err < 0
|
149
|
+
end
|
150
|
+
|
151
|
+
def save(file)
|
152
|
+
err = SDL.SDL_SaveBMP_RW(self, SDL.SDL_RWFromFile(src, "rb"), 1)
|
153
|
+
raise SDLError if err < 0
|
154
|
+
end
|
155
|
+
|
156
|
+
def size = [w, h]
|
157
|
+
|
158
|
+
def synchronize(&)
|
159
|
+
lock
|
160
|
+
begin
|
161
|
+
yield
|
162
|
+
ensure
|
163
|
+
unlock
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_s = synchronize { @st.pixels.to_str(h * pitch) }
|
168
|
+
|
169
|
+
def to_surface(format = nil)
|
170
|
+
return self unless format
|
171
|
+
|
172
|
+
ptr = SDL.SDL_ConvertSurface(self, format, 0)
|
173
|
+
raise SDLError if ptr.null?
|
174
|
+
Surface.new(ptr)
|
175
|
+
end
|
176
|
+
|
177
|
+
def unlock = SDL.SDL_UnlockSurface(self)
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module TextInput
|
3
|
+
class << self
|
4
|
+
include SDL
|
5
|
+
|
6
|
+
# テキスト入力イベントが有効かチェックする
|
7
|
+
def active? = SDL.SDL_IsTextInputActive != 0
|
8
|
+
|
9
|
+
# コンポジションウィンドウ/IMEをIMEを無効化せずに閉じる
|
10
|
+
#
|
11
|
+
def hide = SDL.SDL_ClearComposition
|
12
|
+
|
13
|
+
# テキスト入力で使う領域を設定する
|
14
|
+
# ※ 表示はされるが指定が行われない。調査が必要。
|
15
|
+
# もし指定ができないのならば show メソッドに名前を変えた方が良い。
|
16
|
+
# NOTICE:
|
17
|
+
# システムの IMEウィンドウを使う場合はSDL_HINT_IME_SHOW_UIヒントを1に設定する。
|
18
|
+
# これはウィンドウの生成前に行う必要がある。※SDL_Initの後でも問題はない。
|
19
|
+
#
|
20
|
+
def rect=(rect)
|
21
|
+
SDL.SDL_SetTextInputRect(Rect[*rect])
|
22
|
+
end
|
23
|
+
|
24
|
+
# 環境がスクリーンキーボードに対応しているかチェックする
|
25
|
+
def screen_keyboard_supported? = SDL.SDL_HasScreenKeyboardSupport != 0
|
26
|
+
|
27
|
+
# スクリーンキーボードが指定のウィンドウに表示されているかチェックする
|
28
|
+
def screen_keyboard_shown?(window) = SDL.SDL_IsScreenKeyboardShown(window) != 0
|
29
|
+
|
30
|
+
# IMEコンポジット(変換中ウィンドウ・矩形)または変換候補が現在表示されているかを戻す
|
31
|
+
def shown? = SDL.SDL_IsTextInputShown != 0
|
32
|
+
|
33
|
+
def start = SDL.SDL_StartTextInput
|
34
|
+
|
35
|
+
def stop = SDL.SDL_StopTextInput
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class Texture
|
3
|
+
require_relative 'pixel_formatter'
|
4
|
+
|
5
|
+
include PixelFormatter, SDL
|
6
|
+
|
7
|
+
attr_reader :format, :h, :w
|
8
|
+
|
9
|
+
def initialize(ptr)
|
10
|
+
ptr.free = SDL_DESTROY_TEXTURE
|
11
|
+
@ptr = ptr
|
12
|
+
|
13
|
+
query
|
14
|
+
end
|
15
|
+
|
16
|
+
def alpha_mod
|
17
|
+
v = SDL.tmp_value("Uint8")
|
18
|
+
err = SDL.SDL_GetTextureAlphaMod(self, v)
|
19
|
+
raise SDLError if err < 0
|
20
|
+
|
21
|
+
v.value
|
22
|
+
end
|
23
|
+
|
24
|
+
def alpha_mod=(n)
|
25
|
+
err = SDL.SDL_SetTextureAlphaMod(self, n)
|
26
|
+
raise SDLError if err < 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def blend_mode
|
30
|
+
v = SDL.tmp_value("int")
|
31
|
+
err = SDL.SDL_GetTextureBlendMode(self, v)
|
32
|
+
raise SDLError if err < 0
|
33
|
+
|
34
|
+
v.value
|
35
|
+
end
|
36
|
+
|
37
|
+
def blend_mode=(n)
|
38
|
+
err = SDL.SDL_SetTextureBlendMode(self, n)
|
39
|
+
raise SDLError if err < 0
|
40
|
+
end
|
41
|
+
|
42
|
+
def color_mod
|
43
|
+
r, g, b = SDL.tmp_value("Uint8", "Uint8", "Uint8")
|
44
|
+
err = SDL.SDL_GetTextureColorMod(self, r, g, b)
|
45
|
+
raise SDLError if err < 0
|
46
|
+
|
47
|
+
[r.value, g.value, b.value]
|
48
|
+
end
|
49
|
+
|
50
|
+
def color_mod=(color)
|
51
|
+
r, g, b = *color
|
52
|
+
err = SDL.SDL_SetTextureColorMod(self, r, g, b)
|
53
|
+
raise SDLError if err < 0
|
54
|
+
end
|
55
|
+
|
56
|
+
private def query
|
57
|
+
format, access, w, h = SDL.tmp_value("Uint32", "int", "int", "int")
|
58
|
+
err = SDL.SDL_QueryTexture(@ptr, format, access, w, h)
|
59
|
+
raise SDLError if err < 0
|
60
|
+
|
61
|
+
@format = format.value
|
62
|
+
@access = access.value
|
63
|
+
@w = w.value
|
64
|
+
@h = h.value
|
65
|
+
end
|
66
|
+
|
67
|
+
def scale_mode
|
68
|
+
v = SDL.tmp_value("int")
|
69
|
+
err = SDL.SDL_GetTextureScaleMode(self, v)
|
70
|
+
raise SDLError if err < 0
|
71
|
+
|
72
|
+
v.value
|
73
|
+
end
|
74
|
+
|
75
|
+
def scale_mode=(n)
|
76
|
+
err = SDL.SDL_SetTextureScaleMode(self, n)
|
77
|
+
raise SDLError if err < 0
|
78
|
+
end
|
79
|
+
|
80
|
+
def size = [@w, @h]
|
81
|
+
|
82
|
+
def to_ptr = @ptr
|
83
|
+
|
84
|
+
def to_surface
|
85
|
+
ptr = SDL.tmp_value("void*")
|
86
|
+
err = SDL.SDL_LockTextureToSurface(self, nil, ptr)
|
87
|
+
raise SDLError if err < 0
|
88
|
+
SDL.SDL_UnlockTexture(self)
|
89
|
+
|
90
|
+
Surface.new(ptr.value)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module SDLRuby::TTF
|
2
|
+
typealias "TTF_Font", "struct _TTF_Font"
|
3
|
+
typealias "TTF_Direction", "int"
|
4
|
+
extern "const SDL_version * TTF_Linked_Version(void)"
|
5
|
+
extern "void TTF_GetFreeTypeVersion(int *major, int *minor, int *patch)"
|
6
|
+
extern "void TTF_GetHarfBuzzVersion(int *major, int *minor, int *patch)"
|
7
|
+
extern "void TTF_ByteSwappedUNICODE(SDL_bool swapped)"
|
8
|
+
extern "int TTF_Init(void)"
|
9
|
+
extern "TTF_Font * TTF_OpenFont(const char *file, int ptsize)"
|
10
|
+
extern "TTF_Font * TTF_OpenFontIndex(const char *file, int ptsize, long index)"
|
11
|
+
extern "TTF_Font * TTF_OpenFontRW(SDL_RWops *src, int freesrc, int ptsize)"
|
12
|
+
extern "TTF_Font * TTF_OpenFontIndexRW(SDL_RWops *src, int freesrc, int ptsize, long index)"
|
13
|
+
extern "TTF_Font * TTF_OpenFontDPI(const char *file, int ptsize, unsigned int hdpi, unsigned int vdpi)"
|
14
|
+
extern "TTF_Font * TTF_OpenFontIndexDPI(const char *file, int ptsize, long index, unsigned int hdpi, unsigned int vdpi)"
|
15
|
+
extern "TTF_Font * TTF_OpenFontDPIRW(SDL_RWops *src, int freesrc, int ptsize, unsigned int hdpi, unsigned int vdpi)"
|
16
|
+
extern "TTF_Font * TTF_OpenFontIndexDPIRW(SDL_RWops *src, int freesrc, int ptsize, long index, unsigned int hdpi, unsigned int vdpi)"
|
17
|
+
extern "int TTF_SetFontSize(TTF_Font *font, int ptsize)"
|
18
|
+
extern "int TTF_SetFontSizeDPI(TTF_Font *font, int ptsize, unsigned int hdpi, unsigned int vdpi)"
|
19
|
+
extern "int TTF_GetFontStyle(const TTF_Font *font)"
|
20
|
+
extern "void TTF_SetFontStyle(TTF_Font *font, int style)"
|
21
|
+
extern "int TTF_GetFontOutline(const TTF_Font *font)"
|
22
|
+
extern "void TTF_SetFontOutline(TTF_Font *font, int outline)"
|
23
|
+
extern "int TTF_GetFontHinting(const TTF_Font *font)"
|
24
|
+
extern "void TTF_SetFontHinting(TTF_Font *font, int hinting)"
|
25
|
+
extern "int TTF_GetFontWrappedAlign(const TTF_Font *font)"
|
26
|
+
extern "void TTF_SetFontWrappedAlign(TTF_Font *font, int align)"
|
27
|
+
extern "int TTF_FontHeight(const TTF_Font *font)"
|
28
|
+
extern "int TTF_FontAscent(const TTF_Font *font)"
|
29
|
+
extern "int TTF_FontDescent(const TTF_Font *font)"
|
30
|
+
extern "int TTF_FontLineSkip(const TTF_Font *font)"
|
31
|
+
extern "int TTF_GetFontKerning(const TTF_Font *font)"
|
32
|
+
extern "void TTF_SetFontKerning(TTF_Font *font, int allowed)"
|
33
|
+
extern "long TTF_FontFaces(const TTF_Font *font)"
|
34
|
+
extern "int TTF_FontFaceIsFixedWidth(const TTF_Font *font)"
|
35
|
+
extern "const char * TTF_FontFaceFamilyName(const TTF_Font *font)"
|
36
|
+
extern "const char * TTF_FontFaceStyleName(const TTF_Font *font)"
|
37
|
+
extern "int TTF_GlyphIsProvided32(TTF_Font *font, Uint32 ch)"
|
38
|
+
extern "int TTF_GlyphMetrics32(TTF_Font *font, Uint32 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance)"
|
39
|
+
extern "int TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h)"
|
40
|
+
extern "int TTF_MeasureUTF8(TTF_Font *font, const char *text, int measure_width, int *extent, int *count)"
|
41
|
+
extern "SDL_Surface * TTF_RenderUTF8_Solid(TTF_Font *font, const char *text, SDL_Color fg)"
|
42
|
+
extern "SDL_Surface * TTF_RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, Uint32 wrapLength)"
|
43
|
+
extern "SDL_Surface * TTF_RenderUTF8_Shaded(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg)"
|
44
|
+
extern "SDL_Surface * TTF_RenderUTF8_Shaded_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg, Uint32 wrapLength)"
|
45
|
+
extern "SDL_Surface * TTF_RenderUTF8_Blended(TTF_Font *font, const char *text, SDL_Color fg)"
|
46
|
+
extern "SDL_Surface * TTF_RenderUTF8_Blended_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, Uint32 wrapLength)"
|
47
|
+
extern "SDL_Surface * TTF_RenderUTF8_LCD(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg)"
|
48
|
+
extern "SDL_Surface * TTF_RenderUTF8_LCD_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg, Uint32 wrapLength)"
|
49
|
+
extern "void TTF_CloseFont(TTF_Font *font)"
|
50
|
+
extern "void TTF_Quit(void)"
|
51
|
+
extern "int TTF_WasInit(void)"
|
52
|
+
extern "int TTF_SetFontDirection(TTF_Font *font, TTF_Direction direction)"
|
53
|
+
extern "int TTF_SetFontScriptName(TTF_Font *font, const char *script)"
|
54
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module TTF
|
3
|
+
require_relative "include/SDL_ttf.h"
|
4
|
+
|
5
|
+
# ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark)
|
6
|
+
#
|
7
|
+
UNICODE_BOM_NATIVE = 0xFEFF
|
8
|
+
UNICODE_BOM_SWAPPED = 0xFFFE
|
9
|
+
|
10
|
+
# Font style flags
|
11
|
+
#
|
12
|
+
TTF_STYLE_NORMAL = 0x00
|
13
|
+
TTF_STYLE_BOLD = 0x01
|
14
|
+
TTF_STYLE_ITALIC = 0x02
|
15
|
+
TTF_STYLE_UNDERLINE = 0x04
|
16
|
+
TTF_STYLE_STRIKETHROUGH = 0x08
|
17
|
+
|
18
|
+
# Hinting flags
|
19
|
+
#
|
20
|
+
TTF_HINTING_NORMAL = 0
|
21
|
+
TTF_HINTING_LIGHT = 1
|
22
|
+
TTF_HINTING_MONO = 2
|
23
|
+
TTF_HINTING_NONE = 3
|
24
|
+
TTF_HINTING_LIGHT_SUBPIXEL = 4
|
25
|
+
|
26
|
+
# Special layout option for rendering wrapped text
|
27
|
+
#
|
28
|
+
TTF_WRAPPED_ALIGN_LEFT = 0
|
29
|
+
TTF_WRAPPED_ALIGN_CENTER = 1
|
30
|
+
TTF_WRAPPED_ALIGN_RIGHT = 2
|
31
|
+
|
32
|
+
# Direction flags
|
33
|
+
#
|
34
|
+
TTF_DIRECTION_LTR = 0
|
35
|
+
TTF_DIRECTION_RTL = 1
|
36
|
+
TTF_DIRECTION_TTB = 2
|
37
|
+
TTF_DIRECTION_BTT = 3
|
38
|
+
|
39
|
+
TTF_CLOSE_FONT = import_symbol("TTF_CloseFont").to_int
|
40
|
+
end
|
41
|
+
end
|
data/lib/SDLRuby/ttf.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'fiddle/import'
|
2
|
+
|
3
|
+
module SDLRuby
|
4
|
+
module TTF
|
5
|
+
include SDL
|
6
|
+
extend Fiddle::Importer
|
7
|
+
|
8
|
+
dlload "SDL2_ttf"
|
9
|
+
|
10
|
+
typealias "Uint32", "uint32_t"
|
11
|
+
typealias "SDL_bool", "int"
|
12
|
+
typealias "SDL_Color", "void*"
|
13
|
+
|
14
|
+
require_relative 'ttf/ttf'
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def byte_swapped_unicode=(b)
|
18
|
+
TTF.TTF_ByteSwappedUNICODE(b ? 1 : 0)
|
19
|
+
end
|
20
|
+
|
21
|
+
def free_type_version
|
22
|
+
major, minor, patch = SDL.tmp_value("int", "int", "int")
|
23
|
+
TTF.TTF_GetFreeTypeVersion(major, minor, patch)
|
24
|
+
|
25
|
+
"#{major}.#{minor}.#{patch}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def harf_bazz_version
|
29
|
+
major, minor, patch = SDL.tmp_value("int", "int", "int")
|
30
|
+
TTF.TTF_GetHarfBuzzVersion(major, minor, patch)
|
31
|
+
|
32
|
+
"#{major}.#{minor}.#{patch}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def init
|
36
|
+
return if init?
|
37
|
+
err = TTF.TTF_Init
|
38
|
+
raise SDLError if err < 0
|
39
|
+
end
|
40
|
+
|
41
|
+
# 初期化した回数を戻す。その回数分だけquitを呼ばなければならない。
|
42
|
+
#
|
43
|
+
def init? = TTF.TTF_WasInit.nonzero?
|
44
|
+
|
45
|
+
# 使用中のフォントがある場合、quitを呼ぶとフォントを閉じることができなくなる!
|
46
|
+
# これを呼び出す前に全てのフォントを閉じておくこと。
|
47
|
+
# しかし、Rubyがポインターを管理するためアプリケーションでは制御できないだろう・・・
|
48
|
+
#
|
49
|
+
def quit = TTF.TTF_Quit
|
50
|
+
|
51
|
+
def version = SDL_version.new(TTF.TTF_Linked_Version).to_a.join(".")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class Window
|
3
|
+
module Accessor
|
4
|
+
def boarder_size
|
5
|
+
t, l, b, r = SDL.tmp_value("int", "int", "int", "int")
|
6
|
+
err = SDL.SDL_GetWindowBordersSize(self, t, l, b, r)
|
7
|
+
raise SDLError if err < 0
|
8
|
+
|
9
|
+
[t.value, l.value, b.value, r.value]
|
10
|
+
end
|
11
|
+
|
12
|
+
def h
|
13
|
+
v = SDL.tmp_value("int")
|
14
|
+
SDL.SDL_GetWindowSize(self, nil, v)
|
15
|
+
v.value
|
16
|
+
end
|
17
|
+
|
18
|
+
def h=(n)
|
19
|
+
SDL.SDL_SetWindowSize(self, w, n)
|
20
|
+
end
|
21
|
+
|
22
|
+
def icon=(surface)
|
23
|
+
SDL.SDL_SetWindowIcon(self, surface)
|
24
|
+
end
|
25
|
+
|
26
|
+
def maximum_size
|
27
|
+
w, h = SDL.tmp_value("int", "int")
|
28
|
+
SDL.SDL_GetWindowMaximumSize(self, w, h)
|
29
|
+
|
30
|
+
[w.value, h.value]
|
31
|
+
end
|
32
|
+
|
33
|
+
def maximum_size=(wh)
|
34
|
+
SDL.SDL_SetWindowMaximumSize(self, *wh)
|
35
|
+
end
|
36
|
+
|
37
|
+
def minimum_size
|
38
|
+
w, h = SDL.tmp_value("int", "int")
|
39
|
+
SDL.SDL_GetWindowMinimumSize(self, w, h)
|
40
|
+
|
41
|
+
[w.value, h.value]
|
42
|
+
end
|
43
|
+
|
44
|
+
def minimum_size=(wh)
|
45
|
+
SDL.SDL_SetWindowMinimumSize(self, *wh)
|
46
|
+
end
|
47
|
+
|
48
|
+
def opacity
|
49
|
+
f = SDL.tmp_value("float")
|
50
|
+
err = SDL.SDL_GetWindowOpacity(self, f)
|
51
|
+
raise SDLError if err < 0
|
52
|
+
|
53
|
+
f.value
|
54
|
+
end
|
55
|
+
|
56
|
+
def opacity=(f)
|
57
|
+
err = SDL.SDL_SetWindowOpacity(self, f)
|
58
|
+
raise SDLError if err < 0
|
59
|
+
end
|
60
|
+
|
61
|
+
def pos
|
62
|
+
vx, vy = SDL.tmp_value("int", "int")
|
63
|
+
SDL.SDL_GetWindowPosition(self, vx, vy)
|
64
|
+
[vx.value, vy.value]
|
65
|
+
end
|
66
|
+
|
67
|
+
def pos=(xy)
|
68
|
+
SDL.SDL_SetWindowPosition(self, *xy)
|
69
|
+
end
|
70
|
+
|
71
|
+
def size
|
72
|
+
vw, vh = SDL.tmp_value("int", "int")
|
73
|
+
SDL.SDL_GetWindowSize(self, vw, vh)
|
74
|
+
[vw.value, vh.value]
|
75
|
+
end
|
76
|
+
|
77
|
+
def size=(wh)
|
78
|
+
SDL.SDL_SetWindowSize(self, *wh)
|
79
|
+
end
|
80
|
+
|
81
|
+
def size_in_pixels
|
82
|
+
vw, vh = SDL.tmp_value("int", "int")
|
83
|
+
SDL.SDL_GetWindowSizeInPixels(self, vw, vh)
|
84
|
+
|
85
|
+
[vw.value, vh.value]
|
86
|
+
end
|
87
|
+
|
88
|
+
def title = SDL.SDL_GetWindowTitle(self).to_s.force_encoding("UTF-8")
|
89
|
+
|
90
|
+
def title=(s)
|
91
|
+
SDL.SDL_SetWindowTitle(self, s.encode("UTF-8"))
|
92
|
+
end
|
93
|
+
|
94
|
+
def w
|
95
|
+
v = SDL.tmp_value("int")
|
96
|
+
SDL.SDL_GetWindowSize(self, v, nil)
|
97
|
+
v.value
|
98
|
+
end
|
99
|
+
|
100
|
+
def w=(n)
|
101
|
+
SDL.SDL_SetWindowSize(self, n, h)
|
102
|
+
end
|
103
|
+
|
104
|
+
def x
|
105
|
+
v = SDL.tmp_value("int")
|
106
|
+
SDL.SDL_GetWindowPosition(self, v, nil)
|
107
|
+
v.value
|
108
|
+
end
|
109
|
+
|
110
|
+
def x=(n)
|
111
|
+
SDL.SDL_SetWindowPosition(self, n, y)
|
112
|
+
end
|
113
|
+
|
114
|
+
def y
|
115
|
+
v = SDL.tmp_value("int")
|
116
|
+
SDL.SDL_GetWindowPosition(self, nil, v)
|
117
|
+
v.value
|
118
|
+
end
|
119
|
+
|
120
|
+
def y=(n)
|
121
|
+
SDL.SDL_SetWindowPosition(self, x, n)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
class Window
|
3
|
+
module Controller
|
4
|
+
def always_on_top = SDL.SDL_SetWindowAlwaysOnTop(self)
|
5
|
+
|
6
|
+
def always_on_top? = flags & SDL_WINDOW_ALWAYS_ON_TOP != 0
|
7
|
+
|
8
|
+
def border=(obj)
|
9
|
+
SDL.SDL_SetWindowBordered(self, obj ? 1 : 0)
|
10
|
+
end
|
11
|
+
|
12
|
+
def borderless? = flags & SDL_WINDOW_BORDERLESS != 0
|
13
|
+
|
14
|
+
def fullscreen=(obj)
|
15
|
+
err = SDL.SDL_SetWindowFullscreen(self, obj ? SDL_WINDOW_FULLSCREEN : 0)
|
16
|
+
raise SDLError if err < 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def fullscreen? = flags & SDL_WINDOW_FULLSCREEN != 0
|
20
|
+
|
21
|
+
def fullscreen_desktop=(obj)
|
22
|
+
err = SDL.SDL_SetWindowFullscreen(self, obj ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)
|
23
|
+
raise SDLError if err < 0
|
24
|
+
end
|
25
|
+
|
26
|
+
def fullscreen_desktop? = flags & SDL_WINDOW_FULLSCREEN_DESKTOP != 0
|
27
|
+
|
28
|
+
def hide = SDL.SDL_HideWindow(self)
|
29
|
+
|
30
|
+
def hidden? = flags & SDL_WINDOW_HIDDEN != 0
|
31
|
+
|
32
|
+
def maximize = SDL.SDL_MaximizeWindow(self)
|
33
|
+
|
34
|
+
def maximized? = flags & SDL_WINDOW_MAXIMIZED != 0
|
35
|
+
|
36
|
+
def minimize = SDL.SDL_MinimizeWindow(self)
|
37
|
+
|
38
|
+
def minimized? = flags & SDL_WINDOW_MINIMIZED != 0
|
39
|
+
|
40
|
+
def resizable=(obj)
|
41
|
+
SDL.SDL_SetWindowResizable(self, obj ? 1 : 0)
|
42
|
+
end
|
43
|
+
|
44
|
+
def resizable? = flags & SDL_WINDOW_RESIZABLE != 0
|
45
|
+
|
46
|
+
def restore = SDL.SDL_RestoreWindow(self)
|
47
|
+
|
48
|
+
def show = SDL.SDL_ShowWindow(self)
|
49
|
+
|
50
|
+
def shown? = flags & SDL_WINDOW_SHOWN != 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|