Minor cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21155 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-05-16 15:50:04 +00:00
parent 8ca5764554
commit da7c734d5c
+37 -37
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2006, Haiku Inc. * Copyright 2001-2007, Haiku Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -14,14 +14,15 @@
BCheckBox::BCheckBox(BRect frame, const char *name, const char *label, BCheckBox::BCheckBox(BRect frame, const char *name, const char *label,
BMessage *message, uint32 resizingMode, uint32 flags) BMessage *message, uint32 resizingMode, uint32 flags)
: BControl(frame, name, label, message, resizingMode, flags), : BControl(frame, name, label, message, resizingMode, flags),
fOutlined(false) fOutlined(false)
{ {
// Resize to minimum height if needed // Resize to minimum height if needed
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
float minHeight = (float)ceil(6.0f + fontHeight.ascent + fontHeight.descent); float minHeight = (float)ceil(6.0f + fontHeight.ascent
+ fontHeight.descent);
if (Bounds().Height() < minHeight) if (Bounds().Height() < minHeight)
ResizeTo(Bounds().Width(), minHeight); ResizeTo(Bounds().Width(), minHeight);
} }
@@ -52,7 +53,7 @@ BCheckBox::Instantiate(BMessage *archive)
status_t status_t
BCheckBox::Archive(BMessage *archive, bool deep) const BCheckBox::Archive(BMessage *archive, bool deep) const
{ {
return BControl::Archive(archive,deep); return BControl::Archive(archive, deep);
} }
@@ -73,24 +74,23 @@ BCheckBox::Draw(BRect updateRect)
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y)); StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
return; return;
} }
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR);
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT), rgb_color lighten1 = tint_color(noTint, B_LIGHTEN_1_TINT);
lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), rgb_color lightenMax = tint_color(noTint, B_LIGHTEN_MAX_TINT);
darken1 = tint_color(no_tint, B_DARKEN_1_TINT), rgb_color darken1 = tint_color(noTint, B_DARKEN_1_TINT);
darken2 = tint_color(no_tint, B_DARKEN_2_TINT), rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT);
darken3 = tint_color(no_tint, B_DARKEN_3_TINT), rgb_color darken3 = tint_color(noTint, B_DARKEN_3_TINT);
darken4 = tint_color(no_tint, B_DARKEN_4_TINT), rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT);
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); rgb_color darkenmax = tint_color(noTint, B_DARKEN_MAX_TINT);
BRect rect = _CheckBoxFrame(); BRect rect = _CheckBoxFrame();
if (IsEnabled()) { if (IsEnabled()) {
// Filling // Filling
SetHighColor(lightenmax); SetHighColor(lightenMax);
FillRect(rect); FillRect(rect);
// Box // Box
@@ -98,7 +98,7 @@ BCheckBox::Draw(BRect updateRect)
SetHighColor(darken3); SetHighColor(darken3);
StrokeRect(rect); StrokeRect(rect);
rect.InsetBy(1,1); rect.InsetBy(1, 1);
BeginLineArray(6); BeginLineArray(6);
@@ -119,33 +119,33 @@ BCheckBox::Draw(BRect updateRect)
BPoint(rect.left, rect.top), darken1); BPoint(rect.left, rect.top), darken1);
AddLine(BPoint(rect.left, rect.top), AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.top), darken1); BPoint(rect.right, rect.top), darken1);
rect.InsetBy(1,1); rect.InsetBy(1, 1);
AddLine(BPoint(rect.left, rect.bottom), AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left, rect.top), darken4); BPoint(rect.left, rect.top), darken4);
AddLine(BPoint(rect.left, rect.top), AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.top), darken4); BPoint(rect.right, rect.top), darken4);
AddLine(BPoint(rect.left + 1.0f, rect.bottom), AddLine(BPoint(rect.left + 1.0f, rect.bottom),
BPoint(rect.right, rect.bottom), no_tint); BPoint(rect.right, rect.bottom), noTint);
AddLine(BPoint(rect.right, rect.bottom), AddLine(BPoint(rect.right, rect.bottom),
BPoint(rect.right, rect.top + 1.0f), no_tint); BPoint(rect.right, rect.top + 1.0f), noTint);
EndLineArray(); EndLineArray();
} }
// Checkmark // Checkmark
if (Value() == B_CONTROL_ON) { if (Value() == B_CONTROL_ON) {
rect.InsetBy(2,2); rect.InsetBy(2, 2);
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
SetPenSize(2); SetPenSize(2);
// Yes, Haiku is differnt because of the anti-aliasing SetDrawingMode(B_OP_OVER);
SetDrawingMode(B_OP_OVER); // needed because of anti-aliasing
StrokeLine(BPoint(rect.left, rect.top), StrokeLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.bottom)); BPoint(rect.right, rect.bottom));
StrokeLine(BPoint(rect.left, rect.bottom), StrokeLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.top)); BPoint(rect.right, rect.top));
SetPenSize(1); SetPenSize(1);
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
} }
// Label // Label
@@ -170,10 +170,10 @@ SetDrawingMode(B_OP_COPY);
BeginLineArray(6); BeginLineArray(6);
AddLine(BPoint(rect.left, rect.bottom), AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left, rect.top), no_tint); BPoint(rect.left, rect.top), noTint);
AddLine(BPoint(rect.left, rect.top), AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.top), no_tint); BPoint(rect.right, rect.top), noTint);
rect.InsetBy(1,1); rect.InsetBy(1, 1);
AddLine(BPoint(rect.left, rect.bottom), AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left, rect.top), darken2); BPoint(rect.left, rect.top), darken2);
AddLine(BPoint(rect.left, rect.top), AddLine(BPoint(rect.left, rect.top),
@@ -192,18 +192,18 @@ SetDrawingMode(B_OP_COPY);
SetHighColor(tint_color(ui_color(B_KEYBOARD_NAVIGATION_COLOR), SetHighColor(tint_color(ui_color(B_KEYBOARD_NAVIGATION_COLOR),
B_DISABLED_MARK_TINT)); B_DISABLED_MARK_TINT));
SetPenSize(2); SetPenSize(2);
// Yes, Haiku is differnt because of the anti-aliasing SetDrawingMode(B_OP_OVER);
SetDrawingMode(B_OP_OVER); // needed because of anti-aliasing
StrokeLine(BPoint(rect.left, rect.top), StrokeLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.bottom)); BPoint(rect.right, rect.bottom));
StrokeLine(BPoint(rect.left, rect.bottom), StrokeLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.top)); BPoint(rect.right, rect.top));
SetPenSize(1); SetPenSize(1);
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
} }
// Label // Label
SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT)); SetHighColor(tint_color(noTint, B_DISABLED_LABEL_TINT));
DrawString(Label(), BPoint((float)ceil(10.0f + fontHeight.ascent), DrawString(Label(), BPoint((float)ceil(10.0f + fontHeight.ascent),
3.0f + (float)ceil(fontHeight.ascent))); 3.0f + (float)ceil(fontHeight.ascent)));
} }
@@ -242,7 +242,6 @@ BCheckBox::MouseDown(BPoint point)
GetMouse(&point, &buttons, true); GetMouse(&point, &buttons, true);
bool inside = bounds.Contains(point); bool inside = bounds.Contains(point);
if (fOutlined != inside) { if (fOutlined != inside) {
fOutlined = inside; fOutlined = inside;
Invalidate(); Invalidate();
@@ -309,8 +308,7 @@ BCheckBox::MouseUp(BPoint point)
void void
BCheckBox::MouseMoved(BPoint point, uint32 transit, BCheckBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
const BMessage *message)
{ {
if (!IsTracking()) if (!IsTracking())
return; return;
@@ -396,7 +394,8 @@ BHandler *
BCheckBox::ResolveSpecifier(BMessage *message, int32 index, BCheckBox::ResolveSpecifier(BMessage *message, int32 index,
BMessage *specifier, int32 what, const char *property) BMessage *specifier, int32 what, const char *property)
{ {
return BControl::ResolveSpecifier(message, index, specifier, what, property); return BControl::ResolveSpecifier(message, index, specifier, what,
property);
} }
@@ -446,12 +445,13 @@ BCheckBox::operator=(const BCheckBox &)
return *this; return *this;
} }
// _CheckBoxFrame
BRect BRect
BCheckBox::_CheckBoxFrame() const BCheckBox::_CheckBoxFrame() const
{ {
font_height fh; font_height fontHeight;
GetFontHeight(&fh); GetFontHeight(&fontHeight);
return BRect(1.0f, 3.0f, ceilf(3.0f + fh.ascent), ceilf(5.0f + fh.ascent)); return BRect(1.0f, 3.0f, ceilf(3.0f + fontHeight.ascent),
ceilf(5.0f + fontHeight.ascent));
} }