sdl2_ffi 0.0.2
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 +7 -0
- data/.gitignore +20 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +33 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +7 -0
- data/bin/coderay +16 -0
- data/bin/guard +16 -0
- data/bin/pry +16 -0
- data/bin/rake +16 -0
- data/bin/thor +16 -0
- data/lib/sdl2/assert.rb +7 -0
- data/lib/sdl2/audio.rb +139 -0
- data/lib/sdl2/clipboard.rb +27 -0
- data/lib/sdl2/color.rb +12 -0
- data/lib/sdl2/cpuinfo.rb +18 -0
- data/lib/sdl2/display/mode.rb +53 -0
- data/lib/sdl2/display/modes.rb +36 -0
- data/lib/sdl2/display.rb +74 -0
- data/lib/sdl2/error.rb +9 -0
- data/lib/sdl2/events.rb +358 -0
- data/lib/sdl2/gamecontroller.rb +62 -0
- data/lib/sdl2/gem_version.rb +4 -0
- data/lib/sdl2/gesture.rb +15 -0
- data/lib/sdl2/haptic.rb +159 -0
- data/lib/sdl2/hints.rb +47 -0
- data/lib/sdl2/init.rb +54 -0
- data/lib/sdl2/joystick.rb +58 -0
- data/lib/sdl2/keyboard.rb +34 -0
- data/lib/sdl2/keycode.rb +294 -0
- data/lib/sdl2/log.rb +70 -0
- data/lib/sdl2/mouse.rb +54 -0
- data/lib/sdl2/palette.rb +15 -0
- data/lib/sdl2/pixel_format.rb +28 -0
- data/lib/sdl2/pixels.rb +35 -0
- data/lib/sdl2/point.rb +7 -0
- data/lib/sdl2/power.rb +9 -0
- data/lib/sdl2/rect.rb +38 -0
- data/lib/sdl2/render.rb +77 -0
- data/lib/sdl2/renderer.rb +34 -0
- data/lib/sdl2/renderer_info.rb +13 -0
- data/lib/sdl2/rwops.rb +127 -0
- data/lib/sdl2/scancode.rb +275 -0
- data/lib/sdl2/sdl_module.rb +8 -0
- data/lib/sdl2/surface.rb +83 -0
- data/lib/sdl2/syswm/info.rb +49 -0
- data/lib/sdl2/syswm/msg.rb +46 -0
- data/lib/sdl2/syswm.rb +20 -0
- data/lib/sdl2/texture.rb +9 -0
- data/lib/sdl2/timer.rb +17 -0
- data/lib/sdl2/touch.rb +24 -0
- data/lib/sdl2/version.rb +30 -0
- data/lib/sdl2/video.rb +154 -0
- data/lib/sdl2/window.rb +259 -0
- data/lib/sdl2.rb +99 -0
- data/lib/sdl2_ffi.rb +6 -0
- data/sdl2_ffi.gemspec +31 -0
- data/test/test_helper.rb +2 -0
- data/test/unit/sdl2/test_assert.rb +10 -0
- data/test/unit/sdl2/test_audio.rb +9 -0
- data/test/unit/sdl2/test_clipboard.rb +13 -0
- data/test/unit/sdl2/test_cpuinfo.rb +11 -0
- data/test/unit/sdl2/test_error.rb +20 -0
- data/test/unit/sdl2/test_events.rb +31 -0
- data/test/unit/sdl2/test_haptic.rb +10 -0
- data/test/unit/sdl2/test_hints.rb +50 -0
- data/test/unit/sdl2/test_init.rb +29 -0
- data/test/unit/sdl2/test_keyboard.rb +9 -0
- data/test/unit/sdl2/test_log.rb +80 -0
- data/test/unit/sdl2/test_pixels.rb +24 -0
- data/test/unit/sdl2/test_power.rb +11 -0
- data/test/unit/sdl2/test_rect.rb +19 -0
- data/test/unit/sdl2/test_render.rb +58 -0
- data/test/unit/sdl2/test_surface.rb +45 -0
- data/test/unit/sdl2/test_syswm.rb +11 -0
- data/test/unit/sdl2/test_timer.rb +9 -0
- data/test/unit/sdl2/test_version.rb +16 -0
- data/test/unit/sdl2/test_video.rb +170 -0
- data/test/unit/sdl2/test_window.rb +158 -0
- data/test/unit/test_sdl2.rb +16 -0
- metadata +280 -0
data/lib/sdl2/render.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
require 'sdl2/video'
|
3
|
+
require 'sdl2/renderer'
|
4
|
+
require 'sdl2/texture'
|
5
|
+
require 'sdl2/point'
|
6
|
+
|
7
|
+
module SDL2
|
8
|
+
# lines 64~73
|
9
|
+
enum :renderer_flags, [
|
10
|
+
:software, Renderer::SOFTWARE,
|
11
|
+
:accelerated, Renderer::ACCELERATED,
|
12
|
+
:present_vsync, Renderer::PRESENTVSYNC,
|
13
|
+
:target_texture, Renderer::TARGETTEXTURE
|
14
|
+
]
|
15
|
+
# lines 91~96
|
16
|
+
enum :texture_access, [:static, :streaming, :target]
|
17
|
+
# lines 101~106
|
18
|
+
enum :texture_modulate, [:none, 0x00000000, :color, 0x00000001, :alpha, 0x00000002]
|
19
|
+
# lines 111~116
|
20
|
+
enum :renderer_flip, [:none, 0x00000000, :horizontal, 0x00000001, :vertical, 0x00000002]
|
21
|
+
|
22
|
+
typedef :int, :render_driver_index
|
23
|
+
api :SDL_GetNumRenderDrivers, [], :int
|
24
|
+
api :SDL_GetRenderDriverInfo, [:render_driver_index, RendererInfo.by_ref], :int
|
25
|
+
api :SDL_CreateWindowAndRenderer, [:int, :int, :window_flags, Window.by_ref, Renderer.by_ref], :int
|
26
|
+
api :SDL_CreateRenderer, [Window.by_ref, :render_driver_index, :renderer_flags], Renderer.auto_ptr
|
27
|
+
api :SDL_CreateSoftwareRenderer, [Surface.by_ref], Renderer.auto_ptr
|
28
|
+
api :SDL_GetRenderer, [Window.by_ref], Renderer.auto_ptr
|
29
|
+
api :SDL_GetRendererInfo, [Renderer.by_ref, RendererInfo.by_ref], :int
|
30
|
+
api :SDL_GetRendererOutputSize, [Renderer.by_ref, IntStruct.by_ref, IntStruct.by_ref], :int
|
31
|
+
api :SDL_CreateTexture, [Renderer.by_ref, :pixel_format, :texture_access, :int, :int], Texture.auto_ptr
|
32
|
+
api :SDL_CreateTextureFromSurface, [Renderer.by_ref, Surface.by_ref], Texture.auto_ptr
|
33
|
+
api :SDL_QueryTexture, [Texture.by_ref, UInt32Struct.by_ref, IntStruct.by_ref, IntStruct.by_ref, IntStruct.by_ref], :int
|
34
|
+
api :SDL_SetTextureColorMod, [Texture.by_ref, :uint8, :uint8, :uint8], :int
|
35
|
+
api :SDL_GetTextureColorMod, [Texture.by_ref, UInt8Struct.by_ref, UInt8Struct.by_ref, UInt8Struct.by_ref], :int
|
36
|
+
api :SDL_SetTextureAlphaMod, [Texture.by_ref, :uint8], :int
|
37
|
+
api :SDL_GetTextureAlphaMod, [Texture.by_ref, UInt8Struct.by_ref], :int
|
38
|
+
api :SDL_SetTextureBlendMode, [Texture.by_ref, :blend_mode], :int
|
39
|
+
api :SDL_GetTextureBlendMode, [Texture.by_ref, BlendModeStruct.by_ref], :int
|
40
|
+
api :SDL_UpdateTexture, [Texture.by_ref, Rect.by_ref, :pointer, :int], :int
|
41
|
+
api :SDL_LockTexture, [Texture.by_ref, Rect.by_ref, :pointer, IntStruct.by_ref], :int
|
42
|
+
api :SDL_UnlockTexture, [Texture.by_ref], :void
|
43
|
+
api :SDL_RenderTargetSupported, [Renderer.by_ref], :bool
|
44
|
+
api :SDL_GetRenderTarget, [Renderer.by_ref], Texture.by_ref
|
45
|
+
api :SDL_SetRenderTarget, [Renderer.by_ref, Texture.by_ref], :int
|
46
|
+
api :SDL_RenderSetLogicalSize, [Renderer.by_ref, :int, :int],:int
|
47
|
+
api :SDL_RenderGetLogicalSize, [Renderer.by_ref, IntStruct.by_ref, IntStruct.by_ref], :void
|
48
|
+
api :SDL_RenderSetViewport, [Renderer.by_ref, Rect.by_ref], :int
|
49
|
+
api :SDL_RenderGetViewport, [Renderer.by_ref, Rect.by_ref], :int
|
50
|
+
api :SDL_RenderSetClipRect, [Renderer.by_ref, Rect.by_ref], :int
|
51
|
+
api :SDL_RenderGetClipRect, [Renderer.by_ref, Rect.by_ref], :int
|
52
|
+
api :SDL_RenderSetScale, [Renderer.by_ref, :float, :float], :int
|
53
|
+
api :SDL_RenderGetScale, [Renderer.by_ref, FloatStruct.by_ref, FloatStruct.by_ref], :int
|
54
|
+
api :SDL_SetRenderDrawColor, [Renderer.by_ref, :uint8, :uint8, :uint8, :uint8], :int
|
55
|
+
api :SDL_GetRenderDrawColor, [Renderer.by_ref, UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref], :int
|
56
|
+
api :SDL_SetRenderDrawBlendMode, [Renderer.by_ref, :blend_mode], :int
|
57
|
+
api :SDL_GetRenderDrawBlendMode, [Renderer.by_ref, BlendModeStruct.by_ref], :int
|
58
|
+
api :SDL_RenderClear, [Renderer.by_ref], :int
|
59
|
+
api :SDL_RenderDrawPoint, [Renderer.by_ref, :int, :int], :int
|
60
|
+
api :SDL_RenderDrawPoints, [Renderer.by_ref, Point.by_ref, :count], :int
|
61
|
+
api :SDL_RenderDrawLine, [Renderer.by_ref, :int, :int, :int, :int], :int
|
62
|
+
api :SDL_RenderDrawLines, [Renderer.by_ref, Point.by_ref, :count], :int
|
63
|
+
api :SDL_RenderDrawRect, [Renderer.by_ref, Rect.by_ref], :int
|
64
|
+
api :SDL_RenderDrawRects, [Renderer.by_ref, Rect.by_ref, :count], :int
|
65
|
+
api :SDL_RenderFillRect, [Renderer.by_ref, Rect.by_ref], :int
|
66
|
+
api :SDL_RenderFillRects, [Renderer.by_ref, Rect.by_ref, :count], :int
|
67
|
+
api :SDL_RenderCopy, [Renderer.by_ref, Texture.by_ref, Rect.by_ref, Rect.by_ref], :int
|
68
|
+
api :SDL_RenderCopyEx, [Renderer.by_ref, Texture.by_ref, Rect.by_ref, Rect.by_ref, :double, Point.by_ref, :renderer_flip], :int
|
69
|
+
api :SDL_RenderReadPixels, [Renderer.by_ref, Rect.by_ref, :pixel_format, :pointer, :int], :int #TODO: Review linking.
|
70
|
+
api :SDL_RenderPresent, [Renderer.by_ref], :void
|
71
|
+
api :SDL_DestroyTexture, [Texture.by_ref], :void
|
72
|
+
api :SDL_DestroyRenderer, [Renderer.by_ref], :void
|
73
|
+
api :SDL_GL_BindTexture, [Texture.by_ref, FloatStruct.by_ref, FloatStruct.by_ref], :int
|
74
|
+
api :SDL_GL_UnbindTexture, [Texture.by_ref], :int
|
75
|
+
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
require 'sdl2/renderer_info'
|
3
|
+
module SDL2
|
4
|
+
|
5
|
+
class Renderer < Struct
|
6
|
+
layout :blank, :uint8 # Ignore Structure?
|
7
|
+
SOFTWARE = 0x00000001
|
8
|
+
ACCELERATED = 0x00000002
|
9
|
+
PRESENTVSYNC = 0x00000004
|
10
|
+
TARGETTEXTURE = 0x00000008
|
11
|
+
|
12
|
+
def self.create(window, driver_idx, flags)
|
13
|
+
create_render(window, driver_idx, flags)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get(window)
|
17
|
+
get_renderer(window)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create_software(surface)
|
21
|
+
create_software_renderer(surface)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.release(pointer)
|
25
|
+
destroy_renderer(pointer)
|
26
|
+
end
|
27
|
+
|
28
|
+
def clear
|
29
|
+
render_clear(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/sdl2/rwops.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
|
3
|
+
module SDL2
|
4
|
+
#Forward Declaration for callbacks
|
5
|
+
class RWops < Struct
|
6
|
+
end
|
7
|
+
callback :rwops_size, [RWops.by_ref], :int64
|
8
|
+
callback :rwops_seek, [RWops.by_ref, :int64, :int], :int64
|
9
|
+
callback :rwops_read, [RWops.by_ref, :pointer, :size_t, :size_t], :size_t
|
10
|
+
callback :rwops_write, [RWops.by_ref, :pointer, :size_t, :size_t], :size_t
|
11
|
+
callback :rwops_close, [RWops.by_ref], :int
|
12
|
+
|
13
|
+
class RWops
|
14
|
+
class AndroidIO < Struct
|
15
|
+
layout :fileNameRef, :pointer,
|
16
|
+
:inputSteramRef, :pointer,
|
17
|
+
:readableByteChannelRef, :pointer,
|
18
|
+
:readMethod, :pointer,
|
19
|
+
:assetFileDescriptorRef, :pointer,
|
20
|
+
:position, :long,
|
21
|
+
:size, :long,
|
22
|
+
:offset, :long,
|
23
|
+
:fd, :int
|
24
|
+
end
|
25
|
+
|
26
|
+
class WindowsIO < Struct
|
27
|
+
class Buffer < Struct
|
28
|
+
layout :data, :pointer,
|
29
|
+
:size, :size_t,
|
30
|
+
:left, :size_t
|
31
|
+
end
|
32
|
+
layout :append, :bool,
|
33
|
+
:h, :pointer,
|
34
|
+
:buffer, Buffer
|
35
|
+
end
|
36
|
+
|
37
|
+
class STDIO < Struct
|
38
|
+
layout :autoclose, :bool,
|
39
|
+
:fp, :pointer
|
40
|
+
end
|
41
|
+
|
42
|
+
class Mem <Struct
|
43
|
+
layout :base, UInt8Struct.by_ref,
|
44
|
+
:here, UInt8Struct.by_ref,
|
45
|
+
:stop, UInt8Struct.by_ref
|
46
|
+
end
|
47
|
+
|
48
|
+
class Unkown < Struct
|
49
|
+
layout :data1, :pointer,
|
50
|
+
:data2, :pointer
|
51
|
+
end
|
52
|
+
|
53
|
+
class Hidden < FFI::Union
|
54
|
+
layout :androidio, AndroidIO,
|
55
|
+
:windowsio, WindowsIO,
|
56
|
+
:stdio, STDIO,
|
57
|
+
:mem, Mem,
|
58
|
+
:unkown, Unkown
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
layout :size, :rwops_size,
|
63
|
+
:seek, :rwops_seek,
|
64
|
+
:read, :rwops_read,
|
65
|
+
:write, :rwops_write,
|
66
|
+
:close, :rwops_close,
|
67
|
+
:type, :uint32,
|
68
|
+
:hidden, Hidden
|
69
|
+
|
70
|
+
def self.release(pointer)
|
71
|
+
SDL2.free_rw(pointer)
|
72
|
+
end
|
73
|
+
|
74
|
+
# CONSTANTS
|
75
|
+
SEEK_SET = 0
|
76
|
+
SEEK_CUR = 1
|
77
|
+
SEEK_END = 2
|
78
|
+
|
79
|
+
# Read/Write Macros re-implemented: Lines #184~189
|
80
|
+
def size
|
81
|
+
self[:size].call
|
82
|
+
end
|
83
|
+
|
84
|
+
def seek(offset, whence)
|
85
|
+
self[:seek].call(self, offset, whence)
|
86
|
+
end
|
87
|
+
|
88
|
+
def tell
|
89
|
+
self[:seek].call(self, 0, SEEK_CUR)
|
90
|
+
end
|
91
|
+
|
92
|
+
def read(pointer, size, n)
|
93
|
+
self[:read].call(self, pointer, size, n)
|
94
|
+
end
|
95
|
+
|
96
|
+
def write(pointer, size, n)
|
97
|
+
self[:write].call(self, pointer, size, n)
|
98
|
+
end
|
99
|
+
|
100
|
+
def close
|
101
|
+
self[:close].call(self)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
api :SDL_RWFromFile, [:string, :string], RWops.auto_ptr
|
107
|
+
api :SDL_RWFromFP, [:pointer, :bool], RWops.auto_ptr
|
108
|
+
api :SDL_RWFromMem, [:pointer, :count], RWops.auto_ptr
|
109
|
+
api :SDL_RWFromConstMem, [:pointer, :count], RWops.auto_ptr
|
110
|
+
api :SDL_AllocRW, [], RWops.auto_ptr
|
111
|
+
api :SDL_FreeRW, [RWops.by_ref], :void
|
112
|
+
api :SDL_ReadU8, [RWops.by_ref], :uint8
|
113
|
+
api :SDL_ReadLE16, [RWops.by_ref], :uint16
|
114
|
+
api :SDL_ReadBE16, [RWops.by_ref], :uint16
|
115
|
+
api :SDL_ReadLE32, [RWops.by_ref], :uint32
|
116
|
+
api :SDL_ReadBE32, [RWops.by_ref], :uint32
|
117
|
+
api :SDL_ReadLE64, [RWops.by_ref], :uint64
|
118
|
+
api :SDL_ReadBE64, [RWops.by_ref], :uint64
|
119
|
+
|
120
|
+
api :SDL_WriteU8, [RWops.by_ref, :uint8], :size_t
|
121
|
+
api :SDL_WriteLE16, [RWops.by_ref, :uint16], :size_t
|
122
|
+
api :SDL_WriteBE16, [RWops.by_ref, :uint16], :size_t
|
123
|
+
api :SDL_WriteLE32, [RWops.by_ref, :uint32], :size_t
|
124
|
+
api :SDL_WriteBE32, [RWops.by_ref, :uint32], :size_t
|
125
|
+
api :SDL_WriteLE64, [RWops.by_ref, :uint64], :size_t
|
126
|
+
api :SDL_WriteBE64, [RWops.by_ref, :uint64], :size_t
|
127
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
require 'yinum'
|
3
|
+
|
4
|
+
module SDL2
|
5
|
+
NUM_SCANCODES = 512
|
6
|
+
|
7
|
+
Scancode = Enum.new(:SCANCODE, {
|
8
|
+
:A => 4,
|
9
|
+
:B => 5,
|
10
|
+
:C => 6,
|
11
|
+
:D => 7,
|
12
|
+
:E => 8,
|
13
|
+
:F => 9,
|
14
|
+
:G => 10,
|
15
|
+
:H => 11,
|
16
|
+
:I => 12,
|
17
|
+
:J => 13,
|
18
|
+
:K => 14,
|
19
|
+
:L => 15,
|
20
|
+
:M => 16,
|
21
|
+
:N => 17,
|
22
|
+
:O => 18,
|
23
|
+
:P => 19,
|
24
|
+
:Q => 20,
|
25
|
+
:R => 21,
|
26
|
+
:S => 22,
|
27
|
+
:T => 23,
|
28
|
+
:U => 24,
|
29
|
+
:V => 25,
|
30
|
+
:W => 26,
|
31
|
+
:X => 27,
|
32
|
+
:Y => 28,
|
33
|
+
:Z => 29,
|
34
|
+
|
35
|
+
:'1' => 30,
|
36
|
+
:'2' => 31,
|
37
|
+
:'3' => 32,
|
38
|
+
:'4' => 33,
|
39
|
+
:'5' => 34,
|
40
|
+
:'6' => 35,
|
41
|
+
:'7' => 36,
|
42
|
+
:'8' => 37,
|
43
|
+
:'9' => 38,
|
44
|
+
:'0' => 39,
|
45
|
+
|
46
|
+
:RETURN => 40,
|
47
|
+
:ESCAPE => 41,
|
48
|
+
:BACKSPACE => 42,
|
49
|
+
:TAB => 43,
|
50
|
+
:SPACE => 44,
|
51
|
+
|
52
|
+
:MINUS => 45,
|
53
|
+
:EQUALS => 46,
|
54
|
+
:LEFTBRACKET => 47,
|
55
|
+
:RIGHTBRACKET => 48,
|
56
|
+
:BACKSLASH => 49,
|
57
|
+
:NONUSHASH => 50,
|
58
|
+
:SEMICOLON => 51,
|
59
|
+
:APOSTROPHE => 52,
|
60
|
+
:GRAVE => 53,
|
61
|
+
:COMMA => 54,
|
62
|
+
:PERIOD => 55,
|
63
|
+
:SLASH => 56,
|
64
|
+
|
65
|
+
:CAPSLOCK => 57,
|
66
|
+
|
67
|
+
:F1 => 58,
|
68
|
+
:F2 => 59,
|
69
|
+
:F3 => 60,
|
70
|
+
:F4 => 61,
|
71
|
+
:F5 => 62,
|
72
|
+
:F6 => 63,
|
73
|
+
:F7 => 64,
|
74
|
+
:F8 => 65,
|
75
|
+
:F9 => 66,
|
76
|
+
:F10 => 67,
|
77
|
+
:F11 => 68,
|
78
|
+
:F12 => 69,
|
79
|
+
|
80
|
+
:PRINTSCREEN => 70,
|
81
|
+
:SCROLLLOCK => 71,
|
82
|
+
:PAUSE => 72,
|
83
|
+
:INSERT => 73,
|
84
|
+
|
85
|
+
:HOME => 74,
|
86
|
+
:PAGEUP => 75,
|
87
|
+
:DELETE => 76,
|
88
|
+
:END => 77,
|
89
|
+
:PAGEDOWN => 78,
|
90
|
+
:RIGHT => 79,
|
91
|
+
:LEFT => 80,
|
92
|
+
:DOWN => 81,
|
93
|
+
:UP => 82,
|
94
|
+
|
95
|
+
:NUMLOCKCLEAR => 83,
|
96
|
+
|
97
|
+
:KP_DIVIDE => 84,
|
98
|
+
:KP_MULTIPLY => 85,
|
99
|
+
:KP_MINUS => 86,
|
100
|
+
:KP_PLUS => 87,
|
101
|
+
:KP_ENTER => 88,
|
102
|
+
:KP_1 => 89,
|
103
|
+
:KP_2 => 90,
|
104
|
+
:KP_3 => 91,
|
105
|
+
:KP_4 => 92,
|
106
|
+
:KP_5 => 93,
|
107
|
+
:KP_6 => 94,
|
108
|
+
:KP_7 => 95,
|
109
|
+
:KP_8 => 96,
|
110
|
+
:KP_9 => 97,
|
111
|
+
:KP_0 => 98,
|
112
|
+
:KP_PERIOD => 99,
|
113
|
+
|
114
|
+
:NONUSBACKSLASH => 100,
|
115
|
+
|
116
|
+
:APPLICATION => 101,
|
117
|
+
:POWER => 102,
|
118
|
+
|
119
|
+
:KP_EQUALS => 103,
|
120
|
+
:F13 => 104,
|
121
|
+
:F14 => 105,
|
122
|
+
:F15 => 106,
|
123
|
+
:F16 => 107,
|
124
|
+
:F17 => 108,
|
125
|
+
:F18 => 109,
|
126
|
+
:F19 => 110,
|
127
|
+
:F20 => 111,
|
128
|
+
:F21 => 112,
|
129
|
+
:F22 => 113,
|
130
|
+
:F23 => 114,
|
131
|
+
:F24 => 115,
|
132
|
+
:EXECUTE => 116,
|
133
|
+
:HELP => 117,
|
134
|
+
:MENU => 118,
|
135
|
+
:SELECT => 119,
|
136
|
+
:STOP => 120,
|
137
|
+
:AGAIN => 121,
|
138
|
+
:UNDO => 122,
|
139
|
+
:CUT => 123,
|
140
|
+
:COPY => 124,
|
141
|
+
:PASTE => 125,
|
142
|
+
:FIND => 126,
|
143
|
+
:MUTE => 127,
|
144
|
+
:VOLUMEUP => 128,
|
145
|
+
:VOLUMEDOWN => 129,
|
146
|
+
|
147
|
+
:KP_COMMA => 133,
|
148
|
+
:KP_EQUALSAS400 => 134,
|
149
|
+
|
150
|
+
:INTERNATIONAL1 => 135,
|
151
|
+
|
152
|
+
:INTERNATIONAL2 => 136,
|
153
|
+
:INTERNATIONAL3 => 137,
|
154
|
+
:INTERNATIONAL4 => 138,
|
155
|
+
:INTERNATIONAL5 => 139,
|
156
|
+
:INTERNATIONAL6 => 140,
|
157
|
+
:INTERNATIONAL7 => 141,
|
158
|
+
:INTERNATIONAL8 => 142,
|
159
|
+
:INTERNATIONAL9 => 143,
|
160
|
+
:LANG1 => 144,
|
161
|
+
:LANG2 => 145,
|
162
|
+
:LANG3 => 146,
|
163
|
+
:LANG4 => 147,
|
164
|
+
:LANG5 => 148,
|
165
|
+
:LANG6 => 149,
|
166
|
+
:LANG7 => 150,
|
167
|
+
:LANG8 => 151,
|
168
|
+
:LANG9 => 152,
|
169
|
+
|
170
|
+
:ALTERASE => 153,
|
171
|
+
:SYSREQ => 154,
|
172
|
+
:CANCEL => 155,
|
173
|
+
:CLEAR => 156,
|
174
|
+
:PRIOR => 157,
|
175
|
+
:RETURN2 => 158,
|
176
|
+
:SEPARATOR => 159,
|
177
|
+
:OUT => 160,
|
178
|
+
:OPER => 161,
|
179
|
+
:CLEARAGAIN => 162,
|
180
|
+
:CRSEL => 163,
|
181
|
+
:EXSEL => 164,
|
182
|
+
|
183
|
+
:KP_00 => 176,
|
184
|
+
:KP_000 => 177,
|
185
|
+
:THOUSANDSSEPARATOR => 178,
|
186
|
+
:DECIMALSEPARATOR => 179,
|
187
|
+
:CURRENCYUNIT => 180,
|
188
|
+
:CURRENCYSUBUNIT => 181,
|
189
|
+
:KP_LEFTPAREN => 182,
|
190
|
+
:KP_RIGHTPAREN => 183,
|
191
|
+
:KP_LEFTBRACE => 184,
|
192
|
+
:KP_RIGHTBRACE => 185,
|
193
|
+
:KP_TAB => 186,
|
194
|
+
:KP_BACKSPACE => 187,
|
195
|
+
:KP_A => 188,
|
196
|
+
:KP_B => 189,
|
197
|
+
:KP_C => 190,
|
198
|
+
:KP_D => 191,
|
199
|
+
:KP_E => 192,
|
200
|
+
:KP_F => 193,
|
201
|
+
:KP_XOR => 194,
|
202
|
+
:KP_POWER => 195,
|
203
|
+
:KP_PERCENT => 196,
|
204
|
+
:KP_LESS => 197,
|
205
|
+
:KP_GREATER => 198,
|
206
|
+
:KP_AMPERSAND => 199,
|
207
|
+
:KP_DBLAMPERSAND => 200,
|
208
|
+
:KP_VERTICALBAR => 201,
|
209
|
+
:KP_DBLVERTICALBAR => 202,
|
210
|
+
:KP_COLON => 203,
|
211
|
+
:KP_HASH => 204,
|
212
|
+
:KP_SPACE => 205,
|
213
|
+
:KP_AT => 206,
|
214
|
+
:KP_EXCLAM => 207,
|
215
|
+
:KP_MEMSTORE => 208,
|
216
|
+
:KP_MEMRECALL => 209,
|
217
|
+
:KP_MEMCLEAR => 210,
|
218
|
+
:KP_MEMADD => 211,
|
219
|
+
:KP_MEMSUBTRACT => 212,
|
220
|
+
:KP_MEMMULTIPLY => 213,
|
221
|
+
:KP_MEMDIVIDE => 214,
|
222
|
+
:KP_PLUSMINUS => 215,
|
223
|
+
:KP_CLEAR => 216,
|
224
|
+
:KP_CLEARENTRY => 217,
|
225
|
+
:KP_BINARY => 218,
|
226
|
+
:KP_OCTAL => 219,
|
227
|
+
:KP_DECIMAL => 220,
|
228
|
+
:KP_HEXADECIMAL => 221,
|
229
|
+
|
230
|
+
:LCTRL => 224,
|
231
|
+
:LSHIFT => 225,
|
232
|
+
:LALT => 226,
|
233
|
+
:LGUI => 227,
|
234
|
+
:RCTRL => 228,
|
235
|
+
:RSHIFT => 229,
|
236
|
+
:RALT => 230,
|
237
|
+
:RGUI => 231,
|
238
|
+
|
239
|
+
:MODE => 257,
|
240
|
+
|
241
|
+
:AUDIONEXT => 258,
|
242
|
+
:AUDIOPREV => 259,
|
243
|
+
:AUDIOSTOP => 260,
|
244
|
+
:AUDIOPLAY => 261,
|
245
|
+
:AUDIOMUTE => 262,
|
246
|
+
:MEDIASELECT => 263,
|
247
|
+
:WWW => 264,
|
248
|
+
:MAIL => 265,
|
249
|
+
:CALCULATOR => 266,
|
250
|
+
:COMPUTER => 267,
|
251
|
+
:AC_SEARCH => 268,
|
252
|
+
:AC_HOME => 269,
|
253
|
+
:AC_BACK => 270,
|
254
|
+
:AC_FORWARD => 271,
|
255
|
+
:AC_STOP => 272,
|
256
|
+
:AC_REFRESH => 273,
|
257
|
+
:AC_BOOKMARKS => 274,
|
258
|
+
|
259
|
+
:BRIGHTNESSDOWN => 275,
|
260
|
+
:BRIGHTNESSUP => 276,
|
261
|
+
:DISPLAYSWITCH => 277,
|
262
|
+
|
263
|
+
:KBDILLUMTOGGLE => 278,
|
264
|
+
:KBDILLUMDOWN => 279,
|
265
|
+
:KBDILLUMUP => 280,
|
266
|
+
:EJECT => 281,
|
267
|
+
:SLEEP => 282,
|
268
|
+
|
269
|
+
:APP1 => 283,
|
270
|
+
:APP2 => 284
|
271
|
+
})
|
272
|
+
|
273
|
+
enum :scancode, Scancode.by_name
|
274
|
+
|
275
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
module SDL2
|
3
|
+
# Default load-path. To modify what library this RubyGem loads:
|
4
|
+
# 1) require 'sdl2/sdl_module' before anything else.
|
5
|
+
# 2) Modify the SDL2::SDL_MODULE array.
|
6
|
+
# 3) require any of the rest of the SDL2 module: require 'sdl2/video', etc
|
7
|
+
SDL_MODULE = ['libSDL2','/usr/local/lib/libSDL2.so']
|
8
|
+
end
|
data/lib/sdl2/surface.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
require 'sdl2/rwops'
|
3
|
+
require 'sdl2/pixels'
|
4
|
+
require 'sdl2/rect'
|
5
|
+
#require 'sdl2/pixel_format'
|
6
|
+
|
7
|
+
module SDL2
|
8
|
+
typedef :uint32, :surface_flags
|
9
|
+
class Surface < FFI::Struct
|
10
|
+
layout :flags, :surface_flags,
|
11
|
+
:format, PixelFormat.by_ref,
|
12
|
+
:w, :int,
|
13
|
+
:h, :int,
|
14
|
+
:pixels, :pointer,
|
15
|
+
:userdata, :pointer,
|
16
|
+
:locked, :int,
|
17
|
+
:lock_data, :pointer,
|
18
|
+
:clip_rect, Rect,
|
19
|
+
:map, :pointer,
|
20
|
+
:refcount, :int
|
21
|
+
|
22
|
+
def self.release(pointer)
|
23
|
+
SDL2.free_surface(pointer)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Surface Flags, Used internally but maybe useful
|
27
|
+
SWSURFACE = 0
|
28
|
+
PREALLOC = 0x00000001
|
29
|
+
RLEACCEL = 0x00000002
|
30
|
+
DONTFREE = 0x00000004
|
31
|
+
|
32
|
+
# Macro, redefined here for use.
|
33
|
+
def mustlock?
|
34
|
+
self[:flags] & RLEACCEL != 0
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
callback :blit, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
|
40
|
+
|
41
|
+
|
42
|
+
api :SDL_CreateRGBSurface, [:surface_flags, :int, :int, :int, :uint32, :uint32, :uint32, :uint32], Surface.auto_ptr
|
43
|
+
api :SDL_FreeSurface, [Surface.by_ref], :void
|
44
|
+
api :SDL_SetSurfacePalette, [Surface.by_ref, Palette.by_ref], :int
|
45
|
+
api :SDL_LockSurface, [Surface.by_ref], :int
|
46
|
+
api :SDL_UnlockSurface, [Surface.by_ref], :void
|
47
|
+
api :SDL_LoadBMP_RW, [RWops.by_ref, :int], Surface.auto_ptr
|
48
|
+
# Redefine SDL_LoadBMP macro:
|
49
|
+
def self.load_bmp(file)
|
50
|
+
SDL2.load_bmp_rw(RWops.from_file(file, 'rb'), 1)
|
51
|
+
end
|
52
|
+
api :SDL_SaveBMP_RW, [Surface.by_ref, RWops.by_ref, :int], :int
|
53
|
+
|
54
|
+
def self.save_bmp(file)
|
55
|
+
SDL2.save_bmp_rw(RWops.from_file(file, 'wb'), 1)
|
56
|
+
end
|
57
|
+
|
58
|
+
api :SDL_SetSurfaceRLE, [Surface.by_ref, :int], :int
|
59
|
+
api :SDL_SetColorKey, [Surface.by_ref, :int, :uint32], :int
|
60
|
+
api :SDL_GetColorKey, [Surface.by_ref, UInt32Struct.by_ref], :int
|
61
|
+
api :SDL_SetSurfaceColorMod, [Surface.by_ref, :uint8, :uint8, :uint8], :int
|
62
|
+
api :SDL_GetSurfaceColorMod, [Surface.by_ref, UInt8Struct.by_ref,UInt8Struct.by_ref,UInt8Struct.by_ref], :int
|
63
|
+
api :SDL_SetSurfaceAlphaMod, [Surface.by_ref, :uint8], :int
|
64
|
+
api :SDL_GetSurfaceAlphaMod, [Surface.by_ref,UInt8Struct.by_ref], :int
|
65
|
+
api :SDL_SetSurfaceBlendMode, [Surface.by_ref, :blend_mode], :int
|
66
|
+
api :SDL_GetSurfaceBlendMode, [Surface.by_ref, BlendModeStruct.by_ref], :int
|
67
|
+
api :SDL_SetClipRect, [Surface.by_ref, Rect.by_ref], :int
|
68
|
+
api :SDL_GetClipRect, [Surface.by_ref, Rect.by_ref], :int
|
69
|
+
api :SDL_ConvertSurface, [Surface.by_ref, PixelFormat.by_ref, :surface_flags], Surface.auto_ptr
|
70
|
+
api :SDL_ConvertSurfaceFormat, [Surface.by_ref, :pixel_format, :surface_flags], Surface.auto_ptr
|
71
|
+
api :SDL_ConvertPixels, [:int, :int, :pixel_format, :pointer, :int, :pixel_format, :pointer, :int], :int
|
72
|
+
api :SDL_FillRect, [Surface.by_ref, Rect.by_ref, :uint32], :int
|
73
|
+
api :SDL_FillRects, [Surface.by_ref, Rect.by_ref, :count, :uint32], :int
|
74
|
+
api :SDL_UpperBlit, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
|
75
|
+
#alias_method :blit_surface, :upper_blit # TODO: Review if this is what line 447 means.
|
76
|
+
#alias_class_method :blit_surface, :upper_blit
|
77
|
+
api :SDL_LowerBlit, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
|
78
|
+
api :SDL_SoftStretch, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
|
79
|
+
api :SDL_UpperBlitScaled, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
|
80
|
+
alias_method :blit_scaled, :upper_blit_scaled
|
81
|
+
api :SDL_LowerBlitScaled, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
require 'sdl2/version'
|
3
|
+
|
4
|
+
module SDL2
|
5
|
+
|
6
|
+
module SysWM
|
7
|
+
class Info < Struct
|
8
|
+
|
9
|
+
class Win < Struct
|
10
|
+
layout :window, :pointer
|
11
|
+
end
|
12
|
+
|
13
|
+
class X11 < Struct
|
14
|
+
layout :display, :pointer,
|
15
|
+
:window, :ulong
|
16
|
+
end
|
17
|
+
|
18
|
+
class DirectFB < Struct
|
19
|
+
layout :dfb, :pointer,
|
20
|
+
:window, :pointer,
|
21
|
+
:surface, :pointer
|
22
|
+
end
|
23
|
+
|
24
|
+
class Cocoa < Struct
|
25
|
+
layout :window, :pointer
|
26
|
+
end
|
27
|
+
|
28
|
+
class UIKit < Struct
|
29
|
+
layout :window, :pointer
|
30
|
+
end
|
31
|
+
|
32
|
+
class InfoUnion < FFI::Union
|
33
|
+
layout :win, Win,
|
34
|
+
:x11, X11,
|
35
|
+
:dfb, DirectFB,
|
36
|
+
:cocoa, Cocoa,
|
37
|
+
:uikit, UIKit,
|
38
|
+
:dummy, :int
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
layout :version, Version,
|
43
|
+
:subsystem, :int,
|
44
|
+
:info, InfoUnion
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|