Module: SDL2::MessageBox
- Defined in:
- messagebox.c
Constant Summary
- ERROR =
This flag means that the message box shows an error message
INT2NUM(SDL_MESSAGEBOX_ERROR)
- WARNING =
This flag means that the message box shows a warning message
INT2NUM(SDL_MESSAGEBOX_WARNING)
- INFORMATION =
This flag means that the message box shows an informational message
INT2NUM(SDL_MESSAGEBOX_INFORMATION)
- BUTTON_RETURNKEY_DEFAULT =
This flag represents the button is selected when return key is pressed
INT2NUM(SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT)
- BUTTON_ESCAPEKEY_DEFAULT =
This flag represents the button is selected when escape key is pressed
INT2NUM(SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT)
Class Method Summary (collapse)
-
+ (Integer) show(flag:, window:nil, title:, message:, buttons:, color_scheme:nil)
Create a model message box.
-
+ (nil) show_simple_box(flag, title, message, parent)
Create a simple modal message box.
Class Method Details
+ (Integer) show(flag:, window:nil, title:, message:, buttons:, color_scheme:nil)
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'messagebox.c', line 137
static VALUE MessageBox_s_show(VALUE self, VALUE params)
{
SDL_MessageBoxData mb_data;
VALUE title, message, texts, buttons, color_scheme;
long num_buttons;
int i;
SDL_MessageBoxButtonData* button_data;
SDL_MessageBoxColorScheme scheme;
int buttonid;
Check_Type(params, T_HASH);
mb_data.flags = NUM2INT(rb_hash_aref(params, sym_flags));
mb_data.window = Get_SDL_Window_or_NULL(rb_hash_aref(params, sym_window));
title = rb_str_export_to_utf8(rb_hash_aref(params, sym_title));
mb_data.title = StringValueCStr(title);
message = rb_str_export_to_utf8(rb_hash_aref(params, sym_message));
mb_data.message = StringValueCStr(message);
buttons = rb_hash_aref(params, sym_buttons);
Check_Type(buttons, T_ARRAY);
mb_data.numbuttons = num_buttons = RARRAY_LEN(buttons);
button_data = ALLOCA_N(SDL_MessageBoxButtonData, num_buttons);
mb_data.buttons = button_data;
texts = rb_ary_new2(num_buttons);
for (i=0; i<num_buttons; ++i) {
VALUE button = rb_ary_entry(buttons, i);
VALUE flags = rb_hash_aref(button, sym_flags);
VALUE text;
if (flags == Qnil)
button_data[i].flags = 0;
else
button_data[i].flags = NUM2INT(flags);
text = rb_str_export_to_utf8(rb_hash_aref(button, sym_text));
rb_ary_push(texts, text);
button_data[i].buttonid = NUM2INT(rb_hash_aref(button, sym_id));
button_data[i].text = StringValueCStr(text);
}
color_scheme = rb_hash_aref(params, sym_color_scheme);
if (color_scheme == Qnil) {
mb_data.colorScheme = NULL;
} else {
Check_Type(color_scheme, T_HASH);
mb_data.colorScheme = &scheme;
set_color_scheme(color_scheme, sym_bg, &scheme.colors[0]);
set_color_scheme(color_scheme, sym_text, &scheme.colors[1]);
set_color_scheme(color_scheme, sym_button_border, &scheme.colors[2]);
set_color_scheme(color_scheme, sym_button_bg, &scheme.colors[3]);
set_color_scheme(color_scheme, sym_button_selected, &scheme.colors[4]);
}
HANDLE_ERROR(SDL_ShowMessageBox(&mb_data, &buttonid));
RB_GC_GUARD(title); RB_GC_GUARD(message); RB_GC_GUARD(texts);
return INT2NUM(buttonid);
}
|
+ (nil) show_simple_box(flag, title, message, parent)
45 46 47 48 49 50 51 52 53 54 55 |
# File 'messagebox.c', line 45
static VALUE MessageBox_s_show_simple_box(VALUE self, VALUE flag, VALUE title,
VALUE message, VALUE parent)
{
title = rb_str_export_to_utf8(title);
message = rb_str_export_to_utf8(message);
HANDLE_ERROR(SDL_ShowSimpleMessageBox(NUM2UINT(flag),
StringValueCStr(title),
StringValueCStr(message),
Get_SDL_Window_or_NULL(parent)));
return Qnil;
}
|