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/timer.rb
CHANGED
@@ -1,31 +1,36 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
module Timer
|
3
|
-
class << self
|
4
|
-
# ms へ与えたミリ秒だけスレッドを停止します。SDL のタイマーを使用しています。
|
5
|
-
# ms が負の数だった場合 ArgumentError が発生します。
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
module RbSDL2
|
2
|
+
module Timer
|
3
|
+
class << self
|
4
|
+
# ms へ与えたミリ秒だけスレッドを停止します。SDL のタイマーを使用しています。
|
5
|
+
# ms が負の数だった場合 ArgumentError が発生します。
|
6
|
+
# このメソッドは SDL_Init の前に呼び出すことができます。
|
7
|
+
def delay(ms)
|
8
|
+
raise ArgumentError if ms < 0
|
9
|
+
::SDL.Delay(ms)
|
10
|
+
end
|
11
|
+
|
12
|
+
# performance_count の 1 秒あたりの増加量を返します。
|
13
|
+
def performance_frequency = ::SDL.GetPerformanceFrequency
|
14
|
+
|
15
|
+
# SDL が提供する高精度カウンターの値を返します。
|
16
|
+
# 返ってくる値には意味がありません。精度も SDL の実装や動作環境ごとに違います。
|
17
|
+
# このメソッドは SDL_Init の前に呼び出すことができます。
|
18
|
+
def performance_count = ::SDL.GetPerformanceCounter
|
19
|
+
|
20
|
+
# 与えられたブロックの実行時間を返します。単位は秒です。
|
21
|
+
# 実行時間の計測に SDL の高精度カウンターを使用しています。
|
22
|
+
# このメソッドは SDL_Init の前に呼び出すことができます。
|
23
|
+
def realtime
|
24
|
+
t = performance_count
|
25
|
+
yield
|
26
|
+
(performance_count - t).fdiv(performance_frequency)
|
27
|
+
end
|
28
|
+
|
29
|
+
# SDL が起動してからの経過時間をミリ秒で返します。
|
30
|
+
# このメソッドは SDL_Init の前に呼び出すことができます。
|
31
|
+
# タイマーの開始は SDL_Init を呼ぶか、このメソッドをその前に呼び出したときです。
|
32
|
+
# SDL のタイマーを使用しており、49日ほどで 0 に戻ります。
|
33
|
+
def ticks = ::SDL.GetTicks
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/rb_sdl2/version.rb
CHANGED
@@ -2,12 +2,12 @@ module RbSDL2
|
|
2
2
|
module Version
|
3
3
|
class << self
|
4
4
|
# SDL ライブラリのリビジョンを文字列で返します。
|
5
|
-
def revision = ::
|
5
|
+
def revision = ::SDL.GetRevision.read_string
|
6
6
|
|
7
7
|
# SDL ライブラリのバージョン番号を文字列で返します。形式はセマンティックバージョニングです。
|
8
8
|
def version
|
9
|
-
st = ::
|
10
|
-
::
|
9
|
+
st = ::SDL::Version.new
|
10
|
+
::SDL.GetVersion(st)
|
11
11
|
"#{st[:major]}.#{st[:minor]}.#{st[:patch]}"
|
12
12
|
end
|
13
13
|
end
|
data/lib/rb_sdl2/video.rb
CHANGED
@@ -2,24 +2,36 @@ module RbSDL2
|
|
2
2
|
module Video
|
3
3
|
class << self
|
4
4
|
def init(driver = nil)
|
5
|
-
raise RbSDL2Error if ::
|
5
|
+
raise RbSDL2Error if ::SDL.VideoInit(driver) < 0
|
6
6
|
end
|
7
7
|
|
8
8
|
def current
|
9
|
-
ptr = ::
|
9
|
+
ptr = ::SDL.GetCurrentVideoDriver
|
10
10
|
raise RbSDL2Error if ptr.null?
|
11
11
|
ptr.read_string
|
12
12
|
end
|
13
13
|
|
14
14
|
def drivers
|
15
|
-
::
|
16
|
-
ptr = ::
|
15
|
+
::SDL.GetNumVideoDrivers.times.map do |num|
|
16
|
+
ptr = ::SDL.GetVideoDriver(num)
|
17
17
|
raise RbSDL2Error if ptr.null?
|
18
18
|
ptr.read_string
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def quit = ::
|
22
|
+
def quit = ::SDL.VideoQuit
|
23
|
+
|
24
|
+
# SDL アプリケーションがスクリーンセーバーの起動を有効にしている場合に true を戻します。
|
25
|
+
# false が戻る場合はスクリーンセーバーの起動が無効です。
|
26
|
+
# SDL アプリケーションが起動している間はスクリーンセーバーが起動しません。
|
27
|
+
def screen_saver? = ::SDL.IsScreenSaverEnabled == ::SDL::TRUE
|
28
|
+
|
29
|
+
# bool に false を与えたときスクリーンセーバーの起動を無効にすることができます。
|
30
|
+
# これは SDL アプリケーション実行中のみシステムに影響を与えます。システムの設定を変更しません。
|
31
|
+
# SDL 2.0.2以降 のデフォルトは false です。
|
32
|
+
def screen_saver=(bool)
|
33
|
+
bool ? ::SDL.EnableScreenSaver : ::SDL.DisableScreenSaver
|
34
|
+
end
|
23
35
|
end
|
24
36
|
end
|
25
37
|
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module RbSDL2
|
2
|
+
class Window
|
3
|
+
module Accessor
|
4
|
+
def border_size
|
5
|
+
top_left_bottom_right = Array.new(4) { ::FFI::MemoryPointer.new(:int) }
|
6
|
+
err = ::SDL.GetWindowBordersSize(self, *top_left_bottom_right)
|
7
|
+
raise RbSDL2Error if err < 0
|
8
|
+
top_left_bottom_right.map(&:read_int)
|
9
|
+
end
|
10
|
+
|
11
|
+
def height
|
12
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
13
|
+
::SDL.GetWindowSize(self, nil, ptr)
|
14
|
+
ptr.read_int
|
15
|
+
end
|
16
|
+
alias h height
|
17
|
+
|
18
|
+
def height=(num)
|
19
|
+
self.size = [w, num]
|
20
|
+
end
|
21
|
+
alias h= height=
|
22
|
+
|
23
|
+
def icon=(surface)
|
24
|
+
::SDL.SetWindowIcon(self, surface)
|
25
|
+
end
|
26
|
+
|
27
|
+
def maximum_size
|
28
|
+
w_h = Array.new(2) { ::FFI::MemoryPointer.new(:int) }
|
29
|
+
::SDL.GetWindowMaximumSize(self, *w_h)
|
30
|
+
w_h.map(&:read_int)
|
31
|
+
end
|
32
|
+
|
33
|
+
def maximum_size=(w_h)
|
34
|
+
::SDL.SetWindowMaximumSize(self, *w_h)
|
35
|
+
end
|
36
|
+
|
37
|
+
def minimum_size
|
38
|
+
w_h = Array.new(2) { ::FFI::MemoryPointer.new(:int) }
|
39
|
+
::SDL.GetWindowMinimumSize(self, *w_h)
|
40
|
+
w_h.map(&:read_int)
|
41
|
+
end
|
42
|
+
|
43
|
+
def minimum_size=(w_h)
|
44
|
+
::SDL.SetWindowMinimumSize(self, *w_h)
|
45
|
+
end
|
46
|
+
|
47
|
+
# 戻り値が nil の場合は範囲が設定されていません。
|
48
|
+
def mouse_rect
|
49
|
+
ptr = ::SDL.GetWindowMouseRect(self)
|
50
|
+
ptr.null? ? nil : Rect.to_ary(ptr)
|
51
|
+
end
|
52
|
+
|
53
|
+
# 範囲を破棄する場合は rect には nil を与えます。
|
54
|
+
def mouse_rect=(rect)
|
55
|
+
err = ::SDL.SetWindowMouseRect(self, rect && Rect.new(*rect))
|
56
|
+
raise RbSDL2Error if err < 0
|
57
|
+
end
|
58
|
+
|
59
|
+
# ウィンドウの透明度を戻す。値は 0.0 から 1.0。値が低いほど透明になる。
|
60
|
+
def opacity
|
61
|
+
out_opacity = ::FFI::MemoryPointer.new(:float)
|
62
|
+
err = ::SDL.GetWindowOpacity(self, out_opacity)
|
63
|
+
raise RbSDL2Error if err < 0
|
64
|
+
out_opacity.read_float
|
65
|
+
end
|
66
|
+
|
67
|
+
# ウィンドウの透明度を変更する。値は 0.0 から 1.0。値が低いほど透明になる。
|
68
|
+
def opacity=(val)
|
69
|
+
err = ::SDL.SetWindowOpacity(self, val)
|
70
|
+
raise RbSDL2Error if err < 0
|
71
|
+
end
|
72
|
+
|
73
|
+
def position
|
74
|
+
x_y = Array.new(2) { ::FFI::MemoryPointer.new(:int) }
|
75
|
+
::SDL.GetWindowPosition(self, *x_y)
|
76
|
+
x_y.map(&:read_int)
|
77
|
+
end
|
78
|
+
|
79
|
+
def position=(x_y)
|
80
|
+
wx, wy = x_y
|
81
|
+
::SDL.SetWindowPosition(self,
|
82
|
+
wx || SDL_WINDOWPOS_CENTERED_MASK,
|
83
|
+
wy || SDL_WINDOWPOS_CENTERED_MASK)
|
84
|
+
end
|
85
|
+
|
86
|
+
def size
|
87
|
+
w_h = Array.new(2) { ::FFI::MemoryPointer.new(:int) }
|
88
|
+
::SDL.GetWindowSize(self, *w_h)
|
89
|
+
w_h.map(&:read_int)
|
90
|
+
end
|
91
|
+
|
92
|
+
def size=(w_h)
|
93
|
+
::SDL.SetWindowSize(self, *w_h)
|
94
|
+
end
|
95
|
+
|
96
|
+
def title = SDL.ptr_to_str(::SDL.GetWindowTitle(self))
|
97
|
+
|
98
|
+
def title=(s)
|
99
|
+
::SDL.SetWindowTitle(self, SDL.str_to_sdl(s))
|
100
|
+
end
|
101
|
+
|
102
|
+
def width
|
103
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
104
|
+
::SDL.GetWindowSize(self, ptr, nil)
|
105
|
+
ptr.read_int
|
106
|
+
end
|
107
|
+
alias w width
|
108
|
+
|
109
|
+
def width=(num)
|
110
|
+
self.size = [num, h]
|
111
|
+
end
|
112
|
+
alias w= width=
|
113
|
+
|
114
|
+
def x
|
115
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
116
|
+
::SDL.GetWindowPosition(self, ptr, nil)
|
117
|
+
ptr.read_int
|
118
|
+
end
|
119
|
+
|
120
|
+
def x=(num)
|
121
|
+
self.position = [num, y]
|
122
|
+
end
|
123
|
+
|
124
|
+
def y
|
125
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
126
|
+
::SDL.GetWindowPosition(self, nil, ptr)
|
127
|
+
ptr.read_int
|
128
|
+
end
|
129
|
+
|
130
|
+
def y=(num)
|
131
|
+
self.position = [x, num]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -3,10 +3,10 @@ module RbSDL2
|
|
3
3
|
module Display
|
4
4
|
# Brightness はウィンドウ単体ではなくウインドウの中心があるディスプレイの輝度の取得、変更を行う。
|
5
5
|
# 対象となるディスプレイの取得は Window#display メソッドを呼び出す。
|
6
|
-
def brightness = ::
|
6
|
+
def brightness = ::SDL.GetWindowBrightness(self)
|
7
7
|
|
8
8
|
def brightness=(float)
|
9
|
-
err = ::
|
9
|
+
err = ::SDL.SetWindowBrightness(self, float)
|
10
10
|
raise RbSDL2Error if err < 0
|
11
11
|
end
|
12
12
|
|
@@ -15,7 +15,7 @@ module RbSDL2
|
|
15
15
|
def display = Display.new(display_index)
|
16
16
|
|
17
17
|
def display_index
|
18
|
-
index = ::
|
18
|
+
index = ::SDL.GetWindowDisplayIndex(to_ptr)
|
19
19
|
raise RbSDL2Error if index < 0
|
20
20
|
index
|
21
21
|
end
|
@@ -23,13 +23,13 @@ module RbSDL2
|
|
23
23
|
require_relative '../display_mode'
|
24
24
|
def fullscreen_display_mode
|
25
25
|
obj = DisplayMode.new
|
26
|
-
err = ::
|
26
|
+
err = ::SDL.GetWindowDisplayMode(self, obj)
|
27
27
|
raise RbSDL2Error if err < 0
|
28
28
|
obj
|
29
29
|
end
|
30
30
|
|
31
31
|
def fullscreen_display_mode=(display_mode)
|
32
|
-
err = ::
|
32
|
+
err = ::SDL.SetWindowDisplayMode(self, display_mode)
|
33
33
|
raise RbSDL2Error if err < 0
|
34
34
|
end
|
35
35
|
|
@@ -45,7 +45,7 @@ module RbSDL2
|
|
45
45
|
|
46
46
|
def new(gamma)
|
47
47
|
ptr = ::FFI::MemoryPointer.new(:uint16, 256)
|
48
|
-
::
|
48
|
+
::SDL.CalculateGammaRamp(gamma, ptr)
|
49
49
|
super(ptr)
|
50
50
|
end
|
51
51
|
end
|
@@ -68,7 +68,7 @@ module RbSDL2
|
|
68
68
|
|
69
69
|
def gamma_ramp
|
70
70
|
rgb = Array.new(3) { GammaRamp.new }
|
71
|
-
err = ::
|
71
|
+
err = ::SDL.GetWindowGammaRamp(self, *rgb)
|
72
72
|
raise RbSDL2Error if err < 0
|
73
73
|
rgb.map(&:to_a)
|
74
74
|
end
|
@@ -77,7 +77,7 @@ module RbSDL2
|
|
77
77
|
# 画面全体に影響を与える。OSからリセットされることもある。
|
78
78
|
# アプリケーションが終了しても永続的に影響をあたえる。ユーザにとって望ましくないだろう。
|
79
79
|
def gamma_ramp=(r_g_b)
|
80
|
-
err = ::
|
80
|
+
err = ::SDL.SetWindowGammaRamp(self, *r_g_b.map { |a| GammaRamp[*a] })
|
81
81
|
raise RbSDL2Error if err < 0
|
82
82
|
end
|
83
83
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RbSDL2
|
2
|
+
class Window
|
3
|
+
module Flash
|
4
|
+
SDL_FLASH_CANCEL = 0
|
5
|
+
SDL_FLASH_BRIEFLY = 1
|
6
|
+
SDL_FLASH_UNTIL_FOCUSED = 2
|
7
|
+
|
8
|
+
def flash(bool = true)
|
9
|
+
operation = bool ? SDL_FLASH_UNTIL_FOCUSED : SDL_FLASH_CANCEL
|
10
|
+
err = ::SDL.FlashWindow(self, operation)
|
11
|
+
raise RbSDL2Error if err < 0
|
12
|
+
bool
|
13
|
+
end
|
14
|
+
|
15
|
+
def flash!
|
16
|
+
err = ::SDL.FlashWindow(self, SDL_FLASH_BRIEFLY)
|
17
|
+
raise RbSDL2Error if err < 0
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,50 +1,29 @@
|
|
1
1
|
module RbSDL2
|
2
2
|
class Window
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
@mutex.synchronize do
|
15
|
-
err = ::SDL2.SDL_SetWindowHitTest(window, func, userdata)
|
16
|
-
raise RbSDL2Error if err < 0
|
17
|
-
id = window.id
|
18
|
-
if obj
|
19
|
-
@callbacks[id] = [func, userdata]
|
20
|
-
else
|
21
|
-
@callbacks.delete(id)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
[obj, userdata]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
HIT_TEST_RESULT = Hash.new(::SDL2::SDL_HITTEST_NORMAL).merge!(
|
29
|
-
:normal => ::SDL2::SDL_HITTEST_NORMAL,
|
30
|
-
:draggable => ::SDL2::SDL_HITTEST_DRAGGABLE,
|
31
|
-
:top_left => ::SDL2::SDL_HITTEST_RESIZE_TOPLEFT,
|
32
|
-
:top => ::SDL2::SDL_HITTEST_RESIZE_TOP,
|
33
|
-
:top_right => ::SDL2::SDL_HITTEST_RESIZE_TOPRIGHT,
|
34
|
-
:resize_right => ::SDL2::SDL_HITTEST_RESIZE_RIGHT,
|
35
|
-
:bottom_right => ::SDL2::SDL_HITTEST_RESIZE_BOTTOMRIGHT,
|
36
|
-
:bottom => ::SDL2::SDL_HITTEST_RESIZE_BOTTOM,
|
37
|
-
:bottom_left => ::SDL2::SDL_HITTEST_RESIZE_BOTTOMLEFT,
|
38
|
-
:resize_left => ::SDL2::SDL_HITTEST_RESIZE_LEFT,
|
39
|
-
).freeze
|
3
|
+
SDL_HITTEST_NORMAL = 0
|
4
|
+
SDL_HITTEST_DRAGGABLE = 1
|
5
|
+
SDL_HITTEST_RESIZE_TOPLEFT = 2
|
6
|
+
SDL_HITTEST_RESIZE_TOP = 3
|
7
|
+
SDL_HITTEST_RESIZE_TOPRIGHT = 4
|
8
|
+
SDL_HITTEST_RESIZE_RIGHT = 5
|
9
|
+
SDL_HITTEST_RESIZE_BOTTOMRIGHT = 6
|
10
|
+
SDL_HITTEST_RESIZE_BOTTOM = 7
|
11
|
+
SDL_HITTEST_RESIZE_BOTTOMLEFT = 8
|
12
|
+
SDL_HITTEST_RESIZE_LEFT = 9
|
40
13
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
14
|
+
class HitTest < ::FFI::Function
|
15
|
+
# proc には引数を1つ取るコーラブル・オブジェクトを与えます。
|
16
|
+
# コーラブル・オブジェクトの引数に与えられる値はウィンドウのクリックされた位置を表す配列([x, y])です。
|
17
|
+
# コールバックは整数を戻す必要があります。何もしないのであれば SDL_HITTEST_NORMAL を戻します。
|
18
|
+
# 詳しくは SDL_HitTestResult 列挙体を参照してください。
|
19
|
+
# コールバックを呼び出したウィンドウの情報を受け取ることはできません。
|
20
|
+
# コーラブル・オブジェクトに対応するウィンドウ・オブジェクトを取り込むことで同じことができます。
|
21
|
+
def initialize(proc)
|
22
|
+
# SDL_HitTestResult SDL_HitTest(SDL_Window* win, const SDL_Point* area, void* data)
|
23
|
+
super(:int, [:pointer, :pointer, :pointer]) do |_win, area, _data|
|
45
24
|
# コールバック実行終了を OS が待つようなので、与えらえた window ポインターは有効なものとしてよいだろう。
|
46
|
-
# area には
|
47
|
-
|
25
|
+
# area には Point のアドレスが入る。Point は x, y の2つの int 型メンバーである。
|
26
|
+
proc.call(::SDL::Point.new(area).values)
|
48
27
|
end
|
49
28
|
end
|
50
29
|
end
|
data/lib/rb_sdl2/window/shape.rb
CHANGED
@@ -1,65 +1,80 @@
|
|
1
1
|
module RbSDL2
|
2
2
|
class Window
|
3
3
|
module Shape
|
4
|
+
|
5
|
+
class WindowShapeMode < ::SDL::WindowShapeMode
|
6
|
+
def alpha_test = self[:parameters][:binarizationCutoff]
|
7
|
+
|
8
|
+
def alpha_test? = [::SDL::ShapeModeBinarizeAlpha, ::SDL::ShapeModeDefault].include?(mode)
|
9
|
+
|
10
|
+
def alpha_test=(num)
|
11
|
+
self[:parameters][:binarizationCutoff] = num
|
12
|
+
end
|
13
|
+
|
14
|
+
def color_key = self[:parameters][:colorKey].values.first(3)
|
15
|
+
|
16
|
+
def color_key? = ::SDL::ShapeModeColorKey == mode
|
17
|
+
|
18
|
+
def color_key=(color)
|
19
|
+
self[:parameters][:colorKey].tap { |c| c[:r], c[:g], c[:b] = color }
|
20
|
+
end
|
21
|
+
|
22
|
+
def mode = self[:mode]
|
23
|
+
|
24
|
+
def mode=(num)
|
25
|
+
self[:mode] = num
|
26
|
+
end
|
27
|
+
|
28
|
+
def reverse_alpha_test? = ::SDL::ShapeModeReverseBinarizeAlpha == mode
|
29
|
+
end
|
30
|
+
|
4
31
|
private def shape_mode
|
5
|
-
mode =
|
6
|
-
|
7
|
-
#
|
8
|
-
if
|
32
|
+
mode = WindowShapeMode.new
|
33
|
+
err = ::SDL.GetShapedWindowMode(self, mode)
|
34
|
+
# GetShapedWindowMode は INVALID_SHAPE_ARGUMENT を返すことはない。
|
35
|
+
if err == ::SDL::NONSHAPEABLE_WINDOW
|
9
36
|
raise RbSDL2Error, "unshaped window"
|
10
|
-
elsif
|
37
|
+
elsif err == ::SDL::WINDOW_LACKS_SHAPE
|
11
38
|
raise RbSDL2Error, "window lacks shape"
|
12
|
-
elsif
|
39
|
+
elsif err < 0
|
13
40
|
raise RbSDL2Error
|
14
41
|
end
|
15
42
|
mode
|
16
43
|
end
|
17
44
|
|
18
|
-
def alpha_test
|
19
|
-
shape_mode[:parameters][:binarizationCutoff] unless shaped? && color_key?
|
20
|
-
end
|
45
|
+
def alpha_test = shaped? && alpha_test? ? shape_mode.alpha_test : nil
|
21
46
|
|
22
|
-
def alpha_test?
|
23
|
-
shaped? && [::SDL2::ShapeModeBinarizeAlpha,
|
24
|
-
::SDL2::ShapeModeDefault].include?(shape_mode[:mode])
|
25
|
-
end
|
47
|
+
def alpha_test? = shaped? && shape_mode.alpha_test?
|
26
48
|
|
27
|
-
def color_key
|
28
|
-
shape_mode[:parameters][:colorKey].values if shaped? && color_key?
|
29
|
-
end
|
49
|
+
def color_key = shaped? && color_key? ? shape_mode.color_key : nil
|
30
50
|
|
31
|
-
def color_key?
|
32
|
-
shaped? && ::SDL2::ShapeModeColorKey == shape_mode[:mode]
|
33
|
-
end
|
51
|
+
def color_key? = shaped? && shape_mode.color_key?
|
34
52
|
|
35
|
-
def reverse_alpha_test?
|
36
|
-
shaped? && ::SDL2::ShapeModeReverseBinarizeAlpha == shape_mode[:mode]
|
37
|
-
end
|
53
|
+
def reverse_alpha_test? = shaped? && shape_mode.reverse_alpha_test?
|
38
54
|
|
39
55
|
# サーフェスにアルファ―チャンネルが含まれていない場合、color_key オプションを与える必要がある。
|
40
56
|
# 形状マスクの設定を行う。ウィンドウの描画域は透明なピクセルで埋められている。
|
41
57
|
# このメソッド呼び出しの成功後にウィンドウのサーフェスへ描画を行う必要がある。
|
42
58
|
# 描画方法はウィンドウのサーフェスまたはレンダラーのどちらを使用してもよい。
|
43
59
|
def shape_set(surface, alpha_test: nil, color_key: nil)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
60
|
+
shape = WindowShapeMode.new
|
61
|
+
if color_key
|
62
|
+
shape.mode = ::SDL::ShapeModeColorKey
|
63
|
+
shape.color_key = color_key
|
64
|
+
elsif alpha_test&.>= 0
|
65
|
+
shape.mode = ::SDL::ShapeModeBinarizeAlpha
|
66
|
+
shape.alpha_test = alpha_test
|
67
|
+
elsif alpha_test&.< 0
|
68
|
+
shape.mode = ::SDL::ShapeModeReverseBinarizeAlpha
|
69
|
+
shape.alpha_test = alpha_test.abs
|
70
|
+
else
|
71
|
+
shape.mode = ::SDL::ShapeModeDefault
|
57
72
|
end
|
58
|
-
err = ::
|
59
|
-
#
|
60
|
-
if err == ::
|
73
|
+
err = ::SDL.SetWindowShape(self, surface, shape)
|
74
|
+
# SetWindowShape は WINDOW_LACKS_SHAPE を返すことはない。
|
75
|
+
if err == ::SDL::NONSHAPEABLE_WINDOW
|
61
76
|
raise RbSDL2Error, "unshaped window"
|
62
|
-
elsif err == ::
|
77
|
+
elsif err == ::SDL::INVALID_SHAPE_ARGUMENT
|
63
78
|
raise RbSDL2Error,
|
64
79
|
"Invalid shape argument. \
|
65
80
|
The size of the window and the size of the surface do not match. \
|
@@ -70,7 +85,7 @@ Or the color key is not specified in the surface without alpha channel."
|
|
70
85
|
surface
|
71
86
|
end
|
72
87
|
|
73
|
-
def shaped? = ::
|
88
|
+
def shaped? = ::SDL.IsShapedWindow(self) == ::SDL::TRUE
|
74
89
|
end
|
75
90
|
end
|
76
91
|
end
|