2 * Copyright 2010, Stephan Aßmus <superstippi@gmx.de>.
3 * Distributed under the terms of the MIT License.
7 #include "SymbolButton.h"
9 #include <GradientLinear.h>
10 #include <LayoutUtils.h>
14 static const rgb_color kGreen
= (rgb_color
){ 116, 224, 0, 255 };
18 SymbolButton::SymbolButton(const char* name
, BShape
* symbolShape
,
19 BMessage
* message
, uint32 borders
)
21 BButton(name
, NULL
, message
),
28 SymbolButton::~SymbolButton()
35 SymbolButton::Draw(BRect updateRect
)
37 uint32 flags
= be_control_look
->Flags(this);
38 rgb_color base
= LowColor();
39 BRect
bounds(Bounds());
42 be_control_look
->DrawButtonFrame(this, bounds
, updateRect
, base
,
43 base
, flags
& ~BControlLook::B_DISABLED
, fBorders
);
44 be_control_look
->DrawButtonBackground(this, bounds
, updateRect
, base
,
47 FillRect(updateRect
, B_SOLID_LOW
);
53 if (Value() == B_CONTROL_ON
)
54 base
= tint_color(base
, (B_DARKEN_4_TINT
+ B_DARKEN_MAX_TINT
) / 2);
56 base
= tint_color(base
, B_DARKEN_4_TINT
);
58 if (Value() == B_CONTROL_ON
)
59 base
= tint_color(base
, B_DARKEN_2_TINT
);
61 base
= tint_color(base
, B_DARKEN_1_TINT
);
65 offset
.x
= (bounds
.left
+ bounds
.right
) / 2;
66 offset
.y
= (bounds
.top
+ bounds
.bottom
) / 2;
67 offset
.x
-= fSymbol
->Bounds().Width() / 2;
68 offset
.y
-= fSymbol
->Bounds().Height() / 2;
69 offset
.x
= floorf(offset
.x
- fSymbol
->Bounds().left
);
70 offset
.y
= ceilf(offset
.y
- fSymbol
->Bounds().top
);
73 BGradientLinear gradient
;
74 gradient
.AddColor(tint_color(base
, B_DARKEN_1_TINT
), 0);
75 gradient
.AddColor(base
, 255);
76 gradient
.SetStart(offset
);
77 offset
.y
+= fSymbol
->Bounds().Height();
78 gradient
.SetEnd(offset
);
79 FillShape(fSymbol
, gradient
);
84 SymbolButton::MinSize()
87 return BButton::MinSize();
89 float scale
= fBorders
!= 0 ? 2.5f
: 1.0f
;
92 size
.width
= ceilf(fSymbol
->Bounds().Width() * scale
);
93 size
.height
= ceilf(fSymbol
->Bounds().Height() * scale
);
94 return BLayoutUtils::ComposeSize(ExplicitMinSize(), size
);
99 SymbolButton::MaxSize()
101 BSize
size(MinSize());
103 size
.width
= ceilf(size
.width
* 1.5f
);
104 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size
);
109 SymbolButton::SetSymbol(BShape
* symbolShape
)
111 BSize oldSize
= MinSize();
114 fSymbol
= symbolShape
;
116 if (MinSize() != oldSize
)