]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwidgets/extrapanel.cpp
Preferences: don't show empty boxes ('zoom' box bug)
[vlc] / modules / gui / wxwidgets / extrapanel.cpp
index 505e2e71107b815d4e47105e2470bbb9d2360adf..deb146460a2fd5929f110836d4be2443993635f1 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <vlc/vlc.h>
-#include <vlc/aout.h>
-#include <aout_internal.h>
-#include <vlc/vout.h>
-#include <vlc/intf.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_aout.h>
+#include <vlc_vout.h>
+#include <vlc_interface.h>
 
 #include <math.h>
 
@@ -46,9 +49,9 @@ static int IntfBandsCallback( vlc_object_t *, char const *,
 static int IntfPreampCallback( vlc_object_t *, char const *,
                                vlc_value_t, vlc_value_t, void * );
 static void ChangeFiltersString( intf_thread_t *, aout_instance_t *,
-                                 char *, vlc_bool_t );
-static void ChangeVFiltersString( intf_thread_t *, char *, vlc_bool_t );
-
+                                 char *, bool );
+static void ChangeVFiltersString( intf_thread_t *, char *, bool );
+static void ChangeVFilters2String( intf_thread_t *, char *, bool );
 
 /* IDs for the controls and the menu commands */
 enum
@@ -141,17 +144,20 @@ struct filter {
     char *psz_filter;
     char *psz_name;
     char *psz_help;
+    bool  b_vfilter2;
 };
 
 static const struct filter vfilters[] =
 {
-    { "clone", N_("Image clone"), N_("Creates several clones of the image") },
-    { "distort", N_("Distortion"), N_("Adds distortion effects") },
-    { "invert", N_("Image inversion") , N_("Inverts the colors of the image") },
-    { "motionblur", N_("Blurring"), N_("Adds motion blurring to the image") },
-    { "transform",  N_("Transformation"), N_("Rotates or flips the image") },
-    { "magnify",  N_("Magnify"), N_("Magnifies part of the image") },
-    { "puzzle",  N_("Puzzle"), N_("Turns the image into a puzzle") },
+    { "clone", N_("Image clone"), N_("Creates several clones of the image"), false },
+    { "gradient", N_("Cartoon effect"), N_("Gradient effects (cartoon) on the image"), true },
+    { "invert", N_("Image inversion") , N_("Inverts the colors of the image"), true },
+    { "motionblur", N_("Blurring"), N_("Adds motion blurring to the image"), true },
+    { "ripple", N_("Water effect"), N_("Adds water effect to the image"), true },
+    { "wave", N_("Wave effect"), N_("Adds wave effect to the image"), true },
+    { "transform",  N_("Transformation"), N_("Rotates or flips the image"), false },
+    { "magnify",  N_("Magnify"), N_("Magnifies part of the image"), false },
+    { "puzzle",  N_("Puzzle"), N_("Turns the image into a puzzle"), false },
     { NULL, NULL, NULL } /* Do not remove this line */
 };
 
@@ -354,7 +360,7 @@ wxPanel *ExtraPanel::VideoPanel( wxWindow *parent )
         hue_slider->Disable();
         gamma_slider->Disable();
     }
-    if( psz_filters ) free( psz_filters );
+    free( psz_filters );
 
     int i_value = config_GetInt( p_intf, "hue" );
     if( i_value > 0 && i_value < 360 )
@@ -373,7 +379,7 @@ wxPanel *ExtraPanel::VideoPanel( wxWindow *parent )
     if( f_value > 0 && f_value < 10 )
         gamma_slider->SetValue( (int)(10 * f_value) );
 
-    b_update = VLC_FALSE;
+    b_update = false;
 
     return panel;
 }
@@ -484,12 +490,12 @@ wxPanel *ExtraPanel::EqzPanel( wxWindow *parent )
     top_sizer->Add( 0, 0, 1, wxALL, 2 );
 
     smooth_text = new wxStaticText( panel, -1, wxU( _("Smooth :") ));
-    smooth_text->SetToolTip( wxU( SMOOTH_TIP ) );
+    smooth_text->SetToolTip( wxU( _(SMOOTH_TIP) ) );
     top_sizer->Add( smooth_text, 0, wxALL, 2 );
 
     smooth_slider =new wxSlider( panel, Smooth_Event, 0, 0, 10 ,
                     wxDefaultPosition, wxSize( 100, -1 ) );
-    smooth_slider->SetToolTip( wxU( SMOOTH_TIP ) );
+    smooth_slider->SetToolTip( wxU( _(SMOOTH_TIP) ) );
     top_sizer->Add( smooth_slider, 0, wxALL, 2 );
     i_smooth = 0;
 
@@ -545,13 +551,13 @@ wxPanel *ExtraPanel::EqzPanel( wxWindow *parent )
 
     aout_instance_t *p_aout = (aout_instance_t *)vlc_object_find(p_intf,
                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
-    char *psz_af = NULL;
+    char *psz_af;
     if( p_aout )
     {
-        psz_af = var_GetString( p_aout, "audio-filter" );
+        psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
         if( var_GetBool( p_aout, "equalizer-2pass" ) )
             eq_2p_chkbox->SetValue( true );
-       vlc_object_release( p_aout );
+        vlc_object_release( p_aout );
     }
     else
     {
@@ -559,7 +565,7 @@ wxPanel *ExtraPanel::EqzPanel( wxWindow *parent )
         if( config_GetInt( p_intf, "equalizer-2pass" ) )
             eq_2p_chkbox->SetValue( true );
     }
-    if( psz_af != NULL ? strstr( psz_af, "equalizer" ) != NULL : VLC_FALSE )
+    if( psz_af != NULL && strstr( psz_af, "equalizer" ) )
     {
         eq_chkbox->SetValue( true );
     } else {
@@ -588,11 +594,11 @@ wxPanel *ExtraPanel::EqzPanel( wxWindow *parent )
 void ExtraPanel::OnIdle( wxIdleEvent &event )
 {
     CheckAout();
-    if( b_update == VLC_TRUE )
+    if( b_update == true )
     {
-        if( b_my_update == VLC_TRUE )
+        if( b_my_update == true )
         {
-            b_update = b_my_update = VLC_FALSE;
+            b_update = b_my_update = false;
             return;
         }
         char *p = psz_bands;
@@ -624,7 +630,7 @@ void ExtraPanel::OnIdle( wxIdleEvent &event )
         const wxString preamp = wxT("Preamp\n");
         preamp_text->SetLabel( preamp + wxU( psz_val ) + wxT( "dB" ) );
         eq_chkbox->SetValue( TRUE );
-        b_update = VLC_FALSE;
+        b_update = false;
     }
 }
 
@@ -637,7 +643,7 @@ void ExtraPanel::OnEnableEqualizer( wxCommandEvent &event )
     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
     ChangeFiltersString( p_intf,p_aout, "equalizer",
-                         event.IsChecked() ? VLC_TRUE : VLC_FALSE );
+                         event.IsChecked() ? true : false );
 
     if( event.IsChecked() )
     {
@@ -677,7 +683,7 @@ void ExtraPanel::OnEqRestore( wxCommandEvent &event )
     if( p_aout == NULL )
     {
         vlc_value_t val;
-        vlc_bool_t b_previous = eq_chkbox->IsChecked();
+        bool b_previous = eq_chkbox->IsChecked();
         val.f_float = 12.0;
         IntfPreampCallback( NULL, NULL, val,val, this );
         config_PutFloat( p_intf, "equalizer-preamp", 12.0 );
@@ -707,7 +713,7 @@ void ExtraPanel::OnEq2Pass( wxCommandEvent &event )
     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
 
-    vlc_bool_t b_2p = event.IsChecked() ? VLC_TRUE : VLC_FALSE;
+    bool b_2p = event.IsChecked() ? true : false;
 
     if( p_aout == NULL )
     {
@@ -721,7 +727,7 @@ void ExtraPanel::OnEq2Pass( wxCommandEvent &event )
         {
             for( int i = 0; i < p_aout->i_nb_inputs; i++ )
             {
-                p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
+                p_aout->pp_inputs[i]->b_restart = true;
             }
         }
         vlc_object_release( p_aout );
@@ -754,7 +760,7 @@ void ExtraPanel::OnPreamp( wxScrollEvent &event )
     {
         var_SetFloat( p_aout, "equalizer-preamp", f );
         config_PutFloat( p_intf, "equalizer-preamp", f );
-        b_my_update = VLC_TRUE;
+        b_my_update = true;
         vlc_object_release( p_aout );
     }
 }
@@ -806,7 +812,7 @@ void ExtraPanel::OnChangeEqualizer( wxScrollEvent &event )
     {
         var_SetString( p_aout, "equalizer-bands", psz_values );
         config_PutPsz( p_intf, "equalizer-bands", psz_values );
-        b_my_update = VLC_TRUE;
+        b_my_update = true;
         vlc_object_release( p_aout );
     }
 }
@@ -819,7 +825,7 @@ void ExtraPanel::OnHeadphone( wxCommandEvent &event )
     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
     ChangeFiltersString( p_intf , p_aout, "headphone_channel_mixer",
-                         event.IsChecked() ? VLC_TRUE : VLC_FALSE );
+                         event.IsChecked() ? true : false );
     if( p_aout != NULL )
         vlc_object_release( p_aout );
 }
