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
@@ -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,18 +2,26 @@
|
|
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
9
|
spec.summary = "Multimedia library with SDL."
|
9
10
|
spec.description = "RbSDL2 treats the functions and pointers provided by SDL as Ruby objects."
|
11
|
+
spec.homepage = "https://github.com/shinokaro/rb_sdl2/blob/main/README.md"
|
10
12
|
spec.license = "Zlib"
|
11
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 3.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")
|
14
|
+
|
15
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/shinokaro/rb_sdl2/issues'
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/shinokaro/rb_sdl2/blob/main/CHANGELOG.md"
|
17
|
+
spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/rb_sdl2"
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/shinokaro/rb_sdl2"
|
12
20
|
|
13
21
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
14
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
15
23
|
end
|
16
24
|
|
17
|
-
spec.add_dependency "ffi", "
|
18
|
-
spec.add_dependency "sdl2-bindings", "
|
25
|
+
spec.add_dependency "ffi", "~> 1.15"
|
26
|
+
spec.add_dependency "sdl2-bindings", "~> 0.1.1"
|
19
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,20 +97,23 @@ 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
|
-
homepage:
|
108
|
+
homepage: https://github.com/shinokaro/rb_sdl2/blob/main/README.md
|
113
109
|
licenses:
|
114
110
|
- Zlib
|
115
|
-
metadata:
|
111
|
+
metadata:
|
112
|
+
bug_tracker_uri: https://github.com/shinokaro/rb_sdl2/issues
|
113
|
+
changelog_uri: https://github.com/shinokaro/rb_sdl2/blob/main/CHANGELOG.md
|
114
|
+
documentation_uri: https://www.rubydoc.info/gems/rb_sdl2
|
115
|
+
homepage_uri: https://github.com/shinokaro/rb_sdl2/blob/main/README.md
|
116
|
+
source_code_uri: https://github.com/shinokaro/rb_sdl2
|
116
117
|
post_install_message:
|
117
118
|
rdoc_options: []
|
118
119
|
require_paths:
|
@@ -121,14 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
122
|
requirements:
|
122
123
|
- - ">="
|
123
124
|
- !ruby/object:Gem::Version
|
124
|
-
version: 3.
|
125
|
+
version: 3.1.0
|
125
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
127
|
requirements:
|
127
128
|
- - ">="
|
128
129
|
- !ruby/object:Gem::Version
|
129
130
|
version: '0'
|
130
131
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.3.3
|
132
133
|
signing_key:
|
133
134
|
specification_version: 4
|
134
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
|
data/lib/rb_sdl2/audio.rb
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
class Audio
|
3
|
-
IS_CAPTURE = -> (capture) { capture ? 1 : 0 }
|
4
|
-
CAPTURE = -> (capture) { capture ? true : false }
|
5
|
-
# AudioStream, AudioCallback の実装は行っていない。
|
6
|
-
# AudioCallback は Ruby 側からまともに使う方法がない。
|
7
|
-
# AudioStream はリアルタイムなリサンプラー、リフォーマッターとして使えるがこれが本当に必要か判らない。
|
8
|
-
class << self
|
9
|
-
def current
|
10
|
-
ptr = ::SDL2.SDL_GetCurrentAudioDriver
|
11
|
-
raise RbSDL2Error, "Audio subsystem has not been initialized" if ptr.null?
|
12
|
-
ptr.read_string
|
13
|
-
end
|
14
|
-
|
15
|
-
require_relative 'audio/audio_device'
|
16
|
-
|
17
|
-
def devices = AudioDevice.devices
|
18
|
-
|
19
|
-
def drivers
|
20
|
-
::SDL2.SDL_GetNumAudioDrivers.times.map do |num|
|
21
|
-
ptr = ::SDL2.SDL_GetAudioDriver(num)
|
22
|
-
raise RbSDL2Error if ptr.null?
|
23
|
-
ptr.read_string
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def init(driver)
|
28
|
-
raise RbSDL2Error if ::SDL2.SDL_AudioInit(driver) < 0
|
29
|
-
end
|
30
|
-
|
31
|
-
require_relative 'audio/audio_buffer'
|
32
|
-
|
33
|
-
def load(...) = AudioBuffer.load(...)
|
34
|
-
|
35
|
-
require_relative 'audio/audio_allowed_changes'
|
36
|
-
require_relative 'audio/audio_format'
|
37
|
-
require_relative 'audio/audio_spec'
|
38
|
-
|
39
|
-
def new(device = nil, capture = false, allowed_changes: {}, channels: 2, format: {},
|
40
|
-
frequency: 48_000, samples: 0)
|
41
|
-
want = AudioSpec.new(channels: channels, format: AudioFormat.to_num(**format),
|
42
|
-
frequency: frequency, samples: samples)
|
43
|
-
have = AudioSpec.new
|
44
|
-
id = ::SDL2.SDL_OpenAudioDevice(device&.to_s, IS_CAPTURE.(capture), want, have,
|
45
|
-
AudioAllowedChanges.to_num(**allowed_changes))
|
46
|
-
raise RbSDL2Error if id == 0
|
47
|
-
super(id, capture, have)
|
48
|
-
end
|
49
|
-
alias open new
|
50
|
-
|
51
|
-
def quit = ::SDL2.SDL_AudioQuit
|
52
|
-
end
|
53
|
-
|
54
|
-
def initialize(id, capture, spec)
|
55
|
-
@capture = CAPTURE.(capture)
|
56
|
-
@closed = false
|
57
|
-
@id = id
|
58
|
-
@spec = spec
|
59
|
-
end
|
60
|
-
|
61
|
-
def capture? = @capture
|
62
|
-
|
63
|
-
def clear
|
64
|
-
raise IOError if closed?
|
65
|
-
::SDL2.SDL_ClearQueuedAudio(self)
|
66
|
-
end
|
67
|
-
|
68
|
-
def close
|
69
|
-
::SDL2.SDL_CloseAudioDevice(id) unless @closed
|
70
|
-
@closed = true
|
71
|
-
nil
|
72
|
-
end
|
73
|
-
|
74
|
-
def closed? = @closed
|
75
|
-
|
76
|
-
attr_reader :id
|
77
|
-
alias to_int id
|
78
|
-
|
79
|
-
def pause
|
80
|
-
raise IOError if closed?
|
81
|
-
::SDL2.SDL_PauseAudioDevice(id, 1)
|
82
|
-
end
|
83
|
-
|
84
|
-
def play
|
85
|
-
raise IOError if closed?
|
86
|
-
::SDL2.SDL_PauseAudioDevice(id, 0)
|
87
|
-
end
|
88
|
-
|
89
|
-
def read(len)
|
90
|
-
raise IOError if closed?
|
91
|
-
ptr = ::FFI::MemoryPointer.new(len)
|
92
|
-
size = ::SDL2.SDL_DequeueAudio(id, ptr, len)
|
93
|
-
ptr.read_bytes(size)
|
94
|
-
end
|
95
|
-
|
96
|
-
def size
|
97
|
-
raise IOError if closed?
|
98
|
-
::SDL2.SDL_GetQueuedAudioSize(id)
|
99
|
-
end
|
100
|
-
alias length size
|
101
|
-
|
102
|
-
attr_reader :spec
|
103
|
-
|
104
|
-
require 'forwardable'
|
105
|
-
extend Forwardable
|
106
|
-
def_delegators :spec, *%i(channels chunk_size format frequency samples)
|
107
|
-
|
108
|
-
require_relative 'audio/audio_format'
|
109
|
-
include AudioFormat
|
110
|
-
|
111
|
-
def status
|
112
|
-
raise IOError if closed?
|
113
|
-
::SDL2.SDL_GetAudioDeviceStatus(id)
|
114
|
-
end
|
115
|
-
|
116
|
-
module AudioStatus
|
117
|
-
def paused? = ::SDL2::SDL_AUDIO_PAUSED == status
|
118
|
-
|
119
|
-
def playing? = ::SDL2::SDL_AUDIO_PLAYING == status
|
120
|
-
|
121
|
-
def stopped? = ::SDL2::SDL_AUDIO_STOPPED == status
|
122
|
-
end
|
123
|
-
include AudioStatus
|
124
|
-
|
125
|
-
def write(data)
|
126
|
-
raise IOError if closed?
|
127
|
-
err = ::SDL2.SDL_QueueAudio(id, data, data.size)
|
128
|
-
raise RbSDL2Error if err < 0
|
129
|
-
data.size
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module RbSDL2
|
2
|
-
module Cursor
|
3
|
-
require_relative 'cursor_class'
|
4
|
-
|
5
|
-
class ColorCursor < CursorClass
|
6
|
-
class << self
|
7
|
-
require_relative 'cursor_pointer'
|
8
|
-
|
9
|
-
def new(surface, hot_x = 0, hot_y = 0)
|
10
|
-
# SDL_CreateColorCursor は与えられた surface をコピーする。
|
11
|
-
# 呼び出し後に引数に与えた surface オブジェクトは安全に開放できる。
|
12
|
-
ptr = CursorPointer.new(::SDL2.SDL_CreateColorCursor(surface, hot_x, hot_y))
|
13
|
-
raise RbSDL2Error if ptr.null?
|
14
|
-
super(ptr)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|