2 * Copyright 2010 Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 #include "BitmapButton.h"
11 #include <ControlLook.h>
12 #include <TranslationUtils.h>
15 static const float kFrameInset
= 2;
18 BitmapButton::BitmapButton(const char* resourceName
, BMessage
* message
)
21 fBitmap(BTranslationUtils::GetBitmap(resourceName
)),
22 fBackgroundMode(BUTTON_BACKGROUND
)
27 BitmapButton::BitmapButton(const uint8
* bits
, uint32 width
, uint32 height
,
28 color_space format
, BMessage
* message
)
31 fBitmap(new BBitmap(BRect(0, 0, width
- 1, height
- 1), 0, format
)),
32 fBackgroundMode(BUTTON_BACKGROUND
)
34 memcpy(fBitmap
->Bits(), bits
, fBitmap
->BitsLength());
38 BitmapButton::~BitmapButton()
45 BitmapButton::MinSize()
49 min
.width
= fBitmap
->Bounds().Width();
50 min
.height
= fBitmap
->Bounds().Height();
52 min
.width
+= kFrameInset
* 2;
53 min
.height
+= kFrameInset
* 2;
59 BitmapButton::MaxSize()
61 return BSize(B_SIZE_UNLIMITED
, B_SIZE_UNLIMITED
);
66 BitmapButton::PreferredSize()
73 BitmapButton::Draw(BRect updateRect
)
75 BRect
bounds(Bounds());
76 rgb_color base
= ui_color(B_PANEL_BACKGROUND_COLOR
);
77 uint32 flags
= be_control_look
->Flags(this);
79 if (fBackgroundMode
== BUTTON_BACKGROUND
|| Value() == B_CONTROL_ON
) {
80 be_control_look
->DrawButtonBackground(this, bounds
, updateRect
, base
,
83 SetHighColor(tint_color(base
, B_DARKEN_2_TINT
));
84 StrokeLine(bounds
.LeftBottom(), bounds
.RightBottom());
86 be_control_look
->DrawMenuBarBackground(this, bounds
, updateRect
, base
,
93 SetDrawingMode(B_OP_ALPHA
);
96 SetBlendingMode(B_CONSTANT_ALPHA
, B_ALPHA_OVERLAY
);
97 SetHighColor(0, 0, 0, 120);
100 BRect
bitmapBounds(fBitmap
->Bounds());
101 BPoint
bitmapLocation(
102 floorf((bounds
.left
+ bounds
.right
103 - (bitmapBounds
.left
+ bitmapBounds
.right
)) / 2 + 0.5f
),
104 floorf((bounds
.top
+ bounds
.bottom
105 - (bitmapBounds
.top
+ bitmapBounds
.bottom
)) / 2 + 0.5f
));
107 DrawBitmap(fBitmap
, bitmapLocation
);
112 BitmapButton::SetBackgroundMode(uint32 mode
)
114 if (fBackgroundMode
!= mode
) {
115 fBackgroundMode
= mode
;