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
@@ -0,0 +1,178 @@
|
|
1
|
+
module RbSDL2
|
2
|
+
class Window
|
3
|
+
SDL_WINDOW_FULLSCREEN = 0x00000001
|
4
|
+
SDL_WINDOW_OPENGL = 0x00000002
|
5
|
+
SDL_WINDOW_SHOWN = 0x00000004
|
6
|
+
SDL_WINDOW_HIDDEN = 0x00000008
|
7
|
+
SDL_WINDOW_BORDERLESS = 0x00000010
|
8
|
+
SDL_WINDOW_RESIZABLE = 0x00000020
|
9
|
+
SDL_WINDOW_MINIMIZED = 0x00000040
|
10
|
+
SDL_WINDOW_MAXIMIZED = 0x00000080
|
11
|
+
SDL_WINDOW_MOUSE_GRABBED = 0x00000100
|
12
|
+
SDL_WINDOW_INPUT_FOCUS = 0x00000200
|
13
|
+
SDL_WINDOW_MOUSE_FOCUS = 0x00000400
|
14
|
+
SDL_WINDOW_FULLSCREEN_DESKTOP = SDL_WINDOW_FULLSCREEN | 0x00001000
|
15
|
+
SDL_WINDOW_FOREIGN = 0x00000800
|
16
|
+
SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000
|
17
|
+
SDL_WINDOW_MOUSE_CAPTURE = 0x00004000
|
18
|
+
SDL_WINDOW_ALWAYS_ON_TOP = 0x00008000
|
19
|
+
SDL_WINDOW_SKIP_TASKBAR = 0x00010000
|
20
|
+
SDL_WINDOW_UTILITY = 0x00020000
|
21
|
+
SDL_WINDOW_TOOLTIP = 0x00040000
|
22
|
+
SDL_WINDOW_POPUP_MENU = 0x00080000
|
23
|
+
SDL_WINDOW_KEYBOARD_GRABBED = 0x00100000
|
24
|
+
SDL_WINDOW_VULKAN = 0x10000000
|
25
|
+
SDL_WINDOW_METAL = 0x20000000
|
26
|
+
|
27
|
+
SDL_WINDOW_INPUT_GRABBED = SDL_WINDOW_MOUSE_GRABBED
|
28
|
+
|
29
|
+
module State
|
30
|
+
class << self
|
31
|
+
def to_flags(allow_high_dpi: false, always_on_top: false, borderless: false, foreign: false,
|
32
|
+
fullscreen: false, fullscreen_desktop: false, hidden: false, input_focus: false,
|
33
|
+
input_grabbed: false, keyboard_grabbed: false, maximized: false, metal: false,
|
34
|
+
minimized: false, mouse_capture: false, mouse_focus: false, mouse_grabbed: false,
|
35
|
+
opengl: false, popup_menu: false, resizable: false, shown: false,
|
36
|
+
skip_taskbar: false, tooltip: false, utility: false, vulkan: false)
|
37
|
+
0 |
|
38
|
+
(allow_high_dpi ? SDL_WINDOW_ALLOW_HIGHDPI : 0) |
|
39
|
+
(always_on_top ? SDL_WINDOW_ALWAYS_ON_TOP : 0) |
|
40
|
+
(borderless ? SDL_WINDOW_BORDERLESS : 0) |
|
41
|
+
(foreign ? SDL_WINDOW_FOREIGN : 0) |
|
42
|
+
(fullscreen ? SDL_WINDOW_FULLSCREEN : 0) |
|
43
|
+
(fullscreen_desktop ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0) |
|
44
|
+
(hidden ? SDL_WINDOW_HIDDEN : 0) |
|
45
|
+
(input_focus ? SDL_WINDOW_INPUT_FOCUS : 0) |
|
46
|
+
(input_grabbed ? SDL_WINDOW_INPUT_GRABBED : 0) |
|
47
|
+
(keyboard_grabbed ? SDL_WINDOW_KEYBOARD_GRABBED : 0) |
|
48
|
+
(maximized ? SDL_WINDOW_MAXIMIZED : 0) |
|
49
|
+
(metal ? SDL_WINDOW_METAL : 0) |
|
50
|
+
(minimized ? SDL_WINDOW_MINIMIZED : 0) |
|
51
|
+
(mouse_capture ? SDL_WINDOW_MOUSE_CAPTURE : 0) |
|
52
|
+
(mouse_focus ? SDL_WINDOW_MOUSE_FOCUS : 0) |
|
53
|
+
(mouse_grabbed ? SDL_WINDOW_MOUSE_GRABBED : 0) |
|
54
|
+
(opengl ? SDL_WINDOW_OPENGL : 0) |
|
55
|
+
(popup_menu ? SDL_WINDOW_POPUP_MENU : 0) |
|
56
|
+
(resizable ? SDL_WINDOW_RESIZABLE : 0) |
|
57
|
+
(shown ? SDL_WINDOW_SHOWN : 0) |
|
58
|
+
(skip_taskbar ? SDL_WINDOW_SKIP_TASKBAR : 0) |
|
59
|
+
(tooltip ? SDL_WINDOW_TOOLTIP : 0) |
|
60
|
+
(utility ? SDL_WINDOW_UTILITY : 0) |
|
61
|
+
(vulkan ? SDL_WINDOW_VULKAN : 0)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def allow_high_dpi? = flags?(SDL_WINDOW_ALLOW_HIGHDPI)
|
66
|
+
|
67
|
+
def always_on_top=(bool)
|
68
|
+
::SDL.SetWindowAlwaysOnTop(self, bool ? ::SDL::TRUE : ::SDL::FALSE)
|
69
|
+
end
|
70
|
+
|
71
|
+
def always_on_top? = flags?(SDL_WINDOW_ALWAYS_ON_TOP)
|
72
|
+
|
73
|
+
def bordered=(bool)
|
74
|
+
::SDL.SetWindowBordered(self, bool ? ::SDL::TRUE : ::SDL::FALSE)
|
75
|
+
end
|
76
|
+
|
77
|
+
def borderless? = flags?(SDL_WINDOW_BORDERLESS)
|
78
|
+
|
79
|
+
def current! = ::SDL.RaiseWindow(self); self
|
80
|
+
|
81
|
+
def flags = ::SDL.GetWindowFlags(self)
|
82
|
+
|
83
|
+
def flags?(num) = flags & num != 0
|
84
|
+
|
85
|
+
def foreign? = flags?(SDL_WINDOW_FOREIGN)
|
86
|
+
|
87
|
+
def fullscreen
|
88
|
+
err = ::SDL.SetWindowFullscreen(self, ::SDL::WINDOW_FULLSCREEN)
|
89
|
+
raise RbSDL2Error if err < 0
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
def fullscreen? = flags?(SDL_WINDOW_FULLSCREEN)
|
94
|
+
|
95
|
+
def fullscreen_desktop
|
96
|
+
err = ::SDL.SetWindowFullscreen(self, ::SDL::WINDOW_FULLSCREEN_DESKTOP)
|
97
|
+
raise RbSDL2Error if err < 0
|
98
|
+
self
|
99
|
+
end
|
100
|
+
|
101
|
+
def fullscreen_desktop? = flags?(SDL_WINDOW_FULLSCREEN_DESKTOP)
|
102
|
+
|
103
|
+
def grab=(bool)
|
104
|
+
::SDL.SetWindowGrab(self, bool ? ::SDL::TRUE : ::SDL::FALSE)
|
105
|
+
end
|
106
|
+
|
107
|
+
def grabbed? = ::SDL.GetWindowGrab(self) == ::SDL::TRUE
|
108
|
+
|
109
|
+
def grabbed_keyboard? = ::SDL.GetWindowKeyboardGrab(self) == ::SDL::TRUE
|
110
|
+
|
111
|
+
def grabbed_mouse? = ::SDL.GetWindowMouseGrab(self) == ::SDL::TRUE
|
112
|
+
|
113
|
+
def hide = ::SDL.HideWindow(self); self
|
114
|
+
|
115
|
+
def hidden? = flags?(SDL_WINDOW_HIDDEN)
|
116
|
+
|
117
|
+
def input_focused? = flags?(SDL_WINDOW_INPUT_FOCUS)
|
118
|
+
|
119
|
+
def input_grabbed? = flags?(SDL_WINDOW_INPUT_GRABBED)
|
120
|
+
|
121
|
+
def keyboard_grab=(bool)
|
122
|
+
::SDL.SetWindowKeyboardGrab(self, bool ? ::SDL::TRUE : ::SDL::FALSE)
|
123
|
+
end
|
124
|
+
|
125
|
+
def keyboard_grabbed? = flags?(SDL_WINDOW_KEYBOARD_GRABBED)
|
126
|
+
|
127
|
+
def maximize = ::SDL.MaximizeWindow(self); self
|
128
|
+
|
129
|
+
def maximized? = flags?(SDL_WINDOW_MAXIMIZED)
|
130
|
+
|
131
|
+
def metal? = flags?(SDL_WINDOW_METAL)
|
132
|
+
|
133
|
+
def minimize = ::SDL.MinimizeWindow(self); self
|
134
|
+
|
135
|
+
def minimized? = flags?(SDL_WINDOW_MINIMIZED)
|
136
|
+
|
137
|
+
def mouse_captured? = flags?(SDL_WINDOW_MOUSE_CAPTURE)
|
138
|
+
|
139
|
+
def mouse_focused? = flags?(SDL_WINDOW_MOUSE_FOCUS)
|
140
|
+
|
141
|
+
def mouse_grab=(bool)
|
142
|
+
::SDL.SetWindowMouseGrab(self, bool ? ::SDL::TRUE : ::SDL::FALSE)
|
143
|
+
end
|
144
|
+
|
145
|
+
def mouse_grabbed? = flags?(SDL_WINDOW_MOUSE_GRABBED)
|
146
|
+
|
147
|
+
def opengl? = flags?(SDL_WINDOW_OPENGL)
|
148
|
+
|
149
|
+
def popup_menu? = flags?(SDL_WINDOW_POPUP_MENU)
|
150
|
+
|
151
|
+
def resizable=(bool)
|
152
|
+
::SDL.SetWindowResizable(self, bool ? ::SDL::TRUE : ::SDL::FALSE)
|
153
|
+
end
|
154
|
+
|
155
|
+
def resizable? = flags?(SDL_WINDOW_RESIZABLE)
|
156
|
+
|
157
|
+
def restore = ::SDL.RestoreWindow(self); self
|
158
|
+
|
159
|
+
def show = ::SDL.ShowWindow(self); self
|
160
|
+
|
161
|
+
def shown? = flags?(SDL_WINDOW_SHOWN)
|
162
|
+
|
163
|
+
def skip_taskbar? = flags?(SDL_WINDOW_SKIP_TASKBAR)
|
164
|
+
|
165
|
+
def tooltip? = flags?(SDL_WINDOW_TOOLTIP)
|
166
|
+
|
167
|
+
def utility? = flags?(SDL_WINDOW_UTILITY)
|
168
|
+
|
169
|
+
def vulkan? = flags?(SDL_WINDOW_VULKAN)
|
170
|
+
|
171
|
+
def windowed
|
172
|
+
err = ::SDL.SetWindowFullscreen(self, 0)
|
173
|
+
raise RbSDL2Error if err < 0
|
174
|
+
self
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
module RbSDL2
|
2
|
+
class Window
|
3
|
+
SDL_WINDOWPOS_CENTERED_MASK = 0x2FFF0000
|
4
|
+
|
5
|
+
require_relative 'accessor'
|
6
|
+
require_relative 'display'
|
7
|
+
require_relative 'flash'
|
8
|
+
require_relative 'shape'
|
9
|
+
require_relative 'state'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def keyboard_focused = (ptr = ::SDL.GetKeyboardFocus).null? ? nil : to_ptr(ptr)
|
13
|
+
|
14
|
+
def mouse_focused = (ptr = ::SDL.GetMouseFocus).null? ? nil : to_ptr(ptr)
|
15
|
+
|
16
|
+
def grabbed = (ptr = ::SDL.GetGrabbedWindow).null? ? nil : to_ptr(ptr)
|
17
|
+
|
18
|
+
def new(title = "", x = nil, y = nil, w = 640, h = 480, flags: nil, **opts)
|
19
|
+
ptr = ::SDL.CreateWindow(SDL.str_to_sdl(title),
|
20
|
+
x || SDL_WINDOWPOS_CENTERED_MASK, y || SDL_WINDOWPOS_CENTERED_MASK,
|
21
|
+
w, h, flags || State.to_flags(**opts))
|
22
|
+
raise RbSDL2Error if ptr.null?
|
23
|
+
to_ptr(ptr)
|
24
|
+
end
|
25
|
+
|
26
|
+
# w, h は nil の場合は shape に与えられたサーフェィスの w, h を使用する。
|
27
|
+
# flags は常に borderless: true, fullscreen: false, resizable: false が設定される。
|
28
|
+
# shape には Surface のインスタンス・オブジェクトを与える。
|
29
|
+
# 作成されたウィンドウは透明である。表示内容は作成後に描画する必要がある。
|
30
|
+
# ウィンドウへの操作を扱いたければ HitTest コールバックを設定しコールバック側で処理を行う必要がある。
|
31
|
+
def shaped(title = "", x = nil, y = nil, w = nil, h = nil, flags: nil,
|
32
|
+
alpha_test: nil, color_key: nil, shape:, **opts)
|
33
|
+
size = [w || shape.w, h || shape.h]
|
34
|
+
# w, h は形状マスクのサイズに合わせる必要がある。
|
35
|
+
ptr = ::SDL.CreateShapedWindow(SDL.str_to_sdl(title), 0, 0, *size,
|
36
|
+
flags || State.to_flags(**opts))
|
37
|
+
raise RbSDL2Error if ptr.null?
|
38
|
+
to_ptr(ptr).tap do |obj|
|
39
|
+
obj.shape_set(shape, alpha_test: alpha_test, color_key: color_key)
|
40
|
+
obj.size = size
|
41
|
+
# CreateShapedWindow は引数 x, y を無視する。そして x = -1000, y = -1000 に強制する。
|
42
|
+
# 位置の再指定を行いアプリケーションの意図した位置に表示する。
|
43
|
+
obj.position = [x || SDL_WINDOWPOS_CENTERED_MASK, y || SDL_WINDOWPOS_CENTERED_MASK]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_id(num)
|
48
|
+
ptr = ::SDL.GetWindowFromID(num)
|
49
|
+
raise RbSDL2Error, "invalid window id" if ptr.null?
|
50
|
+
obj = allocate
|
51
|
+
obj.__send__(:initialize, num)
|
52
|
+
obj
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_ptr(ptr)
|
56
|
+
num = ::SDL.GetWindowID(ptr)
|
57
|
+
raise RbSDL2Error if num == 0
|
58
|
+
obj = allocate
|
59
|
+
obj.__send__(:initialize, num)
|
60
|
+
obj
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
include Accessor, Display, Flash, Shape, State
|
65
|
+
|
66
|
+
def initialize(num)
|
67
|
+
@window_id = num
|
68
|
+
end
|
69
|
+
|
70
|
+
def ==(other)
|
71
|
+
# ウィンドウのポインターアドレスは SDL によって再利用されることがある。
|
72
|
+
# 最初に window_id を比較しなければならない。
|
73
|
+
other.respond_to?(:window_id) && other.window_id == window_id ||
|
74
|
+
other.respond_to?(:to_ptr) && other.to_ptr == to_ptr
|
75
|
+
end
|
76
|
+
|
77
|
+
def destroy = ::SDL.DestroyWindow(::SDL.GetWindowFromID(@window_id))
|
78
|
+
|
79
|
+
def destroyed? = ::SDL.GetWindowFromID(@window_id).null?
|
80
|
+
|
81
|
+
def format = ::SDL.GetWindowPixelFormat(self)
|
82
|
+
|
83
|
+
require_relative "../pixel_format_enum"
|
84
|
+
include PixelFormatEnum
|
85
|
+
|
86
|
+
require_relative 'hit_test'
|
87
|
+
|
88
|
+
def hit_test=(obj)
|
89
|
+
# dup されて片方で無効にした場合、もう一方にコールバックオブジェクトの拘束がおきる。
|
90
|
+
# これはほおっておくことにする。
|
91
|
+
@hit_test_callback = if obj
|
92
|
+
func = HitTest.new(obj)
|
93
|
+
err = ::SDL.SetWindowHitTest(self, func, nil)
|
94
|
+
raise RbSDL2Error if err < 0
|
95
|
+
func
|
96
|
+
end
|
97
|
+
@hit_test_object = obj
|
98
|
+
end
|
99
|
+
|
100
|
+
def mouse_position=(x_y)
|
101
|
+
::SDL.WarpMouseInWindow(self, *x_y)
|
102
|
+
end
|
103
|
+
|
104
|
+
def surface
|
105
|
+
ptr = ::SDL.GetWindowSurface(self)
|
106
|
+
if ptr.null?
|
107
|
+
@surface = nil
|
108
|
+
raise RbSDL2Error
|
109
|
+
end
|
110
|
+
# Surface は参照カウンターで管理されているため Ruby 側でポインターを保持している限り
|
111
|
+
# 同アドレスに違う Surface が作成されることはない。安全にキャッシュできる。
|
112
|
+
ptr == @surface&.to_ptr ? @surface : @surface = Surface.to_ptr(ptr)
|
113
|
+
end
|
114
|
+
|
115
|
+
def to_ptr
|
116
|
+
ptr = ::SDL.GetWindowFromID(@window_id)
|
117
|
+
raise RbSDL2Error, "Invalid window id or window was destroyed" if ptr.null?
|
118
|
+
ptr
|
119
|
+
end
|
120
|
+
|
121
|
+
# ウィンドウのサーフェィスのコピーを戻す。
|
122
|
+
# このメソッドはウィンドウのスクリーンショットが欲しい場合に使う。
|
123
|
+
def to_surface = surface.then { |s| convert(s.format) }
|
124
|
+
|
125
|
+
# surface メソッドを実行後に Window のサイズ変更があった場合、update メソッドを実行するとエラーになる。
|
126
|
+
# このメソッドは self を戻す。
|
127
|
+
def update(rect = nil)
|
128
|
+
yield(surface) if block_given?
|
129
|
+
# UpdateWindowSurface, UpdateWindowSurfaceRects の *初回* 呼び出しの前に
|
130
|
+
# GetWindowSurface が必要になる。
|
131
|
+
surface unless @surface
|
132
|
+
|
133
|
+
err = if rect
|
134
|
+
::SDL.UpdateWindowSurfaceRects(self, Rect.new(*rect), 1)
|
135
|
+
else
|
136
|
+
::SDL.UpdateWindowSurface(self)
|
137
|
+
end
|
138
|
+
# GetWindowSurface の後に Window のサイズ変更があった場合はエラーになる。
|
139
|
+
if err < 0
|
140
|
+
@surface = nil
|
141
|
+
raise RbSDL2Error
|
142
|
+
end
|
143
|
+
self
|
144
|
+
end
|
145
|
+
|
146
|
+
attr_reader :window_id
|
147
|
+
alias id window_id
|
148
|
+
end
|
149
|
+
end
|
data/lib/rb_sdl2.rb
CHANGED
@@ -1,53 +1,115 @@
|
|
1
1
|
module RbSDL2
|
2
2
|
require 'sdl2'
|
3
|
-
require_relative 'rb_sdl2/audio'
|
3
|
+
require_relative 'rb_sdl2/audio/audio'
|
4
4
|
require_relative 'rb_sdl2/clipboard'
|
5
5
|
require_relative 'rb_sdl2/cpu_info'
|
6
6
|
require_relative 'rb_sdl2/cursor'
|
7
7
|
require_relative 'rb_sdl2/display'
|
8
8
|
require_relative 'rb_sdl2/display_mode'
|
9
9
|
require_relative 'rb_sdl2/error'
|
10
|
-
require_relative 'rb_sdl2/
|
10
|
+
require_relative 'rb_sdl2/errors'
|
11
|
+
require_relative 'rb_sdl2/event/event'
|
11
12
|
require_relative 'rb_sdl2/filesystem'
|
12
13
|
require_relative 'rb_sdl2/hint'
|
13
|
-
require_relative 'rb_sdl2/keyboard'
|
14
|
+
require_relative 'rb_sdl2/keyboard/keyboard'
|
14
15
|
require_relative 'rb_sdl2/message_box'
|
15
|
-
require_relative 'rb_sdl2/mouse'
|
16
|
+
require_relative 'rb_sdl2/mouse/mouse'
|
16
17
|
require_relative 'rb_sdl2/palette'
|
17
18
|
require_relative 'rb_sdl2/pixel_format_enum'
|
18
19
|
require_relative 'rb_sdl2/platform'
|
19
20
|
require_relative 'rb_sdl2/power_info'
|
20
21
|
require_relative 'rb_sdl2/rect'
|
21
|
-
require_relative 'rb_sdl2/rw_ops'
|
22
|
-
require_relative 'rb_sdl2/screen_saver'
|
22
|
+
require_relative 'rb_sdl2/rw_ops/rw_ops'
|
23
23
|
require_relative 'rb_sdl2/sdl'
|
24
24
|
require_relative 'rb_sdl2/surface'
|
25
25
|
require_relative 'rb_sdl2/text_input'
|
26
26
|
require_relative 'rb_sdl2/timer'
|
27
|
-
require_relative 'rb_sdl2/window'
|
28
27
|
require_relative 'rb_sdl2/video'
|
29
28
|
require_relative 'rb_sdl2/version'
|
29
|
+
require_relative 'rb_sdl2/window/window'
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
require 'forwardable'
|
32
|
+
extend SingleForwardable
|
33
|
+
def_single_delegator Clipboard, :text, :clipboard_text
|
34
|
+
def_single_delegator Clipboard, :text=, :clipboard_text=
|
35
|
+
def_single_delegators CPUInfo, *%i(cpu_cache_line_size cpu_count system_ram)
|
36
|
+
def_single_delegators Keyboard, *%i(hit_any_key? pressed_any_key? pressed_key?)
|
37
|
+
def_single_delegators Platform, *%i(platform)
|
38
|
+
def_single_delegators SDL, *%i(init init? quit)
|
39
|
+
def_single_delegators Timer, *%i(delay realtime ticks)
|
40
|
+
def_single_delegators Version, *%i(revision version)
|
41
|
+
def_single_delegators Video, *%i(screen_saver? screen_saver=)
|
34
42
|
|
35
43
|
class << self
|
36
|
-
def
|
44
|
+
def hide_cursor = Cursor.hide
|
45
|
+
|
46
|
+
def show_cursor = Cursor.show
|
47
|
+
|
48
|
+
def confirm(message) = MessageBox.show(0, message, buttons: %w(Cancel OK), default: 1) == 1
|
49
|
+
alias confirm? confirm
|
50
|
+
|
51
|
+
def alert(message) = MessageBox.simple(0, message)
|
52
|
+
|
53
|
+
def error_alert(message) = MessageBox.simple(MessageBox::ERROR, message)
|
54
|
+
|
55
|
+
def info_alert(message) = MessageBox.simple(MessageBox::INFO, message)
|
56
|
+
|
57
|
+
def warn_alert(message) = MessageBox.simple(MessageBox::WARN, message)
|
37
58
|
|
38
59
|
def load(path)
|
39
|
-
::
|
60
|
+
::SDL.load_lib(path)
|
40
61
|
# オーディオデバイスを閉じ忘れるとアプリケーションの終了時にメモリーアクセス違反を起こす。
|
41
62
|
# アプリケーションが強制終了した場合を考慮し終了処理を設定する。
|
42
|
-
at_exit { ::
|
63
|
+
at_exit { ::SDL.Quit }
|
64
|
+
::SDL.module_exec do
|
65
|
+
attach_function :SDL_AtomicAdd, [:pointer, :int], :int
|
66
|
+
attach_function :SDL_GetPreferredLocales, [], :pointer
|
67
|
+
end
|
43
68
|
end
|
44
69
|
|
45
70
|
def loop
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
71
|
+
Event.clear
|
72
|
+
yield until Event.quit?
|
73
|
+
end
|
74
|
+
|
75
|
+
# => ["ja", "JP", "en", "US"]
|
76
|
+
def locales
|
77
|
+
ptr = SDLPointer.new(::SDL.SDL_GetPreferredLocales)
|
78
|
+
# メモリーが確保できない、もしくは情報が無い。
|
79
|
+
return [] if ptr.null?
|
80
|
+
|
81
|
+
ptr_size = ::FFI::Pointer.size
|
82
|
+
a = []
|
83
|
+
until (c = ptr.read_pointer).null?
|
84
|
+
a << c.read_string
|
85
|
+
ptr += ptr_size
|
86
|
+
end
|
87
|
+
a
|
88
|
+
end
|
89
|
+
|
90
|
+
def open_rw(obj, ...)
|
91
|
+
case obj
|
92
|
+
when String then RWFile.open(obj, ...)
|
93
|
+
when ::FFI::Pointer then RWMemory.open(obj, ...)
|
94
|
+
when RWOps then block_given? ? yield(obj) : obj
|
95
|
+
else RWObject.open(obj, ...)
|
50
96
|
end
|
51
97
|
end
|
98
|
+
|
99
|
+
# url に与えた URL に応じたアプリケーションが起動します。
|
100
|
+
# URL はローカルファイルを指定することができます。
|
101
|
+
# その場合は "file:///full/path/to/file" の形式の文字列を使います。
|
102
|
+
# Windows 環境では "file:///C:/full/path/to/file" のようにドライブレターも含みます。
|
103
|
+
# (パス区切り文字は '/' でも '\' でも問題はない)
|
104
|
+
# 主な使い方としてユーザに提示したい Web サイトをブラウザーを起動して見せたい場合に使用します。
|
105
|
+
# 成功時にアプリケーションへのフォーカスが失われる場合もあります。
|
106
|
+
# 成功しても何も起きていない場合もある。確実な動作のためには実働テストを行う必要がある。
|
107
|
+
# 未対応の環境ではエラーになる。
|
108
|
+
def open_url(url)
|
109
|
+
err = ::SDL.OpenURL(SDL.str_to_sdl(url))
|
110
|
+
raise RbSDL2Error if err < 0
|
111
|
+
end
|
112
|
+
|
113
|
+
def power_info = PowerInfo.new
|
52
114
|
end
|
53
115
|
end
|
data/rb_sdl2.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "rb_sdl2"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.2.0"
|
6
6
|
spec.author = "shinokaro"
|
7
7
|
spec.email = "shinokaro@hotmail.co.jp"
|
8
8
|
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.description = "RbSDL2 treats the functions and pointers provided by SDL as Ruby objects."
|
11
11
|
spec.homepage = "https://github.com/shinokaro/rb_sdl2/blob/main/README.md"
|
12
12
|
spec.license = "Zlib"
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 3.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")
|
14
14
|
|
15
15
|
spec.metadata['bug_tracker_uri'] = 'https://github.com/shinokaro/rb_sdl2/issues'
|
16
16
|
spec.metadata["changelog_uri"] = "https://github.com/shinokaro/rb_sdl2/blob/main/CHANGELOG.md"
|
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
23
23
|
end
|
24
24
|
|
25
|
-
spec.add_dependency "ffi", "
|
26
|
-
spec.add_dependency "sdl2-bindings", "
|
25
|
+
spec.add_dependency "ffi", "~> 1.15"
|
26
|
+
spec.add_dependency "sdl2-bindings", "~> 0.1.1"
|
27
27
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb_sdl2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shinokaro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.15
|
19
|
+
version: '1.15'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.15
|
26
|
+
version: '1.15'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sdl2-bindings
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.1.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.1.1
|
41
41
|
description: RbSDL2 treats the functions and pointers provided by SDL as Ruby objects.
|
42
42
|
email: shinokaro@hotmail.co.jp
|
43
43
|
executables: []
|
@@ -48,50 +48,48 @@ files:
|
|
48
48
|
- LICENSE.txt
|
49
49
|
- README.md
|
50
50
|
- lib/rb_sdl2.rb
|
51
|
-
- lib/rb_sdl2/audio.rb
|
52
|
-
- lib/rb_sdl2/audio/audio_allowed_changes.rb
|
51
|
+
- lib/rb_sdl2/audio/audio.rb
|
53
52
|
- lib/rb_sdl2/audio/audio_buffer.rb
|
54
53
|
- lib/rb_sdl2/audio/audio_device.rb
|
55
|
-
- lib/rb_sdl2/audio/audio_format.rb
|
56
54
|
- lib/rb_sdl2/audio/audio_spec.rb
|
55
|
+
- lib/rb_sdl2/audio/audio_spec_reader.rb
|
57
56
|
- lib/rb_sdl2/clipboard.rb
|
58
57
|
- lib/rb_sdl2/cpu_info.rb
|
59
58
|
- lib/rb_sdl2/cursor.rb
|
60
|
-
- lib/rb_sdl2/cursor/color_cursor.rb
|
61
|
-
- lib/rb_sdl2/cursor/cursor_class.rb
|
62
|
-
- lib/rb_sdl2/cursor/cursor_pointer.rb
|
63
|
-
- lib/rb_sdl2/cursor/default_cursor.rb
|
64
|
-
- lib/rb_sdl2/cursor/system_cursor.rb
|
65
59
|
- lib/rb_sdl2/display.rb
|
66
60
|
- lib/rb_sdl2/display_mode.rb
|
67
61
|
- lib/rb_sdl2/error.rb
|
68
|
-
- lib/rb_sdl2/
|
62
|
+
- lib/rb_sdl2/errors.rb
|
63
|
+
- lib/rb_sdl2/event/event.rb
|
69
64
|
- lib/rb_sdl2/event/event_filter.rb
|
65
|
+
- lib/rb_sdl2/event/event_pointer.rb
|
70
66
|
- lib/rb_sdl2/event/event_queue.rb
|
71
67
|
- lib/rb_sdl2/event/event_type.rb
|
72
68
|
- lib/rb_sdl2/filesystem.rb
|
73
69
|
- lib/rb_sdl2/hint.rb
|
74
|
-
- lib/rb_sdl2/keyboard.rb
|
75
|
-
- lib/rb_sdl2/keyboard/
|
76
|
-
- lib/rb_sdl2/keyboard/
|
70
|
+
- lib/rb_sdl2/keyboard/keyboard.rb
|
71
|
+
- lib/rb_sdl2/keyboard/mod_state.rb
|
72
|
+
- lib/rb_sdl2/keyboard/state.rb
|
77
73
|
- lib/rb_sdl2/message_box.rb
|
78
|
-
- lib/rb_sdl2/mouse.rb
|
79
74
|
- lib/rb_sdl2/mouse/global_mouse.rb
|
75
|
+
- lib/rb_sdl2/mouse/mouse.rb
|
80
76
|
- lib/rb_sdl2/mouse/mouse_button.rb
|
81
77
|
- lib/rb_sdl2/mouse/mouse_class.rb
|
82
78
|
- lib/rb_sdl2/mouse/mouse_wheel.rb
|
83
79
|
- lib/rb_sdl2/mouse/relative_mouse.rb
|
84
|
-
- lib/rb_sdl2/mouse/window_mouse.rb
|
85
80
|
- lib/rb_sdl2/palette.rb
|
86
81
|
- lib/rb_sdl2/pixel_format_enum.rb
|
87
82
|
- lib/rb_sdl2/platform.rb
|
88
83
|
- lib/rb_sdl2/power_info.rb
|
89
84
|
- lib/rb_sdl2/rect.rb
|
90
85
|
- lib/rb_sdl2/ref_count_pointer.rb
|
91
|
-
- lib/rb_sdl2/rw_ops.rb
|
92
|
-
- lib/rb_sdl2/rw_ops/
|
93
|
-
- lib/rb_sdl2/
|
86
|
+
- lib/rb_sdl2/rw_ops/rw_file.rb
|
87
|
+
- lib/rb_sdl2/rw_ops/rw_memory.rb
|
88
|
+
- lib/rb_sdl2/rw_ops/rw_object.rb
|
89
|
+
- lib/rb_sdl2/rw_ops/rw_ops.rb
|
90
|
+
- lib/rb_sdl2/rw_ops/rw_ops_pointer.rb
|
94
91
|
- lib/rb_sdl2/sdl.rb
|
92
|
+
- lib/rb_sdl2/sdl_pointer.rb
|
95
93
|
- lib/rb_sdl2/surface.rb
|
96
94
|
- lib/rb_sdl2/surface/blend_mode.rb
|
97
95
|
- lib/rb_sdl2/surface/pixel_format.rb
|
@@ -99,15 +97,13 @@ files:
|
|
99
97
|
- lib/rb_sdl2/timer.rb
|
100
98
|
- lib/rb_sdl2/version.rb
|
101
99
|
- lib/rb_sdl2/video.rb
|
102
|
-
- lib/rb_sdl2/window.rb
|
103
|
-
- lib/rb_sdl2/window/dialog.rb
|
100
|
+
- lib/rb_sdl2/window/accessor.rb
|
104
101
|
- lib/rb_sdl2/window/display.rb
|
105
|
-
- lib/rb_sdl2/window/
|
102
|
+
- lib/rb_sdl2/window/flash.rb
|
106
103
|
- lib/rb_sdl2/window/hit_test.rb
|
107
|
-
- lib/rb_sdl2/window/position.rb
|
108
104
|
- lib/rb_sdl2/window/shape.rb
|
109
|
-
- lib/rb_sdl2/window/
|
110
|
-
- lib/rb_sdl2/window/
|
105
|
+
- lib/rb_sdl2/window/state.rb
|
106
|
+
- lib/rb_sdl2/window/window.rb
|
111
107
|
- rb_sdl2.gemspec
|
112
108
|
homepage: https://github.com/shinokaro/rb_sdl2/blob/main/README.md
|
113
109
|
licenses:
|
@@ -126,14 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
122
|
requirements:
|
127
123
|
- - ">="
|
128
124
|
- !ruby/object:Gem::Version
|
129
|
-
version: 3.
|
125
|
+
version: 3.1.0
|
130
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
127
|
requirements:
|
132
128
|
- - ">="
|
133
129
|
- !ruby/object:Gem::Version
|
134
130
|
version: '0'
|
135
131
|
requirements: []
|
136
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.3.3
|
137
133
|
signing_key:
|
138
134
|
specification_version: 4
|
139
135
|
summary: Multimedia library with SDL.
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class Audio
|
3
|
-
module AudioAllowedChanges
|
4
|
-
class << self
|
5
|
-
def to_num(any_change: false, channels_change: false, format_change: false,
|
6
|
-
frequency_change: false, samples_change: false)
|
7
|
-
0 |
|
8
|
-
(any_change ? ::SDL2::SDL_AUDIO_ALLOW_ANY_CHANGE : 0) |
|
9
|
-
(channels_change ? ::SDL2::SDL_AUDIO_ALLOW_CHANNELS_CHANGE : 0) |
|
10
|
-
(format_change ? ::SDL2::SDL_AUDIO_ALLOW_FORMAT_CHANGE : 0) |
|
11
|
-
(frequency_change ? ::SDL2::SDL_AUDIO_ALLOW_FREQUENCY_CHANGE : 0) |
|
12
|
-
(samples_change ? ::SDL2::SDL_AUDIO_ALLOW_SAMPLES_CHANGE : 0)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class Audio
|
3
|
-
module AudioFormat
|
4
|
-
class << self
|
5
|
-
def to_num(signed: true, big_endian: false, bit_size: 16, float: false)
|
6
|
-
num = 0 |
|
7
|
-
(big_endian ? ::SDL2::SDL_AUDIO_MASK_ENDIAN : 0) |
|
8
|
-
(bit_size & ::SDL2::SDL_AUDIO_MASK_BITSIZE) |
|
9
|
-
(signed ? ::SDL2::SDL_AUDIO_MASK_SIGNED : 0)
|
10
|
-
num | (float ? ::SDL2::SDL_AUDIO_MASK_DATATYPE & ::SDL2::SDL_AUDIO_MASK_SIGNED : 0)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def big_endian? = ::SDL2::SDL_AUDIO_MASK_ENDIAN & format != 0
|
15
|
-
|
16
|
-
def bit_size = ::SDL2::SDL_AUDIO_MASK_BITSIZE & format
|
17
|
-
|
18
|
-
def float? = ::SDL2::SDL_AUDIO_MASK_DATATYPE & format != 0
|
19
|
-
|
20
|
-
def signed? = ::SDL2::SDL_AUDIO_MASK_SIGNED & format != 0
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|