]> git.sesse.net Git - vlc/blob - modules/gui/beos/PreferencesWindow.cpp
* Needed update because variables names changed in the 'adjust' module.
[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.5 2003/01/11 20:42:47 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         "Warning: changing settings after starting playback may have no effect." );
128     /*rgb_color redColor = {255, 0, 0, 255};
129     fRestartString->SetHighColor(redColor);*/
130     fRestartString->SetAlignment( B_ALIGN_CENTER );
131     fPrefsView->AddChild( fRestartString );
132
133     /* buttons */
134     BButton *button;
135     rect = Bounds();
136     rect.InsetBy( 10, 10 );
137     rect.top = rect.bottom - 25;
138     rect.left = rect.right - 80;
139     button = new BButton( rect, NULL, "OK", new BMessage( PREFS_OK ) );
140     fPrefsView->AddChild( button );
141     
142     rect.OffsetBy( -90, 0 );
143     button = new BButton( rect, NULL, "Defaults", new BMessage( PREFS_DEFAULTS ) );
144     fPrefsView->AddChild( button );
145     
146         // start window thread in hidden state
147         Hide();
148         Show();
149 }
150
151 /*****************************************************************************
152  * PreferencesWindow::~PreferencesWindow
153  *****************************************************************************/
154 PreferencesWindow::~PreferencesWindow()
155 {
156 }
157
158 /*****************************************************************************
159  * PreferencesWindow::MessageReceived
160  *****************************************************************************/
161 void PreferencesWindow::MessageReceived( BMessage * p_message )
162 {
163         switch ( p_message->what )
164         {
165             case SLIDER_UPDATE:
166             {
167                 ApplyChanges();
168                 break;
169             }
170             case PREFS_DEFAULTS:
171             {
172                 SetDefaults();
173             ApplyChanges();
174                 break;
175             }
176             case PREFS_OK:
177             {
178             Hide();
179             break;
180             }
181                 default:
182                         BWindow::MessageReceived( p_message );
183                         break;
184         }
185 }
186
187 /*****************************************************************************
188  * PreferencesWindow::ReallyQuit
189  *****************************************************************************/
190 void PreferencesWindow::ReallyQuit()
191 {
192     Hide();
193     Quit();
194 }
195
196 /*****************************************************************************
197  * PreferencesWindow::SetDefaults
198  *****************************************************************************/
199 void PreferencesWindow::SetDefaults()
200 {
201     fPpSlider->SetValue( 0 );
202     fBrightnessSlider->SetValue( 100 );
203     fContrastSlider->SetValue( 100 );
204     fHueSlider->SetValue( 0 );
205     fSaturationSlider->SetValue( 100 );
206 }
207
208 /*****************************************************************************
209  * PreferencesWindow::ApplyChanges
210  *****************************************************************************/
211 void PreferencesWindow::ApplyChanges()
212 {
213     config_PutInt( p_intf, "ffmpeg-pp-q", fPpSlider->Value() );
214     config_PutFloat( p_intf, "brightness",
215                      (float)fBrightnessSlider->Value() / 100 );
216     config_PutFloat( p_intf, "contrast",
217                      (float)fContrastSlider->Value() / 100 );
218     config_PutInt( p_intf, "hue", fHueSlider->Value() );
219     config_PutFloat( p_intf, "saturation",
220                      (float)fSaturationSlider->Value() / 100 );
221
222     if( config_GetFloat( p_intf, "brightness" ) != 1 ||
223         config_GetFloat( p_intf, "contrast" ) != 1 ||
224         config_GetInt( p_intf, "hue" ) != 0 ||
225         config_GetFloat( p_intf, "saturation" ) != 1 )
226     {
227         config_PutPsz( p_intf, "filter", "adjust" );
228     }
229     else
230     {
231         config_PutPsz( p_intf, "filter", NULL );
232     }
233 }