textbox
[vg.git] / vg.h
diff --git a/vg.h b/vg.h
index d98828e3bd380b2f9d041436e2dc29045110487f..64f9187a3befde770f71dc15889c5f12145d3f08 100644 (file)
--- a/vg.h
+++ b/vg.h
@@ -122,7 +122,7 @@ VG_STATIC void vg_update_fixed(void);
 VG_STATIC void vg_update_post(void);
 
 VG_STATIC void vg_render(void);
-VG_STATIC void vg_ui(void);
+VG_STATIC void vg_gui(void);
 
 struct vg
 {
@@ -200,6 +200,8 @@ struct vg
       k_quality_profile_low = 1,
    }
    quality_profile;
+
+   float loader_ring;
 }
 VG_STATIC vg = { .time_rate = 1.0 };
 
@@ -251,6 +253,7 @@ VG_STATIC void vg_checkgl( const char *src_info );
 #include "vg_tex.h"
 #include "vg_input.h"
 #include "vg_ui.h"
+#include "vg_imgui.h"
 #include "vg_lines.h"
 #include "vg_loader.h"
 #include "vg_opt.h"
@@ -322,22 +325,28 @@ VG_STATIC void _vg_process_events(void)
    v2_zero( vg.mouse_wheel );
    v2_zero( vg.mouse_delta );
 
+   /* Update input */
+   vg_process_inputs();
+
    /* SDL event loop */
    SDL_Event event;
    while( SDL_PollEvent( &event ) ){
       if( event.type == SDL_KEYDOWN ){
-         console_proc_key( event.key.keysym );
+         //console_proc_key( event.key.keysym );
+         _ui_proc_key( event.key.keysym );
       }
       else if( event.type == SDL_MOUSEWHEEL ){
          vg.mouse_wheel[0] += event.wheel.preciseX;
          vg.mouse_wheel[1] += event.wheel.preciseY;
       }
+      else if( event.type == SDL_CONTROLLERDEVICEADDED ||
+               event.type == SDL_CONTROLLERDEVICEREMOVED )
+      {
+         vg_input_device_event( &event );
+      }
       else if( event.type == SDL_CONTROLLERAXISMOTION ||
                event.type == SDL_CONTROLLERBUTTONDOWN ||
-               event.type == SDL_CONTROLLERBUTTONUP ||
-               event.type == SDL_CONTROLLERDEVICEADDED ||
-               event.type == SDL_CONTROLLERDEVICEREMOVED
-               )
+               event.type == SDL_CONTROLLERBUTTONUP )
       {
          vg_input_controller_event( &event );
       }
@@ -366,15 +375,13 @@ VG_STATIC void _vg_process_events(void)
          }
       }
       else if( event.type == SDL_TEXTINPUT ){
-         console_proc_utf8( event.text.text );
+         //console_proc_utf8( event.text.text );
+         ui_proc_utf8( event.text.text );
       }
    }
 
    vg.mouse_pos[0] += vg.mouse_delta[0];
    vg.mouse_pos[1] += vg.mouse_delta[1];
-
-   /* Update input */
-   vg_update_inputs();
 }
 
 VG_STATIC void _vg_gameloop_update(void)
@@ -422,6 +429,10 @@ VG_STATIC void _vg_gameloop_render(void)
    /* ui */
    vg.engine_stage = k_engine_stage_ui;
    {
+      ui_prerender();
+      vg_gui();
+      ui_postrender();
+#if 0
       ui_begin( vg.window_x, vg.window_y );
 
       /* TODO */
@@ -468,11 +479,12 @@ VG_STATIC void _vg_gameloop_render(void)
 
       /* FIXME */
       audio_debug_ui( vg.pv );
-      vg_ui();
+      vg_gui();
       _vg_console_draw();
       
       ui_resolve();
       ui_draw( NULL );
+#endif
    }
 
    vg_profile_end( &vg_prof_render );
@@ -546,11 +558,10 @@ VG_STATIC int vg_framefilter( double dt )
 
 VG_STATIC int _vg_crashscreen(void)
 {
-   if( vg.window_should_close )
-      return 1;
-
+#if 0
    if( vg_getkey( SDLK_ESCAPE ) )
       return 1;
+#endif
 
    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
    glEnable(GL_BLEND);
@@ -594,20 +605,20 @@ VG_STATIC void _vg_gameloop(void)
 
       enum engine_status status = _vg_engine_status();
 
+      vg.time_delta = vg.time_frame_delta * vg.time_rate;
+      vg.time += vg.time_delta;
+
+      vg_run_async_checked();
+      _vg_process_events();
+
+      if( vg.window_should_close )
+         break;
+         
       if( status == k_engine_status_crashed ){
          if( _vg_crashscreen() )
             break;
       }
       else{
-         vg.time_delta = vg.time_frame_delta * vg.time_rate;
-         vg.time += vg.time_delta;
-
-         vg_run_async_checked();
-         _vg_process_events();
-
-         if( vg.window_should_close )
-            break;
-         
          if( status == k_engine_status_running ){
             _vg_gameloop_update();
             _vg_gameloop_render();
@@ -617,6 +628,11 @@ VG_STATIC void _vg_gameloop(void)
          }
       }
 
+      if( vg.loader_ring > 0.01f ){
+         vg.loader_ring -= vg.time_frame_delta * 0.5f;
+         _vg_loader_render_ring( vg.loader_ring );
+      }
+
       vg.time_frame_delta = 0.0;
       vg.time_spinning = 0;
    }
@@ -716,7 +732,7 @@ VG_STATIC void _vg_init_window( const char *window_name )
 
 #ifdef VG_DEVWINDOW
          0, 0, vg.window_x, vg.window_y, 
-         SDL_WINDOW_BORDERLESS|SDL_WINDOW_OPENGL|SDL_WINDOW_INPUT_GRABBED
+         SDL_WINDOW_BORDERLESS|SDL_WINDOW_OPENGL
       ))){}
 #else
                                      0, 0,
@@ -743,6 +759,9 @@ VG_STATIC void _vg_init_window( const char *window_name )
 
    vg_info( "CreateContext\n" );
 
+   /* ????? */
+   if( SDL_IsTextInputActive() ) SDL_StopTextInput();
+
    /* 
     * OpenGL loading 
     */
@@ -821,7 +840,10 @@ VG_STATIC void vg_enter( int argc, char *argv[], const char *window_name )
 
    vg_async_init();
    
+#ifndef VG_DEVWINDOW
    SDL_SetRelativeMouseMode(1);
+#endif
+
    vg.thread_id_main = SDL_GetThreadID(NULL);
    
    /* Opengl-required systems */