@@ -829,7 +835,7 @@ void ExtraPanel::OnNormvol( wxCommandEvent &event )
     aout_instance_t *p_aout= (aout_instance_t *)vlc_object_find(p_intf,
                                  VLC_OBJECT_AOUT, FIND_ANYWHERE);
     ChangeFiltersString( p_intf , p_aout, "normvol",
-                         event.IsChecked() ? VLC_TRUE : VLC_FALSE );
+                         event.IsChecked() ? true : false );
     if( p_aout != NULL )
         vlc_object_release( p_aout );
 }
@@ -855,7 +861,7 @@ void ExtraPanel::OnNormvolSlider( wxScrollEvent &event )
 void ExtraPanel::OnEnableAdjust(wxCommandEvent& event)
 {
     ChangeVFiltersString( p_intf,  "adjust",
-                          event.IsChecked() ? VLC_TRUE : VLC_FALSE );
+                          event.IsChecked() ? true : false );
 
     if( event.IsChecked() )
     {
@@ -981,7 +987,7 @@ void ExtraPanel::OnAdjustUpdate( wxScrollEvent &event)
 /* FIXME */
 void ExtraPanel::OnRatio( wxCommandEvent& event )
 {
-   config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue().mb_str() );
+   config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue().mb_str(wxConvUTF8) );
 }
 
 
@@ -990,8 +996,12 @@ void ExtraPanel::OnSelectFilter(wxCommandEvent& event)
     int i_filter = event.GetId() - Filter0_Event ;
     if( vfilters[i_filter].psz_filter  )
     {
-        ChangeVFiltersString( p_intf, vfilters[i_filter].psz_filter ,
-                              event.IsChecked() ? VLC_TRUE : VLC_FALSE );
+        if( vfilters[i_filter].b_vfilter2 )
+            ChangeVFilters2String( p_intf, vfilters[i_filter].psz_filter ,
+                                event.IsChecked() ? true : false );
+        else
+            ChangeVFiltersString( p_intf, vfilters[i_filter].psz_filter ,
+                                  event.IsChecked() ? true : false );
     }
 }
 
@@ -1037,16 +1047,17 @@ void ExtraPanel::CheckAout()
             p_intf->p_sys->p_aout = p_aout;
 
             f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
