SDLRuby 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/lib/SDLRuby/keyboard.rb +43 -32
- data/lib/SDLRuby/mouse.rb +105 -27
- data/lib/SDLRuby/sdl/include/SDL_keycode.h.rb +70 -70
- data/lib/SDLRuby/sdl.rb +29 -2
- data/lib/SDLRuby/timer.rb +25 -0
- data/lib/SDLRuby/version.rb +1 -1
- data/lib/SDLRuby/window/surfacer.rb +37 -37
- data/sig/lib/SDLRuby/keyboard.rbs +25 -0
- data/sig/lib/SDLRuby/mouse.rbs +35 -0
- data/sig/lib/SDLRuby/timer.rbs +7 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 808c30b69ff9a14dd61fae1fa5c6812a1be91e6313affb2a46ff136cbffcfeac
|
4
|
+
data.tar.gz: 42794a0310f8329168a8237897d62dddf14cb14922d1db1d631570308708c8da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c840b525923d6e083094d5783ad70057f758dbd4be86f1660d16f7873eeb9e12bf5bdfdfb739c0664287eda2bde514926bc8e0fffd25f1822001482b024b3820
|
7
|
+
data.tar.gz: 1bec511a45a3786d35c407d51c66b3e75fb0b339835b2d00e492cce65d73c98873a9433043b8faa43f3ac6117988746c4178c14b7468d68a8873fd99a0d45785
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.3.0] - 2023-09-19
|
4
|
+
- Implemented Mouse Module.
|
5
|
+
- Implementation of the Timer Module.
|
6
|
+
- Implemented Keyboard Module.
|
7
|
+
- Specification and implementation of SDL.init, SDL.init?, and SDL.quit.
|
8
|
+
|
9
|
+
## [0.2.1] - 2023-09-13
|
4
10
|
|
5
11
|
- Memory leak fix on event retrieval failure.
|
6
12
|
|
data/lib/SDLRuby/keyboard.rb
CHANGED
@@ -3,56 +3,67 @@ module SDLRuby
|
|
3
3
|
module_eval do
|
4
4
|
num_keys = SDL.tmp_value("int")
|
5
5
|
|
6
|
-
# SDL_GetKeyboardState
|
7
|
-
#
|
6
|
+
# The SDL_GetKeyboardState function can be called before SDL_Init.
|
7
|
+
#
|
8
8
|
ptr = SDL.SDL_GetKeyboardState(num_keys)
|
9
9
|
|
10
|
-
#
|
10
|
+
# SDL_GetKeyboardState returns an error when num_keys is NULL.
|
11
|
+
#
|
11
12
|
raise SDLError if ptr.null?
|
12
13
|
|
13
14
|
ptr.size = num_keys.value
|
14
|
-
@
|
15
|
+
@ptr = ptr.freeze
|
15
16
|
end
|
16
17
|
|
17
18
|
class << self
|
18
|
-
|
19
|
-
raise IndexError if idx < 0 || @state.size <= idx
|
20
|
-
@state[idx] != 0
|
21
|
-
end
|
22
|
-
|
23
|
-
def any? = to_a.any?
|
24
|
-
|
25
|
-
def clear = SDL.SDL_ResetKeyboard
|
26
|
-
|
27
|
-
# キー名からキーコードを得る
|
28
|
-
def keycode(s) = SDL.GetKeyFromName(s).nonzero?
|
19
|
+
include SDL
|
29
20
|
|
30
|
-
#
|
31
|
-
|
32
|
-
|
21
|
+
# This method specifies the ability to check for a match with
|
22
|
+
# the characters appearing in the 'when' clause of a 'case' statement.
|
23
|
+
#
|
24
|
+
# see also: String#===
|
25
|
+
#
|
26
|
+
def ==(other)
|
27
|
+
case other
|
28
|
+
when Integer
|
29
|
+
0 <= other && other < @ptr.size && @ptr[other] != 0
|
30
|
+
when String, Symbol
|
31
|
+
(idx = scancode(other)) != 0 && @ptr[idx] != 0
|
32
|
+
else
|
33
|
+
super
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
def any?
|
38
|
+
# SDL sets a byte to either 0x00 or 0x01 for each scancode.
|
39
|
+
# It does not fill the byte sequence with 0x80, so this should work.
|
40
|
+
#
|
41
|
+
to_str.sum != 0
|
38
42
|
end
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
def clear
|
45
|
+
# SDL_ResetKeyboard should be preceded by initializing SDL events since
|
46
|
+
# it sends SDLK_KEYUP events for pressed keys.
|
47
|
+
#
|
48
|
+
# Calling SDL_ResetKeyboard when the SDL event subsystem is not initialized
|
49
|
+
# results in a core dump.
|
50
|
+
#
|
51
|
+
SDL.SDL_ResetKeyboard if SDL.init?(SDL_INIT_EVENTS)
|
43
52
|
end
|
44
53
|
|
45
|
-
|
46
|
-
def scancode(s) = SDL.GetScancodeFromName(s).nonzero?
|
54
|
+
def mod = SDL.SDL_GetModState
|
47
55
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
56
|
+
def scancode(s) = SDL.SDL_GetScancodeFromName(s.to_s)
|
57
|
+
|
58
|
+
def scancode_name(num) = SDL.SDL_GetScancodeName(num).to_s
|
59
|
+
|
60
|
+
def size = @ptr.size
|
61
|
+
|
62
|
+
alias length size
|
52
63
|
|
53
|
-
def to_a =
|
64
|
+
def to_a = size.times.select { |i| @ptr[i] != 0 }
|
54
65
|
|
55
|
-
def to_str = @
|
66
|
+
def to_str = @ptr.to_str
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
data/lib/SDLRuby/mouse.rb
CHANGED
@@ -1,52 +1,130 @@
|
|
1
1
|
module SDLRuby
|
2
2
|
module Mouse
|
3
|
-
@global_x, @global_y = *SDL.tmp_value("int", "int")
|
4
|
-
@relative_x, @relative_y = *SDL.tmp_value("int", "int")
|
5
|
-
@x, @y = *SDL.tmp_value("int", "int")
|
6
|
-
|
7
3
|
class << self
|
8
4
|
include SDL
|
9
5
|
|
10
|
-
def
|
11
|
-
[
|
12
|
-
num & SDL_BUTTON_LMASK != 0,
|
13
|
-
num & SDL_BUTTON_MMASK != 0,
|
14
|
-
num & SDL_BUTTON_RMASK != 0,
|
15
|
-
num & SDL_BUTTON_X1MASK != 0,
|
16
|
-
num & SDL_BUTTON_X2MASK != 0
|
17
|
-
]
|
18
|
-
end
|
6
|
+
def button = button_to_ary(WindowMouse.button)
|
19
7
|
|
8
|
+
# If called without initializing the SDL video subsystem,
|
9
|
+
# even if a mouse is present in the system, it will return an error.
|
10
|
+
#
|
11
|
+
# This method must be called from the main thread.
|
12
|
+
#
|
20
13
|
def capture=(b)
|
21
14
|
err = SDL.SDL_CaptureMouse(b ? 1 : 0)
|
22
15
|
raise SDLError if err < 0
|
23
16
|
end
|
24
17
|
|
18
|
+
def global_button = button_to_ary(GlobalMouse.button)
|
19
|
+
|
20
|
+
def global_pos = GlobalMouse.pos
|
21
|
+
|
22
|
+
# If called without initializing the SDL video subsystem,
|
23
|
+
# even if a mouse is present in the system, it will return an error.
|
24
|
+
#
|
25
25
|
def global_pos=(xy)
|
26
|
-
|
27
|
-
raise SDLError if err < 0
|
26
|
+
GlobalMouse.pos=(xy)
|
28
27
|
end
|
29
28
|
|
30
|
-
def global_state
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def global_state
|
30
|
+
a = GlobalMouse.state
|
31
|
+
a[0] = button_to_ary(a[0])
|
32
|
+
a
|
33
|
+
end
|
34
34
|
|
35
|
+
def pos = WindowMouse.pos
|
36
|
+
|
37
|
+
def pos=(xy)
|
38
|
+
SDL.SDL_WarpMouseInWindow(nil, *xy)
|
39
|
+
end
|
40
|
+
|
41
|
+
# If called without initializing the SDL video subsystem,
|
42
|
+
# even if a mouse is present in the system, it will return an error.
|
43
|
+
#
|
35
44
|
def relative=(b)
|
36
45
|
err = SDL.SDL_SetRelativeMouseMode(b ? 1 : 0)
|
37
46
|
raise SDLError if err < 0
|
38
47
|
end
|
39
48
|
|
40
|
-
def relative? = SDL.SDL_GetRelativeMouseMode
|
49
|
+
def relative? = SDL.SDL_GetRelativeMouseMode != 0
|
50
|
+
|
51
|
+
def relative_pos = RelativeMouse.pos
|
52
|
+
|
53
|
+
def relative_state
|
54
|
+
a = RelativeMouse.state
|
55
|
+
a[0] = button_to_ary(a[0])
|
56
|
+
a
|
57
|
+
end
|
58
|
+
|
59
|
+
def state
|
60
|
+
a = WindowMouse.state
|
61
|
+
a[0] = button_to_ary(a[0])
|
62
|
+
a
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def button_to_ary(num)
|
68
|
+
[
|
69
|
+
num & SDL_BUTTON_LMASK != 0,
|
70
|
+
num & SDL_BUTTON_MMASK != 0,
|
71
|
+
num & SDL_BUTTON_RMASK != 0,
|
72
|
+
num & SDL_BUTTON_X1MASK != 0,
|
73
|
+
num & SDL_BUTTON_X2MASK != 0,
|
74
|
+
]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
module GlobalMouse
|
79
|
+
@x, @y = SDL.tmp_value("int", "int")
|
80
|
+
|
81
|
+
class << self
|
82
|
+
def button = SDL.SDL_GetGlobalMouseState(nil, nil)
|
41
83
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
84
|
+
def pos
|
85
|
+
SDL.SDL_GetGlobalMouseState(@x, @y)
|
86
|
+
[@x.value, @y.value]
|
87
|
+
end
|
46
88
|
|
47
|
-
|
48
|
-
|
49
|
-
|
89
|
+
def pos=(xy)
|
90
|
+
err = SDL.SDL_WarpMouseGlobal(*xy)
|
91
|
+
raise SDLError if err < 0
|
92
|
+
end
|
93
|
+
|
94
|
+
def state = [SDL.SDL_GetGlobalMouseState(@x, @y), @x.value, @y.value]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
module RelativeMouse
|
99
|
+
@x, @y = SDL.tmp_value("int", "int")
|
100
|
+
|
101
|
+
class << self
|
102
|
+
def pos
|
103
|
+
SDL.SDL_GetRelativeMouseState(@x, @y)
|
104
|
+
[@x.value, @y.value]
|
105
|
+
end
|
106
|
+
|
107
|
+
def state = [SDL.SDL_GetRelativeMouseState(@x, @y), @x.value, @y.value]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
module WindowMouse
|
112
|
+
@x, @y = SDL.tmp_value("int", "int")
|
113
|
+
|
114
|
+
class << self
|
115
|
+
def button = SDL.SDL_GetMouseState(nil, nil)
|
116
|
+
|
117
|
+
def pos
|
118
|
+
SDL.SDL_GetMouseState(@x, @y)
|
119
|
+
[@x.value, @y.value]
|
120
|
+
end
|
121
|
+
|
122
|
+
def pos=(xy)
|
123
|
+
SDL.SDL_WarpMouseInWindow(nil, *xy)
|
124
|
+
end
|
125
|
+
|
126
|
+
def state = [SDL.SDL_GetMouseState(@x, @y), @x.value, @y.value]
|
127
|
+
end
|
50
128
|
end
|
51
129
|
end
|
52
130
|
end
|
@@ -12,76 +12,76 @@ module SDLRuby::SDL
|
|
12
12
|
end
|
13
13
|
|
14
14
|
SDLK_UNKNOWN = 0
|
15
|
-
SDLK_RETURN = "\r"
|
16
|
-
SDLK_ESCAPE = "\x1B"
|
17
|
-
SDLK_BACKSPACE = "\b"
|
18
|
-
SDLK_TAB = "\t"
|
19
|
-
SDLK_SPACE = ' '
|
20
|
-
SDLK_EXCLAIM = '!'
|
21
|
-
SDLK_QUOTEDBL = '"'
|
22
|
-
SDLK_HASH = '#'
|
23
|
-
SDLK_PERCENT = '%'
|
24
|
-
SDLK_DOLLAR = '$'
|
25
|
-
SDLK_AMPERSAND = '&'
|
26
|
-
SDLK_QUOTE = '\''
|
27
|
-
SDLK_LEFTPAREN = '('
|
28
|
-
SDLK_RIGHTPAREN = ')'
|
29
|
-
SDLK_ASTERISK = '*'
|
30
|
-
SDLK_PLUS = '+'
|
31
|
-
SDLK_COMMA = ','
|
32
|
-
SDLK_MINUS = '-'
|
33
|
-
SDLK_PERIOD = '.'
|
34
|
-
SDLK_SLASH = '/'
|
35
|
-
SDLK_0 = '0'
|
36
|
-
SDLK_1 = '1'
|
37
|
-
SDLK_2 = '2'
|
38
|
-
SDLK_3 = '3'
|
39
|
-
SDLK_4 = '4'
|
40
|
-
SDLK_5 = '5'
|
41
|
-
SDLK_6 = '6'
|
42
|
-
SDLK_7 = '7'
|
43
|
-
SDLK_8 = '8'
|
44
|
-
SDLK_9 = '9'
|
45
|
-
SDLK_COLON = ':'
|
46
|
-
SDLK_SEMICOLON = ';'
|
47
|
-
SDLK_LESS = '<'
|
48
|
-
SDLK_EQUALS = '='
|
49
|
-
SDLK_GREATER = '>'
|
50
|
-
SDLK_QUESTION = '?'
|
51
|
-
SDLK_AT = '@'
|
15
|
+
SDLK_RETURN = "\r".unpack1("C")
|
16
|
+
SDLK_ESCAPE = "\x1B".unpack1("C")
|
17
|
+
SDLK_BACKSPACE = "\b".unpack1("C")
|
18
|
+
SDLK_TAB = "\t".unpack1("C")
|
19
|
+
SDLK_SPACE = ' '.unpack1("C")
|
20
|
+
SDLK_EXCLAIM = '!'.unpack1("C")
|
21
|
+
SDLK_QUOTEDBL = '"'.unpack1("C")
|
22
|
+
SDLK_HASH = '#'.unpack1("C")
|
23
|
+
SDLK_PERCENT = '%'.unpack1("C")
|
24
|
+
SDLK_DOLLAR = '$'.unpack1("C")
|
25
|
+
SDLK_AMPERSAND = '&'.unpack1("C")
|
26
|
+
SDLK_QUOTE = '\''.unpack1("C")
|
27
|
+
SDLK_LEFTPAREN = '('.unpack1("C")
|
28
|
+
SDLK_RIGHTPAREN = ')'.unpack1("C")
|
29
|
+
SDLK_ASTERISK = '*'.unpack1("C")
|
30
|
+
SDLK_PLUS = '+'.unpack1("C")
|
31
|
+
SDLK_COMMA = ','.unpack1("C")
|
32
|
+
SDLK_MINUS = '-'.unpack1("C")
|
33
|
+
SDLK_PERIOD = '.'.unpack1("C")
|
34
|
+
SDLK_SLASH = '/'.unpack1("C")
|
35
|
+
SDLK_0 = '0'.unpack1("C")
|
36
|
+
SDLK_1 = '1'.unpack1("C")
|
37
|
+
SDLK_2 = '2'.unpack1("C")
|
38
|
+
SDLK_3 = '3'.unpack1("C")
|
39
|
+
SDLK_4 = '4'.unpack1("C")
|
40
|
+
SDLK_5 = '5'.unpack1("C")
|
41
|
+
SDLK_6 = '6'.unpack1("C")
|
42
|
+
SDLK_7 = '7'.unpack1("C")
|
43
|
+
SDLK_8 = '8'.unpack1("C")
|
44
|
+
SDLK_9 = '9'.unpack1("C")
|
45
|
+
SDLK_COLON = ':'.unpack1("C")
|
46
|
+
SDLK_SEMICOLON = ';'.unpack1("C")
|
47
|
+
SDLK_LESS = '<'.unpack1("C")
|
48
|
+
SDLK_EQUALS = '='.unpack1("C")
|
49
|
+
SDLK_GREATER = '>'.unpack1("C")
|
50
|
+
SDLK_QUESTION = '?'.unpack1("C")
|
51
|
+
SDLK_AT = '@'.unpack1("C")
|
52
52
|
|
53
|
-
SDLK_LEFTBRACKET = '['
|
54
|
-
SDLK_BACKSLASH = '\\'
|
55
|
-
SDLK_RIGHTBRACKET = ']'
|
56
|
-
SDLK_CARET = '^'
|
57
|
-
SDLK_UNDERSCORE = '_'
|
58
|
-
SDLK_BACKQUOTE = '`'
|
59
|
-
SDLK_a = 'a'
|
60
|
-
SDLK_b = 'b'
|
61
|
-
SDLK_c = 'c'
|
62
|
-
SDLK_d = 'd'
|
63
|
-
SDLK_e = 'e'
|
64
|
-
SDLK_f = 'f'
|
65
|
-
SDLK_g = 'g'
|
66
|
-
SDLK_h = 'h'
|
67
|
-
SDLK_i = 'i'
|
68
|
-
SDLK_j = 'j'
|
69
|
-
SDLK_k = 'k'
|
70
|
-
SDLK_l = 'l'
|
71
|
-
SDLK_m = 'm'
|
72
|
-
SDLK_n = 'n'
|
73
|
-
SDLK_o = 'o'
|
74
|
-
SDLK_p = 'p'
|
75
|
-
SDLK_q = 'q'
|
76
|
-
SDLK_r = 'r'
|
77
|
-
SDLK_s = 's'
|
78
|
-
SDLK_t = 't'
|
79
|
-
SDLK_u = 'u'
|
80
|
-
SDLK_v = 'v'
|
81
|
-
SDLK_w = 'w'
|
82
|
-
SDLK_x = 'x'
|
83
|
-
SDLK_y = 'y'
|
84
|
-
SDLK_z = 'z'
|
53
|
+
SDLK_LEFTBRACKET = '['.unpack1("C")
|
54
|
+
SDLK_BACKSLASH = '\\'.unpack1("C")
|
55
|
+
SDLK_RIGHTBRACKET = ']'.unpack1("C")
|
56
|
+
SDLK_CARET = '^'.unpack1("C")
|
57
|
+
SDLK_UNDERSCORE = '_'.unpack1("C")
|
58
|
+
SDLK_BACKQUOTE = '`'.unpack1("C")
|
59
|
+
SDLK_a = 'a'.unpack1("C")
|
60
|
+
SDLK_b = 'b'.unpack1("C")
|
61
|
+
SDLK_c = 'c'.unpack1("C")
|
62
|
+
SDLK_d = 'd'.unpack1("C")
|
63
|
+
SDLK_e = 'e'.unpack1("C")
|
64
|
+
SDLK_f = 'f'.unpack1("C")
|
65
|
+
SDLK_g = 'g'.unpack1("C")
|
66
|
+
SDLK_h = 'h'.unpack1("C")
|
67
|
+
SDLK_i = 'i'.unpack1("C")
|
68
|
+
SDLK_j = 'j'.unpack1("C")
|
69
|
+
SDLK_k = 'k'.unpack1("C")
|
70
|
+
SDLK_l = 'l'.unpack1("C")
|
71
|
+
SDLK_m = 'm'.unpack1("C")
|
72
|
+
SDLK_n = 'n'.unpack1("C")
|
73
|
+
SDLK_o = 'o'.unpack1("C")
|
74
|
+
SDLK_p = 'p'.unpack1("C")
|
75
|
+
SDLK_q = 'q'.unpack1("C")
|
76
|
+
SDLK_r = 'r'.unpack1("C")
|
77
|
+
SDLK_s = 's'.unpack1("C")
|
78
|
+
SDLK_t = 't'.unpack1("C")
|
79
|
+
SDLK_u = 'u'.unpack1("C")
|
80
|
+
SDLK_v = 'v'.unpack1("C")
|
81
|
+
SDLK_w = 'w'.unpack1("C")
|
82
|
+
SDLK_x = 'x'.unpack1("C")
|
83
|
+
SDLK_y = 'y'.unpack1("C")
|
84
|
+
SDLK_z = 'z'.unpack1("C")
|
85
85
|
SDLK_CAPSLOCK = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK)
|
86
86
|
SDLK_F1 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1)
|
87
87
|
SDLK_F2 = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2)
|
@@ -101,7 +101,7 @@ module SDLRuby::SDL
|
|
101
101
|
SDLK_INSERT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_INSERT)
|
102
102
|
SDLK_HOME = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_HOME)
|
103
103
|
SDLK_PAGEUP = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEUP)
|
104
|
-
SDLK_DELETE =
|
104
|
+
SDLK_DELETE = "\x7F".unpack1("C")
|
105
105
|
SDLK_END = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_END)
|
106
106
|
SDLK_PAGEDOWN = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_PAGEDOWN)
|
107
107
|
SDLK_RIGHT = SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_RIGHT)
|
data/lib/SDLRuby/sdl.rb
CHANGED
@@ -50,6 +50,7 @@ module SDLRuby
|
|
50
50
|
require_relative 'surface'
|
51
51
|
require_relative 'text_input'
|
52
52
|
require_relative 'texture'
|
53
|
+
require_relative 'timer'
|
53
54
|
require_relative 'window'
|
54
55
|
|
55
56
|
class << self
|
@@ -60,7 +61,33 @@ module SDLRuby
|
|
60
61
|
raise SDLError if err < 0
|
61
62
|
end
|
62
63
|
|
63
|
-
|
64
|
+
# Description:
|
65
|
+
#
|
66
|
+
# This method checks the initialization status of SDL subsystems based on
|
67
|
+
# the provided flags. You can specify the SDL subsystems you want to check
|
68
|
+
# by combining the SDL_INIT_* flags using bitwise OR.
|
69
|
+
#
|
70
|
+
# Parameters:
|
71
|
+
#
|
72
|
+
# flags (optional): An integer or a combination of SDL_INIT_* flags
|
73
|
+
# representing the SDL subsystems to check. Default is nil.
|
74
|
+
#
|
75
|
+
# Return Value:
|
76
|
+
#
|
77
|
+
# If all the specified SDL subsystems in flags are initialized,
|
78
|
+
# the method returns true.
|
79
|
+
# If any of the specified SDL subsystems are not initialized,
|
80
|
+
# it returns false.
|
81
|
+
# If flags is given as nil or 0,
|
82
|
+
# the method returns true if any of the SDL subsystems are initialized.
|
83
|
+
#
|
84
|
+
def init?(flags = nil)
|
85
|
+
if flags && flags != 0
|
86
|
+
SDL.SDL_WasInit(flags) == flags
|
87
|
+
else
|
88
|
+
SDL.SDL_WasInit(0) != 0
|
89
|
+
end
|
90
|
+
end
|
64
91
|
|
65
92
|
def quit = SDL.SDL_Quit
|
66
93
|
|
@@ -157,7 +184,7 @@ module SDLRuby
|
|
157
184
|
|
158
185
|
# timer
|
159
186
|
#
|
160
|
-
def ticks =
|
187
|
+
def ticks = Timer.ticks
|
161
188
|
|
162
189
|
# version
|
163
190
|
#
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module Timer
|
3
|
+
class << self
|
4
|
+
def ticks
|
5
|
+
# Use the same Ticks as the one utilized for SDL event timestamps.
|
6
|
+
#
|
7
|
+
SDL.SDL_GetTicks
|
8
|
+
end
|
9
|
+
|
10
|
+
def inspect
|
11
|
+
n = SDL.SDL_GetTicks64
|
12
|
+
epoch_time = n / 1000
|
13
|
+
|
14
|
+
sprintf(
|
15
|
+
"%d %02d:%02d:%02d.%03d0000",
|
16
|
+
epoch_time / 86400, # days
|
17
|
+
epoch_time / 3600 % 24, # hours
|
18
|
+
epoch_time / 60 % 60, # minutes
|
19
|
+
epoch_time % 60, # seconds
|
20
|
+
n % 1000 # fractional seconds
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/SDLRuby/version.rb
CHANGED
@@ -1,37 +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
|
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,25 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module Keyboard
|
3
|
+
include SDL
|
4
|
+
|
5
|
+
def self.==: (untyped other) -> bool
|
6
|
+
|
7
|
+
def self.any?: () -> bool
|
8
|
+
|
9
|
+
def self.clear: () -> void
|
10
|
+
|
11
|
+
def self.mod: () -> Integer
|
12
|
+
|
13
|
+
def self.scancode: (String | Symbol s) -> Integer
|
14
|
+
|
15
|
+
def self.scancode_name: (Integer num) -> String
|
16
|
+
|
17
|
+
def self.size: () -> Integer
|
18
|
+
|
19
|
+
alias self.length self.size
|
20
|
+
|
21
|
+
def self.to_a: () -> Array[Integer]
|
22
|
+
|
23
|
+
def self.to_str: () -> String
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module SDLRuby
|
2
|
+
module Mouse
|
3
|
+
include SDL
|
4
|
+
|
5
|
+
def self.button: () -> Array[bool]
|
6
|
+
|
7
|
+
def self.capture=: (boolish) -> void
|
8
|
+
|
9
|
+
def self.global_button: () -> Array[bool]
|
10
|
+
|
11
|
+
def self.global_pos: () -> [Integer, Integer]
|
12
|
+
|
13
|
+
def self.global_pos=: ([Integer, Integer] xy) -> void
|
14
|
+
|
15
|
+
def self.global_state: () -> [Array[bool], Integer, Integer]
|
16
|
+
|
17
|
+
def self.pos: () -> [Integer, Integer]
|
18
|
+
|
19
|
+
def self.pos=: ([Integer, Integer] xy) -> void
|
20
|
+
|
21
|
+
def self.relative=: (boolish) -> untyped
|
22
|
+
|
23
|
+
def self.relative?: () -> bool
|
24
|
+
|
25
|
+
def self.relative_pos: () -> [Integer, Integer]
|
26
|
+
|
27
|
+
def self.relative_state: () -> [Array[bool], Integer, Integer]
|
28
|
+
|
29
|
+
def self.state: () -> [Array[bool], Integer, Integer]
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def self.button_to_ary: (Integer num) -> ::Array[bool]
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SDLRuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shinokaro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: SDLRuby is a GEM that allows calling the SDL library from Ruby, enabling
|
14
14
|
window creation, image display, audio playback, and more. It easily manages C pointers
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/SDLRuby/surface/surface_renderer.rb
|
103
103
|
- lib/SDLRuby/text_input.rb
|
104
104
|
- lib/SDLRuby/texture.rb
|
105
|
+
- lib/SDLRuby/timer.rb
|
105
106
|
- lib/SDLRuby/ttf.rb
|
106
107
|
- lib/SDLRuby/ttf/include/SDL_ttf.h.rb
|
107
108
|
- lib/SDLRuby/ttf/ttf.rb
|
@@ -122,7 +123,10 @@ files:
|
|
122
123
|
- sig/lib/SDLRuby/event.rbs
|
123
124
|
- sig/lib/SDLRuby/event/accessor.rbs
|
124
125
|
- sig/lib/SDLRuby/event/type.rbs
|
126
|
+
- sig/lib/SDLRuby/keyboard.rbs
|
127
|
+
- sig/lib/SDLRuby/mouse.rbs
|
125
128
|
- sig/lib/SDLRuby/sdl.rbs
|
129
|
+
- sig/lib/SDLRuby/timer.rbs
|
126
130
|
homepage: https://github.com/shinokaro/SDLRuby
|
127
131
|
licenses:
|
128
132
|
- MIT
|