BSlider¶
Constructor and Destructor¶
BSlider()
BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, int32 minValue, int32 maxValue, thumb_style thumbType = B_BLOCK_THUMB, int32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, int32 flags = B_FRAME_EVENTS | B_WILL_DRAW | B_NAVIGABLE)
BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, int32 minValue, int32 maxValue, orientation posture, thumb_style thumbType = B_BLOCK_THUMB, int32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, int32 flags = B_FRAME_EVENTS | B_WILL_DRAW | B_NAVIGABLE)
BSlider::BSlider(BMessage *archive)
Initializes the BSlider by passing the appropriate arguments to
the BControl
constructor. BControl
initializes
the slider’s label and assigns it a model message that
identifies the action that should be carried out when the slider is
invoked.
The frame, name, resizingMode, and
flags arguments are the same as those declared for the
BView
class and are passed up the inheritance hierarchy to the
BView
constructor without change.
The minValue and maxValue parameters define the minimum and maximum values to which the slider can be set.
If you want to control whether the slider is horizontal or vertical, use
the second form of the constructor, and set the posture argument
to either B_HORIZONTAL
or B_VERTICAL
.
If you don’t specify this argument, the slider will be horizontal by
default.
The thumbType argument defines the look of the slider’s thumb, and can be either of the following values:
Constant |
Description |
---|---|
|
The thumb is a rectangular block. |
|
The thumb is a triangular pointer. |
~BSlider()
virtual BSlider::~BSlider()
Frees memory allocated by the BSlider object.
Hook Functions¶
AttachedToWindow()
virtual void BSlider::AttachedToWindow()
Augments the BControl
version of this function to set the
background color of the button so that it matches the background color of
its parent. This function also sets the start position of the slider and
allocates other memory needed for the slider to function.
See also: BView::AttachedToWindow()
,
BControl::AttachedToWindow()
Draw()
virtual void BSlider::Draw(BRect updateRect)
Draws the slider by calling DrawSlider()
.
See also: BView::Draw()
DrawBar(), BarFrame()
virtual void BSlider::DrawBar()
virtual BRect BSlider::BarFrame() const
DrawBar() draws the slider bar. The bar is the narrow region the thumb slides through. The bar should be drawn into the offscreen view.
BarFrame() returns the frame rectangle that encloses the slider bar.
These functions can be augmented or replaced by your own versions to alter the appearance of the slider bar.
See also: OffscreenView()
DrawFocusMark()
virtual void BSlider::DrawFocusMark()
If the slider is in focus, draws a mark indicating that this is the case.
You can override this function to alter the appearance of the slider control.
DrawHashMarks(), HashMarksFrame()
virtual void BSlider::DrawHashMarks()
virtual BRect BSlider::HashMarksFrame() const
DrawHashMarks() draws the hash marks.
HashMarksFrame() returns the frame rectangle that encloses the
hash marks. If the hash marks are set to B_HASH_MARKS_TOP
or B_HASH_MARKS_BOTTOM
, the rectangle encloses only the
area needed to draw the marks. If the setting is
B_HASH_MARKS_BOTH
, the hash marks frame rectangle is the
bounds rectangle of the entire slider control.
These functions can be augmented or replaced by your own versions to alter the appearance of the hash marks.
DrawSlider()
virtual void BSlider::DrawSlider()
Draws the entire slider control by calling the functions responsible for drawing the various parts of the control:
Once the slider has been drawn into the offscreen view, it’s copied to its parent window.
DrawText()
virtual void BSlider::DrawText()
Draws the slider’s text areas. These are the minimum label, maximum label, and status message.
The minimum and maximum labels can be set using the
SetLimitLabels()
function. The status message is
obtained by calling the UpdateText()
function. If you
want there to be a status message, simply override
UpdateText()
to return the string you want drawn as
the status message.
Note
In the default implementation of this function, the limit labels are only drawn if both of them have been configured to a value other than NULL. If either of them is NULL, neither will be drawn.
This function can be augmented or replaced by your own version to alter the appearance or placement of the text.
DrawThumb(), ThumbFrame()
virtual void BSlider::DrawThumb()
virtual BRect BSlider::ThumbFrame() const
DrawThumb() draws the slider’s thumb. If you choose to
reimplement this function, you should call Style()
to
determine whether to draw a block thumb or a triangle thumb.
ThumbFrame() returns the frame rectangle that encloses the thumb.
These functions can be augmented or replaced by your own versions to alter the appearance of the thumb.
FrameResized()
virtual void BSlider::FrameResized(float *width, float *height)
Augments the BControl
version of
FrameResized()
to adjust the offscreen view and bitmap
used for rendering the slider.
GetPreferredSize(), ResizeToPreferred()
virtual void BSlider::GetPreferredSize(float *width, float *height)
virtual void BSlider::ResizeToPreferred()
GetPreferredSize() calculates the width and height of the area needed to render the complete slider control, given the current configuration of the control’s various settings.
The width returned by this function is the width of the slider control. The height is calculated by taking the height of the slider bar itself, adding two times the height of the hash marks, then adding room for the status text (if there is any) and limit strings (if there are any).
Note that the height always includes room for hash marks both above and below the slider, even if the slider has no hash marks or only one of the two sets of marks.
ResizeToPreferred() resizes the slider control to be the preferred size.
You can override these functions to alter the preferred size of the slider; this is particularly important if you override other functions to change the appearance of the slider.
KeyDown()
virtual void BSlider::KeyDown(const char *bytes, int32 numBytes)
Augments the inherited version of KeyDown()
to let
the up and right arrow keys increment the value of the slider, and the down
and left arrow keys to decrement the value of the slider.
See also: BControl::Invoke()
, BView::KeyDown()
MouseDown()
virtual void BSlider::MouseDown(BPoint point)
Overrides the BView
version of MouseDown()
to track mouse the mouse when the button is pressed. A single click causes
the thumb to immediately reposition itself to the clicked location, and a
click and drag motion causes the slider to follow the mouse cursor until
the button is released.
If a modification message has been established, it is sent repeatedly while the mouse button is down. This can be used, for example, to let the changes to the value of the slider be instantly reflected in an onscreen display. When the mouse button is released and the slider has been set to its resting position, the slider’s model message is sent.
See also: BControl::Invoke()
,
BInvoker::SetTarget()
,
ModificationMessage()
,
SetModificationMessage()
Member Functions¶
Archive()
virtual status_t BSlider::Archive(BMessage *archive, bool deep = true) const
Archives the BSlider by recording its the fields shown
here
in the BMessage
archive.
See also: BArchivable::Archive()
,
Instantiate()
static function
OffscreenView()
BView *BSlider::OffscreenView(BView *view)
Returns a pointer to the offscreen BView
in which the slider
is rendered prior to being copied to the screen. Because the slider is a
complex graphical construct, it’s rendered offscreen, then copied onto the
screen. This function is provided to make it possible to further customize
the appearance of a custom slider control.
SetBarColor(), BarColor()
virtual void BSlider::SetBarColor(rgb_color bar_color)
virtual rgb_color BSlider::BarColor() const
SetBarColor() sets the color of the slider bar.
BarColor() returns the slider bar’s color.
SetBarThickness(), BarThickness()
virtual void BSlider::SetBarThickness(float thickness)
float BSlider::BarThickness() const
SetBarThickness() sets the slider bar’s thickness and BarThickness() returns the current thickness.
The slider bar’s thickness determines how many pixels across the slider bar is. If no thickness is defined, the bar occupies the entire unused width or height of the slider’s bounding rectangle.
SetFont()
virtual void BSlider::SetFont(const BFont *font, uint32 properties = B_FONT_ALL)
Sets the font used for the slider’s labels to font. The properties flags indicate which properties of the font should be used, and which should remain unchanged.
SetHashMarks(), HashMarks()
virtual void BSlider::SetHashMarks(hash_mark_location where)
hash_mark_location BSlider::HashMarks() const
SetHashMarks() sets the placement of the hash marks. This value can be one of the following:
Constant |
Description |
---|---|
|
The slider should have no hash marks. |
|
The slider should have hash marks above the slider bar. For horizontal sliders only. |
|
The slider should have hash marks below the slider bar. For horizontal sliders only. |
|
The slider should have hash marks above and below the slider bar. |
|
The slider should have has marks to the left of the slider bar. For vertical sliders only. |
|
The slider should have has marks to the right of the slider bar. For vertical sliders only. |
HashMarks() returns the current placement of the hash marks.
SetHashMarkCount(), HashMarkCount()
virtual void BSlider::SetHashMarkCount(int32 hash_mark_count)
int32 BSlider::HashMarkCount() const
SetHashMarkCount() sets the number of hash marks that will be displayed above and/or below the slider.
HashMarkCount() returns the number of hash marks currently set up.
SetKeyIncrementValue(), KeyIncrementValue()
virtual void BSlider::SetKeyIncrementValue(int32 increment_value)
int32 BSlider::KeyIncrementValue() const
SetKeyIncrementValue() sets the amount by which the slider’s value changes when the keyboard is used to move the thumb.
KeyIncrementValue() returns the amount by which the slider’s value changes when the keyboard is used to move the thumb.
SetLimitLabels(), MinLimitLabel(), MaxLimitLabel()
virtual void BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel)
const char *BSlider::MinLimitLabel() const
const char *BSlider::MaxLimitLabel() const
SetLimitLabels() sets the labels used to mark the minimum and maximum values on the slider.
MinLimitLabel() and MaxLimitLabel() return the current strings used to mark the minimum and maximum values on the slider.
SetModificationMessage(), ModificationMessage()
virtual void BSlider::SetModificationMessage(BMessage *message)
BMessage *BSlider::ModificationMessage() const
SetModificationMessage() sets the model message that’s sent while the mouse is being tracked. The modification message is sent repeatedly as long as the mouse button is held down after being initially clicked inside the slider.
ModificationMessage() returns the modification message currently set up.
See also: MouseDown()
SetOrientation(), Orientation()
virtual void BSlider::SetOrientation(orientation posture)
orientation BSlider::Orientation() const
SetOrientation() sets the slider’s orientation and
Orientation() returns its current orientation. The possible
values are B_HORIZONTAL
and B_VERTICAL
.
SetPosition(), Position()
virtual void BSlider::SetPosition(float *position)
virtual float BSlider::Position() const
SetPosition() sets the value of the slider given a value between 0.0 and 1.0, where 0.0 is the minimum value of the slider, and 1.0 is the maximum value. This lets you set the slider to a relative position without having to look up the maximum and minimum values of the slider.
Position() returns the slider value scaled to the range 0.0 to 1.0.
SetSnoozeAmount(), SnoozeAmount()
virtual void BSlider::SetSnoozeAmount(int32 snooze_time)
int32 BSlider::SnoozeAmount() const
SetSnoozeAmount() sets the time (in microseconds) that the slider snoozes for between updates while the mouse is being tracked.
SnoozeAmount() returns the time that the slider snoozes while the mouse is being tracked.
SetStyle(), Style()
virtual void BSlider::SetStyle(thumb_style style)
thumb_style BSlider::Style() const
SetStyle() sets the thumb style for the slider. The style can be either of the following two values:
Constant |
Description |
---|---|
|
The thumb is a rectangular block. |
|
The thumb is a triangular pointer. |
Style() returns the current thumb style.
SetValue(), Value(), ValueForPoint()
virtual void BSlider::SetValue(int32 *value)
virtual int32 BSlider::Value() const
virtual int32 BSlider::ValueForPoint(BPoint location) const
SetValue() augments the BControl
function
to pin the value to the maximum
and minimum values for the slider and the position of the thumb before
calling the inherited function.
ValueForPoint() returns the slider value represented by the given screen coordinates.
UpdateText()
virtual char *BSlider::UpdateText() const
Returns the status message that should be displayed with the slider. By default, this function returns NULL; if you want a status message to be displayed, simply override this function to return the appropriate string.
The pointer you return is yours; the DrawText()
routine won’t dispose of it unless you augment it to do so.
UseFillColor(), FillColor()
virtual void BSlider::UseFillColor(bool use_fill, const rgb_color *bar_color = NULL)
virtual bool BSlider::FillColor(rgb_color *bar_color) const
UseFillColor() sets the color used to fill the area of the slider bar that’s “filled.” That is, the part of the bar between the minimum value of the slider and the current thumb position. If the use_fill parameter is true, filling this area of the slider with the fill color is turned on. If use_fill is false, the entire slider bar is always drawn in the bar color.
FillColor() stores the current fill color in bar_color. The boolean value returned by the function is true if the fill color is being used, false if not.
Static Functions¶
Instantiate()
static BArchivable *BSlider::Instantiate(BMessage *archive)
Returns a new BSlider object, allocated by new and created with
the version of the constructor that takes a BMessage
archive.
However, if the archive doesn’t contain data for a BSlider
object, Instantiate() returns NULL.
See also: BArchivable::Instantiate()
,
instantiate_object()
, Archive()
Archived Fields¶
The Archive()
function adds the following fields to
its BMessage
argument:
Field |
Type code |
Description |
---|---|---|
_mod_msg |
|
The flattened modification message. |
_sdelay |
|
The snooze amount. |
_bcolor |
|
The bar color. |
_fcolor |
|
The fill color. |
_minlbl |
|
The minimum limit label. |
_maxlbl |
|
The maximum limit label. |
_min |
|
The minimum possible value. |
_max |
|
The maximum possible value. |
_incrementvalue |
|
The keyboard navigation increment value. |
_hashcount |
|
The number of hash marks to draw. |
_hashloc |
|
Where to draw the hash marks. |
_sstyle |
|
The thumb style. |
Some of these fields may not be present if the setting they represent isn’t used, or is the default value. For example, if there is no minimum limit label set, the _min_lbl field doesn’t exist.