Removed duplicate code in drawing functions, fixed drawing of text when button is default, fixed drawing of text when button is disabled.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10979 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+121
-184
@@ -86,7 +86,7 @@ status_t BButton::Archive(BMessage* archive, bool deep) const
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::Draw(BRect updateRect)
|
void HButton::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
font_height fh;
|
font_height fh;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
@@ -120,163 +120,115 @@ void BButton::Draw(BRect updateRect)
|
|||||||
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
|
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
|
||||||
lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT),
|
lighten2 = tint_color(no_tint, B_LIGHTEN_2_TINT),
|
||||||
lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT),
|
lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT),
|
||||||
darken2 = tint_color(no_tint, B_DARKEN_2_TINT),
|
|
||||||
darken4 = tint_color(no_tint, B_DARKEN_4_TINT),
|
|
||||||
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT);
|
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT);
|
||||||
|
|
||||||
BRect rect(bounds);
|
BRect rect(bounds);
|
||||||
|
bool bEnabled = IsEnabled();
|
||||||
|
|
||||||
if (IsDefault())
|
if (IsDefault())
|
||||||
rect = DrawDefault(rect, IsEnabled());
|
rect = DrawDefault(rect, bEnabled);
|
||||||
else
|
else
|
||||||
rect.InsetBy(1,1);
|
rect.InsetBy(1,1);
|
||||||
|
|
||||||
if (IsEnabled())
|
// This can be set outside draw
|
||||||
|
if (bEnabled)
|
||||||
|
SetHighColor(tint_color(no_tint, B_DARKEN_4_TINT));
|
||||||
|
else
|
||||||
|
SetHighColor(tint_color(no_tint, B_DARKEN_2_TINT));
|
||||||
|
|
||||||
|
// Dark border
|
||||||
|
StrokeRect(rect);
|
||||||
|
|
||||||
|
BeginLineArray(8);
|
||||||
|
|
||||||
|
// Corners
|
||||||
|
rgb_color cornerColor = no_tint;
|
||||||
|
if (IsDefault())
|
||||||
|
cornerColor = lighten1;
|
||||||
|
AddLine(rect.LeftBottom(), rect.LeftBottom(), cornerColor);
|
||||||
|
AddLine(rect.LeftTop(), rect.LeftTop(), cornerColor);
|
||||||
|
AddLine(rect.RightTop(), rect.RightTop(), cornerColor);
|
||||||
|
AddLine(rect.RightBottom(), rect.RightBottom(), cornerColor);
|
||||||
|
|
||||||
|
rect.InsetBy(1, 1);
|
||||||
|
|
||||||
|
// First bevel
|
||||||
|
rgb_color firstBevelColor;
|
||||||
|
if (bEnabled)
|
||||||
|
firstBevelColor = tint_color(no_tint, B_DARKEN_2_TINT);
|
||||||
|
else
|
||||||
|
firstBevelColor = no_tint;
|
||||||
|
AddLine(BPoint(rect.left + 1.0f, rect.bottom),
|
||||||
|
BPoint(rect.right, rect.bottom), firstBevelColor);
|
||||||
|
AddLine(BPoint(rect.right, rect.bottom - 1.0f),
|
||||||
|
BPoint(rect.right, rect.top + 1.0f), firstBevelColor);
|
||||||
|
|
||||||
|
AddLine(BPoint(rect.left, rect.top),
|
||||||
|
BPoint(rect.left, rect.bottom), lighten1);
|
||||||
|
AddLine(BPoint(rect.left + 1.0f, rect.top),
|
||||||
|
BPoint(rect.right, rect.top), lighten1);
|
||||||
|
|
||||||
|
EndLineArray();
|
||||||
|
|
||||||
|
rect.InsetBy(1, 1);
|
||||||
|
|
||||||
|
// Second bevel
|
||||||
|
SetHighColor(lightenmax);
|
||||||
|
FillRect(rect);
|
||||||
|
|
||||||
|
SetHighColor(no_tint);
|
||||||
|
StrokeLine(BPoint(rect.right, rect.top + 1.0f),
|
||||||
|
BPoint(rect.right, rect.bottom));
|
||||||
|
StrokeLine(BPoint(rect.left + 1.0f, rect.bottom));
|
||||||
|
|
||||||
|
rect.InsetBy(1, 1);
|
||||||
|
|
||||||
|
// Filling
|
||||||
|
rect.left += 1.0f;
|
||||||
|
rect.top += 1.0f;
|
||||||
|
SetHighColor(lighten1);
|
||||||
|
FillRect(rect);
|
||||||
|
|
||||||
|
if (bEnabled && Value())
|
||||||
{
|
{
|
||||||
// This can be set outside draw
|
// Invert
|
||||||
SetHighColor(darken4);
|
rect.left -= 3;
|
||||||
|
rect.top -= 3;
|
||||||
|
rect.right += 2;
|
||||||
|
rect.bottom += 2;
|
||||||
|
InvertRect(rect);
|
||||||
|
}
|
||||||
|
|
||||||
// Dark border
|
// Label
|
||||||
StrokeRect(rect);
|
float x = (bounds.right - StringWidth(Label())) / 2.0f;
|
||||||
|
float y = bounds.top + ((bounds.Height() - fh.ascent - fh.descent) / 2.0f) + fh.ascent + 1;
|
||||||
|
|
||||||
BeginLineArray(8);
|
if (bEnabled && Value())
|
||||||
|
{
|
||||||
// Corners
|
|
||||||
AddLine(rect.LeftBottom(), rect.LeftBottom(), no_tint);
|
|
||||||
AddLine(rect.LeftTop(), rect.LeftTop(), no_tint);
|
|
||||||
AddLine(rect.RightTop(), rect.RightTop(), no_tint);
|
|
||||||
AddLine(rect.RightBottom(), rect.RightBottom(), no_tint);
|
|
||||||
|
|
||||||
rect.InsetBy(1, 1);
|
|
||||||
|
|
||||||
// First bevel
|
|
||||||
AddLine(BPoint(rect.left + 1.0f, rect.bottom),
|
|
||||||
BPoint(rect.right, rect.bottom), darken2);
|
|
||||||
AddLine(BPoint(rect.right, rect.bottom - 1.0f),
|
|
||||||
BPoint(rect.right, rect.top + 1.0f), darken2);
|
|
||||||
|
|
||||||
AddLine(BPoint(rect.left, rect.top),
|
|
||||||
BPoint(rect.left, rect.bottom), lighten1);
|
|
||||||
AddLine(BPoint(rect.left + 1.0f, rect.top),
|
|
||||||
BPoint(rect.right, rect.top), lighten1);
|
|
||||||
|
|
||||||
EndLineArray();
|
|
||||||
|
|
||||||
rect.InsetBy(1, 1);
|
|
||||||
|
|
||||||
// Second bevel
|
|
||||||
SetHighColor(lightenmax);
|
SetHighColor(lightenmax);
|
||||||
FillRect(rect);
|
SetLowColor(darkenmax);
|
||||||
|
|
||||||
SetHighColor(no_tint);
|
|
||||||
StrokeLine(BPoint(rect.right, rect.top + 1.0f),
|
|
||||||
BPoint(rect.right, rect.bottom));
|
|
||||||
StrokeLine(BPoint(rect.left + 1.0f, rect.bottom));
|
|
||||||
|
|
||||||
rect.InsetBy(1, 1);
|
|
||||||
|
|
||||||
// Filling
|
|
||||||
rect.left += 1.0f;
|
|
||||||
rect.top += 1.0f;
|
|
||||||
SetHighColor(lighten1);
|
|
||||||
FillRect(rect);
|
|
||||||
|
|
||||||
if (Value())
|
|
||||||
{
|
|
||||||
// Invert
|
|
||||||
rect.left -= 3;
|
|
||||||
rect.top -= 3;
|
|
||||||
rect.right += 2;
|
|
||||||
rect.bottom += 2;
|
|
||||||
InvertRect(rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Label
|
|
||||||
float x = (bounds.right - StringWidth(Label())) / 2.0f;
|
|
||||||
float y = bounds.top + ((bounds.Height() - fh.ascent - fh.descent) / 2.0f) + fh.ascent + 1;
|
|
||||||
|
|
||||||
|
|
||||||
if (Value())
|
|
||||||
{
|
|
||||||
SetHighColor(lightenmax);
|
|
||||||
SetLowColor(darkenmax);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetHighColor(darkenmax);
|
|
||||||
SetLowColor(lighten2);
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawString(Label(), BPoint(x, y));
|
|
||||||
|
|
||||||
if (IsFocus() && Window()->IsActive())
|
|
||||||
{
|
|
||||||
// Draw focus line
|
|
||||||
y += fh.descent;
|
|
||||||
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
|
||||||
StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
|
|
||||||
SetHighColor(255, 255, 255);
|
|
||||||
StrokeLine(BPoint(x, y + 1), BPoint(x + StringWidth(Label()), y + 1));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This can be set outside draw
|
if (bEnabled)
|
||||||
SetHighColor(darken2);
|
SetHighColor(darkenmax);
|
||||||
|
else
|
||||||
// Dark border
|
SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT));
|
||||||
StrokeRect(rect);
|
|
||||||
|
|
||||||
BeginLineArray(8);
|
|
||||||
|
|
||||||
// Corners
|
|
||||||
AddLine(rect.LeftBottom(), rect.LeftBottom(), no_tint);
|
|
||||||
AddLine(rect.LeftTop(), rect.LeftTop(), no_tint);
|
|
||||||
AddLine(rect.RightTop(), rect.RightTop(), no_tint);
|
|
||||||
AddLine(rect.RightBottom(), rect.RightBottom(), no_tint);
|
|
||||||
|
|
||||||
rect.InsetBy(1, 1);
|
|
||||||
|
|
||||||
// First bevel
|
|
||||||
AddLine(BPoint(rect.left + 1.0f, rect.bottom),
|
|
||||||
BPoint(rect.right, rect.bottom), no_tint);
|
|
||||||
AddLine(BPoint(rect.right, rect.bottom - 1.0f),
|
|
||||||
BPoint(rect.right, rect.top + 1.0f), no_tint);
|
|
||||||
|
|
||||||
AddLine(BPoint(rect.left, rect.top),
|
|
||||||
BPoint(rect.left, rect.bottom), lighten1);
|
|
||||||
AddLine(BPoint(rect.left + 1.0f, rect.top),
|
|
||||||
BPoint(rect.right, rect.top), lighten1);
|
|
||||||
|
|
||||||
EndLineArray();
|
|
||||||
|
|
||||||
rect.InsetBy(1, 1);
|
|
||||||
|
|
||||||
// Second bevel
|
|
||||||
SetHighColor(lightenmax);
|
|
||||||
FillRect(rect);
|
|
||||||
|
|
||||||
SetHighColor(no_tint);
|
|
||||||
StrokeLine(BPoint(rect.right, rect.top + 1.0f),
|
|
||||||
BPoint(rect.right, rect.bottom));
|
|
||||||
StrokeLine(BPoint(rect.left + 1.0f, rect.bottom));
|
|
||||||
|
|
||||||
rect.InsetBy(1, 1);
|
|
||||||
|
|
||||||
// Filling
|
|
||||||
rect.left += 1.0f;
|
|
||||||
rect.top += 1.0f;
|
|
||||||
SetHighColor(lighten1);
|
|
||||||
FillRect(rect);
|
|
||||||
|
|
||||||
// Label
|
|
||||||
float x = (bounds.right - StringWidth(Label())) / 2.0f;
|
|
||||||
float y = bounds.bottom - fh.descent - 5.0f;
|
|
||||||
|
|
||||||
SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT));
|
|
||||||
SetLowColor(lighten2);
|
SetLowColor(lighten2);
|
||||||
DrawString(Label(), BPoint(x, y));
|
}
|
||||||
|
|
||||||
|
// Draw the label
|
||||||
|
DrawString(Label(), BPoint(x, y));
|
||||||
|
|
||||||
|
if (bEnabled && IsFocus() && Window()->IsActive())
|
||||||
|
{
|
||||||
|
// Draw focus line
|
||||||
|
y += fh.descent;
|
||||||
|
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
|
||||||
|
StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
|
||||||
|
SetHighColor(255, 255, 255);
|
||||||
|
StrokeLine(BPoint(x, y + 1), BPoint(x + StringWidth(Label()), y + 1));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,63 +465,48 @@ BButton &BButton::operator=(const BButton &)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BRect BButton::DrawDefault(BRect bounds, bool enabled)
|
BRect HButton::DrawDefault(BRect bounds, bool enabled)
|
||||||
{
|
{
|
||||||
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
|
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||||
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
|
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
|
||||||
darken1 = tint_color(no_tint, B_DARKEN_1_TINT),
|
darken1 = tint_color(no_tint, B_DARKEN_1_TINT);
|
||||||
darken4 = tint_color(no_tint, B_DARKEN_4_TINT);
|
|
||||||
|
rgb_color borderColor;
|
||||||
|
if (enabled)
|
||||||
|
borderColor = tint_color(no_tint, B_DARKEN_4_TINT);
|
||||||
|
else
|
||||||
|
borderColor = darken1;
|
||||||
|
|
||||||
|
// Dark border
|
||||||
|
BeginLineArray(4);
|
||||||
|
AddLine(BPoint(bounds.left, bounds.bottom - 1.0f),
|
||||||
|
BPoint(bounds.left, bounds.top + 1.0f), borderColor);
|
||||||
|
AddLine(BPoint(bounds.left + 1.0f, bounds.top),
|
||||||
|
BPoint(bounds.right - 1.0f, bounds.top), borderColor);
|
||||||
|
AddLine(BPoint(bounds.right, bounds.top + 1.0f),
|
||||||
|
BPoint(bounds.right, bounds.bottom - 1.0f), borderColor);
|
||||||
|
AddLine(BPoint(bounds.left + 1.0f, bounds.bottom),
|
||||||
|
BPoint(bounds.right - 1.0f, bounds.bottom), borderColor);
|
||||||
|
EndLineArray();
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
// Dark border
|
|
||||||
BeginLineArray(4);
|
|
||||||
AddLine(BPoint(bounds.left, bounds.bottom - 1.0f),
|
|
||||||
BPoint(bounds.left, bounds.top + 1.0f), darken4);
|
|
||||||
AddLine(BPoint(bounds.left + 1.0f, bounds.top),
|
|
||||||
BPoint(bounds.right - 1.0f, bounds.top), darken4);
|
|
||||||
AddLine(BPoint(bounds.right, bounds.top + 1.0f),
|
|
||||||
BPoint(bounds.right, bounds.bottom - 1.0f), darken4);
|
|
||||||
AddLine(BPoint(bounds.left + 1.0f, bounds.bottom),
|
|
||||||
BPoint(bounds.right - 1.0f, bounds.bottom), darken4);
|
|
||||||
EndLineArray();
|
|
||||||
|
|
||||||
bounds.InsetBy(1.0f, 1.0f);
|
|
||||||
|
|
||||||
// Bevel
|
// Bevel
|
||||||
|
bounds.InsetBy(1.0f, 1.0f);
|
||||||
SetHighColor(darken1);
|
SetHighColor(darken1);
|
||||||
StrokeRect(bounds);
|
StrokeRect(bounds);
|
||||||
|
}
|
||||||
|
|
||||||
bounds.InsetBy(1.0f, 1.0f);
|
bounds.InsetBy(1.0f, 1.0f);
|
||||||
|
|
||||||
// Filling
|
// Filling
|
||||||
SetHighColor(lighten1);
|
SetHighColor(lighten1);
|
||||||
FillRect(bounds);
|
FillRect(bounds);
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
bounds.InsetBy(2.0f, 2.0f);
|
bounds.InsetBy(2.0f, 2.0f);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
// Dark border
|
|
||||||
BeginLineArray(4);
|
|
||||||
AddLine(BPoint(bounds.left, bounds.bottom - 1.0f),
|
|
||||||
BPoint(bounds.left, bounds.top + 1.0f), darken1);
|
|
||||||
AddLine(BPoint(bounds.left + 1.0f, bounds.top),
|
|
||||||
BPoint(bounds.right - 1.0f, bounds.top), darken1);
|
|
||||||
AddLine(BPoint(bounds.right, bounds.top + 1.0f),
|
|
||||||
BPoint(bounds.right, bounds.bottom - 1.0f), darken1);
|
|
||||||
AddLine(BPoint(bounds.left + 1.0f, bounds.bottom),
|
|
||||||
BPoint(bounds.right - 1.0f, bounds.bottom), darken1);
|
|
||||||
EndLineArray();
|
|
||||||
|
|
||||||
bounds.InsetBy(1.0f, 1.0f);
|
|
||||||
|
|
||||||
// Filling
|
|
||||||
SetHighColor(lighten1);
|
|
||||||
FillRect(bounds);
|
|
||||||
|
|
||||||
bounds.InsetBy(3.0f, 3.0f);
|
bounds.InsetBy(3.0f, 3.0f);
|
||||||
}
|
|
||||||
|
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user