a couple assertions about async loaders
[vg.git] / vg_imgui.h
index 1b5aceac38bfc931a723ac4bf24213ada60381c7..3fa07d415ca485dad7a10d52d89bc697aa137f6d 100644 (file)
@@ -82,6 +82,13 @@ typedef u32 ui_scheme[8*4];
 #define UI_TEXTBOX_MULTILINE 0x1
 #define UI_TEXTBOX_WRAP      0x2
 #define UI_TEXTBOX_AUTOFOCUS 0x4
+
+#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))
@@ -107,7 +114,8 @@ struct{
    enum ui_control_type{
       k_ui_control_none,
       k_ui_control_textbox,
-      k_ui_control_dropdown
+      k_ui_control_dropdown,
+               k_ui_control_modal
    }
    focused_control_type;
 
@@ -138,6 +146,16 @@ struct{
    }
    dropdown;
    };
+       struct ui_modal{
+               const char *message;
+               u32 options;
+               
+               struct ui_modal_callbacks{
+                       void (*close)(u32);
+               }
+               callbacks;
+       }
+   modal;
        
        GLuint tex_glyphs, vao, vbo, ebo;
 
@@ -836,7 +854,7 @@ static u32 ui_ntext( ui_rect rect, const char *str, u32 len, ui_px scale,
          text_cursor[0] -= UI_GLYPH_SPACING_X*scale;
 
                        u8 glyph_base[2];
-                       u8 glyph_index = '\x90';
+                       u8 glyph_index = '\xb6';
                        glyph_base[0] = glyph_index & 0xf;
                        glyph_base[1] = (glyph_index-glyph_base[0])>>4;
                        glyph_base[0] *= 8;
@@ -1073,6 +1091,43 @@ static void ui_postrender(void)
    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 );
+      row0[0] += UI_GLYPH_SPACING_X;
+      ui_ntext( row0, vg_ui.modal.message, (box[2]/UI_GLYPH_SPACING_X)-2, 1, 
+                k_ui_align_left, 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 );
 
@@ -1511,17 +1566,17 @@ static void _ui_textbox_cut(void)
 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 );
-      }
    }
 }
 
@@ -1627,6 +1682,7 @@ static int ui_textbox( ui_rect rect, char *buf, u32 len, u32 flags,
       click = 0;
       target = 0;
       hover = 0;
+      flags &= ~UI_TEXTBOX_AUTOFOCUS;
    }
 
    u32 col_base      = ui_colour( k_ui_bg ),
@@ -1799,6 +1855,23 @@ static int ui_textbox( ui_rect rect, char *buf, u32 len, u32 flags,
    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
  * -----------------------------------------------------------------------------