ruby-sdl2 0.3.5 → 0.3.7
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/.gitignore +4 -1
- data/Gemfile +10 -0
- data/README.md +8 -3
- data/Rakefile +22 -2
- data/Steepfile +24 -0
- data/doc/DEVELOP.md +35 -0
- data/event.c +36 -32
- data/gamecontroller.c +31 -27
- data/gamecontroller.c.m4 +31 -27
- data/gl.c +63 -67
- data/gl.c.m4 +63 -67
- data/hint.c +3 -3
- data/joystick.c +16 -12
- data/joystick.c.m4 +16 -12
- data/key.c +21 -19
- data/key.c.m4 +21 -19
- data/lib/sdl2/version.rb +3 -3
- data/main.c +13 -16
- data/messagebox.c +7 -7
- data/mixer.c +54 -38
- data/mixer.c.m4 +54 -38
- data/mouse.c +3 -3
- data/rbs_collection.yaml +32 -0
- data/rubysdl2_internal.h +12 -1
- data/sample/test_read_pixels.rb +41 -0
- data/ttf.c +20 -17
- data/ttf.c.m4 +20 -17
- data/video.c +262 -143
- data/video.c.m4 +199 -112
- metadata +8 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a1d841e87d0b4437b0eb204f4062d451ff279a49bbae6b98fc70af51daf36f7
|
|
4
|
+
data.tar.gz: 933024c5bc62bbcb3b7fcdaec2dabdc89a54185a16c82d18a5483dde3c8443c6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f515b8d0a224220af3feb34e11c47ec8212a9efb24166fccd42469a2d04fc5ec250798ae45d374aed504e68bccf3b18c02fc5a03db0727fcdf8de96ed01e31dc
|
|
7
|
+
data.tar.gz: 32404bacccbd2c18426a90322ca93a112cc9d2e4b247d8b64eac978ce8e23a4e625f37d54d4c0785511dde85f59565ea0896b97a43c20e458e3125d3eae39d3f
|
data/.gitignore
CHANGED
|
@@ -11,6 +11,8 @@ mixer.c
|
|
|
11
11
|
joystick.c
|
|
12
12
|
gamecontroller.c
|
|
13
13
|
extconf.h
|
|
14
|
+
sdl2.rbi
|
|
15
|
+
sdl2.rbs
|
|
14
16
|
pkg/
|
|
15
17
|
TAGS
|
|
16
18
|
local/
|
|
@@ -20,4 +22,5 @@ sample/sample.wav
|
|
|
20
22
|
.yardoc/
|
|
21
23
|
doc/doc-*
|
|
22
24
|
doc/po/rubysdl2.pot
|
|
23
|
-
extconf-options.txt
|
|
25
|
+
extconf-options.txt
|
|
26
|
+
.gem_rbs_collection/
|
data/Gemfile
ADDED
data/README.md
CHANGED
|
@@ -5,15 +5,18 @@ The simple ruby extension library for SDL 2.x.
|
|
|
5
5
|
# Install
|
|
6
6
|
Before installing Ruby/SDL2, you need to install:
|
|
7
7
|
|
|
8
|
-
* [devkit](
|
|
8
|
+
* [devkit](https://rubyinstaller.org/add-ons/devkit.html) (only for windows)
|
|
9
9
|
* M4 (only for installing from git repository)
|
|
10
10
|
* [SDL 2.x](http://www.libsdl.org/download-2.0.php)
|
|
11
11
|
* [SDL_image](https://www.libsdl.org/projects/SDL_image/)
|
|
12
12
|
* [SDL_mixer](https://www.libsdl.org/projects/SDL_mixer/)
|
|
13
13
|
* [SDL_ttf](https://www.libsdl.org/projects/SDL_ttf/)
|
|
14
14
|
|
|
15
|
-
After installing these libraries, you can install Ruby/SDL2
|
|
16
|
-
|
|
15
|
+
After installing these libraries, you can install Ruby/SDL2 by gem command as follows:
|
|
16
|
+
|
|
17
|
+
gem install ruby-sdl2
|
|
18
|
+
|
|
19
|
+
Alternatively You can also install the master version of Ruby/SDL2 from github:
|
|
17
20
|
|
|
18
21
|
git clone https://github.com/ohai/ruby-sdl2.git
|
|
19
22
|
cd ruby-sdl2
|
|
@@ -28,6 +31,8 @@ from github:
|
|
|
28
31
|
|
|
29
32
|
LGPL v3 (see {file:COPYING.txt}).
|
|
30
33
|
|
|
34
|
+
The API documentation is based on [SDL2 Wiki](https://wiki.libsdl.org/SDL2/FrontPage), which is distributed under CC-BY 4.0.
|
|
35
|
+
|
|
31
36
|
# Author
|
|
32
37
|
|
|
33
38
|
Ippei Obayashi <ohai@kmc.gr.jp>
|
data/Rakefile
CHANGED
|
@@ -10,7 +10,9 @@ RB_FILES = Dir.glob("lib/**/*.rb")
|
|
|
10
10
|
O_FILES = Rake::FileList[*C_FILES].pathmap('%n.o')
|
|
11
11
|
|
|
12
12
|
POT_SOURCES = RB_FILES + ["main.c"] + (C_FILES - ["main.c"])
|
|
13
|
+
YARD_DOC_FILES = ["README.md", "COPYING.txt"] + POT_SOURCES
|
|
13
14
|
YARD_SOURCES = "-m markdown --main README.md --files COPYING.txt #{POT_SOURCES.join(" ")}"
|
|
15
|
+
YARD_CHECKSUM_FILE = ".yardoc/checksums"
|
|
14
16
|
|
|
15
17
|
WATCH_TARGETS = (C_FILES - C_FROM_M4_FILES) + C_M4_FILES + ["README.md"]
|
|
16
18
|
|
|
@@ -74,7 +76,7 @@ if locale
|
|
|
74
76
|
sh "yard doc -o doc/doc-#{locale} --locale #{locale} --po-dir doc/po #{YARD_SOURCES}"
|
|
75
77
|
end
|
|
76
78
|
else
|
|
77
|
-
task "doc" =>
|
|
79
|
+
task "doc" => YARD_DOC_FILES do
|
|
78
80
|
sh "yard doc -o doc/doc-en #{YARD_SOURCES}"
|
|
79
81
|
end
|
|
80
82
|
end
|
|
@@ -84,7 +86,7 @@ task "doc-all" do
|
|
|
84
86
|
end
|
|
85
87
|
|
|
86
88
|
desc "List undocumented classes/modules/methods/constants"
|
|
87
|
-
task "doc-stat-undocumented" =>
|
|
89
|
+
task "doc-stat-undocumented" => YARD_DOC_FILES do
|
|
88
90
|
sh "yard stats --list-undoc --compact #{YARD_SOURCES}"
|
|
89
91
|
end
|
|
90
92
|
|
|
@@ -110,3 +112,21 @@ task "watch-doc" do
|
|
|
110
112
|
sh "inotifywait -e modify #{WATCH_TARGETS.join(" ")} && rake doc && notify-send -u low \"Ruby/SDL2 build doc OK\""
|
|
111
113
|
end
|
|
112
114
|
end
|
|
115
|
+
|
|
116
|
+
file YARD_CHECKSUM_FILE => YARD_DOC_FILES do
|
|
117
|
+
sh "yard doc -n #{YARD_SOURCES}"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
file "sdl2.rbs" => YARD_CHECKSUM_FILE do
|
|
121
|
+
sh "sord --no-regenerate --rbs sdl2.rbs"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
file "sdl2.rbi" => YARD_CHECKSUM_FILE do
|
|
125
|
+
sh "sord --no-regenerate --rbi sdl2.rbi"
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
task "clean" do
|
|
129
|
+
sh "rm -r .yardoc"
|
|
130
|
+
sh "rm -r doc/doc-en"
|
|
131
|
+
sh "rm #{C_FROM_M4_FILES.join(' ')}"
|
|
132
|
+
end
|
data/Steepfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
D = Steep::Diagnostic
|
|
2
|
+
|
|
3
|
+
# target :lib do
|
|
4
|
+
# signature "sdl2.rbs"
|
|
5
|
+
# library "rbs"
|
|
6
|
+
|
|
7
|
+
# check "lib"
|
|
8
|
+
# end
|
|
9
|
+
|
|
10
|
+
target :sample_testspriteminimal do
|
|
11
|
+
signature "sample/testspriteminimal.rbs"
|
|
12
|
+
signature "sdl2.rbs"
|
|
13
|
+
library "rbs"
|
|
14
|
+
|
|
15
|
+
check "sample/testspriteminimal.rb"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# configure_code_diagnostics(D::Ruby.strict)
|
|
19
|
+
# configure_code_diagnostics(D::Ruby.lenient)
|
|
20
|
+
configure_code_diagnostics do |hash|
|
|
21
|
+
hash[D::Ruby::MethodDefinitionMissing] = :information
|
|
22
|
+
hash[D::Ruby::UnknownConstant] = :information
|
|
23
|
+
end
|
|
24
|
+
end
|
data/doc/DEVELOP.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# For Developer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Check out and build a gem
|
|
5
|
+
|
|
6
|
+
git clone https://github.com/ohai/ruby-sdl2.git
|
|
7
|
+
cd ruby-sdl2
|
|
8
|
+
bundle install
|
|
9
|
+
bundle exec rake gem # To build a gem
|
|
10
|
+
bundle exec rake doc # To build API documents
|
|
11
|
+
|
|
12
|
+
## Build C extension and run samples
|
|
13
|
+
|
|
14
|
+
bundle exec rake build # To build sdl2_ext.so
|
|
15
|
+
cd sample
|
|
16
|
+
ruby -I .. -I ../lib testspriteminimal.rb
|
|
17
|
+
|
|
18
|
+
## For type checking
|
|
19
|
+
|
|
20
|
+
Preparation
|
|
21
|
+
|
|
22
|
+
bundle exec rbs collection install
|
|
23
|
+
|
|
24
|
+
Generate ruby-sdl2's rbs file
|
|
25
|
+
|
|
26
|
+
bundle exec rake sdl2.rbs
|
|
27
|
+
|
|
28
|
+
Signature file validation
|
|
29
|
+
|
|
30
|
+
bundle exec steep validate
|
|
31
|
+
|
|
32
|
+
Type checking with Steep
|
|
33
|
+
|
|
34
|
+
bundle exec steep check
|
|
35
|
+
|
data/event.c
CHANGED
|
@@ -86,11 +86,14 @@ static VALUE event_type_to_class[SDL_LASTEVENT];
|
|
|
86
86
|
* timestamp of the event
|
|
87
87
|
* @return [Integer]
|
|
88
88
|
*/
|
|
89
|
+
DEFINE_DATA_TYPE(SDL_Event, free);
|
|
90
|
+
|
|
89
91
|
static VALUE Event_new(SDL_Event* ev)
|
|
90
92
|
{
|
|
91
|
-
SDL_Event* e
|
|
93
|
+
SDL_Event* e;
|
|
94
|
+
VALUE obj = TypedData_Make_Struct(event_type_to_class[ev->type], SDL_Event, &SDL_Event_data_type, e);
|
|
92
95
|
*e = *ev;
|
|
93
|
-
return
|
|
96
|
+
return obj;
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
static VALUE Event_s_allocate(VALUE klass)
|
|
@@ -99,11 +102,12 @@ static VALUE Event_s_allocate(VALUE klass)
|
|
|
99
102
|
VALUE event_type = rb_iv_get(klass, "event_type");
|
|
100
103
|
if (event_type == Qnil)
|
|
101
104
|
rb_raise(rb_eArgError, "Cannot allocate %s", rb_class2name(klass));
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
|
|
106
|
+
{
|
|
107
|
+
VALUE obj = TypedData_Make_Struct(klass, SDL_Event, &SDL_Event_data_type, e);
|
|
108
|
+
e->common.type = NUM2INT(event_type);
|
|
109
|
+
return obj;
|
|
110
|
+
}
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
/*
|
|
@@ -176,7 +180,7 @@ static void set_string(char* field, VALUE str, int maxlength)
|
|
|
176
180
|
static VALUE Ev##classname##_##name(VALUE self) \
|
|
177
181
|
{ \
|
|
178
182
|
SDL_Event* ev; \
|
|
179
|
-
|
|
183
|
+
TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev); \
|
|
180
184
|
return c2ruby(ev->field); \
|
|
181
185
|
} \
|
|
182
186
|
|
|
@@ -184,7 +188,7 @@ static void set_string(char* field, VALUE str, int maxlength)
|
|
|
184
188
|
static VALUE Ev##classname##_set_##name(VALUE self, VALUE val) \
|
|
185
189
|
{ \
|
|
186
190
|
SDL_Event* ev; \
|
|
187
|
-
|
|
191
|
+
TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev); \
|
|
188
192
|
ev->field = ruby2c(val); \
|
|
189
193
|
return Qnil; \
|
|
190
194
|
}
|
|
@@ -214,7 +218,7 @@ EVENT_ACCESSOR_UINT(Event, timestamp, common.timestamp);
|
|
|
214
218
|
/* @return [String] inspection string */
|
|
215
219
|
static VALUE Event_inspect(VALUE self)
|
|
216
220
|
{
|
|
217
|
-
SDL_Event* ev;
|
|
221
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
218
222
|
return rb_sprintf("<%s: type=%u timestamp=%u>",
|
|
219
223
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp);
|
|
220
224
|
}
|
|
@@ -303,7 +307,7 @@ EVENT_ACCESSOR_INT(Window, data2, window.data2);
|
|
|
303
307
|
/* @return [String] inspection string */
|
|
304
308
|
static VALUE EvWindow_inspect(VALUE self)
|
|
305
309
|
{
|
|
306
|
-
SDL_Event* ev;
|
|
310
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
307
311
|
return rb_sprintf("<%s: type=%u timestamp=%u window_id=%u event=%u data1=%d data2=%d>",
|
|
308
312
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
309
313
|
ev->window.windowID, ev->window.event,
|
|
@@ -326,11 +330,11 @@ static VALUE EvWindow_inspect(VALUE self)
|
|
|
326
330
|
*
|
|
327
331
|
* @attribute pressed
|
|
328
332
|
* key is pressed
|
|
329
|
-
* @return [
|
|
333
|
+
* @return [boolean]
|
|
330
334
|
*
|
|
331
335
|
* @attribute repeat
|
|
332
336
|
* key repeat
|
|
333
|
-
* @return [
|
|
337
|
+
* @return [boolean]
|
|
334
338
|
*
|
|
335
339
|
* @attribute scancode
|
|
336
340
|
* physical key code
|
|
@@ -357,7 +361,7 @@ EVENT_ACCESSOR_UINT(Keyboard, mod, key.keysym.mod);
|
|
|
357
361
|
/* @return [String] inspection string */
|
|
358
362
|
static VALUE EvKeyboard_inspect(VALUE self)
|
|
359
363
|
{
|
|
360
|
-
SDL_Event* ev;
|
|
364
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
361
365
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
362
366
|
" window_id=%u state=%u repeat=%u"
|
|
363
367
|
" scancode=%u sym=%u mod=%u>",
|
|
@@ -407,7 +411,7 @@ EVENT_READER(TextEditing, text, edit.text, utf8str_new_cstr);
|
|
|
407
411
|
static VALUE EvTextEditing_set_text(VALUE self, VALUE str)
|
|
408
412
|
{
|
|
409
413
|
SDL_Event* ev;
|
|
410
|
-
|
|
414
|
+
TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
411
415
|
set_string(ev->edit.text, str, 30);
|
|
412
416
|
return str;
|
|
413
417
|
}
|
|
@@ -415,7 +419,7 @@ static VALUE EvTextEditing_set_text(VALUE self, VALUE str)
|
|
|
415
419
|
/* @return [String] inspection string */
|
|
416
420
|
static VALUE EvTextEditing_inspect(VALUE self)
|
|
417
421
|
{
|
|
418
|
-
SDL_Event* ev;
|
|
422
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
419
423
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
420
424
|
" window_id=%u text=%s start=%d length=%d>",
|
|
421
425
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
@@ -441,7 +445,7 @@ EVENT_READER(TextInput, text, text.text, utf8str_new_cstr);
|
|
|
441
445
|
static VALUE EvTextInput_set_text(VALUE self, VALUE str)
|
|
442
446
|
{
|
|
443
447
|
SDL_Event* ev;
|
|
444
|
-
|
|
448
|
+
TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
445
449
|
set_string(ev->text.text, str, 30);
|
|
446
450
|
return str;
|
|
447
451
|
}
|
|
@@ -449,7 +453,7 @@ static VALUE EvTextInput_set_text(VALUE self, VALUE str)
|
|
|
449
453
|
/* @return [String] inspection string */
|
|
450
454
|
static VALUE EvTextInput_inspect(VALUE self)
|
|
451
455
|
{
|
|
452
|
-
SDL_Event* ev;
|
|
456
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
453
457
|
return rb_sprintf("<%s: type=%u timestamp=%u window_id=%u text=%s>",
|
|
454
458
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
455
459
|
ev->text.windowID, ev->text.text);
|
|
@@ -507,7 +511,7 @@ EVENT_ACCESSOR_INT(MouseButton, y, button.y);
|
|
|
507
511
|
/* @return [String] inspection string */
|
|
508
512
|
static VALUE EvMouseButton_inspect(VALUE self)
|
|
509
513
|
{
|
|
510
|
-
SDL_Event* ev;
|
|
514
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
511
515
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
512
516
|
" window_id=%u which=%u button=%hhu pressed=%s"
|
|
513
517
|
#if SDL_VERSION_ATLEAST(2,0,2)
|
|
@@ -576,7 +580,7 @@ EVENT_ACCESSOR_INT(MouseMotion, yrel, motion.yrel);
|
|
|
576
580
|
/* @return [String] inspection string */
|
|
577
581
|
static VALUE EvMouseMotion_inspect(VALUE self)
|
|
578
582
|
{
|
|
579
|
-
SDL_Event* ev;
|
|
583
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
580
584
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
581
585
|
" window_id=%u which=%u state=%u"
|
|
582
586
|
" x=%d y=%d xrel=%d yrel=%d>",
|
|
@@ -615,7 +619,7 @@ EVENT_ACCESSOR_INT(MouseWheel, y, wheel.y);
|
|
|
615
619
|
/* @return [String] inspection string */
|
|
616
620
|
static VALUE EvMouseWheel_inspect(VALUE self)
|
|
617
621
|
{
|
|
618
|
-
SDL_Event* ev;
|
|
622
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
619
623
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
620
624
|
" window_id=%u which=%u x=%d y=%d>",
|
|
621
625
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
@@ -651,7 +655,7 @@ EVENT_ACCESSOR_BOOL(JoyButton, pressed, jbutton.state);
|
|
|
651
655
|
/* @return [String] inspection string */
|
|
652
656
|
static VALUE EvJoyButton_inspect(VALUE self)
|
|
653
657
|
{
|
|
654
|
-
SDL_Event* ev;
|
|
658
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
655
659
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
656
660
|
" which=%d button=%u pressed=%s>",
|
|
657
661
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
@@ -690,10 +694,10 @@ static VALUE EvJoyButton_inspect(VALUE self)
|
|
|
690
694
|
EVENT_ACCESSOR_INT(JoyAxisMotion, which, jaxis.which);
|
|
691
695
|
EVENT_ACCESSOR_UINT8(JoyAxisMotion, axis, jaxis.axis);
|
|
692
696
|
EVENT_ACCESSOR_INT(JoyAxisMotion, value, jaxis.value);
|
|
693
|
-
/* @return [
|
|
697
|
+
/* @return [String] inspection string */
|
|
694
698
|
static VALUE EvJoyAxisMotion_inspect(VALUE self)
|
|
695
699
|
{
|
|
696
|
-
SDL_Event* ev;
|
|
700
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
697
701
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
698
702
|
" which=%d axis=%u value=%d>",
|
|
699
703
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
@@ -728,7 +732,7 @@ EVENT_ACCESSOR_INT(JoyBallMotion, yrel, jball.yrel);
|
|
|
728
732
|
/* @return [String] inspection string */
|
|
729
733
|
static VALUE EvJoyBallMotion_inspect(VALUE self)
|
|
730
734
|
{
|
|
731
|
-
SDL_Event* ev;
|
|
735
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
732
736
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
733
737
|
" which=%d ball=%u xrel=%d yrel=%d>",
|
|
734
738
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
@@ -758,7 +762,7 @@ EVENT_ACCESSOR_UINT8(JoyHatMotion, value, jhat.value);
|
|
|
758
762
|
/* @return [String] inspection string */
|
|
759
763
|
static VALUE EvJoyHatMotion_inspect(VALUE self)
|
|
760
764
|
{
|
|
761
|
-
SDL_Event* ev;
|
|
765
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
762
766
|
return rb_sprintf("<%s: type=%u timestamp=%u which=%d hat=%u value=%u>",
|
|
763
767
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
764
768
|
ev->jhat.which, ev->jhat.hat, ev->jhat.value);
|
|
@@ -775,7 +779,7 @@ EVENT_ACCESSOR_INT(JoyDevice, which, jdevice.which);
|
|
|
775
779
|
/* @return [String] inspection string */
|
|
776
780
|
static VALUE EvJoyDevice_inspect(VALUE self)
|
|
777
781
|
{
|
|
778
|
-
SDL_Event* ev;
|
|
782
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
779
783
|
return rb_sprintf("<%s: type=%u timestamp=%u which=%d>",
|
|
780
784
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
781
785
|
ev->jdevice.which);
|
|
@@ -816,7 +820,7 @@ EVENT_ACCESSOR_INT(ControllerAxis, value, caxis.value);
|
|
|
816
820
|
/* @return [String] inspection string */
|
|
817
821
|
static VALUE ControllerAxis_inspect(VALUE self)
|
|
818
822
|
{
|
|
819
|
-
SDL_Event* ev;
|
|
823
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
820
824
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
821
825
|
" which=%d axis=%s value=%d>",
|
|
822
826
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
@@ -853,7 +857,7 @@ EVENT_ACCESSOR_BOOL(ControllerButton, pressed, cbutton.state);
|
|
|
853
857
|
/* @return [String] inspection string */
|
|
854
858
|
static VALUE ControllerButton_inspect(VALUE self)
|
|
855
859
|
{
|
|
856
|
-
SDL_Event* ev;
|
|
860
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
857
861
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
858
862
|
" which=%d button=%s state=%s>",
|
|
859
863
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
@@ -893,7 +897,7 @@ EVENT_ACCESSOR_INT(ControllerDevice, which, cdevice.which);
|
|
|
893
897
|
/* @return [String] inspection string */
|
|
894
898
|
static VALUE ControllerDevice_inspect(VALUE self)
|
|
895
899
|
{
|
|
896
|
-
SDL_Event* ev;
|
|
900
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
897
901
|
return rb_sprintf("<%s: type=%u timestamp=%u which=%d>",
|
|
898
902
|
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
|
899
903
|
ev->cdevice.which);
|
|
@@ -953,7 +957,7 @@ EVENT_ACCESSOR_DBL(TouchFinger, pressure, tfinger.pressure);
|
|
|
953
957
|
/* @return [String] inspection string */
|
|
954
958
|
static VALUE EvTouchFinger_inspect(VALUE self)
|
|
955
959
|
{
|
|
956
|
-
SDL_Event* ev;
|
|
960
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
957
961
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
958
962
|
" touch_id=%d finger_id=%d"
|
|
959
963
|
" x=%f y=%f pressure=%f>",
|
|
@@ -990,7 +994,7 @@ EVENT_ACCESSOR_DBL(FingerMotion, dy, tfinger.dy);
|
|
|
990
994
|
/* @return [String] inspection string */
|
|
991
995
|
static VALUE EvFingerMotion_inspect(VALUE self)
|
|
992
996
|
{
|
|
993
|
-
SDL_Event* ev;
|
|
997
|
+
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, ev);
|
|
994
998
|
return rb_sprintf("<%s: type=%u timestamp=%u"
|
|
995
999
|
" touch_id=%d finger_id=%d"
|
|
996
1000
|
" x=%f y=%f pressure=%f"
|
data/gamecontroller.c
CHANGED
|
@@ -17,6 +17,8 @@ static void GameController_free(GameController* g)
|
|
|
17
17
|
free(g);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
DEFINE_DATA_TYPE(GameController, GameController_free);
|
|
21
|
+
|
|
20
22
|
/*
|
|
21
23
|
* Document-class: SDL2::GameController
|
|
22
24
|
*
|
|
@@ -60,9 +62,10 @@ static void GameController_free(GameController* g)
|
|
|
60
62
|
|
|
61
63
|
static VALUE GameController_new(SDL_GameController* controller)
|
|
62
64
|
{
|
|
63
|
-
GameController* g
|
|
65
|
+
GameController* g;
|
|
66
|
+
VALUE obj = TypedData_Make_Struct(cGameController, GameController, &GameController_data_type, g);
|
|
64
67
|
g->controller = controller;
|
|
65
|
-
return
|
|
68
|
+
return obj;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
DEFINE_WRAPPER(SDL_GameController, GameController, controller, cGameController,
|
|
@@ -302,6 +305,7 @@ static VALUE GameController_axis(VALUE self, VALUE axis)
|
|
|
302
305
|
* Return true if a button is pressed.
|
|
303
306
|
*
|
|
304
307
|
* @param button [Integer] the index of a button, one of the constants in {Button}
|
|
308
|
+
* @return [Boolean]
|
|
305
309
|
*/
|
|
306
310
|
static VALUE GameController_button_pressed_p(VALUE self, VALUE button)
|
|
307
311
|
{
|
|
@@ -353,56 +357,56 @@ void rubysdl2_init_gamecontorller(void)
|
|
|
353
357
|
mButton = rb_define_module_under(cGameController, "Button");
|
|
354
358
|
|
|
355
359
|
/* */
|
|
356
|
-
/*
|
|
360
|
+
/* @return [Integer] index for invalid axis*/
|
|
357
361
|
rb_define_const(mAxis, "INVALID", INT2NUM(SDL_CONTROLLER_AXIS_INVALID));
|
|
358
|
-
/* Left X axis */
|
|
362
|
+
/* @return [Integer] index for Left X axis */
|
|
359
363
|
rb_define_const(mAxis, "LEFTX", INT2NUM(SDL_CONTROLLER_AXIS_LEFTX));
|
|
360
|
-
/* Left Y axis */
|
|
364
|
+
/* @return [Integer] index for Left Y axis */
|
|
361
365
|
rb_define_const(mAxis, "LEFTY", INT2NUM(SDL_CONTROLLER_AXIS_LEFTY));
|
|
362
|
-
/* Right X axis */
|
|
366
|
+
/* @return [Integer] index for Right X axis */
|
|
363
367
|
rb_define_const(mAxis, "RIGHTX", INT2NUM(SDL_CONTROLLER_AXIS_RIGHTX));
|
|
364
|
-
/* Right Y axis */
|
|
368
|
+
/* @return [Integer] index for Right Y axis */
|
|
365
369
|
rb_define_const(mAxis, "RIGHTY", INT2NUM(SDL_CONTROLLER_AXIS_RIGHTY));
|
|
366
|
-
/* Left trigger axis */
|
|
370
|
+
/* @return [Integer] index for Left trigger axis */
|
|
367
371
|
rb_define_const(mAxis, "TRIGGERLEFT", INT2NUM(SDL_CONTROLLER_AXIS_TRIGGERLEFT));
|
|
368
|
-
/* Right trigger axis */
|
|
372
|
+
/* @return [Integer] index for Right trigger axis */
|
|
369
373
|
rb_define_const(mAxis, "TRIGGERRIGHT", INT2NUM(SDL_CONTROLLER_AXIS_TRIGGERRIGHT));
|
|
370
|
-
/*
|
|
374
|
+
/* @return [Integer] the max value of axis indices */
|
|
371
375
|
rb_define_const(mAxis, "MAX", INT2NUM(SDL_CONTROLLER_AXIS_MAX));
|
|
372
376
|
|
|
373
377
|
/* */
|
|
374
|
-
/* Invalid button
|
|
378
|
+
/* @return [Integer] index for Invalid button */
|
|
375
379
|
rb_define_const(mButton, "INVALID", INT2NUM(SDL_CONTROLLER_BUTTON_INVALID));
|
|
376
|
-
/* Button A */
|
|
380
|
+
/* @return [Integer] index for Button A */
|
|
377
381
|
rb_define_const(mButton, "A", INT2NUM(SDL_CONTROLLER_BUTTON_A));
|
|
378
|
-
/* Button B */
|
|
382
|
+
/* @return [Integer] index for Button B */
|
|
379
383
|
rb_define_const(mButton, "B", INT2NUM(SDL_CONTROLLER_BUTTON_B));
|
|
380
|
-
/* Button X */
|
|
384
|
+
/* @return [Integer] index for Button X */
|
|
381
385
|
rb_define_const(mButton, "X", INT2NUM(SDL_CONTROLLER_BUTTON_X));
|
|
382
|
-
/* Button Y */
|
|
386
|
+
/* @return [Integer] index for Button Y */
|
|
383
387
|
rb_define_const(mButton, "Y", INT2NUM(SDL_CONTROLLER_BUTTON_Y));
|
|
384
|
-
/* Back Button */
|
|
388
|
+
/* @return [Integer] index for Back Button */
|
|
385
389
|
rb_define_const(mButton, "BACK", INT2NUM(SDL_CONTROLLER_BUTTON_BACK));
|
|
386
|
-
/* Guide Button */
|
|
390
|
+
/* @return [Integer] index for Guide Button */
|
|
387
391
|
rb_define_const(mButton, "GUIDE", INT2NUM(SDL_CONTROLLER_BUTTON_GUIDE));
|
|
388
|
-
/* Start Button */
|
|
392
|
+
/* @return [Integer] index for Start Button */
|
|
389
393
|
rb_define_const(mButton, "START", INT2NUM(SDL_CONTROLLER_BUTTON_START));
|
|
390
|
-
/* Left stick Button */
|
|
394
|
+
/* @return [Integer] index for Left stick Button */
|
|
391
395
|
rb_define_const(mButton, "LEFTSTICK", INT2NUM(SDL_CONTROLLER_BUTTON_LEFTSTICK));
|
|
392
|
-
/* Right stick Button */
|
|
396
|
+
/* @return [Integer] index for Right stick Button */
|
|
393
397
|
rb_define_const(mButton, "RIGHTSTICK", INT2NUM(SDL_CONTROLLER_BUTTON_RIGHTSTICK));
|
|
394
|
-
/* Left shoulder Button */
|
|
398
|
+
/* @return [Integer] index for Left shoulder Button */
|
|
395
399
|
rb_define_const(mButton, "LEFTSHOULDER", INT2NUM(SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
|
|
396
|
-
/* Right shoulder Button */
|
|
400
|
+
/* @return [Integer] index for Right shoulder Button */
|
|
397
401
|
rb_define_const(mButton, "RIGHTSHOULDER", INT2NUM(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER));
|
|
398
|
-
/* D-pad UP Button */
|
|
402
|
+
/* @return [Integer] index for D-pad UP Button */
|
|
399
403
|
rb_define_const(mButton, "DPAD_UP", INT2NUM(SDL_CONTROLLER_BUTTON_DPAD_UP));
|
|
400
|
-
/* D-pad DOWN Button */
|
|
404
|
+
/* @return [Integer] index for D-pad DOWN Button */
|
|
401
405
|
rb_define_const(mButton, "DPAD_DOWN", INT2NUM(SDL_CONTROLLER_BUTTON_DPAD_DOWN));
|
|
402
|
-
/* D-pad LEFT Button */
|
|
406
|
+
/* @return [Integer] index for D-pad LEFT Button */
|
|
403
407
|
rb_define_const(mButton, "DPAD_LEFT", INT2NUM(SDL_CONTROLLER_BUTTON_DPAD_LEFT));
|
|
404
|
-
/* D-pad RIGHT Button */
|
|
408
|
+
/* @return [Integer] index for D-pad RIGHT Button */
|
|
405
409
|
rb_define_const(mButton, "DPAD_RIGHT", INT2NUM(SDL_CONTROLLER_BUTTON_DPAD_RIGHT));
|
|
406
|
-
/* The max of
|
|
410
|
+
/* @return [Integer] The max value of button indices */
|
|
407
411
|
rb_define_const(mButton, "MAX", INT2NUM(SDL_CONTROLLER_BUTTON_MAX));
|
|
408
412
|
}
|
data/gamecontroller.c.m4
CHANGED
|
@@ -17,6 +17,8 @@ static void GameController_free(GameController* g)
|
|
|
17
17
|
free(g);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
DEFINE_DATA_TYPE(GameController, GameController_free);
|
|
21
|
+
|
|
20
22
|
/*
|
|
21
23
|
* Document-class: SDL2::GameController
|
|
22
24
|
*
|
|
@@ -60,9 +62,10 @@ static void GameController_free(GameController* g)
|
|
|
60
62
|
|
|
61
63
|
static VALUE GameController_new(SDL_GameController* controller)
|
|
62
64
|
{
|
|
63
|
-
GameController* g
|
|
65
|
+
GameController* g;
|
|
66
|
+
VALUE obj = TypedData_Make_Struct(cGameController, GameController, &GameController_data_type, g);
|
|
64
67
|
g->controller = controller;
|
|
65
|
-
return
|
|
68
|
+
return obj;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
DEFINE_WRAPPER(SDL_GameController, GameController, controller, cGameController,
|
|
@@ -302,6 +305,7 @@ static VALUE GameController_axis(VALUE self, VALUE axis)
|
|
|
302
305
|
* Return true if a button is pressed.
|
|
303
306
|
*
|
|
304
307
|
* @param button [Integer] the index of a button, one of the constants in {Button}
|
|
308
|
+
* @return [Boolean]
|
|
305
309
|
*/
|
|
306
310
|
static VALUE GameController_button_pressed_p(VALUE self, VALUE button)
|
|
307
311
|
{
|
|
@@ -353,56 +357,56 @@ void rubysdl2_init_gamecontorller(void)
|
|
|
353
357
|
mButton = rb_define_module_under(cGameController, "Button");
|
|
354
358
|
|
|
355
359
|
/* define(`DEFINE_CONTROLLER_AXIS_CONST',`rb_define_const(mAxis, "$1", INT2NUM(SDL_CONTROLLER_AXIS_$1))') */
|
|
356
|
-
/*
|
|
360
|
+
/* @return [Integer] index for invalid axis*/
|
|
357
361
|
DEFINE_CONTROLLER_AXIS_CONST(INVALID);
|
|
358
|
-
/* Left X axis */
|
|
362
|
+
/* @return [Integer] index for Left X axis */
|
|
359
363
|
DEFINE_CONTROLLER_AXIS_CONST(LEFTX);
|
|
360
|
-
/* Left Y axis */
|
|
364
|
+
/* @return [Integer] index for Left Y axis */
|
|
361
365
|
DEFINE_CONTROLLER_AXIS_CONST(LEFTY);
|
|
362
|
-
/* Right X axis */
|
|
366
|
+
/* @return [Integer] index for Right X axis */
|
|
363
367
|
DEFINE_CONTROLLER_AXIS_CONST(RIGHTX);
|
|
364
|
-
/* Right Y axis */
|
|
368
|
+
/* @return [Integer] index for Right Y axis */
|
|
365
369
|
DEFINE_CONTROLLER_AXIS_CONST(RIGHTY);
|
|
366
|
-
/* Left trigger axis */
|
|
370
|
+
/* @return [Integer] index for Left trigger axis */
|
|
367
371
|
DEFINE_CONTROLLER_AXIS_CONST(TRIGGERLEFT);
|
|
368
|
-
/* Right trigger axis */
|
|
372
|
+
/* @return [Integer] index for Right trigger axis */
|
|
369
373
|
DEFINE_CONTROLLER_AXIS_CONST(TRIGGERRIGHT);
|
|
370
|
-
/*
|
|
374
|
+
/* @return [Integer] the max value of axis indices */
|
|
371
375
|
DEFINE_CONTROLLER_AXIS_CONST(MAX);
|
|
372
376
|
|
|
373
377
|
/* define(`DEFINE_CONTROLLER_BUTTON_CONST',`rb_define_const(mButton, "$1", INT2NUM(SDL_CONTROLLER_BUTTON_$1))') */
|
|
374
|
-
/* Invalid button
|
|
378
|
+
/* @return [Integer] index for Invalid button */
|
|
375
379
|
DEFINE_CONTROLLER_BUTTON_CONST(INVALID);
|
|
376
|
-
/* Button A */
|
|
380
|
+
/* @return [Integer] index for Button A */
|
|
377
381
|
DEFINE_CONTROLLER_BUTTON_CONST(A);
|
|
378
|
-
/* Button B */
|
|
382
|
+
/* @return [Integer] index for Button B */
|
|
379
383
|
DEFINE_CONTROLLER_BUTTON_CONST(B);
|
|
380
|
-
/* Button X */
|
|
384
|
+
/* @return [Integer] index for Button X */
|
|
381
385
|
DEFINE_CONTROLLER_BUTTON_CONST(X);
|
|
382
|
-
/* Button Y */
|
|
386
|
+
/* @return [Integer] index for Button Y */
|
|
383
387
|
DEFINE_CONTROLLER_BUTTON_CONST(Y);
|
|
384
|
-
/* Back Button */
|
|
388
|
+
/* @return [Integer] index for Back Button */
|
|
385
389
|
DEFINE_CONTROLLER_BUTTON_CONST(BACK);
|
|
386
|
-
/* Guide Button */
|
|
390
|
+
/* @return [Integer] index for Guide Button */
|
|
387
391
|
DEFINE_CONTROLLER_BUTTON_CONST(GUIDE);
|
|
388
|
-
/* Start Button */
|
|
392
|
+
/* @return [Integer] index for Start Button */
|
|
389
393
|
DEFINE_CONTROLLER_BUTTON_CONST(START);
|
|
390
|
-
/* Left stick Button */
|
|
394
|
+
/* @return [Integer] index for Left stick Button */
|
|
391
395
|
DEFINE_CONTROLLER_BUTTON_CONST(LEFTSTICK);
|
|
392
|
-
/* Right stick Button */
|
|
396
|
+
/* @return [Integer] index for Right stick Button */
|
|
393
397
|
DEFINE_CONTROLLER_BUTTON_CONST(RIGHTSTICK);
|
|
394
|
-
/* Left shoulder Button */
|
|
398
|
+
/* @return [Integer] index for Left shoulder Button */
|
|
395
399
|
DEFINE_CONTROLLER_BUTTON_CONST(LEFTSHOULDER);
|
|
396
|
-
/* Right shoulder Button */
|
|
400
|
+
/* @return [Integer] index for Right shoulder Button */
|
|
397
401
|
DEFINE_CONTROLLER_BUTTON_CONST(RIGHTSHOULDER);
|
|
398
|
-
/* D-pad UP Button */
|
|
402
|
+
/* @return [Integer] index for D-pad UP Button */
|
|
399
403
|
DEFINE_CONTROLLER_BUTTON_CONST(DPAD_UP);
|
|
400
|
-
/* D-pad DOWN Button */
|
|
404
|
+
/* @return [Integer] index for D-pad DOWN Button */
|
|
401
405
|
DEFINE_CONTROLLER_BUTTON_CONST(DPAD_DOWN);
|
|
402
|
-
/* D-pad LEFT Button */
|
|
406
|
+
/* @return [Integer] index for D-pad LEFT Button */
|
|
403
407
|
DEFINE_CONTROLLER_BUTTON_CONST(DPAD_LEFT);
|
|
404
|
-
/* D-pad RIGHT Button */
|
|
408
|
+
/* @return [Integer] index for D-pad RIGHT Button */
|
|
405
409
|
DEFINE_CONTROLLER_BUTTON_CONST(DPAD_RIGHT);
|
|
406
|
-
/* The max of
|
|
410
|
+
/* @return [Integer] The max value of button indices */
|
|
407
411
|
DEFINE_CONTROLLER_BUTTON_CONST(MAX);
|
|
408
412
|
}
|