diff --git a/src/apps/haiku-depot/BitmapButton.cpp b/src/apps/haiku-depot/BitmapButton.cpp index 342bf0bcf8..b5794d430f 100644 --- a/src/apps/haiku-depot/BitmapButton.cpp +++ b/src/apps/haiku-depot/BitmapButton.cpp @@ -6,16 +6,19 @@ #include "BitmapButton.h" +#include #include #include -BitmapButton::BitmapButton(const char* name) +BitmapButton::BitmapButton(const char* name, BMessage* message) : BitmapView(name), + BInvoker(message, NULL, NULL), fMouseInside(false), fMouseDown(false) { + SetScaleBitmap(false); } @@ -48,7 +51,10 @@ BitmapButton::MouseMoved(BPoint where, uint32 transit, void BitmapButton::MouseDown(BPoint where) { - _SetMouseDown(true); + if (fMouseInside) { + _SetMouseDown(true); + SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); + } } @@ -56,6 +62,8 @@ void BitmapButton::MouseUp(BPoint where) { _SetMouseDown(false); + if (fMouseInside) + Invoke(); } @@ -63,6 +71,8 @@ BSize BitmapButton::MinSize() { BSize size = BitmapView::MinSize(); + size.width += 6; + size.height += 6; return BLayoutUtils::ComposeSize(ExplicitMinSize(), size); } @@ -86,6 +96,28 @@ BitmapButton::MaxSize() // #pragma mark - +void +BitmapButton::DrawBackground(BRect& bounds, BRect updateRect) +{ + if (Message() != NULL && (fMouseInside || fMouseDown)) { + rgb_color color = LowColor(); + uint32 flags = 0; + if (fMouseDown) + flags |= BControlLook::B_ACTIVATED; + + be_control_look->DrawButtonFrame(this, bounds, updateRect, + color, color, flags); + be_control_look->DrawButtonBackground(this, bounds, updateRect, + color, flags); + } else { + BitmapView::DrawBackground(bounds, updateRect); + } +} + + +// #pragma mark - + + void BitmapButton::_SetMouseInside(bool inside) { diff --git a/src/apps/haiku-depot/BitmapButton.h b/src/apps/haiku-depot/BitmapButton.h index 8c63128967..b41b136af8 100644 --- a/src/apps/haiku-depot/BitmapButton.h +++ b/src/apps/haiku-depot/BitmapButton.h @@ -13,7 +13,8 @@ class BitmapButton : public BitmapView, public BInvoker { public: - BitmapButton(const char* name); + BitmapButton(const char* name, + BMessage* message = NULL); virtual ~BitmapButton(); virtual void AttachedToWindow(); @@ -27,6 +28,10 @@ public: virtual BSize PreferredSize(); virtual BSize MaxSize(); +protected: + virtual void DrawBackground(BRect& bounds, + BRect updateRect); + private: void _SetMouseInside(bool inside); void _SetMouseDown(bool down); diff --git a/src/apps/haiku-depot/BitmapView.cpp b/src/apps/haiku-depot/BitmapView.cpp index bc4a897130..b34b642098 100644 --- a/src/apps/haiku-depot/BitmapView.cpp +++ b/src/apps/haiku-depot/BitmapView.cpp @@ -15,11 +15,11 @@ BitmapView::BitmapView(const char* name) : BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE), - fBitmap(NULL) + fBitmap(NULL), + fScaleBitmap(true) { SetViewColor(B_TRANSPARENT_COLOR); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - SetDrawingMode(B_OP_OVER); } @@ -45,7 +45,7 @@ void BitmapView::Draw(BRect updateRect) { BRect bounds(Bounds()); - FillRect(updateRect, B_SOLID_LOW); + DrawBackground(bounds, updateRect); if (fBitmap == NULL) return; @@ -54,10 +54,14 @@ BitmapView::Draw(BRect updateRect) if (bitmapBounds.Width() <= 0.0f || bitmapBounds.Height() <= 0.0f) return; - float hScale = bounds.Width() / bitmapBounds.Width(); - float vScale = bounds.Height() / bitmapBounds.Height(); - - float scale = std::min(hScale, vScale); + float scale = 1.0f; + + if (fScaleBitmap) { + float hScale = bounds.Width() / bitmapBounds.Width(); + float vScale = bounds.Height() / bitmapBounds.Height(); + + scale = std::min(hScale, vScale); + } float width = bitmapBounds.Width() * scale; float height = bitmapBounds.Height() * scale; @@ -90,6 +94,7 @@ BitmapView::Draw(BRect updateRect) bounds.right = ceilf(bounds.left + width); bounds.bottom = ceilf(bounds.top + height); + SetDrawingMode(B_OP_OVER); DrawBitmap(fBitmap, bitmapBounds, bounds, B_FILTER_BITMAP_BILINEAR); } @@ -141,3 +146,22 @@ BitmapView::SetBitmap(const BBitmap* bitmap) Invalidate(); } + + +void +BitmapView::SetScaleBitmap(bool scaleBitmap) +{ + if (scaleBitmap == fScaleBitmap) + return; + + fScaleBitmap = scaleBitmap; + + Invalidate(); +} + + +void +BitmapView::DrawBackground(BRect& bounds, BRect updateRect) +{ + FillRect(updateRect, B_SOLID_LOW); +} diff --git a/src/apps/haiku-depot/BitmapView.h b/src/apps/haiku-depot/BitmapView.h index 1452bfb8f6..283eef98fe 100644 --- a/src/apps/haiku-depot/BitmapView.h +++ b/src/apps/haiku-depot/BitmapView.h @@ -23,9 +23,15 @@ public: virtual BSize MaxSize(); void SetBitmap(const BBitmap* bitmap); + void SetScaleBitmap(bool scaleBitmap); + +protected: + virtual void DrawBackground(BRect& bounds, + BRect updateRect); private: const BBitmap* fBitmap; + bool fScaleBitmap; };