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:
parent
33413e498b
commit
76f106fb04
@ -86,7 +86,7 @@ status_t BButton::Archive(BMessage* archive, bool deep) const
|
||||
return err;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void BButton::Draw(BRect updateRect)
|
||||
void HButton::Draw(BRect updateRect)
|
||||
{
|
||||
font_height fh;
|
||||
GetFontHeight(&fh);
|
||||
@ -120,21 +120,21 @@ void BButton::Draw(BRect updateRect)
|
||||
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
|
||||
lighten2 = tint_color(no_tint, B_LIGHTEN_2_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);
|
||||
|
||||
BRect rect(bounds);
|
||||
bool bEnabled = IsEnabled();
|
||||
|
||||
if (IsDefault())
|
||||
rect = DrawDefault(rect, IsEnabled());
|
||||
rect = DrawDefault(rect, bEnabled);
|
||||
else
|
||||
rect.InsetBy(1,1);
|
||||
|
||||
if (IsEnabled())
|
||||
{
|
||||
// This can be set outside draw
|
||||
SetHighColor(darken4);
|
||||
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);
|
||||
@ -142,18 +142,26 @@ void BButton::Draw(BRect updateRect)
|
||||
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);
|
||||
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), darken2);
|
||||
BPoint(rect.right, rect.bottom), firstBevelColor);
|
||||
AddLine(BPoint(rect.right, rect.bottom - 1.0f),
|
||||
BPoint(rect.right, rect.top + 1.0f), darken2);
|
||||
BPoint(rect.right, rect.top + 1.0f), firstBevelColor);
|
||||
|
||||
AddLine(BPoint(rect.left, rect.top),
|
||||
BPoint(rect.left, rect.bottom), lighten1);
|
||||
@ -181,7 +189,7 @@ void BButton::Draw(BRect updateRect)
|
||||
SetHighColor(lighten1);
|
||||
FillRect(rect);
|
||||
|
||||
if (Value())
|
||||
if (bEnabled && Value())
|
||||
{
|
||||
// Invert
|
||||
rect.left -= 3;
|
||||
@ -195,21 +203,24 @@ void BButton::Draw(BRect updateRect)
|
||||
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())
|
||||
if (bEnabled && Value())
|
||||
{
|
||||
SetHighColor(lightenmax);
|
||||
SetLowColor(darkenmax);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bEnabled)
|
||||
SetHighColor(darkenmax);
|
||||
else
|
||||
SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT));
|
||||
SetLowColor(lighten2);
|
||||
}
|
||||
|
||||
// Draw the label
|
||||
DrawString(Label(), BPoint(x, y));
|
||||
|
||||
if (IsFocus() && Window()->IsActive())
|
||||
if (bEnabled && IsFocus() && Window()->IsActive())
|
||||
{
|
||||
// Draw focus line
|
||||
y += fh.descent;
|
||||
@ -219,65 +230,6 @@ void BButton::Draw(BRect updateRect)
|
||||
StrokeLine(BPoint(x, y + 1), BPoint(x + StringWidth(Label()), y + 1));
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// This can be set outside draw
|
||||
SetHighColor(darken2);
|
||||
|
||||
// Dark border
|
||||
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);
|
||||
DrawString(Label(), BPoint(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -513,32 +465,37 @@ BButton &BButton::operator=(const BButton &)
|
||||
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),
|
||||
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
|
||||
darken1 = tint_color(no_tint, B_DARKEN_1_TINT),
|
||||
darken4 = tint_color(no_tint, B_DARKEN_4_TINT);
|
||||
darken1 = tint_color(no_tint, B_DARKEN_1_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)
|
||||
{
|
||||
// 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
|
||||
bounds.InsetBy(1.0f, 1.0f);
|
||||
SetHighColor(darken1);
|
||||
StrokeRect(bounds);
|
||||
}
|
||||
|
||||
bounds.InsetBy(1.0f, 1.0f);
|
||||
|
||||
@ -546,30 +503,10 @@ BRect BButton::DrawDefault(BRect bounds, bool enabled)
|
||||
SetHighColor(lighten1);
|
||||
FillRect(bounds);
|
||||
|
||||
if (enabled)
|
||||
bounds.InsetBy(2.0f, 2.0f);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user