-            psz_bands = var_GetString( p_aout, "equalizer-bands" );
-            b_update = VLC_TRUE;
+            psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
+            if( psz_bands == NULL )
+                psz_bands = strdup("");
+            b_update = true;
         }
         vlc_object_release( p_aout );
     }
 }
 
-
 static void ChangeVFiltersString( intf_thread_t *p_intf,
-                                 char *psz_name, vlc_bool_t b_add )
+                                  char *psz_name, bool b_add )
 {
     vout_thread_t *p_vout;
     char *psz_parser, *psz_string;
@@ -1106,16 +1117,76 @@ static void ChangeVFiltersString( intf_thread_t *p_intf,
     free( psz_string );
 }
 
+static void ChangeVFilters2String( intf_thread_t *p_intf,
+                                  char *psz_name, bool b_add )
+{
+    vout_thread_t *p_vout;
+    char *psz_parser, *psz_string;
+
+    psz_string = config_GetPsz( p_intf, "video-filter" );
+
+    if( !psz_string ) psz_string = strdup("");
+
+    psz_parser = strstr( psz_string, psz_name );
+
+    if( b_add )
+    {
+        if( !psz_parser )
+        {
+            psz_parser = psz_string;
+            asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
+                            psz_string, psz_name );
+            free( psz_parser );
+        }
+        else
+        {
+            return;
+        }
+    }
+    else
+    {
+        if( psz_parser )
+        {
+            memmove( psz_parser, psz_parser + strlen(psz_name) +
+                            (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
+                            strlen(psz_parser + strlen(psz_name)) + 1 );
+
+            /* Remove trailing : : */
+            if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
+            {
+                *(psz_string+strlen(psz_string ) -1 ) = '\0';
+            }
+         }
+         else
+         {
+             free( psz_string );
+             return;
+         }
+    }
+    /* Vout is not kept, so put that in the config */
+    config_PutPsz( p_intf, "video-filter", psz_string );
+
+    /* Try to set on the fly */
+    p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
+                                              FIND_ANYWHERE );
+    if( p_vout )
+    {
+        var_SetString( p_vout, "video-filter", psz_string );
+        vlc_object_release( p_vout );
+    }
+    free( psz_string );
+}
+
 
 static void ChangeFiltersString( intf_thread_t *p_intf,
                                  aout_instance_t * p_aout,
-                                 char *psz_name, vlc_bool_t b_add )
+                                 char *psz_name, bool b_add )
 {
     char *psz_parser, *psz_string;
 
     if( p_aout )
     {
-        psz_string = var_GetString( p_aout, "audio-filter" );
+        psz_string = var_GetNonEmptyString( p_aout, "audio-filter" );
     }
     else
     {
@@ -1169,7 +1240,7 @@ static void ChangeFiltersString( intf_thread_t *p_intf,
         var_SetString( p_aout, "audio-filter", psz_string );
         for( int i = 0; i < p_aout->i_nb_inputs; i++ )
         {
-            p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
+            p_aout->pp_inputs[i]->b_restart = true;
         }
     }
     free( psz_string );
@@ -1182,7 +1253,7 @@ static int IntfBandsCallback( vlc_object_t *p_this, char const *psz_cmd,
     ExtraPanel *p_panel = (ExtraPanel *)param;
 
     p_panel->psz_bands = strdup( newval.psz_string );
-    p_panel->b_update = VLC_TRUE;
+    p_panel->b_update = true;
 
     return VLC_SUCCESS;
 }
@@ -1193,7 +1264,7 @@ static int IntfPreampCallback( vlc_object_t *p_this, char const *psz_cmd,
     ExtraPanel *p_panel = (ExtraPanel *)param;
 
     p_panel->f_preamp = newval.f_float;
-    p_panel->b_update = VLC_TRUE;
+    p_panel->b_update = true;
 
     return VLC_SUCCESS;
 }