Serious reworking of the code - AFAICT it works the way it should now.

My first attempt at OT style-compliant code. Axel would be proud. :P


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12757 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2005-05-21 20:31:58 +00:00
parent 980fda2605
commit 1d32aaa939
13 changed files with 1009 additions and 465 deletions
+2 -2
View File
@@ -2,6 +2,6 @@ SubDir OBOS_TOP src prefs scrollbar ;
AddResources ScrollBar : ScrollBar.rdef ; AddResources ScrollBar : ScrollBar.rdef ;
Preference ScrollBar : ScrollBar.cpp ScrollBarApp.cpp ScrollBarWindow.cpp ScrollBarView.cpp ; Preference ScrollBar : ScrollBarApp.cpp ScrollBarWindow.cpp ScrollBarView.cpp knobsizeadjuster.cpp fakescrollbar.cpp ;
LinkSharedOSLibs ScrollBar : be root <boot!home!config!lib>libopenbeos.so ; LinkSharedOSLibs ScrollBar : be root ;
+1 -1
View File
@@ -81,4 +81,4 @@ resource mini_icon array {
$"FFFF00000E0F0F0F0F0000FFFFFFFFFF" $"FFFF00000E0F0F0F0F0000FFFFFFFFFF"
}; };
resource app_signature "application/x-vnd.obos.scroll-bar"; resource app_signature "application/x-vnd.haiku-ScrollBar";
+41 -7
View File
@@ -1,13 +1,40 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: ScrollBarApp.cpp
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: main app class
//
//------------------------------------------------------------------------------
#include "ScrollBarApp.h" #include "ScrollBarApp.h"
#include "ScrollBarWindow.h" #include "ScrollBarWindow.h"
ScrollBarApp * scroll_bar_app = 0; scroll_bar_info gSettings;
scroll_bar_info gRevertSettings;
ScrollBarApp::ScrollBarApp() ScrollBarApp::ScrollBarApp()
: BApplication("application/x-vnd.obos.scroll-bar") : BApplication("application/x-vnd.haiku-ScrollBar")
{ {
window = new ScrollBarWindow(); fWindow = new ScrollBarWindow();
scroll_bar_app = this;
} }
ScrollBarApp::~ScrollBarApp() ScrollBarApp::~ScrollBarApp()
@@ -17,7 +44,14 @@ ScrollBarApp::~ScrollBarApp()
void void
ScrollBarApp::ReadyToRun() ScrollBarApp::ReadyToRun()
{ {
if (window) { fWindow->Show();
window->Show(); }
}
int main(int, char**)
{
ScrollBarApp myApplication;
myApplication.Run();
return 0;
} }
+33 -4
View File
@@ -1,3 +1,30 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: ScrollBarApp.h
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: main app class
//
//------------------------------------------------------------------------------
#ifndef SCROLL_BAR_APP_H #ifndef SCROLL_BAR_APP_H
#define SCROLL_BAR_APP_H #define SCROLL_BAR_APP_H
@@ -7,14 +34,16 @@ class ScrollBarWindow;
class ScrollBarApp : public BApplication class ScrollBarApp : public BApplication
{ {
public: public:
ScrollBarApp(); ScrollBarApp();
virtual ~ScrollBarApp(); virtual ~ScrollBarApp();
virtual void ReadyToRun(); virtual void ReadyToRun();
private:
ScrollBarWindow * window; private:
ScrollBarWindow *fWindow;
}; };
extern ScrollBarApp * scroll_bar_app; extern scroll_bar_info gSettings;
extern scroll_bar_info gRevertSettings;
#endif // SCROLL_BAR_APP_H #endif // SCROLL_BAR_APP_H
+322 -66
View File
@@ -1,95 +1,133 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: ScrollBarView.cpp
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: view which does all the work
//
//------------------------------------------------------------------------------
#include "ScrollBarApp.h"
#include "ScrollBarView.h" #include "ScrollBarView.h"
#include "fakescrollbar.h"
#include "knobsizeadjuster.h"
#include "messages.h" #include "messages.h"
// our own homegrown private cheat function for controlling scrollbars // This is R5's default value
status_t control_scrollbar(scroll_bar_info *info, BScrollBar *sb); #define DEFAULT_KNOB_SIZE 15
ScrollBarView::ScrollBarView(void) ScrollBarView::ScrollBarView(void)
: BView(BRect(0,0,348,280),"scrollbarview", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW) : BView( BRect(0,0,348,280),"scrollbarview", B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW)
{ {
SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) ); SetViewColor( ui_color(B_PANEL_BACKGROUND_COLOR) );
arrowstyleBox = new BBox( BRect( 12, 7, 169, 119) ); get_scroll_bar_info(&gRevertSettings);
gSettings=gRevertSettings;
// Set up the top left box - single vs. double arrow selection
BBox *arrowstyleBox = new BBox( BRect(12, 7, 169, 119) );
arrowstyleBox->SetLabel( "Arrow Style" ); arrowstyleBox->SetLabel( "Arrow Style" );
float doubleWidth = StringWidth("Double:"); float doubleWidth = StringWidth("Double:");
int32 tempint; BStringView *doubleStringView = new BStringView( BRect(25,20,25+doubleWidth,38),
bool tempbool; "doubleStringView","Double:");
scroll_bar_info sbi;
// We're going to need the basics here fDouble=new FakeScrollBar( BPoint(12,38), gSettings.double_arrows, gSettings.knob,
get_scroll_bar_info(&sbi); !gSettings.proportional, true, gSettings.min_knob_size,
new BMessage(SCROLLBAR_ARROW_STYLE_DOUBLE));
// save this for later use arrowstyleBox->AddChild( fDouble );
tempbool=sbi.double_arrows;
doubleStringView = new BStringView( BRect(25,20,25+doubleWidth,38), "doubleStringView", "Double:");
sbdouble=new BScrollBar(BRect(12,38,145,58),"doublearrowsbar",NULL,0,100,B_HORIZONTAL);
arrowstyleBox->AddChild( sbdouble );
sbi.double_arrows=true;
control_scrollbar(&sbi,sbdouble);
float singleWidth = StringWidth("Single:"); float singleWidth = StringWidth("Single:");
singleStringView = new BStringView( BRect(25,60,25+singleWidth,87), "singleStringView", "Single:"); BStringView *singleStringView = new BStringView( BRect(25,60,25+singleWidth,87),
sbsingle=new BScrollBar(BRect(12,82,145,102),"singlearrowsbar",NULL,0,100,B_HORIZONTAL); "singleStringView", "Single:");
arrowstyleBox->AddChild( sbsingle );
sbi.double_arrows=false; fSingle=new FakeScrollBar( BPoint(12,singleStringView->Frame().bottom+1),
control_scrollbar(&sbi,sbsingle); !gSettings.double_arrows, gSettings.knob,
!gSettings.proportional, false, gSettings.min_knob_size,
new BMessage(SCROLLBAR_ARROW_STYLE_SINGLE));
arrowstyleBox->AddChild( fSingle );
// Restore the original value so we don't screw up the other ones BBox *knobtypeBox = new BBox( BRect(180, 7, 338, 119) );
sbi.double_arrows=tempbool;
tempbool=sbi.proportional;
knobtypeBox = new BBox( BRect( 180, 7, 338, 119) );
knobtypeBox->SetLabel( "Knob Type" ); knobtypeBox->SetLabel( "Knob Type" );
float proportionalWidth = StringWidth("Proportional"); float proportionalWidth = StringWidth("Proportional:");
proportionalStringView = new BStringView( BRect(193,20,193+proportionalWidth,38), "proportionalStringView", "Proportional" ); BStringView *proportionalStringView = new BStringView( BRect(193,20,193+proportionalWidth,38),
sbproportional=new BScrollBar(BRect(12,38,145,58),"proportionalbar",NULL,0,100,B_HORIZONTAL); "proportionalStringView",
knobtypeBox->AddChild( sbproportional ); "Proportional:" );
sbi.proportional=true; fProportional=new FakeScrollBar( BPoint(12,38),gSettings.proportional, gSettings.knob,
control_scrollbar(&sbi,sbproportional); false, gSettings.double_arrows, gSettings.min_knob_size,
new BMessage(SCROLLBAR_KNOB_TYPE_PROPORTIONAL));
knobtypeBox->AddChild( fProportional );
float fixedWidth = StringWidth("Fixed"); float fixedWidth = StringWidth("Fixed:");
fixedStringView = new BStringView( BRect(193,60,193+fixedWidth,87), "fixedStringView", "Fixed" ); BStringView *fixedStringView = new BStringView( BRect(193,60,193+fixedWidth,87),
sbfixed=new BScrollBar(BRect(12,87,145,105),"fixedbar",NULL,0,100,B_HORIZONTAL); "fixedStringView", "Fixed:" );
knobtypeBox->AddChild( sbfixed );
sbi.proportional=false; fFixed=new FakeScrollBar( BPoint(12,87),!gSettings.proportional, gSettings.knob,
control_scrollbar(&sbi,sbfixed); true, gSettings.double_arrows, gSettings.min_knob_size,
new BMessage(SCROLLBAR_KNOB_TYPE_FIXED));
knobtypeBox->AddChild( fFixed );
minknobsizeBox = new BBox( BRect( 12, 123, 169, 232) ); BBox *minknobsizeBox = new BBox( BRect(12, 123, 169, 232) );
minknobsizeBox->SetLabel( "Minimum Knob Size" ); minknobsizeBox->SetLabel( "Minimum Knob Size:" );
sbi.proportional=tempbool; fSizeAdjuster = new KnobSizeAdjuster( BPoint(12,38), gSettings.min_knob_size );
minknobsizeBox->AddChild( fSizeAdjuster );
knobstyleBox = new BBox( BRect( 180, 123, 338, 232) ); BBox *knobstyleBox = new BBox( BRect(180, 123, 338, 232) );
knobstyleBox->SetLabel( "Knob Style" ); knobstyleBox->SetLabel( "Knob Style:" );
tempint=sbi.knob; fFlat=new FakeScrollBar( BPoint(12,22),gSettings.knob==THUMB_BLANK, THUMB_BLANK,
sbflat=new BScrollBar(BRect(12,22,145,42),"flatbar",NULL,0,100,B_HORIZONTAL); !gSettings.proportional, gSettings.double_arrows,
knobstyleBox->AddChild( sbflat ); gSettings.min_knob_size,
sbi.knob=0; new BMessage(SCROLLBAR_KNOB_STYLE_FLAT));
control_scrollbar(&sbi,sbflat); knobstyleBox->AddChild( fFlat );
sbdots=new BScrollBar(BRect(12,52,145,72),"dotbar",NULL,0,100,B_HORIZONTAL); fDots=new FakeScrollBar( BPoint(12,52),gSettings.knob==THUMB_DOTS, THUMB_DOTS,
knobstyleBox->AddChild( sbdots ); !gSettings.proportional, gSettings.double_arrows,
sbi.knob=1; gSettings.min_knob_size,
control_scrollbar(&sbi,sbdots); new BMessage(SCROLLBAR_KNOB_STYLE_DOT));
knobstyleBox->AddChild( fDots );
sblines=new BScrollBar(BRect(12,82,145,102),"linebar",NULL,0,100,B_HORIZONTAL); fLines=new FakeScrollBar( BPoint(12,82),gSettings.knob==THUMB_LINES, THUMB_LINES,
knobstyleBox->AddChild( sblines ); !gSettings.proportional, gSettings.double_arrows,
sbi.knob=2; gSettings.min_knob_size,
control_scrollbar(&sbi,sblines); new BMessage(SCROLLBAR_KNOB_STYLE_LINE));
knobstyleBox->AddChild( fLines );
fDefaultsButton = new BButton( BRect(10, 242, 85, 265), "defaultsbutton",
"Defaults", new BMessage(SCROLLBAR_DEFAULTS) );
defaultsButton = new BButton( BRect( 10, 242, 85, 265), "defaultsButton", "Defaults", NULL ); // Disable defaults button if the current settings are already the defaults
revertButton = new BButton( BRect( 95, 242, 170, 265), "revertButton", "Revert", NULL ); if( gSettings.knob==THUMB_DOTS && gSettings.proportional==true &&
revertButton->SetEnabled( FALSE ); gSettings.double_arrows==true && gSettings.min_knob_size==DEFAULT_KNOB_SIZE )
{
fDefaultsButton->SetEnabled(false);
}
fRevertButton = new BButton( BRect( 95, 242, 170, 265), "revertbutton", "Revert",
new BMessage(SCROLLBAR_REVERT) );
fRevertButton->SetEnabled( false );
AddChild( arrowstyleBox ); AddChild( arrowstyleBox );
AddChild( doubleStringView ); AddChild( doubleStringView );
@@ -102,19 +140,237 @@ ScrollBarView::ScrollBarView(void)
AddChild( minknobsizeBox ); AddChild( minknobsizeBox );
AddChild( knobstyleBox ); AddChild( knobstyleBox );
AddChild( defaultsButton ); AddChild( fDefaultsButton );
AddChild( revertButton ); AddChild( fRevertButton );
} }
ScrollBarView::~ScrollBarView(void) ScrollBarView::~ScrollBarView(void)
{ {
} }
void ScrollBarView::MessageReceived(BMessage *msg) void
ScrollBarView::AttachedToWindow(void)
{
fSingle->SetTarget(this);
fDouble->SetTarget(this);
fProportional->SetTarget(this);
fFixed->SetTarget(this);
fFlat->SetTarget(this);
fDots->SetTarget(this);
fLines->SetTarget(this);
fSizeAdjuster->SetTarget(this);
fDefaultsButton->SetTarget(this);
fRevertButton->SetTarget(this);
}
void
ScrollBarView::HandleButtonStates(void)
{
if( gSettings.knob!=gRevertSettings.knob ||
gSettings.proportional!=gRevertSettings.proportional ||
gSettings.double_arrows!=gRevertSettings.double_arrows ||
gSettings.min_knob_size!=gRevertSettings.min_knob_size )
{
fDefaultsButton->SetEnabled(false);
fRevertButton->SetEnabled(true);
}
else
{
fDefaultsButton->SetEnabled(true);
fRevertButton->SetEnabled(false);
}
}
void
ScrollBarView::SetAllScrollBars(void)
{
fSingle->SetFromScrollBarInfo(gSettings);
fDouble->SetFromScrollBarInfo(gSettings);
fProportional->SetFromScrollBarInfo(gSettings);
fFixed->SetFromScrollBarInfo(gSettings);
fFlat->SetFromScrollBarInfo(gSettings);
fDots->SetFromScrollBarInfo(gSettings);
fLines->SetFromScrollBarInfo(gSettings);
fSingle->SetSelected( !gSettings.double_arrows );
fDouble->SetSelected( gSettings.double_arrows );
fProportional->SetSelected( gSettings.proportional );
fFixed->SetSelected( !gSettings.proportional );
fFlat->SetSelected(gSettings.knob==THUMB_BLANK);
fDots->SetSelected(gSettings.knob==THUMB_DOTS);
fLines->SetSelected(gSettings.knob==THUMB_LINES);
}
void
ScrollBarView::MessageReceived(BMessage *msg)
{ {
switch(msg->what) switch(msg->what)
{ {
case SCROLLBAR_DEFAULTS:
{
gSettings.double_arrows=true;
gSettings.proportional=true;
gSettings.knob=THUMB_DOTS;
gSettings.min_knob_size=DEFAULT_KNOB_SIZE;
SetAllScrollBars();
HandleButtonStates();
break;
}
case SCROLLBAR_REVERT:
{
gSettings=gRevertSettings;
fSingle->SetFromScrollBarInfo(gSettings);
fDouble->SetFromScrollBarInfo(gSettings);
fProportional->SetFromScrollBarInfo(gSettings);
fFixed->SetFromScrollBarInfo(gSettings);
fFlat->SetFromScrollBarInfo(gSettings);
fDots->SetFromScrollBarInfo(gSettings);
fLines->SetFromScrollBarInfo(gSettings);
SetAllScrollBars();
HandleButtonStates();
break;
}
case SCROLLBAR_ARROW_STYLE_DOUBLE:
{
fDouble->SetSelected(true);
fSingle->SetSelected(false);
fFixed->SetDoubleArrows(true);
fProportional->SetDoubleArrows(true);
fFlat->SetDoubleArrows(true);
fDots->SetDoubleArrows(true);
fLines->SetDoubleArrows(true);
gSettings.double_arrows=true;
HandleButtonStates();
break;
}
case SCROLLBAR_ARROW_STYLE_SINGLE:
{
fDouble->SetSelected(false);
fSingle->SetSelected(true);
fFixed->SetDoubleArrows(false);
fProportional->SetDoubleArrows(false);
fFlat->SetDoubleArrows(false);
fDots->SetDoubleArrows(false);
fLines->SetDoubleArrows(false);
gSettings.double_arrows=false;
HandleButtonStates();
break;
}
case SCROLLBAR_KNOB_TYPE_PROPORTIONAL:
{
fDouble->SetFixedThumb(false);
fSingle->SetFixedThumb(false);
fFixed->SetSelected(false);
fProportional->SetSelected(true);
fFlat->SetFixedThumb(false);
fDots->SetFixedThumb(false);
fLines->SetFixedThumb(false);
gSettings.proportional=true;
HandleButtonStates();
break;
}
case SCROLLBAR_KNOB_TYPE_FIXED:
{
fDouble->SetFixedThumb(true);
fSingle->SetFixedThumb(true);
fFixed->SetSelected(true);
fProportional->SetSelected(false);
fFlat->SetFixedThumb(true);
fDots->SetFixedThumb(true);
fLines->SetFixedThumb(true);
gSettings.proportional=false;
HandleButtonStates();
break;
}
case SCROLLBAR_KNOB_STYLE_FLAT:
{
fDouble->SetKnobStyle(THUMB_BLANK);
fSingle->SetKnobStyle(THUMB_BLANK);
fFixed->SetKnobStyle(THUMB_BLANK);
fProportional->SetKnobStyle(THUMB_BLANK);
fFlat->SetSelected(true);
fDots->SetSelected(false);
fLines->SetSelected(false);
gSettings.knob=THUMB_BLANK;
HandleButtonStates();
break;
}
case SCROLLBAR_KNOB_STYLE_DOT:
{
fDouble->SetKnobStyle(THUMB_DOTS);
fSingle->SetKnobStyle(THUMB_DOTS);
fFixed->SetKnobStyle(THUMB_DOTS);
fProportional->SetKnobStyle(THUMB_DOTS);
fFlat->SetSelected(false);
fDots->SetSelected(true);
fLines->SetSelected(false);
gSettings.knob=THUMB_DOTS;
HandleButtonStates();
break;
}
case SCROLLBAR_KNOB_STYLE_LINE:
{
fDouble->SetKnobStyle(THUMB_LINES);
fSingle->SetKnobStyle(THUMB_LINES);
fFixed->SetKnobStyle(THUMB_LINES);
fProportional->SetKnobStyle(THUMB_LINES);
fFlat->SetSelected(false);
fDots->SetSelected(false);
fLines->SetSelected(true);
gSettings.knob=THUMB_LINES;
HandleButtonStates();
break;
}
case SCROLLBAR_KNOB_SIZE_CHANGED:
{
fDouble->SetKnobSize(fSizeAdjuster->KnobSize());
fSingle->SetKnobSize(fSizeAdjuster->KnobSize());
fFixed->SetKnobSize(fSizeAdjuster->KnobSize());
fProportional->SetKnobSize(fSizeAdjuster->KnobSize());
fFlat->SetKnobSize(fSizeAdjuster->KnobSize());
fDots->SetKnobSize(fSizeAdjuster->KnobSize());
fLines->SetKnobSize(fSizeAdjuster->KnobSize());
gSettings.min_knob_size=fSizeAdjuster->KnobSize();
HandleButtonStates();
break;
}
default: default:
BView::MessageReceived(msg);
break; break;
} }
} }
+46 -6
View File
@@ -1,3 +1,30 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: ScrollBarView.cpp
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: view which does all the work
//
//------------------------------------------------------------------------------
#ifndef SCROLLBAR_VIEW #ifndef SCROLLBAR_VIEW
#define SCROLLBAR_VIEW #define SCROLLBAR_VIEW
@@ -7,6 +34,8 @@
#include <Button.h> #include <Button.h>
#include <ScrollBar.h> #include <ScrollBar.h>
class FakeScrollBar;
class KnobSizeAdjuster;
class ScrollBarView : public BView class ScrollBarView : public BView
{ {
@@ -14,14 +43,25 @@ public:
ScrollBarView(void); ScrollBarView(void);
~ScrollBarView(void); ~ScrollBarView(void);
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
void AttachedToWindow(void);
BBox *arrowstyleBox, *knobtypeBox, *knobstyleBox, *minknobsizeBox; private:
BStringView *singleStringView,*doubleStringView, *proportionalStringView,
*fixedStringView;
BButton *defaultsButton, *revertButton;
BScrollBar *sbsingle, *sbdouble, *sbproportional, *sbfixed, void HandleButtonStates(void);
*sbflat, *sbdots, *sblines; void SetAllScrollBars(void);
BButton *fDefaultsButton;
BButton *fRevertButton;
KnobSizeAdjuster *fSizeAdjuster;
FakeScrollBar *fSingle;
FakeScrollBar *fDouble;
FakeScrollBar *fProportional;
FakeScrollBar *fFixed;
FakeScrollBar *fFlat;
FakeScrollBar *fDots;
FakeScrollBar *fLines;
}; };
#endif #endif
+35 -4
View File
@@ -1,17 +1,46 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: ScrollBarWindow.cpp
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: Container window class
//
//------------------------------------------------------------------------------
#include <Application.h>
#include <Window.h> #include <Window.h>
#include <View.h> #include <View.h>
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <StringView.h> #include <StringView.h>
#include "ScrollBarWindow.h" #include "ScrollBarWindow.h"
#include "ScrollBarApp.h" #include "ScrollBarApp.h"
#include "ScrollBarView.h" #include "ScrollBarView.h"
ScrollBarWindow::ScrollBarWindow(void) ScrollBarWindow::ScrollBarWindow(void)
: BWindow( BRect(50,50,398,325), "Scroll Bar", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE ) : BWindow( BRect(50,50,398,325), "Scroll Bar", B_TITLED_WINDOW, B_NOT_RESIZABLE |
B_NOT_ZOOMABLE )
{ {
sbview=new ScrollBarView; AddChild(new ScrollBarView);
AddChild(sbview);
} }
ScrollBarWindow::~ScrollBarWindow(void) ScrollBarWindow::~ScrollBarWindow(void)
@@ -21,6 +50,8 @@ ScrollBarWindow::~ScrollBarWindow(void)
bool bool
ScrollBarWindow::QuitRequested(void) ScrollBarWindow::QuitRequested(void)
{ {
scroll_bar_app->PostMessage(B_QUIT_REQUESTED); set_scroll_bar_info(&gSettings);
be_app->PostMessage(B_QUIT_REQUESTED);
return true; return true;
} }
+29 -3
View File
@@ -1,3 +1,30 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: ScrollBarWindow.h
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: Container window class
//
//------------------------------------------------------------------------------
#ifndef SCROLL_BAR_WINDOW_H #ifndef SCROLL_BAR_WINDOW_H
#define SCROLL_BAR_WINDOW_H #define SCROLL_BAR_WINDOW_H
@@ -5,13 +32,12 @@
class ScrollBarView; class ScrollBarView;
class ScrollBarWindow : public BWindow { class ScrollBarWindow : public BWindow
{
public: public:
ScrollBarWindow(void); ScrollBarWindow(void);
virtual ~ScrollBarWindow(void); virtual ~ScrollBarWindow(void);
virtual bool QuitRequested(void); virtual bool QuitRequested(void);
ScrollBarView *sbview;
}; };
#endif // SCROLL_BAR_WINDOW_H #endif // SCROLL_BAR_WINDOW_H
+228 -250
View File
@@ -1,307 +1,258 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: fakescrollbar.cpp
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: Control to simulate a scrollbar
//
//------------------------------------------------------------------------------
#include "scrollbar.h" #include "scrollbar.h"
#include "fakescrollbar.h" #include "fakescrollbar.h"
#include "messages.h" #include "messages.h"
FakeScrollBar::FakeScrollBar( BPoint position, bool selected, FakeScrollBar::FakeScrollBar( BPoint position, bool selected, int32 knobstyle,
uint32 style, uint32 type, uint32 arrow, uint32 size, BMessage *message ): bool fixedthumb, bool doublearrow, int32 size, BMessage *message )
BView( BRect( position.x, position.y, position.x+132,
position.y+20 ), "FakeScrollBar", B_FOLLOW_LEFT |
B_FOLLOW_TOP, B_WILL_DRAW )
{
Selected=selected;
Pressed=false;
ArrowStyle=arrow;
KnobType=type;
KnobStyle=style;
KnobSize=size;
Message=message; : BControl( BRect(position.x, position.y, position.x+132, position.y+20), "FakeScrollBar", NULL,
message, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE)
{
fIsSelected=selected;
fIsPressed=false;
fDoubleArrows=doublearrow;
fFixedThumb=fixedthumb;
fKnobStyle=knobstyle;
fMinKnobSize=size;
} }
void FakeScrollBar::DrawArrowBox( uint32 x, bool facingleft ) FakeScrollBar::~FakeScrollBar(void)
{
}
void
FakeScrollBar::DrawArrowBox( uint32 x, bool facingleft )
{ {
// draw box // draw box
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
FillRect( BRect( x, Bounds().top+3, FillRect( BRect(x, Bounds().top+3, x+16, Bounds().bottom-3), B_SOLID_HIGH );
x+16, Bounds().bottom-3 ), B_SOLID_HIGH );
SetHighColor( 152, 152, 152 ); SetHighColor( 152, 152, 152 );
StrokeRect( BRect( x, Bounds().top+3, x+16, StrokeRect( BRect(x, Bounds().top+3, x+16, Bounds().bottom-3 ) , B_SOLID_HIGH );
Bounds().bottom-3 ) , B_SOLID_HIGH );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x+1, Bounds().top+4 ), StrokeLine( BPoint(x+1, Bounds().top+4), BPoint(x+15, Bounds().top+4), B_SOLID_HIGH );
BPoint( x+15, Bounds().top+4 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+1, Bounds().top+4), BPoint(x+1, Bounds().bottom-4), B_SOLID_HIGH );
StrokeLine( BPoint( x+1, Bounds().top+4 ),
BPoint( x+1, Bounds().bottom-4 ), B_SOLID_HIGH );
SetHighColor( 192, 192, 192 ); SetHighColor( 192, 192, 192 );
StrokeLine( BPoint( x+15, Bounds().bottom-4 ), StrokeLine( BPoint(x+15, Bounds().bottom-4), BPoint(x+15, Bounds().top+4), B_SOLID_HIGH );
BPoint( x+15, Bounds().top+4 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+15, Bounds().bottom-4), BPoint(x+1, Bounds().bottom-4), B_SOLID_HIGH );
StrokeLine( BPoint( x+15, Bounds().bottom-4 ),
BPoint( x+1, Bounds().bottom-4 ), B_SOLID_HIGH );
if ( facingleft == true ) if ( facingleft )
{ {
// draw arrow // draw arrow
SetHighColor( 112, 112, 112 ); SetHighColor( 112, 112, 112 );
StrokeLine( BPoint( x+4, Bounds().top+10 ), StrokeLine( BPoint(x+4, Bounds().top+10), BPoint(x+11, Bounds().top+7), B_SOLID_HIGH );
BPoint( x+11, Bounds().top+7 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+4, Bounds().top+10), BPoint(x+11, Bounds().bottom-7), B_SOLID_HIGH );
StrokeLine( BPoint( x+4, Bounds().top+10 ), StrokeLine( BPoint(x+11, Bounds().top+7), BPoint(x+11, Bounds().bottom-7), B_SOLID_HIGH );
BPoint( x+11, Bounds().bottom-7 ), B_SOLID_HIGH );
StrokeLine( BPoint( x+11, Bounds().top+7 ),
BPoint( x+11, Bounds().bottom-7 ), B_SOLID_HIGH );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x+4, Bounds().top+11 ), StrokeLine( BPoint(x+4, Bounds().top+11), BPoint(x+11, Bounds().bottom-6), B_SOLID_HIGH );
BPoint( x+11, Bounds().bottom-6 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+12, Bounds().top+7), BPoint(x+12, Bounds().bottom-6), B_SOLID_HIGH );
StrokeLine( BPoint( x+12, Bounds().top+7 ),
BPoint( x+12, Bounds().bottom-6 ), B_SOLID_HIGH );
SetHighColor( 192, 192, 192 ); SetHighColor( 192, 192, 192 );
StrokeLine( BPoint( x+4, Bounds().top+9 ), StrokeLine( BPoint(x+4, Bounds().top+9), BPoint(x+11, Bounds().top+6), B_SOLID_HIGH );
BPoint( x+11, Bounds().top+6 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+3, Bounds().top+10), BPoint(x+3, Bounds().top+10), B_SOLID_HIGH );
StrokeLine( BPoint( x+3, Bounds().top+10 ), StrokeLine( BPoint(x+12, Bounds().top+6), BPoint(x+12, Bounds().top+6), B_SOLID_HIGH );
BPoint( x+3, Bounds().top+10 ), B_SOLID_HIGH );
StrokeLine( BPoint( x+12, Bounds().top+6 ),
BPoint( x+12, Bounds().top+6 ), B_SOLID_HIGH );
} }
else else
{ {
// draw arrow // draw arrow
SetHighColor( 112, 112, 112 ); SetHighColor( 112, 112, 112 );
StrokeLine( BPoint( x+12, Bounds().top+10 ), StrokeLine( BPoint(x+12, Bounds().top+10), BPoint(x+5, Bounds().top+7), B_SOLID_HIGH );
BPoint( x+5, Bounds().top+7 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+12, Bounds().top+10), BPoint(x+5, Bounds().bottom-7), B_SOLID_HIGH );
StrokeLine( BPoint( x+12, Bounds().top+10 ), StrokeLine( BPoint(x+5, Bounds().top+7), BPoint(x+5, Bounds().bottom-7), B_SOLID_HIGH );
BPoint( x+5, Bounds().bottom-7 ), B_SOLID_HIGH );
StrokeLine( BPoint( x+5, Bounds().top+7 ),
BPoint( x+5, Bounds().bottom-7 ), B_SOLID_HIGH );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x+12, Bounds().top+11 ), StrokeLine( BPoint(x+12, Bounds().top+11), BPoint(x+5, Bounds().bottom-6), B_SOLID_HIGH );
BPoint( x+5, Bounds().bottom-6 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+4, Bounds().top+7), BPoint(x+4, Bounds().bottom-6), B_SOLID_HIGH );
StrokeLine( BPoint( x+4, Bounds().top+7 ),
BPoint( x+4, Bounds().bottom-6 ), B_SOLID_HIGH );
SetHighColor( 192, 192, 192 ); SetHighColor( 192, 192, 192 );
StrokeLine( BPoint( x+12, Bounds().top+9 ), StrokeLine( BPoint(x+12, Bounds().top+9), BPoint(x+5, Bounds().top+6), B_SOLID_HIGH );
BPoint( x+5, Bounds().top+6 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+13, Bounds().top+10), BPoint(x+13, Bounds().top+10), B_SOLID_HIGH );
StrokeLine( BPoint( x+13, Bounds().top+10 ), StrokeLine( BPoint(x+4, Bounds().top+6), BPoint(x+4, Bounds().top+6), B_SOLID_HIGH );
BPoint( x+13, Bounds().top+10 ), B_SOLID_HIGH );
StrokeLine( BPoint( x+4, Bounds().top+6 ),
BPoint( x+4, Bounds().top+6 ), B_SOLID_HIGH );
} }
} }
void FakeScrollBar::Draw( BRect updateRect ) void
FakeScrollBar::Draw( BRect updateRect )
{ {
SetViewColor( 216, 216, 216 ); SetViewColor( 216, 216, 216 );
// Draw border.
if ( Selected == true ) // Draw border
if ( fIsSelected )
SetHighColor( 0, 0, 0 ); SetHighColor( 0, 0, 0 );
else if ( Pressed == true ) else if ( fIsPressed )
SetHighColor( 128, 128, 128 ); SetHighColor( 128, 128, 128 );
else else
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
SetPenSize( 2 ); SetPenSize( 2 );
StrokeRect( BRect( Bounds().left, Bounds().top, StrokeRect( BRect(Bounds().left, Bounds().top, Bounds().right-1, Bounds().bottom-1) );
Bounds().right-1, Bounds().bottom-1 ), B_SOLID_HIGH );
SetPenSize( 1 ); SetPenSize( 1 );
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
FillRect( BRect( Bounds().left+2, Bounds().top+2,
Bounds().right-2, Bounds().bottom-2 ), B_SOLID_HIGH ); FillRect( BRect(Bounds().left+2, Bounds().top+2, Bounds().right-2, Bounds().bottom-2) );
// Draw first arrows // Draw first arrows
if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_SINGLE )
{
DrawArrowBox( 3, true ); DrawArrowBox( 3, true );
DrawArrowBox( 113, false ); DrawArrowBox( 113, false );
}
// If double arrows, draw another set. // If double arrows, draw another set.
if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_DOUBLE ) if ( fDoubleArrows )
{ {
DrawArrowBox( 3, true );
DrawArrowBox( 113, false );
DrawArrowBox( 19, false ); DrawArrowBox( 19, false );
DrawArrowBox( 97, true ); DrawArrowBox( 97, true );
} }
// Draw back // Draw back
if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_DOUBLE ) if ( fDoubleArrows )
{ {
SetHighColor( 200, 200, 200 ); SetHighColor( 200, 200, 200 );
FillRect( BRect( 36, 3, 96, 15 ), B_SOLID_HIGH ); FillRect( BRect(36, 3, 96, 15) );
SetHighColor( 152, 152, 152 ); SetHighColor( 152, 152, 152 );
StrokeLine( BPoint( 36, 3 ), BPoint( 96, 3 ), B_SOLID_HIGH ); StrokeLine( BPoint(36, 3), BPoint(96, 3) );
StrokeLine( BPoint( 36, 17 ), BPoint( 96, 17 ), B_SOLID_HIGH ); StrokeLine( BPoint(36, 17), BPoint(96, 17) );
SetHighColor( 216, 216, 216 );
StrokeLine( BPoint( 36, 16 ), BPoint( 96, 16 ), B_SOLID_HIGH );
SetHighColor( 184, 184, 184 );
FillRect( BRect( 36, 4, 37, 15 ), B_SOLID_HIGH );
FillRect( BRect( 36, 4, 96, 5 ), B_SOLID_HIGH );
}
else if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_SINGLE )
{
SetHighColor( 200, 200, 200 );
FillRect( BRect( 20, 3, 112, 15 ), B_SOLID_HIGH );
SetHighColor( 152, 152, 152 );
StrokeLine( BPoint( 20, 3 ), BPoint( 112, 3 ), B_SOLID_HIGH );
StrokeLine( BPoint( 20, 17 ), BPoint( 112, 17 ), B_SOLID_HIGH );
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
StrokeLine( BPoint( 20, 16 ), BPoint( 112, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(36, 16), BPoint(96, 16) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
FillRect( BRect( 20, 4, 21, 15 ), B_SOLID_HIGH ); FillRect( BRect(36, 4, 37, 15) );
FillRect( BRect( 20, 4, 112, 5 ), B_SOLID_HIGH ); FillRect( BRect(36, 4, 96, 5) );
} }
else else
{ {
SetHighColor( 152, 152, 152 );
StrokeLine( BPoint( 4, 3 ), BPoint( Bounds().right-5, 3 ), B_SOLID_HIGH );
StrokeLine( BPoint( 4, 17 ), BPoint( Bounds().right-5, 17 ), B_SOLID_HIGH );
SetHighColor( 184, 184, 184 );
FillRect( BRect( 4, 4, Bounds().right-5, 5 ), B_SOLID_HIGH );
SetHighColor( 200, 200, 200 ); SetHighColor( 200, 200, 200 );
FillRect( BRect( 4, 6, Bounds().right-5, 15), B_SOLID_HIGH ); FillRect( BRect(20, 3, 112, 15) );
StrokeLine( BPoint( 3, 15 ), BPoint( 3, 13 ), B_SOLID_HIGH );
StrokeLine( BPoint( Bounds().right-4, 7 ), BPoint( Bounds().right-4, 11 ), B_SOLID_HIGH ); SetHighColor( 152, 152, 152 );
StrokeLine( BPoint( Bounds().right-3, 9 ), BPoint( Bounds().right-3, 9 ), B_SOLID_HIGH ); StrokeLine( BPoint(20, 3), BPoint(112, 3) );
StrokeLine( BPoint(20, 17), BPoint(112, 17) );
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
StrokeLine( BPoint( 4, 7 ), BPoint( 4, 11 ), B_SOLID_HIGH ); StrokeLine( BPoint(20, 16), BPoint(112, 16) );
StrokeLine( BPoint( 5, 9 ), BPoint( 5, 9 ), B_SOLID_HIGH );
StrokeLine( BPoint( Bounds().right-5, 15 ), BPoint( Bounds().right-5, 13 ), B_SOLID_HIGH ); SetHighColor( 184, 184, 184 );
FillRect( BRect(20, 4, 21, 15) );
FillRect( BRect(20, 4, 112, 5) );
} }
// Draw knob // Draw knob
if ( KnobType == SCROLLBAR_KNOB_TYPE_PROPORTIONAL ) if ( fFixedThumb )
{
if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_DOUBLE )
{ {
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
FillRect( BRect( 44, 3, 88, 17 ), B_SOLID_HIGH ); FillRect( BRect((Bounds().right/2)-(fMinKnobSize/2), 3,
(Bounds().right/2)+(fMinKnobSize/2), 17) );
SetHighColor( 152, 152, 152 ); SetHighColor( 152, 152, 152 );
StrokeRect( BRect( 44, 3, 88, 17 ), B_SOLID_HIGH ); StrokeRect( BRect((Bounds().right/2)-(fMinKnobSize/2), 3,
(Bounds().right/2)+(fMinKnobSize/2), 17) );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( 45, 4 ), BPoint( 87, 4 ), B_SOLID_HIGH ); StrokeLine( BPoint((Bounds().right/2)-(fMinKnobSize/2)+1, 4),
StrokeLine( BPoint( 45, 4 ), BPoint( 45, 16 ), B_SOLID_HIGH ); BPoint((Bounds().right/2)+(fMinKnobSize/2)-1, 4) );
StrokeLine( BPoint((Bounds().right/2)-(fMinKnobSize/2)+1, 4),
BPoint((Bounds().right/2)-(fMinKnobSize/2)+1, 16) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( 45, 16 ), BPoint( 87, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint((Bounds().right/2)-(fMinKnobSize/2)+1, 16),
StrokeLine( BPoint( 87, 16 ), BPoint( 87, 4 ), B_SOLID_HIGH ); BPoint((Bounds().right/2)+(fMinKnobSize/2)-1, 16) );
StrokeLine( BPoint((Bounds().right/2)+(fMinKnobSize/2)-1, 16),
BPoint((Bounds().right/2)+(fMinKnobSize/2)-1, 4) );
SetHighColor( 96, 96, 96 ); SetHighColor( 96, 96, 96 );
StrokeLine( BPoint( 88, 4 ), BPoint( 88, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint((Bounds().right/2)+(fMinKnobSize/2), 4),
BPoint((Bounds().right/2)+(fMinKnobSize/2), 16) );
} }
else if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_SINGLE ) else
{
if ( fDoubleArrows )
{ {
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
FillRect( BRect( 32, 3, 100, 17 ), B_SOLID_HIGH ); FillRect( BRect(44, 3, 88, 17) );
SetHighColor( 152, 152, 152 ); SetHighColor( 152, 152, 152 );
StrokeRect( BRect( 32, 3, 100, 17 ), B_SOLID_HIGH ); StrokeRect( BRect(44, 3, 88, 17) );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( 33, 4 ), BPoint( 99, 4 ), B_SOLID_HIGH ); StrokeLine( BPoint(45, 4), BPoint(87, 4) );
StrokeLine( BPoint( 33, 4 ), BPoint( 33, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(45, 4), BPoint(45, 16) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( 33, 16 ), BPoint( 99, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(45, 16), BPoint(87, 16) );
StrokeLine( BPoint( 99, 16 ), BPoint( 99, 4 ), B_SOLID_HIGH ); StrokeLine( BPoint(87, 16), BPoint(87, 4) );
SetHighColor( 96, 96, 96 ); SetHighColor( 96, 96, 96 );
StrokeLine( BPoint( 100, 4 ), BPoint( 100, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(88, 4), BPoint(88, 16) );
} }
else else
{ {
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
FillRect( BRect( 13, 3, 119, 17 ), B_SOLID_HIGH ); FillRect( BRect(32, 3, 100, 17) );
SetHighColor( 152, 152, 152 ); SetHighColor( 152, 152, 152 );
StrokeRect( BRect( 13, 3, 119, 17 ), B_SOLID_HIGH ); StrokeRect( BRect(32, 3, 100, 17) );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( 14, 4 ), BPoint( 118, 4 ), B_SOLID_HIGH ); StrokeLine( BPoint(33, 4), BPoint(99, 4) );
StrokeLine( BPoint( 14, 4 ), BPoint( 14, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(33, 4), BPoint(33, 16) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( 14, 16 ), BPoint( 118, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(33, 16), BPoint(99, 16) );
StrokeLine( BPoint( 118, 16 ), BPoint( 118, 4 ), B_SOLID_HIGH ); StrokeLine( BPoint(99, 16), BPoint(99, 4) );
SetHighColor( 96, 96, 96 ); SetHighColor( 96, 96, 96 );
StrokeLine( BPoint( 119, 4 ), BPoint( 119, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(100, 4), BPoint(100, 16) );
}
}
else
{
if ( ArrowStyle == SCROLLBAR_ARROW_STYLE_NONE )
{
SetHighColor( 216, 216, 216 );
FillRect( BRect( 13, 3, 119, 17 ), B_SOLID_HIGH );
SetHighColor( 152, 152, 152 );
StrokeRect( BRect( 13, 3, 119, 17 ), B_SOLID_HIGH );
SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( 14, 4 ), BPoint( 118, 4 ), B_SOLID_HIGH );
StrokeLine( BPoint( 14, 4 ), BPoint( 14, 16 ), B_SOLID_HIGH );
SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( 14, 16 ), BPoint( 118, 16 ), B_SOLID_HIGH );
StrokeLine( BPoint( 118, 16 ), BPoint( 118, 4 ), B_SOLID_HIGH );
SetHighColor( 96, 96, 96 );
StrokeLine( BPoint( 119, 4 ), BPoint( 119, 16 ), B_SOLID_HIGH );
}
else
{
SetHighColor( 216, 216, 216 );
FillRect( BRect( (Bounds().right/2)-(KnobSize/2), 3,
(Bounds().right/2)+(KnobSize/2), 17 ), B_SOLID_HIGH );
SetHighColor( 152, 152, 152 );
StrokeRect( BRect( (Bounds().right/2)-(KnobSize/2), 3,
(Bounds().right/2)+(KnobSize/2), 17 ), B_SOLID_HIGH );
SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( (Bounds().right/2)-(KnobSize/2)+1, 4 ),
BPoint( (Bounds().right/2)+(KnobSize/2)-1, 4 ), B_SOLID_HIGH );
StrokeLine( BPoint( (Bounds().right/2)-(KnobSize/2)+1, 4 ),
BPoint( (Bounds().right/2)-(KnobSize/2)+1, 16 ), B_SOLID_HIGH );
SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( (Bounds().right/2)-(KnobSize/2)+1, 16 ),
BPoint( (Bounds().right/2)+(KnobSize/2)-1, 16 ), B_SOLID_HIGH );
StrokeLine( BPoint( (Bounds().right/2)+(KnobSize/2)-1, 16 ),
BPoint( (Bounds().right/2)+(KnobSize/2)-1, 4 ), B_SOLID_HIGH );
SetHighColor( 96, 96, 96 );
StrokeLine( BPoint( (Bounds().right/2)+(KnobSize/2), 4 ),
BPoint( (Bounds().right/2)+(KnobSize/2), 16 ), B_SOLID_HIGH );
} }
} }
// Draw knob grabber // Draw knob grabber
if ( KnobStyle == SCROLLBAR_KNOB_STYLE_DOT ) if ( fKnobStyle == THUMB_DOTS )
{ {
if ( KnobType == SCROLLBAR_KNOB_TYPE_PROPORTIONAL || if( fFixedThumb )
ArrowStyle == SCROLLBAR_ARROW_STYLE_NONE ) DrawDotGrabber( Bounds().right/2, fMinKnobSize );
else
DrawDotGrabber( Bounds().right/2, 100 ); DrawDotGrabber( Bounds().right/2, 100 );
else
DrawDotGrabber( Bounds().right/2, KnobSize );
} }
else if ( KnobStyle == SCROLLBAR_KNOB_STYLE_LINE ) else if ( fKnobStyle == THUMB_LINES )
{ {
if ( KnobType == SCROLLBAR_KNOB_TYPE_PROPORTIONAL || if ( fFixedThumb )
ArrowStyle == SCROLLBAR_ARROW_STYLE_NONE ) DrawLineGrabber( Bounds().right/2, fMinKnobSize );
DrawLineGrabber( Bounds().right/2, 100 );
else else
DrawLineGrabber( Bounds().right/2, KnobSize ); DrawLineGrabber( Bounds().right/2, 100 );
} }
} }
void FakeScrollBar::DrawLineGrabber( uint32 x, uint32 size ) void
FakeScrollBar::DrawLineGrabber( uint32 x, uint32 size )
{ {
if ( size < 12 ) if ( size < 12 )
{ {
@@ -310,39 +261,40 @@ void FakeScrollBar::DrawLineGrabber( uint32 x, uint32 size )
else if ( size < 22 ) else if ( size < 22 )
{ {
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x-1, 7 ), BPoint( x+1, 7 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-1, 7), BPoint(x+1, 7) );
StrokeLine( BPoint( x-1, 7 ), BPoint( x-1, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-1, 7), BPoint(x-1, 13) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( x+1, 7 ), BPoint( x+1, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+1, 7), BPoint(x+1, 13) );
StrokeLine( BPoint( x+1, 13 ), BPoint( x-1, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+1, 13), BPoint(x-1, 13) );
} }
else else
{ {
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x-1, 7 ), BPoint( x+1, 7 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-1, 7), BPoint(x+1, 7) );
StrokeLine( BPoint( x-1, 7 ), BPoint( x-1, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-1, 7), BPoint(x-1, 13) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( x+1, 7 ), BPoint( x+1, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+1, 7), BPoint(x+1, 13) );
StrokeLine( BPoint( x+1, 13 ), BPoint( x-1, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+1, 13), BPoint(x-1, 13) );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x-5, 7 ), BPoint( x-3, 7 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-5, 7), BPoint(x-3, 7) );
StrokeLine( BPoint( x-5, 7 ), BPoint( x-5, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-5, 7), BPoint(x-5, 13) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( x-3, 7 ), BPoint( x-3, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-3, 7), BPoint(x-3, 13) );
StrokeLine( BPoint( x-3, 13 ), BPoint( x-5, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-3, 13), BPoint(x-5, 13) );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x+3, 7 ), BPoint( x+5, 7 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+3, 7), BPoint(x+5, 7) );
StrokeLine( BPoint( x+3, 7 ), BPoint( x+3, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+3, 7), BPoint(x+3, 13) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( x+5, 7 ), BPoint( x+5, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+5, 7), BPoint(x+5, 13) );
StrokeLine( BPoint( x+5, 13 ), BPoint( x+3, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+5, 13), BPoint(x+3, 13) );
} }
} }
void FakeScrollBar::DrawDotGrabber( uint32 x, uint32 size ) void
FakeScrollBar::DrawDotGrabber( uint32 x, uint32 size )
{ {
if ( size < 14 ) if ( size < 14 )
{ {
@@ -351,100 +303,124 @@ void FakeScrollBar::DrawDotGrabber( uint32 x, uint32 size )
else if ( size < 27 ) else if ( size < 27 )
{ {
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x-2, 8 ), BPoint( x+2, 8 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-2, 8), BPoint(x+2, 8) );
StrokeLine( BPoint( x-2, 8 ), BPoint( x-2, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-2, 8), BPoint(x-2, 12) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( x+2, 8 ), BPoint( x+2, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+2, 8), BPoint(x+2, 12) );
StrokeLine( BPoint( x+2, 12 ), BPoint( x-2, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+2, 12), BPoint(x-2, 12) );
} }
else else
{ {
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x-2, 8 ), BPoint( x+2, 8 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-2, 8), BPoint(x+2, 8) );
StrokeLine( BPoint( x-2, 8 ), BPoint( x-2, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-2, 8), BPoint(x-2, 12) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( x+2, 8 ), BPoint( x+2, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+2, 8), BPoint(x+2, 12) );
StrokeLine( BPoint( x+2, 12 ), BPoint( x-2, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+2, 12), BPoint(x-2, 12) );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x-9, 8 ), BPoint( x-5, 8 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-9, 8), BPoint(x-5, 8) );
StrokeLine( BPoint( x-9, 8 ), BPoint( x-9, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-9, 8), BPoint(x-9, 12) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( x-5, 8 ), BPoint( x-5, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-5, 8), BPoint(x-5, 12) );
StrokeLine( BPoint( x-5, 12 ), BPoint( x-9, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x-5, 12), BPoint(x-9, 12) );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( x+5, 8 ), BPoint( x+9, 8 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+5, 8), BPoint(x+9, 8) );
StrokeLine( BPoint( x+5, 8 ), BPoint( x+5, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+5, 8), BPoint(x+5, 12) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( x+9, 8 ), BPoint( x+9, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+9, 8), BPoint(x+9, 12) );
StrokeLine( BPoint( x+9, 12 ), BPoint( x+5, 12 ), B_SOLID_HIGH ); StrokeLine( BPoint(x+9, 12), BPoint(x+5, 12) );
} }
} }
void FakeScrollBar::MouseDown( BPoint point ) void
FakeScrollBar::MouseDown( BPoint point )
{ {
SetTracking( true ); SetTracking( true );
} }
void FakeScrollBar::MouseUp( BPoint point ) void
FakeScrollBar::MouseUp( BPoint point )
{ {
if ( IsPressed() == true ) if ( IsPressed() )
be_app->PostMessage( Message ); Invoke();
SetTracking( false ); SetTracking( false );
} }
void FakeScrollBar::MouseMoved( BPoint point, uint32 transit, const BMessage *message ) void
FakeScrollBar::MouseMoved( BPoint point, uint32 transit, const BMessage *message )
{ {
if ( transit == B_ENTERED_VIEW && IsTracking() == true ) if ( transit == B_ENTERED_VIEW && IsTracking() )
SetPressed( true ); SetPressed( true );
if ( transit == B_EXITED_VIEW && IsTracking() == true )
if ( transit == B_EXITED_VIEW && IsTracking() )
SetPressed( false ); SetPressed( false );
} }
void FakeScrollBar::SetKnobStyle( uint32 style ) void
FakeScrollBar::SetDoubleArrows( bool doublearrows )
{ {
KnobStyle=style; fDoubleArrows = doublearrows;
Invalidate(); Invalidate();
} }
void FakeScrollBar::SetKnobType( uint32 type ) void
FakeScrollBar::SetFixedThumb( bool fixed )
{ {
KnobType=type; fFixedThumb = fixed;
Invalidate(); Invalidate();
} }
void FakeScrollBar::SetArrowStyle( uint32 arrow ) void
FakeScrollBar::SetKnobStyle( uint32 style )
{ {
ArrowStyle=arrow; fKnobStyle=style;
Invalidate(); Invalidate();
} }
void FakeScrollBar::SetKnobSize( uint32 size ) void
FakeScrollBar::SetKnobSize( int32 size )
{ {
KnobSize=size; fMinKnobSize=size;
Invalidate(); Invalidate();
} }
void FakeScrollBar::SetSelected( bool selected ) void
FakeScrollBar::SetFromScrollBarInfo(const scroll_bar_info &info)
{ {
Selected=selected; fDoubleArrows=info.double_arrows;
fFixedThumb=!info.proportional;
fMinKnobSize=info.min_knob_size;
fKnobStyle=info.knob;
Invalidate(); Invalidate();
} }
void FakeScrollBar::SetPressed( bool pressed ) void
FakeScrollBar::SetSelected( bool selected )
{ {
Pressed=pressed; fIsSelected=selected;
Invalidate(); Invalidate();
} }
void FakeScrollBar::SetTracking( bool tracking ) void
FakeScrollBar::SetPressed( bool pressed )
{ {
Tracking=tracking; fIsPressed=pressed;
Invalidate();
}
if ( IsTracking() == true ) void
FakeScrollBar::SetTracking( bool tracking )
{
fIsTracking=tracking;
if ( IsTracking() )
{ {
SetEventMask( B_POINTER_EVENTS ); SetEventMask( B_POINTER_EVENTS );
SetPressed( true ); SetPressed( true );
@@ -456,18 +432,20 @@ void FakeScrollBar::SetTracking( bool tracking )
} }
} }
bool FakeScrollBar::IsSelected() bool
FakeScrollBar::IsSelected()
{ {
return Selected; return fIsSelected;
} }
bool FakeScrollBar::IsPressed() bool
FakeScrollBar::IsPressed()
{ {
return Pressed; return fIsPressed;
} }
bool FakeScrollBar::IsTracking() bool
FakeScrollBar::IsTracking()
{ {
return Tracking; return fIsTracking;
} }
+64 -14
View File
@@ -1,36 +1,86 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: fakescrollbar.h
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: Control to simulate a scrollbar
//
//------------------------------------------------------------------------------
#ifndef SCROLLBAR_FAKE_H #ifndef SCROLLBAR_FAKE_H
#define SCROLLBAR_FAKE_H #define SCROLLBAR_FAKE_H
#include <View.h> #include <Control.h>
// These values are the same as what is kept in the scroll_bar_info struct.
class FakeScrollBar : public BView enum
{ {
public: THUMB_BLANK = 0,
FakeScrollBar( BPoint position, bool selected, uint32 style, THUMB_DOTS,
uint32 type, uint32 arrow, uint32 size, BMessage *message ); THUMB_LINES
};
class FakeScrollBar : public BControl
{
public:
FakeScrollBar( BPoint position, bool selected, int32 knobstyle,
bool fixedthumb, bool doublearrows, int32 size,
BMessage *message );
~FakeScrollBar(void);
void SetFromScrollBarInfo(const scroll_bar_info &info);
void SetDoubleArrows( bool doublearrows );
void SetKnobSize( int32 size );
void SetFixedThumb( bool fixed );
void SetKnobStyle( uint32 style ); void SetKnobStyle( uint32 style );
void SetKnobType( uint32 type );
void SetArrowStyle( uint32 arrow );
void SetKnobSize( uint32 size );
void SetSelected( bool selected ); void SetSelected( bool selected );
void SetPressed( bool pressed ); void SetPressed( bool pressed );
void SetTracking( bool tracking ); void SetTracking( bool tracking );
bool IsPressed(); bool IsPressed();
bool IsSelected(); bool IsSelected();
bool IsTracking(); bool IsTracking();
private:
void Draw( BRect updateRect ); private:
void MouseDown( BPoint point ); void MouseDown( BPoint point );
void MouseUp( BPoint point ); void MouseUp( BPoint point );
void MouseMoved( BPoint point, uint32 transit, const BMessage *message ); void MouseMoved( BPoint point, uint32 transit, const BMessage *message );
void Draw( BRect updateRect );
void DrawArrowBox( uint32 x, bool facingleft ); void DrawArrowBox( uint32 x, bool facingleft );
void DrawDotGrabber( uint32 x, uint32 size ); void DrawDotGrabber( uint32 x, uint32 size );
void DrawLineGrabber( uint32 x, uint32 size ); void DrawLineGrabber( uint32 x, uint32 size );
BMessage *Message;
bool Selected, Pressed, Tracking; bool fIsSelected;
uint32 ArrowStyle,KnobType,KnobStyle,KnobSize; bool fIsPressed;
bool fIsTracking;
int32 fKnobStyle;
bool fDoubleArrows;
bool fFixedThumb;
int32 fMinKnobSize;
}; };
#endif #endif
+79 -38
View File
@@ -1,63 +1,99 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: knobsizeadjuster.cpp
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: Control for changing the minimum size of thumb for scrollbars
//
//------------------------------------------------------------------------------
#include <stdio.h> #include <stdio.h>
#include "scrollbar.h" #include "ScrollBarApp.h"
#include "knobsizeadjuster.h" #include "knobsizeadjuster.h"
#include "messages.h" #include "messages.h"
KnobSizeAdjuster::KnobSizeAdjuster( BPoint position, uint32 size ): #define MAXIMUM_KNOB_SIZE 50
BView( BRect( position.x, position.y, position.x+133, #define MINIMUM_KNOB_SIZE 9
position.y+26 ), "KnobSizeAdjuster", B_FOLLOW_LEFT |
B_FOLLOW_TOP, B_WILL_DRAW ) KnobSizeAdjuster::KnobSizeAdjuster( BPoint position, uint32 size )
:BControl( BRect(position.x, position.y, position.x+133, position.y+26),
"KnobSizeAdjuster", NULL, new BMessage(SCROLLBAR_KNOB_SIZE_CHANGED),
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW )
{ {
KnobSize=size; fKnobSize=size;
} }
void KnobSizeAdjuster::Draw( BRect updateRect ) void KnobSizeAdjuster::Draw( BRect updateRect )
{ {
SetViewColor( 216, 216, 216 ); SetViewColor( 216, 216, 216 );
// Draw border.
// Draw border
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
FillRect( Bounds(), B_SOLID_HIGH ); FillRect( Bounds() );
// Draw back // Draw back
SetHighColor( 152, 152, 152 ); SetHighColor( 152, 152, 152 );
StrokeLine( BPoint( 4, 3 ), BPoint( Bounds().right-5, 3 ), B_SOLID_HIGH ); StrokeLine( BPoint(4, 3), BPoint(Bounds().right-5, 3) );
StrokeLine( BPoint( 4, 17 ), BPoint( Bounds().right-5, 17 ), B_SOLID_HIGH ); StrokeLine( BPoint(4, 17), BPoint(Bounds().right-5, 17) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
FillRect( BRect( 4, 4, Bounds().right-5, 5 ), B_SOLID_HIGH ); FillRect( BRect(4, 4, Bounds().right-5, 5) );
SetHighColor( 200, 200, 200 ); SetHighColor( 200, 200, 200 );
FillRect( BRect( 4, 6, Bounds().right-5, 15), B_SOLID_HIGH ); FillRect( BRect(4, 6, Bounds().right-5, 15) );
StrokeLine( BPoint( 3, 15 ), BPoint( 3, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(3, 15), BPoint(3, 13) );
StrokeLine( BPoint( Bounds().right-4, 7 ), BPoint( Bounds().right-4, 11 ), B_SOLID_HIGH ); StrokeLine( BPoint(Bounds().right-4, 7), BPoint(Bounds().right-4, 11) );
StrokeLine( BPoint( Bounds().right-3, 9 ), BPoint( Bounds().right-3, 9 ), B_SOLID_HIGH ); StrokeLine( BPoint(Bounds().right-3, 9), BPoint(Bounds().right-3, 9) );
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
StrokeLine( BPoint( 4, 7 ), BPoint( 4, 11 ), B_SOLID_HIGH ); StrokeLine( BPoint(4, 7), BPoint(4, 11) );
StrokeLine( BPoint( 5, 9 ), BPoint( 5, 9 ), B_SOLID_HIGH ); StrokeLine( BPoint(5, 9), BPoint(5, 9) );
StrokeLine( BPoint( Bounds().right-5, 15 ), BPoint( Bounds().right-5, 13 ), B_SOLID_HIGH ); StrokeLine( BPoint(Bounds().right-5, 15), BPoint(Bounds().right-5, 13) );
// Draw knob // Draw knob
SetHighColor( 216, 216, 216 ); SetHighColor( 216, 216, 216 );
FillRect( BRect( 41, 3, 41+KnobSize, 17 ), B_SOLID_HIGH ); FillRect( BRect(41, 3, 41+fKnobSize, 17) );
SetHighColor( 152, 152, 152 ); SetHighColor( 152, 152, 152 );
StrokeRect( BRect( 41, 3, 41+KnobSize, 17 ), B_SOLID_HIGH ); StrokeRect( BRect(41, 3, 41+fKnobSize, 17) );
SetHighColor( 255, 255, 255 ); SetHighColor( 255, 255, 255 );
StrokeLine( BPoint( 42, 4 ), BPoint( 41+KnobSize-1, 4 ), B_SOLID_HIGH ); StrokeLine( BPoint(42, 4), BPoint(41+fKnobSize-1, 4) );
StrokeLine( BPoint( 42, 4 ), BPoint( 42, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(42, 4), BPoint(42, 16) );
SetHighColor( 184, 184, 184 ); SetHighColor( 184, 184, 184 );
StrokeLine( BPoint( 42, 16 ), BPoint( 41+KnobSize-1, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(42, 16), BPoint(41+fKnobSize-1, 16) );
StrokeLine( BPoint( 41+KnobSize-1, 16 ), BPoint( 41+KnobSize-1, 4 ), B_SOLID_HIGH ); StrokeLine( BPoint(41+fKnobSize-1, 16), BPoint(41+fKnobSize-1, 4) );
SetHighColor( 96, 96, 96 ); SetHighColor( 96, 96, 96 );
StrokeLine( BPoint( 41+KnobSize, 4 ), BPoint( 41+KnobSize, 16 ), B_SOLID_HIGH ); StrokeLine( BPoint(41+fKnobSize, 4), BPoint(41+fKnobSize, 16) );
// Draw slider // Draw slider
SetHighColor( 0, 255, 0 ); SetHighColor( 0, 255, 0 );
FillTriangle( BPoint( 41+KnobSize, 18), BPoint( 41+KnobSize+5, 23 ), BPoint( 41+KnobSize-5, 23), B_SOLID_HIGH ); FillTriangle( BPoint(41+fKnobSize, 18), BPoint(41+fKnobSize+5, 23), BPoint(41+fKnobSize-5, 23) );
SetHighColor( 0, 0, 0 ); SetHighColor( 0, 0, 0 );
StrokeTriangle( BPoint( 41+KnobSize, 18), BPoint( 41+KnobSize+5, 23 ), StrokeTriangle( BPoint(41+fKnobSize, 18), BPoint(41+fKnobSize+5, 23),
BPoint( 41+KnobSize-5, 23), B_SOLID_HIGH ); BPoint(41+fKnobSize-5, 23) );
} }
void KnobSizeAdjuster::MouseDown( BPoint point ) void KnobSizeAdjuster::MouseDown( BPoint point )
@@ -66,10 +102,13 @@ void KnobSizeAdjuster::MouseDown( BPoint point )
if ( point.x > 41+MINIMUM_KNOB_SIZE && point.x < MAXIMUM_KNOB_SIZE+41 ) if ( point.x > 41+MINIMUM_KNOB_SIZE && point.x < MAXIMUM_KNOB_SIZE+41 )
newsize = (int)point.x-41; newsize = (int)point.x-41;
if ( point.x <= 41+MINIMUM_KNOB_SIZE ) if ( point.x <= 41+MINIMUM_KNOB_SIZE )
newsize = MINIMUM_KNOB_SIZE; newsize = MINIMUM_KNOB_SIZE;
if ( point.x >= 41+MAXIMUM_KNOB_SIZE ) if ( point.x >= 41+MAXIMUM_KNOB_SIZE )
newsize = MAXIMUM_KNOB_SIZE; newsize = MAXIMUM_KNOB_SIZE;
SetKnobSize( newsize ); SetKnobSize( newsize );
SetTracking( true ); SetTracking( true );
@@ -78,11 +117,10 @@ void KnobSizeAdjuster::MouseDown( BPoint point )
void KnobSizeAdjuster::MouseUp( BPoint point ) void KnobSizeAdjuster::MouseUp( BPoint point )
{ {
SetTracking( false ); SetTracking( false );
be_app->PostMessage( SCROLLBAR_KNOB_SIZE_CHANGED ); Invoke();
} }
void KnobSizeAdjuster::MouseMoved( BPoint point, uint32 transit, void KnobSizeAdjuster::MouseMoved( BPoint point, uint32 transit, const BMessage *message )
const BMessage *message )
{ {
int32 newsize=0; int32 newsize=0;
@@ -90,30 +128,33 @@ void KnobSizeAdjuster::MouseMoved( BPoint point, uint32 transit,
{ {
if ( point.x > 41+MINIMUM_KNOB_SIZE && point.x < MAXIMUM_KNOB_SIZE+41 ) if ( point.x > 41+MINIMUM_KNOB_SIZE && point.x < MAXIMUM_KNOB_SIZE+41 )
newsize = (int)point.x-41; newsize = (int)point.x-41;
if ( point.x <= 41+MINIMUM_KNOB_SIZE ) if ( point.x <= 41+MINIMUM_KNOB_SIZE )
newsize = MINIMUM_KNOB_SIZE; newsize = MINIMUM_KNOB_SIZE;
if ( point.x >= 41+MAXIMUM_KNOB_SIZE ) if ( point.x >= 41+MAXIMUM_KNOB_SIZE )
newsize = MAXIMUM_KNOB_SIZE; newsize = MAXIMUM_KNOB_SIZE;
SetKnobSize( newsize ); SetKnobSize( newsize );
} }
} }
void KnobSizeAdjuster::SetKnobSize( uint32 size ) void KnobSizeAdjuster::SetKnobSize( int32 size )
{ {
KnobSize=size; fKnobSize=size;
Settings.KnobSize=KnobSize; gSettings.min_knob_size=fKnobSize;
Invalidate(); Invalidate();
} }
void KnobSizeAdjuster::SetPressed( bool pressed ) void KnobSizeAdjuster::SetPressed( bool pressed )
{ {
Pressed=pressed; fPressed=pressed;
} }
void KnobSizeAdjuster::SetTracking( bool tracking ) void KnobSizeAdjuster::SetTracking( bool tracking )
{ {
Tracking=tracking; fTracking=tracking;
if ( IsTracking() == true ) if ( IsTracking() == true )
SetEventMask( B_POINTER_EVENTS ); SetEventMask( B_POINTER_EVENTS );
@@ -123,12 +164,12 @@ void KnobSizeAdjuster::SetTracking( bool tracking )
bool KnobSizeAdjuster::IsPressed() bool KnobSizeAdjuster::IsPressed()
{ {
return Pressed; return fPressed;
} }
bool KnobSizeAdjuster::IsTracking() bool KnobSizeAdjuster::IsTracking()
{ {
return Tracking; return fTracking;
} }
+40 -8
View File
@@ -1,26 +1,58 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: knobsizeadjuster.h
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: Control for changing the minimum size of thumb for scrollbars
//
//------------------------------------------------------------------------------
#ifndef SCROLLBAR_KNOB_ADJUSTER_H #ifndef SCROLLBAR_KNOB_ADJUSTER_H
#define SCROLLBAR_KNOB_ADJUSTER_H #define SCROLLBAR_KNOB_ADJUSTER_H
#include <View.h> #include <Control.h>
class KnobSizeAdjuster : public BControl
class KnobSizeAdjuster : public BView
{ {
public: public:
KnobSizeAdjuster( BPoint position, uint32 size ); KnobSizeAdjuster( BPoint position, uint32 size );
void SetKnobSize( uint32 size ); void SetKnobSize( int32 size );
void SetPressed( bool pressed ); void SetPressed( bool pressed );
void SetTracking( bool tracking ); void SetTracking( bool tracking );
bool IsPressed(); bool IsPressed();
bool IsTracking(); bool IsTracking();
private:
int32 KnobSize(void) const { return fKnobSize; }
private:
void Draw( BRect updateRect ); void Draw( BRect updateRect );
void MouseDown( BPoint point ); void MouseDown( BPoint point );
void MouseUp( BPoint point ); void MouseUp( BPoint point );
void MouseMoved( BPoint point, uint32 transit, const BMessage *message ); void MouseMoved( BPoint point, uint32 transit, const BMessage *message );
uint32 KnobSize;
bool Pressed, Tracking; int32 fKnobSize;
bool fPressed;
bool fTracking;
}; };
#endif #endif
+27
View File
@@ -1,3 +1,30 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2005, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: messages.h
// Author: MrSiggler
// DarkWyrm <[email protected]>
// Description: message defs
//
//------------------------------------------------------------------------------
#ifndef SCROLLBAR_MESSAGES_H #ifndef SCROLLBAR_MESSAGES_H
#define SCROLLBAR_MESSAGES_H #define SCROLLBAR_MESSAGES_H