add dsp and optional game page
[vg.git] / vg_settings_menu.h
index fb6a11616c3d688f642fdc16f18819fe1f4f9389..f84fcf127112df98b4ae586dd57ae73c5c829b91 100644 (file)
@@ -4,6 +4,11 @@
 #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" },
@@ -22,6 +27,11 @@ struct ui_enum_opt vg_settings_screen_mode_enum[] = {
    { 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;
@@ -37,7 +47,7 @@ struct {
       u32 option_count;
       const char *label;
    }
-   vsync, quality, screenmode, audio_devices;
+   vsync, quality, screenmode, audio_devices, dsp;
    i32 temp_audio_choice;
 
    int windowed_before[4];
@@ -56,7 +66,10 @@ static vg_settings = {
                      .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 }
+                      .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 ){
@@ -154,6 +167,32 @@ static void vg_settings_ui_header( ui_rect inout_panel, const char *name ){
    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;
@@ -231,27 +270,8 @@ static void vg_settings_video_gui( ui_rect panel ){
    ui_standard_widget( panel, duo, 1 );
    vg_settings_enum( &vg_settings.screenmode, duo );
 
-   /* apply */
-   ui_rect last_row;
-   ui_px height = (vg_ui.font->glyph_height + 18) * k_ui_scale;
-   ui_split( panel, k_ui_axis_h, -height, k_ui_padding, 
-             panel, last_row );
-
-   const char *string = "Apply";
-   if( validated ){
-      if( ui_button( last_row, string ) == 1 )
-         vg_settings_video_apply();
-   }
-   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) );
-   }
+   if( vg_settings_apply_button( panel, validated ) )
+      vg_settings_video_apply();
 }
 
 static void vg_settings_audio_apply(void){
@@ -287,21 +307,25 @@ static void vg_settings_audio_apply(void){
       *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 );
 
-   const char *string = "Apply";
-
-   ui_rect last_row;
-   ui_px height = (vg_ui.font->glyph_height + 18) * k_ui_scale;
-   ui_split( panel, k_ui_axis_h, -height, k_ui_padding, 
-             panel, last_row );
-
-   if( ui_button( last_row, string ) == 1 )
+   if( vg_settings_apply_button( panel, 1 ) )
       vg_settings_audio_apply();
 }
 
@@ -351,6 +375,11 @@ static void vg_settings_open(void){
    }
 
    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){
@@ -388,15 +417,25 @@ static void vg_settings_gui(void){
 
    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, (const char *[]){ "video", "audio", "game" }, 
-            3, &page );
+   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[] ){