Lots of fixes, geometry calculations updated, added buffered BSlider support

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2539 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marc Flerackers
2003-01-23 14:55:18 +00:00
parent 2dc718a7e8
commit ac6f7aa850
4 changed files with 2722 additions and 2637 deletions
+41 -25
View File
@@ -45,8 +45,12 @@ BButton::BButton(BRect frame, const char *name, const char *label, BMessage *mes
: BControl(frame, name, label, message, resizingMode, flags), : BControl(frame, name, label, message, resizingMode, flags),
fDrawAsDefault(false) fDrawAsDefault(false)
{ {
if (Bounds().Height() < 24.0f) // Resize to minimum height if needed
ResizeTo(Bounds().Width(), 24.0f); font_height fh;
GetFontHeight(&fh);
float minHeight = 12.0f + (float)ceil(fh.ascent + fh.descent);
if (Bounds().Height() < minHeight)
ResizeTo(Bounds().Width(), minHeight);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BButton::~BButton() BButton::~BButton()
@@ -56,11 +60,11 @@ BButton::~BButton()
BButton::BButton(BMessage *archive) BButton::BButton(BMessage *archive)
: BControl (archive) : BControl (archive)
{ {
if ( archive->FindBool ( "_default", &fDrawAsDefault ) != B_OK ) if (archive->FindBool("_default", &fDrawAsDefault) != B_OK)
fDrawAsDefault = false; fDrawAsDefault = false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BArchivable *BButton::Instantiate ( BMessage *archive ) BArchivable *BButton::Instantiate(BMessage *archive)
{ {
if (validate_instantiation(archive, "BButton")) if (validate_instantiation(archive, "BButton"))
return new BButton(archive); return new BButton(archive);
@@ -83,7 +87,27 @@ status_t BButton::Archive(BMessage* archive, bool deep) const
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BButton::Draw(BRect updateRect) void BButton::Draw(BRect updateRect)
{ {
BRect rect = Bounds(); font_height fh;
GetFontHeight(&fh);
BRect bounds(Bounds());
// If the focus is changing, just redraw the focus indicator
if (IsFocusChanging())
{
float x = bounds.right / 2 - StringWidth(Label()) / 2.0f;
float y = bounds.bottom - fh.descent - (IsDefault() ? 6.0f : 3.0f);
if (IsFocus())
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
else
SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_LIGHTEN_1_TINT));
StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
return;
}
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT), lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
@@ -93,6 +117,8 @@ void BButton::Draw(BRect updateRect)
darken4 = tint_color(no_tint, B_DARKEN_4_TINT), darken4 = tint_color(no_tint, B_DARKEN_4_TINT),
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT);
BRect rect(bounds);
if (IsDefault()) if (IsDefault())
rect = DrawDefault(rect, IsEnabled()); rect = DrawDefault(rect, IsEnabled());
else else
@@ -162,11 +188,8 @@ void BButton::Draw(BRect updateRect)
} }
// Label // Label
BFont font; float x = bounds.right / 2 - StringWidth(Label()) / 2.0f;
GetFont(&font); float y = bounds.bottom - fh.descent - (IsDefault() ? 8.0f : 5.0f);
float x = Bounds().Width() / 2 - StringWidth(Label()) / 2.0f;
float y = Bounds().Height() / 2.0f + (float)ceil(font.Size() / 2.0f);
if (Value()) if (Value())
{ {
@@ -184,9 +207,6 @@ void BButton::Draw(BRect updateRect)
// Focus // Focus
if (IsFocus()) if (IsFocus())
{ {
font_height fh;
font.GetHeight(&fh);
y += 2.0f; y += 2.0f;
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y)); StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
@@ -243,11 +263,8 @@ void BButton::Draw(BRect updateRect)
FillRect(rect); FillRect(rect);
// Label // Label
BFont font; float x = bounds.right / 2 - StringWidth(Label()) / 2.0f;
GetFont(&font); float y = bounds.bottom - fh.descent - 5.0f;
float x = Bounds().Width() / 2 - StringWidth(Label()) / 2.0f;
float y = Bounds().Height() / 2.0f + (float)ceil(font.Size() / 2.0f);
SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT)); SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT));
SetLowColor(lighten2); SetLowColor(lighten2);
@@ -367,7 +384,7 @@ void BButton::MouseUp(BPoint point)
if ( Value() == B_CONTROL_ON) if ( Value() == B_CONTROL_ON)
{ {
SetValue(B_CONTROL_OFF); SetValue(B_CONTROL_OFF);
BControl::Invoke(); Invoke();
} }
} }
@@ -385,13 +402,12 @@ void BButton::SetValue(int32 value)
BControl::SetValue(value); BControl::SetValue(value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BButton::GetPreferredSize (float *width, float *height) void BButton::GetPreferredSize(float *width, float *height)
{ {
font_height fh; font_height fh;
GetFontHeight(&fh); GetFontHeight(&fh);
*height = (float)ceil(fh.ascent + fh.descent + fh.leading) + 12.0f; *height = 12.0f + (float)ceil(fh.ascent + fh.descent);
*width = 20.0f + (float)ceil(StringWidth(Label())); *width = 20.0f + (float)ceil(StringWidth(Label()));
if (*width < 75.0f) if (*width < 75.0f)
@@ -527,10 +543,10 @@ BRect BButton::DrawDefault(BRect bounds, bool enabled)
return bounds; return bounds;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t Execute() status_t BButton::Execute()
{ {
// TODO: // TODO: Is there a use for this? Maybe visual feedback happens here?
return B_ERROR; return Invoke();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
+4 -2
View File
@@ -176,8 +176,7 @@ status_t BControl::Archive(BMessage *archive, bool deep) const
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BControl::WindowActivated(bool active) void BControl::WindowActivated(bool active)
{ {
// Should we check this? if (IsFocus())
if (Window())
{ {
Draw(Bounds()); Draw(Bounds());
Flush(); Flush();
@@ -339,6 +338,9 @@ void BControl::DetachedFromWindow()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BControl::SetLabel(const char *string) void BControl::SetLabel(const char *string)
{ {
if (strcmp(fLabel, string) == 0)
return;
if (fLabel) if (fLabel)
free(fLabel); free(fLabel);
+20 -14
View File
@@ -75,6 +75,24 @@ status_t BRadioButton::Archive(BMessage *archive, bool deep) const
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BRadioButton::Draw(BRect updateRect) void BRadioButton::Draw(BRect updateRect)
{ {
font_height fh;
GetFontHeight(&fh);
// If the focus is changing, just redraw the focus indicator
if (IsFocusChanging())
{
float h = 8.0f + (float)ceil(fh.ascent / 2.0f) + 2.0f;
if (IsFocus())
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
else
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
StrokeLine(BPoint(20.0f, h), BPoint(20.0f + StringWidth(Label()), h));
return;
}
// Placeholder until sBitmaps is filled in // Placeholder until sBitmaps is filled in
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT), lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
@@ -143,11 +161,6 @@ void BRadioButton::Draw(BRect updateRect)
BPoint(rect.right - 1, rect.top + 1)); BPoint(rect.right - 1, rect.top + 1));
// Label // Label
BFont font;
GetFont(&font);
font_height fh;
font.GetHeight(&fh);
SetHighColor(darkenmax); SetHighColor(darkenmax);
DrawString(Label(), BPoint(20.0f, 8.0f + (float)ceil(fh.ascent / 2.0f))); DrawString(Label(), BPoint(20.0f, 8.0f + (float)ceil(fh.ascent / 2.0f)));
@@ -205,11 +218,6 @@ void BRadioButton::Draw(BRect updateRect)
BPoint(rect.right - 1, rect.top + 1)); BPoint(rect.right - 1, rect.top + 1));
// Label // Label
BFont font;
GetFont(&font);
font_height fh;
font.GetHeight(&fh);
SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT)); SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT));
DrawString(Label(), BPoint(20.0f, 8.0f + (float)ceil(fh.ascent / 2.0f))); DrawString(Label(), BPoint(20.0f, 8.0f + (float)ceil(fh.ascent / 2.0f)));
} }
@@ -283,9 +291,7 @@ void BRadioButton::GetPreferredSize(float *width, float *height)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BRadioButton::ResizeToPreferred() void BRadioButton::ResizeToPreferred()
{ {
float width, height; BControl::ResizeToPreferred();
GetPreferredSize(&width, &height);
BControl::ResizeTo(width, height);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BRadioButton::Invoke(BMessage *message) status_t BRadioButton::Invoke(BMessage *message)
@@ -364,7 +370,7 @@ BHandler *BRadioButton::ResolveSpecifier(BMessage *message, int32 index,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BRadioButton::MakeFocus(bool focused) void BRadioButton::MakeFocus(bool focused)
{ {
BControl::MakeFocus(); BControl::MakeFocus(focused);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BRadioButton::AllAttached() void BRadioButton::AllAttached()
+170 -109
View File
@@ -32,7 +32,8 @@
#include <Slider.h> #include <Slider.h>
#include <Message.h> #include <Message.h>
#include <Window.h> #include <Window.h>
#include <Support/Errors.h> #include <Bitmap.h>
#include <Errors.h>
// Project Includes ------------------------------------------------------------ // Project Includes ------------------------------------------------------------
@@ -101,7 +102,22 @@ BSlider::~BSlider()
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BSlider::BSlider(BMessage *archive) BSlider::BSlider(BMessage *archive)
: BControl (archive) : BControl (archive),
fModificationMessage(NULL),
fSnoozeAmount(20000),
fUseFillColor(false),
fMinLimitStr(NULL),
fMaxLimitStr(NULL),
fMinValue(0),
fMaxValue(100),
fKeyIncrementValue(1),
fHashMarkCount(0),
fHashMarks(B_HASH_MARKS_NONE),
fOffScreenBits(NULL),
fOffScreenView(NULL),
fStyle(B_BLOCK_THUMB),
fOrientation(B_HORIZONTAL),
fBarThickness(6.0f)
{ {
BMessage modMessage; BMessage modMessage;
int16 anInt16; int16 anInt16;
@@ -236,14 +252,13 @@ void BSlider::AttachedToWindow()
{ {
BControl::AttachedToWindow(); BControl::AttachedToWindow();
if (Parent())
SetViewColor(Parent()->ViewColor());
ResizeToPreferred(); ResizeToPreferred();
fLocation.Set(9.0f, 0.0f); fLocation.Set(9.0f, 0.0f);
// TODO: Allocate fOffScreenBits and fOffScreenView fOffScreenBits = new BBitmap(Bounds(), B_CMAP8, true, false);
fOffScreenView = new BView(Bounds(), "", B_FOLLOW_NONE, B_WILL_DRAW);
fOffScreenBits->AddChild(fOffScreenView);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::AllAttached() void BSlider::AllAttached()
@@ -256,6 +271,21 @@ void BSlider::AllDetached()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::DetachedFromWindow() void BSlider::DetachedFromWindow()
{ {
// TODO rewrite this
if (fOffScreenView)
{
fOffScreenBits->Lock();
fOffScreenView->RemoveSelf();
fOffScreenBits->Unlock();
delete fOffScreenView;
fOffScreenView = NULL;
}
if (fOffScreenBits)
{
delete fOffScreenBits;
fOffScreenBits = NULL;
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::MessageReceived(BMessage *msg) void BSlider::MessageReceived(BMessage *msg)
@@ -268,6 +298,21 @@ void BSlider::FrameMoved(BPoint new_position)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::FrameResized(float w,float h) void BSlider::FrameResized(float w,float h)
{ {
if (fOffScreenView)
{
fOffScreenBits->Lock();
fOffScreenView->RemoveSelf();
fOffScreenView->ResizeTo(Bounds().Width(), Bounds().Height());
fOffScreenBits->Unlock();
}
else
fOffScreenView = new BView(Bounds(), "", B_FOLLOW_NONE, B_WILL_DRAW);
if (fOffScreenBits)
delete fOffScreenBits;
fOffScreenBits = new BBitmap(Bounds(), B_CMAP8, true, false);
fOffScreenBits->AddChild(fOffScreenView);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::KeyDown(const char *bytes, int32 numBytes) void BSlider::KeyDown(const char *bytes, int32 numBytes)
@@ -398,16 +443,19 @@ void BSlider::GetLimits(int32 *minimum, int32 *maximum)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::Draw(BRect updateRect) void BSlider::Draw(BRect updateRect)
{ {
fOffScreenBits->Lock();
DrawSlider(); DrawSlider();
fOffScreenView->Sync();
fOffScreenBits->Unlock();
if (fOffScreenBits)
DrawBitmap(fOffScreenBits, B_ORIGIN);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::DrawSlider() void BSlider::DrawSlider()
{ {
// TODO: Draw into fOffScreenView and draw fOffScreenBits on the view OffscreenView()->SetHighColor(ViewColor());
// Write drawing code for a vertical slider OffscreenView()->FillRect(Bounds());
SetHighColor(ViewColor());
FillRect(Bounds());
DrawBar(); DrawBar();
DrawHashMarks(); DrawHashMarks();
@@ -422,37 +470,38 @@ void BSlider::DrawSlider()
void BSlider::DrawBar() void BSlider::DrawBar()
{ {
BRect frame = BarFrame(); BRect frame = BarFrame();
BView *view = OffscreenView();
if (fUseFillColor) if (fUseFillColor)
{ {
if (fOrientation == B_HORIZONTAL) if (fOrientation == B_HORIZONTAL)
{ {
SetHighColor(fBarColor); view->SetHighColor(fBarColor);
FillRect(BRect((float)floor(frame.left + 1 + Position() * (frame.Width() - 2)), view->FillRect(BRect((float)floor(frame.left + 1 + Position() *
frame.top, frame.right, frame.bottom)); (frame.Width() - 2)), frame.top, frame.right, frame.bottom));
SetHighColor(fFillColor); view->SetHighColor(fFillColor);
FillRect(BRect(frame.left, frame.top, view->FillRect(BRect(frame.left, frame.top,
(float)floor(frame.left + 1 + Position() * (frame.Width() - 2)), (float)floor(frame.left + 1 + Position() * (frame.Width() - 2)),
frame.bottom)); frame.bottom));
} }
else else
{ {
SetHighColor(fBarColor); view->SetHighColor(fBarColor);
FillRect(BRect(frame.left, frame.top, frame.right, view->FillRect(BRect(frame.left, frame.top, frame.right,
(float)floor(frame.bottom - 1 - Position() * (frame.Height() - 2)))); (float)floor(frame.bottom - 1 - Position() * (frame.Height() - 2))));
SetHighColor(fFillColor); view->SetHighColor(fFillColor);
FillRect(BRect(frame.left, view->FillRect(BRect(frame.left,
(float)floor(frame.bottom - 1 - Position() * (frame.Height() - 2)), (float)floor(frame.bottom - 1 - Position() *
frame.right, frame.bottom)); (frame.Height() - 2)), frame.right, frame.bottom));
} }
} }
else else
{ {
SetHighColor(fBarColor); view->SetHighColor(fBarColor);
FillRect(frame); view->FillRect(frame);
} }
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
@@ -461,29 +510,37 @@ void BSlider::DrawBar()
darken2 = tint_color(no_tint, B_DARKEN_2_TINT), darken2 = tint_color(no_tint, B_DARKEN_2_TINT),
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT);
SetHighColor(darken1); view->SetHighColor(darken1);
StrokeLine(BPoint(frame.left, frame.top), BPoint(frame.left + 1.0f, frame.top)); view->StrokeLine(BPoint(frame.left, frame.top),
StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.left + 1.0f, frame.bottom)); BPoint(frame.left + 1.0f, frame.top));
StrokeLine(BPoint(frame.right - 1.0f, frame.top), BPoint(frame.right, frame.top)); view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.left + 1.0f, frame.bottom));
view->StrokeLine(BPoint(frame.right - 1.0f, frame.top),
BPoint(frame.right, frame.top));
SetHighColor(darken2); view->SetHighColor(darken2);
StrokeLine(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.right - 1.0f, frame.top)); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top),
StrokeLine(BPoint(frame.left, frame.bottom - 1.0f), BPoint(frame.left, frame.top + 1.0f)); BPoint(frame.right - 1.0f, frame.top));
view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f),
BPoint(frame.left, frame.top + 1.0f));
SetHighColor(lightenmax); view->SetHighColor(lightenmax);
StrokeLine(BPoint(frame.left + 1.0f, frame.bottom), BPoint(frame.right, frame.bottom)); view->StrokeLine(BPoint(frame.left + 1.0f, frame.bottom),
StrokeLine(BPoint(frame.right, frame.top + 1.0f)); BPoint(frame.right, frame.bottom));
view->StrokeLine(BPoint(frame.right, frame.top + 1.0f));
frame.InsetBy(1.0f, 1.0f); frame.InsetBy(1.0f, 1.0f);
SetHighColor(darkenmax); view->SetHighColor(darkenmax);
StrokeLine(BPoint(frame.left, frame.bottom), BPoint(frame.left, frame.top)); view->StrokeLine(BPoint(frame.left, frame.bottom),
StrokeLine(BPoint(frame.right, frame.top)); BPoint(frame.left, frame.top));
view->StrokeLine(BPoint(frame.right, frame.top));
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::DrawHashMarks() void BSlider::DrawHashMarks()
{ {
BRect frame = HashMarksFrame(); BRect frame = HashMarksFrame();
BView *view = OffscreenView();
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT),
darken2 = tint_color(no_tint, B_DARKEN_2_TINT); darken2 = tint_color(no_tint, B_DARKEN_2_TINT);
@@ -497,11 +554,11 @@ void BSlider::DrawHashMarks()
{ {
for (int32 i = 0; i < fHashMarkCount; i++) for (int32 i = 0; i < fHashMarkCount; i++)
{ {
SetHighColor(darken2); view->SetHighColor(darken2);
StrokeLine(BPoint(pos, frame.top), view->StrokeLine(BPoint(pos, frame.top),
BPoint(pos, frame.top + 5)); BPoint(pos, frame.top + 5));
SetHighColor(lightenmax); view->SetHighColor(lightenmax);
StrokeLine(BPoint(pos + 1, frame.top), view->StrokeLine(BPoint(pos + 1, frame.top),
BPoint(pos + 1, frame.top + 5)); BPoint(pos + 1, frame.top + 5));
pos += factor; pos += factor;
@@ -511,11 +568,11 @@ void BSlider::DrawHashMarks()
{ {
for (int32 i = 0; i < fHashMarkCount; i++) for (int32 i = 0; i < fHashMarkCount; i++)
{ {
SetHighColor(darken2); view->SetHighColor(darken2);
StrokeLine(BPoint(frame.left, pos), view->StrokeLine(BPoint(frame.left, pos),
BPoint(frame.left + 5, pos)); BPoint(frame.left + 5, pos));
SetHighColor(lightenmax); view->SetHighColor(lightenmax);
StrokeLine(BPoint(frame.left, pos + 1), view->StrokeLine(BPoint(frame.left, pos + 1),
BPoint(frame.left + 5, pos + 1)); BPoint(frame.left + 5, pos + 1));
pos += factor; pos += factor;
@@ -531,11 +588,11 @@ void BSlider::DrawHashMarks()
{ {
for (int32 i = 0; i < fHashMarkCount; i++) for (int32 i = 0; i < fHashMarkCount; i++)
{ {
SetHighColor(darken2); view->SetHighColor(darken2);
StrokeLine(BPoint(pos, frame.bottom - 5), view->StrokeLine(BPoint(pos, frame.bottom - 5),
BPoint(pos, frame.bottom)); BPoint(pos, frame.bottom));
SetHighColor(lightenmax); view->SetHighColor(lightenmax);
StrokeLine(BPoint(pos + 1, frame.bottom - 5), view->StrokeLine(BPoint(pos + 1, frame.bottom - 5),
BPoint(pos + 1, frame.bottom)); BPoint(pos + 1, frame.bottom));
pos += factor; pos += factor;
@@ -545,11 +602,11 @@ void BSlider::DrawHashMarks()
{ {
for (int32 i = 0; i < fHashMarkCount; i++) for (int32 i = 0; i < fHashMarkCount; i++)
{ {
SetHighColor(darken2); view->SetHighColor(darken2);
StrokeLine(BPoint(frame.right - 5, pos), view->StrokeLine(BPoint(frame.right - 5, pos),
BPoint(frame.right, pos)); BPoint(frame.right, pos));
SetHighColor(lightenmax); view->SetHighColor(lightenmax);
StrokeLine(BPoint(frame.right - 5, pos + 1), view->StrokeLine(BPoint(frame.right - 5, pos + 1),
BPoint(frame.right, pos + 1)); BPoint(frame.right, pos + 1));
pos += factor; pos += factor;
@@ -568,14 +625,16 @@ void BSlider::DrawThumb()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::DrawFocusMark() void BSlider::DrawFocusMark()
{ {
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); OffscreenView()->SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
StrokeRect(Bounds()); OffscreenView()->StrokeRect(Bounds());
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::DrawText() void BSlider::DrawText()
{ {
BRect bounds(Bounds()); BRect bounds(Bounds());
SetHighColor(0, 0, 0); BView *view = OffscreenView();
view->SetHighColor(0, 0, 0);
font_height fheight; font_height fheight;
@@ -584,13 +643,13 @@ void BSlider::DrawText()
if (Orientation() == B_HORIZONTAL) if (Orientation() == B_HORIZONTAL)
{ {
if (Label()) if (Label())
DrawString(Label(), BPoint(2.0f, (float)ceil(fheight.ascent))); view->DrawString(Label(), BPoint(2.0f, (float)ceil(fheight.ascent)));
if (fMinLimitStr) if (fMinLimitStr)
DrawString(fMinLimitStr, BPoint(2.0f, bounds.bottom - 4.0f)); view->DrawString(fMinLimitStr, BPoint(2.0f, bounds.bottom - 4.0f));
if (fMaxLimitStr) if (fMaxLimitStr)
DrawString(fMaxLimitStr, BPoint(bounds.right - view->DrawString(fMaxLimitStr, BPoint(bounds.right -
StringWidth(fMaxLimitStr) - 2.0f, bounds.bottom - 4.0f)); StringWidth(fMaxLimitStr) - 2.0f, bounds.bottom - 4.0f));
} }
else else
@@ -598,16 +657,16 @@ void BSlider::DrawText()
float ascent = (float)ceil(fheight.ascent); float ascent = (float)ceil(fheight.ascent);
if (Label()) if (Label())
DrawString(Label(), BPoint(bounds.Width() / 2.0f - view->DrawString(Label(), BPoint(bounds.Width() / 2.0f -
StringWidth(Label()) / 2.0f, ascent)); StringWidth(Label()) / 2.0f, ascent));
if (fMaxLimitStr) if (fMaxLimitStr)
DrawString(fMaxLimitStr, BPoint(bounds.Width() / 2.0f - view->DrawString(fMaxLimitStr, BPoint(bounds.Width() / 2.0f -
StringWidth(fMaxLimitStr) / 2.0f, ascent + StringWidth(fMaxLimitStr) / 2.0f, ascent +
(Label() ? (float)ceil(ascent + fheight.descent + 2.0f) : 0.0f))); (Label() ? (float)ceil(ascent + fheight.descent + 2.0f) : 0.0f)));
if (fMinLimitStr) if (fMinLimitStr)
DrawString(fMinLimitStr, BPoint(bounds.Width() / 2.0f - view->DrawString(fMinLimitStr, BPoint(bounds.Width() / 2.0f -
StringWidth(fMinLimitStr) / 2.0f, StringWidth(fMinLimitStr) / 2.0f,
bounds.bottom - 2.0f)); bounds.bottom - 2.0f));
} }
@@ -912,8 +971,7 @@ bool BSlider::FillColor(rgb_color *bar_color) const
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
BView *BSlider::OffscreenView() const BView *BSlider::OffscreenView() const
{ {
// TODO: return fOffscreenView return fOffScreenView;
return (BView*)this;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
orientation BSlider::Orientation() const orientation BSlider::Orientation() const
@@ -947,6 +1005,7 @@ void BSlider::SetFont(const BFont *font, uint32 properties)
void BSlider::_DrawBlockThumb() void BSlider::_DrawBlockThumb()
{ {
BRect frame = ThumbFrame(); BRect frame = ThumbFrame();
BView *view = OffscreenView();
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT), lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT),
@@ -955,70 +1014,71 @@ void BSlider::_DrawBlockThumb()
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT);
// Outline // Outline
SetHighColor(darken3); view->SetHighColor(darken3);
StrokeLine(BPoint(frame.left, frame.bottom - 2.0f), view->StrokeLine(BPoint(frame.left, frame.bottom - 2.0f),
BPoint(frame.left, frame.top + 1.0f)); BPoint(frame.left, frame.top + 1.0f));
StrokeLine(BPoint(frame.left + 1.0f, frame.top), view->StrokeLine(BPoint(frame.left + 1.0f, frame.top),
BPoint(frame.right - 2.0f, frame.top)); BPoint(frame.right - 2.0f, frame.top));
StrokeLine(BPoint(frame.right, frame.top + 2.0f), view->StrokeLine(BPoint(frame.right, frame.top + 2.0f),
BPoint(frame.right, frame.bottom - 1.0f)); BPoint(frame.right, frame.bottom - 1.0f));
StrokeLine(BPoint(frame.left + 2.0f, frame.bottom), view->StrokeLine(BPoint(frame.left + 2.0f, frame.bottom),
BPoint(frame.right - 1.0f, frame.bottom)); BPoint(frame.right - 1.0f, frame.bottom));
// First bevel // First bevel
frame.InsetBy(1.0f, 1.0f); frame.InsetBy(1.0f, 1.0f);
SetHighColor(lighten2); view->SetHighColor(lighten2);
FillRect(frame); view->FillRect(frame);
SetHighColor(darkenmax); view->SetHighColor(darkenmax);
StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.right - 1.0f, frame.bottom)); BPoint(frame.right - 1.0f, frame.bottom));
StrokeLine(BPoint(frame.right, frame.bottom - 1), view->StrokeLine(BPoint(frame.right, frame.bottom - 1),
BPoint(frame.right, frame.top)); BPoint(frame.right, frame.top));
frame.InsetBy(1.0f, 1.0f); frame.InsetBy(1.0f, 1.0f);
// Second bevel and center dots // Second bevel and center dots
SetHighColor(darken2); view->SetHighColor(darken2);
StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.right, frame.bottom)); BPoint(frame.right, frame.bottom));
StrokeLine(BPoint(frame.right, frame.top)); view->StrokeLine(BPoint(frame.right, frame.top));
if (Orientation() == B_HORIZONTAL) if (Orientation() == B_HORIZONTAL)
{ {
StrokeLine(BPoint(frame.left + 6.0f, frame.top + 2.0f), view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 2.0f),
BPoint(frame.left + 6.0f, frame.top + 2.0f)); BPoint(frame.left + 6.0f, frame.top + 2.0f));
StrokeLine(BPoint(frame.left + 6.0f, frame.top + 4.0f), view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 4.0f),
BPoint(frame.left + 6.0f, frame.top + 4.0f)); BPoint(frame.left + 6.0f, frame.top + 4.0f));
StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f), view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f),
BPoint(frame.left + 6.0f, frame.top + 6.0f)); BPoint(frame.left + 6.0f, frame.top + 6.0f));
} }
else else
{ {
StrokeLine(BPoint(frame.left + 2.0f, frame.top + 6.0f), view->StrokeLine(BPoint(frame.left + 2.0f, frame.top + 6.0f),
BPoint(frame.left + 2.0f, frame.top + 6.0f)); BPoint(frame.left + 2.0f, frame.top + 6.0f));
StrokeLine(BPoint(frame.left + 4.0f, frame.top + 6.0f), view->StrokeLine(BPoint(frame.left + 4.0f, frame.top + 6.0f),
BPoint(frame.left + 4.0f, frame.top + 6.0f)); BPoint(frame.left + 4.0f, frame.top + 6.0f));
StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f), view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f),
BPoint(frame.left + 6.0f, frame.top + 6.0f)); BPoint(frame.left + 6.0f, frame.top + 6.0f));
} }
StrokeLine(BPoint(frame.right + 1.0f, frame.bottom + 1.0f), view->StrokeLine(BPoint(frame.right + 1.0f, frame.bottom + 1.0f),
BPoint(frame.right + 1.0f, frame.bottom + 1.0f)); BPoint(frame.right + 1.0f, frame.bottom + 1.0f));
frame.InsetBy(1.0f, 1.0f); frame.InsetBy(1.0f, 1.0f);
// Third bevel // Third bevel
SetHighColor(no_tint); view->SetHighColor(no_tint);
StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.right, frame.bottom)); BPoint(frame.right, frame.bottom));
StrokeLine(BPoint(frame.right, frame.top)); view->StrokeLine(BPoint(frame.right, frame.top));
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::_DrawTriangleThumb() void BSlider::_DrawTriangleThumb()
{ {
BRect frame = ThumbFrame(); BRect frame = ThumbFrame();
BView *view = OffscreenView();
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT), lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
@@ -1031,52 +1091,52 @@ void BSlider::_DrawTriangleThumb()
if (Orientation() == B_HORIZONTAL) if (Orientation() == B_HORIZONTAL)
{ {
SetHighColor(lighten1); view->SetHighColor(lighten1);
FillTriangle(BPoint(frame.left, frame.bottom - 1.0f), view->FillTriangle(BPoint(frame.left, frame.bottom - 1.0f),
BPoint(frame.left + 6.0f, frame.top), BPoint(frame.left + 6.0f, frame.top),
BPoint(frame.right, frame.bottom - 1.0f)); BPoint(frame.right, frame.bottom - 1.0f));
SetHighColor(darkenmax); view->SetHighColor(darkenmax);
StrokeLine(BPoint(frame.right, frame.bottom + 1), view->StrokeLine(BPoint(frame.right, frame.bottom + 1),
BPoint(frame.left, frame.bottom + 1)); BPoint(frame.left, frame.bottom + 1));
StrokeLine(BPoint(frame.right, frame.bottom), view->StrokeLine(BPoint(frame.right, frame.bottom),
BPoint(frame.left + 6.0f, frame.top)); BPoint(frame.left + 6.0f, frame.top));
SetHighColor(darken2); view->SetHighColor(darken2);
StrokeLine(BPoint(frame.right - 1, frame.bottom), view->StrokeLine(BPoint(frame.right - 1, frame.bottom),
BPoint(frame.left, frame.bottom)); BPoint(frame.left, frame.bottom));
StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.left + 5.0f, frame.top + 1)); BPoint(frame.left + 5.0f, frame.top + 1));
SetHighColor(no_tint); view->SetHighColor(no_tint);
StrokeLine(BPoint(frame.right - 2, frame.bottom - 1.0f), view->StrokeLine(BPoint(frame.right - 2, frame.bottom - 1.0f),
BPoint(frame.left + 3.0f, frame.bottom - 1.0f)); BPoint(frame.left + 3.0f, frame.bottom - 1.0f));
StrokeLine(BPoint(frame.right - 3, frame.bottom - 2.0f), view->StrokeLine(BPoint(frame.right - 3, frame.bottom - 2.0f),
BPoint(frame.left + 6.0f, frame.top + 1)); BPoint(frame.left + 6.0f, frame.top + 1));
} }
else else
{ {
SetHighColor(lighten1); view->SetHighColor(lighten1);
FillTriangle(BPoint(frame.left + 1.0f, frame.top), view->FillTriangle(BPoint(frame.left + 1.0f, frame.top),
BPoint(frame.left + 7.0f, frame.top + 6.0f), BPoint(frame.left + 7.0f, frame.top + 6.0f),
BPoint(frame.left + 1.0f, frame.bottom)); BPoint(frame.left + 1.0f, frame.bottom));
SetHighColor(darkenmax); view->SetHighColor(darkenmax);
StrokeLine(BPoint(frame.left, frame.top + 1), view->StrokeLine(BPoint(frame.left, frame.top + 1),
BPoint(frame.left, frame.bottom)); BPoint(frame.left, frame.bottom));
StrokeLine(BPoint(frame.left + 1.0f, frame.bottom), view->StrokeLine(BPoint(frame.left + 1.0f, frame.bottom),
BPoint(frame.left + 7.0f, frame.top + 6.0f)); BPoint(frame.left + 7.0f, frame.top + 6.0f));
SetHighColor(darken2); view->SetHighColor(darken2);
StrokeLine(BPoint(frame.left, frame.top), view->StrokeLine(BPoint(frame.left, frame.top),
BPoint(frame.left, frame.bottom - 1)); BPoint(frame.left, frame.bottom - 1));
StrokeLine(BPoint(frame.left + 1.0f, frame.top), view->StrokeLine(BPoint(frame.left + 1.0f, frame.top),
BPoint(frame.left + 6.0f, frame.top + 5.0f)); BPoint(frame.left + 6.0f, frame.top + 5.0f));
SetHighColor(no_tint); view->SetHighColor(no_tint);
StrokeLine(BPoint(frame.left + 1.0f, frame.top + 2.0f), view->StrokeLine(BPoint(frame.left + 1.0f, frame.top + 2.0f),
BPoint(frame.left + 1.0f, frame.bottom - 1.0f)); BPoint(frame.left + 1.0f, frame.bottom - 1.0f));
StrokeLine(BPoint(frame.left + 2.0f, frame.bottom - 2.0f), view->StrokeLine(BPoint(frame.left + 2.0f, frame.bottom - 2.0f),
BPoint(frame.left + 6.0f, frame.top + 6.0f)); BPoint(frame.left + 6.0f, frame.top + 6.0f));
} }
} }
@@ -1124,6 +1184,7 @@ BSlider &BSlider::operator=(const BSlider &)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BSlider::_InitObject() void BSlider::_InitObject()
{ {
// TODO: Move common init code here
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------