build system revision
[vg.git] / vg_settings_menu.h
diff --git a/vg_settings_menu.h b/vg_settings_menu.h
deleted file mode 100644 (file)
index 7198810..0000000
+++ /dev/null
@@ -1,434 +0,0 @@
-#ifndef VG_SETTINGS_MENU_H
-#define VG_SETTINGS_MENU_H
-
-#include "vg.h"
-#include "vg_imgui.h"
-
-#ifdef VG_GAME_SETTINGS
-static void vg_game_settings_gui( ui_rect panel ) ;
-static void vg_game_settings_init(void);
-#endif 
-
-struct ui_enum_opt vg_settings_vsync_enum[] = { 
-   { 0, "None" },
-   { 1, "On" },
-   {-1, "Adaptive" },
-};
-
-struct ui_enum_opt vg_settings_quality_enum[] = { 
-   { 0, "High Quality" },
-   { 1, "Faster" },
-   { 2, "Absolute Minimum" },
-};
-
-struct ui_enum_opt vg_settings_screen_mode_enum[] = {
-   { 0, "Fullscreen (desktop)" },
-   { 1, "Fullscreen (native)" },
-   { 2, "Floating Window" }
-};
-
-struct ui_enum_opt vg_settings_dsp_enum[] = {
-   { 1, "Enabled" },
-   { 0, "Disabled" },
-};
-
-struct {
-   struct vg_setting_ranged_i32{
-      i32 new_value, *actual_value, min, max;
-      char buf[10];
-      const char *label;
-   }
-   fps_limit;
-
-   struct vg_setting_enum{
-      i32 new_value, *actual_value;
-
-      struct ui_enum_opt *options;
-      u32 option_count;
-      const char *label;
-   }
-   vsync, quality, screenmode, audio_devices, dsp;
-   i32 temp_audio_choice;
-}
-static vg_settings = {
-   .fps_limit =   { .label = "Fps Limit",
-                     .min=24,   .max=300,  .actual_value = &vg.fps_limit },
-   .vsync =       { .label = "Vsync",
-                     .actual_value = &vg.vsync,
-                     .options = vg_settings_vsync_enum, .option_count = 3 },
-   .quality =     { .label = "Graphic Quality",
-                     .actual_value = &vg.quality_profile,
-                     .options = vg_settings_quality_enum, .option_count = 3 },
-   .screenmode =  { .label = "Type",
-                     .actual_value = &vg.screen_mode,
-                     .options = vg_settings_screen_mode_enum, .option_count=3 },
-   .audio_devices = { .label = "Audio Device",
-                      .actual_value = &vg_settings.temp_audio_choice,
-                      .options = NULL, .option_count = 0 },
-   .dsp = { .label = "Audio effects (reverb etc.)",
-             .actual_value = &vg_audio.dsp_enabled,
-             .options = vg_settings_dsp_enum, .option_count=2 },
-};
-
-static void vg_settings_ui_draw_diff( ui_rect orig ){
-   ui_rect l,r;
-   ui_split( orig, k_ui_axis_v, -32, 0, l, r );
-   ui_text( r, "*", 1, k_ui_align_middle_center, ui_colour(k_ui_blue) );
-}
-
-/* i32 settings 
- * ------------------------------------------------------------------------- */
-
-static void vg_settings_ui_int( char *buf, u32 len ){
-   for( u32 i=0, j=0; i<len; i ++ ){
-      if( ((buf[i] >= '0') && (buf[i] <= '9')) || (buf[i] == '\0') )
-         buf[j ++] = buf[i];
-   }
-}
-
-struct ui_textbox_callbacks static vg_settings_ui_int_callbacks = {
-   .change = vg_settings_ui_int
-};
-
-static bool vg_settings_ranged_i32_valid( struct vg_setting_ranged_i32 *prop ){
-   if( prop->new_value < prop->min ) return 0;
-   if( prop->new_value > prop->max ) return 0;
-   return 1;
-}
-
-static bool vg_settings_ranged_i32_diff( struct vg_setting_ranged_i32 *prop ){
-   if( prop->new_value != *prop->actual_value ) return 1;
-   else return 0;
-}
-
-static bool vg_settings_ui_ranged_i32( struct vg_setting_ranged_i32 *prop, 
-                                       ui_rect rect ){
-   ui_rect orig;
-   rect_copy( rect, orig );
-
-   ui_textbox( rect, prop->label, prop->buf, sizeof(prop->buf), 
-               1, 0, &vg_settings_ui_int_callbacks );
-   prop->new_value = atoi( prop->buf );
-
-   if( vg_settings_ranged_i32_diff( prop ) )
-      vg_settings_ui_draw_diff( orig );
-
-   bool valid = vg_settings_ranged_i32_valid( prop );
-   if( !valid ){
-      ui_rect _null, line;
-      ui_split( orig, k_ui_axis_h, -1, 0, _null, line );
-      line[1] += 3;
-
-      ui_fill( line, ui_colour( k_ui_red ) );
-   }
-
-   return valid;
-}
-
-static void ui_settings_ranged_i32_init( struct vg_setting_ranged_i32 *prop ){
-   vg_str tmp;
-   vg_strnull( &tmp, prop->buf, sizeof(prop->buf) );
-   vg_strcati32( &tmp, *prop->actual_value );
-   prop->new_value = *prop->actual_value;
-}
-
-/* enum settings
- * ------------------------------------------------------------------------- */
-
-static bool vg_settings_enum_diff( struct vg_setting_enum *prop ){
-   if( prop->new_value != *prop->actual_value ) return 1;
-   else return 0;
-}
-
-static bool vg_settings_enum( struct vg_setting_enum *prop, ui_rect rect ){
-   ui_rect orig;
-   rect_copy( rect, orig );
-
-   ui_enum( rect, prop->label,
-            prop->options, prop->option_count, &prop->new_value );
-
-   if( vg_settings_enum_diff( prop ) )
-      vg_settings_ui_draw_diff( orig );
-   
-   return 1;
-}
-
-static void ui_settings_enum_init( struct vg_setting_enum *prop ){
-   prop->new_value = *prop->actual_value;
-}
-
-/* .. */
-
-static void vg_settings_ui_header( ui_rect inout_panel, const char *name ){
-   ui_rect rect;
-   ui_standard_widget( inout_panel, rect, 2 );
-   ui_text( rect, name, 1, k_ui_align_middle_center, ui_colour(k_ui_fg+3) );
-}
-
-
-static bool vg_settings_apply_button( ui_rect inout_panel, bool validated ){
-   ui_rect last_row;
-   ui_px height = (vg_ui.font->glyph_height + 18) * k_ui_scale;
-   ui_split( inout_panel, k_ui_axis_h, -height, k_ui_padding, 
-             inout_panel, last_row );
-
-   const char *string = "Apply";
-   if( validated ){
-      if( ui_button( last_row, string ) == 1 )
-         return 1;
-   }
-   else{
-      ui_rect rect;
-      ui_standard_widget( last_row, rect, 1 );
-      ui_fill( rect, ui_colour( k_ui_bg+1 ) );
-      ui_outline( rect, -1, ui_colour( k_ui_red ), 0 );
-
-      ui_rect t = { 0,0, ui_text_line_width( string ), 14 };
-      ui_rect_center( rect, t );
-      ui_text( t, string, 1, k_ui_align_left, ui_colour(k_ui_fg+3) );
-   }
-
-   return 0;
-}
-
-static void vg_settings_video_apply(void){
-   if( vg_settings_enum_diff( &vg_settings.screenmode ) ){
-      vg.screen_mode = vg_settings.screenmode.new_value;
-
-      if( (vg.screen_mode == 0) || (vg.screen_mode == 1) ){
-         SDL_DisplayMode video_mode;
-         if( SDL_GetDesktopDisplayMode( 0, &video_mode ) ){
-            vg_error("SDL_GetDesktopDisplayMode failed: %s\n", SDL_GetError());
-         }
-         else {
-            //vg.display_refresh_rate = video_mode.refresh_rate;
-            vg.window_x = video_mode.w;
-            vg.window_y = video_mode.h;
-         }
-         SDL_SetWindowSize( vg.window, vg.window_x, vg.window_y );
-      }
-
-      if( vg.screen_mode == 0 )
-         SDL_SetWindowFullscreen( vg.window, SDL_WINDOW_FULLSCREEN_DESKTOP );
-      if( vg.screen_mode == 1 )
-         SDL_SetWindowFullscreen( vg.window, SDL_WINDOW_FULLSCREEN );
-      if( vg.screen_mode == 2 ){
-         SDL_SetWindowFullscreen( vg.window, 0 );
-         SDL_SetWindowSize( vg.window, 1280, 720 );
-         SDL_SetWindowPosition( vg.window, 16, 16 );
-         SDL_SetWindowMinimumSize( vg.window, 1280, 720 );
-         SDL_SetWindowMaximumSize( vg.window, 4096, 4096 );
-      }
-   }
-
-   vg.fps_limit = vg_settings.fps_limit.new_value;
-   vg.quality_profile = vg_settings.quality.new_value;
-   vg.vsync = vg_settings.vsync.new_value;
-}
-
-static void aaaaaaaaaaaaaaaaa( ui_rect r );
-static void vg_settings_video_gui( ui_rect panel ){
-   bool validated = 1;
-   ui_rect rq;
-   ui_standard_widget( panel, rq, 1 );
-   vg_settings_enum( &vg_settings.quality, rq );
-
-   /* FIXME */
-#if 0
-   if( vg.vsync_feature == k_vsync_feature_error ){
-      ui_info( panel, "There was an error activating vsync feature." );
-   }
-#endif
-
-   /* frame timing */
-   vg_settings_ui_header( panel, "Frame Timing" );
-   ui_rect duo, d0,d1;
-   ui_standard_widget( panel, duo, 1 );
-   ui_split_ratio( duo, k_ui_axis_v, 0.5f, 16, d0, d1 );
-
-   vg_settings_enum( &vg_settings.vsync, d0 );
-   validated &= vg_settings_ui_ranged_i32( &vg_settings.fps_limit, d1 );
-
-   ui_standard_widget( panel, duo, 10 );
-   aaaaaaaaaaaaaaaaa( duo );
-
-   /* window spec */
-   vg_settings_ui_header( panel, "Window Specification" );
-
-   ui_standard_widget( panel, duo, 1 );
-   vg_settings_enum( &vg_settings.screenmode, duo );
-
-   if( vg_settings_apply_button( panel, validated ) )
-      vg_settings_video_apply();
-}
-
-static void vg_settings_audio_apply(void){
-   if( vg_settings_enum_diff( &vg_settings.audio_devices ) ){
-      if( vg_audio.sdl_output_device ){
-         vg_info( "Closing audio device %d\n", vg_audio.sdl_output_device );
-         SDL_CloseAudioDevice( vg_audio.sdl_output_device );
-      }
-      
-      vg_strfree( &vg_audio.device_choice );
-
-      if( vg_settings.audio_devices.new_value == -1 ){ }
-      else if( vg_settings.audio_devices.new_value == -2 ){
-         vg_fatal_error( "Programming error\n" );
-      }
-      else {
-         struct ui_enum_opt *selected = NULL, *oi;
-
-         for( int i=0; i<vg_settings.audio_devices.option_count; i ++ ){
-            oi = &vg_settings.audio_devices.options[i];
-
-            if( oi->value == vg_settings.audio_devices.new_value ){
-               selected = oi;
-               break;
-            }
-         }
-
-         vg_strnull( &vg_audio.device_choice, NULL, -1 );
-         vg_strcat( &vg_audio.device_choice, oi->alias );
-      }
-
-      vg_audio_device_init();
-      *vg_settings.audio_devices.actual_value = 
-         vg_settings.audio_devices.new_value;
-   }
-
-   audio_lock();
-   if( vg_settings_enum_diff( &vg_settings.dsp ) ){
-      *vg_settings.dsp.actual_value =
-         vg_settings.dsp.new_value;
-   }
-
-   audio_unlock();
-}
-
-static void vg_settings_audio_gui( ui_rect panel ){
-   ui_rect rq;
-   ui_standard_widget( panel, rq, 1 );
-   vg_settings_enum( &vg_settings.audio_devices, rq );
-   
-   ui_standard_widget( panel, rq, 1 );
-   vg_settings_enum( &vg_settings.dsp, rq );
-
-   if( vg_settings_apply_button( panel, 1 ) )
-      vg_settings_audio_apply();
-}
-
-static void vg_settings_open(void){
-   vg.settings_open = 1;
-
-   ui_settings_ranged_i32_init( &vg_settings.fps_limit );
-   ui_settings_enum_init( &vg_settings.vsync );
-   ui_settings_enum_init( &vg_settings.quality );
-   ui_settings_enum_init( &vg_settings.screenmode );
-   
-   /* Create audio options */
-   int count = SDL_GetNumAudioDevices( 0 );
-
-   struct ui_enum_opt *options = malloc( sizeof(struct ui_enum_opt)*(count+1) );
-   vg_settings.audio_devices.options = options;
-   vg_settings.audio_devices.option_count = count+1;
-
-   struct ui_enum_opt *o0 = &options[0];
-   o0->alias = "OS Default";
-   o0->value = -1;
-
-   for( int i=0; i<count; i ++ ){
-      struct ui_enum_opt *oi = &options[i+1];
-
-      const char *device_name = SDL_GetAudioDeviceName( i, 0 );
-      int len = strlen(device_name);
-
-      oi->alias = malloc( len+1 );
-      memcpy( (void *)oi->alias, device_name, len+1 );
-      oi->value = i;
-   }
-
-   if( vg_audio.device_choice.buffer ){
-      vg_settings.temp_audio_choice = -2;
-
-      for( int i=0; i<count; i ++ ){
-         struct ui_enum_opt *oi = &options[i+1];
-         if( !strcmp( oi->alias, vg_audio.device_choice.buffer ) ){
-            vg_settings.temp_audio_choice = oi->value;
-            break;
-         }
-      }
-   }
-   else {
-      vg_settings.temp_audio_choice = -1;
-   }
-
-   ui_settings_enum_init( &vg_settings.audio_devices );
-   ui_settings_enum_init( &vg_settings.dsp );
-
-#ifdef VG_GAME_SETTINGS
-   vg_game_settings_init();
-#endif
-}
-
-static void vg_settings_close(void){
-   vg.settings_open = 0;
-
-   struct ui_enum_opt *options = vg_settings.audio_devices.options;
-   for( int i=1; i < vg_settings.audio_devices.option_count; i ++ )
-      free( (void *)options[i].alias );
-   free( vg_settings.audio_devices.options );
-}
-
-static void vg_settings_gui(void){
-   ui_rect null;
-   ui_rect screen = { 0, 0, vg.window_x, vg.window_y };
-   ui_rect window = { 0, 0, 1000, 700 };
-   ui_rect_center( screen, window );
-   vg_ui.wants_mouse = 1;
-
-   ui_fill( window, ui_colour( k_ui_bg+1 ) );
-   ui_outline( window, 1, ui_colour( k_ui_bg+7 ), 0 );
-
-   ui_rect title, panel;
-   ui_split( window, k_ui_axis_h, 28, 0, title, panel );
-   ui_fill( title, ui_colour( k_ui_bg+7 ) );
-   ui_text( title, "Settings", 1, k_ui_align_middle_center, 
-            ui_colourcont(k_ui_bg+7) );
-
-   ui_rect quit_button;
-   ui_split( title, k_ui_axis_v, title[2]-title[3], 2, title, quit_button );
-
-   if( ui_button_text( quit_button, "X", 1 ) == 1 ){
-      vg_settings_close();
-      return;
-   }
-
-   ui_rect_pad( panel, (ui_px[2]){ 8, 8 } );
-   
-   const char *opts[] = { "video", "audio",
-#ifdef VG_GAME_SETTINGS
-   "game"
-#endif
-   };
-
-   static i32 page = 0;
-   ui_tabs( panel, panel, opts, vg_list_size(opts), &page );
-
-   if( page == 0 ){
-      vg_settings_video_gui( panel );
-   }
-   else if( page == 1 )
-      vg_settings_audio_gui( panel );
-
-#ifdef VG_GAME_SETTINGS
-   else if( page == 2 )
-      vg_game_settings_gui( panel );
-#endif
-}
-
-static int cmd_vg_settings_toggle( int argc, const char *argv[] ){
-   vg_settings_open();
-   return 0;
-}
-
-#endif /* VG_SETTINGS_MENU_H */