repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / mediaplayer / interface / SymbolButton.cpp
blobce9b5c127edd34a7d784aac4ad998843f151c0cc
1 /*
2 * Copyright 2010, Stephan Aßmus <superstippi@gmx.de>.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "SymbolButton.h"
9 #include <GradientLinear.h>
10 #include <LayoutUtils.h>
11 #include <Shape.h>
14 static const rgb_color kGreen = (rgb_color){ 116, 224, 0, 255 };
17 // constructor
18 SymbolButton::SymbolButton(const char* name, BShape* symbolShape,
19 BMessage* message, uint32 borders)
21 BButton(name, NULL, message),
22 fSymbol(symbolShape),
23 fBorders(borders)
28 SymbolButton::~SymbolButton()
30 delete fSymbol;
34 void
35 SymbolButton::Draw(BRect updateRect)
37 uint32 flags = be_control_look->Flags(this);
38 rgb_color base = LowColor();
39 BRect bounds(Bounds());
41 if (fBorders != 0) {
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,
45 flags);
46 } else
47 FillRect(updateRect, B_SOLID_LOW);
49 if (fSymbol == NULL)
50 return;
52 if (IsEnabled()) {
53 if (Value() == B_CONTROL_ON)
54 base = tint_color(base, (B_DARKEN_4_TINT + B_DARKEN_MAX_TINT) / 2);
55 else
56 base = tint_color(base, B_DARKEN_4_TINT);
57 } else {
58 if (Value() == B_CONTROL_ON)
59 base = tint_color(base, B_DARKEN_2_TINT);
60 else
61 base = tint_color(base, B_DARKEN_1_TINT);
64 BPoint offset;
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);
72 MovePenTo(offset);
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);
83 BSize
84 SymbolButton::MinSize()
86 if (fSymbol == NULL)
87 return BButton::MinSize();
89 float scale = fBorders != 0 ? 2.5f : 1.0f;
91 BSize size;
92 size.width = ceilf(fSymbol->Bounds().Width() * scale);
93 size.height = ceilf(fSymbol->Bounds().Height() * scale);
94 return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
98 BSize
99 SymbolButton::MaxSize()
101 BSize size(MinSize());
102 if (fBorders != 0)
103 size.width = ceilf(size.width * 1.5f);
104 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
108 void
109 SymbolButton::SetSymbol(BShape* symbolShape)
111 BSize oldSize = MinSize();
113 delete fSymbol;
114 fSymbol = symbolShape;
116 if (MinSize() != oldSize)
117 InvalidateLayout();
119 Invalidate();