ruby-sdl2 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +5 -6
- data/Rakefile +13 -0
- data/clipboard.c +24 -0
- data/event.c +216 -5
- data/filesystem.c +27 -0
- data/gamecontroller.c +244 -30
- data/gamecontroller.c.m4 +408 -0
- data/gl.c.m4 +159 -9
- data/hint.c +51 -8
- data/key.c.m4 +6 -0
- data/lib/sdl2/version.rb +2 -2
- data/messagebox.c +40 -38
- data/mixer.c +138 -21
- data/mixer.c.m4 +1196 -0
- data/mouse.c +5 -5
- data/sample/message_box.rb +5 -5
- data/sample/primitives.rb +1 -1
- data/sample/test_video.rb +3 -3
- data/sample/testgl.rb +1 -1
- data/sample/testsprite.rb +5 -5
- data/ttf.c +193 -14
- data/ttf.c.m4 +375 -0
- data/video.c.m4 +465 -122
- metadata +6 -3
data/gl.c.m4
CHANGED
@@ -27,15 +27,51 @@ static VALUE GLContext_new(SDL_GLContext context)
|
|
27
27
|
c->context = context;
|
28
28
|
return Data_Wrap_Struct(cGLContext, 0, GLContext_free, c);
|
29
29
|
}
|
30
|
+
|
31
|
+
/*
|
32
|
+
* Document-module: SDL2::GL
|
33
|
+
*
|
34
|
+
* This module provides the initialize/shutdown functions of OpenGL.
|
35
|
+
*
|
36
|
+
*/
|
37
|
+
|
38
|
+
/*
|
39
|
+
* Document-class: SDL2::GL::Context
|
40
|
+
*
|
41
|
+
* This class represents an OpenGL context.
|
42
|
+
*
|
43
|
+
* You must create a new OpenGL context before using
|
44
|
+
* OpenGL functions.
|
45
|
+
*
|
46
|
+
* @!method destroy?
|
47
|
+
* Return true if the context is {#destroy destroyed}.
|
48
|
+
*/
|
49
|
+
|
30
50
|
/*
|
31
51
|
* @overload create(window)
|
32
52
|
* Create an OpenGL context for use with an OpenGL window, and make it
|
33
53
|
* current.
|
34
54
|
*
|
35
|
-
* @param window [SDL2::Window] the window
|
55
|
+
* @param window [SDL2::Window] the window associate with a new context
|
36
56
|
* @return [SDL2::GL::Context]
|
37
57
|
*
|
38
58
|
* @see #delete
|
59
|
+
*
|
60
|
+
* @example
|
61
|
+
*
|
62
|
+
* SDL2.init(SDL2::INIT_EVERYTHING)
|
63
|
+
* # You need to create a window with `OPENGL' flag
|
64
|
+
* window = SDL2::Window.create("testgl", 0, 0, WINDOW_W, WINDOW_H,
|
65
|
+
* SDL2::Window::Flags::OPENGL)
|
66
|
+
*
|
67
|
+
* # Create a OpenGL context attached to the window
|
68
|
+
* context = SDL2::GL::Context.create(window)
|
69
|
+
*
|
70
|
+
* # You can use OpenGL functions
|
71
|
+
* :
|
72
|
+
*
|
73
|
+
* # Delete the context after using OpenGL functions
|
74
|
+
* context.destroy
|
39
75
|
*/
|
40
76
|
static VALUE GLContext_s_create(VALUE self, VALUE window)
|
41
77
|
{
|
@@ -46,6 +82,13 @@ static VALUE GLContext_s_create(VALUE self, VALUE window)
|
|
46
82
|
return (current_context = GLContext_new(context));
|
47
83
|
}
|
48
84
|
|
85
|
+
/*
|
86
|
+
* Delete the OpenGL context.
|
87
|
+
*
|
88
|
+
* @return [nil]
|
89
|
+
*
|
90
|
+
* @see #destroy?
|
91
|
+
*/
|
49
92
|
static VALUE GLContext_destroy(VALUE self)
|
50
93
|
{
|
51
94
|
GLContext* c = Get_GLContext(self);
|
@@ -55,6 +98,13 @@ static VALUE GLContext_destroy(VALUE self)
|
|
55
98
|
return Qnil;
|
56
99
|
}
|
57
100
|
|
101
|
+
/*
|
102
|
+
* @overload make_current(window)
|
103
|
+
* Set the OpenGL context for rendering into an OpenGL window.
|
104
|
+
*
|
105
|
+
* @param window [SDL2::Window] the window to associate with the context
|
106
|
+
* @return [nil]
|
107
|
+
*/
|
58
108
|
static VALUE GLContext_make_current(VALUE self, VALUE window)
|
59
109
|
{
|
60
110
|
HANDLE_ERROR(SDL_GL_MakeCurrent(Get_SDL_Window(window), Get_SDL_GLContext(self)));
|
@@ -62,27 +112,71 @@ static VALUE GLContext_make_current(VALUE self, VALUE window)
|
|
62
112
|
return Qnil;
|
63
113
|
}
|
64
114
|
|
115
|
+
/*
|
116
|
+
* Get the current OpenGL context.
|
117
|
+
*
|
118
|
+
* @return [SDL2::GL::Context] the curren context
|
119
|
+
* @return [nil] if there is no current context
|
120
|
+
*
|
121
|
+
* @see #make_current
|
122
|
+
*/
|
65
123
|
static VALUE GLContext_s_current(VALUE self)
|
66
124
|
{
|
67
125
|
return current_context;
|
68
126
|
}
|
69
127
|
|
128
|
+
/*
|
129
|
+
* @overload extension_supported?(extension)
|
130
|
+
* Return true if the current context supports **extension**
|
131
|
+
*
|
132
|
+
* @param extension [String] the name of an extension
|
133
|
+
* @example
|
134
|
+
* SDL2::GL.extension_supported?("GL_EXT_framebuffer_blit")
|
135
|
+
*/
|
70
136
|
static VALUE GL_s_extension_supported_p(VALUE self, VALUE extension)
|
71
137
|
{
|
72
138
|
return INT2BOOL(SDL_GL_ExtensionSupported(StringValueCStr(extension)));
|
73
139
|
}
|
74
140
|
|
141
|
+
/*
|
142
|
+
* Get the state of swap interval of the current context.
|
143
|
+
*
|
144
|
+
* @return [Integer]
|
145
|
+
* return 0 when vsync is not used,
|
146
|
+
* return 1 when vsync is used,
|
147
|
+
* and return -1 when vsync is not supported by the system (OS).
|
148
|
+
*
|
149
|
+
*/
|
75
150
|
static VALUE GL_s_swap_interval(VALUE self)
|
76
151
|
{
|
77
152
|
return INT2NUM(SDL_GL_GetSwapInterval());
|
78
153
|
}
|
79
154
|
|
155
|
+
|
156
|
+
/*
|
157
|
+
* @overload swap_interval=(interval)
|
158
|
+
* Set the state of swap interval of the current context.
|
159
|
+
*
|
160
|
+
* @param interval [Integer]
|
161
|
+
* 0 if you don't want to wait for vsync,
|
162
|
+
* 1 if you want to wait for vsync,
|
163
|
+
* -1 if you want to use late swap tearing
|
164
|
+
* @return [nil]
|
165
|
+
*
|
166
|
+
*/
|
80
167
|
static VALUE GL_s_set_swap_interval(VALUE self, VALUE interval)
|
81
168
|
{
|
82
169
|
HANDLE_ERROR(SDL_GL_SetSwapInterval(NUM2INT(interval)));
|
83
170
|
return Qnil;
|
84
171
|
}
|
85
172
|
|
173
|
+
/*
|
174
|
+
* @overload get_attribute(attr)
|
175
|
+
* Get the acutal value for an attribute from current context.
|
176
|
+
*
|
177
|
+
* @param attr [Integer] the OpenGL attribute to query
|
178
|
+
* @return [Integer]
|
179
|
+
*/
|
86
180
|
static VALUE GL_s_get_attribute(VALUE self, VALUE attr)
|
87
181
|
{
|
88
182
|
int value;
|
@@ -90,6 +184,14 @@ static VALUE GL_s_get_attribute(VALUE self, VALUE attr)
|
|
90
184
|
return INT2NUM(value);
|
91
185
|
}
|
92
186
|
|
187
|
+
/*
|
188
|
+
* @overload set_attribute(attr, value)
|
189
|
+
* Set an OpenGL window attribute before window creation.
|
190
|
+
*
|
191
|
+
* @param attr [Integer] the OpenGL attribute to set
|
192
|
+
* @param value [Integer] the desired value for the attribute
|
193
|
+
* @return [value]
|
194
|
+
*/
|
93
195
|
static VALUE GL_s_set_attribute(VALUE self, VALUE attr, VALUE value)
|
94
196
|
{
|
95
197
|
HANDLE_ERROR(SDL_GL_SetAttribute(NUM2INT(attr), NUM2INT(value)));
|
@@ -113,7 +215,7 @@ void rubysdl2_init_gl(void)
|
|
113
215
|
rb_define_module_function(mGL, "swap_interval=", GL_s_set_swap_interval, 1);
|
114
216
|
rb_define_module_function(mGL, "get_attribute", GL_s_get_attribute, 1);
|
115
217
|
rb_define_module_function(mGL, "set_attribute", GL_s_set_attribute, 2);
|
116
|
-
|
218
|
+
|
117
219
|
/* define(`DEFINE_GL_ATTR_CONST',`rb_define_const(mGL, "$1", INT2NUM(SDL_GL_$1))') */
|
118
220
|
/* OpenGL attribute - minimal bits of red channel in color buffer, default is 3 */
|
119
221
|
DEFINE_GL_ATTR_CONST(RED_SIZE);
|
@@ -161,21 +263,33 @@ void rubysdl2_init_gl(void)
|
|
161
263
|
DEFINE_GL_ATTR_CONST(CONTEXT_MAJOR_VERSION);
|
162
264
|
/* OpenGL attribute - OpenGL context minor version */
|
163
265
|
DEFINE_GL_ATTR_CONST(CONTEXT_MINOR_VERSION);
|
164
|
-
/*
|
165
|
-
*
|
266
|
+
/*
|
267
|
+
* INT2NUM(SDL_GL_CONTEXT_FLAGS):
|
166
268
|
*
|
269
|
+
* OpenGL attribute - the bit combination of following constants, or 0.
|
270
|
+
* default is 0
|
271
|
+
*
|
167
272
|
* * {SDL2::GL::CONTEXT_DEBUG_FLAG}
|
168
273
|
* * {SDL2::GL::CONTEXT_FORWARD_COMPATIBLE_FLAG}
|
169
274
|
* * {SDL2::GL::CONTEXT_ROBUST_ACCESS_FLAG}
|
170
275
|
* * {SDL2::GL::CONTEXT_RESET_ISOLATION_FLAG}
|
276
|
+
*
|
277
|
+
* These flags are mapped to some OpenGL extensions. Please see
|
278
|
+
* the documentation of each constant for more details.
|
279
|
+
*
|
280
|
+
* https://wiki.libsdl.org/SDL_GLcontextFlag
|
171
281
|
*/
|
172
282
|
DEFINE_GL_ATTR_CONST(CONTEXT_FLAGS);
|
173
|
-
/*
|
283
|
+
/* INT2NUM(SDL_GL_CONTEXT_PROFILE_MASK):
|
284
|
+
*
|
285
|
+
* OpenGL attribute - type of GL context, one of the following constants,
|
174
286
|
* defaults depends on platform
|
175
287
|
*
|
176
|
-
* * {
|
177
|
-
* * {
|
178
|
-
* * {
|
288
|
+
* * {CONTEXT_PROFILE_CORE}
|
289
|
+
* * {CONTEXT_PROFILE_COMPATIBILITY}
|
290
|
+
* * {CONTEXT_PROFILE_ES}
|
291
|
+
*
|
292
|
+
* https://wiki.libsdl.org/SDL_GLprofile
|
179
293
|
*/
|
180
294
|
DEFINE_GL_ATTR_CONST(CONTEXT_PROFILE_MASK);
|
181
295
|
/* OpenGL attribute - OpenGL context sharing, default is 0 */
|
@@ -188,13 +302,49 @@ void rubysdl2_init_gl(void)
|
|
188
302
|
DEFINE_GL_ATTR_CONST(CONTEXT_EGL);
|
189
303
|
|
190
304
|
/* define(`DEFINE_GL_CONTEXT_CONST',`rb_define_const(mGL, "CONTEXT_$1", INT2NUM(SDL_GL_CONTEXT_$1))') */
|
305
|
+
|
306
|
+
/* This flag maps to GLX_CONTEXT_DEBUG_BIT_ARB in
|
307
|
+
* the GLX_ARB_create_context extension for X11
|
308
|
+
* and WGL_CONTEXT_DEBUG_BIT_ARB in the WGL_ARB_create_context
|
309
|
+
* extension for Windows.
|
310
|
+
*/
|
191
311
|
DEFINE_GL_CONTEXT_CONST(DEBUG_FLAG);
|
312
|
+
/*
|
313
|
+
* This flag maps to GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB in the
|
314
|
+
* GLX_ARB_create_context extension for X11 and
|
315
|
+
* WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB in the WGL_ARB_create_context
|
316
|
+
* extension for Windows.
|
317
|
+
*/
|
192
318
|
DEFINE_GL_CONTEXT_CONST(FORWARD_COMPATIBLE_FLAG);
|
319
|
+
/*
|
320
|
+
* This flag maps to GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB in the
|
321
|
+
* GLX_ARB_create_context_robustness extension for X11 and
|
322
|
+
* WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB in the WGL_ARB_create_context_robustness
|
323
|
+
* extension for Windows.
|
324
|
+
*/
|
193
325
|
DEFINE_GL_CONTEXT_CONST(ROBUST_ACCESS_FLAG);
|
326
|
+
/*
|
327
|
+
* This flag maps to GLX_CONTEXT_RESET_ISOLATION_BIT_ARB in the
|
328
|
+
* GLX_ARB_robustness_isolation extension for X11 and
|
329
|
+
* WGL_CONTEXT_RESET_ISOLATION_BIT_ARB in the WGL_ARB_create_context_robustness
|
330
|
+
* extension for Windows.
|
331
|
+
*/
|
194
332
|
DEFINE_GL_CONTEXT_CONST(RESET_ISOLATION_FLAG);
|
195
|
-
|
333
|
+
|
334
|
+
/*
|
335
|
+
* OpenGL core profile - deprecated
|
336
|
+
* functions are disabled
|
337
|
+
*/
|
196
338
|
DEFINE_GL_CONTEXT_CONST(PROFILE_CORE);
|
339
|
+
/*
|
340
|
+
* OpenGL compatibility profile -
|
341
|
+
* deprecated functions are allowed
|
342
|
+
*/
|
197
343
|
DEFINE_GL_CONTEXT_CONST(PROFILE_COMPATIBILITY);
|
344
|
+
/*
|
345
|
+
* OpenGL ES profile - only a subset of the
|
346
|
+
* base OpenGL functionality is available
|
347
|
+
*/
|
198
348
|
DEFINE_GL_CONTEXT_CONST(PROFILE_ES);
|
199
349
|
|
200
350
|
rb_gc_register_address(¤t_context);
|
data/hint.c
CHANGED
@@ -3,12 +3,33 @@
|
|
3
3
|
|
4
4
|
static VALUE sym_priority;
|
5
5
|
|
6
|
+
/*
|
7
|
+
* Document-module: SDL2::Hints
|
8
|
+
*
|
9
|
+
* This module enables you to get and set configuration hints.
|
10
|
+
*
|
11
|
+
*/
|
12
|
+
|
13
|
+
/*
|
14
|
+
* Clear all hints set by {.[]=}.
|
15
|
+
*
|
16
|
+
* @return [nil]
|
17
|
+
*/
|
6
18
|
static VALUE Hints_s_clear(VALUE self)
|
7
19
|
{
|
8
20
|
SDL_ClearHints();
|
9
21
|
return Qnil;
|
10
22
|
}
|
11
23
|
|
24
|
+
/*
|
25
|
+
* @overload [](hint)
|
26
|
+
* Get the value of a hint.
|
27
|
+
*
|
28
|
+
* @param hint [String] the name of the hint to query
|
29
|
+
*
|
30
|
+
* @return [String] the string value of a hint
|
31
|
+
* @return [nil] if the hint isn't set
|
32
|
+
*/
|
12
33
|
static VALUE Hints_s_aref(VALUE self, VALUE name)
|
13
34
|
{
|
14
35
|
const char* value = SDL_GetHint(StringValueCStr(name));
|
@@ -18,6 +39,29 @@ static VALUE Hints_s_aref(VALUE self, VALUE name)
|
|
18
39
|
return Qnil;
|
19
40
|
}
|
20
41
|
|
42
|
+
/*
|
43
|
+
* Set the value of a hint.
|
44
|
+
*
|
45
|
+
* @overload []=(hint, value)
|
46
|
+
* Set a hint with normal priority.
|
47
|
+
*
|
48
|
+
* @param hint [String] the name of the hint to query
|
49
|
+
* @param value [String] the value of the hint varaible
|
50
|
+
*
|
51
|
+
* @overload []=(hint, priority: , value)
|
52
|
+
* Set a hint with given priority.
|
53
|
+
*
|
54
|
+
* @param hint [String] the name of the hint to query
|
55
|
+
* @param priority [Integer] the priority, one of the
|
56
|
+
* {DEFAULT}, {NORMAL}, or {OVERRIDE}.
|
57
|
+
* @param value [String] the value of the hint varaible
|
58
|
+
*
|
59
|
+
* @return [Boolean] return true if the hint was set
|
60
|
+
*
|
61
|
+
* @example
|
62
|
+
* SDL2::Hints["SDL_HINT_XINPUT_ENABLED", priority: SDL2::Hints::OVERRIDE] = "0"
|
63
|
+
*
|
64
|
+
*/
|
21
65
|
static VALUE Hints_s_aset(int argc, VALUE* argv, VALUE self)
|
22
66
|
{
|
23
67
|
VALUE name, pri, value;
|
@@ -41,16 +85,15 @@ void rubysdl2_init_hints(void)
|
|
41
85
|
VALUE mHints = rb_define_module_under(mSDL2, "Hints");
|
42
86
|
|
43
87
|
rb_define_singleton_method(mHints, "clear", Hints_s_clear, 0);
|
44
|
-
rb_define_singleton_method(mHints, "[]", Hints_s_aref, 1);
|
45
88
|
rb_define_singleton_method(mHints, "get", Hints_s_aref, 1);
|
46
89
|
rb_define_singleton_method(mHints, "[]=", Hints_s_aset, -1);
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
90
|
+
|
91
|
+
/* low priority, used fro default values */
|
92
|
+
rb_define_const(mHints, "DEFAULT", INT2NUM(SDL_HINT_DEFAULT));
|
93
|
+
/* medium priority, overrided by an environment variable */
|
94
|
+
rb_define_const(mHints, "NORMAL", INT2NUM(SDL_HINT_NORMAL));
|
95
|
+
/* high priority, this priority overrides the value by environment variables */
|
96
|
+
rb_define_const(mHints, "OVERRIDE", INT2NUM(SDL_HINT_OVERRIDE));
|
54
97
|
|
55
98
|
sym_priority = ID2SYM(rb_intern("priority"));
|
56
99
|
}
|
data/key.c.m4
CHANGED
@@ -168,6 +168,12 @@ static VALUE Mod_s_set_state(VALUE self, VALUE keymod)
|
|
168
168
|
return Qnil;
|
169
169
|
}
|
170
170
|
|
171
|
+
/*
|
172
|
+
* Document-module: SDL2::TextInput
|
173
|
+
*
|
174
|
+
* This module provides Unicode text input support.
|
175
|
+
*
|
176
|
+
*/
|
171
177
|
static VALUE TextInput_s_active_p(VALUE self)
|
172
178
|
{
|
173
179
|
return INT2BOOL(SDL_IsTextInputActive());
|
data/lib/sdl2/version.rb
CHANGED
data/messagebox.c
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
static VALUE sym_flags, sym_window, sym_title, sym_message, sym_buttons, sym_color_scheme,
|
5
5
|
sym_id, sym_text, sym_bg, sym_button_border, sym_button_bg, sym_button_selected;
|
6
6
|
|
7
|
+
static VALUE mMessageBox;
|
8
|
+
|
7
9
|
static inline SDL_Window* Get_SDL_Window_or_NULL(VALUE win)
|
8
10
|
{
|
9
11
|
if (win == Qnil)
|
@@ -13,7 +15,13 @@ static inline SDL_Window* Get_SDL_Window_or_NULL(VALUE win)
|
|
13
15
|
}
|
14
16
|
|
15
17
|
/*
|
16
|
-
*
|
18
|
+
* Document-module: SDL2::MessageBox
|
19
|
+
*
|
20
|
+
* This module provides functions to show a modal message box.
|
21
|
+
*/
|
22
|
+
|
23
|
+
/*
|
24
|
+
* @overload show_simple_box(flag, title, message, parent)
|
17
25
|
* Create a simple modal message box.
|
18
26
|
*
|
19
27
|
* This function pauses all ruby's threads and
|
@@ -23,13 +31,13 @@ static inline SDL_Window* Get_SDL_Window_or_NULL(VALUE win)
|
|
23
31
|
*
|
24
32
|
* You specify one of the following constants as flag
|
25
33
|
*
|
26
|
-
* * {SDL2::
|
27
|
-
* * {SDL2::
|
28
|
-
* * {SDL2::
|
34
|
+
* * {SDL2::MessageBox::ERROR}
|
35
|
+
* * {SDL2::MessageBox::WARNING}
|
36
|
+
* * {SDL2::MessageBox::INFORMATION}
|
29
37
|
*
|
30
38
|
* @example show warning dialog
|
31
39
|
*
|
32
|
-
* SDL2.show_simple_message_box(SDL2::
|
40
|
+
* SDL2.show_simple_message_box(SDL2::MessageBox::WARNING, "warning!",
|
33
41
|
* "Somewhat special warning message!!", nil)
|
34
42
|
*
|
35
43
|
* @param [Integer] flag one of the above flags
|
@@ -40,8 +48,8 @@ static inline SDL_Window* Get_SDL_Window_or_NULL(VALUE win)
|
|
40
48
|
*
|
41
49
|
* @see .show_message_box
|
42
50
|
*/
|
43
|
-
static VALUE
|
44
|
-
|
51
|
+
static VALUE MessageBox_s_show_simple_box(VALUE self, VALUE flag, VALUE title,
|
52
|
+
VALUE message, VALUE parent)
|
45
53
|
{
|
46
54
|
title = rb_str_export_to_utf8(title);
|
47
55
|
message = rb_str_export_to_utf8(message);
|
@@ -62,19 +70,19 @@ static void set_color_scheme(VALUE colors, VALUE sym, SDL_MessageBoxColor* color
|
|
62
70
|
}
|
63
71
|
|
64
72
|
/*
|
65
|
-
* @overload
|
73
|
+
* @overload show(flag:, window: nil, title:, message:, buttons:, color_scheme: nil)
|
66
74
|
* Create a model message box.
|
67
75
|
*
|
68
76
|
* You specify one of the following constants as flag
|
69
77
|
*
|
70
|
-
* * {SDL2::
|
71
|
-
* * {SDL2::
|
72
|
-
* * {SDL2::
|
78
|
+
* * {SDL2::MessageBox::ERROR}
|
79
|
+
* * {SDL2::MessageBox::WARNING}
|
80
|
+
* * {SDL2::MessageBox::INFORMATION}
|
73
81
|
*
|
74
82
|
* One button in the dialog represents a hash with folloing elements.
|
75
83
|
*
|
76
|
-
* { flags: 0, SDL2::
|
77
|
-
* SDL2::
|
84
|
+
* { flags: 0, SDL2::MessageBox::BUTTON_ESCAPEKEY_DEFAULT, or
|
85
|
+
* SDL2::MessageBox::BUTTON_RETURNKEY_DEFAULT,
|
78
86
|
* you can ignore it for 0,
|
79
87
|
* text: text of a button,
|
80
88
|
* id: index of the button
|
@@ -95,7 +103,7 @@ static void set_color_scheme(VALUE colors, VALUE sym, SDL_MessageBoxColor* color
|
|
95
103
|
* You can create a message box before calling {SDL2.init}.
|
96
104
|
*
|
97
105
|
* @example show a dialog with 3 buttons
|
98
|
-
* button = SDL2.
|
106
|
+
* button = SDL2::MessageBox.show(flags: SDL2::MessageBox::WARNING,
|
99
107
|
* window: nil,
|
100
108
|
* title: "Warning window",
|
101
109
|
* message: "Here is the warning message",
|
@@ -103,11 +111,11 @@ static void set_color_scheme(VALUE colors, VALUE sym, SDL_MessageBoxColor* color
|
|
103
111
|
* id: 0,
|
104
112
|
* text: "No",
|
105
113
|
* },
|
106
|
-
* {flags: SDL2::
|
114
|
+
* {flags: SDL2::MessageBox::BUTTON_RETURNKEY_DEFAULT,
|
107
115
|
* id: 1,
|
108
116
|
* text: "Yes",
|
109
117
|
* },
|
110
|
-
* {flags: SDL2::
|
118
|
+
* {flags: SDL2::MessageBox::BUTTON_ESCAPEKEY_DEFAULT,
|
111
119
|
* id: 2,
|
112
120
|
* text: "Cancel",
|
113
121
|
* },
|
@@ -132,7 +140,7 @@ static void set_color_scheme(VALUE colors, VALUE sym, SDL_MessageBoxColor* color
|
|
132
140
|
*
|
133
141
|
* @see .show_simple_message_box
|
134
142
|
*/
|
135
|
-
static VALUE
|
143
|
+
static VALUE MessageBox_s_show(VALUE self, VALUE params)
|
136
144
|
{
|
137
145
|
SDL_MessageBoxData mb_data;
|
138
146
|
VALUE title, message, texts, buttons, color_scheme;
|
@@ -192,28 +200,22 @@ static VALUE SDL2_s_show_message_box(VALUE self, VALUE params)
|
|
192
200
|
|
193
201
|
void rubysdl2_init_messagebox(void)
|
194
202
|
{
|
195
|
-
|
196
|
-
|
197
|
-
rb_define_singleton_method(
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
rb_define_const(
|
202
|
-
/* This flag means that the message box shows a warning message
|
203
|
-
|
204
|
-
|
205
|
-
rb_define_const(
|
206
|
-
/* This flag
|
207
|
-
|
208
|
-
*/
|
209
|
-
rb_define_const(mSDL2, "MESSAGEBOX_INFORMATION", INT2NUM(SDL_MESSAGEBOX_INFORMATION));
|
210
|
-
/* This flag represents the button is selected when return key is pressed in
|
211
|
-
* {SDL2.show_message_box}. */
|
212
|
-
rb_define_const(mSDL2, "MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT",
|
203
|
+
mMessageBox = rb_define_module_under(mSDL2, "MessageBox");
|
204
|
+
|
205
|
+
rb_define_singleton_method(mMessageBox, "show_simple_box",
|
206
|
+
MessageBox_s_show_simple_box, 4);
|
207
|
+
rb_define_singleton_method(mMessageBox, "show", MessageBox_s_show, 1);
|
208
|
+
/* This flag means that the message box shows an error message */
|
209
|
+
rb_define_const(mMessageBox, "ERROR", INT2NUM(SDL_MESSAGEBOX_ERROR));
|
210
|
+
/* This flag means that the message box shows a warning message */
|
211
|
+
rb_define_const(mMessageBox, "WARNING", INT2NUM(SDL_MESSAGEBOX_WARNING));
|
212
|
+
/* This flag means that the message box shows an informational message */
|
213
|
+
rb_define_const(mMessageBox, "INFORMATION", INT2NUM(SDL_MESSAGEBOX_INFORMATION));
|
214
|
+
/* This flag represents the button is selected when return key is pressed */
|
215
|
+
rb_define_const(mMessageBox, "BUTTON_RETURNKEY_DEFAULT",
|
213
216
|
INT2NUM(SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT));
|
214
|
-
/* This flag represents the button is selected when escape key is pressed
|
215
|
-
|
216
|
-
rb_define_const(mSDL2, "MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT",
|
217
|
+
/* This flag represents the button is selected when escape key is pressed */
|
218
|
+
rb_define_const(mMessageBox, "BUTTON_ESCAPEKEY_DEFAULT",
|
217
219
|
INT2NUM(SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT));
|
218
220
|
|
219
221
|
sym_flags = ID2SYM(rb_intern("flags"));
|