SDLRuby 0.1.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.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +31 -0
  5. data/Rakefile +12 -0
  6. data/lib/SDLRuby/audio.rb +65 -0
  7. data/lib/SDLRuby/cursor.rb +46 -0
  8. data/lib/SDLRuby/display.rb +79 -0
  9. data/lib/SDLRuby/event/accessor.rb +127 -0
  10. data/lib/SDLRuby/event/type.rb +75 -0
  11. data/lib/SDLRuby/event.rb +80 -0
  12. data/lib/SDLRuby/font.rb +227 -0
  13. data/lib/SDLRuby/hint.rb +36 -0
  14. data/lib/SDLRuby/image/image.rb +23 -0
  15. data/lib/SDLRuby/image/include/SDL_image.h.rb +61 -0
  16. data/lib/SDLRuby/image.rb +69 -0
  17. data/lib/SDLRuby/keyboard.rb +58 -0
  18. data/lib/SDLRuby/mixer/channel.rb +43 -0
  19. data/lib/SDLRuby/mixer/chunk.rb +49 -0
  20. data/lib/SDLRuby/mixer/controller.rb +44 -0
  21. data/lib/SDLRuby/mixer/include/SDL_mixer.h.rb +95 -0
  22. data/lib/SDLRuby/mixer/sdl_mixer.rb +60 -0
  23. data/lib/SDLRuby/mixer.rb +87 -0
  24. data/lib/SDLRuby/mouse.rb +52 -0
  25. data/lib/SDLRuby/music.rb +158 -0
  26. data/lib/SDLRuby/palette.rb +49 -0
  27. data/lib/SDLRuby/pixel_formatter.rb +67 -0
  28. data/lib/SDLRuby/rect.rb +11 -0
  29. data/lib/SDLRuby/renderer/accessor.rb +70 -0
  30. data/lib/SDLRuby/renderer/drawer.rb +107 -0
  31. data/lib/SDLRuby/renderer/renderer_info.rb +27 -0
  32. data/lib/SDLRuby/renderer.rb +101 -0
  33. data/lib/SDLRuby/rw_ops/rw_object.rb +128 -0
  34. data/lib/SDLRuby/rw_ops.rb +216 -0
  35. data/lib/SDLRuby/sdl/include/SDL.h.rb +33 -0
  36. data/lib/SDLRuby/sdl/include/SDL_audio.h.rb +49 -0
  37. data/lib/SDLRuby/sdl/include/SDL_blendmode.h.rb +6 -0
  38. data/lib/SDLRuby/sdl/include/SDL_clipboard.h.rb +10 -0
  39. data/lib/SDLRuby/sdl/include/SDL_config.h.rb +13 -0
  40. data/lib/SDLRuby/sdl/include/SDL_cpuinfo.h.rb +27 -0
  41. data/lib/SDLRuby/sdl/include/SDL_endian.h.rb +3 -0
  42. data/lib/SDLRuby/sdl/include/SDL_error.h.rb +9 -0
  43. data/lib/SDLRuby/sdl/include/SDL_events.h.rb +32 -0
  44. data/lib/SDLRuby/sdl/include/SDL_filesystem.h.rb +6 -0
  45. data/lib/SDLRuby/sdl/include/SDL_gamecontroller.h.rb +66 -0
  46. data/lib/SDLRuby/sdl/include/SDL_gesture.h.rb +12 -0
  47. data/lib/SDLRuby/sdl/include/SDL_guid.h.rb +7 -0
  48. data/lib/SDLRuby/sdl/include/SDL_hints.h.rb +14 -0
  49. data/lib/SDLRuby/sdl/include/SDL_joystick.h.rb +69 -0
  50. data/lib/SDLRuby/sdl/include/SDL_keyboard.h.rb +26 -0
  51. data/lib/SDLRuby/sdl/include/SDL_keycode.h.rb +7 -0
  52. data/lib/SDLRuby/sdl/include/SDL_locale.h.rb +6 -0
  53. data/lib/SDLRuby/sdl/include/SDL_main.h.rb +3 -0
  54. data/lib/SDLRuby/sdl/include/SDL_messagebox.h.rb +10 -0
  55. data/lib/SDLRuby/sdl/include/SDL_misc.h.rb +5 -0
  56. data/lib/SDLRuby/sdl/include/SDL_mouse.h.rb +26 -0
  57. data/lib/SDLRuby/sdl/include/SDL_pixels.h.rb +25 -0
  58. data/lib/SDLRuby/sdl/include/SDL_platform.h.rb +3 -0
  59. data/lib/SDLRuby/sdl/include/SDL_power.h.rb +6 -0
  60. data/lib/SDLRuby/sdl/include/SDL_rect.h.rb +17 -0
  61. data/lib/SDLRuby/sdl/include/SDL_render.h.rb +94 -0
  62. data/lib/SDLRuby/sdl/include/SDL_revision.h.rb +2 -0
  63. data/lib/SDLRuby/sdl/include/SDL_rwops.h.rb +34 -0
  64. data/lib/SDLRuby/sdl/include/SDL_scancode.h.rb +5 -0
  65. data/lib/SDLRuby/sdl/include/SDL_sensor.h.rb +25 -0
  66. data/lib/SDLRuby/sdl/include/SDL_shape.h.rb +13 -0
  67. data/lib/SDLRuby/sdl/include/SDL_stdinc.h.rb +24 -0
  68. data/lib/SDLRuby/sdl/include/SDL_surface.h.rb +37 -0
  69. data/lib/SDLRuby/sdl/include/SDL_system.h.rb +6 -0
  70. data/lib/SDLRuby/sdl/include/SDL_syswm.h.rb +16 -0
  71. data/lib/SDLRuby/sdl/include/SDL_timer.h.rb +13 -0
  72. data/lib/SDLRuby/sdl/include/SDL_touch.h.rb +15 -0
  73. data/lib/SDLRuby/sdl/include/SDL_types.h.rb +3 -0
  74. data/lib/SDLRuby/sdl/include/SDL_version.h.rb +6 -0
  75. data/lib/SDLRuby/sdl/include/SDL_video.h.rb +117 -0
  76. data/lib/SDLRuby/sdl/sdl.rb +55 -0
  77. data/lib/SDLRuby/sdl/sdl_audio.rb +75 -0
  78. data/lib/SDLRuby/sdl/sdl_blendmode.rb +10 -0
  79. data/lib/SDLRuby/sdl/sdl_error.rb +5 -0
  80. data/lib/SDLRuby/sdl/sdl_events.rb +470 -0
  81. data/lib/SDLRuby/sdl/sdl_hints.rb +9 -0
  82. data/lib/SDLRuby/sdl/sdl_keyboard.rb +12 -0
  83. data/lib/SDLRuby/sdl/sdl_locale.rb +8 -0
  84. data/lib/SDLRuby/sdl/sdl_message_box.rb +7 -0
  85. data/lib/SDLRuby/sdl/sdl_mouse.rb +32 -0
  86. data/lib/SDLRuby/sdl/sdl_palette.rb +12 -0
  87. data/lib/SDLRuby/sdl/sdl_pixels.rb +138 -0
  88. data/lib/SDLRuby/sdl/sdl_rect.rb +11 -0
  89. data/lib/SDLRuby/sdl/sdl_render.rb +35 -0
  90. data/lib/SDLRuby/sdl/sdl_rw_ops.rb +29 -0
  91. data/lib/SDLRuby/sdl/sdl_scancode.rb +255 -0
  92. data/lib/SDLRuby/sdl/sdl_surface.rb +27 -0
  93. data/lib/SDLRuby/sdl/sdl_version.rb +5 -0
  94. data/lib/SDLRuby/sdl/sdl_video.rb +104 -0
  95. data/lib/SDLRuby/sdl.rb +192 -0
  96. data/lib/SDLRuby/sdl_error.rb +8 -0
  97. data/lib/SDLRuby/surface/pixel_format.rb +51 -0
  98. data/lib/SDLRuby/surface/surface_renderer.rb +26 -0
  99. data/lib/SDLRuby/surface.rb +179 -0
  100. data/lib/SDLRuby/text_input.rb +38 -0
  101. data/lib/SDLRuby/texture.rb +93 -0
  102. data/lib/SDLRuby/ttf/include/SDL_ttf.h.rb +54 -0
  103. data/lib/SDLRuby/ttf/ttf.rb +41 -0
  104. data/lib/SDLRuby/ttf.rb +54 -0
  105. data/lib/SDLRuby/version.rb +5 -0
  106. data/lib/SDLRuby/window/accessor.rb +125 -0
  107. data/lib/SDLRuby/window/controller.rb +53 -0
  108. data/lib/SDLRuby/window/display_info.rb +48 -0
  109. data/lib/SDLRuby/window/flag.rb +42 -0
  110. data/lib/SDLRuby/window/hit_tester.rb +61 -0
  111. data/lib/SDLRuby/window/input.rb +68 -0
  112. data/lib/SDLRuby/window/shaper.rb +68 -0
  113. data/lib/SDLRuby/window/surfacer.rb +37 -0
  114. data/lib/SDLRuby/window/window_renderer.rb +31 -0
  115. data/lib/SDLRuby/window.rb +90 -0
  116. data/lib/SDLRuby.rb +16 -0
  117. data/sig/SDLRuby/event.rbs +104 -0
  118. data/sig/SDLRuby/pixel_formmater.rbs +24 -0
  119. data/sig/SDLRuby/rect.rbs +5 -0
  120. data/sig/SDLRuby/sdl.rbs +606 -0
  121. data/sig/SDLRuby.rbs +4 -0
  122. metadata +168 -0
