* Finished rewriting the header.

* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32667 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-08-25 14:13:59 +00:00
parent f1f6eacd46
commit d89b690d3b
2 changed files with 235 additions and 228 deletions
+39 -47
View File
@@ -1,15 +1,7 @@
/*******************************************************************************
/
/ File: ChannelSlider.h
/
/ Description: BChannelSlider implements a slider which can have a number
/ of (on-screen) related values. A typical use is for a stereo
/ volume control.
/
/ Copyright 1998-99, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
/*
* Copyright 2009, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*/
#ifndef _CHANNEL_SLIDER_H
#define _CHANNEL_SLIDER_H
@@ -41,13 +33,8 @@ public:
virtual ~BChannelSlider();
static BArchivable* Instantiate(BMessage* from);
virtual status_t Archive(BMessage* into, bool deep = true) const;
virtual orientation Orientation() const;
void SetOrientation(enum orientation orientation);
virtual int32 MaxChannelCount() const;
virtual bool SupportsIndividualLimits() const;
virtual status_t Archive(BMessage* into,
bool deep = true) const;
virtual void AttachedToWindow();
virtual void AllAttached();
@@ -56,7 +43,7 @@ public:
virtual void MessageReceived(BMessage* message);
virtual void Draw(BRect area);
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint where);
virtual void MouseUp(BPoint where);
virtual void MouseMoved(BPoint where, uint32 transit,
@@ -70,26 +57,29 @@ public:
uint32 mask = B_FONT_ALL);
virtual void MakeFocus(bool focusState = true);
virtual void SetEnabled(bool on);
virtual void GetPreferredSize(float* _width, float* _height);
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 form,
const char* p);
virtual BHandler* ResolveSpecifier(BMessage* message,
int32 index, BMessage* specifier,
int32 form, const char* property);
virtual status_t GetSupportedSuites(BMessage* data);
// Perform rendering for an entire slider channel.
virtual void DrawChannel(BView* into, int32 channel, BRect area,
bool pressed);
virtual void SetEnabled(bool on);
// Draw groove that appears behind a channel's thumb.
virtual void DrawGroove(BView* into, int32 channel, BPoint lt,
BPoint br);
virtual orientation Orientation() const;
void SetOrientation(enum orientation orientation);
// Draw the thumb for a single channel.
virtual void DrawThumb(BView* into, int32 channel, BPoint where,
bool pressed);
virtual int32 MaxChannelCount() const;
virtual bool SupportsIndividualLimits() const;
virtual void DrawChannel(BView* into, int32 channel,
BRect area, bool pressed);
virtual void DrawGroove(BView* into, int32 channel,
BPoint leftTop, BPoint rightBottom);
virtual void DrawThumb(BView* into, int32 channel,
BPoint where, bool pressed);
virtual const BBitmap* ThumbFor(int32 channel, bool pressed);
virtual BRect ThumbFrameFor(int32 channel);
@@ -97,6 +87,7 @@ virtual float ThumbDeltaFor(int32 channel);
virtual float ThumbRangeFor(int32 channel);
private:
// FBC padding
BChannelSlider(const BChannelSlider&);
BChannelSlider& operator=(const BChannelSlider&);
@@ -110,6 +101,16 @@ virtual void _Reserved_BChannelSlider_5(void* , ...);
virtual void _Reserved_BChannelSlider_6(void*, ...);
virtual void _Reserved_BChannelSlider_7(void*, ...);
private:
void _InitData();
void _FinishChange(bool update = false);
void _UpdateFontDimens();
void _DrawThumbs();
void _DrawGrooveFrame(BView* where,
const BRect& area);
void _MouseMovedCommon(BPoint point, BPoint point2);
private:
float fBaseLine;
float fLineFeed;
BBitmap* fLeftKnob;
@@ -117,27 +118,18 @@ virtual void _Reserved_BChannelSlider_7(void* , ...);
BBitmap* fRightKnob;
BBitmap* fBacking;
BView* fBackingView;
bool fVertical;
bool fPadding[3];
bool fIsVertical;
bool _padding_[3];
BPoint fClickDelta;
int32 fCurrentChannel;
bool fAllChannels;
int32* fInitialValues;
float fMinpoint;
float fMinPoint;
int32 fFocusChannel;
uint32 _reserved_[12];
void _InitData();
void _FinishChange(bool update = false);
void _UpdateFontDimens();
void _DrawThumbs();
void _DrawGrooveFrame(BView* where, const BRect& area);
bool _Vertical() const;
void _Redraw();
void _MouseMovedCommon(BPoint point, BPoint point2);
};
#endif /* _CHANNEL_SLIDER_H */
#endif // _CHANNEL_SLIDER_H
+130 -115
View File
@@ -1,11 +1,16 @@
/*
* Copyright 2005 - 2008, Haiku Inc. All Rights Reserved.
* Author: Stefano Ceccherini ([email protected])
* Copyright 2005-2009, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stefano Ceccherini ([email protected])
* Stephan Aßmus <[email protected]>
*/
#include <ChannelSlider.h>
#include <new>
#include <Bitmap.h>
#include <ControlLook.h>
#include <Debug.h>
@@ -14,9 +19,6 @@
#include <Window.h>
#include <new>
const static unsigned char
kVerticalKnobData[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -144,38 +146,6 @@ BChannelSlider::Archive(BMessage *into, bool deep) const
}
orientation
BChannelSlider::Orientation() const
{
return _Vertical() ? B_VERTICAL : B_HORIZONTAL;
}
void
BChannelSlider::SetOrientation(enum orientation orientation)
{
bool isVertical = orientation == B_VERTICAL;
if (isVertical != _Vertical()) {
fVertical = isVertical;
Invalidate(Bounds());
}
}
int32
BChannelSlider::MaxChannelCount() const
{
return 32;
}
bool
BChannelSlider::SupportsIndividualLimits() const
{
return false;
}
void
BChannelSlider::AttachedToWindow()
{
@@ -224,7 +194,8 @@ BChannelSlider::MessageReceived(BMessage *message)
&what, &property);
BPropertyInfo propInfo(sPropertyInfo);
if (status == B_OK
&& propInfo.FindMatch(message, index, &specifier, what, property) >= 0) {
&& propInfo.FindMatch(message, index, &specifier, what,
property) >= 0) {
handled = true;
if (message->what == B_SET_PROPERTY) {
orientation orient;
@@ -267,27 +238,32 @@ BChannelSlider::Draw(BRect updateRect)
}
if (MinLimitLabel()) {
if (_Vertical()) {
if (fIsVertical) {
if (MinLimitLabel()) {
float x = (bounds.Width() - StringWidth(MinLimitLabel())) / 2.0;
DrawString(MinLimitLabel(), BPoint(x, bounds.bottom - kPadding));
float x = (bounds.Width() - StringWidth(MinLimitLabel()))
/ 2.0;
DrawString(MinLimitLabel(), BPoint(x, bounds.bottom
- kPadding));
}
} else {
if (MinLimitLabel())
DrawString(MinLimitLabel(), BPoint(kPadding, bounds.bottom - kPadding));
if (MinLimitLabel()) {
DrawString(MinLimitLabel(), BPoint(kPadding, bounds.bottom
- kPadding));
}
}
}
if (MaxLimitLabel()) {
if (_Vertical()) {
if (fIsVertical) {
if (MaxLimitLabel()) {
float x = (bounds.Width() - StringWidth(MaxLimitLabel())) / 2.0;
float x = (bounds.Width() - StringWidth(MaxLimitLabel()))
/ 2.0;
DrawString(MaxLimitLabel(), BPoint(x, 2 * fLineFeed));
}
} else {
if (MaxLimitLabel()) {
DrawString(MaxLimitLabel(), BPoint(bounds.right - kPadding -
StringWidth(MaxLimitLabel()), bounds.bottom - kPadding));
DrawString(MaxLimitLabel(), BPoint(bounds.right - kPadding
- StringWidth(MaxLimitLabel()), bounds.bottom - kPadding));
}
}
}
@@ -301,7 +277,7 @@ BChannelSlider::MouseDown(BPoint where)
BControl::MouseDown(where);
else {
fCurrentChannel = -1;
fMinpoint = 0;
fMinPoint = 0;
// Search the channel on which the mouse was over
int32 numChannels = CountChannels();
@@ -310,13 +286,13 @@ BChannelSlider::MouseDown(BPoint where)
frame.OffsetBy(fClickDelta);
float range = ThumbRangeFor(channel);
if (_Vertical()) {
fMinpoint = frame.top + frame.Height() / 2;
if (fIsVertical) {
fMinPoint = frame.top + frame.Height() / 2;
frame.bottom += range;
} else {
// TODO: Fix this, the clickzone isn't perfect
frame.right += range;
fMinpoint = frame.Width();
fMinPoint = frame.Width();
}
// Click was on a slider.
@@ -387,7 +363,7 @@ BChannelSlider::MouseUp(BPoint where)
SetTracking(false);
fAllChannels = false;
fCurrentChannel = -1;
fMinpoint = 0;
fMinPoint = 0;
} else {
BChannelControl::MouseUp(where);
}
@@ -453,19 +429,12 @@ BChannelSlider::MakeFocus(bool focusState)
}
void
BChannelSlider::SetEnabled(bool on)
{
BChannelControl::SetEnabled(on);
}
void
BChannelSlider::GetPreferredSize(float* width, float* height)
{
_UpdateFontDimens();
if (_Vertical()) {
if (fIsVertical) {
*width = 11.0 * CountChannels();
*width = max_c(*width, ceilf(StringWidth(Label())));
*width = max_c(*width, ceilf(StringWidth(MinLimitLabel())));
@@ -475,24 +444,26 @@ BChannelSlider::GetPreferredSize(float *width, float *height)
*height = (fLineFeed * 3.0) + (kPadding * 2.0) + 147.0;
} else {
*width = max_c(64.0, ceilf(StringWidth(Label())));
*width = max_c(*width, ceilf(StringWidth(MinLimitLabel())) +
ceilf(StringWidth(MaxLimitLabel())) + 10.0);
*width = max_c(*width, ceilf(StringWidth(MinLimitLabel()))
+ ceilf(StringWidth(MaxLimitLabel())) + 10.0);
*width += kPadding * 2.0;
*height = 11.0 * CountChannels() + (fLineFeed * 2.0) + (kPadding * 2.0);
*height = 11.0 * CountChannels() + (fLineFeed * 2.0)
+ (kPadding * 2.0);
}
}
BHandler*
BChannelSlider::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
int32 form, const char *property)
BChannelSlider::ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 form, const char* property)
{
BHandler* target = this;
BPropertyInfo propertyInfo(sPropertyInfo);
if (propertyInfo.FindMatch(msg, index, specifier, form, property) < B_OK) {
target = BChannelControl::ResolveSpecifier(msg, index, specifier, form,
property);
if (propertyInfo.FindMatch(message, index, specifier, form,
property) != B_OK) {
target = BChannelControl::ResolveSpecifier(message, index, specifier,
form, property);
}
return target;
}
@@ -517,14 +488,55 @@ BChannelSlider::GetSupportedSuites(BMessage *data)
void
BChannelSlider::DrawChannel(BView *into, int32 channel, BRect area, bool pressed)
BChannelSlider::SetEnabled(bool on)
{
BChannelControl::SetEnabled(on);
}
orientation
BChannelSlider::Orientation() const
{
return fIsVertical ? B_VERTICAL : B_HORIZONTAL;
}
void
BChannelSlider::SetOrientation(enum orientation orientation)
{
bool isVertical = orientation == B_VERTICAL;
if (isVertical != fIsVertical) {
fIsVertical = isVertical;
InvalidateLayout();
Invalidate(Bounds());
}
}
int32
BChannelSlider::MaxChannelCount() const
{
return 32;
}
bool
BChannelSlider::SupportsIndividualLimits() const
{
return false;
}
void
BChannelSlider::DrawChannel(BView* into, int32 channel, BRect area,
bool pressed)
{
float hCenter = area.Width() / 2;
float vCenter = area.Height() / 2;
BPoint leftTop;
BPoint bottomRight;
if (_Vertical()) {
if (fIsVertical) {
leftTop.Set(area.left + hCenter, area.top + vCenter);
bottomRight.Set(leftTop.x, leftTop.y + ThumbRangeFor(channel));
} else {
@@ -535,7 +547,7 @@ BChannelSlider::DrawChannel(BView *into, int32 channel, BRect area, bool pressed
DrawGroove(into, channel, leftTop, bottomRight);
BPoint thumbLocation = leftTop;
if (_Vertical())
if (fIsVertical)
thumbLocation.y += ThumbDeltaFor(channel);
else
thumbLocation.x += ThumbDeltaFor(channel);
@@ -573,7 +585,8 @@ BChannelSlider::DrawGroove(BView *into, int32 channel, BPoint leftTop,
void
BChannelSlider::DrawThumb(BView* into, int32 channel, BPoint where, bool pressed)
BChannelSlider::DrawThumb(BView* into, int32 channel, BPoint where,
bool pressed)
{
ASSERT(into != NULL);
@@ -627,16 +640,18 @@ BChannelSlider::DrawThumb(BView* into, int32 channel, BPoint where, bool pressed
const BBitmap*
BChannelSlider::ThumbFor(int32 channel, bool pressed)
{
// TODO: Finish me
// TODO: Finish me (check allocations... etc)
if (fLeftKnob == NULL) {
if (_Vertical()) {
fLeftKnob = new (std::nothrow) BBitmap(BRect(0, 0, 11, 14), B_CMAP8);
if (fIsVertical) {
fLeftKnob = new (std::nothrow) BBitmap(BRect(0, 0, 11, 14),
B_CMAP8);
fLeftKnob->SetBits(kVerticalKnobData, sizeof(kVerticalKnobData), 0,
B_CMAP8);
} else {
fLeftKnob = new (std::nothrow) BBitmap(BRect(0, 0, 14, 11), B_CMAP8);
fLeftKnob->SetBits(kHorizontalKnobData, sizeof(kHorizontalKnobData),
0, B_CMAP8);
fLeftKnob = new (std::nothrow) BBitmap(BRect(0, 0, 14, 11),
B_CMAP8);
fLeftKnob->SetBits(kHorizontalKnobData,
sizeof(kHorizontalKnobData), 0, B_CMAP8);
}
}
@@ -653,11 +668,12 @@ BChannelSlider::ThumbFrameFor(int32 channel)
const BBitmap* thumb = ThumbFor(channel, false);
if (thumb != NULL) {
frame = thumb->Bounds();
if (_Vertical()) {
if (fIsVertical) {
frame.OffsetBy(channel * frame.Width(), (frame.Height() / 2.0) -
(kPadding * 2.0) - 1.0);
} else {
frame.OffsetBy(frame.Width() / 2.0, channel * frame.Height() + 1.0);
frame.OffsetBy(frame.Width() / 2.0, channel * frame.Height()
+ 1.0);
}
}
return frame;
@@ -671,9 +687,10 @@ BChannelSlider::ThumbDeltaFor(int32 channel)
if (channel >= 0 && channel < MaxChannelCount()) {
float range = ThumbRangeFor(channel);
int32 limitRange = MaxLimitList()[channel] - MinLimitList()[channel];
delta = (ValueList()[channel] - MinLimitList()[channel]) * range / limitRange;
delta = (ValueList()[channel] - MinLimitList()[channel]) * range
/ limitRange;
if (_Vertical())
if (fIsVertical)
delta = range - delta;
}
@@ -689,7 +706,7 @@ BChannelSlider::ThumbRangeFor(int32 channel)
float range = 0;
BRect bounds = Bounds();
BRect frame = ThumbFrameFor(channel);
if (_Vertical()) {
if (fIsVertical) {
// *height = (fLineFeed * 3.0) + (kPadding * 2.0) + 100.0;
range = bounds.Height() - frame.Height() - (fLineFeed * 3.0) -
(kPadding * 2.0);
@@ -701,6 +718,9 @@ BChannelSlider::ThumbRangeFor(int32 channel)
}
// #pragma mark -
void
BChannelSlider::_InitData()
{
@@ -711,13 +731,13 @@ BChannelSlider::_InitData()
fRightKnob = NULL;
fBacking = NULL;
fBackingView = NULL;
fVertical = Bounds().Width() / Bounds().Height() < 1;
fIsVertical = Bounds().Width() / Bounds().Height() < 1;
fClickDelta = B_ORIGIN;
fCurrentChannel = -1;
fAllChannels = false;
fInitialValues = NULL;
fMinpoint = 0;
fMinPoint = 0;
fFocusChannel = -1;
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -738,12 +758,13 @@ BChannelSlider::_FinishChange(bool update)
inMask[fCurrentChannel] = true;
}
}
InvokeChannel(update ? ModificationMessage() : NULL, 0, numChannels, inMask);
InvokeChannel(update ? ModificationMessage() : NULL, 0, numChannels,
inMask);
}
if (!update) {
SetTracking(false);
_Redraw();
Invalidate();
}
}
@@ -768,7 +789,7 @@ BChannelSlider::_DrawThumbs()
BRect last = ThumbFrameFor(CountChannels() - 1);
BRect rect(first.LeftTop(), last.RightBottom());
if (_Vertical())
if (fIsVertical)
rect.top -= ThumbRangeFor(0);
else
rect.right += ThumbRangeFor(0);
@@ -781,8 +802,10 @@ BChannelSlider::_DrawThumbs()
if (fBacking->Lock()) {
fBacking->AddChild(fBackingView);
fBackingView->SetFontSize(10.0);
fBackingView->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fBackingView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fBackingView->SetLowColor(
ui_color(B_PANEL_BACKGROUND_COLOR));
fBackingView->SetViewColor(
ui_color(B_PANEL_BACKGROUND_COLOR));
fBacking->Unlock();
}
} else {
@@ -812,7 +835,7 @@ BChannelSlider::_DrawThumbs()
}
// draw some kind of current value tool tip
if (fCurrentChannel != -1 && fMinpoint != 0) {
if (fCurrentChannel != -1 && fMinPoint != 0) {
char valueString[32];
snprintf(valueString, 32, "%ld", ValueFor(fCurrentChannel));
float stringWidth = fBackingView->StringWidth(valueString);
@@ -822,24 +845,28 @@ BChannelSlider::_DrawThumbs()
BRect thumbFrame(ThumbFrameFor(fCurrentChannel));
float thumbDelta(ThumbDeltaFor(fCurrentChannel));
if (_Vertical()) {
if (fIsVertical) {
valueRect.OffsetTo((thumbFrame.Width() - width) / 2.0 +
fCurrentChannel * thumbFrame.Width(),
thumbDelta + thumbFrame.Height() + 2.0);
if (valueRect.bottom > fBackingView->Frame().bottom)
valueRect.OffsetBy(0.0, -(thumbFrame.Height() + 12.0));
} else {
valueRect.OffsetTo((thumbDelta - (width + 2.0)), thumbFrame.top);
if (valueRect.left < fBackingView->Frame().left)
valueRect.OffsetBy(thumbFrame.Width() + width + 2.0, 0.0);
valueRect.OffsetTo((thumbDelta - (width + 2.0)),
thumbFrame.top);
if (valueRect.left < fBackingView->Frame().left) {
valueRect.OffsetBy(thumbFrame.Width() + width + 2.0,
0.0);
}
}
rgb_color oldColor = fBackingView->HighColor();
fBackingView->SetHighColor(255, 255, 172);
fBackingView->FillRect(valueRect);
fBackingView->SetHighColor(0, 0, 0);
fBackingView->DrawString(valueString, BPoint(valueRect.left +
(valueRect.Width() - stringWidth) / 2.0, valueRect.bottom -1.0));
fBackingView->DrawString(valueString, BPoint(valueRect.left
+ (valueRect.Width() - stringWidth) / 2.0, valueRect.bottom
- 1.0));
fBackingView->StrokeRect(valueRect.InsetByCopy(-0.5, -0.5));
fBackingView->SetHighColor(oldColor);
}
@@ -879,21 +906,6 @@ BChannelSlider::_DrawGrooveFrame(BView *into, const BRect &area)
}
bool
BChannelSlider::_Vertical() const
{
return fVertical;
}
void
BChannelSlider::_Redraw()
{
Invalidate(Bounds());
Flush();
}
void
BChannelSlider::_MouseMovedCommon(BPoint point, BPoint point2)
{
@@ -901,10 +913,10 @@ BChannelSlider::_MouseMovedCommon(BPoint point, BPoint point2)
int32 limitRange = MaxLimitList()[fCurrentChannel] -
MinLimitList()[fCurrentChannel];
float range = ThumbRangeFor(fCurrentChannel);
if (_Vertical())
floatValue = range - (point.y - fMinpoint);
if (fIsVertical)
floatValue = range - (point.y - fMinPoint);
else
floatValue = range + (point.x - fMinpoint);
floatValue = range + (point.x - fMinPoint);
int32 value = (int32)(floatValue / range * limitRange) +
MinLimitList()[fCurrentChannel];
@@ -920,6 +932,9 @@ BChannelSlider::_MouseMovedCommon(BPoint point, BPoint point2)
}
// #pragma mark - FBC padding
void BChannelSlider::_Reserved_BChannelSlider_0(void*, ...) {}
void BChannelSlider::_Reserved_BChannelSlider_1(void*, ...) {}
void BChannelSlider::_Reserved_BChannelSlider_2(void*, ...) {}