2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
7 #include "BitmapButton.h"
9 #include <ControlLook.h>
10 #include <LayoutUtils.h>
14 BitmapButton::BitmapButton(const char* name
, BMessage
* message
)
17 BInvoker(message
, NULL
, NULL
),
21 SetScaleBitmap(false);
25 BitmapButton::~BitmapButton()
31 BitmapButton::AttachedToWindow()
33 // TODO: Init fMouseInside
34 BitmapView::AttachedToWindow();
38 BitmapButton::MouseMoved(BPoint where
, uint32 transit
,
39 const BMessage
* dragMessage
)
42 if (Window() != NULL
&& Window()->CurrentMessage() != NULL
)
43 Window()->CurrentMessage()->FindInt32("buttons", &buttons
);
45 bool ignoreEvent
= dragMessage
!= NULL
|| (!fMouseDown
&& buttons
!= 0);
47 _SetMouseInside(!ignoreEvent
&& transit
== B_INSIDE_VIEW
);
52 BitmapButton::MouseDown(BPoint where
)
56 SetMouseEventMask(B_POINTER_EVENTS
, B_LOCK_WINDOW_FOCUS
);
62 BitmapButton::MouseUp(BPoint where
)
71 BitmapButton::MinSize()
73 BSize size
= BitmapView::MinSize();
76 return BLayoutUtils::ComposeSize(ExplicitMinSize(), size
);
81 BitmapButton::PreferredSize()
83 BSize size
= MinSize();
84 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size
);
89 BitmapButton::MaxSize()
91 BSize size
= MinSize();
92 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size
);
100 BitmapButton::DrawBackground(BRect
& bounds
, BRect updateRect
)
102 if (Message() != NULL
&& (fMouseInside
|| fMouseDown
)) {
103 rgb_color color
= LowColor();
106 flags
|= BControlLook::B_ACTIVATED
;
108 be_control_look
->DrawButtonFrame(this, bounds
, updateRect
,
109 color
, color
, flags
);
110 be_control_look
->DrawButtonBackground(this, bounds
, updateRect
,
113 BitmapView::DrawBackground(bounds
, updateRect
);
122 BitmapButton::_SetMouseInside(bool inside
)
124 if (fMouseInside
== inside
)
127 fMouseInside
= inside
;
129 if (Message() != NULL
)
135 BitmapButton::_SetMouseDown(bool down
)
137 if (fMouseDown
== down
)
142 if (Message() != NULL
)