sdl2-win93 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.dir-locals.el +2 -0
- data/.github/workflows/gempush.yml +29 -0
- data/.gitignore +14 -0
- data/COPYING.txt +165 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +24 -0
- data/Makefile +4 -0
- data/README.md +36 -0
- data/Rakefile +51 -0
- data/doc/po/ja.po +10357 -0
- data/ext/sdl2_ext/clipboard.c +61 -0
- data/ext/sdl2_ext/color.c +103 -0
- data/ext/sdl2_ext/color.h +4 -0
- data/ext/sdl2_ext/event.c +1298 -0
- data/ext/sdl2_ext/extconf.rb +22 -0
- data/ext/sdl2_ext/filesystem.c +63 -0
- data/ext/sdl2_ext/gamecontroller.c +408 -0
- data/ext/sdl2_ext/gamecontroller.c.m4 +408 -0
- data/ext/sdl2_ext/gl.c +351 -0
- data/ext/sdl2_ext/gl.c.m4 +351 -0
- data/ext/sdl2_ext/hint.c +99 -0
- data/ext/sdl2_ext/joystick.c +339 -0
- data/ext/sdl2_ext/joystick.c.m4 +339 -0
- data/ext/sdl2_ext/key.c +1302 -0
- data/ext/sdl2_ext/key.c.m4 +833 -0
- data/ext/sdl2_ext/main.c +258 -0
- data/ext/sdl2_ext/messagebox.c +233 -0
- data/ext/sdl2_ext/mixer.c +1205 -0
- data/ext/sdl2_ext/mixer.c.m4 +1205 -0
- data/ext/sdl2_ext/mouse.c +286 -0
- data/ext/sdl2_ext/rubysdl2_internal.h +127 -0
- data/ext/sdl2_ext/timer.c +63 -0
- data/ext/sdl2_ext/ttf.c +376 -0
- data/ext/sdl2_ext/ttf.c.m4 +376 -0
- data/ext/sdl2_ext/video.c +4093 -0
- data/ext/sdl2_ext/video.c.m4 +3867 -0
- data/lib/sdl2.rb +3 -0
- data/lib/sdl2/event.rb +55 -0
- data/lib/sdl2/version.rb +8 -0
- data/sample/chunk_destroy.rb +16 -0
- data/sample/gfxprimitives.rb +54 -0
- data/sample/icon.bmp +0 -0
- data/sample/memory_test/m1.rb +28 -0
- data/sample/memory_test/m2.rb +18 -0
- data/sample/memory_test/m3.rb +12 -0
- data/sample/message_box.rb +33 -0
- data/sample/music_player.rb +137 -0
- data/sample/playwave.rb +19 -0
- data/sample/primitives.rb +32 -0
- data/sample/test_clipboard.rb +16 -0
- data/sample/test_controller.rb +62 -0
- data/sample/test_joystick.rb +53 -0
- data/sample/test_keyboard.rb +52 -0
- data/sample/test_mouse.rb +50 -0
- data/sample/test_surface.rb +13 -0
- data/sample/test_ttf.rb +82 -0
- data/sample/test_video.rb +59 -0
- data/sample/testgl.rb +175 -0
- data/sample/testsprite.rb +296 -0
- data/sample/testspriteminimal.rb +75 -0
- data/sample/timer.rb +11 -0
- data/sample/version.rb +12 -0
- data/sample/video_info.rb +64 -0
- data/sdl2-win93.gemspec +31 -0
- metadata +158 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
#include "rubysdl2_internal.h"
|
2
|
+
#include <SDL_clipboard.h>
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Document-module: SDL2::Clipboard
|
6
|
+
*
|
7
|
+
* This module has clipboard manipulating functions.
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
|
11
|
+
/*
|
12
|
+
* Get the text from the clipboard.
|
13
|
+
*
|
14
|
+
* @return [String] a string in the clipboard
|
15
|
+
* @return [nil] if the clipboard is empty
|
16
|
+
*/
|
17
|
+
static VALUE Clipboard_s_text(VALUE self)
|
18
|
+
{
|
19
|
+
if (SDL_HasClipboardText()) {
|
20
|
+
char* text = SDL_GetClipboardText();
|
21
|
+
VALUE str;
|
22
|
+
if (!text)
|
23
|
+
SDL_ERROR();
|
24
|
+
str = utf8str_new_cstr(text);
|
25
|
+
SDL_free(text);
|
26
|
+
return str;
|
27
|
+
} else {
|
28
|
+
return Qnil;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
* @overload text=(text)
|
34
|
+
* Set the text in the clipboard.
|
35
|
+
*
|
36
|
+
* @param text [String] a new text
|
37
|
+
* @return [String] text
|
38
|
+
*/
|
39
|
+
static VALUE Clipboard_s_set_text(VALUE self, VALUE text)
|
40
|
+
{
|
41
|
+
HANDLE_ERROR(SDL_SetClipboardText(StringValueCStr(text)));
|
42
|
+
return text;
|
43
|
+
}
|
44
|
+
|
45
|
+
/*
|
46
|
+
* Return true if the clipboard has any text.
|
47
|
+
*
|
48
|
+
*/
|
49
|
+
static VALUE Clipboard_s_has_text_p(VALUE self)
|
50
|
+
{
|
51
|
+
return INT2BOOL(SDL_HasClipboardText());
|
52
|
+
}
|
53
|
+
|
54
|
+
void rubysdl2_init_clipboard(void)
|
55
|
+
{
|
56
|
+
VALUE mClipBoard = rb_define_module_under(mSDL2, "Clipboard");
|
57
|
+
|
58
|
+
rb_define_module_function(mClipBoard, "text", Clipboard_s_text, 0);
|
59
|
+
rb_define_module_function(mClipBoard, "text=", Clipboard_s_set_text, 1);
|
60
|
+
rb_define_module_function(mClipBoard, "has_text?", Clipboard_s_has_text_p, 0);
|
61
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
/*
|
2
|
+
PORTIONS OF THIS ARE BASED ON
|
3
|
+
https://raw.githubusercontent.com/wvanbergen/oily_png/master/ext/oily_png/color.{c,h}
|
4
|
+
|
5
|
+
Original Version Copyright (c) 2010-2014 Willem van Bergen
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
a copy of this software and associated documentation files (the
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
#include <math.h>
|
28
|
+
#include "rubysdl2_internal.h"
|
29
|
+
|
30
|
+
typedef uint32_t PIXEL; // Pixels use 32 bits unsigned integers
|
31
|
+
typedef unsigned char BYTE; // Bytes use 8 bits unsigned integers
|
32
|
+
|
33
|
+
#define R_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0xff000000) >> 24))
|
34
|
+
#define G_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x00ff0000) >> 16))
|
35
|
+
#define B_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x0000ff00) >> 8))
|
36
|
+
#define A_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x000000ff)))
|
37
|
+
|
38
|
+
#define BUILD_PIXEL(r, g, b, a) (((PIXEL) (r) << 24) + ((PIXEL) (g) << 16) + ((PIXEL) (b) << 8) + (PIXEL) (a))
|
39
|
+
|
40
|
+
VALUE Color_s_r(VALUE self, VALUE value) {
|
41
|
+
return INT2FIX(R_BYTE(NUM2UINT(value)));
|
42
|
+
}
|
43
|
+
|
44
|
+
VALUE Color_s_g(VALUE self, VALUE value) {
|
45
|
+
return INT2FIX(G_BYTE(NUM2UINT(value)));
|
46
|
+
}
|
47
|
+
|
48
|
+
VALUE Color_s_b(VALUE self, VALUE value) {
|
49
|
+
return INT2FIX(B_BYTE(NUM2UINT(value)));
|
50
|
+
}
|
51
|
+
|
52
|
+
VALUE Color_s_a(VALUE self, VALUE value) {
|
53
|
+
return INT2FIX(A_BYTE(NUM2UINT(value)));
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE Color_s_rgb(VALUE self, VALUE r, VALUE g, VALUE b) {
|
57
|
+
return UINT2NUM(BUILD_PIXEL(FIX2INT(r),
|
58
|
+
FIX2INT(g),
|
59
|
+
FIX2INT(b),
|
60
|
+
0xFF));
|
61
|
+
}
|
62
|
+
|
63
|
+
VALUE Color_s_rgba(VALUE self, VALUE r, VALUE g, VALUE b, VALUE a) {
|
64
|
+
return UINT2NUM(BUILD_PIXEL(FIX2INT(r),
|
65
|
+
FIX2INT(g),
|
66
|
+
FIX2INT(b),
|
67
|
+
FIX2INT(a)));
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
SDL_Color rubysdl2_Color_to_SDL_Color(VALUE rgba)
|
72
|
+
{
|
73
|
+
SDL_Color color;
|
74
|
+
if (rgba == Qnil) {
|
75
|
+
color.r = color.g = color.b = 0; color.a = 255;
|
76
|
+
return color;
|
77
|
+
} else {
|
78
|
+
PIXEL pixel = NUM2UINT(rgba);
|
79
|
+
color.r = R_BYTE(pixel);
|
80
|
+
color.g = G_BYTE(pixel);
|
81
|
+
color.b = B_BYTE(pixel);
|
82
|
+
color.a = A_BYTE(pixel);
|
83
|
+
return color;
|
84
|
+
}
|
85
|
+
|
86
|
+
}
|
87
|
+
|
88
|
+
void rubysdl2_init_color(void) {
|
89
|
+
VALUE cColor = rb_define_module_under(mSDL2, "Color");
|
90
|
+
rb_define_singleton_method(cColor, "rgb", Color_s_rgb, 3);
|
91
|
+
rb_define_singleton_method(cColor, "rgba", Color_s_rgba, 4);
|
92
|
+
rb_define_singleton_method(cColor, "r", Color_s_r, 1);
|
93
|
+
rb_define_singleton_method(cColor, "g", Color_s_g, 1);
|
94
|
+
rb_define_singleton_method(cColor, "b", Color_s_b, 1);
|
95
|
+
rb_define_singleton_method(cColor, "a", Color_s_a, 1);
|
96
|
+
|
97
|
+
rb_define_const(cColor, "WHITE", UINT2NUM(0xFFFFFFFF));
|
98
|
+
rb_define_const(cColor, "BLACK", UINT2NUM(0x000000FF));
|
99
|
+
rb_define_const(cColor, "RED", UINT2NUM(0xFF0000FF));
|
100
|
+
rb_define_const(cColor, "GREEN", UINT2NUM(0x00FF00FF));
|
101
|
+
rb_define_const(cColor, "BLUE", UINT2NUM(0x0000FFFF));
|
102
|
+
}
|
103
|
+
|
@@ -0,0 +1,1298 @@
|
|
1
|
+
#include "rubysdl2_internal.h"
|
2
|
+
#include <SDL_events.h>
|
3
|
+
#include <SDL_version.h>
|
4
|
+
|
5
|
+
static VALUE cEvent;
|
6
|
+
static VALUE cEvQuit;
|
7
|
+
static VALUE cEvWindow;
|
8
|
+
static VALUE cEvSysWM;
|
9
|
+
static VALUE cEvKeyboard;
|
10
|
+
static VALUE cEvKeyDown;
|
11
|
+
static VALUE cEvKeyUp;
|
12
|
+
static VALUE cEvTextEditing;
|
13
|
+
static VALUE cEvTextInput;
|
14
|
+
static VALUE cEvMouseButton;
|
15
|
+
static VALUE cEvMouseButtonDown;
|
16
|
+
static VALUE cEvMouseButtonUp;
|
17
|
+
static VALUE cEvMouseMotion;
|
18
|
+
static VALUE cEvMouseWheel;
|
19
|
+
static VALUE cEvJoyAxisMotion;
|
20
|
+
static VALUE cEvJoyBallMotion;
|
21
|
+
static VALUE cEvJoyButton;
|
22
|
+
static VALUE cEvJoyButtonDown;
|
23
|
+
static VALUE cEvJoyButtonUp;
|
24
|
+
static VALUE cEvJoyHatMotion;
|
25
|
+
static VALUE cEvJoyDevice;
|
26
|
+
static VALUE cEvJoyDeviceAdded;
|
27
|
+
static VALUE cEvJoyDeviceRemoved;
|
28
|
+
static VALUE cEvControllerAxisMotion;
|
29
|
+
static VALUE cEvControllerButton;
|
30
|
+
static VALUE cEvControllerButtonDown;
|
31
|
+
static VALUE cEvControllerButtonUp;
|
32
|
+
static VALUE cEvControllerDevice;
|
33
|
+
static VALUE cEvControllerDeviceAdded;
|
34
|
+
static VALUE cEvControllerDeviceRemoved;
|
35
|
+
static VALUE cEvControllerDeviceRemapped;
|
36
|
+
static VALUE cEvTouchFinger;
|
37
|
+
static VALUE cEvFingerDown;
|
38
|
+
static VALUE cEvFingerUp;
|
39
|
+
static VALUE cEvFingerMotion;
|
40
|
+
static VALUE cEvMultigesture;
|
41
|
+
/* static VALUE cEvUser; */
|
42
|
+
/* static VALUE cEvDrop; */
|
43
|
+
|
44
|
+
/* TODO:
|
45
|
+
- easy
|
46
|
+
SDL_FlushEvent{,s}
|
47
|
+
SDL_HasEvent{,s}
|
48
|
+
SDL_PumpEvent
|
49
|
+
SDL_PeepEvents
|
50
|
+
SDL_DropEvent
|
51
|
+
SDL_QuitRequested
|
52
|
+
- difficult
|
53
|
+
SDL_PushEvent
|
54
|
+
SDL_WaitEvent{,Timeout}
|
55
|
+
SDL_UserEvent, SDL_RegisterEvents
|
56
|
+
*/
|
57
|
+
|
58
|
+
static VALUE event_type_to_class[SDL_LASTEVENT];
|
59
|
+
|
60
|
+
/*
|
61
|
+
* Document-class: SDL2::Event
|
62
|
+
*
|
63
|
+
* This class represents SDL's events.
|
64
|
+
*
|
65
|
+
* All events are represented by the instance of subclasses of this class.
|
66
|
+
*
|
67
|
+
* # Introduction of event subsystem
|
68
|
+
* Event handling allows your application to receive input from the user. Event handling is
|
69
|
+
* initialized (along with video) with a call to:
|
70
|
+
*
|
71
|
+
* SDL2.init(SDL2::INIT_VIDEO|SDL2::INIT_EVENTS)
|
72
|
+
*
|
73
|
+
* Internally, SDL stores all the events waiting to be handled in an event queue.
|
74
|
+
* Using methods like {SDL2::Event.poll}, you can observe and handle input events.
|
75
|
+
*
|
76
|
+
* The queue is conceptually a sequence of objects of SDL2::Event.
|
77
|
+
* You can read an event from the queue with {SDL2::Event.poll} and
|
78
|
+
* you can process the information from the object.
|
79
|
+
*
|
80
|
+
* Note: peep and wait will be implemented later.
|
81
|
+
*
|
82
|
+
* @attribute [rw] type
|
83
|
+
* SDL's internal event type enum
|
84
|
+
* @return [Integer]
|
85
|
+
*
|
86
|
+
* @attribute [rw] timestamp
|
87
|
+
* timestamp of the event
|
88
|
+
* @return [Integer]
|
89
|
+
*/
|
90
|
+
static VALUE Event_new(SDL_Event* ev)
|
91
|
+
{
|
92
|
+
SDL_Event* e = ALLOC(SDL_Event);
|
93
|
+
*e = *ev;
|
94
|
+
return Data_Wrap_Struct(event_type_to_class[ev->type], 0, free, e);
|
95
|
+
}
|
96
|
+
|
97
|
+
static VALUE Event_s_allocate(VALUE klass)
|
98
|
+
{
|
99
|
+
SDL_Event* e;
|
100
|
+
VALUE event_type = rb_iv_get(klass, "event_type");
|
101
|
+
if (event_type == Qnil)
|
102
|
+
rb_raise(rb_eArgError, "Cannot allocate %s", rb_class2name(klass));
|
103
|
+
|
104
|
+
e = ALLOC(SDL_Event);
|
105
|
+
memset(e, 0, sizeof(SDL_Event));
|
106
|
+
e->common.type = NUM2INT(event_type);
|
107
|
+
return Data_Wrap_Struct(klass, 0, free, e);
|
108
|
+
}
|
109
|
+
|
110
|
+
/*
|
111
|
+
* Poll for currently pending events.
|
112
|
+
*
|
113
|
+
* @return [SDL2::Event] next event from the queue
|
114
|
+
* @return [nil] the queue is empty
|
115
|
+
*/
|
116
|
+
static VALUE Event_s_poll(VALUE self)
|
117
|
+
{
|
118
|
+
SDL_Event ev;
|
119
|
+
if (SDL_PollEvent(&ev)) {
|
120
|
+
return Event_new(&ev);
|
121
|
+
} else {
|
122
|
+
return Qnil;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
/*
|
127
|
+
* Get whether the event is enabled.
|
128
|
+
*
|
129
|
+
* This method is available for subclasses of SDL2::Event corresponding to
|
130
|
+
* SDL's event types.
|
131
|
+
*
|
132
|
+
* @see .enabled=
|
133
|
+
*/
|
134
|
+
static VALUE Event_s_enabled_p(VALUE self)
|
135
|
+
{
|
136
|
+
VALUE event_type = rb_iv_get(self, "event_type");
|
137
|
+
if (event_type == Qnil) {
|
138
|
+
rb_warn("You cannot enable %s directly", rb_class2name(self));
|
139
|
+
return Qfalse;
|
140
|
+
}
|
141
|
+
return INT2BOOL(SDL_EventState(NUM2INT(event_type), SDL_QUERY) == SDL_ENABLE);
|
142
|
+
}
|
143
|
+
|
144
|
+
/*
|
145
|
+
* @overload enable=(bool)
|
146
|
+
* Set wheter the event is enable
|
147
|
+
*
|
148
|
+
* This method is only available for subclasses of SDL2::Event corresponding to
|
149
|
+
* SDL's event types.
|
150
|
+
*
|
151
|
+
* @example disable mouse wheel events
|
152
|
+
* SDL2::Event::MouseWheel.enable = false
|
153
|
+
*
|
154
|
+
* @param [Boolean] bool true for enabling the event.
|
155
|
+
* @return [Boolean]
|
156
|
+
* @see SDL2::Event.enabled?
|
157
|
+
*
|
158
|
+
*/
|
159
|
+
static VALUE Event_s_set_enable(VALUE self, VALUE val)
|
160
|
+
{
|
161
|
+
VALUE event_type = rb_iv_get(self, "event_type");
|
162
|
+
if (event_type == Qnil)
|
163
|
+
rb_raise(rb_eArgError, "You cannot enable %s directly", rb_class2name(self));
|
164
|
+
SDL_EventState(NUM2INT(event_type), RTEST(val) ? SDL_ENABLE : SDL_DISABLE);
|
165
|
+
return val;
|
166
|
+
}
|
167
|
+
|
168
|
+
static void set_string(char* field, VALUE str, int maxlength)
|
169
|
+
{
|
170
|
+
StringValueCStr(str);
|
171
|
+
if (RSTRING_LEN(str) > maxlength)
|
172
|
+
rb_raise(rb_eArgError, "string length must be less than %d", maxlength);
|
173
|
+
strcpy(field, RSTRING_PTR(str));
|
174
|
+
}
|
175
|
+
|
176
|
+
#define EVENT_READER(classname, name, field, c2ruby) \
|
177
|
+
static VALUE Ev##classname##_##name(VALUE self) \
|
178
|
+
{ \
|
179
|
+
SDL_Event* ev; \
|
180
|
+
Data_Get_Struct(self, SDL_Event, ev); \
|
181
|
+
return c2ruby(ev->field); \
|
182
|
+
} \
|
183
|
+
|
184
|
+
#define EVENT_WRITER(classname, name, field, ruby2c) \
|
185
|
+
static VALUE Ev##classname##_set_##name(VALUE self, VALUE val) \
|
186
|
+
{ \
|
187
|
+
SDL_Event* ev; \
|
188
|
+
Data_Get_Struct(self, SDL_Event, ev); \
|
189
|
+
ev->field = ruby2c(val); \
|
190
|
+
return Qnil; \
|
191
|
+
}
|
192
|
+
|
193
|
+
#define EVENT_ACCESSOR(classname, name, field, ruby2c, c2ruby) \
|
194
|
+
EVENT_READER(classname, name, field, c2ruby) \
|
195
|
+
EVENT_WRITER(classname, name, field, ruby2c)
|
196
|
+
|
197
|
+
#define EVENT_ACCESSOR_UINT(classname, name, field) \
|
198
|
+
EVENT_ACCESSOR(classname, name, field, NUM2UINT, UINT2NUM)
|
199
|
+
|
200
|
+
#define EVENT_ACCESSOR_UINT8(classname, name, field) \
|
201
|
+
EVENT_ACCESSOR(classname, name, field, NUM2UCHAR, UCHAR2NUM)
|
202
|
+
|
203
|
+
#define EVENT_ACCESSOR_INT(classname, name, field) \
|
204
|
+
EVENT_ACCESSOR(classname, name, field, NUM2INT, INT2NUM)
|
205
|
+
|
206
|
+
#define EVENT_ACCESSOR_DBL(classname, name, field) \
|
207
|
+
EVENT_ACCESSOR(classname, name, field, NUM2DBL, DBL2NUM)
|
208
|
+
|
209
|
+
#define EVENT_ACCESSOR_BOOL(classname, name, field) \
|
210
|
+
EVENT_ACCESSOR(classname, name, field, RTEST, INT2BOOL)
|
211
|
+
|
212
|
+
|
213
|
+
EVENT_READER(Event, type, common.type, INT2NUM);
|
214
|
+
EVENT_ACCESSOR_UINT(Event, timestamp, common.timestamp);
|
215
|
+
/* @return [String] inspection string */
|
216
|
+
static VALUE Event_inspect(VALUE self)
|
217
|
+
{
|
218
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
219
|
+
return rb_sprintf("<%s: type=%u timestamp=%u>",
|
220
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp);
|
221
|
+
}
|
222
|
+
|
223
|
+
/*
|
224
|
+
* Return the object of {SDL2::Window} corresponding to the window_id attribute.
|
225
|
+
*
|
226
|
+
* Some subclasses of SDL2::Event have window_id attribute to point the
|
227
|
+
* window which creates the event. The type of the window_id attribute
|
228
|
+
* is integer, and you need to convert it with {SDL2::Window.find_by_id}
|
229
|
+
* to get the {SDL2::Window} object. This method returns the {SDL2::Window}
|
230
|
+
* object.
|
231
|
+
*
|
232
|
+
* @return [SDL2::Window] the window which creates the event.
|
233
|
+
* @raise [NoMethodError] raised if the window_id attribute is not present.
|
234
|
+
*/
|
235
|
+
static VALUE Event_window(VALUE self)
|
236
|
+
{
|
237
|
+
VALUE window_id = rb_funcall(self, rb_intern("window_id"), 0);
|
238
|
+
return find_window_by_id(NUM2UINT(window_id));
|
239
|
+
}
|
240
|
+
|
241
|
+
/*
|
242
|
+
* Document-class: SDL2::Event::Quit
|
243
|
+
*
|
244
|
+
* This class represents the quit requested event.
|
245
|
+
*
|
246
|
+
* This event occurs when a user try to close window, command-Q on OS X,
|
247
|
+
* or any other quit request by a user. Normally if your application
|
248
|
+
* receive this event, the application should exit. But the application
|
249
|
+
* can query something to the users like "save", or ignore it.
|
250
|
+
*/
|
251
|
+
|
252
|
+
/*
|
253
|
+
* Document-class: SDL2::Event::Window
|
254
|
+
*
|
255
|
+
* This class represents window event. This type of event occurs when
|
256
|
+
* window state is changed.
|
257
|
+
*
|
258
|
+
* @attribute [rw] window_id
|
259
|
+
* the associate window id
|
260
|
+
* @return [Integer]
|
261
|
+
*
|
262
|
+
* @attribute [rw] event
|
263
|
+
* event type, one of the following:
|
264
|
+
*
|
265
|
+
* * SDL2::Event::Window::NONE - (never used)
|
266
|
+
* * SDL2::Event::Window::SHOWN - window has been shown
|
267
|
+
* * SDL2::Event::Window::HIDDEN - window has been hidden
|
268
|
+
* * SDL2::Event::Window::EXPOSED - window has been exposed and should be redrawn
|
269
|
+
* * SDL2::Event::Window::MOVED - window has been moved to data1, data2
|
270
|
+
* * SDL2::Event::Window::RESIZED - window has been resized to data1xdata2;
|
271
|
+
* this is event is always preceded by SIZE_CHANGED
|
272
|
+
* * SDL2::Event::Window::SIZE_CHANGED -
|
273
|
+
* window size has changed, either as a result of an API call or through
|
274
|
+
* the system or user changing the window size;
|
275
|
+
* this event is followed by
|
276
|
+
* RESIZED if the size was changed by an external event,
|
277
|
+
* i.e. the user or the window manager
|
278
|
+
* * SDL2::Event::Window::MINIMIZED - window has been minimized
|
279
|
+
* * SDL2::Event::Window::MAXIMIZED - window has been maximized
|
280
|
+
* * SDL2::Event::Window::RESTORED - window has been restored to normal size and position
|
281
|
+
* * SDL2::Event::Window::ENTER - window has gained mouse focus
|
282
|
+
* * SDL2::Event::Window::LEAVE - window has lost mouse focus
|
283
|
+
* * SDL2::Event::Window::FOCUS_GAINED - window has gained keyboard focus
|
284
|
+
* * SDL2::Event::Window::FOCUS_LOST -window has lost keyboard focus
|
285
|
+
* * SDL2::Event::Window::CLOSE -
|
286
|
+
* the window manager requests that the window be closed
|
287
|
+
*
|
288
|
+
* @return [Integer]
|
289
|
+
*
|
290
|
+
* @attribute data1
|
291
|
+
* event dependent data
|
292
|
+
* @return [Integer]
|
293
|
+
*
|
294
|
+
* @attribute data2
|
295
|
+
* event dependent data
|
296
|
+
* @return [Integer]
|
297
|
+
*
|
298
|
+
*/
|
299
|
+
EVENT_ACCESSOR_UINT(Window, window_id, window.windowID);
|
300
|
+
EVENT_ACCESSOR_UINT(Window, event, window.event);
|
301
|
+
EVENT_ACCESSOR_INT(Window, data1, window.data1);
|
302
|
+
EVENT_ACCESSOR_INT(Window, data2, window.data2);
|
303
|
+
|
304
|
+
/* @return [String] inspection string */
|
305
|
+
static VALUE EvWindow_inspect(VALUE self)
|
306
|
+
{
|
307
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
308
|
+
return rb_sprintf("<%s: type=%u timestamp=%u window_id=%u event=%u data1=%d data2=%d>",
|
309
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
310
|
+
ev->window.windowID, ev->window.event,
|
311
|
+
ev->window.data1, ev->window.data2);
|
312
|
+
}
|
313
|
+
|
314
|
+
/*
|
315
|
+
* Document-class: SDL2::Event::Keyboard
|
316
|
+
*
|
317
|
+
* This class represents keyboard event.
|
318
|
+
*
|
319
|
+
* You don't handle the instance
|
320
|
+
* of this class directly, but you handle the instances of
|
321
|
+
* two subclasses of this subclasses:
|
322
|
+
* {SDL2::Event::KeyDown} and {SDL2::Event::KeyUp}.
|
323
|
+
*
|
324
|
+
* @attribute [rw] window_id
|
325
|
+
* the associate window id
|
326
|
+
* @return [Integer]
|
327
|
+
*
|
328
|
+
* @attribute pressed
|
329
|
+
* key is pressed
|
330
|
+
* @return [Integer]
|
331
|
+
*
|
332
|
+
* @attribute repeat
|
333
|
+
* key repeat
|
334
|
+
* @return [Integer]
|
335
|
+
*
|
336
|
+
* @attribute scancode
|
337
|
+
* physical key code
|
338
|
+
* @return [Integer]
|
339
|
+
* @see SDL2::Key::Scan
|
340
|
+
*
|
341
|
+
* @attribute sym
|
342
|
+
* virtual key code
|
343
|
+
* @return [Integer]
|
344
|
+
* @see SDL2::Key
|
345
|
+
*
|
346
|
+
* @attribute mod
|
347
|
+
* current key modifier
|
348
|
+
* @return [Integer]
|
349
|
+
* @see SDL2::Key::Mod
|
350
|
+
*
|
351
|
+
*/
|
352
|
+
EVENT_ACCESSOR_UINT(Keyboard, window_id, key.windowID);
|
353
|
+
EVENT_ACCESSOR_BOOL(Keyboard, pressed, key.state);
|
354
|
+
EVENT_ACCESSOR_BOOL(Keyboard, repeat, key.repeat);
|
355
|
+
EVENT_ACCESSOR_UINT(Keyboard, scancode, key.keysym.scancode);
|
356
|
+
EVENT_ACCESSOR_UINT(Keyboard, sym, key.keysym.sym);
|
357
|
+
EVENT_ACCESSOR_UINT(Keyboard, mod, key.keysym.mod);
|
358
|
+
/* @return [String] inspection string */
|
359
|
+
static VALUE EvKeyboard_inspect(VALUE self)
|
360
|
+
{
|
361
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
362
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
363
|
+
" window_id=%u state=%u repeat=%u"
|
364
|
+
" scancode=%u sym=%u mod=%u>",
|
365
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
366
|
+
ev->key.windowID, ev->key.state, ev->key.repeat,
|
367
|
+
ev->key.keysym.scancode, ev->key.keysym.sym, ev->key.keysym.mod);
|
368
|
+
}
|
369
|
+
|
370
|
+
|
371
|
+
/*
|
372
|
+
* Document-class: SDL2::Event::KeyDown
|
373
|
+
*
|
374
|
+
* This class represents a key down event.
|
375
|
+
*/
|
376
|
+
|
377
|
+
/*
|
378
|
+
* Document-class: SDL2::Event::KeyUp
|
379
|
+
*
|
380
|
+
* This class represents a key up event.
|
381
|
+
*/
|
382
|
+
|
383
|
+
/*
|
384
|
+
* Document-class: SDL2::Event::TextEditing
|
385
|
+
*
|
386
|
+
* This class represents text editing event.
|
387
|
+
*
|
388
|
+
* @attribute window_id
|
389
|
+
* the associate window id
|
390
|
+
* @return [Integer]
|
391
|
+
*
|
392
|
+
* @attribute text
|
393
|
+
* the editing text
|
394
|
+
* @return [String]
|
395
|
+
*
|
396
|
+
* @attribute start
|
397
|
+
* the start cursor of selected editing text
|
398
|
+
* @return [Integer]
|
399
|
+
*
|
400
|
+
* @attribute length
|
401
|
+
* the length of selected editing text
|
402
|
+
* @return [Integer]
|
403
|
+
*/
|
404
|
+
EVENT_ACCESSOR_UINT(TextEditing, window_id, edit.windowID);
|
405
|
+
EVENT_ACCESSOR_INT(TextEditing, start, edit.start);
|
406
|
+
EVENT_ACCESSOR_INT(TextEditing, length, edit.length);
|
407
|
+
EVENT_READER(TextEditing, text, edit.text, utf8str_new_cstr);
|
408
|
+
static VALUE EvTextEditing_set_text(VALUE self, VALUE str)
|
409
|
+
{
|
410
|
+
SDL_Event* ev;
|
411
|
+
Data_Get_Struct(self, SDL_Event, ev);
|
412
|
+
set_string(ev->edit.text, str, 30);
|
413
|
+
return str;
|
414
|
+
}
|
415
|
+
|
416
|
+
/* @return [String] inspection string */
|
417
|
+
static VALUE EvTextEditing_inspect(VALUE self)
|
418
|
+
{
|
419
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
420
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
421
|
+
" window_id=%u text=%s start=%d length=%d>",
|
422
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
423
|
+
ev->edit.windowID, ev->edit.text, ev->edit.start, ev->edit.length);
|
424
|
+
}
|
425
|
+
|
426
|
+
|
427
|
+
/*
|
428
|
+
* Document-class: SDL2::Event::TextInput
|
429
|
+
*
|
430
|
+
* This class represents text input events.
|
431
|
+
*
|
432
|
+
* @attribute window_id
|
433
|
+
* the associate window id
|
434
|
+
* @return [Integer]
|
435
|
+
*
|
436
|
+
* @attribute text
|
437
|
+
* the input text
|
438
|
+
* @return [String]
|
439
|
+
*/
|
440
|
+
EVENT_ACCESSOR_UINT(TextInput, window_id, text.windowID);
|
441
|
+
EVENT_READER(TextInput, text, text.text, utf8str_new_cstr);
|
442
|
+
static VALUE EvTextInput_set_text(VALUE self, VALUE str)
|
443
|
+
{
|
444
|
+
SDL_Event* ev;
|
445
|
+
Data_Get_Struct(self, SDL_Event, ev);
|
446
|
+
set_string(ev->text.text, str, 30);
|
447
|
+
return str;
|
448
|
+
}
|
449
|
+
|
450
|
+
/* @return [String] inspection string */
|
451
|
+
static VALUE EvTextInput_inspect(VALUE self)
|
452
|
+
{
|
453
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
454
|
+
return rb_sprintf("<%s: type=%u timestamp=%u window_id=%u text=%s>",
|
455
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
456
|
+
ev->text.windowID, ev->text.text);
|
457
|
+
}
|
458
|
+
|
459
|
+
/*
|
460
|
+
* Document-class: SDL2::Event::MouseButton
|
461
|
+
*
|
462
|
+
* This class represents mouse button events.
|
463
|
+
*
|
464
|
+
* You don't handle the instance
|
465
|
+
* of this class directly, but you handle the instances of
|
466
|
+
* two subclasses of this subclasses:
|
467
|
+
* {SDL2::Event::MouseButtonDown} and {SDL2::Event::MouseButtonUp}.
|
468
|
+
*
|
469
|
+
* @attribute window_id
|
470
|
+
* the window id with mouse focus
|
471
|
+
* @return [Integer]
|
472
|
+
*
|
473
|
+
* @attribute which
|
474
|
+
* the mouse index
|
475
|
+
* @return [Integer]
|
476
|
+
*
|
477
|
+
* @attribute button
|
478
|
+
* the mouse button index
|
479
|
+
* @return [Integer]
|
480
|
+
*
|
481
|
+
* @attribute pressed
|
482
|
+
* button is pressed or not
|
483
|
+
* @return [Boolean]
|
484
|
+
*
|
485
|
+
* @attribute clicks
|
486
|
+
* 1 for single click, 2 for double click
|
487
|
+
*
|
488
|
+
* This attribute is available after SDL 2.0.2
|
489
|
+
* @return [Integer]
|
490
|
+
*
|
491
|
+
* @attribute x
|
492
|
+
* the x coordinate of the mouse pointer, relative to window
|
493
|
+
* @return [Integer]
|
494
|
+
*
|
495
|
+
* @attribute y
|
496
|
+
* the y coordinate of the mouse pointer, relative to window
|
497
|
+
* @return [Integer]
|
498
|
+
*/
|
499
|
+
EVENT_ACCESSOR_UINT(MouseButton, window_id, button.windowID);
|
500
|
+
EVENT_ACCESSOR_UINT(MouseButton, which, button.which);
|
501
|
+
EVENT_ACCESSOR_UINT8(MouseButton, button, button.button);
|
502
|
+
EVENT_ACCESSOR_BOOL(MouseButton, pressed, button.state);
|
503
|
+
#if SDL_VERSION_ATLEAST(2,0,2)
|
504
|
+
EVENT_ACCESSOR_UINT8(MouseButton, clicks, button.clicks);
|
505
|
+
#endif
|
506
|
+
EVENT_ACCESSOR_INT(MouseButton, x, button.x);
|
507
|
+
EVENT_ACCESSOR_INT(MouseButton, y, button.y);
|
508
|
+
/* @return [String] inspection string */
|
509
|
+
static VALUE EvMouseButton_inspect(VALUE self)
|
510
|
+
{
|
511
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
512
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
513
|
+
" window_id=%u which=%u button=%hhu pressed=%s"
|
514
|
+
#if SDL_VERSION_ATLEAST(2,0,2)
|
515
|
+
" clicks=%hhu"
|
516
|
+
#endif
|
517
|
+
" x=%d y=%d>",
|
518
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
519
|
+
ev->button.windowID, ev->button.which,
|
520
|
+
ev->button.button, INT2BOOLCSTR(ev->button.state),
|
521
|
+
#if SDL_VERSION_ATLEAST(2,0,2)
|
522
|
+
ev->button.clicks,
|
523
|
+
#endif
|
524
|
+
ev->button.x, ev->button.y);
|
525
|
+
}
|
526
|
+
|
527
|
+
/*
|
528
|
+
* Document-class: SDL2::Event::MouseButtonDown
|
529
|
+
* This class represents mouse button press events.
|
530
|
+
*/
|
531
|
+
/*
|
532
|
+
* Document-class: SDL2::Event::MouseButtonUp
|
533
|
+
* This class represents mouse button release events.
|
534
|
+
*/
|
535
|
+
|
536
|
+
/*
|
537
|
+
* Document-class: SDL2::Event::MouseMotion
|
538
|
+
*
|
539
|
+
* This class represents mouse motion events.
|
540
|
+
*
|
541
|
+
* @attribute window_id
|
542
|
+
* the window id with mouse focus
|
543
|
+
* @return [Integer]
|
544
|
+
*
|
545
|
+
* @attribute which
|
546
|
+
* the mouse index
|
547
|
+
* @return [Integer]
|
548
|
+
*
|
549
|
+
* @attribute state
|
550
|
+
* the current mouse state
|
551
|
+
* @return [Integer]
|
552
|
+
* @todo use SDL2::Mouse::State
|
553
|
+
*
|
554
|
+
* @attribute x
|
555
|
+
* the x coordinate of the mouse pointer, relative to window
|
556
|
+
* @return [Integer]
|
557
|
+
*
|
558
|
+
* @attribute y
|
559
|
+
* the y coordinate of the mouse pointer, relative to window
|
560
|
+
* @return [Integer]
|
561
|
+
*
|
562
|
+
* @attribute xrel
|
563
|
+
* the relative motion in the x direction
|
564
|
+
* @return [Integer]
|
565
|
+
*
|
566
|
+
* @attribute yrel
|
567
|
+
* the relative motion in the y direction
|
568
|
+
* @return [Integer]
|
569
|
+
*/
|
570
|
+
EVENT_ACCESSOR_UINT(MouseMotion, window_id, motion.windowID);
|
571
|
+
EVENT_ACCESSOR_UINT(MouseMotion, which, motion.which);
|
572
|
+
EVENT_ACCESSOR_UINT(MouseMotion, state, motion.state);
|
573
|
+
EVENT_ACCESSOR_INT(MouseMotion, x, motion.x);
|
574
|
+
EVENT_ACCESSOR_INT(MouseMotion, y, motion.y);
|
575
|
+
EVENT_ACCESSOR_INT(MouseMotion, xrel, motion.xrel);
|
576
|
+
EVENT_ACCESSOR_INT(MouseMotion, yrel, motion.yrel);
|
577
|
+
/* @return [String] inspection string */
|
578
|
+
static VALUE EvMouseMotion_inspect(VALUE self)
|
579
|
+
{
|
580
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
581
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
582
|
+
" window_id=%u which=%u state=%u"
|
583
|
+
" x=%d y=%d xrel=%d yrel=%d>",
|
584
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
585
|
+
ev->motion.windowID, ev->motion.which, ev->motion.state,
|
586
|
+
ev->motion.x, ev->motion.y, ev->motion.xrel, ev->motion.yrel);
|
587
|
+
}
|
588
|
+
|
589
|
+
/*
|
590
|
+
* Document-class: SDL2::Event::MouseWheel
|
591
|
+
*
|
592
|
+
* This class represents mouse wheel events.
|
593
|
+
*
|
594
|
+
* @attribute window_id
|
595
|
+
* the window id with mouse focus
|
596
|
+
* @return [Integer]
|
597
|
+
*
|
598
|
+
* @attribute which
|
599
|
+
* the mouse index
|
600
|
+
* @return [Integer]
|
601
|
+
*
|
602
|
+
* @attribute x
|
603
|
+
* the amount of scrolled horizontally, positive to the right and negative
|
604
|
+
* to the left
|
605
|
+
* @return [Integer]
|
606
|
+
*
|
607
|
+
* @attribute y
|
608
|
+
* the amount of scrolled vertically, positve away from the user and negative
|
609
|
+
* toward the user
|
610
|
+
* @return [Integer]
|
611
|
+
*/
|
612
|
+
EVENT_ACCESSOR_UINT(MouseWheel, window_id, wheel.windowID);
|
613
|
+
EVENT_ACCESSOR_UINT(MouseWheel, which, wheel.which);
|
614
|
+
EVENT_ACCESSOR_INT(MouseWheel, x, wheel.x);
|
615
|
+
EVENT_ACCESSOR_INT(MouseWheel, y, wheel.y);
|
616
|
+
/* @return [String] inspection string */
|
617
|
+
static VALUE EvMouseWheel_inspect(VALUE self)
|
618
|
+
{
|
619
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
620
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
621
|
+
" window_id=%u which=%u x=%d y=%d>",
|
622
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
623
|
+
ev->wheel.windowID, ev->wheel.which, ev->wheel.x, ev->wheel.y);
|
624
|
+
}
|
625
|
+
|
626
|
+
/*
|
627
|
+
* Document-class: SDL2::Event::JoyButton
|
628
|
+
*
|
629
|
+
* This class represents joystick button events.
|
630
|
+
*
|
631
|
+
* You don't handle the instance
|
632
|
+
* of this class directly, but you handle the instances of
|
633
|
+
* two subclasses of this subclasses:
|
634
|
+
* {SDL2::Event::JoyButtonDown} and {SDL2::Event::JoyButtonUp}.
|
635
|
+
*
|
636
|
+
* @attribute which
|
637
|
+
* the joystick index
|
638
|
+
* @return [Integer]
|
639
|
+
*
|
640
|
+
* @attribute button
|
641
|
+
* the joystick button index
|
642
|
+
* @return [Integer]
|
643
|
+
*
|
644
|
+
* @attribute pressed
|
645
|
+
* button is pressed or not
|
646
|
+
* @return [Boolean]
|
647
|
+
*
|
648
|
+
*/
|
649
|
+
EVENT_ACCESSOR_INT(JoyButton, which, jbutton.which);
|
650
|
+
EVENT_ACCESSOR_UINT8(JoyButton, button, jbutton.button);
|
651
|
+
EVENT_ACCESSOR_BOOL(JoyButton, pressed, jbutton.state);
|
652
|
+
/* @return [String] inspection string */
|
653
|
+
static VALUE EvJoyButton_inspect(VALUE self)
|
654
|
+
{
|
655
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
656
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
657
|
+
" which=%d button=%u pressed=%s>",
|
658
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
659
|
+
ev->jbutton.which, ev->jbutton.button,
|
660
|
+
INT2BOOLCSTR(ev->jbutton.state));
|
661
|
+
}
|
662
|
+
/*
|
663
|
+
* Document-class: SDL2::Event::JoyButtonDown
|
664
|
+
*
|
665
|
+
* This class represents the joystick button press events.
|
666
|
+
*/
|
667
|
+
|
668
|
+
/*
|
669
|
+
* Document-class: SDL2::Event::JoyButtonUp
|
670
|
+
*
|
671
|
+
* This class represents the joystick button release events.
|
672
|
+
*/
|
673
|
+
|
674
|
+
/*
|
675
|
+
* Document-class: SDL2::Event::JoyAxisMotion
|
676
|
+
*
|
677
|
+
* This class represents the joystick axis motion events.
|
678
|
+
*
|
679
|
+
* @attribute which
|
680
|
+
* the joystick index
|
681
|
+
* @return [Integer]
|
682
|
+
*
|
683
|
+
* @attribute axis
|
684
|
+
* the axis index
|
685
|
+
* @return [Integer]
|
686
|
+
*
|
687
|
+
* @attribute value
|
688
|
+
* the axis value (range: -32768 to -32767, 0 for newtral)
|
689
|
+
* @return [Integer]
|
690
|
+
*/
|
691
|
+
EVENT_ACCESSOR_INT(JoyAxisMotion, which, jaxis.which);
|
692
|
+
EVENT_ACCESSOR_UINT8(JoyAxisMotion, axis, jaxis.axis);
|
693
|
+
EVENT_ACCESSOR_INT(JoyAxisMotion, value, jaxis.value);
|
694
|
+
/* @return [Stirng] inspection string */
|
695
|
+
static VALUE EvJoyAxisMotion_inspect(VALUE self)
|
696
|
+
{
|
697
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
698
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
699
|
+
" which=%d axis=%u value=%d>",
|
700
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
701
|
+
ev->jaxis.which, ev->jaxis.axis, ev->jaxis.value);
|
702
|
+
}
|
703
|
+
|
704
|
+
/*
|
705
|
+
* Document-class: SDL2::Event::JoyBallMotion
|
706
|
+
*
|
707
|
+
* This class represents the joystick trackball motion events.
|
708
|
+
*
|
709
|
+
* @attribute which
|
710
|
+
* the joystick index
|
711
|
+
* @return [Integer]
|
712
|
+
*
|
713
|
+
* @attribute ball
|
714
|
+
* the joystick trackball index
|
715
|
+
* @return [Integer]
|
716
|
+
*
|
717
|
+
* @attribute xrel
|
718
|
+
* the relative motion in the x direction
|
719
|
+
* @return [Integer]
|
720
|
+
*
|
721
|
+
* @attribute yrel
|
722
|
+
* the relative motion in the y direction
|
723
|
+
* @return [Integer]
|
724
|
+
*/
|
725
|
+
EVENT_ACCESSOR_INT(JoyBallMotion, which, jball.which);
|
726
|
+
EVENT_ACCESSOR_UINT8(JoyBallMotion, ball, jball.ball);
|
727
|
+
EVENT_ACCESSOR_INT(JoyBallMotion, xrel, jball.xrel);
|
728
|
+
EVENT_ACCESSOR_INT(JoyBallMotion, yrel, jball.yrel);
|
729
|
+
/* @return [String] inspection string */
|
730
|
+
static VALUE EvJoyBallMotion_inspect(VALUE self)
|
731
|
+
{
|
732
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
733
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
734
|
+
" which=%d ball=%u xrel=%d yrel=%d>",
|
735
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
736
|
+
ev->jball.which, ev->jball.ball, ev->jball.xrel, ev->jball.yrel);
|
737
|
+
}
|
738
|
+
|
739
|
+
/*
|
740
|
+
* Document-class: SDL2::Event::JoyHatMotion
|
741
|
+
*
|
742
|
+
* This class represents the joystick hat position change events.
|
743
|
+
*
|
744
|
+
* @attribute which
|
745
|
+
* the joystick index
|
746
|
+
* @return [Integer]
|
747
|
+
*
|
748
|
+
* @attribute hat
|
749
|
+
* the joystick hat index
|
750
|
+
* @return [Integer]
|
751
|
+
*
|
752
|
+
* @attribute value
|
753
|
+
* the hat position value, same value as {SDL2::Joystick#hat}.
|
754
|
+
* @return [Integer]
|
755
|
+
*/
|
756
|
+
EVENT_ACCESSOR_INT(JoyHatMotion, which, jhat.which);
|
757
|
+
EVENT_ACCESSOR_UINT8(JoyHatMotion, hat, jhat.hat);
|
758
|
+
EVENT_ACCESSOR_UINT8(JoyHatMotion, value, jhat.value);
|
759
|
+
/* @return [String] inspection string */
|
760
|
+
static VALUE EvJoyHatMotion_inspect(VALUE self)
|
761
|
+
{
|
762
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
763
|
+
return rb_sprintf("<%s: type=%u timestamp=%u which=%d hat=%u value=%u>",
|
764
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
765
|
+
ev->jhat.which, ev->jhat.hat, ev->jhat.value);
|
766
|
+
}
|
767
|
+
|
768
|
+
/*
|
769
|
+
* Document-class: SDL2::Event::JoyDevice
|
770
|
+
*
|
771
|
+
* This class represents joystick device events
|
772
|
+
* ({SDL2::Event::JoyDeviceAdded joystick connected events} and
|
773
|
+
* {SDL2::Event::JoyDeviceRemoved joystick disconnected events}).
|
774
|
+
*/
|
775
|
+
EVENT_ACCESSOR_INT(JoyDevice, which, jdevice.which);
|
776
|
+
/* @return [String] inspection string */
|
777
|
+
static VALUE EvJoyDevice_inspect(VALUE self)
|
778
|
+
{
|
779
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
780
|
+
return rb_sprintf("<%s: type=%u timestamp=%u which=%d>",
|
781
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
782
|
+
ev->jdevice.which);
|
783
|
+
}
|
784
|
+
|
785
|
+
/*
|
786
|
+
* Document-class: SDL2::Event::JoyDeviceAdded
|
787
|
+
*
|
788
|
+
* This class represents joystick device connected events.
|
789
|
+
*/
|
790
|
+
/*
|
791
|
+
* Document-class: SDL2::Event::JoyDeviceRemoved
|
792
|
+
*
|
793
|
+
* This class represents joystick device disconnected events.
|
794
|
+
*/
|
795
|
+
|
796
|
+
|
797
|
+
/*
|
798
|
+
* Document-class: SDL2::Event::ControllerAxisMotion
|
799
|
+
*
|
800
|
+
* This class represents the {SDL2::GameController controller} axis motion events.
|
801
|
+
*
|
802
|
+
* @attribute which
|
803
|
+
* the controller index
|
804
|
+
* @return [Integer]
|
805
|
+
*
|
806
|
+
* @attribute axis
|
807
|
+
* the axis index
|
808
|
+
* @return [Integer]
|
809
|
+
*
|
810
|
+
* @attribute value
|
811
|
+
* the axis value (range: -32768 to -32767, 0 for newtral)
|
812
|
+
* @return [Integer]
|
813
|
+
*/
|
814
|
+
EVENT_ACCESSOR_INT(ControllerAxis, which, caxis.which);
|
815
|
+
EVENT_ACCESSOR_UINT8(ControllerAxis, axis, caxis.axis);
|
816
|
+
EVENT_ACCESSOR_INT(ControllerAxis, value, caxis.value);
|
817
|
+
/* @return [String] inspection string */
|
818
|
+
static VALUE ControllerAxis_inspect(VALUE self)
|
819
|
+
{
|
820
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
821
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
822
|
+
" which=%d axis=%s value=%d>",
|
823
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
824
|
+
ev->caxis.which, SDL_GameControllerGetStringForAxis(ev->caxis.axis),
|
825
|
+
ev->caxis.value);
|
826
|
+
}
|
827
|
+
|
828
|
+
/*
|
829
|
+
* Document-class: SDL2::Event::ControllerButton
|
830
|
+
*
|
831
|
+
* This class represents the {SDL2::GameController controller} button events.
|
832
|
+
*
|
833
|
+
* You don't handle the instance
|
834
|
+
* of this class directly, but you handle the instances of
|
835
|
+
* two subclasses of this subclasses:
|
836
|
+
* {SDL2::Event::ControllerButtonDown} and {SDL2::Event::ControllerButtonUp}.
|
837
|
+
*
|
838
|
+
* @attribute which
|
839
|
+
* the controller index
|
840
|
+
* @return [Integer]
|
841
|
+
*
|
842
|
+
* @attribute button
|
843
|
+
* the controller button index
|
844
|
+
* @return [Integer]
|
845
|
+
*
|
846
|
+
* @attribute pressed
|
847
|
+
* button is pressed or not
|
848
|
+
* @return [Boolean]
|
849
|
+
*
|
850
|
+
*/
|
851
|
+
EVENT_ACCESSOR_INT(ControllerButton, which, cbutton.which);
|
852
|
+
EVENT_ACCESSOR_UINT8(ControllerButton, button, cbutton.button);
|
853
|
+
EVENT_ACCESSOR_BOOL(ControllerButton, pressed, cbutton.state);
|
854
|
+
/* @return [String] inspection string */
|
855
|
+
static VALUE ControllerButton_inspect(VALUE self)
|
856
|
+
{
|
857
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
858
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
859
|
+
" which=%d button=%s state=%s>",
|
860
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
861
|
+
ev->cbutton.which,
|
862
|
+
SDL_GameControllerGetStringForButton(ev->cbutton.button),
|
863
|
+
INT2BOOLCSTR(ev->cbutton.state));
|
864
|
+
}
|
865
|
+
/*
|
866
|
+
* Document-class: SDL2::Event::ControllerButtonDown
|
867
|
+
*
|
868
|
+
* This class represents the {SDL2::GameController controller} button press events.
|
869
|
+
*/
|
870
|
+
|
871
|
+
/*
|
872
|
+
* Document-class: SDL2::Event::ControllerButtonUp
|
873
|
+
*
|
874
|
+
* This class represents the {SDL2::GameController controller} button release events.
|
875
|
+
*/
|
876
|
+
|
877
|
+
/*
|
878
|
+
* Document-class: SDL2::Event::ControllerDevice
|
879
|
+
*
|
880
|
+
* This class represents {SDL2::GameController controller} device events (connected/disconnected/remapped).
|
881
|
+
*
|
882
|
+
* The event of this event doesn't occur. Only the event of the following subclasses
|
883
|
+
* occur in Ruby/SDL2.
|
884
|
+
*
|
885
|
+
* * {SDL2::Event::ControllerDeviceAdded}
|
886
|
+
* * {SDL2::Event::ControllerDeviceRemoved}
|
887
|
+
* * {SDL2::Event::ControllerDeviceRemapped}
|
888
|
+
*
|
889
|
+
* @attribute which
|
890
|
+
* the controller index
|
891
|
+
* @return [Integer]
|
892
|
+
*/
|
893
|
+
EVENT_ACCESSOR_INT(ControllerDevice, which, cdevice.which);
|
894
|
+
/* @return [String] inspection string */
|
895
|
+
static VALUE ControllerDevice_inspect(VALUE self)
|
896
|
+
{
|
897
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
898
|
+
return rb_sprintf("<%s: type=%u timestamp=%u which=%d>",
|
899
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
900
|
+
ev->cdevice.which);
|
901
|
+
}
|
902
|
+
|
903
|
+
/*
|
904
|
+
* Document-class: SDL2::Event::ControllerDeviceAdded
|
905
|
+
*
|
906
|
+
* This class represents {SDL2::GameController controller} device connected events.
|
907
|
+
*/
|
908
|
+
/*
|
909
|
+
* Document-class: SDL2::Event::ControllerDeviceRemoved
|
910
|
+
*
|
911
|
+
* This class represents {SDL2::GameController controller} device disconnected events.
|
912
|
+
*/
|
913
|
+
/*
|
914
|
+
* Document-class: SDL2::Event::ControllerDeviceRemapped
|
915
|
+
*
|
916
|
+
* This class represents {SDL2::GameController controller} device remapped events.
|
917
|
+
*/
|
918
|
+
|
919
|
+
/*
|
920
|
+
* Document-class: SDL2::Event::TouchFinger
|
921
|
+
*
|
922
|
+
* This class represents touch finger events.
|
923
|
+
*
|
924
|
+
* You don't handle the instance
|
925
|
+
* of this class directly, but you handle the instances of
|
926
|
+
* two subclasses of this subclasses:
|
927
|
+
* {SDL2::Event::FingerMotion}, {SDL2::Event::FingerDown}, and {SDL2::Event::FingerUp}.
|
928
|
+
*
|
929
|
+
* @attribute touch_id
|
930
|
+
* the touch device id
|
931
|
+
* @return [Integer]
|
932
|
+
*
|
933
|
+
* @attribute finger_id
|
934
|
+
* the finger id
|
935
|
+
* @return [Integer]
|
936
|
+
*
|
937
|
+
* @attribute x
|
938
|
+
* the x-axis location of the touch event, normalized (0...1)
|
939
|
+
* @return [Float]
|
940
|
+
*
|
941
|
+
* @attribute y
|
942
|
+
* the y-axis location of the touch event, normalized (0...1)
|
943
|
+
* @return [Float]
|
944
|
+
*
|
945
|
+
* @attribute pressure
|
946
|
+
* the quantity of pressure applied, normalized (0...1)
|
947
|
+
* @return [Float]
|
948
|
+
*/
|
949
|
+
EVENT_ACCESSOR_INT(TouchFinger, touch_id, tfinger.touchId);
|
950
|
+
EVENT_ACCESSOR_INT(TouchFinger, finger_id, tfinger.fingerId);
|
951
|
+
EVENT_ACCESSOR_DBL(TouchFinger, x, tfinger.x);
|
952
|
+
EVENT_ACCESSOR_DBL(TouchFinger, y, tfinger.y);
|
953
|
+
EVENT_ACCESSOR_DBL(TouchFinger, pressure, tfinger.pressure);
|
954
|
+
/* @return [String] inspection string */
|
955
|
+
static VALUE EvTouchFinger_inspect(VALUE self)
|
956
|
+
{
|
957
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
958
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
959
|
+
" touch_id=%d finger_id=%d"
|
960
|
+
" x=%f y=%f pressure=%f>",
|
961
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
962
|
+
(int)ev->tfinger.touchId, (int)ev->tfinger.fingerId,
|
963
|
+
ev->tfinger.x, ev->tfinger.y, ev->tfinger.pressure);
|
964
|
+
}
|
965
|
+
|
966
|
+
/*
|
967
|
+
* Document-class: SDL2::Event::FingerUp
|
968
|
+
* This class represents finger touch events.
|
969
|
+
*/
|
970
|
+
/*
|
971
|
+
* Document-class: SDL2::Event::FingerDown
|
972
|
+
* This class represents finger release events.
|
973
|
+
*/
|
974
|
+
|
975
|
+
/*
|
976
|
+
* Document-class: SDL2::Event::FingerMotion
|
977
|
+
*
|
978
|
+
* This class represents touch move events.
|
979
|
+
*
|
980
|
+
* @attribute dx
|
981
|
+
* the distance moved in the x-axis, normalized (0...1)
|
982
|
+
* @return [Float]
|
983
|
+
*
|
984
|
+
* @attribute dy
|
985
|
+
* the distance moved in the y-axis, normalized (0...1)
|
986
|
+
* @return [Float]
|
987
|
+
*
|
988
|
+
*/
|
989
|
+
EVENT_ACCESSOR_DBL(FingerMotion, dx, tfinger.dx);
|
990
|
+
EVENT_ACCESSOR_DBL(FingerMotion, dy, tfinger.dy);
|
991
|
+
/* @return [String] inspection string */
|
992
|
+
static VALUE EvFingerMotion_inspect(VALUE self)
|
993
|
+
{
|
994
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
995
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
996
|
+
" touch_id=%d finger_id=%d"
|
997
|
+
" x=%f y=%f pressure=%f"
|
998
|
+
" dy=%f dx=%f>",
|
999
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
1000
|
+
(int) ev->tfinger.touchId, (int) ev->tfinger.fingerId,
|
1001
|
+
ev->tfinger.x, ev->tfinger.y, ev->tfinger.pressure,
|
1002
|
+
ev->tfinger.dx, ev->tfinger.dx);
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
|
1006
|
+
/*
|
1007
|
+
* Document-class: SDL2::Event::Multigesture
|
1008
|
+
*
|
1009
|
+
* This class represents multiple finger gesture events.
|
1010
|
+
*
|
1011
|
+
*
|
1012
|
+
* @attribute touch_id
|
1013
|
+
* the touch device id
|
1014
|
+
* @return [Integer]
|
1015
|
+
*
|
1016
|
+
* @attribute d_theta
|
1017
|
+
* rotation of fingers
|
1018
|
+
* @return [Float]
|
1019
|
+
*
|
1020
|
+
* @attribute d_dist
|
1021
|
+
* amount of fingers pinched
|
1022
|
+
* @return [Float]
|
1023
|
+
*
|
1024
|
+
* @attribute x
|
1025
|
+
* the x-axis location of the touch event, normalized (0...1)
|
1026
|
+
* @return [Float]
|
1027
|
+
*
|
1028
|
+
* @attribute y
|
1029
|
+
* the y-axis location of the touch event, normalized (0...1)
|
1030
|
+
* @return [Float]
|
1031
|
+
*
|
1032
|
+
* @attribute num_fingers
|
1033
|
+
* number of fingers involved
|
1034
|
+
* @return [Integer]
|
1035
|
+
*/
|
1036
|
+
EVENT_ACCESSOR_INT(Multigesture, touch_id, mgesture.touchId);
|
1037
|
+
EVENT_ACCESSOR_DBL(Multigesture, x, mgesture.x);
|
1038
|
+
EVENT_ACCESSOR_DBL(Multigesture, y, mgesture.y);
|
1039
|
+
EVENT_ACCESSOR_DBL(Multigesture, d_theta, mgesture.dTheta);
|
1040
|
+
EVENT_ACCESSOR_DBL(Multigesture, d_dist, mgesture.dDist);
|
1041
|
+
EVENT_ACCESSOR_INT(Multigesture, num_fingers, mgesture.numFingers);
|
1042
|
+
/* @return [String] inspection string */
|
1043
|
+
static VALUE EvMultigesture_inspect(VALUE self)
|
1044
|
+
{
|
1045
|
+
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
|
1046
|
+
return rb_sprintf("<%s: type=%u timestamp=%u"
|
1047
|
+
" touch_id=%d d_theta=%f d_dist=%f"
|
1048
|
+
" x=%f y=%f num_fingers=%d>",
|
1049
|
+
rb_obj_classname(self), ev->common.type, ev->common.timestamp,
|
1050
|
+
(int)ev->mgesture.touchId, ev->mgesture.dTheta, ev->mgesture.dDist,
|
1051
|
+
ev->mgesture.x, ev->mgesture.y, ev->mgesture.numFingers);
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
|
1055
|
+
/*
|
1056
|
+
* Document-class: SDL2::Event::SysWM
|
1057
|
+
*
|
1058
|
+
* This class represents video driver dependent system events.
|
1059
|
+
*
|
1060
|
+
* This event is disabled by default. You can enable it with {SDL2::Event.enable=}.
|
1061
|
+
* This event is now useless because now there is no way to get
|
1062
|
+
* driver dependent information from this event class.
|
1063
|
+
* You are encouraged to avoid this event.
|
1064
|
+
*
|
1065
|
+
*/
|
1066
|
+
static void connect_event_class(SDL_EventType type, VALUE klass)
|
1067
|
+
{
|
1068
|
+
event_type_to_class[type] = klass;
|
1069
|
+
rb_iv_set(klass, "event_type", INT2NUM(type));
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
static void init_event_type_to_class(void)
|
1073
|
+
{
|
1074
|
+
int i;
|
1075
|
+
for (i=0; i<SDL_LASTEVENT; ++i)
|
1076
|
+
event_type_to_class[i] = cEvent;
|
1077
|
+
|
1078
|
+
connect_event_class(SDL_QUIT, cEvQuit);
|
1079
|
+
connect_event_class(SDL_WINDOWEVENT, cEvWindow);
|
1080
|
+
connect_event_class(SDL_KEYDOWN, cEvKeyDown);
|
1081
|
+
connect_event_class(SDL_KEYUP, cEvKeyUp);
|
1082
|
+
connect_event_class(SDL_TEXTEDITING, cEvTextEditing);
|
1083
|
+
connect_event_class(SDL_TEXTINPUT, cEvTextInput);
|
1084
|
+
connect_event_class(SDL_MOUSEBUTTONDOWN, cEvMouseButtonDown);
|
1085
|
+
connect_event_class(SDL_MOUSEBUTTONUP, cEvMouseButtonUp);
|
1086
|
+
connect_event_class(SDL_MOUSEMOTION, cEvMouseMotion);
|
1087
|
+
connect_event_class(SDL_MOUSEWHEEL, cEvMouseWheel);
|
1088
|
+
connect_event_class(SDL_JOYBUTTONDOWN, cEvJoyButtonDown);
|
1089
|
+
connect_event_class(SDL_JOYBUTTONUP, cEvJoyButtonUp);
|
1090
|
+
connect_event_class(SDL_JOYAXISMOTION, cEvJoyAxisMotion);
|
1091
|
+
connect_event_class(SDL_JOYBALLMOTION, cEvJoyBallMotion);
|
1092
|
+
connect_event_class(SDL_JOYDEVICEADDED, cEvJoyDeviceAdded);
|
1093
|
+
connect_event_class(SDL_JOYDEVICEREMOVED, cEvJoyDeviceRemoved);
|
1094
|
+
connect_event_class(SDL_JOYHATMOTION, cEvJoyHatMotion);
|
1095
|
+
connect_event_class(SDL_CONTROLLERAXISMOTION, cEvControllerAxisMotion);
|
1096
|
+
connect_event_class(SDL_CONTROLLERBUTTONDOWN, cEvControllerButtonDown);
|
1097
|
+
connect_event_class(SDL_CONTROLLERBUTTONUP, cEvControllerButtonUp);
|
1098
|
+
connect_event_class(SDL_CONTROLLERDEVICEADDED, cEvControllerDeviceAdded);
|
1099
|
+
connect_event_class(SDL_CONTROLLERDEVICEREMOVED, cEvControllerDeviceRemoved);
|
1100
|
+
connect_event_class(SDL_CONTROLLERDEVICEREMAPPED, cEvControllerDeviceRemapped);
|
1101
|
+
connect_event_class(SDL_FINGERDOWN, cEvFingerDown);
|
1102
|
+
connect_event_class(SDL_FINGERUP, cEvFingerUp);
|
1103
|
+
connect_event_class(SDL_FINGERMOTION, cEvFingerMotion);
|
1104
|
+
connect_event_class(SDL_MULTIGESTURE, cEvMultigesture);
|
1105
|
+
}
|
1106
|
+
|
1107
|
+
#define DEFINE_EVENT_READER(classname, classvar, name) \
|
1108
|
+
rb_define_method(classvar, #name, Ev##classname##_##name, 0)
|
1109
|
+
|
1110
|
+
#define DEFINE_EVENT_WRITER(classname, classvar, name) \
|
1111
|
+
rb_define_method(classvar, #name "=", Ev##classname##_set_##name, 1)
|
1112
|
+
|
1113
|
+
#define DEFINE_EVENT_ACCESSOR(classname, classvar, name) \
|
1114
|
+
do { \
|
1115
|
+
DEFINE_EVENT_READER(classname, classvar, name); \
|
1116
|
+
DEFINE_EVENT_WRITER(classname, classvar, name); \
|
1117
|
+
} while(0)
|
1118
|
+
|
1119
|
+
void rubysdl2_init_event(void)
|
1120
|
+
{
|
1121
|
+
cEvent = rb_define_class_under(mSDL2, "Event", rb_cObject);
|
1122
|
+
rb_define_alloc_func(cEvent, Event_s_allocate);
|
1123
|
+
rb_define_singleton_method(cEvent, "poll", Event_s_poll, 0);
|
1124
|
+
rb_define_singleton_method(cEvent, "enabled?", Event_s_enabled_p, 0);
|
1125
|
+
rb_define_singleton_method(cEvent, "enable=", Event_s_set_enable, 1);
|
1126
|
+
|
1127
|
+
cEvQuit = rb_define_class_under(cEvent, "Quit", cEvent);
|
1128
|
+
cEvWindow = rb_define_class_under(cEvent, "Window", cEvent);
|
1129
|
+
cEvSysWM = rb_define_class_under(cEvent, "SysWM", cEvent);
|
1130
|
+
cEvKeyboard = rb_define_class_under(cEvent, "Keyboard", cEvent);
|
1131
|
+
cEvKeyUp = rb_define_class_under(cEvent, "KeyUp", cEvKeyboard);
|
1132
|
+
cEvKeyDown = rb_define_class_under(cEvent, "KeyDown", cEvKeyboard);
|
1133
|
+
cEvTextEditing = rb_define_class_under(cEvent, "TextEditing", cEvent);
|
1134
|
+
cEvTextInput = rb_define_class_under(cEvent, "TextInput", cEvent);
|
1135
|
+
cEvMouseButton = rb_define_class_under(cEvent, "MouseButton", cEvent);
|
1136
|
+
cEvMouseButtonDown = rb_define_class_under(cEvent, "MouseButtonDown", cEvMouseButton);
|
1137
|
+
cEvMouseButtonUp = rb_define_class_under(cEvent, "MouseButtonUp", cEvMouseButton);
|
1138
|
+
cEvMouseMotion = rb_define_class_under(cEvent, "MouseMotion", cEvent);
|
1139
|
+
cEvMouseWheel = rb_define_class_under(cEvent, "MouseWheel", cEvent);
|
1140
|
+
cEvJoyButton = rb_define_class_under(cEvent, "JoyButton", cEvent);
|
1141
|
+
cEvJoyButtonDown = rb_define_class_under(cEvent, "JoyButtonDown", cEvJoyButton);
|
1142
|
+
cEvJoyButtonUp = rb_define_class_under(cEvent, "JoyButtonUp", cEvJoyButton);
|
1143
|
+
cEvJoyAxisMotion = rb_define_class_under(cEvent, "JoyAxisMotion", cEvent);
|
1144
|
+
cEvJoyBallMotion = rb_define_class_under(cEvent, "JoyBallMotion", cEvent);
|
1145
|
+
cEvJoyHatMotion = rb_define_class_under(cEvent, "JoyHatMotion", cEvent);
|
1146
|
+
cEvJoyDevice = rb_define_class_under(cEvent, "JoyDevice", cEvent);
|
1147
|
+
cEvJoyDeviceAdded = rb_define_class_under(cEvent, "JoyDeviceAdded", cEvJoyDevice);
|
1148
|
+
cEvJoyDeviceRemoved = rb_define_class_under(cEvent, "JoyDeviceRemoved", cEvJoyDevice);
|
1149
|
+
cEvControllerAxisMotion = rb_define_class_under(cEvent, "ControllerAxisMotion", cEvent);
|
1150
|
+
cEvControllerButton = rb_define_class_under(cEvent, "ControllerButton", cEvent);
|
1151
|
+
cEvControllerButtonDown = rb_define_class_under(cEvent, "ControllerButtonDown", cEvControllerButton);
|
1152
|
+
cEvControllerButtonUp = rb_define_class_under(cEvent, "ControllerButtonUp", cEvControllerButton);
|
1153
|
+
cEvControllerDevice = rb_define_class_under(cEvent, "ControllerDevice", cEvent);
|
1154
|
+
cEvControllerDeviceAdded = rb_define_class_under(cEvent, "ControllerDeviceAdded", cEvControllerDevice);
|
1155
|
+
cEvControllerDeviceRemoved = rb_define_class_under(cEvent, "ControllerDeviceRemoved", cEvControllerDevice);
|
1156
|
+
cEvControllerDeviceRemapped = rb_define_class_under(cEvent, "ControllerDeviceRemapped", cEvControllerDevice);
|
1157
|
+
cEvTouchFinger = rb_define_class_under(cEvent, "TouchFinger", cEvent);
|
1158
|
+
cEvFingerUp = rb_define_class_under(cEvent, "FingerUp", cEvTouchFinger);
|
1159
|
+
cEvFingerDown = rb_define_class_under(cEvent, "FingerDown", cEvTouchFinger);
|
1160
|
+
cEvFingerMotion = rb_define_class_under(cEvent, "FingerMotion", cEvTouchFinger);
|
1161
|
+
cEvMultigesture = rb_define_class_under(cEvent, "Multigesture", cEvent);
|
1162
|
+
|
1163
|
+
|
1164
|
+
DEFINE_EVENT_READER(Event, cEvent, type);
|
1165
|
+
DEFINE_EVENT_ACCESSOR(Event, cEvent, timestamp);
|
1166
|
+
rb_define_method(cEvent, "inspect", Event_inspect, 0);
|
1167
|
+
rb_define_method(cEvent, "window", Event_window, 0);
|
1168
|
+
|
1169
|
+
DEFINE_EVENT_ACCESSOR(Window, cEvWindow, window_id);
|
1170
|
+
DEFINE_EVENT_ACCESSOR(Window, cEvWindow, event);
|
1171
|
+
DEFINE_EVENT_ACCESSOR(Window, cEvWindow, data1);
|
1172
|
+
DEFINE_EVENT_ACCESSOR(Window, cEvWindow, data2);
|
1173
|
+
rb_define_method(cEvWindow, "inspect", EvWindow_inspect, 0);
|
1174
|
+
#define DEFINE_EVENT_ID_CONST(t) \
|
1175
|
+
rb_define_const(cEvWindow, #t, INT2NUM(SDL_WINDOWEVENT_##t))
|
1176
|
+
DEFINE_EVENT_ID_CONST(NONE);
|
1177
|
+
DEFINE_EVENT_ID_CONST(SHOWN);
|
1178
|
+
DEFINE_EVENT_ID_CONST(HIDDEN);
|
1179
|
+
DEFINE_EVENT_ID_CONST(EXPOSED);
|
1180
|
+
DEFINE_EVENT_ID_CONST(MOVED);
|
1181
|
+
DEFINE_EVENT_ID_CONST(RESIZED);
|
1182
|
+
DEFINE_EVENT_ID_CONST(SIZE_CHANGED);
|
1183
|
+
DEFINE_EVENT_ID_CONST(MINIMIZED);
|
1184
|
+
DEFINE_EVENT_ID_CONST(MAXIMIZED);
|
1185
|
+
DEFINE_EVENT_ID_CONST(RESTORED);
|
1186
|
+
DEFINE_EVENT_ID_CONST(ENTER);
|
1187
|
+
DEFINE_EVENT_ID_CONST(LEAVE);
|
1188
|
+
DEFINE_EVENT_ID_CONST(FOCUS_GAINED);
|
1189
|
+
DEFINE_EVENT_ID_CONST(FOCUS_LOST);
|
1190
|
+
DEFINE_EVENT_ID_CONST(CLOSE);
|
1191
|
+
|
1192
|
+
|
1193
|
+
DEFINE_EVENT_ACCESSOR(Keyboard, cEvKeyboard, window_id);
|
1194
|
+
DEFINE_EVENT_ACCESSOR(Keyboard, cEvKeyboard, pressed);
|
1195
|
+
DEFINE_EVENT_ACCESSOR(Keyboard, cEvKeyboard, repeat);
|
1196
|
+
DEFINE_EVENT_ACCESSOR(Keyboard, cEvKeyboard, scancode);
|
1197
|
+
DEFINE_EVENT_ACCESSOR(Keyboard, cEvKeyboard, sym);
|
1198
|
+
DEFINE_EVENT_ACCESSOR(Keyboard, cEvKeyboard, mod);
|
1199
|
+
rb_define_alias(cEvKeyboard, "pressed?", "pressed");
|
1200
|
+
rb_define_alias(cEvKeyboard, "repeat?", "repeat");
|
1201
|
+
rb_define_method(cEvKeyboard, "inspect", EvKeyboard_inspect, 0);
|
1202
|
+
|
1203
|
+
DEFINE_EVENT_ACCESSOR(TextEditing, cEvTextEditing, window_id);
|
1204
|
+
DEFINE_EVENT_ACCESSOR(TextEditing, cEvTextEditing, text);
|
1205
|
+
DEFINE_EVENT_ACCESSOR(TextEditing, cEvTextEditing, start);
|
1206
|
+
DEFINE_EVENT_ACCESSOR(TextEditing, cEvTextEditing, length);
|
1207
|
+
rb_define_method(cEvTextEditing, "inspect", EvTextEditing_inspect, 0);
|
1208
|
+
|
1209
|
+
DEFINE_EVENT_ACCESSOR(TextInput, cEvTextInput, window_id);
|
1210
|
+
DEFINE_EVENT_ACCESSOR(TextInput, cEvTextInput, text);
|
1211
|
+
rb_define_method(cEvTextInput, "inspect", EvTextInput_inspect, 0);
|
1212
|
+
|
1213
|
+
DEFINE_EVENT_ACCESSOR(MouseButton, cEvMouseButton, window_id);
|
1214
|
+
DEFINE_EVENT_ACCESSOR(MouseButton, cEvMouseButton, which);
|
1215
|
+
DEFINE_EVENT_ACCESSOR(MouseButton, cEvMouseButton, button);
|
1216
|
+
DEFINE_EVENT_ACCESSOR(MouseButton, cEvMouseButton, pressed);
|
1217
|
+
#if SDL_VERSION_ATLEAST(2,0,2)
|
1218
|
+
DEFINE_EVENT_ACCESSOR(MouseButton, cEvMouseButton, clicks);
|
1219
|
+
#endif
|
1220
|
+
DEFINE_EVENT_ACCESSOR(MouseButton, cEvMouseButton, x);
|
1221
|
+
DEFINE_EVENT_ACCESSOR(MouseButton, cEvMouseButton, y);
|
1222
|
+
rb_define_alias(cEvMouseButton, "pressed?", "pressed");
|
1223
|
+
rb_define_method(cEvMouseButton, "inspect", EvMouseButton_inspect, 0);
|
1224
|
+
|
1225
|
+
DEFINE_EVENT_ACCESSOR(MouseMotion, cEvMouseMotion, window_id);
|
1226
|
+
DEFINE_EVENT_ACCESSOR(MouseMotion, cEvMouseMotion, which);
|
1227
|
+
DEFINE_EVENT_ACCESSOR(MouseMotion, cEvMouseMotion, state);
|
1228
|
+
DEFINE_EVENT_ACCESSOR(MouseMotion, cEvMouseMotion, x);
|
1229
|
+
DEFINE_EVENT_ACCESSOR(MouseMotion, cEvMouseMotion, y);
|
1230
|
+
DEFINE_EVENT_ACCESSOR(MouseMotion, cEvMouseMotion, xrel);
|
1231
|
+
DEFINE_EVENT_ACCESSOR(MouseMotion, cEvMouseMotion, yrel);
|
1232
|
+
rb_define_method(cEvMouseMotion, "inspect", EvMouseMotion_inspect, 0);
|
1233
|
+
|
1234
|
+
DEFINE_EVENT_ACCESSOR(MouseWheel, cEvMouseWheel, window_id);
|
1235
|
+
DEFINE_EVENT_ACCESSOR(MouseWheel, cEvMouseWheel, which);
|
1236
|
+
DEFINE_EVENT_ACCESSOR(MouseWheel, cEvMouseWheel, x);
|
1237
|
+
DEFINE_EVENT_ACCESSOR(MouseWheel, cEvMouseWheel, y);
|
1238
|
+
rb_define_method(cEvMouseWheel, "inspect", EvMouseWheel_inspect, 0);
|
1239
|
+
|
1240
|
+
DEFINE_EVENT_ACCESSOR(JoyButton, cEvJoyButton, which);
|
1241
|
+
DEFINE_EVENT_ACCESSOR(JoyButton, cEvJoyButton, button);
|
1242
|
+
DEFINE_EVENT_ACCESSOR(JoyButton, cEvJoyButton, pressed);
|
1243
|
+
rb_define_alias(cEvJoyButton, "pressed?", "pressed");
|
1244
|
+
rb_define_method(cEvJoyButton, "inspect", EvJoyButton_inspect, 0);
|
1245
|
+
|
1246
|
+
DEFINE_EVENT_ACCESSOR(JoyAxisMotion, cEvJoyAxisMotion, which);
|
1247
|
+
DEFINE_EVENT_ACCESSOR(JoyAxisMotion, cEvJoyAxisMotion, axis);
|
1248
|
+
DEFINE_EVENT_ACCESSOR(JoyAxisMotion, cEvJoyAxisMotion, value);
|
1249
|
+
rb_define_method(cEvJoyAxisMotion, "inspect", EvJoyAxisMotion_inspect, 0);
|
1250
|
+
|
1251
|
+
DEFINE_EVENT_ACCESSOR(JoyBallMotion, cEvJoyBallMotion, which);
|
1252
|
+
DEFINE_EVENT_ACCESSOR(JoyBallMotion, cEvJoyBallMotion, ball);
|
1253
|
+
DEFINE_EVENT_ACCESSOR(JoyBallMotion, cEvJoyBallMotion, xrel);
|
1254
|
+
DEFINE_EVENT_ACCESSOR(JoyBallMotion, cEvJoyBallMotion, yrel);
|
1255
|
+
rb_define_method(cEvJoyBallMotion, "inspect", EvJoyBallMotion_inspect, 0);
|
1256
|
+
|
1257
|
+
DEFINE_EVENT_ACCESSOR(JoyHatMotion, cEvJoyHatMotion, which);
|
1258
|
+
DEFINE_EVENT_ACCESSOR(JoyHatMotion, cEvJoyHatMotion, hat);
|
1259
|
+
DEFINE_EVENT_ACCESSOR(JoyHatMotion, cEvJoyHatMotion, value);
|
1260
|
+
rb_define_method(cEvJoyHatMotion, "inspect", EvJoyHatMotion_inspect, 0);
|
1261
|
+
|
1262
|
+
DEFINE_EVENT_ACCESSOR(JoyDevice, cEvJoyDevice, which);
|
1263
|
+
rb_define_method(cEvJoyDevice, "inspect", EvJoyDevice_inspect, 0);
|
1264
|
+
|
1265
|
+
DEFINE_EVENT_ACCESSOR(ControllerAxis, cEvControllerAxisMotion, which);
|
1266
|
+
DEFINE_EVENT_ACCESSOR(ControllerAxis, cEvControllerAxisMotion, axis);
|
1267
|
+
DEFINE_EVENT_ACCESSOR(ControllerAxis, cEvControllerAxisMotion, value);
|
1268
|
+
rb_define_method(cEvControllerAxisMotion, "inspect", ControllerAxis_inspect, 0);
|
1269
|
+
|
1270
|
+
DEFINE_EVENT_ACCESSOR(ControllerButton, cEvControllerButton, which);
|
1271
|
+
DEFINE_EVENT_ACCESSOR(ControllerButton, cEvControllerButton, button);
|
1272
|
+
DEFINE_EVENT_ACCESSOR(ControllerButton, cEvControllerButton, pressed);
|
1273
|
+
rb_define_method(cEvControllerButton, "inspect", ControllerButton_inspect, 0);
|
1274
|
+
|
1275
|
+
DEFINE_EVENT_ACCESSOR(ControllerDevice, cEvControllerDevice, which);
|
1276
|
+
rb_define_method(cEvControllerDevice, "inspect", ControllerDevice_inspect, 0);
|
1277
|
+
|
1278
|
+
DEFINE_EVENT_ACCESSOR(TouchFinger, cEvTouchFinger, touch_id);
|
1279
|
+
DEFINE_EVENT_ACCESSOR(TouchFinger, cEvTouchFinger, finger_id);
|
1280
|
+
DEFINE_EVENT_ACCESSOR(TouchFinger, cEvTouchFinger, x);
|
1281
|
+
DEFINE_EVENT_ACCESSOR(TouchFinger, cEvTouchFinger, y);
|
1282
|
+
DEFINE_EVENT_ACCESSOR(TouchFinger, cEvTouchFinger, pressure);
|
1283
|
+
rb_define_method(cEvTouchFinger, "inspect", EvTouchFinger_inspect, 0);
|
1284
|
+
|
1285
|
+
DEFINE_EVENT_ACCESSOR(FingerMotion, cEvFingerMotion, dx);
|
1286
|
+
DEFINE_EVENT_ACCESSOR(FingerMotion, cEvFingerMotion, dy);
|
1287
|
+
rb_define_method(cEvFingerMotion, "inspect", EvFingerMotion_inspect, 0);
|
1288
|
+
|
1289
|
+
DEFINE_EVENT_ACCESSOR(Multigesture, cEvMultigesture, touch_id);
|
1290
|
+
DEFINE_EVENT_ACCESSOR(Multigesture, cEvMultigesture, d_theta);
|
1291
|
+
DEFINE_EVENT_ACCESSOR(Multigesture, cEvMultigesture, d_dist);
|
1292
|
+
DEFINE_EVENT_ACCESSOR(Multigesture, cEvMultigesture, x);
|
1293
|
+
DEFINE_EVENT_ACCESSOR(Multigesture, cEvMultigesture, y);
|
1294
|
+
DEFINE_EVENT_ACCESSOR(Multigesture, cEvMultigesture, num_fingers);
|
1295
|
+
rb_define_method(cEvMultigesture, "inspect", EvMultigesture_inspect, 0);
|
1296
|
+
|
1297
|
+
init_event_type_to_class();
|
1298
|
+
}
|