* Now draws the UpdateText() label as well (was obviously forgotten before).

To reduce the number of calls to UpdateText(), the value returned is now
  buffered. This fixes bug #443.
* SetValue() now calls UpdateText() and also invalidates the region where
  that label is drawn.
* In asynchronous mode, B_NO_POINTER_HISTORY is set now for tracking.
* Increased minimum snooze time in synchronous mode.
* Minor cleanup, renamed fMinLimitStr to fMinLimitLabel, etc.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17146 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-04-16 20:45:22 +00:00
parent c4d51ab434
commit e762848ab2
2 changed files with 106 additions and 76 deletions
+6 -5
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2005, Haiku. * Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -171,8 +171,9 @@ class BSlider : public BControl {
rgb_color fFillColor; rgb_color fFillColor;
bool fUseFillColor; bool fUseFillColor;
char* fMinLimitStr; char* fMinLimitLabel;
char* fMaxLimitStr; char* fMaxLimitLabel;
char* fUpdateText;
int32 fMinValue; int32 fMinValue;
int32 fMaxValue; int32 fMaxValue;
@@ -195,9 +196,9 @@ class BSlider : public BControl {
float fBarThickness; float fBarThickness;
#if USE_OFF_SCREEN_VIEW #if USE_OFF_SCREEN_VIEW
uint32 _reserved[8]; uint32 _reserved[7];
#else #else
uint32 _reserved[10]; uint32 _reserved[9];
#endif #endif
}; };
+100 -71
View File
@@ -49,8 +49,8 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes
fSnoozeAmount = 20000; fSnoozeAmount = 20000;
fOrientation = B_HORIZONTAL; fOrientation = B_HORIZONTAL;
fBarThickness = 6.0f; fBarThickness = 6.0f;
fMinLimitStr = NULL; fMinLimitLabel = NULL;
fMaxLimitStr = NULL; fMaxLimitLabel = NULL;
fMinValue = minValue; fMinValue = minValue;
fMaxValue = maxValue; fMaxValue = maxValue;
@@ -61,12 +61,13 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes
fHashMarks = B_HASH_MARKS_NONE; fHashMarks = B_HASH_MARKS_NONE;
fStyle = thumbType; fStyle = thumbType;
if (Style() == B_BLOCK_THUMB) if (Style() == B_BLOCK_THUMB) {
SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_4_TINT)); B_DARKEN_4_TINT));
else } else {
SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_4_TINT)); B_DARKEN_4_TINT));
}
UseFillColor(false, NULL); UseFillColor(false, NULL);
@@ -83,8 +84,8 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes
fSnoozeAmount = 20000; fSnoozeAmount = 20000;
fOrientation = posture; fOrientation = posture;
fBarThickness = 6.0f; fBarThickness = 6.0f;
fMinLimitStr = NULL; fMinLimitLabel = NULL;
fMaxLimitStr = NULL; fMaxLimitLabel = NULL;
fMinValue = minValue; fMinValue = minValue;
fMaxValue = maxValue; fMaxValue = maxValue;
@@ -108,21 +109,8 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes
} }
BSlider::~BSlider()
{
#if USE_OFF_SCREEN_VIEW
if (fOffScreenBits)
delete fOffScreenBits;
#endif
delete fModificationMessage;
free(fMinLimitStr);
free(fMaxLimitStr);
}
BSlider::BSlider(BMessage *archive) BSlider::BSlider(BMessage *archive)
: BControl (archive) : BControl(archive)
{ {
fModificationMessage = NULL; fModificationMessage = NULL;
@@ -152,8 +140,8 @@ BSlider::BSlider(BMessage *archive)
else else
fOrientation = B_HORIZONTAL; fOrientation = B_HORIZONTAL;
fMinLimitStr = NULL; fMinLimitLabel = NULL;
fMaxLimitStr = NULL; fMaxLimitLabel = NULL;
const char *minlbl = NULL, *maxlbl = NULL; const char *minlbl = NULL, *maxlbl = NULL;
@@ -210,6 +198,19 @@ BSlider::BSlider(BMessage *archive)
} }
BSlider::~BSlider()
{
#if USE_OFF_SCREEN_VIEW
if (fOffScreenBits)
delete fOffScreenBits;
#endif
delete fModificationMessage;
free(fMinLimitLabel);
free(fMaxLimitLabel);
}
void void
BSlider::_InitObject() BSlider::_InitObject()
{ {
@@ -222,6 +223,8 @@ BSlider::_InitObject()
fOffScreenBits = NULL; fOffScreenBits = NULL;
fOffScreenView = NULL; fOffScreenView = NULL;
#endif #endif
fUpdateText = NULL;
} }
@@ -250,11 +253,11 @@ BSlider::Archive(BMessage *archive, bool deep) const
if (FillColor(NULL)) if (FillColor(NULL))
archive->AddInt32("_fcolor", _color_to_long_(fFillColor)); archive->AddInt32("_fcolor", _color_to_long_(fFillColor));
if (fMinLimitStr) if (fMinLimitLabel)
archive->AddString("_minlbl", fMinLimitStr); archive->AddString("_minlbl", fMinLimitLabel);
if (fMaxLimitStr) if (fMaxLimitLabel)
archive->AddString("_maxlbl", fMaxLimitStr); archive->AddString("_maxlbl", fMaxLimitLabel);
archive->AddInt32("_min", fMinValue); archive->AddInt32("_min", fMinValue);
archive->AddInt32("_max", fMaxValue); archive->AddInt32("_max", fMaxValue);
@@ -295,6 +298,7 @@ BSlider::AttachedToWindow()
ResizeToPreferred(); ResizeToPreferred();
fLocation.Set(9.0f, 0.0f); fLocation.Set(9.0f, 0.0f);
fUpdateText = UpdateText();
#if USE_OFF_SCREEN_VIEW #if USE_OFF_SCREEN_VIEW
BRect bounds(Bounds()); BRect bounds(Bounds());
@@ -324,7 +328,6 @@ BSlider::AttachedToWindow()
BControl::AttachedToWindow(); BControl::AttachedToWindow();
if (view) { if (view) {
rgb_color color = ViewColor(); rgb_color color = ViewColor();
if (Parent() != NULL) if (Parent() != NULL)
color = Parent()->ViewColor(); color = Parent()->ViewColor();
@@ -482,7 +485,7 @@ BSlider::MouseDown(BPoint point)
if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) { if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
SetTracking(true); SetTracking(true);
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY);
} else { } else {
// synchronous mouse tracking // synchronous mouse tracking
BPoint prevPoint; BPoint prevPoint;
@@ -551,15 +554,13 @@ void
BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel) BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel)
{ {
if (minLabel) { if (minLabel) {
if (fMinLimitStr) free(fMinLimitLabel);
free(fMinLimitStr); fMinLimitLabel = strdup(minLabel);
fMinLimitStr = strdup(minLabel);
} }
if (maxLabel) { if (maxLabel) {
if (fMaxLimitStr) free(fMaxLimitLabel);
free(fMaxLimitStr); fMaxLimitLabel = strdup(maxLabel);
fMaxLimitStr = strdup(maxLabel);
} }
// TODO: Auto resizing?!? I would not want this as an app programmer! // TODO: Auto resizing?!? I would not want this as an app programmer!
@@ -571,14 +572,14 @@ BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel)
const char* const char*
BSlider::MinLimitLabel() const BSlider::MinLimitLabel() const
{ {
return fMinLimitStr; return fMinLimitLabel;
} }
const char* const char*
BSlider::MaxLimitLabel() const BSlider::MaxLimitLabel() const
{ {
return fMaxLimitStr; return fMaxLimitLabel;
} }
@@ -625,6 +626,26 @@ BSlider::SetValue(int32 value)
BControl::SetValueNoUpdate(value); BControl::SetValueNoUpdate(value);
Invalidate(oldThumbFrame | ThumbFrame()); Invalidate(oldThumbFrame | ThumbFrame());
// update text label
float oldWidth = 0.0f, width = 0.0f;
if (fUpdateText != NULL)
oldWidth = StringWidth(fUpdateText);
fUpdateText = UpdateText();
if (fUpdateText != NULL)
width = StringWidth(fUpdateText);
width = ceilf(max_c(width, oldWidth)) + 2.0f;
if (width != 0) {
font_height fontHeight;
GetFontHeight(&fontHeight);
BRect rect(-width, 0, 0, ceilf(fontHeight.ascent + fontHeight.descent));
rect.OffsetBy(Bounds().Width(), 0);
Invalidate(rect);
}
} }
} }
@@ -692,7 +713,6 @@ BSlider::Draw(BRect updateRect)
if (Style() == B_BLOCK_THUMB) if (Style() == B_BLOCK_THUMB)
background.Exclude(ThumbFrame()); background.Exclude(ThumbFrame());
#if USE_OFF_SCREEN_VIEW #if USE_OFF_SCREEN_VIEW
if (!fOffScreenBits) if (!fOffScreenBits)
return; return;
@@ -989,40 +1009,49 @@ BSlider::DrawText()
view->SetHighColor(tint_color(LowColor(), B_DISABLED_LABEL_TINT)); view->SetHighColor(tint_color(LowColor(), B_DISABLED_LABEL_TINT));
} }
font_height fheight; font_height fontHeight;
GetFontHeight(&fontHeight);
GetFontHeight(&fheight);
if (Orientation() == B_HORIZONTAL) { if (Orientation() == B_HORIZONTAL) {
if (Label()) if (Label())
view->DrawString(Label(), BPoint(2.0f, (float)ceil(fheight.ascent))); view->DrawString(Label(), BPoint(2.0f, ceilf(fontHeight.ascent)));
if (fMinLimitStr) // the update text is updated in SetValue() only
view->DrawString(fMinLimitStr, BPoint(2.0f, bounds.bottom - 4.0f)); if (fUpdateText != NULL) {
view->DrawString(fUpdateText, BPoint(bounds.right - StringWidth(fUpdateText)
- 2.0f, ceilf(fontHeight.ascent)));
}
if (fMaxLimitStr) if (fMinLimitLabel)
view->DrawString(fMaxLimitStr, BPoint(bounds.right - view->DrawString(fMinLimitLabel, BPoint(2.0f, bounds.bottom - 4.0f));
StringWidth(fMaxLimitStr) - 2.0f,
bounds.bottom - 4.0f)); if (fMaxLimitLabel) {
view->DrawString(fMaxLimitLabel, BPoint(bounds.right
- StringWidth(fMaxLimitLabel) - 2.0f, bounds.bottom - 4.0f));
}
} else { } else {
float ascent = (float)ceil(fheight.ascent); if (Label()) {
if (Label())
view->DrawString(Label(), BPoint(bounds.Width() / 2.0f - view->DrawString(Label(), BPoint(bounds.Width() / 2.0f -
StringWidth(Label()) / 2.0f, StringWidth(Label()) / 2.0f,
ascent)); fontHeight.ascent));
}
if (fMaxLimitStr) if (fUpdateText != NULL) {
view->DrawString(fMaxLimitStr, BPoint(bounds.Width() / 2.0f - view->DrawString(fUpdateText, BPoint(bounds.Width() / 2.0f -
StringWidth(fMaxLimitStr) / 2.0f, StringWidth(fUpdateText) / 2.0f, bounds.bottom - fontHeight.descent - 4.0f));
ascent + }
(Label() ? (float)ceil(ascent + fheight.descent + 2.0f)
: 0.0f)));
if (fMinLimitStr) if (fMaxLimitLabel) {
view->DrawString(fMinLimitStr, BPoint(bounds.Width() / 2.0f - view->DrawString(fMaxLimitLabel, BPoint(bounds.Width() / 2.0f -
StringWidth(fMinLimitStr) / 2.0f, StringWidth(fMaxLimitLabel) / 2.0f, fontHeight.ascent + (Label()
bounds.bottom - 2.0f)); ? ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading + 2.0f)
: 0.0f)));
}
if (fMinLimitLabel) {
view->DrawString(fMinLimitLabel, BPoint(bounds.Width() / 2.0f
- StringWidth(fMinLimitLabel) / 2.0f, bounds.bottom - 2.0f));
}
} }
} }
@@ -1053,10 +1082,10 @@ BSlider::BarFrame() const
} else { } else {
frame.left = floor((frame.Width() - fBarThickness) / 2.0f); frame.left = floor((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); (fMaxLimitLabel ? textHeight : 0.0f);
frame.right = frame.left + fBarThickness; frame.right = frame.left + fBarThickness;
frame.bottom = frame.bottom - 8.0f - frame.bottom = frame.bottom - 8.0f -
(fMinLimitStr ? textHeight + 4 : 0.0f); (fMinLimitLabel ? textHeight + 4 : 0.0f);
} }
} else { } else {
if (Orientation() == B_HORIZONTAL) { if (Orientation() == B_HORIZONTAL) {
@@ -1067,10 +1096,10 @@ BSlider::BarFrame() const
} else { } else {
frame.left = floor((frame.Width() - fBarThickness) / 2.0f); frame.left = floor((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); (fMaxLimitLabel ? textHeight : 0.0f);
frame.right = frame.left + fBarThickness; frame.right = frame.left + fBarThickness;
frame.bottom = frame.bottom - 7.0f - frame.bottom = frame.bottom - 7.0f -
(fMinLimitStr ? textHeight + 4 : 0.0f); (fMinLimitLabel ? textHeight + 4 : 0.0f);
} }
} }
@@ -1293,14 +1322,14 @@ BSlider::ModificationMessage() const
void void
BSlider::SetSnoozeAmount(int32 snooze_time) BSlider::SetSnoozeAmount(int32 snoozeTime)
{ {
if (snooze_time < 5000) if (snoozeTime < 10000)
snooze_time = 5000; snoozeTime = 10000;
if (snooze_time > 1000000) else if (snoozeTime > 1000000)
snooze_time = 1000000; snoozeTime = 1000000;
fSnoozeAmount = snooze_time; fSnoozeAmount = snoozeTime;
} }