Commit d59b2b17 authored by Eric Petit's avatar Eric Petit

modules/gui/beos/PreferencesWindow.* :

  * added a BBox around each panel (looks nicer)
  * now use BSliders for {integer,float}_with_range
parent 41d11c19
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* PreferencesWindow.cpp: beos interface * PreferencesWindow.cpp: beos interface
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: PreferencesWindow.cpp,v 1.23 2003/05/20 11:44:18 titer Exp $ * $Id: PreferencesWindow.cpp,v 1.24 2003/05/25 17:21:36 titer Exp $
* *
* Authors: Eric Petit <titer@videolan.org> * Authors: Eric Petit <titer@videolan.org>
* *
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
#include "PreferencesWindow.h" #include "PreferencesWindow.h"
/* TODO: /* TODO:
- handle CONFIG_HINT_SUBCATEGORY
- use BSliders for integer_with_range and float_with_range
- add the needed LockLooper()s - add the needed LockLooper()s
- fix horizontal window resizing */ - fix horizontal window resizing */
...@@ -107,7 +105,6 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -107,7 +105,6 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
return; return;
} }
/* First, handle the main module */ /* First, handle the main module */
module_t * p_module = NULL; module_t * p_module = NULL;
module_config_t * p_item; module_config_t * p_item;
...@@ -130,7 +127,7 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -130,7 +127,7 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
StringItemWithView * stringItem; StringItemWithView * stringItem;
stringItem = new StringItemWithView( p_item->psz_text ); stringItem = new StringItemWithView( p_item->psz_text );
p_item++; p_item++;
stringItem->fConfigView = BuildConfigView( &p_item, true ); BuildConfigView( stringItem, &p_item, true );
fOutline->AddItem( stringItem ); fOutline->AddItem( stringItem );
} }
} }
...@@ -193,7 +190,7 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface, ...@@ -193,7 +190,7 @@ PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
/* Now add the item ! */ /* Now add the item ! */
StringItemWithView * stringItem; StringItemWithView * stringItem;
stringItem = new StringItemWithView( p_module->psz_object_name ); stringItem = new StringItemWithView( p_module->psz_object_name );
stringItem->fConfigView = BuildConfigView( &p_item, false ); BuildConfigView( stringItem, &p_item, false );
fOutline->AddUnder( stringItem, capabilityItem ); fOutline->AddUnder( stringItem, capabilityItem );
} }
...@@ -287,10 +284,6 @@ void PreferencesWindow::FrameResized( float width, float height ) ...@@ -287,10 +284,6 @@ void PreferencesWindow::FrameResized( float width, float height )
{ {
BWindow::FrameResized( width, height ); BWindow::FrameResized( width, height );
/* Get the current config BView */
BView * view;
view = fConfigScroll->ChildAt( 0 );
UpdateScrollBar(); UpdateScrollBar();
} }
...@@ -302,38 +295,29 @@ void PreferencesWindow::Update() ...@@ -302,38 +295,29 @@ void PreferencesWindow::Update()
/* Get the selected item, if any */ /* Get the selected item, if any */
if( fOutline->CurrentSelection() < 0 ) if( fOutline->CurrentSelection() < 0 )
return; return;
StringItemWithView * selectedItem = fCurrent = (StringItemWithView*)
(StringItemWithView*) fOutline->ItemAt( fOutline->CurrentSelection() ); fOutline->ItemAt( fOutline->CurrentSelection() );
if( !selectedItem->fConfigView ) if( !fCurrent->fConfigBox )
/* This is a category */ /* This is a category */
return; return;
if( fConfigScroll ) /* Detach the old item */
{ if( fDummyView->CountChildren() > 0 )
/* If we don't do this, the config BView will remember a wrong position */ fDummyView->RemoveChild( fDummyView->ChildAt( 0 ) );
BScrollBar * scrollBar = fConfigScroll->ScrollBar( B_VERTICAL );
scrollBar->SetValue( 0 );
/* Detach the current config BView, remove the BScrollView */
BView * view;
while( ( view = fConfigScroll->ChildAt( 0 ) ) )
fConfigScroll->RemoveChild( view );
fDummyView->RemoveChild( fConfigScroll );
delete fConfigScroll;
}
/* Create a BScrollView with the new config BView in it */ /* Resize and show the new config box */
BRect oldBounds = selectedItem->fConfigView->Bounds(); fCurrent->fConfigBox->ResizeTo( fDummyView->Bounds().Width(),
selectedItem->fConfigView->ResizeTo( fDummyView->Bounds().Width() -
B_V_SCROLL_BAR_WIDTH,
fDummyView->Bounds().Height() ); fDummyView->Bounds().Height() );
fConfigScroll = new BScrollView( "", selectedItem->fConfigView, B_FOLLOW_ALL_SIDES, fDummyView->AddChild( fCurrent->fConfigBox );
0, false, true, B_NO_BORDER );
fConfigScroll->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); /* Force redrawing of its children */
fDummyView->AddChild( fConfigScroll ); BRect rect = fCurrent->fConfigBox->Bounds();
selectedItem->fConfigView->ResizeTo( oldBounds.Width(), rect.InsetBy( 10,10 );
oldBounds.Height() ); rect.top += 10;
fCurrent->fConfigScroll->ResizeTo( rect.Width(), rect.Height() );
fCurrent->fConfigScroll->Draw( fCurrent->fConfigScroll->Bounds() );
UpdateScrollBar(); UpdateScrollBar();
} }
...@@ -346,21 +330,20 @@ void PreferencesWindow::UpdateScrollBar() ...@@ -346,21 +330,20 @@ void PreferencesWindow::UpdateScrollBar()
/* We have to fix the scrollbar manually because it doesn't handle /* We have to fix the scrollbar manually because it doesn't handle
correctly simple BViews */ correctly simple BViews */
/* Get the current config view */ if( !fCurrent )
BView * view; return;
view = fConfigScroll->ChildAt( 0 );
/* Get the available BRect for display */ /* Get the available BRect for display */
BRect display = fConfigScroll->Bounds(); BRect display = fCurrent->fConfigScroll->Bounds();
display.right -= B_V_SCROLL_BAR_WIDTH; display.right -= B_V_SCROLL_BAR_WIDTH;
/* Fix the scrollbar */ /* Fix the scrollbar */
BScrollBar * scrollBar; BScrollBar * scrollBar;
long max; long max;
BRect visible = display & view->Bounds(); BRect visible = display & fCurrent->fConfigView->Bounds();
BRect total = display | view->Bounds(); BRect total = display | fCurrent->fConfigView->Bounds();
scrollBar = fConfigScroll->ScrollBar( B_VERTICAL ); scrollBar = fCurrent->fConfigScroll->ScrollBar( B_VERTICAL );
max = (long)( view->Bounds().Height() - visible.Height() ); max = (long)( fCurrent->fConfigView->Bounds().Height() - visible.Height() );
if( max < 0 ) max = 0; if( max < 0 ) max = 0;
scrollBar->SetRange( 0, max ); scrollBar->SetRange( 0, max );
scrollBar->SetProportion( visible.Height() / total.Height() ); scrollBar->SetProportion( visible.Height() / total.Height() );
...@@ -464,6 +447,32 @@ void PreferencesWindow::ApplyChanges( bool doIt ) ...@@ -464,6 +447,32 @@ void PreferencesWindow::ApplyChanges( bool doIt )
} }
} }
} }
else if( !strcmp( name, "ConfigSlider" ) )
{
ConfigSlider * slider;
slider = (ConfigSlider*) child;
switch( slider->fConfigType )
{
case CONFIG_ITEM_INTEGER:
if( doIt )
config_PutInt( p_intf, slider->fConfigName,
slider->Value() );
else
slider->SetValue( config_GetInt( p_intf,
slider->fConfigName ) );
break;
case CONFIG_ITEM_FLOAT:
if( doIt )
config_PutFloat( p_intf, slider->fConfigName,
(float)slider->Value() / 100.0 );
else
slider->SetValue( config_GetFloat( p_intf,
slider->fConfigName ) * 100.0 );
break;
}
}
} }
} }
} }
...@@ -490,27 +499,45 @@ void PreferencesWindow::ReallyQuit() ...@@ -490,27 +499,45 @@ void PreferencesWindow::ReallyQuit()
/***************************************************************************** /*****************************************************************************
* PreferencesWindow::BuildConfigView * PreferencesWindow::BuildConfigView
*****************************************************************************/ *****************************************************************************/
BView * PreferencesWindow::BuildConfigView( module_config_t ** pp_item, void PreferencesWindow::BuildConfigView( StringItemWithView * stringItem,
module_config_t ** pp_item,
bool stop_after_category ) bool stop_after_category )
{ {
/* Build the config view for this module */ /* Build the BBox */
BRect rect = fDummyView->Bounds(); BRect rect = fDummyView->Bounds();
rect.right -= B_V_SCROLL_BAR_WIDTH; stringItem->fConfigBox = new BBox( rect, "config box", B_FOLLOW_ALL );
BView * configView; stringItem->fConfigBox->SetLabel( stringItem->fText );
configView = new BView( rect, "config view",
/* Build the BView */
rect = stringItem->fConfigBox->Bounds();
rect.InsetBy( 10,10 );
rect.top += 10;
rect.right -= B_V_SCROLL_BAR_WIDTH + 5;
stringItem->fConfigView = new BView( rect, "config view",
B_FOLLOW_NONE, B_WILL_DRAW ); B_FOLLOW_NONE, B_WILL_DRAW );
configView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); stringItem->fConfigView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
rect = configView->Bounds(); /* Add all the settings options */
rect = stringItem->fConfigView->Bounds();
rect.InsetBy( 10, 10 ); rect.InsetBy( 10, 10 );
ConfigTextControl * textControl; ConfigTextControl * textControl;
ConfigCheckBox * checkBox; ConfigCheckBox * checkBox;
ConfigMenuField * menuField; ConfigMenuField * menuField;
ConfigSlider * slider;
BPopUpMenu * popUp; BPopUpMenu * popUp;
bool categoryHit = false; for( ; (*pp_item)->i_type != CONFIG_HINT_END; (*pp_item)++ )
do
{ {
if( stop_after_category && (*pp_item)->i_type == CONFIG_HINT_CATEGORY )
break;
/* Discard a few options */
if( (*pp_item)->psz_name &&
( !strcmp( (*pp_item)->psz_name, "volume" ) ||
!strcmp( (*pp_item)->psz_name, "saved-volume" ) ||
!strcmp( (*pp_item)->psz_name, "advanced" ) ) )
continue;
switch( (*pp_item)->i_type ) switch( (*pp_item)->i_type )
{ {
case CONFIG_ITEM_STRING: case CONFIG_ITEM_STRING:
...@@ -529,7 +556,7 @@ BView * PreferencesWindow::BuildConfigView( module_config_t ** pp_item, ...@@ -529,7 +556,7 @@ BView * PreferencesWindow::BuildConfigView( module_config_t ** pp_item,
menuItem = new BMenuItem( (*pp_item)->ppsz_list[i], new BMessage() ); menuItem = new BMenuItem( (*pp_item)->ppsz_list[i], new BMessage() );
popUp->AddItem( menuItem ); popUp->AddItem( menuItem );
} }
configView->AddChild( menuField ); stringItem->fConfigView->AddChild( menuField );
rect.top = rect.bottom + 10; rect.top = rect.bottom + 10;
} }
else else
...@@ -537,51 +564,73 @@ BView * PreferencesWindow::BuildConfigView( module_config_t ** pp_item, ...@@ -537,51 +564,73 @@ BView * PreferencesWindow::BuildConfigView( module_config_t ** pp_item,
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
textControl = new ConfigTextControl( rect, (*pp_item)->psz_text, textControl = new ConfigTextControl( rect, (*pp_item)->psz_text,
CONFIG_ITEM_STRING, (*pp_item)->psz_name ); CONFIG_ITEM_STRING, (*pp_item)->psz_name );
configView->AddChild( textControl ); stringItem->fConfigView->AddChild( textControl );
rect.top = rect.bottom + 10; rect.top = rect.bottom + 10;
} }
break; break;
case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_INTEGER:
if( (*pp_item)->i_min == (*pp_item)->i_max )
{
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
textControl = new ConfigTextControl( rect, (*pp_item)->psz_text, textControl = new ConfigTextControl( rect, (*pp_item)->psz_text,
CONFIG_ITEM_INTEGER, (*pp_item)->psz_name ); CONFIG_ITEM_INTEGER,
configView->AddChild( textControl ); (*pp_item)->psz_name );
stringItem->fConfigView->AddChild( textControl );
rect.top = rect.bottom + 10;
}
else
{
rect.bottom = rect.top + 30;
slider = new ConfigSlider( rect, (*pp_item)->psz_text,
CONFIG_ITEM_INTEGER, (*pp_item)->i_min,
(*pp_item)->i_max, (*pp_item)->psz_name );
stringItem->fConfigView->AddChild( slider );
rect.top = rect.bottom + 10; rect.top = rect.bottom + 10;
}
break; break;
case CONFIG_ITEM_FLOAT: case CONFIG_ITEM_FLOAT:
if( (*pp_item)->f_min == (*pp_item)->f_max )
{
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
textControl = new ConfigTextControl( rect, (*pp_item)->psz_text, textControl = new ConfigTextControl( rect, (*pp_item)->psz_text,
CONFIG_ITEM_FLOAT, (*pp_item)->psz_name ); CONFIG_ITEM_FLOAT, (*pp_item)->psz_name );
configView->AddChild( textControl ); stringItem->fConfigView->AddChild( textControl );
rect.top = rect.bottom + 10;
}
else
{
rect.bottom = rect.top + 30;
slider = new ConfigSlider( rect, (*pp_item)->psz_text,
CONFIG_ITEM_FLOAT, 100 * (*pp_item)->f_min,
100 * (*pp_item)->f_max, (*pp_item)->psz_name );
stringItem->fConfigView->AddChild( slider );
rect.top = rect.bottom + 10; rect.top = rect.bottom + 10;
}
break; break;
case CONFIG_ITEM_BOOL: case CONFIG_ITEM_BOOL:
if( !strcmp( (*pp_item)->psz_name, "advanced" ) )
/* Don't show this one, the interface doesn't handle it anyway */
break;
rect.bottom = rect.top + 20; rect.bottom = rect.top + 20;
checkBox = new ConfigCheckBox( rect, (*pp_item)->psz_text, checkBox = new ConfigCheckBox( rect, (*pp_item)->psz_text,
(*pp_item)->psz_name ); (*pp_item)->psz_name );
configView->AddChild( checkBox ); stringItem->fConfigView->AddChild( checkBox );
rect.top = rect.bottom + 10; rect.top = rect.bottom + 10;
break; break;
}
case CONFIG_HINT_CATEGORY:
if( stop_after_category )
categoryHit = true;
} }
} while( !categoryHit && /* Put the BView into a BScrollView */
(*pp_item)->i_type != CONFIG_HINT_END &&
(*pp_item)++ );
/* Adjust the configView size */ stringItem->fConfigScroll =
configView->ResizeTo( configView->Bounds().Width(), rect.top ); new BScrollView( "config scroll", stringItem->fConfigView,
B_FOLLOW_ALL, 0, false, true, B_FANCY_BORDER );
stringItem->fConfigScroll->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
stringItem->fConfigBox->AddChild( stringItem->fConfigScroll );
return configView; /* Adjust the configView size */
stringItem->fConfigView->ResizeTo(
stringItem->fConfigView->Bounds().Width(), rect.top );
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* PreferencesWindow.h * PreferencesWindow.h
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: PreferencesWindow.h,v 1.16 2003/05/20 11:44:18 titer Exp $ * $Id: PreferencesWindow.h,v 1.17 2003/05/25 17:21:36 titer Exp $
* *
* Authors: Eric Petit <titer@videolan.org> * Authors: Eric Petit <titer@videolan.org>
* *
...@@ -39,11 +39,17 @@ class StringItemWithView : public BStringItem ...@@ -39,11 +39,17 @@ class StringItemWithView : public BStringItem
StringItemWithView( const char * text ) StringItemWithView( const char * text )
: BStringItem( text ) : BStringItem( text )
{ {
fConfigBox = NULL;
fConfigScroll = NULL;
fConfigView = NULL; fConfigView = NULL;
fText = strdup( text );
} }
/* Here we store the config BView associated to this module */ /* Here we store the config BBox associated to this module */
BBox * fConfigBox;
BScrollView * fConfigScroll;
BView * fConfigView; BView * fConfigView;
char * fText;
}; };
class ConfigTextControl : public BTextControl class ConfigTextControl : public BTextControl
...@@ -90,6 +96,22 @@ class ConfigMenuField : public BMenuField ...@@ -90,6 +96,22 @@ class ConfigMenuField : public BMenuField
char * fConfigName; char * fConfigName;
}; };
class ConfigSlider : public BSlider
{
public:
ConfigSlider( BRect rect, char * label, int type,
int min, int max, char * configName )
: BSlider( rect, "ConfigSlider", label,
new BMessage(), min, max )
{
fConfigType = type;
fConfigName = strdup( configName );
}
int fConfigType;
char * fConfigName;
};
class PreferencesWindow : public BWindow class PreferencesWindow : public BWindow
{ {
public: public:
...@@ -110,13 +132,15 @@ class PreferencesWindow : public BWindow ...@@ -110,13 +132,15 @@ class PreferencesWindow : public BWindow
void ReallyQuit(); void ReallyQuit();
private: private:
BView * BuildConfigView( module_config_t ** pp_item, void BuildConfigView( StringItemWithView * stringItem,
module_config_t ** pp_item,
bool stop_after_category ); bool stop_after_category );
BView * fPrefsView; BView * fPrefsView;
BOutlineListView * fOutline; BOutlineListView * fOutline;
BView * fDummyView; BView * fDummyView;
BScrollView * fConfigScroll; BScrollView * fConfigScroll;
StringItemWithView * fCurrent;
intf_thread_t * p_intf; intf_thread_t * p_intf;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment