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,220 @@
|
|
|
1
|
+
#include "window/context_settings.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
|
|
7
|
+
#include "core/exceptions.h"
|
|
8
|
+
#include "core/macros.h"
|
|
9
|
+
|
|
10
|
+
typedef struct {
|
|
11
|
+
sfContextSettings settings;
|
|
12
|
+
} ContextSettings;
|
|
13
|
+
|
|
14
|
+
static VALUE rb_cContextSettings;
|
|
15
|
+
|
|
16
|
+
static void ContextSettings_free(void *ptr) {
|
|
17
|
+
free(ptr);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static const rb_data_type_t ContextSettings_data_type = {
|
|
21
|
+
.wrap_struct_name = "SFML::ContextSettings",
|
|
22
|
+
.function = {.dmark = NULL, .dfree = ContextSettings_free, .dsize = NULL},
|
|
23
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
static VALUE ContextSettings_wrap(sfContextSettings settings) {
|
|
27
|
+
ContextSettings *ptr = malloc(sizeof(ContextSettings));
|
|
28
|
+
|
|
29
|
+
ptr->settings = settings;
|
|
30
|
+
|
|
31
|
+
return TypedData_Wrap_Struct(rb_cContextSettings, &ContextSettings_data_type, ptr);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static const char *context_flag_name(VALUE value) {
|
|
35
|
+
if (SYMBOL_P(value)) {
|
|
36
|
+
return rb_id2name(SYM2ID(value));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return StringValueCStr(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static VALUE ContextSettings_new(int argc, VALUE *argv, VALUE klass) { sfContextSettings settings = {0, 0, 0, 1, 1, sfContextDefault, false};
|
|
43
|
+
VALUE rb_depth, rb_stencil, rb_antialiasing, rb_major, rb_minor, rb_flags, rb_srgb;
|
|
44
|
+
VALUE self;
|
|
45
|
+
|
|
46
|
+
rb_scan_args(argc, argv, "07", &rb_depth, &rb_stencil, &rb_antialiasing, &rb_major, &rb_minor, &rb_flags,
|
|
47
|
+
&rb_srgb);
|
|
48
|
+
|
|
49
|
+
if (!NIL_P(rb_depth)) {
|
|
50
|
+
settings.depthBits = (unsigned int) NUM2UINT(rb_depth);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!NIL_P(rb_stencil)) {
|
|
54
|
+
settings.stencilBits = (unsigned int) NUM2UINT(rb_stencil);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!NIL_P(rb_antialiasing)) {
|
|
58
|
+
settings.antiAliasingLevel = (unsigned int) NUM2UINT(rb_antialiasing);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!NIL_P(rb_major)) {
|
|
62
|
+
settings.majorVersion = (unsigned int) NUM2UINT(rb_major);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!NIL_P(rb_minor)) {
|
|
66
|
+
settings.minorVersion = (unsigned int) NUM2UINT(rb_minor);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!NIL_P(rb_flags)) {
|
|
70
|
+
uint32_t flags = 0;
|
|
71
|
+
|
|
72
|
+
if (RB_INTEGER_TYPE_P(rb_flags)) {
|
|
73
|
+
flags = (uint32_t) NUM2UINT(rb_flags);
|
|
74
|
+
} else if (SYMBOL_P(rb_flags) || RB_TYPE_P(rb_flags, T_STRING)) {
|
|
75
|
+
rb_flags = rb_ary_new_from_args(1, rb_flags);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (RB_TYPE_P(rb_flags, T_ARRAY)) {
|
|
79
|
+
for (long i = 0; i < RARRAY_LEN(rb_flags); i++) {
|
|
80
|
+
VALUE entry = rb_ary_entry(rb_flags, i);
|
|
81
|
+
const char *name = context_flag_name(entry);
|
|
82
|
+
|
|
83
|
+
if (strcmp(name, "core") == 0) {
|
|
84
|
+
flags |= sfContextCore;
|
|
85
|
+
} else if (strcmp(name, "debug") == 0) {
|
|
86
|
+
flags |= sfContextDebug;
|
|
87
|
+
} else if (strcmp(name, "default") != 0) {
|
|
88
|
+
rb_raise(rb_eArgError, "unknown context attribute: %s", name);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
settings.attributeFlags = flags;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!NIL_P(rb_srgb)) {
|
|
97
|
+
settings.sRgbCapable = RTEST(rb_srgb);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
self = ContextSettings_wrap(settings);
|
|
101
|
+
|
|
102
|
+
return self;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
#define CONTEXT_SETTINGS_UINT_ACCESSOR(name, field) \
|
|
106
|
+
static VALUE ContextSettings_get_##name(VALUE self) { \
|
|
107
|
+
return UINT2NUM(((ContextSettings *) Get_ContextSettings_Struct(self))->settings.field); \
|
|
108
|
+
} \
|
|
109
|
+
static VALUE ContextSettings_set_##name(VALUE self, VALUE rb_value) { \
|
|
110
|
+
((ContextSettings *) Get_ContextSettings_Struct(self))->settings.field = (unsigned int) NUM2UINT(rb_value); \
|
|
111
|
+
return rb_value; \
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
CONTEXT_SETTINGS_UINT_ACCESSOR(depth_bits, depthBits)
|
|
115
|
+
CONTEXT_SETTINGS_UINT_ACCESSOR(stencil_bits, stencilBits)
|
|
116
|
+
CONTEXT_SETTINGS_UINT_ACCESSOR(antialiasing_level, antiAliasingLevel)
|
|
117
|
+
CONTEXT_SETTINGS_UINT_ACCESSOR(major_version, majorVersion)
|
|
118
|
+
CONTEXT_SETTINGS_UINT_ACCESSOR(minor_version, minorVersion)
|
|
119
|
+
|
|
120
|
+
static VALUE ContextSettings_get_attribute_flags(VALUE self) {
|
|
121
|
+
uint32_t flags = ((ContextSettings *) Get_ContextSettings_Struct(self))->settings.attributeFlags;
|
|
122
|
+
VALUE array = rb_ary_new();
|
|
123
|
+
|
|
124
|
+
if ((flags & sfContextCore) != 0) {
|
|
125
|
+
rb_ary_push(array, ID2SYM(rb_intern("core")));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if ((flags & sfContextDebug) != 0) {
|
|
129
|
+
rb_ary_push(array, ID2SYM(rb_intern("debug")));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (RARRAY_LEN(array) == 0) {
|
|
133
|
+
rb_ary_push(array, ID2SYM(rb_intern("default")));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return array;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static VALUE ContextSettings_set_attribute_flags(VALUE self, VALUE rb_value) {
|
|
140
|
+
ContextSettings *settings = Get_ContextSettings_Struct(self);
|
|
141
|
+
uint32_t flags = 0;
|
|
142
|
+
|
|
143
|
+
if (RB_INTEGER_TYPE_P(rb_value)) {
|
|
144
|
+
flags = (uint32_t) NUM2UINT(rb_value);
|
|
145
|
+
} else {
|
|
146
|
+
VALUE array = RB_TYPE_P(rb_value, T_ARRAY) ? rb_value : rb_ary_new_from_args(1, rb_value);
|
|
147
|
+
|
|
148
|
+
for (long i = 0; i < RARRAY_LEN(array); i++) {
|
|
149
|
+
VALUE entry = rb_ary_entry(array, i);
|
|
150
|
+
const char *name = context_flag_name(entry);
|
|
151
|
+
|
|
152
|
+
if (strcmp(name, "core") == 0) {
|
|
153
|
+
flags |= sfContextCore;
|
|
154
|
+
} else if (strcmp(name, "debug") == 0) {
|
|
155
|
+
flags |= sfContextDebug;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
settings->settings.attributeFlags = flags;
|
|
161
|
+
|
|
162
|
+
return rb_value;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static VALUE ContextSettings_get_srgb(VALUE self) {
|
|
166
|
+
return BOOL2RB(((ContextSettings *) Get_ContextSettings_Struct(self))->settings.sRgbCapable);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static VALUE ContextSettings_set_srgb(VALUE self, VALUE rb_value) {
|
|
170
|
+
((ContextSettings *) Get_ContextSettings_Struct(self))->settings.sRgbCapable = RTEST(rb_value);
|
|
171
|
+
return rb_value;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
void Init_ContextSettings(VALUE rb_module) {
|
|
175
|
+
rb_cContextSettings = rb_define_class_under(rb_module, "ContextSettings", rb_cObject);
|
|
176
|
+
|
|
177
|
+
rb_define_singleton_method(rb_cContextSettings, "new", ContextSettings_new, -1);
|
|
178
|
+
|
|
179
|
+
rb_define_method(rb_cContextSettings, "depth_bits", ContextSettings_get_depth_bits, 0);
|
|
180
|
+
rb_define_method(rb_cContextSettings, "stencil_bits", ContextSettings_get_stencil_bits, 0);
|
|
181
|
+
rb_define_method(rb_cContextSettings, "antialiasing_level", ContextSettings_get_antialiasing_level, 0);
|
|
182
|
+
rb_define_method(rb_cContextSettings, "major_version", ContextSettings_get_major_version, 0);
|
|
183
|
+
rb_define_method(rb_cContextSettings, "minor_version", ContextSettings_get_minor_version, 0);
|
|
184
|
+
rb_define_method(rb_cContextSettings, "attribute_flags", ContextSettings_get_attribute_flags, 0);
|
|
185
|
+
rb_define_method(rb_cContextSettings, "srgb_capable?", ContextSettings_get_srgb, 0);
|
|
186
|
+
|
|
187
|
+
rb_define_method(rb_cContextSettings, "depth_bits=", ContextSettings_set_depth_bits, 1);
|
|
188
|
+
rb_define_method(rb_cContextSettings, "stencil_bits=", ContextSettings_set_stencil_bits, 1);
|
|
189
|
+
rb_define_method(rb_cContextSettings, "antialiasing_level=", ContextSettings_set_antialiasing_level, 1);
|
|
190
|
+
rb_define_method(rb_cContextSettings, "major_version=", ContextSettings_set_major_version, 1);
|
|
191
|
+
rb_define_method(rb_cContextSettings, "minor_version=", ContextSettings_set_minor_version, 1);
|
|
192
|
+
rb_define_method(rb_cContextSettings, "attribute_flags=", ContextSettings_set_attribute_flags, 1);
|
|
193
|
+
rb_define_method(rb_cContextSettings, "srgb_capable=", ContextSettings_set_srgb, 1);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
VALUE Get_Klass_ContextSettings(void) {
|
|
197
|
+
return rb_cContextSettings;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
void *Get_ContextSettings_Struct(VALUE self) {
|
|
201
|
+
ContextSettings *ptr;
|
|
202
|
+
TypedData_Get_Struct(self, ContextSettings, &ContextSettings_data_type, ptr);
|
|
203
|
+
return ptr;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
sfContextSettings context_settings_from_rb(VALUE rb_settings) {
|
|
207
|
+
if (NIL_P(rb_settings)) {
|
|
208
|
+
return (sfContextSettings) {0, 0, 0, 1, 1, sfContextDefault, false};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!rb_obj_is_kind_of(rb_settings, rb_cContextSettings)) {
|
|
212
|
+
raise_invalid_argument_class(rb_cContextSettings);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return ((ContextSettings *) Get_ContextSettings_Struct(rb_settings))->settings;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
VALUE context_settings_to_rb(sfContextSettings settings) {
|
|
219
|
+
return ContextSettings_wrap(settings);
|
|
220
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#ifndef SFML_RB_WINDOW_CONTEXT_SETTINGS_H
|
|
2
|
+
#define SFML_RB_WINDOW_CONTEXT_SETTINGS_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
void Init_ContextSettings(VALUE rb_module);
|
|
9
|
+
|
|
10
|
+
VALUE Get_Klass_ContextSettings(void);
|
|
11
|
+
|
|
12
|
+
void *Get_ContextSettings_Struct(VALUE self);
|
|
13
|
+
|
|
14
|
+
sfContextSettings context_settings_from_rb(VALUE rb_settings);
|
|
15
|
+
|
|
16
|
+
VALUE context_settings_to_rb(sfContextSettings settings);
|
|
17
|
+
|
|
18
|
+
#endif //SFML_RB_WINDOW_CONTEXT_SETTINGS_H
|
data/ext/window/cursor.c
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#include "window/cursor.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
|
|
5
|
+
#include "window/input_enums.h"
|
|
6
|
+
#include "system/vec2.h"
|
|
7
|
+
#include "core/macros.h"
|
|
8
|
+
#include "core/sfml.h"
|
|
9
|
+
|
|
10
|
+
static VALUE rb_cCursor;
|
|
11
|
+
|
|
12
|
+
static void Cursor_free(void *ptr) {
|
|
13
|
+
sfCursor_destroy(ptr);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static const rb_data_type_t Cursor_data_type = {
|
|
17
|
+
.wrap_struct_name = "SFML::Cursor",
|
|
18
|
+
.function = {.dmark = NULL, .dfree = Cursor_free, .dsize = NULL},
|
|
19
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
static VALUE Cursor_wrap(sfCursor *cursor) {
|
|
23
|
+
if (cursor == NULL) {
|
|
24
|
+
rb_raise(rb_eRuntimeError, "failed to create cursor");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return TypedData_Wrap_Struct(rb_cCursor, &Cursor_data_type, cursor);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static VALUE Cursor_from_pixels(VALUE klass, VALUE rb_pixels, VALUE rb_size, VALUE rb_hotspot) {
|
|
31
|
+
StringValue(rb_pixels);
|
|
32
|
+
|
|
33
|
+
return Cursor_wrap(sfCursor_createFromPixels((const uint8_t *) RSTRING_PTR(rb_pixels), vec2u_from_rb(rb_size),
|
|
34
|
+
vec2u_from_rb(rb_hotspot)));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static VALUE Cursor_from_system(VALUE klass, VALUE rb_type) {
|
|
38
|
+
return Cursor_wrap(sfCursor_createFromSystem(cursor_type_from_rb(rb_type)));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
void Init_Cursor(VALUE rb_module) {
|
|
42
|
+
rb_cCursor = rb_define_class_under(rb_module, "Cursor", rb_cObject);
|
|
43
|
+
|
|
44
|
+
rb_define_singleton_method(rb_cCursor, "from_pixels", Cursor_from_pixels, 3);
|
|
45
|
+
rb_define_singleton_method(rb_cCursor, "from_system", Cursor_from_system, 1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
VALUE Get_Klass_Cursor(void) {
|
|
49
|
+
return rb_cCursor;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const sfCursor *Get_Cursor_Struct(VALUE self) {
|
|
53
|
+
sfCursor *ptr;
|
|
54
|
+
TypedData_Get_Struct(self, sfCursor, &Cursor_data_type, ptr);
|
|
55
|
+
return ptr;
|
|
56
|
+
}
|
data/ext/window/cursor.h
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#ifndef SFML_RB_WINDOW_CURSOR_H
|
|
2
|
+
#define SFML_RB_WINDOW_CURSOR_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
void Init_Cursor(VALUE rb_module);
|
|
9
|
+
|
|
10
|
+
VALUE Get_Klass_Cursor(void);
|
|
11
|
+
|
|
12
|
+
const sfCursor *Get_Cursor_Struct(VALUE self);
|
|
13
|
+
|
|
14
|
+
#endif //SFML_RB_WINDOW_CURSOR_H
|
data/ext/window/event.c
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
#include "window/event.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
|
|
7
|
+
#include "window/event_name.h"
|
|
8
|
+
#include "window/keyboard.h"
|
|
9
|
+
#include "window/input_enums.h"
|
|
10
|
+
#include "system/vec2.h"
|
|
11
|
+
#include "system/vec3.h"
|
|
12
|
+
#include "core/macros.h"
|
|
13
|
+
#include "core/sfml.h"
|
|
14
|
+
|
|
15
|
+
static VALUE rb_cEvent;
|
|
16
|
+
|
|
17
|
+
static sfEvent *Event_create() {
|
|
18
|
+
return malloc(sizeof(sfEvent));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static void Event_free(void *ptr) {
|
|
22
|
+
free(ptr);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static const rb_data_type_t Event_data_type = {
|
|
26
|
+
.wrap_struct_name = "SFML::Event",
|
|
27
|
+
.function = {.dmark = NULL, .dfree = Event_free, .dsize = NULL},
|
|
28
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
static VALUE Event_new(VALUE klass) {
|
|
32
|
+
VALUE self;
|
|
33
|
+
sfEvent *event;
|
|
34
|
+
|
|
35
|
+
event = Event_create();
|
|
36
|
+
self = TypedData_Wrap_Struct(klass, &Event_data_type, event);
|
|
37
|
+
|
|
38
|
+
rb_obj_call_init(self, 0, NULL);
|
|
39
|
+
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static VALUE Event_init(VALUE self) {
|
|
44
|
+
return self;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static VALUE Event_type(VALUE self) {
|
|
48
|
+
return rb_str_new2(get_event_name(Get_Event_Struct(self)->type));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static VALUE Event_get_size(VALUE self) {
|
|
52
|
+
sfVector2u size = Get_Event_Struct(self)->size.size;
|
|
53
|
+
|
|
54
|
+
return vec2f_to_rb((sfVector2f) {(float) size.x, (float) size.y});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static VALUE Event_get_key(VALUE self) {
|
|
58
|
+
sfKeyEvent *event = &Get_Event_Struct(self)->key;
|
|
59
|
+
VALUE hash = rb_hash_new();
|
|
60
|
+
|
|
61
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("code")), ID2SYM(rb_intern(get_key_event(event->code))));
|
|
62
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("scancode")), rb_str_new2(sfKeyboard_getDescription(event->scancode)));
|
|
63
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("alt")), BOOL2RB(event->alt));
|
|
64
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("control")), BOOL2RB(event->control));
|
|
65
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("shift")), BOOL2RB(event->shift));
|
|
66
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("system")), BOOL2RB(event->system));
|
|
67
|
+
|
|
68
|
+
return hash;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static VALUE unicode_to_utf8(uint32_t code) {
|
|
72
|
+
char buffer[5];
|
|
73
|
+
int length = 0;
|
|
74
|
+
|
|
75
|
+
if (code < 0x80) {
|
|
76
|
+
buffer[length++] = (char) code;
|
|
77
|
+
} else if (code < 0x800) {
|
|
78
|
+
buffer[length++] = (char) (0xC0 | (code >> 6));
|
|
79
|
+
buffer[length++] = (char) (0x80 | (code & 0x3F));
|
|
80
|
+
} else if (code < 0x10000) {
|
|
81
|
+
buffer[length++] = (char) (0xE0 | (code >> 12));
|
|
82
|
+
buffer[length++] = (char) (0x80 | ((code >> 6) & 0x3F));
|
|
83
|
+
buffer[length++] = (char) (0x80 | (code & 0x3F));
|
|
84
|
+
} else {
|
|
85
|
+
buffer[length++] = (char) (0xF0 | (code >> 18));
|
|
86
|
+
buffer[length++] = (char) (0x80 | ((code >> 12) & 0x3F));
|
|
87
|
+
buffer[length++] = (char) (0x80 | ((code >> 6) & 0x3F));
|
|
88
|
+
buffer[length++] = (char) (0x80 | (code & 0x3F));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return rb_utf8_str_new(buffer, length);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static VALUE Event_get_text(VALUE self) {
|
|
95
|
+
return unicode_to_utf8(Get_Event_Struct(self)->text.unicode);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static VALUE Event_get_mouse_move(VALUE self) {
|
|
99
|
+
sfVector2i position = Get_Event_Struct(self)->mouseMove.position;
|
|
100
|
+
|
|
101
|
+
return vec2f_to_rb((sfVector2f) {(float) position.x, (float) position.y});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static VALUE Event_get_mouse_move_raw(VALUE self) {
|
|
105
|
+
sfVector2i delta = Get_Event_Struct(self)->mouseMoveRaw.delta;
|
|
106
|
+
|
|
107
|
+
return vec2f_to_rb((sfVector2f) {(float) delta.x, (float) delta.y});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static VALUE Event_get_mouse_button(VALUE self) {
|
|
111
|
+
sfMouseButtonEvent *event = &Get_Event_Struct(self)->mouseButton;
|
|
112
|
+
VALUE hash = rb_hash_new();
|
|
113
|
+
|
|
114
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("button")), ID2SYM(rb_intern(mouse_button_name(event->button))));
|
|
115
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("position")),
|
|
116
|
+
vec2f_to_rb((sfVector2f) {(float) event->position.x, (float) event->position.y}));
|
|
117
|
+
|
|
118
|
+
return hash;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static VALUE Event_get_mouse_wheel_scroll(VALUE self) {
|
|
122
|
+
sfMouseWheelScrollEvent *event = &Get_Event_Struct(self)->mouseWheelScroll;
|
|
123
|
+
VALUE hash = rb_hash_new();
|
|
124
|
+
|
|
125
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("wheel")), ID2SYM(rb_intern(mouse_wheel_name(event->wheel))));
|
|
126
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("delta")), DBL2NUM(event->delta));
|
|
127
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("position")),
|
|
128
|
+
vec2f_to_rb((sfVector2f) {(float) event->position.x, (float) event->position.y}));
|
|
129
|
+
|
|
130
|
+
return hash;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static VALUE Event_get_joystick_move(VALUE self) {
|
|
134
|
+
sfJoystickMoveEvent *event = &Get_Event_Struct(self)->joystickMove;
|
|
135
|
+
VALUE hash = rb_hash_new();
|
|
136
|
+
|
|
137
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")), UINT2NUM(event->joystickId));
|
|
138
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("axis")), ID2SYM(rb_intern(joystick_axis_name(event->axis))));
|
|
139
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("position")), DBL2NUM(event->position));
|
|
140
|
+
|
|
141
|
+
return hash;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static VALUE Event_get_joystick_button(VALUE self) {
|
|
145
|
+
sfJoystickButtonEvent *event = &Get_Event_Struct(self)->joystickButton;
|
|
146
|
+
VALUE hash = rb_hash_new();
|
|
147
|
+
|
|
148
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")), UINT2NUM(event->joystickId));
|
|
149
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("button")), UINT2NUM(event->button));
|
|
150
|
+
|
|
151
|
+
return hash;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static VALUE Event_get_joystick_connect(VALUE self) {
|
|
155
|
+
sfEvent *event = Get_Event_Struct(self);
|
|
156
|
+
VALUE hash = rb_hash_new();
|
|
157
|
+
|
|
158
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")), UINT2NUM(event->joystickConnect.joystickId));
|
|
159
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("connected")), BOOL2RB(event->type == sfEvtJoystickConnected));
|
|
160
|
+
|
|
161
|
+
return hash;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
static VALUE Event_get_touch(VALUE self) {
|
|
165
|
+
sfTouchEvent *event = &Get_Event_Struct(self)->touch;
|
|
166
|
+
VALUE hash = rb_hash_new();
|
|
167
|
+
|
|
168
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("finger")), UINT2NUM(event->finger));
|
|
169
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("position")),
|
|
170
|
+
vec2f_to_rb((sfVector2f) {(float) event->position.x, (float) event->position.y}));
|
|
171
|
+
|
|
172
|
+
return hash;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static VALUE Event_get_sensor(VALUE self) {
|
|
176
|
+
sfSensorEvent *event = &Get_Event_Struct(self)->sensor;
|
|
177
|
+
VALUE hash = rb_hash_new();
|
|
178
|
+
|
|
179
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("type")), ID2SYM(rb_intern(sensor_type_name(event->sensorType))));
|
|
180
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("value")), vec3f_to_rb(event->value));
|
|
181
|
+
|
|
182
|
+
return hash;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void Init_Event(VALUE rb_module) {
|
|
186
|
+
rb_cEvent = rb_define_class_under(rb_module, "Event", rb_cObject);
|
|
187
|
+
|
|
188
|
+
rb_define_singleton_method(rb_cEvent, "new", Event_new, 0);
|
|
189
|
+
|
|
190
|
+
rb_define_method(rb_cEvent, "initialize", Event_init, 0);
|
|
191
|
+
|
|
192
|
+
rb_define_method(rb_cEvent, "type", Event_type, 0);
|
|
193
|
+
rb_define_method(rb_cEvent, "size", Event_get_size, 0);
|
|
194
|
+
rb_define_method(rb_cEvent, "key", Event_get_key, 0);
|
|
195
|
+
rb_define_method(rb_cEvent, "text", Event_get_text, 0);
|
|
196
|
+
rb_define_method(rb_cEvent, "mouse_move", Event_get_mouse_move, 0);
|
|
197
|
+
rb_define_method(rb_cEvent, "mouse_move_raw", Event_get_mouse_move_raw, 0);
|
|
198
|
+
rb_define_method(rb_cEvent, "mouse_button", Event_get_mouse_button, 0);
|
|
199
|
+
rb_define_method(rb_cEvent, "mouse_wheel_scroll", Event_get_mouse_wheel_scroll, 0);
|
|
200
|
+
rb_define_method(rb_cEvent, "mouse_wheel", Event_get_mouse_wheel_scroll, 0);
|
|
201
|
+
rb_define_method(rb_cEvent, "joystick_move", Event_get_joystick_move, 0);
|
|
202
|
+
rb_define_method(rb_cEvent, "joystick_button", Event_get_joystick_button, 0);
|
|
203
|
+
rb_define_method(rb_cEvent, "joystick_connect", Event_get_joystick_connect, 0);
|
|
204
|
+
rb_define_method(rb_cEvent, "touch", Event_get_touch, 0);
|
|
205
|
+
rb_define_method(rb_cEvent, "sensor", Event_get_sensor, 0);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
sfEvent *Get_Event_Struct(VALUE self) {
|
|
209
|
+
sfEvent *ptr;
|
|
210
|
+
TypedData_Get_Struct(self, sfEvent, &Event_data_type, ptr);
|
|
211
|
+
return ptr;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
VALUE Get_Klass_Event() {
|
|
215
|
+
return rb_cEvent;
|
|
216
|
+
}
|
data/ext/window/event.h
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#ifndef SFML_RB_WINDOW_EVENT_H
|
|
2
|
+
#define SFML_RB_WINDOW_EVENT_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
void Init_Event(VALUE rb_module);
|
|
9
|
+
|
|
10
|
+
sfEvent *Get_Event_Struct(VALUE self);
|
|
11
|
+
|
|
12
|
+
VALUE Get_Klass_Event();
|
|
13
|
+
|
|
14
|
+
#endif //SFML_RB_WINDOW_EVENT_H
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#include "
|
|
1
|
+
#include "window/event_name.h"
|
|
2
2
|
|
|
3
3
|
#include <stddef.h>
|
|
4
4
|
|
|
5
|
-
#include "
|
|
5
|
+
#include "core/sfml.h"
|
|
6
6
|
|
|
7
7
|
/* Indexed by sfEventType rather than by position. The CSFML 2.x table was
|
|
8
8
|
positional, which broke silently under CSFML 3: the enum still has 24
|