sfml3-rb 0.0.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +342 -0
- data/README.md +51 -14
- data/TODO.md +199 -0
- data/ext/audio/audio_enums.c +131 -0
- data/ext/audio/audio_enums.h +18 -0
- data/ext/audio/effect_processor.c +233 -0
- data/ext/audio/effect_processor.h +25 -0
- data/ext/audio/listener.c +83 -0
- data/ext/audio/listener.h +8 -0
- data/ext/audio/music.c +174 -0
- data/ext/audio/music.h +14 -0
- data/ext/audio/sound.c +139 -0
- data/ext/audio/sound.h +14 -0
- data/ext/audio/sound_buffer.c +274 -0
- data/ext/audio/sound_buffer.h +18 -0
- data/ext/audio/sound_buffer_recorder.c +109 -0
- data/ext/audio/sound_buffer_recorder.h +14 -0
- data/ext/audio/sound_recorder.c +268 -0
- data/ext/audio/sound_recorder.h +14 -0
- data/ext/audio/sound_source.h +13 -0
- data/ext/audio/sound_source.inc +271 -0
- data/ext/audio/sound_source_cone.c +138 -0
- data/ext/audio/sound_source_cone.h +20 -0
- data/ext/audio/sound_stream.c +294 -0
- data/ext/audio/sound_stream.h +14 -0
- data/ext/{exceptions.c → core/exceptions.c} +10 -8
- data/ext/{ext → core}/exceptions.h +3 -3
- data/ext/core/foreign_thread.c +149 -0
- data/ext/core/foreign_thread.h +31 -0
- data/ext/core/macros.h +8 -0
- data/ext/{ext → core}/sfml.h +5 -3
- data/ext/core/unicode.c +46 -0
- data/ext/core/unicode.h +25 -0
- data/ext/ext.c +125 -14
- data/ext/extconf.rb +51 -6
- data/ext/graphics/blend_mode.c +261 -0
- data/ext/graphics/blend_mode.h +18 -0
- data/ext/graphics/circle.c +319 -0
- data/ext/{ext/klass/drawable → graphics}/circle.h +3 -3
- data/ext/graphics/color.c +318 -0
- data/ext/graphics/color.h +37 -0
- data/ext/{drawable.c → graphics/drawable.c} +11 -11
- data/ext/graphics/drawable.h +10 -0
- data/ext/graphics/enums.c +123 -0
- data/ext/graphics/enums.h +20 -0
- data/ext/graphics/font.c +148 -0
- data/ext/graphics/font.h +14 -0
- data/ext/graphics/glyph.c +60 -0
- data/ext/graphics/glyph.h +14 -0
- data/ext/graphics/image.c +205 -0
- data/ext/graphics/image.h +16 -0
- data/ext/graphics/polygon.c +300 -0
- data/ext/graphics/polygon.h +10 -0
- data/ext/graphics/rect.c +287 -0
- data/ext/graphics/rect.h +30 -0
- data/ext/graphics/rectangle.c +302 -0
- data/ext/graphics/rectangle.h +10 -0
- data/ext/graphics/render_state.c +204 -0
- data/ext/graphics/render_state.h +18 -0
- data/ext/graphics/render_target.inc +181 -0
- data/ext/graphics/render_texture.c +182 -0
- data/ext/graphics/render_texture.h +14 -0
- data/ext/graphics/shader.c +540 -0
- data/ext/graphics/shader.h +14 -0
- data/ext/graphics/shape.c +311 -0
- data/ext/graphics/shape.h +10 -0
- data/ext/graphics/sprite.c +249 -0
- data/ext/graphics/sprite.h +10 -0
- data/ext/graphics/stencil_mode.c +211 -0
- data/ext/graphics/stencil_mode.h +18 -0
- data/ext/graphics/target.c +133 -0
- data/ext/graphics/target.h +40 -0
- data/ext/graphics/text.c +344 -0
- data/ext/graphics/text.h +10 -0
- data/ext/graphics/texture.c +379 -0
- data/ext/graphics/texture.h +16 -0
- data/ext/graphics/transform.c +372 -0
- data/ext/graphics/transform.h +35 -0
- data/ext/{transformable.c → graphics/transformable.c} +168 -144
- data/ext/{ext/klass → graphics}/transformable.h +3 -3
- data/ext/graphics/vertex.c +179 -0
- data/ext/graphics/vertex.h +23 -0
- data/ext/graphics/vertex_array.c +127 -0
- data/ext/graphics/vertex_array.h +10 -0
- data/ext/graphics/vertex_buffer.c +211 -0
- data/ext/graphics/vertex_buffer.h +14 -0
- data/ext/{view.c → graphics/view.c} +168 -169
- data/ext/{ext/klass → graphics}/view.h +3 -3
- data/ext/network/ftp.c +405 -0
- data/ext/network/ftp.h +20 -0
- data/ext/network/http.c +243 -0
- data/ext/network/http.h +18 -0
- data/ext/network/ip_address.c +164 -0
- data/ext/network/ip_address.h +20 -0
- data/ext/network/network_enums.c +298 -0
- data/ext/network/network_enums.h +26 -0
- data/ext/network/packet.c +189 -0
- data/ext/network/packet.h +14 -0
- data/ext/network/socket_selector.c +142 -0
- data/ext/network/socket_selector.h +14 -0
- data/ext/network/tcp_listener.c +115 -0
- data/ext/network/tcp_listener.h +14 -0
- data/ext/network/tcp_socket.c +199 -0
- data/ext/network/tcp_socket.h +17 -0
- data/ext/network/udp_socket.c +190 -0
- data/ext/network/udp_socket.h +14 -0
- data/ext/ports.rb +97 -21
- data/ext/system/buffer.c +77 -0
- data/ext/system/buffer.h +14 -0
- data/ext/system/clock.c +100 -0
- data/ext/{ext/klass → system}/clock.h +3 -3
- data/ext/system/input_stream.c +229 -0
- data/ext/system/input_stream.h +23 -0
- data/ext/system/sleep.c +16 -0
- data/ext/system/sleep.h +8 -0
- data/ext/system/time.c +218 -0
- data/ext/system/time.h +18 -0
- data/ext/system/vec2.c +251 -0
- data/ext/system/vec2.h +55 -0
- data/ext/system/vec3.c +219 -0
- data/ext/system/vec3.h +18 -0
- data/ext/window/clipboard.c +89 -0
- data/ext/window/clipboard.h +8 -0
- data/ext/window/context.c +70 -0
- data/ext/window/context.h +8 -0
- data/ext/window/context_settings.c +220 -0
- data/ext/window/context_settings.h +18 -0
- data/ext/window/cursor.c +56 -0
- data/ext/window/cursor.h +14 -0
- data/ext/window/event.c +216 -0
- data/ext/window/event.h +14 -0
- data/ext/{event_name.c → window/event_name.c} +2 -2
- data/ext/window/event_name.h +8 -0
- data/ext/window/input_enums.c +261 -0
- data/ext/window/input_enums.h +36 -0
- data/ext/window/joystick.c +60 -0
- data/ext/window/joystick.h +8 -0
- data/ext/{keyboard.c → window/keyboard.c} +74 -2
- data/ext/window/keyboard.h +12 -0
- data/ext/window/mouse.c +70 -0
- data/ext/window/mouse.h +8 -0
- data/ext/window/sensor.c +30 -0
- data/ext/window/sensor.h +8 -0
- data/ext/window/touch.c +49 -0
- data/ext/window/touch.h +8 -0
- data/ext/window/video_mode.c +133 -0
- data/ext/window/video_mode.h +14 -0
- data/ext/window/vulkan.c +44 -0
- data/ext/window/vulkan.h +8 -0
- data/ext/window/window.c +414 -0
- data/ext/{ext/klass → window}/window.h +3 -3
- data/lib/sfml/version.rb +4 -2
- data/lib/sfml.rb +2 -0
- metadata +163 -56
- data/ext/circle.c +0 -198
- data/ext/clock.c +0 -65
- data/ext/color.c +0 -43
- data/ext/event.c +0 -148
- data/ext/ext/klass/color.h +0 -26
- data/ext/ext/klass/drawable/image.h +0 -4
- data/ext/ext/klass/drawable/polygon.h +0 -4
- data/ext/ext/klass/drawable/rectangle.h +0 -4
- data/ext/ext/klass/drawable/sprite.h +0 -4
- data/ext/ext/klass/drawable/texture.h +0 -4
- data/ext/ext/klass/event/event_name.h +0 -8
- data/ext/ext/klass/event.h +0 -12
- data/ext/ext/klass/keyboard.h +0 -8
- data/ext/ext/klass/render_state.h +0 -16
- data/ext/ext/klass/target.h +0 -18
- data/ext/ext/klass/transform.h +0 -17
- data/ext/ext/klass/video_mode.h +0 -12
- data/ext/ext/module/drawable/drawable.h +0 -10
- data/ext/ext/module/transform.h +0 -18
- data/ext/ext/module.h +0 -10
- data/ext/ext/rect.h +0 -16
- data/ext/ext/style_name.h +0 -11
- data/ext/ext/vec2.h +0 -38
- data/ext/image.c +0 -5
- data/ext/polygon.c +0 -5
- data/ext/rect.c +0 -26
- data/ext/rectangle.c +0 -5
- data/ext/render_state.c +0 -109
- data/ext/sprite.c +0 -5
- data/ext/style_name.c +0 -15
- data/ext/target.c +0 -106
- data/ext/texture.c +0 -5
- data/ext/transform.c +0 -107
- data/ext/vec2.c +0 -42
- data/ext/video_mode.c +0 -78
- data/ext/window.c +0 -274
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
#include "window/input_enums.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
#include "core/exceptions.h"
|
|
7
|
+
|
|
8
|
+
static const char *mouse_button_names[] = {"left", "right", "middle", "extra1", "extra2"};
|
|
9
|
+
static const char *mouse_wheel_names[] = {"vertical", "horizontal"};
|
|
10
|
+
static const char *joystick_axis_names[] = {"x", "y", "z", "r", "u", "v", "pov_x", "pov_y"};
|
|
11
|
+
static const char *sensor_type_names[] = {
|
|
12
|
+
"accelerometer", "gyroscope", "magnetometer", "gravity", "user_acceleration", "orientation"
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
static const char *cursor_type_names[] = {
|
|
16
|
+
"arrow", "arrow_wait", "wait", "text", "hand", "size_horizontal", "size_vertical",
|
|
17
|
+
"size_top_left_bottom_right", "size_bottom_left_top_right", "size_left", "size_right",
|
|
18
|
+
"size_top", "size_bottom", "size_top_left", "size_bottom_right", "size_bottom_left",
|
|
19
|
+
"size_top_right", "size_all", "cross", "help", "not_allowed"
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/* Returns the matching index, or -1. Integer arguments pass through unchanged
|
|
23
|
+
by the callers, so this only deals with symbols. */
|
|
24
|
+
static int symbol_index(VALUE rb_symbol, const char *const *names, size_t count) {
|
|
25
|
+
const char *name;
|
|
26
|
+
size_t i;
|
|
27
|
+
|
|
28
|
+
if (!SYMBOL_P(rb_symbol)) {
|
|
29
|
+
return -1;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
name = rb_id2name(SYM2ID(rb_symbol));
|
|
33
|
+
|
|
34
|
+
for (i = 0; i < count; i++) {
|
|
35
|
+
if (strcmp(name, names[i]) == 0) {
|
|
36
|
+
return (int) i;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const char *mouse_button_name(sfMouseButton button) {
|
|
44
|
+
if (button >= 0 && button <= sfMouseButtonExtra2) {
|
|
45
|
+
return mouse_button_names[button];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return "left";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
sfMouseButton mouse_button_from_rb(VALUE rb_button) {
|
|
52
|
+
int index;
|
|
53
|
+
|
|
54
|
+
if (RB_INTEGER_TYPE_P(rb_button)) {
|
|
55
|
+
return (sfMouseButton) NUM2INT(rb_button);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
index = symbol_index(rb_button, mouse_button_names, 5);
|
|
59
|
+
|
|
60
|
+
if (index < 0) {
|
|
61
|
+
rb_raise(rb_eArgError, "unknown mouse button");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (sfMouseButton) index;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const char *mouse_wheel_name(sfMouseWheel wheel) {
|
|
68
|
+
return (wheel == sfMouseHorizontalWheel) ? "horizontal" : "vertical";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
sfMouseWheel mouse_wheel_from_rb(VALUE rb_wheel) {
|
|
72
|
+
int index;
|
|
73
|
+
|
|
74
|
+
if (RB_INTEGER_TYPE_P(rb_wheel)) {
|
|
75
|
+
return (sfMouseWheel) NUM2INT(rb_wheel);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
index = symbol_index(rb_wheel, mouse_wheel_names, 2);
|
|
79
|
+
|
|
80
|
+
if (index < 0) {
|
|
81
|
+
rb_raise(rb_eArgError, "unknown mouse wheel");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (sfMouseWheel) index;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const char *joystick_axis_name(sfJoystickAxis axis) {
|
|
88
|
+
if (axis >= 0 && axis <= sfJoystickPovY) {
|
|
89
|
+
return joystick_axis_names[axis];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return "x";
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
sfJoystickAxis joystick_axis_from_rb(VALUE rb_axis) {
|
|
96
|
+
int index;
|
|
97
|
+
|
|
98
|
+
if (RB_INTEGER_TYPE_P(rb_axis)) {
|
|
99
|
+
return (sfJoystickAxis) NUM2INT(rb_axis);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
index = symbol_index(rb_axis, joystick_axis_names, 8);
|
|
103
|
+
|
|
104
|
+
if (index < 0) {
|
|
105
|
+
rb_raise(rb_eArgError, "unknown joystick axis");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return (sfJoystickAxis) index;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const char *sensor_type_name(sfSensorType type) {
|
|
112
|
+
if (type >= 0 && type <= sfSensorOrientation) {
|
|
113
|
+
return sensor_type_names[type];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return "accelerometer";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
sfSensorType sensor_type_from_rb(VALUE rb_type) {
|
|
120
|
+
int index;
|
|
121
|
+
|
|
122
|
+
if (RB_INTEGER_TYPE_P(rb_type)) {
|
|
123
|
+
return (sfSensorType) NUM2INT(rb_type);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
index = symbol_index(rb_type, sensor_type_names, 6);
|
|
127
|
+
|
|
128
|
+
if (index < 0) {
|
|
129
|
+
rb_raise(rb_eArgError, "unknown sensor type");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (sfSensorType) index;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const char *cursor_type_name(sfCursorType type) {
|
|
136
|
+
if (type >= 0 && type <= sfCursorNotAllowed) {
|
|
137
|
+
return cursor_type_names[type];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return "arrow";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
sfCursorType cursor_type_from_rb(VALUE rb_type) {
|
|
144
|
+
int index;
|
|
145
|
+
|
|
146
|
+
if (RB_INTEGER_TYPE_P(rb_type)) {
|
|
147
|
+
return (sfCursorType) NUM2INT(rb_type);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
index = symbol_index(rb_type, cursor_type_names, 21);
|
|
151
|
+
|
|
152
|
+
if (index < 0) {
|
|
153
|
+
rb_raise(rb_eArgError, "unknown cursor type");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return (sfCursorType) index;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static uint32_t style_flag_from_symbol(VALUE rb_symbol) {
|
|
160
|
+
const char *name;
|
|
161
|
+
|
|
162
|
+
if (!SYMBOL_P(rb_symbol)) {
|
|
163
|
+
rb_raise(rb_eArgError, "expected a window style symbol");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
name = rb_id2name(SYM2ID(rb_symbol));
|
|
167
|
+
|
|
168
|
+
if (strcmp(name, "none") == 0) {
|
|
169
|
+
return sfNone;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (strcmp(name, "titlebar") == 0) {
|
|
173
|
+
return sfTitlebar;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (strcmp(name, "resize") == 0) {
|
|
177
|
+
return sfResize;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (strcmp(name, "close") == 0) {
|
|
181
|
+
return sfClose;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (strcmp(name, "default") == 0) {
|
|
185
|
+
return sfDefaultStyle;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
rb_raise(rb_eArgError, "unknown window style: %s", name);
|
|
189
|
+
return sfNone;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
uint32_t window_style_from_rb(VALUE rb_style) {
|
|
193
|
+
uint32_t style = 0;
|
|
194
|
+
|
|
195
|
+
if (RB_INTEGER_TYPE_P(rb_style)) {
|
|
196
|
+
return (uint32_t) NUM2UINT(rb_style);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (SYMBOL_P(rb_style)) {
|
|
200
|
+
return style_flag_from_symbol(rb_style);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (RB_TYPE_P(rb_style, T_ARRAY)) {
|
|
204
|
+
for (long i = 0; i < RARRAY_LEN(rb_style); i++) {
|
|
205
|
+
style |= style_flag_from_symbol(rb_ary_entry(rb_style, i));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return style;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
rb_raise(rb_eArgError, "expected a window style symbol or array of symbols");
|
|
212
|
+
return sfNone;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
VALUE window_style_to_rb(uint32_t style) {
|
|
216
|
+
VALUE array = rb_ary_new();
|
|
217
|
+
|
|
218
|
+
if (style == sfNone) {
|
|
219
|
+
rb_ary_push(array, ID2SYM(rb_intern("none")));
|
|
220
|
+
return array;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if ((style & sfTitlebar) != 0) {
|
|
224
|
+
rb_ary_push(array, ID2SYM(rb_intern("titlebar")));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if ((style & sfResize) != 0) {
|
|
228
|
+
rb_ary_push(array, ID2SYM(rb_intern("resize")));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if ((style & sfClose) != 0) {
|
|
232
|
+
rb_ary_push(array, ID2SYM(rb_intern("close")));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return array;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
sfWindowState window_state_from_rb(VALUE rb_state) {
|
|
239
|
+
if (RB_INTEGER_TYPE_P(rb_state)) {
|
|
240
|
+
return (sfWindowState) NUM2INT(rb_state);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (SYMBOL_P(rb_state)) {
|
|
244
|
+
const char *name = rb_id2name(SYM2ID(rb_state));
|
|
245
|
+
|
|
246
|
+
if (strcmp(name, "fullscreen") == 0) {
|
|
247
|
+
return sfFullscreen;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (strcmp(name, "windowed") == 0) {
|
|
251
|
+
return sfWindowed;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
rb_raise(rb_eArgError, "expected :windowed or :fullscreen");
|
|
256
|
+
return sfWindowed;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
VALUE window_state_to_rb(sfWindowState state) {
|
|
260
|
+
return ID2SYM(rb_intern(state == sfFullscreen ? "fullscreen" : "windowed"));
|
|
261
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#ifndef SFML_RB_WINDOW_INPUT_ENUMS_H
|
|
2
|
+
#define SFML_RB_WINDOW_INPUT_ENUMS_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
const char *mouse_button_name(sfMouseButton button);
|
|
9
|
+
|
|
10
|
+
sfMouseButton mouse_button_from_rb(VALUE rb_button);
|
|
11
|
+
|
|
12
|
+
const char *mouse_wheel_name(sfMouseWheel wheel);
|
|
13
|
+
|
|
14
|
+
sfMouseWheel mouse_wheel_from_rb(VALUE rb_wheel);
|
|
15
|
+
|
|
16
|
+
const char *joystick_axis_name(sfJoystickAxis axis);
|
|
17
|
+
|
|
18
|
+
sfJoystickAxis joystick_axis_from_rb(VALUE rb_axis);
|
|
19
|
+
|
|
20
|
+
const char *sensor_type_name(sfSensorType type);
|
|
21
|
+
|
|
22
|
+
sfSensorType sensor_type_from_rb(VALUE rb_type);
|
|
23
|
+
|
|
24
|
+
const char *cursor_type_name(sfCursorType type);
|
|
25
|
+
|
|
26
|
+
sfCursorType cursor_type_from_rb(VALUE rb_type);
|
|
27
|
+
|
|
28
|
+
uint32_t window_style_from_rb(VALUE rb_style);
|
|
29
|
+
|
|
30
|
+
VALUE window_style_to_rb(uint32_t style);
|
|
31
|
+
|
|
32
|
+
sfWindowState window_state_from_rb(VALUE rb_state);
|
|
33
|
+
|
|
34
|
+
VALUE window_state_to_rb(sfWindowState state);
|
|
35
|
+
|
|
36
|
+
#endif //SFML_RB_WINDOW_INPUT_ENUMS_H
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#include "window/joystick.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
|
|
5
|
+
#include "window/input_enums.h"
|
|
6
|
+
#include "core/macros.h"
|
|
7
|
+
#include "core/sfml.h"
|
|
8
|
+
|
|
9
|
+
static VALUE Joystick_is_connected(VALUE module, VALUE rb_joystick) {
|
|
10
|
+
return BOOL2RB(sfJoystick_isConnected(NUM2UINT(rb_joystick)));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static VALUE Joystick_get_button_count(VALUE module, VALUE rb_joystick) {
|
|
14
|
+
return UINT2NUM(sfJoystick_getButtonCount(NUM2UINT(rb_joystick)));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static VALUE Joystick_has_axis(VALUE module, VALUE rb_joystick, VALUE rb_axis) {
|
|
18
|
+
return BOOL2RB(sfJoystick_hasAxis(NUM2UINT(rb_joystick), joystick_axis_from_rb(rb_axis)));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static VALUE Joystick_is_button_pressed(VALUE module, VALUE rb_joystick, VALUE rb_button) {
|
|
22
|
+
return BOOL2RB(sfJoystick_isButtonPressed(NUM2UINT(rb_joystick), NUM2UINT(rb_button)));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static VALUE Joystick_get_axis_position(VALUE module, VALUE rb_joystick, VALUE rb_axis) {
|
|
26
|
+
return DBL2NUM(sfJoystick_getAxisPosition(NUM2UINT(rb_joystick), joystick_axis_from_rb(rb_axis)));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static VALUE Joystick_get_identification(VALUE module, VALUE rb_joystick) {
|
|
30
|
+
sfJoystickIdentification identification = sfJoystick_getIdentification(NUM2UINT(rb_joystick));
|
|
31
|
+
VALUE hash = rb_hash_new();
|
|
32
|
+
|
|
33
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("name")),
|
|
34
|
+
rb_str_new_cstr(identification.name != NULL ? identification.name : ""));
|
|
35
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("vendor_id")), UINT2NUM(identification.vendorId));
|
|
36
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("product_id")), UINT2NUM(identification.productId));
|
|
37
|
+
|
|
38
|
+
return hash;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static VALUE Joystick_update(VALUE module) {
|
|
42
|
+
sfJoystick_update();
|
|
43
|
+
return Qnil;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void Init_Joystick(VALUE rb_module) {
|
|
47
|
+
VALUE rb_mJoystick = rb_define_module_under(rb_module, "Joystick");
|
|
48
|
+
|
|
49
|
+
rb_define_const(rb_mJoystick, "COUNT", INT2NUM(sfJoystickCount));
|
|
50
|
+
rb_define_const(rb_mJoystick, "BUTTON_COUNT", INT2NUM(sfJoystickButtonCount));
|
|
51
|
+
rb_define_const(rb_mJoystick, "AXIS_COUNT", INT2NUM(sfJoystickAxisCount));
|
|
52
|
+
|
|
53
|
+
rb_define_module_function(rb_mJoystick, "connected?", Joystick_is_connected, 1);
|
|
54
|
+
rb_define_module_function(rb_mJoystick, "button_count", Joystick_get_button_count, 1);
|
|
55
|
+
rb_define_module_function(rb_mJoystick, "has_axis?", Joystick_has_axis, 2);
|
|
56
|
+
rb_define_module_function(rb_mJoystick, "button_pressed?", Joystick_is_button_pressed, 2);
|
|
57
|
+
rb_define_module_function(rb_mJoystick, "axis_position", Joystick_get_axis_position, 2);
|
|
58
|
+
rb_define_module_function(rb_mJoystick, "identification", Joystick_get_identification, 1);
|
|
59
|
+
rb_define_module_function(rb_mJoystick, "update!", Joystick_update, 0);
|
|
60
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
#include "
|
|
1
|
+
#include "window/keyboard.h"
|
|
2
2
|
|
|
3
3
|
#include <stddef.h>
|
|
4
|
+
#include <ruby.h>
|
|
4
5
|
#include <string.h>
|
|
5
6
|
|
|
6
|
-
#include "
|
|
7
|
+
#include "core/exceptions.h"
|
|
8
|
+
#include "core/macros.h"
|
|
9
|
+
#include "core/sfml.h"
|
|
7
10
|
|
|
8
11
|
/* Indexed by sfKeyCode rather than by position: if upstream reorders or
|
|
9
12
|
removes a key, this fails to compile instead of silently renaming every
|
|
@@ -133,3 +136,72 @@ const char *get_key_event(unsigned int key) {
|
|
|
133
136
|
|
|
134
137
|
return "";
|
|
135
138
|
}
|
|
139
|
+
|
|
140
|
+
static int Keyboard_key_code(VALUE rb_key) {
|
|
141
|
+
int code;
|
|
142
|
+
|
|
143
|
+
if (SYMBOL_P(rb_key)) {
|
|
144
|
+
const char *name = rb_id2name(SYM2ID(rb_key));
|
|
145
|
+
|
|
146
|
+
code = find_key(name);
|
|
147
|
+
|
|
148
|
+
if (code < 0) {
|
|
149
|
+
rb_raise(rb_eArgError, "unknown key: %s", name);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return code;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (RB_TYPE_P(rb_key, T_STRING)) {
|
|
156
|
+
const char *name = StringValueCStr(rb_key);
|
|
157
|
+
|
|
158
|
+
code = find_key(name);
|
|
159
|
+
|
|
160
|
+
if (code < 0) {
|
|
161
|
+
rb_raise(rb_eArgError, "unknown key: %s", name);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return code;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return NUM2INT(rb_key);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static VALUE Keyboard_pressed_p(VALUE module, VALUE rb_key) {
|
|
171
|
+
return BOOL2RB(sfKeyboard_isKeyPressed((sfKeyCode) Keyboard_key_code(rb_key)));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static VALUE Keyboard_scancode_pressed_p(VALUE module, VALUE rb_scancode) {
|
|
175
|
+
return BOOL2RB(sfKeyboard_isScancodePressed((sfScancode) NUM2INT(rb_scancode)));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static VALUE Keyboard_localize(VALUE module, VALUE rb_scancode) {
|
|
179
|
+
return ID2SYM(rb_intern(get_key_event((unsigned int) sfKeyboard_localize((sfScancode) NUM2INT(rb_scancode)))));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static VALUE Keyboard_delocalize(VALUE module, VALUE rb_key) {
|
|
183
|
+
return INT2NUM(sfKeyboard_delocalize((sfKeyCode) Keyboard_key_code(rb_key)));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static VALUE Keyboard_description(VALUE module, VALUE rb_scancode) {
|
|
187
|
+
const char *description = sfKeyboard_getDescription((sfScancode) NUM2INT(rb_scancode));
|
|
188
|
+
|
|
189
|
+
return rb_str_new_cstr(description != NULL ? description : "");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static VALUE Keyboard_set_virtual_keyboard_visible(VALUE module, VALUE rb_visible) {
|
|
193
|
+
sfKeyboard_setVirtualKeyboardVisible(RTEST(rb_visible));
|
|
194
|
+
return rb_visible;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
void Init_Keyboard(VALUE rb_module) {
|
|
198
|
+
VALUE rb_mKeyboard = rb_define_module_under(rb_module, "Keyboard");
|
|
199
|
+
|
|
200
|
+
rb_define_module_function(rb_mKeyboard, "pressed?", Keyboard_pressed_p, 1);
|
|
201
|
+
rb_define_module_function(rb_mKeyboard, "scancode_pressed?", Keyboard_scancode_pressed_p, 1);
|
|
202
|
+
rb_define_module_function(rb_mKeyboard, "localize", Keyboard_localize, 1);
|
|
203
|
+
rb_define_module_function(rb_mKeyboard, "delocalize", Keyboard_delocalize, 1);
|
|
204
|
+
rb_define_module_function(rb_mKeyboard, "description", Keyboard_description, 1);
|
|
205
|
+
rb_define_module_function(rb_mKeyboard, "virtual_keyboard_visible=",
|
|
206
|
+
Keyboard_set_virtual_keyboard_visible, 1);
|
|
207
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#ifndef SFML_RB_WINDOW_KEYBOARD_H
|
|
2
|
+
#define SFML_RB_WINDOW_KEYBOARD_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
void Init_Keyboard(VALUE rb_module);
|
|
7
|
+
|
|
8
|
+
int find_key(const char *name);
|
|
9
|
+
|
|
10
|
+
const char *get_key_event(unsigned int key);
|
|
11
|
+
|
|
12
|
+
#endif //SFML_RB_WINDOW_KEYBOARD_H
|
data/ext/window/mouse.c
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#include "window/mouse.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
|
|
5
|
+
#include "window/input_enums.h"
|
|
6
|
+
#include "window/window.h"
|
|
7
|
+
#include "system/vec2.h"
|
|
8
|
+
#include "core/exceptions.h"
|
|
9
|
+
#include "core/macros.h"
|
|
10
|
+
#include "core/sfml.h"
|
|
11
|
+
|
|
12
|
+
/* nil means desktop-relative. CSFML gives sfRenderWindow its own entry points,
|
|
13
|
+
so a window argument never has to be cast down to sfWindowBase. */
|
|
14
|
+
static const sfRenderWindow* Mouse_relative_window(VALUE rb_window) {
|
|
15
|
+
if (NIL_P(rb_window)) {
|
|
16
|
+
return NULL;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
|
|
20
|
+
raise_invalid_argument_class(Get_Klass_Window());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return Get_Window_Struct(rb_window);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static VALUE Mouse_is_button_pressed(VALUE module, VALUE rb_button) {
|
|
27
|
+
return BOOL2RB(sfMouse_isButtonPressed(mouse_button_from_rb(rb_button)));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static VALUE Mouse_get_position(int argc, VALUE* argv, VALUE module) {
|
|
31
|
+
VALUE rb_window;
|
|
32
|
+
sfVector2i position;
|
|
33
|
+
|
|
34
|
+
rb_scan_args(argc, argv, "01", &rb_window);
|
|
35
|
+
if (NIL_P(rb_window)) {
|
|
36
|
+
position = sfMouse_getPosition(NULL);
|
|
37
|
+
} else {
|
|
38
|
+
position = sfMouse_getPositionRenderWindow(Mouse_relative_window(rb_window));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return vec2f_to_rb((sfVector2f){(float)position.x, (float)position.y});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static VALUE Mouse_set_position(int argc, VALUE* argv, VALUE module) {
|
|
45
|
+
VALUE rb_position, rb_window;
|
|
46
|
+
|
|
47
|
+
rb_scan_args(argc, argv, "11", &rb_position, &rb_window);
|
|
48
|
+
if (NIL_P(rb_window)) {
|
|
49
|
+
sfMouse_setPosition(vec2i_from_rb(rb_position), NULL);
|
|
50
|
+
} else {
|
|
51
|
+
sfMouse_setPositionRenderWindow(vec2i_from_rb(rb_position),
|
|
52
|
+
Mouse_relative_window(rb_window));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return rb_position;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static VALUE Mouse_position_eq(VALUE module, VALUE rb_position) {
|
|
59
|
+
return Mouse_set_position(1, &rb_position, module);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void Init_Mouse(VALUE rb_module) {
|
|
63
|
+
VALUE rb_mMouse = rb_define_module_under(rb_module, "Mouse");
|
|
64
|
+
|
|
65
|
+
rb_define_module_function(rb_mMouse, "button_pressed?", Mouse_is_button_pressed, 1);
|
|
66
|
+
rb_define_module_function(rb_mMouse, "pressed?", Mouse_is_button_pressed, 1);
|
|
67
|
+
rb_define_module_function(rb_mMouse, "position", Mouse_get_position, -1);
|
|
68
|
+
rb_define_module_function(rb_mMouse, "set_position", Mouse_set_position, -1);
|
|
69
|
+
rb_define_module_function(rb_mMouse, "position=", Mouse_position_eq, 1);
|
|
70
|
+
}
|
data/ext/window/mouse.h
ADDED
data/ext/window/sensor.c
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#include "window/sensor.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
|
|
5
|
+
#include "window/input_enums.h"
|
|
6
|
+
#include "system/vec3.h"
|
|
7
|
+
#include "core/macros.h"
|
|
8
|
+
#include "core/sfml.h"
|
|
9
|
+
|
|
10
|
+
static VALUE Sensor_is_available(VALUE module, VALUE rb_type) {
|
|
11
|
+
return BOOL2RB(sfSensor_isAvailable(sensor_type_from_rb(rb_type)));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static VALUE Sensor_set_enabled(VALUE module, VALUE rb_type, VALUE rb_enabled) {
|
|
15
|
+
sfSensor_setEnabled(sensor_type_from_rb(rb_type), RTEST(rb_enabled));
|
|
16
|
+
return rb_enabled;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static VALUE Sensor_get_value(VALUE module, VALUE rb_type) {
|
|
20
|
+
return vec3f_to_rb(sfSensor_getValue(sensor_type_from_rb(rb_type)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void Init_Sensor(VALUE rb_module) {
|
|
24
|
+
VALUE rb_mSensor = rb_define_module_under(rb_module, "Sensor");
|
|
25
|
+
|
|
26
|
+
rb_define_module_function(rb_mSensor, "available?", Sensor_is_available, 1);
|
|
27
|
+
rb_define_module_function(rb_mSensor, "set_enabled", Sensor_set_enabled, 2);
|
|
28
|
+
rb_define_module_function(rb_mSensor, "enabled=", Sensor_set_enabled, 2);
|
|
29
|
+
rb_define_module_function(rb_mSensor, "value", Sensor_get_value, 1);
|
|
30
|
+
}
|
data/ext/window/sensor.h
ADDED
data/ext/window/touch.c
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#include "window/touch.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
|
|
5
|
+
#include "window/window.h"
|
|
6
|
+
#include "system/vec2.h"
|
|
7
|
+
#include "core/exceptions.h"
|
|
8
|
+
#include "core/macros.h"
|
|
9
|
+
#include "core/sfml.h"
|
|
10
|
+
|
|
11
|
+
/* nil means desktop-relative. CSFML gives sfRenderWindow its own entry point,
|
|
12
|
+
so a window argument never has to be cast down to sfWindowBase. */
|
|
13
|
+
static const sfRenderWindow* Touch_relative_window(VALUE rb_window) {
|
|
14
|
+
if (NIL_P(rb_window)) {
|
|
15
|
+
return NULL;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!rb_obj_is_kind_of(rb_window, Get_Klass_Window())) {
|
|
19
|
+
raise_invalid_argument_class(Get_Klass_Window());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return Get_Window_Struct(rb_window);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static VALUE Touch_is_down(VALUE module, VALUE rb_finger) {
|
|
26
|
+
return BOOL2RB(sfTouch_isDown(NUM2UINT(rb_finger)));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static VALUE Touch_get_position(int argc, VALUE* argv, VALUE module) {
|
|
30
|
+
VALUE rb_finger, rb_window;
|
|
31
|
+
sfVector2i position;
|
|
32
|
+
|
|
33
|
+
rb_scan_args(argc, argv, "11", &rb_finger, &rb_window);
|
|
34
|
+
if (NIL_P(rb_window)) {
|
|
35
|
+
position = sfTouch_getPosition(NUM2UINT(rb_finger), NULL);
|
|
36
|
+
} else {
|
|
37
|
+
position =
|
|
38
|
+
sfTouch_getPositionRenderWindow(NUM2UINT(rb_finger), Touch_relative_window(rb_window));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return vec2f_to_rb((sfVector2f){(float)position.x, (float)position.y});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void Init_Touch(VALUE rb_module) {
|
|
45
|
+
VALUE rb_mTouch = rb_define_module_under(rb_module, "Touch");
|
|
46
|
+
|
|
47
|
+
rb_define_module_function(rb_mTouch, "down?", Touch_is_down, 1);
|
|
48
|
+
rb_define_module_function(rb_mTouch, "position", Touch_get_position, -1);
|
|
49
|
+
}
|