#define UI_TEXTBOX_WRAP 0x2
#define UI_TEXTBOX_AUTOFOCUS 0x4
-#define UI_MODAL_OK 0x1
-#define UI_MODAL_YES 0x2
-#define UI_MODAL_NO 0x4
-#define UI_MODAL_CANCEL 0x8
+#define UI_MODAL_OK 0x0
+#define UI_MODAL_GOOD 0x1
+#define UI_MODAL_BAD 0x2
+#define UI_MODAL_WARN 0x3
+#define UI_MODAL_TYPE_BITS 0x3
#define UI_MOUSE_LEFT (SDL_BUTTON(SDL_BUTTON_LEFT))
#define UI_MOUSE_RIGHT (SDL_BUTTON(SDL_BUTTON_RIGHT))
#define UI_MOUSE_MIDDLE (SDL_BUTTON(SDL_BUTTON_MIDDLE))
-
-
struct{
struct ui_vert *vertex_buffer;
u16 *indice_buffer;
ui_rect rect;
}
dropdown;
-
+ };
struct ui_modal{
const char *message;
u32 options;
void (*close)(u32);
}
callbacks;
- };
- };
+ }
+ modal;
GLuint tex_glyphs, vao, vbo, ebo;
if( vg_ui.focused_control_type == k_ui_control_dropdown ){
ui_enum_post();
}
+ else if( vg_ui.focused_control_type == k_ui_control_modal ){
+ ui_rect screen = {0,0,vg.window_x,vg.window_y};
+ ui_fill( screen, 0xa0000000 );
+ ui_rect box = {0,0,400,200};
+
+ u32 colour = ui_colour(k_ui_fg),
+ type = vg_ui.modal.options & UI_MODAL_TYPE_BITS;
+ if ( type == 1 ) colour = ui_colour(k_ui_green);
+ else if( type == 2 ) colour = ui_colour(k_ui_red);
+ else if( type == 3 ) colour = ui_colour(k_ui_yellow);
+
+ ui_rect_center( screen, box );
+ ui_fill( box, ui_colour(k_ui_bg) );
+ ui_outline( box, -1, colour );
+
+ ui_rect message;
+ rect_copy( box, message );
+ message[3] = 100;
+ ui_rect_center( box, message );
+
+ ui_rect row0, row1, btn;
+ ui_split_ratio( message, k_ui_axis_h, 0.5f, 0, row0, row1 );
+ ui_text( row0, vg_ui.modal.message, 1, k_ui_align_middle_center, colour );
+
+ rect_copy( row1, btn );
+ btn[2] = 86;
+ btn[3] = 28;
+ ui_rect_center( row1, btn );
+
+ vg_ui.focused_control_type = k_ui_control_none; /* HACK */
+ if( !ui_button_text( btn, "OK", 1 ) )
+ vg_ui.focused_control_hit = 1;
+ vg_ui.focused_control_type = k_ui_control_modal; /* HACK */
+ vg_ui.wants_mouse = 1;
+ }
ui_flush( k_ui_shader_colour );
static void _ui_textbox_enter(void)
{
if( vg_ui.focused_control_type == k_ui_control_textbox ){
- if( vg_ui.textbox.flags & UI_TEXTBOX_MULTILINE ){
+ if( vg_ui.textbox.callbacks.enter )
+ vg_ui.textbox.callbacks.enter( vg_ui.textbuf, vg_ui.textbox.len );
+
+ if( vg_ui.focused_control_type != k_ui_control_textbox ) return;
+
+ if( vg_ui.textbox.flags & UI_TEXTBOX_MULTILINE )
_ui_textbox_put_char( '\n' );
- }
else{
if( !(vg_ui.textbox.flags & UI_TEXTBOX_AUTOFOCUS ) )
ui_defocus_all();
}
-
- if( vg_ui.textbox.callbacks.enter ){
- vg_ui.textbox.callbacks.enter( vg_ui.textbuf, vg_ui.textbox.len );
- }
}
}
click = 0;
target = 0;
hover = 0;
+ flags &= ~UI_TEXTBOX_AUTOFOCUS;
}
u32 col_base = ui_colour( k_ui_bg ),
return 0;
}
+/*
+ * Modal UI
+ * -----------------------------------------------------------------------------
+ */
+static void ui_start_modal( const char *message, u32 options ){
+ vg_ui.focused_control_type = k_ui_control_modal;
+ vg_ui.modal.message = message;
+ vg_ui.modal.callbacks.close = NULL;
+ vg_ui.modal.options = options;
+
+ u32 type = options & UI_MODAL_TYPE_BITS;
+ if( type == UI_MODAL_OK ) vg_info( message );
+ else if( type == UI_MODAL_WARN ) vg_warn( message );
+ else if( type == UI_MODAL_GOOD ) vg_success( message );
+ else if( type == UI_MODAL_BAD ) vg_error( message );
+}
+
/*
* Input handling
* -----------------------------------------------------------------------------