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 $
7 * Authors: Eric Petit <titer@videolan.org>
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.
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.
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 *****************************************************************************/
25 #include <InterfaceKit.h>
31 /* BeOS module headers */
32 #include "VlcWrapper.h"
34 #include "PreferencesWindow.h"
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 )
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 );
57 fTabView = new BTabView( rect, "preferences view" );
58 fTabView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
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 ) );
65 fFfmpegTab = new BTab();
66 fTabView->AddTab( fFfmpegView, fFfmpegTab );
67 fFfmpegTab->SetLabel( "Ffmpeg" );
69 fAdjustTab = new BTab();
70 fTabView->AddTab( fAdjustView, fAdjustTab );
71 fAdjustTab->SetLabel( "Adjust" );
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 );
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 );
120 fPrefsView->AddChild( fTabView );
122 /* restart message */
123 rect = fPrefsView->Bounds();
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 );
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 );
141 rect.OffsetBy( -90, 0 );
142 button = new BButton( rect, NULL, "Cancel", new BMessage( PREFS_CANCEL ) );
143 fPrefsView->AddChild( button );
145 rect.OffsetBy( -90, 0 );
146 button = new BButton( rect, NULL, "Defaults", new BMessage( PREFS_DEFAULTS ) );
147 fPrefsView->AddChild( button );
149 // start window thread in hidden state
154 /*****************************************************************************
155 * PreferencesWindow::~PreferencesWindow
156 *****************************************************************************/
157 PreferencesWindow::~PreferencesWindow()
161 /*****************************************************************************
162 * PreferencesWindow::MessageReceived
163 *****************************************************************************/
164 void PreferencesWindow::MessageReceived( BMessage * p_message )
166 switch ( p_message->what )
180 config_PutInt( p_intf, "ffmpeg-pp-q", fPpSlider->Value() );
181 config_PutPsz( p_intf, "filter", "adjust" );
186 BWindow::MessageReceived( p_message );
191 /*****************************************************************************
192 * PreferencesWindow::ReallyQuit
193 *****************************************************************************/
194 void PreferencesWindow::ReallyQuit()
200 /*****************************************************************************
201 * PreferencesWindow::SetDefaults
202 *****************************************************************************/
203 void PreferencesWindow::SetDefaults()
205 fPpSlider->SetValue( 0 );
206 fBrightnessSlider->SetValue( 100 );
207 fContrastSlider->SetValue( 100 );
208 fHueSlider->SetValue( 0 );
209 fSaturationSlider->SetValue( 100 );
211 fRestartString->SetText( config_GetInt( p_intf, "ffmpeg-pp-q" ) ?
212 "Changes will take effect after you restart playback" : "" );
214 config_PutPsz( p_intf, "filter", NULL );
215 config_PutInt( p_intf, "ffmpeg-pp-q", 0 );
220 /*****************************************************************************
221 * PreferencesWindow::ApplyChanges
222 *****************************************************************************/
223 void PreferencesWindow::ApplyChanges()
225 bool b_restart_needed = false;
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 ) )
234 b_restart_needed = true;
237 if( fPpSlider->Value() != config_GetInt( p_intf, "ffmpeg-pp-q" ) )
239 b_restart_needed = true;
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 );
250 fRestartString->LockLooper();
251 fRestartString->SetText( b_restart_needed ?
252 "Changes will take effect after you restart playback" : "" );
253 fRestartString->UnlockLooper();