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,286 @@
|
|
1
|
+
#include "rubysdl2_internal.h"
|
2
|
+
#include <SDL_mouse.h>
|
3
|
+
#include <SDL_events.h>
|
4
|
+
|
5
|
+
static VALUE mMouse;
|
6
|
+
static VALUE cCursor;
|
7
|
+
static VALUE cState;
|
8
|
+
|
9
|
+
/*
|
10
|
+
* Document-module: SDL2::Mouse
|
11
|
+
*
|
12
|
+
* This module has mouse input handling functions.
|
13
|
+
*
|
14
|
+
*/
|
15
|
+
|
16
|
+
/*
|
17
|
+
* Document-class: SDL2::Mouse::Cursor
|
18
|
+
*
|
19
|
+
* This class represents mouse cursor shape, and
|
20
|
+
* have some class-methods for a mouse cursor.
|
21
|
+
*/
|
22
|
+
|
23
|
+
/*
|
24
|
+
* Document-class: SDL2::Mouse::State
|
25
|
+
*
|
26
|
+
* This class represents mouse stetes.
|
27
|
+
*
|
28
|
+
* You can get a mouse state with {SDL2::Mouse.state}.
|
29
|
+
*
|
30
|
+
* @!attribute [r] x
|
31
|
+
* the x coordinate of the mouse cursor.
|
32
|
+
*
|
33
|
+
* For {SDL2::Mouse.state}, this attribute means the x coordinate
|
34
|
+
* relative to the window.
|
35
|
+
* For {SDL2::Mouse.relative_state}, this attribute means the x coordinate
|
36
|
+
* relative to the previous call of {SDL2::Mouse.relative_state}.
|
37
|
+
*
|
38
|
+
* @return [Integer]
|
39
|
+
*
|
40
|
+
* @!attribute [r] y
|
41
|
+
* the y coordinate of the mouse cursor
|
42
|
+
*
|
43
|
+
* For {SDL2::Mouse.state}, this attribute means the y coordinate
|
44
|
+
* relative to the window.
|
45
|
+
* For {SDL2::Mouse.relative_state}, this attribute means the y coordinate
|
46
|
+
* relative to the previous call of {SDL2::Mouse.relative_state}.
|
47
|
+
*
|
48
|
+
* @return [Integer]
|
49
|
+
*
|
50
|
+
* @!attribute [r] button_bits
|
51
|
+
* button bits
|
52
|
+
* @return [Integer]
|
53
|
+
* @see #pressed?
|
54
|
+
*/
|
55
|
+
|
56
|
+
static VALUE State_new(int x, int y, Uint32 buttons)
|
57
|
+
{
|
58
|
+
VALUE state = rb_obj_alloc(cState);
|
59
|
+
rb_iv_set(state, "@x", INT2FIX(x));
|
60
|
+
rb_iv_set(state, "@y", INT2FIX(y));
|
61
|
+
rb_iv_set(state, "@button_bits", UINT2NUM(buttons));
|
62
|
+
return state;
|
63
|
+
}
|
64
|
+
|
65
|
+
static VALUE mouse_state(Uint32 (*func)(int*,int*))
|
66
|
+
{
|
67
|
+
int x, y;
|
68
|
+
Uint32 state;
|
69
|
+
state = func(&x, &y);
|
70
|
+
return State_new(x, y, state);
|
71
|
+
}
|
72
|
+
|
73
|
+
#if SDL_VERSION_ATLEAST(2,0,4)
|
74
|
+
/*
|
75
|
+
* Get the current mouse state in relation to the desktop.
|
76
|
+
*
|
77
|
+
* The return value contains the x and y coordinates of the cursor
|
78
|
+
* relative to the desktop and the state of mouse buttons.
|
79
|
+
*
|
80
|
+
* @note This module function is available since SDL 2.0.4.
|
81
|
+
* @return [SDL2::Mouse::State] current state
|
82
|
+
*/
|
83
|
+
static VALUE Mouse_s_global_state(VALUE self)
|
84
|
+
{
|
85
|
+
return mouse_state(SDL_GetGlobalMouseState);
|
86
|
+
}
|
87
|
+
#endif
|
88
|
+
|
89
|
+
/*
|
90
|
+
* Get the current state of the mouse.
|
91
|
+
*
|
92
|
+
* The return value contains the x and y coordinates of the cursor and
|
93
|
+
* the state of mouse buttons.
|
94
|
+
*
|
95
|
+
* @return [SDL2::Mouse::State] current state
|
96
|
+
*/
|
97
|
+
static VALUE Mouse_s_state(VALUE self)
|
98
|
+
{
|
99
|
+
return mouse_state(SDL_GetMouseState);
|
100
|
+
}
|
101
|
+
|
102
|
+
/*
|
103
|
+
* Return true if relative mouse mode is enabled.
|
104
|
+
*
|
105
|
+
* @see .relative_mode=
|
106
|
+
*/
|
107
|
+
static VALUE Mouse_s_relative_mode_p(VALUE self)
|
108
|
+
{
|
109
|
+
return INT2BOOL(SDL_GetRelativeMouseMode());
|
110
|
+
}
|
111
|
+
|
112
|
+
/*
|
113
|
+
* @overload relative_mode=(bool)
|
114
|
+
* @param [Boolean] bool true if you want to enable relative mouse mode
|
115
|
+
*
|
116
|
+
* Set relative mouse mode.
|
117
|
+
*
|
118
|
+
* While the mouse is in relative mode, the cursor is hidden, and the
|
119
|
+
* driver will try to report continuous motion in the current window.
|
120
|
+
* Only relative motion events will be delivered, the mouse position
|
121
|
+
* will not change.
|
122
|
+
*
|
123
|
+
* @note This function will flush any pending mouse motion.
|
124
|
+
*
|
125
|
+
* @return [Boolean]
|
126
|
+
* @see .relative_mode?
|
127
|
+
*/
|
128
|
+
static VALUE Mouse_s_set_relative_mode(VALUE self, VALUE enabled)
|
129
|
+
{
|
130
|
+
HANDLE_ERROR(SDL_SetRelativeMouseMode(RTEST(enabled)));
|
131
|
+
return enabled;
|
132
|
+
}
|
133
|
+
|
134
|
+
/*
|
135
|
+
* Get the relative state of the mouse.
|
136
|
+
*
|
137
|
+
* The button state is same as {.state} and
|
138
|
+
* x and y of the returned object are set to the
|
139
|
+
* mouse deltas since the last call to this method.
|
140
|
+
*
|
141
|
+
* @return [SDL2::Mouse::State]
|
142
|
+
*/
|
143
|
+
static VALUE Mouse_s_relative_state(VALUE self)
|
144
|
+
{
|
145
|
+
return mouse_state(SDL_GetRelativeMouseState);
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* Get the window which has mouse focus.
|
150
|
+
*
|
151
|
+
* @return [SDL2::Window] the window which has mouse focus
|
152
|
+
* @return [nil] if no window governed by SDL has mouse focus
|
153
|
+
*/
|
154
|
+
static VALUE Mouse_s_focused_window(VALUE self)
|
155
|
+
{
|
156
|
+
SDL_Window* window = SDL_GetMouseFocus();
|
157
|
+
if (!window)
|
158
|
+
return Qnil;
|
159
|
+
else
|
160
|
+
return find_window_by_id(SDL_GetWindowID(window));
|
161
|
+
}
|
162
|
+
|
163
|
+
/*
|
164
|
+
* Show the mouse cursor.
|
165
|
+
* @return [nil]
|
166
|
+
*/
|
167
|
+
static VALUE Cursor_s_show(VALUE self)
|
168
|
+
{
|
169
|
+
HANDLE_ERROR(SDL_ShowCursor(SDL_ENABLE));
|
170
|
+
return Qnil;
|
171
|
+
}
|
172
|
+
|
173
|
+
/*
|
174
|
+
* Hide the mouse cursor.
|
175
|
+
* @return [nil]
|
176
|
+
*/
|
177
|
+
static VALUE Cursor_s_hide(VALUE self)
|
178
|
+
{
|
179
|
+
HANDLE_ERROR(SDL_ShowCursor(SDL_DISABLE));
|
180
|
+
return Qnil;
|
181
|
+
}
|
182
|
+
|
183
|
+
/*
|
184
|
+
* Return true if the mouse cursor is shown.
|
185
|
+
*/
|
186
|
+
static VALUE Cursor_s_shown_p(VALUE self)
|
187
|
+
{
|
188
|
+
return INT2BOOL(HANDLE_ERROR(SDL_ShowCursor(SDL_QUERY)));
|
189
|
+
}
|
190
|
+
|
191
|
+
/*
|
192
|
+
* @overload warp(window, x, y)
|
193
|
+
* Move the mouse cursor to the given position within the window.
|
194
|
+
*
|
195
|
+
* @param [SDL::Window] window the window to move the mouse cursor into
|
196
|
+
* @param [Integer] x the x coordinate within the window
|
197
|
+
* @param [Integer] y the y coordinate within the window
|
198
|
+
* @return [nil]
|
199
|
+
*/
|
200
|
+
static VALUE Cursor_s_warp(VALUE self, VALUE window, VALUE x, VALUE y)
|
201
|
+
{
|
202
|
+
SDL_WarpMouseInWindow(Get_SDL_Window(window), NUM2INT(x), NUM2INT(y));
|
203
|
+
return Qnil;
|
204
|
+
}
|
205
|
+
|
206
|
+
#if SDL_VERSION_ATLEAST(2,0,4)
|
207
|
+
/*
|
208
|
+
* @overload warp_globally(x, y)
|
209
|
+
* Move the mouse cursor to the given position within the desktop.
|
210
|
+
*
|
211
|
+
* @note This class module function is available since SDL 2.0.4.
|
212
|
+
* @param [Integer] x the x coordinate within the desktop
|
213
|
+
* @param [Integer] y the y coordinate within the desktop
|
214
|
+
* @return [nil]
|
215
|
+
*/
|
216
|
+
static VALUE Cursor_s_warp_globally(VALUE self, VALUE x, VALUE y)
|
217
|
+
{
|
218
|
+
SDL_WarpMouseGlobal(NUM2INT(x), NUM2INT(y));
|
219
|
+
return Qnil;
|
220
|
+
}
|
221
|
+
#endif
|
222
|
+
|
223
|
+
/*
|
224
|
+
* @overload pressed?(index)
|
225
|
+
* Return true a mouse button is pressed.
|
226
|
+
*
|
227
|
+
* @param [Integer] index the index of a mouse button, start at index 0
|
228
|
+
*
|
229
|
+
*/
|
230
|
+
static VALUE State_pressed_p(VALUE self, VALUE index)
|
231
|
+
{
|
232
|
+
int idx = NUM2INT(index);
|
233
|
+
if (idx < 0 || idx >= 32)
|
234
|
+
rb_raise(rb_eArgError, "button index out of range (%d for 1..32)", idx);
|
235
|
+
return INT2BOOL(NUM2UINT(rb_iv_get(self, "@button_bits")) & SDL_BUTTON(idx));
|
236
|
+
}
|
237
|
+
|
238
|
+
/* @return [String] inspection string */
|
239
|
+
static VALUE State_inspect(VALUE self)
|
240
|
+
{
|
241
|
+
int i;
|
242
|
+
Uint32 buttons = NUM2UINT(rb_iv_get(self, "@button_bits"));
|
243
|
+
VALUE pressed = rb_ary_new();
|
244
|
+
VALUE string_for_pressed;
|
245
|
+
for (i=1; i<=32; ++i)
|
246
|
+
if (buttons & SDL_BUTTON(i))
|
247
|
+
rb_ary_push(pressed, rb_sprintf("%d", i));
|
248
|
+
|
249
|
+
string_for_pressed = rb_ary_join(pressed, rb_str_new2(" "));
|
250
|
+
return rb_sprintf("<%s:%p x=%d y=%d pressed=[%s]>",
|
251
|
+
rb_obj_classname(self), (void*)self,
|
252
|
+
NUM2INT(rb_iv_get(self, "@x")), NUM2INT(rb_iv_get(self, "@y")),
|
253
|
+
StringValueCStr(string_for_pressed));
|
254
|
+
}
|
255
|
+
|
256
|
+
void rubysdl2_init_mouse(void)
|
257
|
+
{
|
258
|
+
mMouse = rb_define_module_under(mSDL2, "Mouse");
|
259
|
+
|
260
|
+
#if SDL_VERSION_ATLEAST(2,0,4)
|
261
|
+
rb_define_module_function(mMouse, "global_state", Mouse_s_global_state, 0);
|
262
|
+
#endif
|
263
|
+
rb_define_module_function(mMouse, "state", Mouse_s_state, 0);
|
264
|
+
rb_define_module_function(mMouse, "relative_mode?", Mouse_s_relative_mode_p, 0);
|
265
|
+
rb_define_module_function(mMouse, "relative_mode=", Mouse_s_set_relative_mode, 1);
|
266
|
+
rb_define_module_function(mMouse, "relative_state", Mouse_s_relative_state, 0);
|
267
|
+
rb_define_module_function(mMouse, "focused_window", Mouse_s_focused_window, 0);
|
268
|
+
|
269
|
+
cCursor = rb_define_class_under(mMouse, "Cursor", rb_cObject);
|
270
|
+
|
271
|
+
rb_define_singleton_method(cCursor, "show", Cursor_s_show, 0);
|
272
|
+
rb_define_singleton_method(cCursor, "hide", Cursor_s_hide, 0);
|
273
|
+
rb_define_singleton_method(cCursor, "shown?", Cursor_s_shown_p, 0);
|
274
|
+
rb_define_singleton_method(cCursor, "warp", Cursor_s_warp, 3);
|
275
|
+
#if SDL_VERSION_ATLEAST(2,0,4)
|
276
|
+
rb_define_singleton_method(cCursor, "warp_globally", Cursor_s_warp_globally, 2);
|
277
|
+
#endif
|
278
|
+
|
279
|
+
|
280
|
+
cState = rb_define_class_under(mMouse, "State", rb_cObject);
|
281
|
+
|
282
|
+
rb_undef_method(rb_singleton_class(cState), "new");
|
283
|
+
define_attr_readers(cState, "x", "y", "button_bits", NULL);
|
284
|
+
rb_define_method(cState, "pressed?", State_pressed_p, 1);
|
285
|
+
rb_define_method(cState, "inspect", State_inspect, 0);
|
286
|
+
}
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/*
|
2
|
+
* Ruby/SDL2 Ruby extensiion library for SDL 2.x
|
3
|
+
*
|
4
|
+
* Copyright (C) 2014 Ippei Obayashi
|
5
|
+
*
|
6
|
+
* This file is part of Ruby/SDL2.
|
7
|
+
*
|
8
|
+
* Ruby/SDL2 is free software: you can redistribute it and/or modify
|
9
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
11
|
+
* (at your option) any later version.
|
12
|
+
*
|
13
|
+
* Ruby/SDL2 is distributed in the hope that it will be useful,
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
* GNU Lesser General Public License for more details.
|
17
|
+
*
|
18
|
+
* You should have received a copy of the GNU Lesser General Public License
|
19
|
+
* along with Ruby/SDL2. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
*/
|
21
|
+
#ifndef RUBYSDL2_INTERNAL_H
|
22
|
+
#define RUBYSDL2_INTERNAL_H
|
23
|
+
|
24
|
+
|
25
|
+
#include <ruby.h>
|
26
|
+
#include <ruby/encoding.h>
|
27
|
+
#define SDL_MAIN_HANDLED
|
28
|
+
#include <SDL_surface.h>
|
29
|
+
#include <SDL_version.h>
|
30
|
+
#include <SDL_video.h>
|
31
|
+
|
32
|
+
#ifndef SDL2_EXTERN
|
33
|
+
#define SDL2_EXTERN extern
|
34
|
+
#endif
|
35
|
+
|
36
|
+
/** utility functions */
|
37
|
+
int rubysdl2_handle_error(int code, const char* cfunc);
|
38
|
+
int rubysdl2_is_active(void);
|
39
|
+
void rubysdl2_define_attr_readers(VALUE klass, ...);
|
40
|
+
VALUE rubysdl2_utf8str_new_cstr(const char* str);
|
41
|
+
VALUE rubysdl2_Surface_new(SDL_Surface* surface);
|
42
|
+
SDL_Color rubysdl2_Array_to_SDL_Color(VALUE ary);
|
43
|
+
VALUE rubysdl2_SDL_version_to_String(const SDL_version* ver);
|
44
|
+
VALUE rubysdl2_SDL_version_to_Array(const SDL_version* ver);
|
45
|
+
VALUE rubysdl2_find_window_by_id(Uint32 id);
|
46
|
+
SDL_Rect* rubysdl2_Get_SDL_Rect(VALUE);
|
47
|
+
SDL_Window* rubysdl2_Get_SDL_Window(VALUE);
|
48
|
+
const char* rubysdl2_INT2BOOLCSTR(int);
|
49
|
+
SDL_Color rubysdl2_Color_to_SDL_Color(VALUE rgba);
|
50
|
+
|
51
|
+
/** initialize interfaces */
|
52
|
+
void rubysdl2_init_hints(void);
|
53
|
+
void rubysdl2_init_video(void);
|
54
|
+
void rubysdl2_init_gl(void);
|
55
|
+
void rubysdl2_init_messagebox(void);
|
56
|
+
void rubysdl2_init_event(void);
|
57
|
+
void rubysdl2_init_key(void);
|
58
|
+
void rubysdl2_init_mouse(void);
|
59
|
+
void rubysdl2_init_joystick(void);
|
60
|
+
void rubysdl2_init_timer(void);
|
61
|
+
void rubysdl2_init_image(void);
|
62
|
+
void rubysdl2_init_mixer(void);
|
63
|
+
void rubysdl2_init_ttf(void);
|
64
|
+
void rubysdl2_init_filesystem(void);
|
65
|
+
void rubysdl2_init_clipboard(void);
|
66
|
+
void rubysdl2_init_gamecontorller(void);
|
67
|
+
void rubysdl2_init_color(void);
|
68
|
+
|
69
|
+
/** macros */
|
70
|
+
#define HANDLE_ERROR(c) (rubysdl2_handle_error((c), __func__))
|
71
|
+
#define SDL_ERROR() (HANDLE_ERROR(-1))
|
72
|
+
#define INT2BOOL(x) ((x)?Qtrue:Qfalse)
|
73
|
+
#define NUM2UCHAR NUM2UINT
|
74
|
+
#define UCHAR2NUM UINT2NUM
|
75
|
+
#define rb_str_export_to_utf8(str) rb_str_export_to_enc((str), rb_utf8_encoding())
|
76
|
+
|
77
|
+
#define DEFINE_GETTER(scope, ctype, var_class, classname) \
|
78
|
+
scope ctype* Get_##ctype(VALUE obj) \
|
79
|
+
{ \
|
80
|
+
ctype* s; \
|
81
|
+
if (!rb_obj_is_kind_of(obj, var_class)) \
|
82
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", \
|
83
|
+
rb_obj_classname(obj), classname); \
|
84
|
+
Data_Get_Struct(obj, ctype, s); \
|
85
|
+
\
|
86
|
+
return s; \
|
87
|
+
}
|
88
|
+
|
89
|
+
#define DEFINE_WRAP_GETTER(scope, SDL_typename, struct_name, field, classname) \
|
90
|
+
scope SDL_typename* Get_##SDL_typename(VALUE obj) \
|
91
|
+
{ \
|
92
|
+
struct_name* s = Get_##struct_name(obj); \
|
93
|
+
if (s->field == NULL) \
|
94
|
+
HANDLE_ERROR(SDL_SetError(classname " is already destroyed")); \
|
95
|
+
\
|
96
|
+
return s->field; \
|
97
|
+
}
|
98
|
+
|
99
|
+
#define DEFINE_DESTROY_P(scope, struct_name, field) \
|
100
|
+
scope VALUE struct_name##_destroy_p(VALUE self) \
|
101
|
+
{ \
|
102
|
+
return INT2BOOL(Get_##struct_name(self)->field == NULL); \
|
103
|
+
}
|
104
|
+
|
105
|
+
#define DEFINE_WRAPPER(SDL_typename, struct_name, field, var_class, classname) \
|
106
|
+
DEFINE_GETTER(static, struct_name, var_class, classname); \
|
107
|
+
DEFINE_WRAP_GETTER(static ,SDL_typename, struct_name, field, classname); \
|
108
|
+
DEFINE_DESTROY_P(static, struct_name, field);
|
109
|
+
|
110
|
+
/** classes and modules */
|
111
|
+
SDL2_EXTERN VALUE rubysdl2_mSDL2;
|
112
|
+
SDL2_EXTERN VALUE rubysdl2_eSDL2Error;
|
113
|
+
|
114
|
+
/** prefix macros */
|
115
|
+
#define define_attr_readers rubysdl2_define_attr_readers
|
116
|
+
#define utf8str_new_cstr rubysdl2_utf8str_new_cstr
|
117
|
+
#define Surface_new rubysdl2_Surface_new
|
118
|
+
#define Get_SDL_Rect rubysdl2_Get_SDL_Rect
|
119
|
+
#define Get_SDL_Window rubysdl2_Get_SDL_Window
|
120
|
+
#define mSDL2 rubysdl2_mSDL2
|
121
|
+
#define eSDL2Error rubysdl2_eSDL2Error
|
122
|
+
#define SDL_version_to_String rubysdl2_SDL_version_to_String
|
123
|
+
#define SDL_version_to_Array rubysdl2_SDL_version_to_Array
|
124
|
+
#define INT2BOOLCSTR rubysdl2_INT2BOOLCSTR
|
125
|
+
#define find_window_by_id rubysdl2_find_window_by_id
|
126
|
+
#define Color_to_SDL_Color rubysdl2_Color_to_SDL_Color
|
127
|
+
#endif
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#include "rubysdl2_internal.h"
|
2
|
+
#include <SDL_timer.h>
|
3
|
+
|
4
|
+
/*
|
5
|
+
* @overload delay(ms)
|
6
|
+
* @param [Integer] ms the number of milliseconds to delay
|
7
|
+
*
|
8
|
+
* Wait a specified milliseconds.
|
9
|
+
*
|
10
|
+
* This function stops all ruby threads. If you want to keep running other
|
11
|
+
* threads, you should use Kernel.sleep instead of this function.
|
12
|
+
*
|
13
|
+
* @return [nil]
|
14
|
+
*/
|
15
|
+
static VALUE SDL_s_delay(VALUE self, VALUE ms)
|
16
|
+
{
|
17
|
+
SDL_Delay(NUM2UINT(ms));
|
18
|
+
return Qnil;
|
19
|
+
}
|
20
|
+
|
21
|
+
/*
|
22
|
+
* Return the number of milliseconds since {SDL2.init} is called.
|
23
|
+
*
|
24
|
+
* @return [Integer] milliseconds in 32bit unsigned value.
|
25
|
+
*/
|
26
|
+
static VALUE SDL_s_get_ticks(VALUE self)
|
27
|
+
{
|
28
|
+
return UINT2NUM(SDL_GetTicks());
|
29
|
+
}
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Return the current value of the high resolution counter.
|
33
|
+
*
|
34
|
+
* This method is typically used for profiling.
|
35
|
+
*
|
36
|
+
* @return [Integer] the current counter value
|
37
|
+
* @see SDL2.get_performance_frequency
|
38
|
+
*/
|
39
|
+
static VALUE SDL_s_get_performance_counter(VALUE self)
|
40
|
+
{
|
41
|
+
return ULL2NUM(SDL_GetPerformanceCounter());
|
42
|
+
}
|
43
|
+
|
44
|
+
/*
|
45
|
+
* Return the frequency (count per second) of the high resolution counter.
|
46
|
+
*
|
47
|
+
* @return [Integer] a platform-specific count per second.
|
48
|
+
* @see SDL2.get_performance_counter
|
49
|
+
*/
|
50
|
+
static VALUE SDL_s_get_performance_frequency(VALUE self)
|
51
|
+
{
|
52
|
+
return ULL2NUM(SDL_GetPerformanceFrequency());
|
53
|
+
}
|
54
|
+
|
55
|
+
void rubysdl2_init_timer(void)
|
56
|
+
{
|
57
|
+
rb_define_module_function(mSDL2, "delay", SDL_s_delay, 1);
|
58
|
+
rb_define_module_function(mSDL2, "get_ticks", SDL_s_get_ticks, 0);
|
59
|
+
rb_define_module_function(mSDL2, "get_performance_counter",
|
60
|
+
SDL_s_get_performance_counter, 0);
|
61
|
+
rb_define_module_function(mSDL2, "get_performance_frequency",
|
62
|
+
SDL_s_get_performance_frequency,0);
|
63
|
+
}
|