rb_sdl2 0.1.2 → 0.2.0
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/CHANGELOG.md +31 -0
- data/README.md +1 -1
- data/lib/rb_sdl2/audio/audio.rb +162 -0
- data/lib/rb_sdl2/audio/audio_buffer.rb +12 -19
- data/lib/rb_sdl2/audio/audio_device.rb +17 -23
- data/lib/rb_sdl2/audio/audio_spec.rb +38 -6
- data/lib/rb_sdl2/audio/audio_spec_reader.rb +10 -0
- data/lib/rb_sdl2/clipboard.rb +31 -31
- data/lib/rb_sdl2/cpu_info.rb +34 -17
- data/lib/rb_sdl2/cursor.rb +105 -24
- data/lib/rb_sdl2/display.rb +16 -16
- data/lib/rb_sdl2/display_mode.rb +1 -1
- data/lib/rb_sdl2/error.rb +11 -4
- data/lib/rb_sdl2/errors.rb +7 -0
- data/lib/rb_sdl2/event/event.rb +130 -0
- data/lib/rb_sdl2/event/event_filter.rb +34 -70
- data/lib/rb_sdl2/event/event_pointer.rb +26 -0
- data/lib/rb_sdl2/event/event_queue.rb +97 -120
- data/lib/rb_sdl2/event/event_type.rb +147 -205
- data/lib/rb_sdl2/filesystem.rb +8 -9
- data/lib/rb_sdl2/hint.rb +26 -24
- data/lib/rb_sdl2/keyboard/keyboard.rb +50 -0
- data/lib/rb_sdl2/keyboard/mod_state.rb +68 -0
- data/lib/rb_sdl2/keyboard/state.rb +39 -0
- data/lib/rb_sdl2/message_box.rb +69 -102
- data/lib/rb_sdl2/mouse/global_mouse.rb +10 -3
- data/lib/rb_sdl2/mouse/mouse.rb +64 -0
- data/lib/rb_sdl2/mouse/mouse_button.rb +13 -11
- data/lib/rb_sdl2/mouse/mouse_class.rb +9 -17
- data/lib/rb_sdl2/mouse/mouse_wheel.rb +21 -37
- data/lib/rb_sdl2/mouse/relative_mouse.rb +15 -1
- data/lib/rb_sdl2/palette.rb +12 -12
- data/lib/rb_sdl2/pixel_format_enum.rb +87 -55
- data/lib/rb_sdl2/platform.rb +1 -1
- data/lib/rb_sdl2/power_info.rb +34 -23
- data/lib/rb_sdl2/rect.rb +7 -1
- data/lib/rb_sdl2/ref_count_pointer.rb +25 -10
- data/lib/rb_sdl2/rw_ops/rw_file.rb +19 -0
- data/lib/rb_sdl2/rw_ops/rw_memory.rb +18 -0
- data/lib/rb_sdl2/rw_ops/rw_object.rb +126 -0
- data/lib/rb_sdl2/rw_ops/rw_ops.rb +104 -0
- data/lib/rb_sdl2/rw_ops/rw_ops_pointer.rb +14 -0
- data/lib/rb_sdl2/sdl.rb +67 -28
- data/lib/rb_sdl2/sdl_pointer.rb +22 -0
- data/lib/rb_sdl2/surface/blend_mode.rb +41 -41
- data/lib/rb_sdl2/surface/pixel_format.rb +34 -33
- data/lib/rb_sdl2/surface.rb +280 -265
- data/lib/rb_sdl2/text_input.rb +21 -15
- data/lib/rb_sdl2/timer.rb +36 -31
- data/lib/rb_sdl2/version.rb +3 -3
- data/lib/rb_sdl2/video.rb +17 -5
- data/lib/rb_sdl2/window/accessor.rb +135 -0
- data/lib/rb_sdl2/window/display.rb +8 -8
- data/lib/rb_sdl2/window/flash.rb +22 -0
- data/lib/rb_sdl2/window/hit_test.rb +22 -43
- data/lib/rb_sdl2/window/shape.rb +55 -40
- data/lib/rb_sdl2/window/state.rb +178 -0
- data/lib/rb_sdl2/window/window.rb +149 -0
- data/lib/rb_sdl2.rb +79 -17
- data/rb_sdl2.gemspec +4 -4
- metadata +31 -35
- data/lib/rb_sdl2/audio/audio_allowed_changes.rb +0 -17
- data/lib/rb_sdl2/audio/audio_format.rb +0 -23
- data/lib/rb_sdl2/audio.rb +0 -132
- data/lib/rb_sdl2/cursor/color_cursor.rb +0 -19
- data/lib/rb_sdl2/cursor/cursor_class.rb +0 -24
- data/lib/rb_sdl2/cursor/cursor_pointer.rb +0 -12
- data/lib/rb_sdl2/cursor/default_cursor.rb +0 -18
- data/lib/rb_sdl2/cursor/system_cursor.rb +0 -45
- data/lib/rb_sdl2/event.rb +0 -161
- data/lib/rb_sdl2/keyboard/key_mod.rb +0 -37
- data/lib/rb_sdl2/keyboard/keyboard_state.rb +0 -34
- data/lib/rb_sdl2/keyboard.rb +0 -50
- data/lib/rb_sdl2/mouse/window_mouse.rb +0 -17
- data/lib/rb_sdl2/mouse.rb +0 -74
- data/lib/rb_sdl2/rw_ops/rw_operator.rb +0 -105
- data/lib/rb_sdl2/rw_ops.rb +0 -149
- data/lib/rb_sdl2/screen_saver.rb +0 -11
- data/lib/rb_sdl2/window/dialog.rb +0 -19
- data/lib/rb_sdl2/window/grab.rb +0 -23
- data/lib/rb_sdl2/window/position.rb +0 -38
- data/lib/rb_sdl2/window/size.rb +0 -59
- data/lib/rb_sdl2/window/window_flags.rb +0 -78
- data/lib/rb_sdl2/window.rb +0 -242
data/lib/rb_sdl2/window.rb
DELETED
@@ -1,242 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class Window
|
3
|
-
class << self
|
4
|
-
def keyboard_focused = (ptr = ::SDL2.SDL_GetKeyboardFocus).null? ? nil : to_ptr(ptr)
|
5
|
-
|
6
|
-
def mouse_focused = (ptr = ::SDL2.SDL_GetMouseFocus).null? ? nil : to_ptr(ptr)
|
7
|
-
|
8
|
-
def grabbed = (ptr = ::SDL2.SDL_GetGrabbedWindow).null? ? nil : to_ptr(ptr)
|
9
|
-
|
10
|
-
def new(title = nil, x = nil, y = nil, w = 640, h = 480, flags = nil, **opts)
|
11
|
-
x ||= ::SDL2::SDL_WINDOWPOS_CENTERED_MASK
|
12
|
-
y ||= ::SDL2::SDL_WINDOWPOS_CENTERED_MASK
|
13
|
-
flags ||= WindowFlags.to_num(**opts)
|
14
|
-
ptr = ::SDL2.SDL_CreateWindow(title&.to_s, x, y, w, h, flags)
|
15
|
-
raise RbSDL2Error if ptr.null?
|
16
|
-
to_ptr(ptr)
|
17
|
-
end
|
18
|
-
|
19
|
-
# w, h は nil の場合は shape に与えられたサーフェィスの w, h を使用する。
|
20
|
-
# flags は常に borderless: true, fullscreen: false, resizable: false が設定される。
|
21
|
-
# shape には Surface のインスタンス・オブジェクトを与える。
|
22
|
-
# 作成されたウィンドウは透明である。表示内容は作成後に描画する必要がある。
|
23
|
-
# ウィンドウへの操作を扱いたければ HitTest コールバックを設定しコールバック側で処理を行う必要がある。
|
24
|
-
def shaped(title = nil, x = nil, y = nil, w = nil, h = nil, flags = nil,
|
25
|
-
alpha_test: nil, color_key: nil, shape:, **opts)
|
26
|
-
flags ||= WindowFlags.to_num(**opts)
|
27
|
-
# SDL_CreateShapedWindow は引数 x, y を無視する。そして x = -1000, y = -1000 に強制する。
|
28
|
-
# w, h は形状マスクのサイズに合わせる必要がある。
|
29
|
-
ptr = ::SDL2.SDL_CreateShapedWindow(title, 0, 0, shape.w, shape.h, flags)
|
30
|
-
raise RbSDL2Error if ptr.null?
|
31
|
-
to_ptr(ptr).tap do |obj|
|
32
|
-
obj.shape_set(shape, alpha_test: alpha_test, color_key: color_key)
|
33
|
-
obj.size = [w || shape.w, h || shape.h]
|
34
|
-
# 位置の再指定を行いアプリケーションの意図した位置に表示する。
|
35
|
-
obj.position = [x || ::SDL2::SDL_WINDOWPOS_CENTERED_MASK,
|
36
|
-
y || ::SDL2::SDL_WINDOWPOS_CENTERED_MASK]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_id(num)
|
41
|
-
ptr = ::SDL2.SDL_GetWindowFromID(num)
|
42
|
-
raise RbSDL2Error, "invalid window id" if ptr.null?
|
43
|
-
obj = allocate
|
44
|
-
obj.__send__(:initialize, num)
|
45
|
-
obj
|
46
|
-
end
|
47
|
-
|
48
|
-
def to_ptr(ptr)
|
49
|
-
num = ::SDL2.SDL_GetWindowID(ptr)
|
50
|
-
raise RbSDL2Error if num == 0
|
51
|
-
obj = allocate
|
52
|
-
obj.__send__(:initialize, num)
|
53
|
-
obj
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def initialize(num)
|
58
|
-
@id = num
|
59
|
-
end
|
60
|
-
|
61
|
-
require_relative 'window/dialog'
|
62
|
-
require_relative 'window/display'
|
63
|
-
require_relative 'window/grab'
|
64
|
-
require_relative 'window/position'
|
65
|
-
require_relative 'window/shape'
|
66
|
-
require_relative 'window/size'
|
67
|
-
include Dialog, Display, Grab, Position, Shape, Size
|
68
|
-
|
69
|
-
def always_on_top=(bool)
|
70
|
-
::SDL2.SDL_SetWindowAlwaysOnTop(self, bool ? ::SDL2::SDL_TRUE : ::SDL2::SDL_FALSE)
|
71
|
-
end
|
72
|
-
|
73
|
-
def border_size
|
74
|
-
top_left_bottom_right = Array.new(4) { ::FFI::MemoryPointer.new(:int) }
|
75
|
-
err = ::SDL2.SDL_GetWindowBordersSize(self, *top_left_bottom_right)
|
76
|
-
raise RbSDL2Error if err < 0
|
77
|
-
top_left_bottom_right.map(&:read_int)
|
78
|
-
end
|
79
|
-
|
80
|
-
def bordered=(bool)
|
81
|
-
::SDL2.SDL_SetWindowBordered(self, bool ? ::SDL2::SDL_TRUE : ::SDL2::SDL_FALSE)
|
82
|
-
end
|
83
|
-
|
84
|
-
def destroy
|
85
|
-
return if destroyed?
|
86
|
-
HitTest.callback_set(self, nil)
|
87
|
-
::SDL2.SDL_DestroyWindow(self)
|
88
|
-
end
|
89
|
-
|
90
|
-
def destroyed? = ::SDL2.SDL_GetWindowFromID(id).null?
|
91
|
-
|
92
|
-
def flags = ::SDL2.SDL_GetWindowFlags(self)
|
93
|
-
|
94
|
-
require_relative 'window/window_flags'
|
95
|
-
include WindowFlags
|
96
|
-
|
97
|
-
def format = ::SDL2.SDL_GetWindowPixelFormat(self)
|
98
|
-
|
99
|
-
require_relative "pixel_format_enum"
|
100
|
-
include PixelFormatEnum
|
101
|
-
|
102
|
-
def flash(bool = true)
|
103
|
-
operation = bool ? ::SDL2::SDL_FLASH_UNTIL_FOCUSED : ::SDL2::SDL_FLASH_CANCEL
|
104
|
-
err = ::SDL2.SDL_FlashWindow(self, operation)
|
105
|
-
raise RbSDL2Error if err < 0
|
106
|
-
bool
|
107
|
-
end
|
108
|
-
|
109
|
-
def flash!
|
110
|
-
err = ::SDL2.SDL_FlashWindow(self, ::SDL2::SDL_FLASH_BRIEFLY)
|
111
|
-
raise RbSDL2Error if err < 0
|
112
|
-
self
|
113
|
-
end
|
114
|
-
|
115
|
-
def fullscreen
|
116
|
-
err = ::SDL2.SDL_SetWindowFullscreen(self, ::SDL2::SDL_WINDOW_FULLSCREEN)
|
117
|
-
raise RbSDL2Error if err < 0
|
118
|
-
self
|
119
|
-
end
|
120
|
-
|
121
|
-
def fullscreen_desktop
|
122
|
-
err = ::SDL2.SDL_SetWindowFullscreen(self, ::SDL2::SDL_WINDOW_FULLSCREEN_DESKTOP)
|
123
|
-
raise RbSDL2Error if err < 0
|
124
|
-
self
|
125
|
-
end
|
126
|
-
|
127
|
-
def hide
|
128
|
-
::SDL2.SDL_HideWindow(self)
|
129
|
-
self
|
130
|
-
end
|
131
|
-
|
132
|
-
require_relative 'window/hit_test'
|
133
|
-
|
134
|
-
def hit_test_callback_set(*args) = HitTest.callback_set(self, *args)
|
135
|
-
|
136
|
-
def icon=(surface)
|
137
|
-
::SDL2.SDL_SetWindowIcon(self, surface)
|
138
|
-
end
|
139
|
-
|
140
|
-
attr_reader :id
|
141
|
-
|
142
|
-
def maximize
|
143
|
-
::SDL2.SDL_MaximizeWindow(self)
|
144
|
-
self
|
145
|
-
end
|
146
|
-
|
147
|
-
def minimize
|
148
|
-
::SDL2.SDL_MinimizeWindow(self)
|
149
|
-
self
|
150
|
-
end
|
151
|
-
|
152
|
-
def mouse_position=(x_y)
|
153
|
-
::SDL2.SDL_WarpMouseInWindow(self, *x_y)
|
154
|
-
end
|
155
|
-
|
156
|
-
def opacity
|
157
|
-
out_opacity = ::FFI::MemoryPointer.new(:float)
|
158
|
-
err = ::SDL2.SDL_GetWindowOpacity(self, out_opacity)
|
159
|
-
raise RbSDL2Error if err < 0
|
160
|
-
out_opacity.read_float
|
161
|
-
end
|
162
|
-
|
163
|
-
# ウィンドウの透明度を変更する。値は 0.0 から 1.0。値が低いほど透明になる。
|
164
|
-
def opacity=(val)
|
165
|
-
err = ::SDL2.SDL_SetWindowOpacity(self, val)
|
166
|
-
raise RbSDL2Error if err < 0
|
167
|
-
end
|
168
|
-
|
169
|
-
def popup
|
170
|
-
::SDL2.SDL_RaiseWindow(self)
|
171
|
-
self
|
172
|
-
end
|
173
|
-
|
174
|
-
def resizable=(bool)
|
175
|
-
::SDL2.SDL_SetWindowResizable(self, bool ? ::SDL2::SDL_TRUE : ::SDL2::SDL_FALSE)
|
176
|
-
end
|
177
|
-
|
178
|
-
def restore
|
179
|
-
::SDL2.SDL_RestoreWindow(self)
|
180
|
-
self
|
181
|
-
end
|
182
|
-
|
183
|
-
def show
|
184
|
-
::SDL2.SDL_ShowWindow(self)
|
185
|
-
self
|
186
|
-
end
|
187
|
-
|
188
|
-
def surface
|
189
|
-
ptr = ::SDL2.SDL_GetWindowSurface(self)
|
190
|
-
if ptr.null?
|
191
|
-
@surface = nil
|
192
|
-
raise RbSDL2Error
|
193
|
-
end
|
194
|
-
# SDL_Surface は参照カウンターで管理されているため Ruby 側でポインターを保持している限り
|
195
|
-
# 同アドレスに違う SDL_Surface が作成されることはない。安全にキャッシュできる。
|
196
|
-
ptr == @surface&.to_ptr ? @surface : @surface = Surface.to_ptr(ptr)
|
197
|
-
end
|
198
|
-
|
199
|
-
def title = ::SDL2.SDL_GetWindowTitle(self).read_string.force_encoding(Encoding::UTF_8)
|
200
|
-
|
201
|
-
def title=(obj)
|
202
|
-
::SDL2.SDL_SetWindowTitle(self, obj&.to_s&.encode(Encoding::UTF_8))
|
203
|
-
end
|
204
|
-
|
205
|
-
def to_ptr
|
206
|
-
ptr = ::SDL2.SDL_GetWindowFromID(id)
|
207
|
-
raise RbSDL2Error, "Invalid window id or window was destroyed" if ptr.null?
|
208
|
-
ptr
|
209
|
-
end
|
210
|
-
|
211
|
-
# ウィンドウのサーフェィスのコピーを戻す。
|
212
|
-
# このメソッドはウィンドウのスクリーンショットが欲しい場合に使う。
|
213
|
-
def to_surface = surface.then { |s| convert(s.format) }
|
214
|
-
|
215
|
-
# surface メソッドを実行後に Window のサイズ変更があった場合、update メソッドを実行するとエラーになる。
|
216
|
-
# このメソッドは self を戻す。
|
217
|
-
def update(rect = nil)
|
218
|
-
yield(surface) if block_given?
|
219
|
-
# SDL_UpdateWindowSurface, SDL_UpdateWindowSurfaceRects の *初回* 呼び出しの前に
|
220
|
-
# SDL_GetWindowSurface が必要になる。
|
221
|
-
surface unless @surface
|
222
|
-
|
223
|
-
err = if rect
|
224
|
-
::SDL2.SDL_UpdateWindowSurfaceRects(self, Rect.new(*rect), 1)
|
225
|
-
else
|
226
|
-
::SDL2.SDL_UpdateWindowSurface(self)
|
227
|
-
end
|
228
|
-
# SDL_GetWindowSurface の後に Window のサイズ変更があった場合はエラーになる。
|
229
|
-
if err < 0
|
230
|
-
@surface = nil
|
231
|
-
raise RbSDL2Error
|
232
|
-
end
|
233
|
-
self
|
234
|
-
end
|
235
|
-
|
236
|
-
def windowed
|
237
|
-
err = ::SDL2.SDL_SetWindowFullscreen(self, 0)
|
238
|
-
raise RbSDL2Error if err < 0
|
239
|
-
self
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|