diff --git a/headers/os/interface/Slider.h b/headers/os/interface/Slider.h index 5e4f20a6a9..26be2073cf 100644 --- a/headers/os/interface/Slider.h +++ b/headers/os/interface/Slider.h @@ -54,6 +54,7 @@ enum thumb_style { // Globals --------------------------------------------------------------------- +#define USE_OFF_SCREEN_VIEW 0 // BSlider class --------------------------------------------------------------- class BSlider : public BControl { @@ -190,7 +191,7 @@ private: float _MinPosition() const; float _MaxPosition() const; - + //virtual void _ReservedSlider1(); //virtual void _ReservedSlider2(); //virtual void _ReservedSlider3(); @@ -207,36 +208,42 @@ virtual void _ReservedSlider12(); BSlider &operator=(const BSlider &); void _InitObject(); - + BMessage* fModificationMessage; int32 fSnoozeAmount; rgb_color fBarColor; rgb_color fFillColor; bool fUseFillColor; - + char* fMinLimitStr; char* fMaxLimitStr; - + int32 fMinValue; int32 fMaxValue; int32 fKeyIncrementValue; - + int32 fHashMarkCount; hash_mark_location fHashMarks; - + +#if USE_OFF_SCREEN_VIEW BBitmap* fOffScreenBits; BView* fOffScreenView; - +#endif + thumb_style fStyle; - + BPoint fLocation; BPoint fInitialLocation; - + orientation fOrientation; float fBarThickness; - + +#if USE_OFF_SCREEN_VIEW uint32 _reserved[8]; +#else + uint32 _reserved[10]; +#endif }; //------------------------------------------------------------------------------ diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp index 349470616a..54e2e6c3aa 100644 --- a/src/kits/interface/Slider.cpp +++ b/src/kits/interface/Slider.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS +// Copyright (c) 2001-2005, Haiku // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -21,6 +21,7 @@ // // File Name: Slider.h // Author: Marc Flerackers (mflerackers@androme.be) +// Stephan Aßmus // Description: BSlider creates and displays a sliding thumb control. //------------------------------------------------------------------------------ @@ -29,11 +30,13 @@ #include // System Includes ------------------------------------------------------------- -#include -#include -#include #include #include +#include +#include +#include + +#include // Project Includes ------------------------------------------------------------ @@ -42,12 +45,14 @@ // Local Defines --------------------------------------------------------------- // Globals --------------------------------------------------------------------- -rgb_color _long_to_color_(int32 color) +rgb_color +_long_to_color_(int32 color) { return *((rgb_color*)&color); } -int32 _color_to_long_(rgb_color color) +int32 +_color_to_long_(rgb_color color) { return *((int32*)&color); } @@ -84,6 +89,8 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes UseFillColor(false, NULL); _InitObject(); + + ResizeToPreferred(); } //------------------------------------------------------------------------------ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, @@ -117,12 +124,16 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes UseFillColor(false, NULL); _InitObject(); + + ResizeToPreferred(); } //------------------------------------------------------------------------------ BSlider::~BSlider() { +#if USE_OFF_SCREEN_VIEW if (fOffScreenBits) delete fOffScreenBits; +#endif if (fModificationMessage) delete fModificationMessage; @@ -153,8 +164,7 @@ BSlider::BSlider(BMessage *archive) int32 color; - if(archive->FindInt32("_fcolor", &color) == B_OK) - { + if (archive->FindInt32("_fcolor", &color) == B_OK) { rgb_color fillColor = _long_to_color_(color); UseFillColor(true, &fillColor); } @@ -206,8 +216,7 @@ BSlider::BSlider(BMessage *archive) if(archive->FindInt32("_bcolor", &color) == B_OK) SetBarColor(_long_to_color_(color)); - else - { + else { if (Style() == B_BLOCK_THUMB) SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_4_TINT)); @@ -226,7 +235,8 @@ BSlider::BSlider(BMessage *archive) _InitObject(); } //------------------------------------------------------------------------------ -BArchivable *BSlider::Instantiate(BMessage *archive) +BArchivable* +BSlider::Instantiate(BMessage *archive) { if (validate_instantiation(archive, "BSlider")) return new BSlider(archive); @@ -234,7 +244,8 @@ BArchivable *BSlider::Instantiate(BMessage *archive) return NULL; } //------------------------------------------------------------------------------ -status_t BSlider::Archive(BMessage *archive, bool deep) const +status_t +BSlider::Archive(BMessage *archive, bool deep) const { BControl::Archive(archive, deep); @@ -272,26 +283,29 @@ status_t BSlider::Archive(BMessage *archive, bool deep) const return B_OK; } //------------------------------------------------------------------------------ -status_t BSlider::Perform(perform_code d, void *arg) +status_t +BSlider::Perform(perform_code d, void *arg) { return BControl::Perform(d, arg); } //------------------------------------------------------------------------------ -void BSlider::WindowActivated(bool state) +void +BSlider::WindowActivated(bool state) { BControl::WindowActivated(state); } //------------------------------------------------------------------------------ -void BSlider::AttachedToWindow() +void +BSlider::AttachedToWindow() { ResizeToPreferred(); fLocation.Set(9.0f, 0.0f); +#if USE_OFF_SCREEN_VIEW BRect bounds(Bounds()); - if (!fOffScreenView) - { + if (!fOffScreenView) { fOffScreenView = new BView(bounds, "", B_FOLLOW_ALL, B_WILL_DRAW); BFont font; @@ -299,65 +313,77 @@ void BSlider::AttachedToWindow() fOffScreenView->SetFont(&font); } - if (!fOffScreenBits) - { - // TODO: should use B_CMAP8 + if (!fOffScreenBits) { fOffScreenBits = new BBitmap(bounds, B_CMAP8, true, false); if (fOffScreenBits && fOffScreenView) fOffScreenBits->AddChild(fOffScreenView); - } - else if (fOffScreenView) + + } else if (fOffScreenView) fOffScreenBits->AddChild(fOffScreenView); +#endif // USE_OFF_SCREEN_VIEW SetValue(Value()); - if (fOffScreenView && Parent()) - { - rgb_color color = Parent()->ViewColor(); - - fOffScreenBits->Lock(); - fOffScreenView->SetViewColor(color); - fOffScreenView->SetLowColor(color); - fOffScreenBits->Unlock(); - } + BView* view = OffscreenView(); BControl::AttachedToWindow(); + + if (view && Parent()) { + rgb_color color = Parent()->ViewColor(); + +/* fOffScreenBits->Lock(); + fOffScreenView->SetViewColor(color); + fOffScreenView->SetLowColor(color); + fOffScreenBits->Unlock();*/ + + view->LockLooper(); + view->SetViewColor(B_TRANSPARENT_COLOR); + view->SetLowColor(color); + view->UnlockLooper(); + } } //------------------------------------------------------------------------------ -void BSlider::AllAttached() +void +BSlider::AllAttached() { BControl::AllAttached(); } //------------------------------------------------------------------------------ -void BSlider::AllDetached() +void +BSlider::AllDetached() { BControl::AllDetached(); } //------------------------------------------------------------------------------ -void BSlider::DetachedFromWindow() +void +BSlider::DetachedFromWindow() { BControl::DetachedFromWindow(); - if (fOffScreenBits) - { +#if USE_OFF_SCREEN_VIEW + if (fOffScreenBits) { delete fOffScreenBits; fOffScreenBits = NULL; fOffScreenView = NULL; } +#endif } //------------------------------------------------------------------------------ -void BSlider::MessageReceived(BMessage *msg) +void +BSlider::MessageReceived(BMessage *msg) { BSlider::MessageReceived(msg); } //------------------------------------------------------------------------------ -void BSlider::FrameMoved(BPoint new_position) +void +BSlider::FrameMoved(BPoint new_position) { BSlider::FrameMoved(new_position); } //------------------------------------------------------------------------------ -void BSlider::FrameResized(float w,float h) +void +BSlider::FrameResized(float w,float h) { BControl::FrameResized(w, h); @@ -366,8 +392,8 @@ void BSlider::FrameResized(float w,float h) if (bounds.right <= 0.0f || bounds.bottom <= 0.0f) return; - if (fOffScreenBits) - { +#if USE_OFF_SCREEN_VIEW + if (fOffScreenBits) { fOffScreenBits->RemoveChild(fOffScreenView); delete fOffScreenBits; @@ -376,28 +402,27 @@ void BSlider::FrameResized(float w,float h) fOffScreenBits = new BBitmap(Bounds(), B_CMAP8, true, false); fOffScreenBits->AddChild(fOffScreenView); } +#endif SetValue(Value()); // virtual } //------------------------------------------------------------------------------ -void BSlider::KeyDown(const char *bytes, int32 numBytes) +void +BSlider::KeyDown(const char *bytes, int32 numBytes) { if (!IsEnabled() || IsHidden()) return; - switch (bytes[0]) - { + switch (bytes[0]) { case B_LEFT_ARROW: - case B_DOWN_ARROW: - { + case B_DOWN_ARROW: { SetValue(Value() - KeyIncrementValue()); Invoke(); break; } case B_RIGHT_ARROW: - case B_UP_ARROW: - { + case B_UP_ARROW: { SetValue(Value() + KeyIncrementValue()); Invoke(); break; @@ -407,7 +432,8 @@ void BSlider::KeyDown(const char *bytes, int32 numBytes) } } //------------------------------------------------------------------------------ -void BSlider::MouseDown(BPoint point) +void +BSlider::MouseDown(BPoint point) { if (!IsEnabled()) return; @@ -420,15 +446,12 @@ void BSlider::MouseDown(BPoint point) GetMouse(&pt, &buttons, true); - if (fOrientation == B_HORIZONTAL) - { + if (fOrientation == B_HORIZONTAL) { if (pt.x < _MinPosition()) pt.x = _MinPosition(); else if (pt.x > _MaxPosition()) pt.x = _MaxPosition(); - } - else - { + } else { if (pt.y > _MinPosition()) pt.y = _MinPosition(); else if (pt.y < _MaxPosition()) @@ -439,28 +462,23 @@ void BSlider::MouseDown(BPoint point) //virtual InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); - if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) - { + if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) { SetTracking(true); SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); - } - else - { + } else { + // synchronous mouse tracking BPoint prevPt; bool update; - while (buttons) - { + while (buttons) { prevPt = pt; update = false; snooze(SnoozeAmount()); GetMouse(&pt, &buttons, true); - if (fOrientation == B_HORIZONTAL) - { - if (pt.x != prevPt.x) - { + if (fOrientation == B_HORIZONTAL) { + if (pt.x != prevPt.x) { update = true; if (pt.x < _MinPosition()) @@ -468,11 +486,8 @@ void BSlider::MouseDown(BPoint point) else if (pt.x > _MaxPosition()) pt.x = _MaxPosition(); } - } - else - { - if (pt.y != prevPt.y) - { + } else { + if (pt.y != prevPt.y) { update = true; if (pt.y > _MinPosition()) @@ -482,8 +497,7 @@ void BSlider::MouseDown(BPoint point) } } - if (update) - { + if (update) { SetValue(ValueForPoint(pt)); //virtual InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); @@ -491,37 +505,32 @@ void BSlider::MouseDown(BPoint point) } } - if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) == 0) - { + if ((Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) == 0) { if (_Location() != fInitialLocation) Invoke(); } } //------------------------------------------------------------------------------ -void BSlider::MouseUp(BPoint point) +void +BSlider::MouseUp(BPoint point) { - if (IsTracking()) - { + if (IsTracking()) { if (_Location() != fInitialLocation) Invoke(); SetTracking(false); - } - else + } else BControl::MouseUp(point); } //------------------------------------------------------------------------------ void BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message) { - if (IsTracking()) - { + if (IsTracking()) { BPoint loc = _Location(); bool update = false; - if (fOrientation == B_HORIZONTAL) - { - if (point.x != loc.x) - { + if (fOrientation == B_HORIZONTAL) { + if (point.x != loc.x) { update = true; if (point.x < _MinPosition()) @@ -529,11 +538,8 @@ void BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message) else if (point.x > _MaxPosition()) point.x = _MaxPosition(); } - } - else - { - if (point.y != loc.y) - { + } else { + if (point.y != loc.y) { update = true; if (point.y < _MinPosition()) @@ -543,8 +549,7 @@ void BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message) } } - if (update) - { + if (update) { SetValue(ValueForPoint(point)); //virtual } @@ -556,84 +561,95 @@ void BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message) BControl::MouseMoved(point, transit, message); } //------------------------------------------------------------------------------ -void BSlider::Pulse() +void +BSlider::Pulse() { BControl::Pulse(); } //------------------------------------------------------------------------------ -void BSlider::SetLabel(const char *label) +void +BSlider::SetLabel(const char *label) { BControl::SetLabel(label); } //------------------------------------------------------------------------------ -void BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel) +void +BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel) { - if (minLabel) - { + if (minLabel) { if (fMinLimitStr) free(fMinLimitStr); fMinLimitStr = strdup(minLabel); } - if (maxLabel) - { + if (maxLabel) { if (fMaxLimitStr) free(fMaxLimitStr); fMaxLimitStr = strdup(maxLabel); } + // TODO: Auto resizing?!? I would not want this as an app programmer! ResizeToPreferred(); Invalidate(); } //------------------------------------------------------------------------------ -const char *BSlider::MinLimitLabel() const +const char* +BSlider::MinLimitLabel() const { return fMinLimitStr; } //------------------------------------------------------------------------------ -const char *BSlider::MaxLimitLabel() const +const char* +BSlider::MaxLimitLabel() const { return fMaxLimitStr; } //------------------------------------------------------------------------------ -void BSlider::SetValue(int32 value) +void +BSlider::SetValue(int32 value) { if (value < fMinValue) value = fMinValue; if (value > fMaxValue) value = fMaxValue; - BPoint loc; - float pos = (float)(value - fMinValue) / (float)(fMaxValue - fMinValue) * - _MaxPosition() - _MinPosition(); - - if (fOrientation == B_HORIZONTAL) - { - loc.x = ceil(_MinPosition() + pos); - loc.y = 0; + if (value != Value()) { + BPoint loc; + float pos = (float)(value - fMinValue) / (float)(fMaxValue - fMinValue) * + _MaxPosition() - _MinPosition(); + + if (fOrientation == B_HORIZONTAL) { + loc.x = ceil(_MinPosition() + pos); + loc.y = 0; + } else { + loc.x = 0; + loc.y = floor(_MaxPosition() - pos); + } + + BRect oldThumbFrame = ThumbFrame(); + + _SetLocation(loc); + + BControl::SetValue(value); + + Invalidate(oldThumbFrame | ThumbFrame()); } - else - { - loc.x = 0; - loc.y = floor(_MaxPosition() - pos); - } - - _SetLocation(loc); - - BControl::SetValue(value); } //------------------------------------------------------------------------------ -int32 BSlider::ValueForPoint(BPoint location) const +int32 +BSlider::ValueForPoint(BPoint location) const { - if (fOrientation == B_HORIZONTAL) + if (fOrientation == B_HORIZONTAL) { return (int32)((location.x - _MinPosition()) * (fMaxValue - fMinValue) / (_MaxPosition() - _MinPosition())) + fMinValue; - else + } else { return (int32)((location.y - _MinPosition()) * (fMaxValue - fMinValue) / (_MaxPosition() - _MinPosition())) + fMinValue; + } } //------------------------------------------------------------------------------ -void BSlider::SetPosition(float position) +void +BSlider::SetPosition(float position) { if (position <= 0.0f) BControl::SetValue(fMinValue); @@ -643,198 +659,236 @@ void BSlider::SetPosition(float position) BControl::SetValue((int32)(position * (fMaxValue - fMinValue) + fMinValue)); } //------------------------------------------------------------------------------ -float BSlider::Position() const +float +BSlider::Position() const { return ((float)(Value() - fMinValue) / (float)(fMaxValue - fMinValue)); } //------------------------------------------------------------------------------ -void BSlider::SetEnabled(bool on) +void +BSlider::SetEnabled(bool on) { BControl::SetEnabled(on); } //------------------------------------------------------------------------------ -void BSlider::GetLimits(int32 *minimum, int32 *maximum) +void +BSlider::GetLimits(int32 *minimum, int32 *maximum) { *minimum = fMinValue; *maximum = fMaxValue; } //------------------------------------------------------------------------------ -void BSlider::Draw(BRect updateRect) +void +BSlider::Draw(BRect updateRect) { + // clear out background + BRegion background(updateRect); + background.Exclude(BarFrame()); + background.Exclude(ThumbFrame()); + if (background.Frame().IsValid()) + OffscreenView()->FillRegion(&background, B_SOLID_LOW); + DrawSlider(); } //------------------------------------------------------------------------------ -void BSlider::DrawSlider() +void +BSlider::DrawSlider() { +#if USE_OFF_SCREEN_VIEW if (!fOffScreenBits) return; +#endif - if (fOffScreenBits->Lock()) - { - OffscreenView()->SetHighColor(ViewColor()); - OffscreenView()->FillRect(Bounds()); - +#if USE_OFF_SCREEN_VIEW + if (fOffScreenBits->Lock()) { +#endif DrawBar(); DrawHashMarks(); DrawThumb(); DrawFocusMark(); DrawText(); - OffscreenView()->Sync(); + +#if USE_OFF_SCREEN_VIEW + fOffscreenView->Sync(); DrawBitmap(fOffScreenBits, B_ORIGIN); fOffScreenBits->Unlock(); } +#endif } //------------------------------------------------------------------------------ -void BSlider::DrawBar() +void +BSlider::DrawBar() { BRect frame = BarFrame(); BView *view = OffscreenView(); - if (fUseFillColor) - { - if (fOrientation == B_HORIZONTAL) - { - view->SetHighColor(fBarColor); + rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); + rgb_color lightenmax; + rgb_color darken1; + rgb_color darken2; + rgb_color darkenmax; + + rgb_color barColor; + rgb_color fillColor; + + if (IsEnabled()) { + lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); + darken1 = tint_color(no_tint, B_DARKEN_1_TINT); + darken2 = tint_color(no_tint, B_DARKEN_2_TINT); + darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); + barColor = fBarColor; + fillColor = fFillColor; + } else { + lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); + darken1 = no_tint; + darken2 = tint_color(no_tint, B_DARKEN_1_TINT); + darkenmax = tint_color(no_tint, B_DARKEN_3_TINT); + + barColor.red = (fBarColor.red + no_tint.red) / 2; + barColor.green = (fBarColor.green + no_tint.green) / 2; + barColor.blue = (fBarColor.blue + no_tint.blue) / 2; + + fillColor.red = (fFillColor.red + no_tint.red) / 2; + fillColor.green = (fFillColor.green + no_tint.green) / 2; + fillColor.blue = (fFillColor.blue + no_tint.blue) / 2; + } + + if (fUseFillColor) { + if (fOrientation == B_HORIZONTAL) { + view->SetHighColor(barColor); view->FillRect(BRect((float)floor(frame.left + 1 + Position() * (frame.Width() - 2)), frame.top, frame.right, frame.bottom)); - view->SetHighColor(fFillColor); + view->SetHighColor(fillColor); view->FillRect(BRect(frame.left, frame.top, (float)floor(frame.left + 1 + Position() * (frame.Width() - 2)), frame.bottom)); - } - else - { - view->SetHighColor(fBarColor); + } else { + view->SetHighColor(barColor); view->FillRect(BRect(frame.left, frame.top, frame.right, (float)floor(frame.bottom - 1 - Position() * (frame.Height() - 2)))); - view->SetHighColor(fFillColor); + view->SetHighColor(fillColor); view->FillRect(BRect(frame.left, (float)floor(frame.bottom - 1 - Position() * (frame.Height() - 2)), frame.right, frame.bottom)); } - } - else - { - view->SetHighColor(fBarColor); + } else { + view->SetHighColor(barColor); view->FillRect(frame); } - rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), - lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), - darken1 = tint_color(no_tint, B_DARKEN_1_TINT), - darken2 = tint_color(no_tint, B_DARKEN_2_TINT), - darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); - view->SetHighColor(darken1); view->StrokeLine(BPoint(frame.left, frame.top), - BPoint(frame.left + 1.0f, frame.top)); + BPoint(frame.left + 1.0f, frame.top)); view->StrokeLine(BPoint(frame.left, frame.bottom), - BPoint(frame.left + 1.0f, frame.bottom)); + BPoint(frame.left + 1.0f, frame.bottom)); view->StrokeLine(BPoint(frame.right - 1.0f, frame.top), - BPoint(frame.right, frame.top)); + BPoint(frame.right, frame.top)); view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), - BPoint(frame.right - 1.0f, frame.top)); + BPoint(frame.right - 1.0f, frame.top)); view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f), - BPoint(frame.left, frame.top + 1.0f)); + BPoint(frame.left, frame.top + 1.0f)); view->SetHighColor(lightenmax); view->StrokeLine(BPoint(frame.left + 1.0f, frame.bottom), - BPoint(frame.right, frame.bottom)); - view->StrokeLine(BPoint(frame.right, frame.top + 1.0f)); + BPoint(frame.right, frame.bottom)); + view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), + BPoint(frame.right, frame.top + 1.0f)); frame.InsetBy(1.0f, 1.0f); view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.left, frame.bottom), - BPoint(frame.left, frame.top)); - view->StrokeLine(BPoint(frame.right, frame.top)); + BPoint(frame.left, frame.top)); + view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), + BPoint(frame.right, frame.top)); } //------------------------------------------------------------------------------ -void BSlider::DrawHashMarks() +void +BSlider::DrawHashMarks() { BRect frame = HashMarksFrame(); BView *view = OffscreenView(); - rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), - lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), - darken2 = tint_color(no_tint, B_DARKEN_2_TINT); + + rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); + rgb_color lightenmax; + rgb_color darken2; + + if (IsEnabled()) { + lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); + darken2 = tint_color(no_tint, B_DARKEN_2_TINT); + } else { + lightenmax = tint_color(no_tint, B_LIGHTEN_2_TINT); + darken2 = tint_color(no_tint, B_DARKEN_1_TINT); + } float pos = _MinPosition(); float factor = (_MaxPosition() - pos) / (fHashMarkCount - 1); - if (fHashMarks & B_HASH_MARKS_TOP) - { - if (fOrientation == B_HORIZONTAL) - { - for (int32 i = 0; i < fHashMarkCount; i++) - { - view->SetHighColor(darken2); - view->StrokeLine(BPoint(pos, frame.top), - BPoint(pos, frame.top + 5)); - view->SetHighColor(lightenmax); - view->StrokeLine(BPoint(pos + 1, frame.top), - BPoint(pos + 1, frame.top + 5)); + if (fHashMarks & B_HASH_MARKS_TOP) { + + view->BeginLineArray(fHashMarkCount * 2); + + if (fOrientation == B_HORIZONTAL) { + for (int32 i = 0; i < fHashMarkCount; i++) { + view->AddLine(BPoint(pos, frame.top), + BPoint(pos, frame.top + 5), darken2); + view->AddLine(BPoint(pos + 1, frame.top), + BPoint(pos + 1, frame.top + 5), lightenmax); + + pos += factor; + } + } else { + for (int32 i = 0; i < fHashMarkCount; i++) { + view->AddLine(BPoint(frame.left, pos), + BPoint(frame.left + 5, pos), darken2); + view->AddLine(BPoint(frame.left, pos + 1), + BPoint(frame.left + 5, pos + 1), lightenmax); pos += factor; } } - else - { - for (int32 i = 0; i < fHashMarkCount; i++) - { - view->SetHighColor(darken2); - view->StrokeLine(BPoint(frame.left, pos), - BPoint(frame.left + 5, pos)); - view->SetHighColor(lightenmax); - view->StrokeLine(BPoint(frame.left, pos + 1), - BPoint(frame.left + 5, pos + 1)); - pos += factor; - } - } + view->EndLineArray(); } pos = _MinPosition(); - if (fHashMarks & B_HASH_MARKS_BOTTOM) - { - if (fOrientation == B_HORIZONTAL) - { - for (int32 i = 0; i < fHashMarkCount; i++) - { - view->SetHighColor(darken2); - view->StrokeLine(BPoint(pos, frame.bottom - 5), - BPoint(pos, frame.bottom)); - view->SetHighColor(lightenmax); - view->StrokeLine(BPoint(pos + 1, frame.bottom - 5), - BPoint(pos + 1, frame.bottom)); + if (fHashMarks & B_HASH_MARKS_BOTTOM) { + + view->BeginLineArray(fHashMarkCount * 2); + + if (fOrientation == B_HORIZONTAL) { + for (int32 i = 0; i < fHashMarkCount; i++) { + view->AddLine(BPoint(pos, frame.bottom - 5), + BPoint(pos, frame.bottom), darken2); + view->AddLine(BPoint(pos + 1, frame.bottom - 5), + BPoint(pos + 1, frame.bottom), lightenmax); + + pos += factor; + } + } else { + for (int32 i = 0; i < fHashMarkCount; i++) { + view->AddLine(BPoint(frame.right - 5, pos), + BPoint(frame.right, pos), darken2); + view->AddLine(BPoint(frame.right - 5, pos + 1), + BPoint(frame.right, pos + 1), lightenmax); pos += factor; } } - else - { - for (int32 i = 0; i < fHashMarkCount; i++) - { - view->SetHighColor(darken2); - view->StrokeLine(BPoint(frame.right - 5, pos), - BPoint(frame.right, pos)); - view->SetHighColor(lightenmax); - view->StrokeLine(BPoint(frame.right - 5, pos + 1), - BPoint(frame.right, pos + 1)); - pos += factor; - } - } + view->EndLineArray(); } } //------------------------------------------------------------------------------ -void BSlider::DrawThumb() +void +BSlider::DrawThumb() { if (Style() == B_BLOCK_THUMB) _DrawBlockThumb(); @@ -842,7 +896,8 @@ void BSlider::DrawThumb() _DrawTriangleThumb(); } //------------------------------------------------------------------------------ -void BSlider::DrawFocusMark() +void +BSlider::DrawFocusMark() { if (!IsFocus()) return; @@ -851,39 +906,41 @@ void BSlider::DrawFocusMark() BRect frame = ThumbFrame(); - if (fStyle == B_BLOCK_THUMB) - { + if (fStyle == B_BLOCK_THUMB) { frame.left += 2.0f; frame.top += 2.0f; frame.right -= 3.0f; frame.bottom -= 3.0f; OffscreenView()->StrokeRect(frame); - } - else - { - if (fOrientation == B_HORIZONTAL) + } else { + if (fOrientation == B_HORIZONTAL) { OffscreenView()->StrokeLine(BPoint(frame.left, frame.bottom + 3.0f), BPoint(frame.right, frame.bottom + 3.0f)); - else + } else { OffscreenView()->StrokeLine(BPoint(frame.left - 2.0f, frame.top), BPoint(frame.left - 2.0f, frame.bottom)); + } } } //------------------------------------------------------------------------------ -void BSlider::DrawText() +void +BSlider::DrawText() { BRect bounds(Bounds()); BView *view = OffscreenView(); - view->SetHighColor(0, 0, 0); + if (IsEnabled()) { + view->SetHighColor(0, 0, 0); + } else { + view->SetHighColor(tint_color(LowColor(), B_DISABLED_LABEL_TINT)); + } font_height fheight; GetFontHeight(&fheight); - if (Orientation() == B_HORIZONTAL) - { + if (Orientation() == B_HORIZONTAL) { if (Label()) view->DrawString(Label(), BPoint(2.0f, (float)ceil(fheight.ascent))); @@ -892,34 +949,38 @@ void BSlider::DrawText() if (fMaxLimitStr) view->DrawString(fMaxLimitStr, BPoint(bounds.right - - StringWidth(fMaxLimitStr) - 2.0f, bounds.bottom - 4.0f)); - } - else - { + StringWidth(fMaxLimitStr) - 2.0f, + bounds.bottom - 4.0f)); + } else { float ascent = (float)ceil(fheight.ascent); if (Label()) view->DrawString(Label(), BPoint(bounds.Width() / 2.0f - - StringWidth(Label()) / 2.0f, ascent)); + StringWidth(Label()) / 2.0f, + ascent)); if (fMaxLimitStr) view->DrawString(fMaxLimitStr, BPoint(bounds.Width() / 2.0f - - StringWidth(fMaxLimitStr) / 2.0f, ascent + - (Label() ? (float)ceil(ascent + fheight.descent + 2.0f) : 0.0f))); + StringWidth(fMaxLimitStr) / 2.0f, + ascent + + (Label() ? (float)ceil(ascent + fheight.descent + 2.0f) + : 0.0f))); if (fMinLimitStr) view->DrawString(fMinLimitStr, BPoint(bounds.Width() / 2.0f - - StringWidth(fMinLimitStr) / 2.0f, - bounds.bottom - 2.0f)); + StringWidth(fMinLimitStr) / 2.0f, + bounds.bottom - 2.0f)); } } //------------------------------------------------------------------------------ -char *BSlider::UpdateText() const +char* +BSlider::UpdateText() const { return NULL; } //------------------------------------------------------------------------------ -BRect BSlider::BarFrame() const +BRect +BSlider::BarFrame() const { BRect frame(Bounds()); font_height fheight; @@ -928,18 +989,14 @@ BRect BSlider::BarFrame() const float textHeight = (float)ceil(fheight.ascent + fheight.descent); - if (fStyle == B_BLOCK_THUMB) - { - if (Orientation() == B_HORIZONTAL) - { + if (fStyle == B_BLOCK_THUMB) { + if (Orientation() == B_HORIZONTAL) { frame.left = 8.0f; frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.right -= 8.0f; frame.bottom = frame.bottom - 6.0f - (fMinLimitStr || fMaxLimitStr ? textHeight + 4.0f : 0.0f); - } - else - { + } else { frame.left = frame.Width() / 2.0f - 3; frame.top = 12.0f + (Label() ? textHeight : 0.0f) + (fMaxLimitStr ? textHeight : 0.0f); @@ -947,19 +1004,14 @@ BRect BSlider::BarFrame() const frame.bottom = frame.bottom - 8.0f - (fMinLimitStr ? textHeight + 4 : 0.0f); } - } - else - { - if (Orientation() == B_HORIZONTAL) - { + } else { + if (Orientation() == B_HORIZONTAL) { frame.left = 7.0f; frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.right -= 7.0f; frame.bottom = frame.bottom - 6.0f - (fMinLimitStr || fMaxLimitStr ? textHeight + 4.0f : 0.0f); - } - else - { + } else { frame.left = frame.Width() / 2.0f - 3; frame.top = 11.0f + (Label() ? textHeight : 0.0f) + (fMaxLimitStr ? textHeight : 0.0f); @@ -972,17 +1024,15 @@ BRect BSlider::BarFrame() const return frame; } //------------------------------------------------------------------------------ -BRect BSlider::HashMarksFrame() const +BRect +BSlider::HashMarksFrame() const { BRect frame(BarFrame()); - if (fOrientation == B_HORIZONTAL) - { + if (fOrientation == B_HORIZONTAL) { frame.top -= 6.0f; frame.bottom += 6.0f; - } - else - { + } else { frame.left -= 6.0f; frame.right += 6.0f; } @@ -990,8 +1040,13 @@ BRect BSlider::HashMarksFrame() const return frame; } //------------------------------------------------------------------------------ -BRect BSlider::ThumbFrame() const +BRect +BSlider::ThumbFrame() const { + // TODO: The slider looks really ugly and broken when it is too little. + // I would suggest using BarFrame() here to get the top and bottom coords + // and spread them further apart for the thumb + BRect frame = Bounds(); font_height fheight; @@ -999,39 +1054,30 @@ BRect BSlider::ThumbFrame() const float textHeight = (float)ceil(fheight.ascent + fheight.descent); - if (fStyle == B_BLOCK_THUMB) - { - if (Orientation() == B_HORIZONTAL) - { + if (fStyle == B_BLOCK_THUMB) { + if (Orientation() == B_HORIZONTAL) { frame.left = (float)floor(Position() * (_MaxPosition() - _MinPosition()) + _MinPosition()) - 8.0f; frame.top = 2.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.right = frame.left + 17.0f; frame.bottom = frame.bottom - 3.0f - (MinLimitLabel() || MaxLimitLabel() ? textHeight + 4.0f : 0.0f); - } - else - { + } else { frame.left = frame.Width() / 2.0f - 7; frame.top = (float)floor(Position() * (_MaxPosition() - _MinPosition()) + _MinPosition()) - 8.0f; frame.right = frame.left + 13; frame.bottom = frame.top + 17; } - } - else - { - if (Orientation() == B_HORIZONTAL) - { + } else { + if (Orientation() == B_HORIZONTAL) { frame.left = (float)floor(Position() * (_MaxPosition() - _MinPosition()) + _MinPosition()) - 6; frame.top = 9.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.right = frame.left + 12.0f; frame.bottom = frame.bottom - 3.0f - (MinLimitLabel() || MaxLimitLabel() ? textHeight + 4.0f : 0.0f); - } - else - { + } else { frame.left = frame.Width() / 2.0f - 6; frame.top = (float)floor(Position() * (_MaxPosition() - _MinPosition())) + _MinPosition() - 6.0f; @@ -1043,24 +1089,26 @@ BRect BSlider::ThumbFrame() const return frame; } //------------------------------------------------------------------------------ -void BSlider::SetFlags(uint32 flags) +void +BSlider::SetFlags(uint32 flags) { BControl::SetFlags(flags); } //------------------------------------------------------------------------------ -void BSlider::SetResizingMode(uint32 mode) +void +BSlider::SetResizingMode(uint32 mode) { BControl::SetResizingMode(mode); } //------------------------------------------------------------------------------ -void BSlider::GetPreferredSize(float *width, float *height) +void +BSlider::GetPreferredSize(float *width, float *height) { font_height fheight; GetFontHeight(&fheight); - if (Orientation() == B_HORIZONTAL) - { + if (Orientation() == B_HORIZONTAL) { *width = (Frame().Width() < 32.0f) ? 32.0f : Frame().Width(); *height = 18.0f; @@ -1069,9 +1117,7 @@ void BSlider::GetPreferredSize(float *width, float *height) if (MinLimitLabel() || MaxLimitLabel()) *height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f; - } - else // B_VERTICAL - { + } else { // B_VERTICAL *width = (Frame().Width() < 18.0f) ? 18.0f : Frame().Width(); *height = 32.0f; @@ -1091,30 +1137,35 @@ void BSlider::GetPreferredSize(float *width, float *height) } } //------------------------------------------------------------------------------ -void BSlider::ResizeToPreferred() +void +BSlider::ResizeToPreferred() { BControl::ResizeToPreferred(); } //------------------------------------------------------------------------------ -status_t BSlider::Invoke(BMessage *msg) +status_t +BSlider::Invoke(BMessage *msg) { return BControl::Invoke(msg); } //------------------------------------------------------------------------------ -BHandler *BSlider::ResolveSpecifier(BMessage *message, int32 index, - BMessage *specifier, int32 command, - const char *property) +BHandler* +BSlider::ResolveSpecifier(BMessage *message, int32 index, + BMessage *specifier, int32 command, + const char *property) { - return BControl::ResolveSpecifier(message, index, specifier, command, - property); + return BControl::ResolveSpecifier(message, index, specifier, + command, property); } //------------------------------------------------------------------------------ -status_t BSlider::GetSupportedSuites(BMessage *message) +status_t +BSlider::GetSupportedSuites(BMessage *message) { return BControl::GetSupportedSuites(message); } //------------------------------------------------------------------------------ -void BSlider::SetModificationMessage(BMessage *message) +void +BSlider::SetModificationMessage(BMessage *message) { if (fModificationMessage) delete fModificationMessage; @@ -1122,12 +1173,14 @@ void BSlider::SetModificationMessage(BMessage *message) fModificationMessage = message; } //------------------------------------------------------------------------------ -BMessage *BSlider::ModificationMessage() const +BMessage* +BSlider::ModificationMessage() const { return fModificationMessage; } //------------------------------------------------------------------------------ -void BSlider::SetSnoozeAmount(int32 snooze_time) +void +BSlider::SetSnoozeAmount(int32 snooze_time) { if (snooze_time < 5000) snooze_time = 5000; @@ -1137,72 +1190,89 @@ void BSlider::SetSnoozeAmount(int32 snooze_time) fSnoozeAmount = snooze_time; } //------------------------------------------------------------------------------ -int32 BSlider::SnoozeAmount() const +int32 +BSlider::SnoozeAmount() const { return fSnoozeAmount; } //------------------------------------------------------------------------------ -void BSlider::SetKeyIncrementValue(int32 increment_value) +void +BSlider::SetKeyIncrementValue(int32 increment_value) { fKeyIncrementValue = increment_value; } //------------------------------------------------------------------------------ -int32 BSlider::KeyIncrementValue() const +int32 +BSlider::KeyIncrementValue() const { return fKeyIncrementValue; } //------------------------------------------------------------------------------ -void BSlider::SetHashMarkCount(int32 hash_mark_count) +void +BSlider::SetHashMarkCount(int32 hash_mark_count) { fHashMarkCount = hash_mark_count; Invalidate(); } //------------------------------------------------------------------------------ -int32 BSlider::HashMarkCount() const +int32 +BSlider::HashMarkCount() const { return fHashMarkCount; } //------------------------------------------------------------------------------ -void BSlider::SetHashMarks(hash_mark_location where) +void +BSlider::SetHashMarks(hash_mark_location where) { fHashMarks = where; Invalidate(); } //------------------------------------------------------------------------------ -hash_mark_location BSlider::HashMarks() const +hash_mark_location +BSlider::HashMarks() const { return fHashMarks; } //------------------------------------------------------------------------------ -void BSlider::SetStyle(thumb_style style) +void +BSlider::SetStyle(thumb_style style) { fStyle = style; + Invalidate(); } //------------------------------------------------------------------------------ -thumb_style BSlider::Style() const +thumb_style +BSlider::Style() const { return fStyle; } //------------------------------------------------------------------------------ -void BSlider::SetBarColor(rgb_color bar_color) +void +BSlider::SetBarColor(rgb_color bar_color) { fBarColor = bar_color; + Invalidate(); } //------------------------------------------------------------------------------ -rgb_color BSlider::BarColor() const +rgb_color +BSlider::BarColor() const { return fBarColor; } //------------------------------------------------------------------------------ -void BSlider::UseFillColor(bool use_fill, const rgb_color *bar_color) +void +BSlider::UseFillColor(bool use_fill, const rgb_color *bar_color) { fUseFillColor = use_fill; if (use_fill && bar_color) fFillColor = *bar_color; + + Invalidate(); } //------------------------------------------------------------------------------ -bool BSlider::FillColor(rgb_color *bar_color) const +bool +BSlider::FillColor(rgb_color *bar_color) const { if (bar_color && fUseFillColor) *bar_color = fFillColor; @@ -1210,128 +1280,200 @@ bool BSlider::FillColor(rgb_color *bar_color) const return fUseFillColor; } //------------------------------------------------------------------------------ -BView *BSlider::OffscreenView() const +BView* +BSlider::OffscreenView() const { +#if USE_OFF_SCREEN_VIEW return fOffScreenView; +#else + return (BView*)this; +#endif } //------------------------------------------------------------------------------ -orientation BSlider::Orientation() const +orientation +BSlider::Orientation() const { return fOrientation; } //------------------------------------------------------------------------------ -void BSlider::SetOrientation(orientation posture) +void +BSlider::SetOrientation(orientation posture) { fOrientation = posture; + Invalidate(); } //------------------------------------------------------------------------------ -float BSlider::BarThickness() const +float +BSlider::BarThickness() const { return fBarThickness; } //------------------------------------------------------------------------------ -void BSlider::SetBarThickness(float thickness) +void +BSlider::SetBarThickness(float thickness) { fBarThickness = thickness; } //------------------------------------------------------------------------------ -void BSlider::SetFont(const BFont *font, uint32 properties) +void +BSlider::SetFont(const BFont *font, uint32 properties) { BControl::SetFont(font, properties); - if (fOffScreenView && fOffScreenBits) - { - if (fOffScreenBits->Lock()) - { +#if USE_OFF_SCREEN_VIEW + if (fOffScreenView && fOffScreenBits) { + if (fOffScreenBits->Lock()) { fOffScreenView->SetFont(font, properties); fOffScreenBits->Unlock(); } } +#endif } //------------------------------------------------------------------------------ #ifdef __HAIKU__ void BSlider::SetLimits(int32 minimum, int32 maximum) { - // TODO: Redraw - fMinValue = minimum; - fMaxValue = maximum; + if (minimum <= maximum) { + fMinValue = minimum; + fMaxValue = maximum; + + int32 value = Value(); + value = max_c(minimum, value); + value = min_c(maximum, value); + + if (value != Value()) { + SetValue(value); + } + } } #endif //------------------------------------------------------------------------------ -void BSlider::_DrawBlockThumb() +void +BSlider::_DrawBlockThumb() { BRect frame = ThumbFrame(); BView *view = OffscreenView(); - rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), - lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT), - darken2 = tint_color(no_tint, B_DARKEN_2_TINT), - darken3 = tint_color(no_tint, B_DARKEN_3_TINT), - darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); + rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); + rgb_color lighten2; + rgb_color lighten1; + rgb_color darken2; + rgb_color darken3; + rgb_color darkenmax; - // Outline + if (IsEnabled()) { + lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT); + lighten1 = no_tint; + darken2 = tint_color(no_tint, B_DARKEN_2_TINT); + darken3 = tint_color(no_tint, B_DARKEN_3_TINT); + darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); + } else { + lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT); + lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT); + darken2 = tint_color(no_tint, (B_NO_TINT + B_DARKEN_1_TINT) / 2.0); + darken3 = tint_color(no_tint, B_DARKEN_1_TINT); + darkenmax = tint_color(no_tint, B_DARKEN_3_TINT); + } + + // blank background for shadow + view->SetHighColor(no_tint); + view->StrokeLine(BPoint(frame.left, frame.top), + BPoint(frame.left, frame.top)); + + BRect barFrame = BarFrame(); + if (barFrame.right >= frame.right) { + // leave out barFrame from shadow background clearing + view->StrokeLine(BPoint(frame.right, frame.top), + BPoint(frame.right, barFrame.top - 1.0f)); + view->StrokeLine(BPoint(frame.right, barFrame.bottom + 1.0f), + BPoint(frame.right, frame.bottom)); + } else { + view->StrokeLine(BPoint(frame.right, frame.top), + BPoint(frame.right, frame.bottom)); + } + + view->StrokeLine(BPoint(frame.left, frame.bottom), + BPoint(frame.right - 1.0f, frame.bottom)); + view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f), + BPoint(frame.left, frame.bottom - 1.0f)); + view->StrokeLine(BPoint(frame.right - 1.0f, frame.top), + BPoint(frame.right - 1.0f, frame.top)); + + // Outline (top, left) view->SetHighColor(darken3); view->StrokeLine(BPoint(frame.left, frame.bottom - 2.0f), - BPoint(frame.left, frame.top + 1.0f)); + BPoint(frame.left, frame.top + 1.0f)); view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), - BPoint(frame.right - 2.0f, frame.top)); + BPoint(frame.right - 2.0f, frame.top)); + + // Shadow + view->SetHighColor(0, 0, 0, IsEnabled() ? 100 : 50); + view->SetDrawingMode(B_OP_ALPHA); view->StrokeLine(BPoint(frame.right, frame.top + 2.0f), - BPoint(frame.right, frame.bottom - 1.0f)); + BPoint(frame.right, frame.bottom - 1.0f)); view->StrokeLine(BPoint(frame.left + 2.0f, frame.bottom), - BPoint(frame.right - 1.0f, frame.bottom)); + BPoint(frame.right - 1.0f, frame.bottom)); + + view->SetDrawingMode(B_OP_COPY); + view->SetHighColor(darken3); + view->StrokeLine(BPoint(frame.right - 1.0f, frame.bottom - 1.0f), + BPoint(frame.right - 1.0f, frame.bottom - 1.0f)); + // First bevel frame.InsetBy(1.0f, 1.0f); - view->SetHighColor(lighten2); - view->FillRect(frame); - view->SetHighColor(darkenmax); view->StrokeLine(BPoint(frame.left, frame.bottom), - BPoint(frame.right - 1.0f, frame.bottom)); - view->StrokeLine(BPoint(frame.right, frame.bottom - 1), - BPoint(frame.right, frame.top)); + BPoint(frame.right - 1.0f, frame.bottom)); + view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), + BPoint(frame.right, frame.top)); + + view->SetHighColor(lighten2); + view->StrokeLine(BPoint(frame.left, frame.top), + BPoint(frame.left, frame.bottom - 1.0f)); + view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), + BPoint(frame.right - 1.0f, frame.top)); frame.InsetBy(1.0f, 1.0f); + view->FillRect(BRect(frame.left, frame.top, frame.right - 1.0f, frame.bottom - 1.0f)); + // Second bevel and center dots view->SetHighColor(darken2); view->StrokeLine(BPoint(frame.left, frame.bottom), - BPoint(frame.right, frame.bottom)); - view->StrokeLine(BPoint(frame.right, frame.top)); + BPoint(frame.right, frame.bottom)); + view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), + BPoint(frame.right, frame.top)); - if (Orientation() == B_HORIZONTAL) - { + if (Orientation() == B_HORIZONTAL) { 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)); 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)); view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f), - BPoint(frame.left + 6.0f, frame.top + 6.0f)); - } - else - { + BPoint(frame.left + 6.0f, frame.top + 6.0f)); + } else { 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)); 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)); 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)); } - view->StrokeLine(BPoint(frame.right + 1.0f, frame.bottom + 1.0f), - BPoint(frame.right + 1.0f, frame.bottom + 1.0f)); - frame.InsetBy(1.0f, 1.0f); // Third bevel - view->SetHighColor(no_tint); + view->SetHighColor(lighten1); view->StrokeLine(BPoint(frame.left, frame.bottom), - BPoint(frame.right, frame.bottom)); - view->StrokeLine(BPoint(frame.right, frame.top)); + BPoint(frame.right, frame.bottom)); + view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), + BPoint(frame.right, frame.top)); } //------------------------------------------------------------------------------ -void BSlider::_DrawTriangleThumb() +void +BSlider::_DrawTriangleThumb() { BRect frame = ThumbFrame(); BView *view = OffscreenView(); @@ -1345,8 +1487,7 @@ void BSlider::_DrawTriangleThumb() // darken3 = tint_color(no_tint, B_DARKEN_3_TINT), darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); - if (Orientation() == B_HORIZONTAL) - { + if (Orientation() == B_HORIZONTAL) { view->SetHighColor(lighten1); view->FillTriangle(BPoint(frame.left, frame.bottom - 1.0f), BPoint(frame.left + 6.0f, frame.top), @@ -1369,9 +1510,7 @@ void BSlider::_DrawTriangleThumb() BPoint(frame.left + 3.0f, frame.bottom - 1.0f)); view->StrokeLine(BPoint(frame.right - 3, frame.bottom - 2.0f), BPoint(frame.left + 6.0f, frame.top + 1)); - } - else - { + } else { view->SetHighColor(lighten1); view->FillTriangle(BPoint(frame.left + 1.0f, frame.top), BPoint(frame.left + 7.0f, frame.top + 6.0f), @@ -1397,17 +1536,20 @@ void BSlider::_DrawTriangleThumb() } } //------------------------------------------------------------------------------ -BPoint BSlider::_Location() const +BPoint +BSlider::_Location() const { return fLocation; } //------------------------------------------------------------------------------ -void BSlider::_SetLocation(BPoint p) +void +BSlider::_SetLocation(BPoint p) { fLocation = p; } //------------------------------------------------------------------------------ -float BSlider::_MinPosition() const +float +BSlider::_MinPosition() const { if (fOrientation == B_HORIZONTAL) return BarFrame().left + 1.0f; @@ -1415,7 +1557,8 @@ float BSlider::_MinPosition() const return BarFrame().bottom - 1.0f; } //------------------------------------------------------------------------------ -float BSlider::_MaxPosition() const +float +BSlider::_MaxPosition() const { if (fOrientation == B_HORIZONTAL) return BarFrame().right - 1.0f; @@ -1445,15 +1588,18 @@ BSlider &BSlider::operator=(const BSlider &) return *this; } //------------------------------------------------------------------------------ -void BSlider::_InitObject() +void +BSlider::_InitObject() { fLocation.x = 0; fLocation.y = 0; fInitialLocation.x = 0; fInitialLocation.y = 0; +#if USE_OFF_SCREEN_VIEW fOffScreenBits = NULL; fOffScreenView = NULL; +#endif } //------------------------------------------------------------------------------ @@ -1478,8 +1624,6 @@ void BSlider::_InitObject() - -