@@ -0,0 +1,48 @@
1
+ module SDLRuby
2
+ class Window
3
+ module DisplayInfo
4
+ include SDL
5
+
6
+ def display_brightness = SDL.SDL_GetWindowBrightness(self)
7
+
8
+ def display_icc_profile
9
+ size = SDL.tmp_value("size_t")
10
+ ptr = SDL.SDL_GetWindowICCProfile(self, size)
11
+ raise SDLError if ptr.null?
12
+
13
+ ptr.free = SDL_FREE
14
+ ptr.to_str(size.value)
15
+ end
16
+
17
+ def display_index
18
+ num = SDL.SDL_GetWindowDisplayIndex(self)
19
+ raise SDLError if num < 0
20
+
21
+ num
22
+ end
23
+
24
+ def display_gamma_ramp
25
+ rgb = Array.new(3) { Fiddle::Pointer.malloc(2 * 256, Fiddle::RUBY_FREE) }
26
+ err = SDL.SDL_GetWindowGammaRamp(self, *rgb)
27
+ raise SDLError if err < 0
28
+
29
+ rgb.map { |ptr| ptr.to_str.unpack("S*") }
30
+ end
31
+
32
+ def display_orientation = Display.orientation(display_index)
33
+
34
+ def fullscreen_display_mode
35
+ mode = DisplayMode.new
36
+ err = SDL.SDL_GetWindowDisplayMode(self, mode)
37
+ raise SDLError if err < 0
38
+
39
+ mode
40
+ end
41
+
42
+ def fullscreen_display_mode=(mode)
43
+ err = SDL.SDL_SetWindowDisplayMode(self, mode)
44
+ raise SDLError if err < 0
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ module SDLRuby
2
+ class Window
3
+ module Flag
4
+ class << self
5
+ def to_i(allow_highdpi: nil, always_on_top: nil, borderless: nil,
6
+ foreign: nil, fullscreen: nil, fullscreen_desktop: nil,
7
+ hidden: nil, input_focus: nil, input_grabbed: nil,
8
+ keyboard_grabbed: nil, maximized: nil, metal: nil,
9
+ minimized: nil, mouse_capture: nil, mouse_focus: nil,
10
+ mouse_grabbed: nil, opengl: nil, popup_menu: nil,
11
+ resizable: nil, shown: nil, skip_taskbar: nil, tooltip: nil,
12
+ utility: nil, vulkan: nil, **)
13
+ 0 |
14
+ (allow_highdpi ? SDL_WINDOW_ALLOW_HIGHDPI : 0) |
15
+ (always_on_top ? SDL_WINDOW_ALWAYS_ON_TOP : 0) |
16
+ (borderless ? SDL_WINDOW_BORDERLESS : 0) |
17
+ (foreign ? SDL_WINDOW_FOREIGN : 0) |
18
+ (fullscreen ? SDL_WINDOW_FULLSCREEN : 0) |
19
+ (fullscreen_desktop ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0) |
20
+ (hidden ? SDL_WINDOW_HIDDEN : 0) |
21
+ (input_focus ? SDL_WINDOW_INPUT_FOCUS : 0) |
22
+ (input_grabbed ? SDL_WINDOW_INPUT_GRABBED : 0) |
23
+ (keyboard_grabbed ? SDL_WINDOW_KEYBOARD_GRABBED : 0) |
24
+ (maximized ? SDL_WINDOW_MAXIMIZED : 0) |
25
+ (metal ? SDL_WINDOW_METAL : 0) |
26
+ (minimized ? SDL_WINDOW_MINIMIZED : 0) |
27
+ (mouse_capture ? SDL_WINDOW_MOUSE_CAPTURE : 0) |
28
+ (mouse_focus ? SDL_WINDOW_MOUSE_FOCUS : 0) |
29
+ (mouse_grabbed ? SDL_WINDOW_MOUSE_GRABBED : 0) |
30
+ (opengl ? SDL_WINDOW_OPENGL : 0) |
31
+ (popup_menu ? SDL_WINDOW_POPUP_MENU : 0) |
32
+ (resizable ? SDL_WINDOW_RESIZABLE : 0) |
33
+ (shown ? SDL_WINDOW_SHOWN : 0) |
34
+ (skip_taskbar ? SDL_WINDOW_SKIP_TASKBAR : 0) |
35
+ (tooltip ? SDL_WINDOW_TOOLTIP : 0) |
36
+ (utility ? SDL_WINDOW_UTILITY : 0) |
37
+ (vulkan ? SDL_WINDOW_VULKAN : 0)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,61 @@
1
+ module SDLRuby
2
+ class Window
3
+ module HitTester
4
+
5
+ module Remover
6
+ def destroy
7
+ Window.set_hit_test_proc(self, nil)
8
+ super
9
+ end
10
+ end
11
+
12
+ class << self
13
+ private def included(klass) = klass.prepend(Remover)
14
+ end
15
+
16
+ # SDL_HitTestResult SDL_HitTest(SDL_Window* win, const SDL_Point* area, void* data)
17
+ #
18
+ class HitTestClosure < Fiddle::Closure
19
+ include Fiddle, SDL
20
+
21
+ def initialize(obj)
22
+ super(TYPE_INT, [TYPE_VOIDP, TYPE_VOIDP, TYPE_VOIDP])
23
+ @obj = obj
24
+ end
25
+
26
+ def call(_win, area, _data) = @obj.call(*SDL_Point.new(area)).to_i
27
+ end
28
+
29
+ @hit_tests = {}
30
+
31
+ class << self
32
+ def get_hit_test_proc(window)
33
+ id = window.to_int
34
+ @hit_tests[id].last
35
+ end
36
+
37
+ def set_hit_test_proc(window, obj)
38
+ func = obj ? HitTestClosure.new(obj) : nil
39
+ err = SDL.SDL_SetWindowHitTest(window, func, nil)
40
+ raise SDLError if err < 0
41
+
42
+ id = window.to_int
43
+
44
+ if obj
45
+ @hit_tests[id] = [func, obj]
46
+ else
47
+ @hit_tests.delete(id)
48
+ end
49
+ end
50
+ end
51
+
52
+ def hit_test_proc = HitTester.get_hit_test_proc(self)
53
+
54
+ # objはcallメソッドを持つオブジェクトであること。
55
+ #
56
+ def hit_test_proc=(obj)
57
+ HitTester.set_hit_test_proc(self, obj)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,68 @@
1
+ module SDLRuby
2
+ class Window
3
+ class << self
4
+ # 該当するウィンドウがない場合はnilを戻す。
5
+ #
6
+ def grabbed
7
+ ptr = SDL.SDL_GetGrabbedWindow
8
+ return if ptr.null?
9
+
10
+ new(ptr)
11
+ end
12
+
13
+ # 該当するウィンドウがない場合はnilを戻す。
14
+ #
15
+ def keyboard_focused
16
+ ptr = SDL.SDL_GetKeyboardFocus
17
+ return if ptr.null?
18
+
19
+ new(ptr)
20
+ end
21
+
22
+ # 該当するウィンドウがない場合はnilを戻す。
23
+ #
24
+ def mouse_focused
25
+ ptr = SDL.SDL_GetMouseFocus
26
+ return if ptr.null?
27
+
28
+ new(ptr)
29
+ end
30
+ end
31
+
32
+ module Input
33
+ def grab = SDL.SDL_GetWindowGrab(self) != 0
34
+
35
+ def grab=(b)
36
+ SDL.SDL_SetWindowGrab(sef, b ? 1 : 0)
37
+ end
38
+
39
+ def keyboard_grabbed? = SDL.SDL_GetWindowKeyboardGrab(self) != 0
40
+
41
+ def keyboard_grab=(b)
42
+ SDL.SDL_SetWindowKeyboardGrab(self, b ? 1 : 0)
43
+ end
44
+
45
+ def mouse_clip
46
+ ptr = SDL.SDL_GetWindowMouseRect(self)
47
+ return if ptr.null?
48
+
49
+ SDL_Rect.new(ptr).to_a
50
+ end
51
+
52
+ def mouse_clip=(rect)
53
+ err = SDL.SDL_SetWindowMouseRect(self, Rect[*rect])
54
+ raise SDLError if err < 0
55
+ end
56
+
57
+ def mouse_pos=(xy)
58
+ SDL.SDL_WarpMouseInWindow(self, *xy)
59
+ end
60
+
61
+ def mouse_grabbed? = SDL.SDL_GetWindowMouseGrab(self) != 0
62
+
63
+ def mouse_grab=(b)
64
+ SDL.SDL_SetWindowMouseGrab(self, b ? 1 : 0)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,68 @@
1
+ module SDLRuby
2
+ class Window
3
+ module Shaper
4
+ def shape(shape, cutoff = nil)
5
+ st = SDL_WindowShapeMode.malloc(Fiddle::RUBY_FREE)
6
+
7
+ case cutoff
8
+ when nil
9
+ st.mode = ShapeModeDefault
10
+ when Integer
11
+ st.mode = cutoff >= 0 ? ShapeModeBinarizeAlpha : ShapeModeReverseBinarizeAlpha
12
+ st.parameters.binarizationCutoff = cutoff.abs
13
+ when Array
14
+ st.mode = ShapeModeColorKey
15
+ st.parameters.colorKey.tap { |c| c.r, c.g, c.b, c.a = *cutoff }
16
+ else
17
+ raise ArgumentError
18
+ end
19
+
20
+ case SDL.SDL_SetWindowShape(self, shape, st)
21
+ when 0
22
+ return
23
+ when SDL_NONSHAPEABLE_WINDOW
24
+ raise SDLError, "SDL_NONSHAPEABLE_WINDOW"
25
+ when SDL_INVALID_SHAPE_ARGUMENT
26
+ if shape.size != size
27
+ raise SDLError, "the size of window and the size of surface do not match."
28
+ elsif !shape.alpha?
29
+ raise SDLError, "the color key is not specified in the surface without alpha channel."
30
+ else
31
+ raise SDLError, "SDL_INVALID_SHAPE_ARGUMENT"
32
+ end
33
+ else
34
+ raise SDLError
35
+ end
36
+ end
37
+
38
+ def cutoff
39
+ st = SDL_WindowShapeMode.malloc(Fiddle::RUBY_FREE)
40
+
41
+ case SDL.SDL_GetShapedWindowMode(self, st)
42
+ when 0
43
+ cutoff = case st.mode
44
+ when ShapeModeDefault
45
+ nil
46
+ when ShapeModeBinarizeAlpha
47
+ st.parameters.binarizationCutoff
48
+ when ShapeModeReverseBinarizeAlpha
49
+ -st.parameters.binarizationCutoff
50
+ when ShapeModeColorKey
51
+ st.parameters.colorKey.to_a[0..2]
52
+ else
53
+ nil
54
+ end
55
+ return cutoff
56
+ when SDL_NONSHAPEABLE_WINDOW
57
+ raise SDLError, "SDL_NONSHAPEABLE_WINDOW"
58
+ when SDL_WINDOW_LACKS_SHAPE
59
+ raise SDLError, "SDL_WINDOW_LACKS_SHAPE"
60
+ else
61
+ raise SDLError
62
+ end
63
+ end
64
+
65
+ def shaped? = SDL.SDL_IsShapedWindow(self) == 1
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,37 @@
1
+ module SDLRuby
2
+ class Window
3
+ module Surfacer
4
+ include SDL
5
+
6
+ def destroy_surface
7
+ err = SDL.SDL_DestroyWindowSurface(self)
8
+ raise SDLError if err < 0
9
+ end
10
+
11
+ def surface
12
+ ptr = SDL.SDL_GetWindowSurface(self)
13
+ raise SDLError if ptr.null?
14
+
15
+ # ウィンドウからのサーフェスにはSDL_DONTFREEフラグが設定されている。
16
+ # このためにSDL_FreeSurfaceではリファレンスカウンターを減じる事ができない。
17
+ # これはRubyのGC管理では問題になる(メモリーリークする)。
18
+ # そのためSDL_DONTFREEフラグを解除する!
19
+ #
20
+ st = SDL_Surface.new(ptr)
21
+ st.flags &= ~SDL_DONTFREE
22
+
23
+ Surface.new(ptr, add_ref: true)
24
+ end
25
+
26
+ # ウィンドウのサーフェスがvalidかどうか確認していない。
27
+ # リサイズなどで壊れていてもtrueを戻す。
28
+ #
29
+ def surface? = SDL.SDL_HasWindowSurface(self) == 1
30
+
31
+ def update_surface
32
+ err = SDL.SDL_UpdateWindowSurface(self)
33
+ raise SDLError if err < 0
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ module SDLRuby
2
+ class Window
3
+ module WindowRenderer
4
+ def init_renderer(name = nil, flags = nil,
5
+ accelerated: nil, software: nil, vsync: nil)
6
+
7
+ idx = if name
8
+ i = Renderer.drivers.index(name)
9
+ raise ArgumentError unless i
10
+ i
11
+ else
12
+ -1
13
+ end
14
+ num = flags || 0 |
15
+ (accelerated ? SDL_RENDERER_ACCELERATED : 0) |
16
+ (software ? SDL_RENDERER_SOFTWARE : 0) |
17
+ (vsync ? SDL_RENDERER_PRESENTVSYNC : 0)
18
+ ptr = SDL.SDL_CreateRenderer(self, idx, num)
19
+ raise SDLError if ptr.null?
20
+ end
21
+
22
+ private def renderer
23
+ ptr = SDL.SDL_GetRenderer(self)
24
+ raise SDLError if ptr.null?
25
+ ptr
26
+ end
27
+
28
+ def destroy_renderer = SDL.SDL_DestroyRenderer(SDL.SDL_GetRenderer(self))
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,90 @@
1
+ require_relative 'display'
2
+ require_relative 'pixel_formatter'
3
+ require_relative 'window/accessor'
4
+ require_relative 'window/controller'
5
+ require_relative 'window/display_info'
6
+ require_relative 'window/flag'
7
+ require_relative 'window/hit_tester'
8
+ require_relative 'window/input'
9
+ require_relative 'window/shaper'
10
+ require_relative 'window/surfacer'
11
+ require_relative 'window/window_renderer'
12
+
13
+ module SDLRuby
14
+ class Window
15
+ include Accessor, Controller, DisplayInfo, HitTester, Input,
16
+ PixelFormatter, Renderer, SDL, Shaper, Surfacer, WindowRenderer
17
+
18
+ class << self
19
+ include SDL
20
+
21
+ # 該当するウィンドウがない場合はnilを戻す。
22
+ #
23
+ def [](obj)
24
+ id = obj.to_int
25
+ ptr = SDL.SDL_GetWindowFromID(id)
26
+ return nil if ptr.null?
27
+
28
+ new(ptr)
29
+ end
30
+
31
+ def _from(ptr)
32
+ ptr = SDL.SDL_CreateWindowFrom(ptr)
33
+ raise SDLError if ptr.null?
34
+
35
+ new(ptr)
36
+ end
37
+
38
+ def create(title, x = nil, y = nil, w = 640, h = 480, flags = nil,
39
+ shaped: nil, **opts)
40
+
41
+ _title = title.encode("UTF-8")
42
+ _x = x ? x : SDL_WINDOWPOS_UNDEFINED
43
+ _y = y ? y : SDL_WINDOWPOS_UNDEFINED
44
+ _flags = flags || Flag.to_i(**opts)
45
+ ptr = if shaped
46
+ SDL.SDL_CreateShapedWindow(_title, _x, _y, w, h, _flags)
47
+ else
48
+ SDL.SDL_CreateWindow(_title, _x, _y, w, h, _flags)
49
+ end
50
+ raise SDLError if ptr.null?
51
+
52
+ new(ptr)
53
+ end
54
+ end
55
+
56
+ attr_reader :id
57
+
58
+ def initialize(ptr)
59
+ id = SDL.SDL_GetWindowID(ptr)
60
+ raise SDLError if id == 0
61
+
62
+ @id = id
63
+ end
64
+
65
+ def ==(other) = other.respond_to?(:to_ptr) && to_ptr == other.to_ptr
66
+
67
+ def destroy = SDL.SDL_DestroyWindow(self)
68
+
69
+ def flags = SDL.SDL_GetWindowFlags(self)
70
+
71
+ def flash(op)
72
+ _op = op ? SDL_FLASH_UNTIL_FOCUSED : SDL_FLASH_CANCEL
73
+ err = SDL.SDL_FlashWindow(self, _op)
74
+ raise SDLError if err < 0
75
+ end
76
+
77
+ def focus! = SDL.SDL_RaiseWindow(self)
78
+
79
+ def format = SDL.SDL_GetWindowPixelFormat(self)
80
+
81
+ alias to_int id
82
+ alias to_i id
83
+
84
+ def to_ptr
85
+ ptr = SDL.SDL_GetWindowFromID(@id)
86
+ raise SDLError if ptr.null?
87
+ ptr
88
+ end
89
+ end
90
+ end
data/lib/SDLRuby.rb ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require_relative 'SDLRuby/version'
5
+ require_relative 'SDLRuby/sdl'
6
+
7
+ # Extended libraries
8
+ #
9
+ require_relative 'SDLRuby/font'
10
+ require_relative 'SDLRuby/image'
11
+ require_relative 'SDLRuby/mixer'
12
+ require_relative 'SDLRuby/music'
13
+
14
+ module SDLRuby
15
+ class Error < StandardError; end
16
+ end
@@ -0,0 +1,104 @@
1
+ module SDLRuby
2
+ type event_type_symbols = (
3
+ :adevice | :button | :caxis | :cbutton | :cdevice | :common | :csensor |
4
+ :ctouchpad | :dgesture | :display | :drop | :edit | :editExt | :jaxis |
5
+ :jball | :jbattery | :jbutton | :jdevice | :jhat | :key | :mgesture |
6
+ :motion | :quit | :sensor | :syswm | :text | :tfinger | :user |
7
+ :wheel | :window
8
+ )
9
+
10
+ class Event
11
+ @st: untyped
12
+
13
+ def self.clear: -> void
14
+
15
+ def self.count: -> Integer
16
+
17
+ def self.disable: (untyped) -> void
18
+
19
+ def self.enable: (untyped) -> void
20
+
21
+ def self.flash: -> void
22
+
23
+ def self.get: -> Event
24
+
25
+ def self.poll: (Event) -> Event
26
+
27
+ def self.pump: -> nil
28
+
29
+ alias self.update self.pump
30
+
31
+ def self.quit?: -> bool
32
+
33
+ def initialize: -> void
34
+
35
+ attr_reader entity: any
36
+
37
+ def to_ptr: -> untyped
38
+
39
+ def to_sym: -> (event_type_symbols)
40
+
41
+ def update: -> self
42
+
43
+ module Accessor
44
+ include SDL
45
+
46
+ self.@modules: Hash[Symbol, Module]
47
+ self.@_ptr: untyped
48
+
49
+ def self.[]: (event_type_symbols) -> Module
50
+
51
+ private
52
+
53
+ def char_ary_to_str: (untyped) -> String
54
+ def char_ptr_to_str: (untyped) -> String
55
+
56
+ public
57
+
58
+ def capture?: -> bool
59
+ def pressed?: -> bool
60
+ def file: -> String
61
+ def text: -> String
62
+ def keysym: -> untyped
63
+ def msg: -> untyped
64
+ def data1: -> untyped
65
+ def data2: -> untyped
66
+ end
67
+
68
+ module Type
69
+ QUIT_EVENT: Range[Integer]
70
+ DISPLAY_EVENT: Range[Integer]
71
+ WINDOW_EVENT: Range[Integer]
72
+ SYSWM_EVENT: Range[Integer]
73
+ KEY_EVENT: Range[Integer]
74
+ EDIT_EVENT: Range[Integer]
75
+ TEXT_EVENT: Range[Integer]
76
+ EDIT_EXT_EVENT: Range[Integer]
77
+ MOTION_EVENT: Range[Integer]
78
+ BUTTON_EVENT: Range[Integer]
79
+ WHEEL_EVENT: Range[Integer]
80
+ JAXIS_EVENT: Range[Integer]
81
+ JBALL_EVENT: Range[Integer]
82
+ JHAT_EVENT: Range[Integer]
83
+ JBUTTON_EVENT: Range[Integer]
84
+ JDEVICE_EVENT: Range[Integer]
85
+ JBATTERY_EVENT: Range[Integer]
86
+ CAXIS_EVENT: Range[Integer]
87
+ CBUTTON_EVENT: Range[Integer]
88
+ CDEVICE_EVENT: Range[Integer]
89
+ CTOUCHPAD_EVENT: Range[Integer]
90
+ CSENSOR_EVENT: Range[Integer]
91
+ TFINGER_EVENT: Range[Integer]
92
+ DGESTURE_EVENT: Range[Integer]
93
+ MGESTURE_EVENT: Range[Integer]
94
+ DROP_EVENT: Range[Integer]
95
+ ADEVICE_EVENT: Range[Integer]
96
+ SENSOR_EVENT: Range[Integer]
97
+ USER_EVENT: Range[Integer]
98
+
99
+ include SDL
100
+
101
+ def self.to_sym: (Integer) -> (event_type_symbols)
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,24 @@
1
+ module SDLRuby
2
+ module PixelFormatter
3
+ INDEXED_PIXELFORMATS: [untyped, untyped, untyped, untyped, untyped]
4
+ ALPHA_PIXELFORMATS: [untyped, untyped, untyped, untyped, untyped, untyped, untyped, untyped, untyped, untyped, untyped, untyped, untyped]
5
+ include SDL
6
+
7
+ def self.alpha?: (untyped x) -> bool
8
+ def self.bits_per_pixel: (untyped x) -> Integer?
9
+ def self.bytes_per_pixel: (untyped x) -> Integer
10
+ def self.format_name: (untyped x) -> String
11
+ def self.fourcc?: (untyped x) -> String?
12
+ def self.indexed_color?: (untyped x) -> bool
13
+ def self.rgb_color?: (untyped x) -> bool
14
+ def alpha?: -> bool
15
+ def bits_per_pixel: -> Integer?
16
+ alias depth bits_per_pixel
17
+ def bytes_per_pixel: -> Integer
18
+ def format_name: -> String
19
+ alias pixel_format_name format_name
20
+ def fourcc?: -> String?
21
+ def indexed_color?: -> bool
22
+ def rgb_color?: -> bool
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module SDLRuby
2
+ class Rect
3
+ def self.[]: (*any) -> self
4
+ end
5
+ end