Improved BSlider class:

- rewrote GetPreferredSize(), it now actually works correctly
- BSlider is certainly not supposed to resize itself on creation
- fixed BarFrame() and ThumbFrame() to support a different view frame
  than the ideal one
- added SetBarThickness() support
- refactored constraining the mouse point to _ConstrainPoint() - it's
  now used by MouseDown() and MouseMoved() - because of that, tracking
  now works with vertical sliders as well
- still has some drawing problems, but less
- _ReservedSlider4() was defined public for the R5 build
Cleanup, more or less rewrote the header.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13342 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-06-29 02:12:42 +00:00
parent d40d872486
commit a00fcbcdf8
2 changed files with 279 additions and 328 deletions
+126 -167
View File
@@ -1,43 +1,18 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2005, Haiku.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * Marc Flerackers ([email protected])
// 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: Slider.h
// Author: Marc Flerackers ([email protected])
// Description: BSlider creates and displays a sliding thumb control.
//------------------------------------------------------------------------------
#ifndef _SLIDER_H #ifndef _SLIDER_H
#define _SLIDER_H #define _SLIDER_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <BeBuild.h> #include <BeBuild.h>
#include <Control.h> #include <Control.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
enum hash_mark_location { enum hash_mark_location {
B_HASH_MARKS_NONE = 0, B_HASH_MARKS_NONE = 0,
B_HASH_MARKS_TOP = 1, B_HASH_MARKS_TOP = 1,
@@ -52,163 +27,148 @@ enum thumb_style {
B_TRIANGLE_THUMB B_TRIANGLE_THUMB
}; };
// Globals ---------------------------------------------------------------------
#define USE_OFF_SCREEN_VIEW 0 #define USE_OFF_SCREEN_VIEW 0
// BSlider class ---------------------------------------------------------------
class BSlider : public BControl { class BSlider : public BControl {
public: public:
BSlider(BRect frame, BSlider(BRect frame, const char *name, const char *label,
const char *name, BMessage *message, int32 minValue, int32 maxValue,
const char *label, thumb_style thumbType = B_BLOCK_THUMB,
BMessage *message, uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
int32 minValue, uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
int32 maxValue,
thumb_style thumbType = B_BLOCK_THUMB,
uint32 resizingMode = B_FOLLOW_LEFT |
B_FOLLOW_TOP,
uint32 flags = B_NAVIGABLE | B_WILL_DRAW |
B_FRAME_EVENTS);
BSlider(BRect frame,
const char *name,
const char *label,
BMessage *message,
int32 minValue,
int32 maxValue,
orientation posture /*= B_HORIZONTAL*/,
thumb_style thumbType = B_BLOCK_THUMB,
uint32 resizingMode = B_FOLLOW_LEFT |
B_FOLLOW_TOP,
uint32 flags = B_NAVIGABLE | B_WILL_DRAW |
B_FRAME_EVENTS);
virtual ~BSlider();
BSlider(BMessage *data); BSlider(BRect frame, const char *name, const char *label,
static BArchivable *Instantiate(BMessage *data); BMessage *message, int32 minValue, int32 maxValue,
virtual status_t Archive(BMessage *data, bool deep = true) const; orientation posture, thumb_style thumbType = B_BLOCK_THUMB,
virtual status_t Perform(perform_code d, void *arg); uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
virtual void WindowActivated(bool state); BSlider(BMessage *data);
virtual void AttachedToWindow(); virtual ~BSlider();
virtual void AllAttached();
virtual void AllDetached();
virtual void DetachedFromWindow();
virtual void MessageReceived(BMessage *msg); static BArchivable *Instantiate(BMessage *data);
virtual void FrameMoved(BPoint new_position); virtual status_t Archive(BMessage *data, bool deep = true) const;
virtual void FrameResized(float w,float h); virtual status_t Perform(perform_code d, void *arg);
virtual void KeyDown(const char * bytes, int32 n);
virtual void MouseDown(BPoint); virtual void WindowActivated(bool state);
virtual void MouseUp(BPoint pt); virtual void AttachedToWindow();
virtual void MouseMoved(BPoint pt, uint32 c, const BMessage *m); virtual void AllAttached();
virtual void Pulse(); virtual void AllDetached();
virtual void DetachedFromWindow();
virtual void SetLabel(const char *label);
virtual void SetLimitLabels(const char *minLabel, virtual void MessageReceived(BMessage *msg);
const char *maxLabel); virtual void FrameMoved(BPoint new_position);
virtual void FrameResized(float w,float h);
virtual void KeyDown(const char * bytes, int32 n);
virtual void MouseDown(BPoint);
virtual void MouseUp(BPoint pt);
virtual void MouseMoved(BPoint pt, uint32 c, const BMessage *m);
virtual void Pulse();
virtual void SetLabel(const char *label);
virtual void SetLimitLabels(const char *minLabel,
const char *maxLabel);
const char* MinLimitLabel() const; const char* MinLimitLabel() const;
const char* MaxLimitLabel() const; const char* MaxLimitLabel() const;
virtual void SetValue(int32); virtual void SetValue(int32);
virtual int32 ValueForPoint(BPoint) const; virtual int32 ValueForPoint(BPoint) const;
virtual void SetPosition(float); virtual void SetPosition(float);
float Position() const; float Position() const;
virtual void SetEnabled(bool on); virtual void SetEnabled(bool on);
void GetLimits(int32 * minimum, int32 * maximum); void GetLimits(int32 * minimum, int32 * maximum);
virtual void Draw(BRect); virtual void Draw(BRect);
virtual void DrawSlider(); virtual void DrawSlider();
virtual void DrawBar(); virtual void DrawBar();
virtual void DrawHashMarks(); virtual void DrawHashMarks();
virtual void DrawThumb(); virtual void DrawThumb();
virtual void DrawFocusMark(); virtual void DrawFocusMark();
virtual void DrawText(); virtual void DrawText();
virtual char* UpdateText() const; virtual char* UpdateText() const;
virtual BRect BarFrame() const;
virtual BRect HashMarksFrame() const;
virtual BRect ThumbFrame() const;
virtual void SetFlags(uint32 flags); virtual BRect BarFrame() const;
virtual void SetResizingMode(uint32 mode); virtual BRect HashMarksFrame() const;
virtual BRect ThumbFrame() const;
virtual void GetPreferredSize( float *width, float *height); virtual void SetFlags(uint32 flags);
virtual void ResizeToPreferred(); virtual void SetResizingMode(uint32 mode);
virtual status_t Invoke(BMessage *msg=NULL);
virtual BHandler *ResolveSpecifier(BMessage *msg,
int32 index,
BMessage *specifier,
int32 form,
const char *property);
virtual status_t GetSupportedSuites(BMessage *data);
virtual void SetModificationMessage(BMessage *message);
BMessage *ModificationMessage() const;
virtual void SetSnoozeAmount(int32);
int32 SnoozeAmount() const;
virtual void SetKeyIncrementValue(int32 value); virtual void GetPreferredSize( float *width, float *height);
int32 KeyIncrementValue() const; virtual void ResizeToPreferred();
virtual void SetHashMarkCount(int32 count);
int32 HashMarkCount() const;
virtual void SetHashMarks(hash_mark_location where); virtual status_t Invoke(BMessage *msg=NULL);
virtual BHandler* ResolveSpecifier(BMessage *msg, int32 index,
BMessage *specifier, int32 form,
const char *property);
virtual status_t GetSupportedSuites(BMessage* data);
virtual void SetModificationMessage(BMessage *message);
BMessage* ModificationMessage() const;
virtual void SetSnoozeAmount(int32);
int32 SnoozeAmount() const;
virtual void SetKeyIncrementValue(int32 value);
int32 KeyIncrementValue() const;
virtual void SetHashMarkCount(int32 count);
int32 HashMarkCount() const;
virtual void SetHashMarks(hash_mark_location where);
hash_mark_location HashMarks() const; hash_mark_location HashMarks() const;
virtual void SetStyle(thumb_style s); virtual void SetStyle(thumb_style s);
thumb_style Style() const; thumb_style Style() const;
virtual void SetBarColor(rgb_color);
rgb_color BarColor() const;
virtual void UseFillColor(bool, const rgb_color* c=NULL);
bool FillColor(rgb_color*) const;
BView* OffscreenView() const;
orientation Orientation() const;
virtual void SetOrientation(orientation);
float BarThickness() const; virtual void SetBarColor(rgb_color);
virtual void SetBarThickness(float thickness); rgb_color BarColor() const;
virtual void UseFillColor(bool, const rgb_color* c=NULL);
bool FillColor(rgb_color*) const;
virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL); BView* OffscreenView() const;
orientation Orientation() const;
virtual void SetOrientation(orientation);
float BarThickness() const;
virtual void SetBarThickness(float thickness);
virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL);
#ifdef __HAIKU__
virtual void SetLimits(int32 minimum, int32 maximum); // Was _ReservedSlider4()
#endif
private:
void _DrawBlockThumb();
void _DrawTriangleThumb();
BPoint _Location() const;
void _SetLocation(BPoint p);
float _MinPosition() const;
float _MaxPosition() const;
bool _ConstrainPoint(BPoint point, BPoint compare) const;
#ifndef __HAIKU__ #ifndef __HAIKU__
virtual void _ReservedSlider4(); virtual void _ReservedSlider4();
#else
virtual void SetLimits(int32 minimum, int32 maximum); // Was _ReservedSlider4()
#endif #endif
/*----- Private or reserved -----------------------------------------*/ virtual void _ReservedSlider5();
private: virtual void _ReservedSlider6();
void _DrawBlockThumb(); virtual void _ReservedSlider7();
void _DrawTriangleThumb(); virtual void _ReservedSlider8();
virtual void _ReservedSlider9();
virtual void _ReservedSlider10();
virtual void _ReservedSlider11();
virtual void _ReservedSlider12();
BPoint _Location() const; BSlider& operator=(const BSlider &);
void _SetLocation(BPoint p);
float _MinPosition() const; void _InitObject();
float _MaxPosition() const;
//virtual void _ReservedSlider1();
//virtual void _ReservedSlider2();
//virtual void _ReservedSlider3();
//virtual void _ReservedSlider4();
virtual void _ReservedSlider5();
virtual void _ReservedSlider6();
virtual void _ReservedSlider7();
virtual void _ReservedSlider8();
virtual void _ReservedSlider9();
virtual void _ReservedSlider10();
virtual void _ReservedSlider11();
virtual void _ReservedSlider12();
BSlider &operator=(const BSlider &);
void _InitObject();
private:
BMessage* fModificationMessage; BMessage* fModificationMessage;
int32 fSnoozeAmount; int32 fSnoozeAmount;
@@ -245,6 +205,5 @@ virtual void _ReservedSlider12();
uint32 _reserved[10]; uint32 _reserved[10];
#endif #endif
}; };
//------------------------------------------------------------------------------
#endif // _SLIDER_H #endif // _SLIDER_H
+153 -161
View File
@@ -9,6 +9,8 @@
*/ */
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -37,7 +39,7 @@ _color_to_long_(rgb_color color)
BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message,
int32 minValue, int32 maxValue, thumb_style thumbType, int32 minValue, int32 maxValue, thumb_style thumbType,
uint32 resizingMode, uint32 flags) uint32 resizingMode, uint32 flags)
: BControl(frame, name, label, message, resizingMode, flags) : BControl(frame, name, label, message, resizingMode, flags)
{ {
fModificationMessage = NULL; fModificationMessage = NULL;
fSnoozeAmount = 20000; fSnoozeAmount = 20000;
@@ -65,15 +67,13 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes
UseFillColor(false, NULL); UseFillColor(false, NULL);
_InitObject(); _InitObject();
ResizeToPreferred();
} }
BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message,
int32 minValue, int32 maxValue, orientation posture, int32 minValue, int32 maxValue, orientation posture,
thumb_style thumbType, uint32 resizingMode, uint32 flags) thumb_style thumbType, uint32 resizingMode, uint32 flags)
: BControl(frame, name, label, message, resizingMode, flags) : BControl(frame, name, label, message, resizingMode, flags)
{ {
fModificationMessage = NULL; fModificationMessage = NULL;
fSnoozeAmount = 20000; fSnoozeAmount = 20000;
@@ -101,8 +101,6 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes
UseFillColor(false, NULL); UseFillColor(false, NULL);
_InitObject(); _InitObject();
ResizeToPreferred();
} }
@@ -113,14 +111,9 @@ BSlider::~BSlider()
delete fOffScreenBits; delete fOffScreenBits;
#endif #endif
if (fModificationMessage) delete fModificationMessage;
delete fModificationMessage; free(fMinLimitStr);
free(fMaxLimitStr);
if (fMinLimitStr)
free(fMinLimitStr);
if (fMaxLimitStr)
free(fMaxLimitStr);
} }
@@ -128,9 +121,8 @@ BSlider::BSlider(BMessage *archive)
: BControl (archive) : BControl (archive)
{ {
fModificationMessage = NULL; fModificationMessage = NULL;
if (archive->HasMessage("_mod_msg")) if (archive->HasMessage("_mod_msg")) {
{
BMessage *message = new BMessage; BMessage *message = new BMessage;
archive->FindMessage("_mod_msg", message); archive->FindMessage("_mod_msg", message);
@@ -146,13 +138,12 @@ BSlider::BSlider(BMessage *archive)
if (archive->FindInt32("_fcolor", &color) == B_OK) { if (archive->FindInt32("_fcolor", &color) == B_OK) {
rgb_color fillColor = _long_to_color_(color); rgb_color fillColor = _long_to_color_(color);
UseFillColor(true, &fillColor); UseFillColor(true, &fillColor);
} } else
else
UseFillColor(false); UseFillColor(false);
int32 orient; int32 orient;
if(archive->FindInt32("_orient", &orient) == B_OK) if (archive->FindInt32("_orient", &orient) == B_OK)
fOrientation = (orientation)orient; fOrientation = (orientation)orient;
else else
fOrientation = B_HORIZONTAL; fOrientation = B_HORIZONTAL;
@@ -181,19 +172,19 @@ BSlider::BSlider(BMessage *archive)
int16 hashloc; int16 hashloc;
if(archive->FindInt16("_hashloc", &hashloc) == B_OK) if (archive->FindInt16("_hashloc", &hashloc) == B_OK)
fHashMarks = (hash_mark_location)hashloc; fHashMarks = (hash_mark_location)hashloc;
else else
fHashMarks = B_HASH_MARKS_NONE; fHashMarks = B_HASH_MARKS_NONE;
int16 sstyle; int16 sstyle;
if(archive->FindInt16("_sstyle", &sstyle) == B_OK) if (archive->FindInt16("_sstyle", &sstyle) == B_OK)
fStyle = (thumb_style)sstyle; fStyle = (thumb_style)sstyle;
else else
fStyle = B_BLOCK_THUMB; fStyle = B_BLOCK_THUMB;
if(archive->FindInt32("_bcolor", &color) == B_OK) if (archive->FindInt32("_bcolor", &color) == B_OK)
SetBarColor(_long_to_color_(color)); SetBarColor(_long_to_color_(color));
else { else {
if (Style() == B_BLOCK_THUMB) if (Style() == B_BLOCK_THUMB)
@@ -215,13 +206,28 @@ BSlider::BSlider(BMessage *archive)
} }
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
}
BArchivable* BArchivable*
BSlider::Instantiate(BMessage *archive) BSlider::Instantiate(BMessage *archive)
{ {
if (validate_instantiation(archive, "BSlider")) if (validate_instantiation(archive, "BSlider"))
return new BSlider(archive); return new BSlider(archive);
else
return NULL; return NULL;
} }
@@ -424,6 +430,33 @@ BSlider::KeyDown(const char *bytes, int32 numBytes)
} }
bool
BSlider::_ConstrainPoint(BPoint point, BPoint comparePoint) const
{
if (fOrientation == B_HORIZONTAL) {
if (point.x != comparePoint.x) {
if (point.x < _MinPosition())
point.x = _MinPosition();
else if (point.x > _MaxPosition())
point.x = _MaxPosition();
return true;
}
} else {
if (point.y != comparePoint.y) {
if (point.y > _MinPosition())
point.y = _MinPosition();
else if (point.y < _MaxPosition())
point.y = _MaxPosition();
return true;
}
}
return false;
}
void void
BSlider::MouseDown(BPoint point) BSlider::MouseDown(BPoint point)
{ {
@@ -433,25 +466,12 @@ BSlider::MouseDown(BPoint point)
if (BarFrame().Contains(point) || ThumbFrame().Contains(point)) if (BarFrame().Contains(point) || ThumbFrame().Contains(point))
fInitialLocation = _Location(); fInitialLocation = _Location();
BPoint pt;
uint32 buttons; uint32 buttons;
GetMouse(&point, &buttons, true);
GetMouse(&pt, &buttons, true); _ConstrainPoint(point, fInitialLocation);
SetValue(ValueForPoint(point));
if (fOrientation == B_HORIZONTAL) {
if (pt.x < _MinPosition())
pt.x = _MinPosition();
else if (pt.x > _MaxPosition())
pt.x = _MaxPosition();
} else {
if (pt.y > _MinPosition())
pt.y = _MinPosition();
else if (pt.y < _MaxPosition())
pt.y = _MaxPosition();
}
SetValue(ValueForPoint(pt));
//virtual
InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED);
if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) { if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
@@ -459,39 +479,16 @@ BSlider::MouseDown(BPoint point)
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
} else { } else {
// synchronous mouse tracking // synchronous mouse tracking
BPoint prevPt; BPoint prevPoint;
bool update;
while (buttons) { while (buttons) {
prevPt = pt; prevPoint = point;
update = false;
snooze(SnoozeAmount()); snooze(SnoozeAmount());
GetMouse(&pt, &buttons, true); GetMouse(&point, &buttons, true);
if (fOrientation == B_HORIZONTAL) { if (_ConstrainPoint(point, prevPoint)) {
if (pt.x != prevPt.x) { SetValue(ValueForPoint(point));
update = true;
if (pt.x < _MinPosition())
pt.x = _MinPosition();
else if (pt.x > _MaxPosition())
pt.x = _MaxPosition();
}
} else {
if (pt.y != prevPt.y) {
update = true;
if (pt.y > _MinPosition())
pt.y = _MinPosition();
else if (pt.y < _MaxPosition())
pt.y = _MaxPosition();
}
}
if (update) {
SetValue(ValueForPoint(pt));
//virtual
InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED);
} }
} }
@@ -521,38 +518,11 @@ void
BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message) BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
{ {
if (IsTracking()) { if (IsTracking()) {
BPoint loc = _Location(); if (_ConstrainPoint(point, _Location())) {
bool update = false;
if (fOrientation == B_HORIZONTAL) {
if (point.x != loc.x) {
update = true;
if (point.x < _MinPosition())
point.x = _MinPosition();
else if (point.x > _MaxPosition())
point.x = _MaxPosition();
}
} else {
if (point.y != loc.y) {
update = true;
if (point.y < _MinPosition())
point.y = _MinPosition();
else if (point.y > _MaxPosition())
point.y = _MaxPosition();
}
}
if (update) {
SetValue(ValueForPoint(point)); SetValue(ValueForPoint(point));
//virtual
}
if (_Location() != loc)
InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED);
} }
else } else
BControl::MouseMoved(point, transit, message); BControl::MouseMoved(point, transit, message);
} }
@@ -654,13 +624,9 @@ BSlider::SetValue(int32 value)
int32 int32
BSlider::ValueForPoint(BPoint location) const BSlider::ValueForPoint(BPoint location) const
{ {
if (fOrientation == B_HORIZONTAL) { return (int32)(((fOrientation == B_HORIZONTAL ? location.x : location.y)
return (int32)((location.x - _MinPosition()) * (fMaxValue - fMinValue) / - _MinPosition())
(_MaxPosition() - _MinPosition())) + fMinValue; * (fMaxValue - fMinValue) / (_MaxPosition() - _MinPosition())) + fMinValue;
} else {
return (int32)((location.y - _MinPosition()) * (fMaxValue - fMinValue) /
(_MaxPosition() - _MinPosition())) + fMinValue;
}
} }
@@ -1021,24 +987,23 @@ BRect
BSlider::BarFrame() const BSlider::BarFrame() const
{ {
BRect frame(Bounds()); BRect frame(Bounds());
font_height fheight;
GetFontHeight(&fheight); font_height fontHeight;
GetFontHeight(&fontHeight);
float textHeight = (float)ceil(fheight.ascent + fheight.descent); float textHeight = (float)ceil(fontHeight.ascent + fontHeight.descent);
if (fStyle == B_BLOCK_THUMB) { if (fStyle == B_BLOCK_THUMB) {
if (Orientation() == B_HORIZONTAL) { if (Orientation() == B_HORIZONTAL) {
frame.left = 8.0f; frame.left = 8.0f;
frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f);
frame.right -= 8.0f; frame.right -= 8.0f;
frame.bottom = frame.bottom - 6.0f - frame.bottom = frame.top + fBarThickness;
(fMinLimitStr || fMaxLimitStr ? textHeight + 4.0f : 0.0f);
} else { } else {
frame.left = frame.Width() / 2.0f - 3; frame.left = (frame.Width() - fBarThickness) / 2.0f;
frame.top = 12.0f + (Label() ? textHeight : 0.0f) + frame.top = 12.0f + (Label() ? textHeight : 0.0f) +
(fMaxLimitStr ? textHeight : 0.0f); (fMaxLimitStr ? textHeight : 0.0f);
frame.right = frame.left + 6; frame.right = frame.left + fBarThickness;
frame.bottom = frame.bottom - 8.0f - frame.bottom = frame.bottom - 8.0f -
(fMinLimitStr ? textHeight + 4 : 0.0f); (fMinLimitStr ? textHeight + 4 : 0.0f);
} }
@@ -1047,13 +1012,12 @@ BSlider::BarFrame() const
frame.left = 7.0f; frame.left = 7.0f;
frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f);
frame.right -= 7.0f; frame.right -= 7.0f;
frame.bottom = frame.bottom - 6.0f - frame.bottom = frame.top + fBarThickness;
(fMinLimitStr || fMaxLimitStr ? textHeight + 4.0f : 0.0f);
} else { } else {
frame.left = frame.Width() / 2.0f - 3; frame.left = (frame.Width() - fBarThickness) / 2.0f;
frame.top = 11.0f + (Label() ? textHeight : 0.0f) + frame.top = 11.0f + (Label() ? textHeight : 0.0f) +
(fMaxLimitStr ? textHeight : 0.0f); (fMaxLimitStr ? textHeight : 0.0f);
frame.right = frame.left + 6; frame.right = frame.left + fBarThickness;
frame.bottom = frame.bottom - 7.0f - frame.bottom = frame.bottom - 7.0f -
(fMinLimitStr ? textHeight + 4 : 0.0f); (fMinLimitStr ? textHeight + 4 : 0.0f);
} }
@@ -1100,25 +1064,24 @@ BSlider::ThumbFrame() const
_MinPosition()) - 8.0f; _MinPosition()) - 8.0f;
frame.top = 2.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.top = 2.0f + (Label() ? textHeight + 4.0f : 0.0f);
frame.right = frame.left + 17.0f; frame.right = frame.left + 17.0f;
frame.bottom = frame.bottom - 3.0f - frame.bottom = frame.top + fBarThickness + 7.0f;
(MinLimitLabel() || MaxLimitLabel() ? textHeight + 4.0f : 0.0f);
} else { } else {
frame.left = frame.Width() / 2.0f - 7; frame.left = (frame.Width() - fBarThickness) / 2.0f - 4;
frame.top = (float)floor(Position() * (_MaxPosition() - _MinPosition()) + frame.top = (float)floor(Position() * (_MaxPosition() - _MinPosition()) +
_MinPosition()) - 8.0f; _MinPosition()) - 8.0f;
frame.right = frame.left + 13; frame.right = frame.left + fBarThickness + 7.0f;
frame.bottom = frame.top + 17; frame.bottom = frame.top + 17;
} }
} else { } else {
if (Orientation() == B_HORIZONTAL) { if (Orientation() == B_HORIZONTAL) {
frame.left = (float)floor(Position() * (_MaxPosition() - _MinPosition()) + frame.left = (float)floor(Position() * (_MaxPosition() - _MinPosition()) +
_MinPosition()) - 6; _MinPosition()) - 6;
frame.top = 9.0f + (Label() ? textHeight + 4.0f : 0.0f);
frame.right = frame.left + 12.0f; frame.right = frame.left + 12.0f;
frame.bottom = frame.bottom - 2.0f - frame.bottom = frame.bottom - 2.0f -
(MinLimitLabel() || MaxLimitLabel() ? textHeight + 4.0f : 0.0f); (MinLimitLabel() || MaxLimitLabel() ? textHeight + 4.0f : 0.0f);
frame.top = frame.bottom - 7.0f;
} else { } else {
frame.left = frame.Width() / 2.0f - 6; frame.left = (frame.Width() - fBarThickness) / 2.0f - 3;
frame.top = (float)floor(Position() * (_MaxPosition() - _MinPosition())) + frame.top = (float)floor(Position() * (_MaxPosition() - _MinPosition())) +
_MinPosition() - 6.0f; _MinPosition() - 6.0f;
frame.right = frame.left + 7; frame.right = frame.left + 7;
@@ -1145,38 +1108,81 @@ BSlider::SetResizingMode(uint32 mode)
void void
BSlider::GetPreferredSize(float *width, float *height) BSlider::GetPreferredSize(float* _width, float* _height)
{ {
font_height fheight; font_height fontHeight;
GetFontHeight(&fontHeight);
GetFontHeight(&fheight); int32 rows = 0;
if (Orientation() == B_HORIZONTAL) { if (Orientation() == B_HORIZONTAL) {
*width = (Frame().Width() < 32.0f) ? 32.0f : Frame().Width(); *_width = Frame().Width();
*height = 18.0f; *_height = 12.0f + fBarThickness;
if (Label()) float labelWidth = 0;
*height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f; if (Label()) {
labelWidth = StringWidth(Label());
rows++;
}
float minWidth = 0;
if (MinLimitLabel())
minWidth = StringWidth(MinLimitLabel());
if (MaxLimitLabel()) {
// some space between the labels
if (MinLimitLabel())
minWidth += 8.0f;
minWidth += StringWidth(MaxLimitLabel());
}
if (minWidth > *_width)
*_width = minWidth;
if (labelWidth > *_width)
*_width = labelWidth;
if (*_width < 32.0f)
*_width = 32.0f;
if (MinLimitLabel() || MaxLimitLabel()) if (MinLimitLabel() || MaxLimitLabel())
*height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f; rows++;
} else { // B_VERTICAL
*width = (Frame().Width() < 18.0f) ? 18.0f : Frame().Width();
*height = 32.0f;
if (Label())
*height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f;
if (MaxLimitLabel()) *_height += rows * ((float)ceil(fontHeight.ascent + fontHeight.descent) + 4.0f);
*height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f; } else {
// B_VERTICAL
*_width = 12.0f + fBarThickness;
*_height = Frame().Height();
if (MinLimitLabel()) // find largest label
*height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f;
if (Label() && (MaxLimitLabel())) float minWidth = 0;
*height -= 4.0f; if (Label()) {
minWidth = StringWidth(Label());
rows++;
}
if (MinLimitLabel()) {
float width = StringWidth(MinLimitLabel());
if (width > minWidth)
minWidth = width;
rows++;
}
if (MaxLimitLabel()) {
float width = StringWidth(MaxLimitLabel());
if (width > minWidth)
minWidth = width;
rows++;
}
*height = (Frame().Height() < *height) ? *height : Frame().Height(); if (minWidth > *_width)
*_width = minWidth;
float minHeight = 32.0f + rows
* ((float)ceil(fontHeight.ascent + fontHeight.descent) + 4.0f);
if (Label() && MaxLimitLabel())
minHeight -= 4.0f;
if (minHeight > *_height)
*_height = minHeight;
} }
} }
@@ -1380,7 +1386,8 @@ BSlider::BarThickness() const
void void
BSlider::SetBarThickness(float thickness) BSlider::SetBarThickness(float thickness)
{ {
fBarThickness = thickness; if (thickness >= 1.0f)
fBarThickness = thickness;
} }
@@ -1673,18 +1680,3 @@ BSlider::operator=(const BSlider &)
return *this; return *this;
} }
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
}