Fixed default button functions and drawing
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1340 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -93,12 +93,10 @@ void BButton::Draw(BRect updateRect)
|
|||||||
darken4 = tint_color(no_tint, B_DARKEN_4_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);
|
||||||
|
|
||||||
if (!IsDefault())
|
if (IsDefault())
|
||||||
{
|
rect = DrawDefault(rect, IsEnabled());
|
||||||
SetHighColor(no_tint);
|
else
|
||||||
StrokeRect(rect);
|
|
||||||
rect.InsetBy(1,1);
|
rect.InsetBy(1,1);
|
||||||
}
|
|
||||||
|
|
||||||
if (IsEnabled())
|
if (IsEnabled())
|
||||||
{
|
{
|
||||||
@@ -341,26 +339,25 @@ void BButton::MakeDefault(bool flag)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
fDrawAsDefault = flag;
|
fDrawAsDefault = flag;
|
||||||
|
BWindow *window = Window();
|
||||||
|
|
||||||
if (Window())
|
if (window)
|
||||||
{
|
{
|
||||||
BButton *button = (BButton*)(Window()->DefaultButton());
|
BButton *button = (BButton*)(window->DefaultButton());
|
||||||
|
|
||||||
if (fDrawAsDefault)
|
if (flag)
|
||||||
{
|
{
|
||||||
if(button)
|
ResizeBy(6.0f, 6.0f);
|
||||||
button->MakeDefault(false);
|
MoveBy(-3.0f, -3.0f);
|
||||||
|
window->SetDefaultButton((BButton*)this);
|
||||||
Window()->SetDefaultButton((BButton*)this);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (button == this)
|
ResizeBy(-6.0f, -6.0f);
|
||||||
Window()->SetDefaultButton(NULL);
|
MoveBy(3.0f, 3.0f);
|
||||||
|
window->SetDefaultButton(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::SetLabel(const char *string)
|
void BButton::SetLabel(const char *string)
|
||||||
@@ -438,9 +435,7 @@ void BButton::GetPreferredSize (float *width, float *height)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::ResizeToPreferred()
|
void BButton::ResizeToPreferred()
|
||||||
{
|
{
|
||||||
float width, height;
|
BControl::ResizeToPreferred();
|
||||||
GetPreferredSize(&width, &height);
|
|
||||||
ResizeTo(width,height);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BButton::Invoke(BMessage *message)
|
status_t BButton::Invoke(BMessage *message)
|
||||||
@@ -502,8 +497,63 @@ BButton &BButton::operator=(const BButton &)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BRect BButton::DrawDefault(BRect bounds, bool enabled)
|
BRect BButton::DrawDefault(BRect bounds, bool enabled)
|
||||||
{
|
{
|
||||||
// TODO:
|
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
|
||||||
return BRect();
|
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);
|
||||||
|
|
||||||
|
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
|
||||||
|
SetHighColor(darken1);
|
||||||
|
StrokeRect(bounds);
|
||||||
|
|
||||||
|
bounds.InsetBy(1.0f, 1.0f);
|
||||||
|
|
||||||
|
// Filling
|
||||||
|
SetHighColor(lighten1);
|
||||||
|
FillRect(bounds);
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t Execute()
|
status_t Execute()
|
||||||
|
|||||||
Reference in New Issue
Block a user