rb_sdl2 0.1.0 → 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 +69 -0
- data/README.md +15 -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 +14 -3
- 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 +15 -11
- data/lib/rb_sdl2/pixel_format_enum.rb +87 -55
- data/lib/rb_sdl2/platform.rb +3 -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 +72 -21
- 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 -244
- data/lib/rb_sdl2/text_input.rb +21 -15
- data/lib/rb_sdl2/timer.rb +36 -22
- data/lib/rb_sdl2/version.rb +5 -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 +12 -4
- metadata +38 -37
- 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 -102
- data/lib/rb_sdl2/rw_ops.rb +0 -124
- 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/rw_ops.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class RWOps
|
3
|
-
class Releaser < ::FFI::AutoPointer
|
4
|
-
class << self
|
5
|
-
def release(ptr)
|
6
|
-
# SDL_RWclose は RWOps構造体を開放する。そのため呼び出しは1回しかできない。
|
7
|
-
# ::FFI::AutoPointer を使うことで2重開放を防ぐ。
|
8
|
-
raise RbSDL2Error if ::SDL2.SDL_RWclose(ptr) < 0
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def free
|
13
|
-
@released = true
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
def released? = @released
|
18
|
-
end
|
19
|
-
|
20
|
-
# マルチスレッド対応はしていない。
|
21
|
-
# close メソッドは SDL 側からクローズされていた場合に対応していない。
|
22
|
-
class << self
|
23
|
-
def from_memory(mem, size, autoclose: true, readonly: true)
|
24
|
-
ptr = if readonly
|
25
|
-
::SDL2.SDL_RWFromConstMem(mem, size)
|
26
|
-
else
|
27
|
-
::SDL2.SDL_RWFromMem(mem, size)
|
28
|
-
end
|
29
|
-
raise RbSDL2Error if ptr.null?
|
30
|
-
obj = allocate
|
31
|
-
obj.__send__(:initialize, ptr, mem, autoclose: autoclose)
|
32
|
-
end
|
33
|
-
|
34
|
-
# mode は一般的なファイルAPIと同じ文字列が使用できる。
|
35
|
-
def new(file, _mode = "rb", autoclose: true, mode: _mode)
|
36
|
-
ptr = ::SDL2.SDL_RWFromFile(file.to_s, mode)
|
37
|
-
raise RbSDL2Error if ptr.null?
|
38
|
-
obj = super(ptr, autoclose: autoclose)
|
39
|
-
if block_given?
|
40
|
-
begin
|
41
|
-
yield(obj)
|
42
|
-
ensure
|
43
|
-
obj.close
|
44
|
-
end
|
45
|
-
else
|
46
|
-
obj
|
47
|
-
end
|
48
|
-
end
|
49
|
-
alias open new
|
50
|
-
|
51
|
-
def to_ptr(ptr)
|
52
|
-
obj = allocate
|
53
|
-
obj.__send__(:initialize, ptr, autoclose: false)
|
54
|
-
obj
|
55
|
-
end
|
56
|
-
|
57
|
-
require_relative 'rw_ops/rw_operator'
|
58
|
-
|
59
|
-
def with_object(obj)
|
60
|
-
rw = RWOperator.new(obj)
|
61
|
-
obj = allocate
|
62
|
-
obj.__send__(:initialize, rw.to_ptr, rw, autoclose: false)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def initialize(ptr, obj = nil, autoclose:)
|
67
|
-
@obj = obj
|
68
|
-
@ptr = Releaser.new(ptr)
|
69
|
-
self.autoclose = autoclose
|
70
|
-
end
|
71
|
-
|
72
|
-
def autoclose=(bool)
|
73
|
-
@ptr.autorelease = bool
|
74
|
-
end
|
75
|
-
|
76
|
-
def autoclose? = @ptr.autorelease
|
77
|
-
|
78
|
-
def close = @ptr.free
|
79
|
-
|
80
|
-
def closed? = @ptr.released?
|
81
|
-
|
82
|
-
def read(length = nil)
|
83
|
-
raise IOError if closed?
|
84
|
-
len = length.nil? ? size : length.to_i
|
85
|
-
raise ArgumentError if len < 0
|
86
|
-
return "" if len == 0
|
87
|
-
ptr = ::FFI::MemoryPointer.new(len)
|
88
|
-
num = ::SDL2.SDL_RWread(self, ptr, 1, len)
|
89
|
-
raise RbSDL2Error if num == 0
|
90
|
-
ptr.read_bytes(num)
|
91
|
-
end
|
92
|
-
|
93
|
-
def seek(offset, whence = IO::SEEK_SET)
|
94
|
-
raise IOError if closed?
|
95
|
-
raise RbSDL2Error if ::SDL2.SDL_RWseek(self, offset, whence) == -1
|
96
|
-
0
|
97
|
-
end
|
98
|
-
|
99
|
-
def size
|
100
|
-
raise IOError if closed?
|
101
|
-
num = ::SDL2.SDL_RWsize(self)
|
102
|
-
raise RbSDL2Error if num < 0
|
103
|
-
num
|
104
|
-
end
|
105
|
-
|
106
|
-
def to_ptr
|
107
|
-
raise IOError if closed?
|
108
|
-
@ptr
|
109
|
-
end
|
110
|
-
|
111
|
-
def write(*str)
|
112
|
-
raise FrozenError if frozen?
|
113
|
-
raise IOError if closed?
|
114
|
-
str.inject(0) do |sum, obj|
|
115
|
-
bytes = obj.to_s
|
116
|
-
len = bytes.size
|
117
|
-
ptr = ::FFI::MemoryPointer.new(len).write_bytes(bytes)
|
118
|
-
num = ::SDL2.SDL_RWwrite(self, ptr, 1, len)
|
119
|
-
raise RbSDL2Error if num < len
|
120
|
-
sum + len
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
data/lib/rb_sdl2/screen_saver.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class Window
|
3
|
-
module Dialog
|
4
|
-
require_relative '../message_box'
|
5
|
-
|
6
|
-
def alert(message, **opts) = MessageBox.alert(message, self, **opts)
|
7
|
-
|
8
|
-
def confirm(message, **opts) = MessageBox.confirm(message, self, **opts)
|
9
|
-
|
10
|
-
def dialog(message, **opts) = MessageBox.dialog(message, self, **opts)
|
11
|
-
|
12
|
-
def error_alert(message, **opts) = MessageBox.error(message, self, **opts)
|
13
|
-
|
14
|
-
def info_alert(message, **opts) = MessageBox.info(message, self, **opts)
|
15
|
-
|
16
|
-
def warn_alert(message, **opts) = MessageBox.warn(message, self, **opts)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/rb_sdl2/window/grab.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class Window
|
3
|
-
module Grab
|
4
|
-
def grab=(bool)
|
5
|
-
::SDL2.SDL_SetWindowGrab(self, bool ? ::SDL2::SDL_TRUE : ::SDL2::SDL_FALSE)
|
6
|
-
end
|
7
|
-
|
8
|
-
def grabbed? = ::SDL2.SDL_GetWindowGrab(self) == ::SDL2::SDL_TRUE
|
9
|
-
|
10
|
-
def grabbed_keyboard? = ::SDL2.SDL_GetWindowKeyboardGrab(self) == ::SDL2::SDL_TRUE
|
11
|
-
|
12
|
-
def grabbed_mouse? = ::SDL2.SDL_GetWindowMouseGrab(self) == ::SDL2::SDL_TRUE
|
13
|
-
|
14
|
-
def keyboard_grab=(bool)
|
15
|
-
::SDL2.SDL_SetWindowKeyboardGrab(self, bool ? ::SDL2::SDL_TRUE : ::SDL2::SDL_FALSE)
|
16
|
-
end
|
17
|
-
|
18
|
-
def mouse_grab=(bool)
|
19
|
-
::SDL2.SDL_SetWindowMouseGrab(self, bool ? ::SDL2::SDL_TRUE : ::SDL2::SDL_FALSE)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class Window
|
3
|
-
module Position
|
4
|
-
def position
|
5
|
-
x_y = Array.new(2) { ::FFI::MemoryPointer.new(:int) }
|
6
|
-
::SDL2.SDL_GetWindowPosition(self, *x_y)
|
7
|
-
x_y.map(&:read_int)
|
8
|
-
end
|
9
|
-
|
10
|
-
def position=(x_y)
|
11
|
-
wx, wy = x_y
|
12
|
-
wx ||= ::SDL2::SDL_WINDOWPOS_CENTERED_MASK
|
13
|
-
wy ||= ::SDL2::SDL_WINDOWPOS_CENTERED_MASK
|
14
|
-
::SDL2.SDL_SetWindowPosition(self, wx, wy)
|
15
|
-
end
|
16
|
-
|
17
|
-
def x
|
18
|
-
ptr = ::FFI::MemoryPointer.new(:int)
|
19
|
-
::SDL2.SDL_GetWindowPosition(self, ptr, nil)
|
20
|
-
ptr.read_int
|
21
|
-
end
|
22
|
-
|
23
|
-
def x=(num)
|
24
|
-
self.position = [num, y]
|
25
|
-
end
|
26
|
-
|
27
|
-
def y
|
28
|
-
ptr = ::FFI::MemoryPointer.new(:int)
|
29
|
-
::SDL2.SDL_GetWindowPosition(self, nil, ptr)
|
30
|
-
ptr.read_int
|
31
|
-
end
|
32
|
-
|
33
|
-
def y=(num)
|
34
|
-
self.position = [x, num]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/rb_sdl2/window/size.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class Window
|
3
|
-
module Size
|
4
|
-
def height
|
5
|
-
ptr = ::FFI::MemoryPointer.new(:int)
|
6
|
-
::SDL2.SDL_GetWindowSize(self, nil, ptr)
|
7
|
-
ptr.read_int
|
8
|
-
end
|
9
|
-
alias h height
|
10
|
-
|
11
|
-
def height=(num)
|
12
|
-
self.size = [w, num]
|
13
|
-
end
|
14
|
-
alias h= height=
|
15
|
-
|
16
|
-
def maximum_size
|
17
|
-
w_h = Array.new(2) { ::FFI::MemoryPointer.new(:int) }
|
18
|
-
::SDL2.SDL_GetWindowMaximumSize(self, *w_h)
|
19
|
-
w_h.map(&:read_int)
|
20
|
-
end
|
21
|
-
|
22
|
-
def maximum_size=(w_h)
|
23
|
-
::SDL2.SDL_SetWindowMaximumSize(self, *w_h)
|
24
|
-
end
|
25
|
-
|
26
|
-
def minimum_size
|
27
|
-
w_h = Array.new(2) { ::FFI::MemoryPointer.new(:int) }
|
28
|
-
::SDL2.SDL_GetWindowMinimumSize(self, *w_h)
|
29
|
-
w_h.map(&:read_int)
|
30
|
-
end
|
31
|
-
|
32
|
-
def minimum_size=(w_h)
|
33
|
-
::SDL2.SDL_SetWindowMinimumSize(self, *w_h)
|
34
|
-
end
|
35
|
-
|
36
|
-
def size
|
37
|
-
w_h = Array.new(2) { ::FFI::MemoryPointer.new(:int) }
|
38
|
-
::SDL2.SDL_GetWindowSize(self, *w_h)
|
39
|
-
w_h.map(&:read_int)
|
40
|
-
end
|
41
|
-
|
42
|
-
def size=(w_h)
|
43
|
-
::SDL2.SDL_SetWindowSize(self, *w_h)
|
44
|
-
end
|
45
|
-
|
46
|
-
def width
|
47
|
-
ptr = ::FFI::MemoryPointer.new(:int)
|
48
|
-
::SDL2.SDL_GetWindowSize(self, ptr, nil)
|
49
|
-
ptr.read_int
|
50
|
-
end
|
51
|
-
alias w width
|
52
|
-
|
53
|
-
def width=(num)
|
54
|
-
self.size = [num, h]
|
55
|
-
end
|
56
|
-
alias w= width=
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class Window
|
3
|
-
module WindowFlags
|
4
|
-
class << self
|
5
|
-
def to_num(allow_high_dpi: false, always_on_top: false, borderless: false, foreign: false,
|
6
|
-
fullscreen: false, fullscreen_desktop: false, hidden: false, input_focus: false,
|
7
|
-
input_grabbed: false, maximized: false, minimized: false, mouse_capture: false,
|
8
|
-
mouse_focus: false, opengl: false, popup_menu: false, resizable: false,
|
9
|
-
shown: false, skip_taskbar: false, tooltip: false, utility: false, vulkan: false)
|
10
|
-
0 |
|
11
|
-
(allow_high_dpi ? ::SDL2::SDL_WINDOW_ALLOW_HIGHDPI : 0) |
|
12
|
-
(always_on_top ? ::SDL2::SDL_WINDOW_ALWAYS_ON_TOP : 0) |
|
13
|
-
(borderless ? ::SDL2::SDL_WINDOW_BORDERLESS : 0) |
|
14
|
-
(foreign ? ::SDL2::SDL_WINDOW_FOREIGN : 0) |
|
15
|
-
(fullscreen ? ::SDL2::SDL_WINDOW_FULLSCREEN : 0) |
|
16
|
-
(fullscreen_desktop ? ::SDL2::SDL_WINDOW_FULLSCREEN_DESKTOP : 0) |
|
17
|
-
(hidden ? ::SDL2::SDL_WINDOW_HIDDEN : 0) |
|
18
|
-
(input_focus ? ::SDL2::SDL_WINDOW_INPUT_FOCUS : 0) |
|
19
|
-
(input_grabbed ? ::SDL2::SDL_WINDOW_INPUT_GRABBED : 0) |
|
20
|
-
(maximized ? ::SDL2::SDL_WINDOW_MAXIMIZED : 0) |
|
21
|
-
(minimized ? ::SDL2::SDL_WINDOW_MINIMIZED : 0) |
|
22
|
-
(mouse_capture ? ::SDL2::SDL_WINDOW_MOUSE_CAPTURE : 0) |
|
23
|
-
(mouse_focus ? ::SDL2::SDL_WINDOW_MOUSE_FOCUS : 0) |
|
24
|
-
(opengl ? ::SDL2::SDL_WINDOW_OPENGL : 0) |
|
25
|
-
(popup_menu ? ::SDL2::SDL_WINDOW_POPUP_MENU : 0) |
|
26
|
-
(resizable ? ::SDL2::SDL_WINDOW_RESIZABLE : 0) |
|
27
|
-
(shown ? ::SDL2::SDL_WINDOW_SHOWN : 0) |
|
28
|
-
(skip_taskbar ? ::SDL2::SDL_WINDOW_SKIP_TASKBAR : 0) |
|
29
|
-
(tooltip ? ::SDL2::SDL_WINDOW_TOOLTIP : 0) |
|
30
|
-
(utility ? ::SDL2::SDL_WINDOW_UTILITY : 0) |
|
31
|
-
(vulkan ? ::SDL2::SDL_WINDOW_VULKAN : 0)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def allow_high_dpi? = ::SDL2::SDL_WINDOW_ALLOW_HIGHDPI & flags != 0
|
36
|
-
|
37
|
-
def always_on_top? = ::SDL2::SDL_WINDOW_ALWAYS_ON_TOP & flags != 0
|
38
|
-
|
39
|
-
def borderless? = ::SDL2::SDL_WINDOW_BORDERLESS & flags != 0
|
40
|
-
|
41
|
-
def foreign? = ::SDL2::SDL_WINDOW_FOREIGN & flags != 0
|
42
|
-
|
43
|
-
def fullscreen? = ::SDL2::SDL_WINDOW_FULLSCREEN & flags != 0
|
44
|
-
|
45
|
-
def fullscreen_desktop? = ::SDL2::SDL_WINDOW_FULLSCREEN_DESKTOP & flags != 0
|
46
|
-
|
47
|
-
def hidden? = ::SDL2::SDL_WINDOW_HIDDEN & flags != 0
|
48
|
-
|
49
|
-
def input_focused? = ::SDL2::SDL_WINDOW_INPUT_FOCUS & flags != 0
|
50
|
-
|
51
|
-
def input_grabbed? = ::SDL2::SDL_WINDOW_INPUT_GRABBED & flags != 0
|
52
|
-
|
53
|
-
def maximized? = ::SDL2::SDL_WINDOW_MAXIMIZED & flags != 0
|
54
|
-
|
55
|
-
def minimized? = ::SDL2::SDL_WINDOW_MINIMIZED & flags != 0
|
56
|
-
|
57
|
-
def mouse_captured? = ::SDL2::SDL_WINDOW_MOUSE_CAPTURE & flags != 0
|
58
|
-
|
59
|
-
def mouse_focused? = ::SDL2::SDL_WINDOW_MOUSE_FOCUS & flags != 0
|
60
|
-
|
61
|
-
def opengl? = ::SDL2::SDL_WINDOW_OPENGL & flags != 0
|
62
|
-
|
63
|
-
def popup_menu? = ::SDL2::SDL_WINDOW_POPUP_MENU & flags != 0
|
64
|
-
|
65
|
-
def resizable? = ::SDL2::SDL_WINDOW_RESIZABLE & flags != 0
|
66
|
-
|
67
|
-
def skip_taskbar? = ::SDL2::SDL_WINDOW_SKIP_TASKBAR & flags != 0
|
68
|
-
|
69
|
-
def shown? = ::SDL2::SDL_WINDOW_SHOWN & flags != 0
|
70
|
-
|
71
|
-
def tooltip? = ::SDL2::SDL_WINDOW_TOOLTIP & flags != 0
|
72
|
-
|
73
|
-
def utility? = ::SDL2::SDL_WINDOW_UTILITY & flags != 0
|
74
|
-
|
75
|
-
def vulkan? = ::SDL2::SDL_WINDOW_VULKAN & flags != 0
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
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
|