]> git.sesse.net Git - vlc/blob - modules/gui/beos/PreferencesWindow.cpp
* enhanced BeOS preferences window (post-processing, brightness,
[vlc] / modules / gui / beos / PreferencesWindow.cpp
1 /*****************************************************************************
2  * PreferencesWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: PreferencesWindow.cpp,v 1.2 2002/11/23 15:00:54 titer Exp $
6  *
7  * Authors: Eric Petit <titer@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /* BeOS headers */
25 #include <InterfaceKit.h>
26
27 /* VLC headers */
28 #include <vlc/vlc.h>
29 #include <vlc/intf.h>
30
31 /* BeOS module headers */
32 #include "VlcWrapper.h"
33 #include "MsgVals.h"
34 #include "PreferencesWindow.h"
35
36
37 /*****************************************************************************
38  * Preferences::PreferencesWindow
39  *****************************************************************************/
40 PreferencesWindow::PreferencesWindow( BRect frame, const char* name,
41                                                                 intf_thread_t *p_interface )
42         :       BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
43                                  B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE )
44 {
45         p_intf = p_interface;
46     BRect rect;
47
48     /* "background" view */
49     p_prefs_view = new BView( Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
50     p_prefs_view->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
51     AddChild( p_prefs_view );
52
53     /* add the tabs */
54     rect = Bounds();
55     rect.top += 10;
56     rect.bottom -= 65;
57     p_tabview = new BTabView( rect, "preferences view" );
58     p_tabview->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
59     
60     p_ffmpeg_view = new BView( p_tabview->Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
61     p_ffmpeg_view->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
62     p_adjust_view = new BView( p_tabview->Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
63     p_adjust_view->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
64     
65     p_ffmpeg_tab = new BTab();
66     p_tabview->AddTab( p_ffmpeg_view, p_ffmpeg_tab );
67     p_ffmpeg_tab->SetLabel( "Ffmpeg" );
68     
69     p_adjust_tab = new BTab();
70     p_tabview->AddTab( p_adjust_view, p_adjust_tab );
71     p_adjust_tab->SetLabel( "Adjust" );
72     
73     /* fills the tabs */
74     /* ffmpeg tab */
75     rect = p_ffmpeg_view->Bounds();
76     rect.InsetBy( 10, 10 );
77     rect.bottom = rect.top + 30;
78     p_pp_slider = new BSlider( rect, "post-processing", "MPEG4 post-processing level",
79                                new BMessage( SLIDER_UPDATE ),
80                                0, 6, B_TRIANGLE_THUMB,
81                                B_FOLLOW_LEFT, B_WILL_DRAW ); 
82     p_pp_slider->SetHashMarks(B_HASH_MARKS_BOTTOM);
83     p_pp_slider->SetHashMarkCount( 7 );
84     p_pp_slider->SetLimitLabels( "None", "Maximum" );
85     p_ffmpeg_view->AddChild( p_pp_slider );
86     
87     
88     /* adjust tab */
89     rect = p_adjust_view->Bounds();
90     rect.InsetBy( 10, 10 );
91     rect.bottom = rect.top + 30;
92     p_brightness_slider = new BSlider( rect, "brightness", "Brightness",
93                                        new BMessage( SLIDER_UPDATE ),
94                                        0, 200, B_TRIANGLE_THUMB,
95                                        B_FOLLOW_LEFT, B_WILL_DRAW );
96     p_brightness_slider->SetValue( 100 * config_GetFloat( p_intf, "Brightness" ) );
97     rect.OffsetBy( 0, 40 );
98     p_contrast_slider = new BSlider( rect, "contrast", "Contrast",
99                                      new BMessage( SLIDER_UPDATE ),
100                                      0, 200, B_TRIANGLE_THUMB,
101                                      B_FOLLOW_LEFT, B_WILL_DRAW );
102     p_contrast_slider->SetValue( 100 * config_GetFloat( p_intf, "Contrast" ) );
103     rect.OffsetBy( 0, 40 );
104     p_hue_slider = new BSlider( rect, "hue", "Hue",
105                                 new BMessage( SLIDER_UPDATE ),
106                                 0, 360, B_TRIANGLE_THUMB,
107                                 B_FOLLOW_LEFT, B_WILL_DRAW );
108     p_hue_slider->SetValue( config_GetInt( p_intf, "Hue" ) );
109     rect.OffsetBy( 0, 40 );
110     p_saturation_slider = new BSlider( rect, "saturation", "Saturation",
111                                        new BMessage( SLIDER_UPDATE ),
112                                        0, 200, B_TRIANGLE_THUMB,
113                                        B_FOLLOW_LEFT, B_WILL_DRAW );
114     p_saturation_slider->SetValue( 100 * config_GetFloat( p_intf, "Saturation" ) );
115     p_adjust_view->AddChild( p_brightness_slider );
116     p_adjust_view->AddChild( p_contrast_slider );
117     p_adjust_view->AddChild( p_hue_slider );
118     p_adjust_view->AddChild( p_saturation_slider );
119     
120     p_prefs_view->AddChild( p_tabview );
121
122     /* restart message */
123     rect = p_prefs_view->Bounds();
124     rect.bottom -= 43;
125     rect.top = rect.bottom - 10;
126     p_restart_string = new BStringView( rect, NULL, "" );
127     rgb_color redColor = {255, 0, 0, 255};
128     p_restart_string->SetHighColor(redColor);
129     p_restart_string->SetAlignment( B_ALIGN_CENTER );
130     p_prefs_view->AddChild( p_restart_string );
131
132     /* buttons */
133     BButton *p_button;
134     rect = Bounds();
135     rect.InsetBy( 10, 10 );
136     rect.top = rect.bottom - 25;
137     rect.left = rect.right - 80;
138     p_button = new BButton( rect, NULL, "OK", new BMessage( PREFS_OK ) );
139     p_prefs_view->AddChild( p_button );
140     
141     rect.OffsetBy( -90, 0 );
142     p_button = new BButton( rect, NULL, "Cancel", new BMessage( PREFS_CANCEL ) );
143     p_prefs_view->AddChild( p_button );
144     
145     rect.OffsetBy( -90, 0 );
146     p_button = new BButton( rect, NULL, "Defaults", new BMessage( PREFS_DEFAULTS ) );
147     p_prefs_view->AddChild( p_button );
148     
149         // start window thread in hidden state
150         Hide();
151         Show();
152 }
153
154 /*****************************************************************************
155  * PreferencesWindow::~PreferencesWindow
156  *****************************************************************************/
157 PreferencesWindow::~PreferencesWindow()
158 {
159 }
160
161 /*****************************************************************************
162  * PreferencesWindow::MessageReceived
163  *****************************************************************************/
164 void PreferencesWindow::MessageReceived( BMessage * p_message )
165 {
166         switch ( p_message->what )
167         {
168             case SLIDER_UPDATE:
169             {
170                 ApplyChanges();
171                 break;
172             }
173             case PREFS_DEFAULTS:
174             {
175                 SetDefaults();
176                 break;
177             }
178             case PREFS_OK:
179             {
180                 config_PutInt( p_intf, "ffmpeg-pp-q", p_pp_slider->Value() );
181             config_PutPsz( p_intf, "filter", "adjust" );
182             ApplyChanges();
183             Hide();
184             }
185                 default:
186                         BWindow::MessageReceived( p_message );
187                         break;
188         }
189 }
190
191 /*****************************************************************************
192  * PreferencesWindow::ReallyQuit
193  *****************************************************************************/
194 void PreferencesWindow::ReallyQuit()
195 {
196     Hide();
197     Quit();
198 }
199
200 /*****************************************************************************
201  * PreferencesWindow::SetDefaults
202  *****************************************************************************/
203 void PreferencesWindow::SetDefaults()
204 {
205     p_pp_slider->SetValue( 0 );
206     p_brightness_slider->SetValue( 100 );
207     p_contrast_slider->SetValue( 100 );
208     p_hue_slider->SetValue( 0 );
209     p_saturation_slider->SetValue( 100 );
210
211     p_restart_string->SetText( config_GetInt( p_intf, "ffmpeg-pp-q" ) ?
212         "Changes will take effect after you restart playback" : "" );
213     
214     config_PutPsz( p_intf, "filter", NULL );
215     config_PutInt( p_intf, "ffmpeg-pp-q", 0 );
216     
217     ApplyChanges();
218 }
219
220 /*****************************************************************************
221  * PreferencesWindow::ApplyChanges
222  *****************************************************************************/
223 void PreferencesWindow::ApplyChanges()
224 {
225     bool b_restart_needed = false;
226
227     if( ( !config_GetPsz( p_intf, "filter" ) ||
228           strncmp( config_GetPsz( p_intf, "filter" ), "adjust", 6 ) ) &&
229         ( p_brightness_slider->Value() != 100 ||
230           p_contrast_slider->Value() != 100 ||
231           p_hue_slider->Value() ||
232           p_saturation_slider->Value() != 100 ) )
233     {
234         b_restart_needed = true;
235     }
236
237     if( p_pp_slider->Value() != config_GetInt( p_intf, "ffmpeg-pp-q" ) )
238     {
239         b_restart_needed = true;
240     }
241     
242     config_PutFloat( p_intf, "Brightness",
243                      (float)p_brightness_slider->Value() / 100 );
244     config_PutFloat( p_intf, "Contrast",
245                      (float)p_contrast_slider->Value() / 100 );
246     config_PutInt( p_intf, "Hue", p_hue_slider->Value() );
247     config_PutFloat( p_intf, "Saturation",
248                      (float)p_saturation_slider->Value() / 100 );
249     
250     p_restart_string->LockLooper();
251     p_restart_string->SetText( b_restart_needed ?
252         "Changes will take effect after you restart playback" : "" );
253     p_restart_string->UnlockLooper();
254 }