]> git.sesse.net Git - vlc/blob - modules/gui/beos/PreferencesWindow.cpp
* ALL: more intensive use of the VLCWrapper class
[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.3 2002/11/26 01:06:08 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     fPrefsView = new BView( Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
50     fPrefsView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
51     AddChild( fPrefsView );
52
53     /* add the tabs */
54     rect = Bounds();
55     rect.top += 10;
56     rect.bottom -= 65;
57     fTabView = new BTabView( rect, "preferences view" );
58     fTabView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
59     
60     fFfmpegView = new BView( fTabView->Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
61     fFfmpegView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
62     fAdjustView = new BView( fTabView->Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
63     fAdjustView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
64     
65     fFfmpegTab = new BTab();
66     fTabView->AddTab( fFfmpegView, fFfmpegTab );
67     fFfmpegTab->SetLabel( "Ffmpeg" );
68     
69     fAdjustTab = new BTab();
70     fTabView->AddTab( fAdjustView, fAdjustTab );
71     fAdjustTab->SetLabel( "Adjust" );
72     
73     /* fills the tabs */
74     /* ffmpeg tab */
75     rect = fFfmpegView->Bounds();
76     rect.InsetBy( 10, 10 );
77     rect.bottom = rect.top + 30;
78     fPpSlider = 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     fPpSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
83     fPpSlider->SetHashMarkCount( 7 );
84     fPpSlider->SetLimitLabels( "None", "Maximum" );
85     fFfmpegView->AddChild( fPpSlider );
86     
87     
88     /* adjust tab */
89     rect = fAdjustView->Bounds();
90     rect.InsetBy( 10, 10 );
91     rect.bottom = rect.top + 30;
92     fBrightnessSlider = new BSlider( rect, "brightness", "Brightness",
93                                        new BMessage( SLIDER_UPDATE ),
94                                        0, 200, B_TRIANGLE_THUMB,
95                                        B_FOLLOW_LEFT, B_WILL_DRAW );
96     fBrightnessSlider->SetValue( 100 * config_GetFloat( p_intf, "Brightness" ) );
97     rect.OffsetBy( 0, 40 );
98     fContrastSlider = new BSlider( rect, "contrast", "Contrast",
99                                      new BMessage( SLIDER_UPDATE ),
100                                      0, 200, B_TRIANGLE_THUMB,
101                                      B_FOLLOW_LEFT, B_WILL_DRAW );
102     fContrastSlider->SetValue( 100 * config_GetFloat( p_intf, "Contrast" ) );
103     rect.OffsetBy( 0, 40 );
104     fHueSlider = new BSlider( rect, "hue", "Hue",
105                                 new BMessage( SLIDER_UPDATE ),
106                                 0, 360, B_TRIANGLE_THUMB,
107                                 B_FOLLOW_LEFT, B_WILL_DRAW );
108     fHueSlider->SetValue( config_GetInt( p_intf, "Hue" ) );
109     rect.OffsetBy( 0, 40 );
110     fSaturationSlider = new BSlider( rect, "saturation", "Saturation",
111                                        new BMessage( SLIDER_UPDATE ),
112                                        0, 200, B_TRIANGLE_THUMB,
113                                        B_FOLLOW_LEFT, B_WILL_DRAW );
114     fSaturationSlider->SetValue( 100 * config_GetFloat( p_intf, "Saturation" ) );
115     fAdjustView->AddChild( fBrightnessSlider );
116     fAdjustView->AddChild( fContrastSlider );
117     fAdjustView->AddChild( fHueSlider );
118     fAdjustView->AddChild( fSaturationSlider );
119     
120     fPrefsView->AddChild( fTabView );
121
122     /* restart message */
123     rect = fPrefsView->Bounds();
124     rect.bottom -= 43;
125     rect.top = rect.bottom - 10;
126     fRestartString = new BStringView( rect, NULL, "" );
127     rgb_color redColor = {255, 0, 0, 255};
128     fRestartString->SetHighColor(redColor);
129     fRestartString->SetAlignment( B_ALIGN_CENTER );
130     fPrefsView->AddChild( fRestartString );
131
132     /* buttons */
133     BButton *button;
134     rect = Bounds();
135     rect.InsetBy( 10, 10 );
136     rect.top = rect.bottom - 25;
137     rect.left = rect.right - 80;
138     button = new BButton( rect, NULL, "OK", new BMessage( PREFS_OK ) );
139     fPrefsView->AddChild( button );
140     
141     rect.OffsetBy( -90, 0 );
142     button = new BButton( rect, NULL, "Cancel", new BMessage( PREFS_CANCEL ) );
143     fPrefsView->AddChild( button );
144     
145     rect.OffsetBy( -90, 0 );
146     button = new BButton( rect, NULL, "Defaults", new BMessage( PREFS_DEFAULTS ) );
147     fPrefsView->AddChild( 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", fPpSlider->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     fPpSlider->SetValue( 0 );
206     fBrightnessSlider->SetValue( 100 );
207     fContrastSlider->SetValue( 100 );
208     fHueSlider->SetValue( 0 );
209     fSaturationSlider->SetValue( 100 );
210
211     fRestartString->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         ( fBrightnessSlider->Value() != 100 ||
230           fContrastSlider->Value() != 100 ||
231           fHueSlider->Value() ||
232           fSaturationSlider->Value() != 100 ) )
233     {
234         b_restart_needed = true;
235     }
236
237     if( fPpSlider->Value() != config_GetInt( p_intf, "ffmpeg-pp-q" ) )
238     {
239         b_restart_needed = true;
240     }
241     
242     config_PutFloat( p_intf, "Brightness",
243                      (float)fBrightnessSlider->Value() / 100 );
244     config_PutFloat( p_intf, "Contrast",
245                      (float)fContrastSlider->Value() / 100 );
246     config_PutInt( p_intf, "Hue", fHueSlider->Value() );
247     config_PutFloat( p_intf, "Saturation",
248                      (float)fSaturationSlider->Value() / 100 );
249     
250     fRestartString->LockLooper();
251     fRestartString->SetText( b_restart_needed ?
252         "Changes will take effect after you restart playback" : "" );
253     fRestartString->UnlockLooper();
254 }