diff --git a/src/apps/webpositive/URLInputGroup.cpp b/src/apps/webpositive/URLInputGroup.cpp index d5f4888234..7fec10caaf 100644 --- a/src/apps/webpositive/URLInputGroup.cpp +++ b/src/apps/webpositive/URLInputGroup.cpp @@ -16,13 +16,13 @@ #include #include #include -#include #include #include #include #include "BaseURL.h" +#include "BitmapButton.h" #include "BrowsingHistory.h" #include "IconButton.h" #include "TextViewCompleter.h" @@ -382,9 +382,6 @@ URLInputGroup::URLTextView::_AlignTextRect() } -// #pragma mark - GoButton - - const uint32 kGoBitmapWidth = 14; const uint32 kGoBitmapHeight = 14; const color_space kGoBitmapFormat = B_RGBA32; @@ -442,87 +439,7 @@ const unsigned char kGoBitmapBits[] = { }; -class BitmapButton : public BButton { - static const float kFrameInset = 2; - -public: - BitmapButton(const char* resourceName, BMessage* message) - : - BButton("", message), - fBitmap(BTranslationUtils::GetBitmap(resourceName)) - { - } - - BitmapButton(const uint8* bits, uint32 width, uint32 height, - color_space format, BMessage* message) - : - BButton("", message), - fBitmap(new BBitmap(BRect(0, 0, width - 1, height - 1), 0, format)) - { - memcpy(fBitmap->Bits(), bits, fBitmap->BitsLength()); - } - - ~BitmapButton() - { - delete fBitmap; - } - - virtual BSize MinSize() - { - BSize min(0, 0); - if (fBitmap) { - min.width = fBitmap->Bounds().Width(); - min.height = fBitmap->Bounds().Height(); - } - min.width += kFrameInset * 2; - min.height += kFrameInset * 2; - return min; - } - - virtual BSize MaxSize() - { - return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); - } - - virtual BSize PreferredSize() - { - return MinSize(); - } - - virtual void Draw(BRect updateRect) - { - BRect bounds(Bounds()); - rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); - uint32 flags = be_control_look->Flags(this); - - be_control_look->DrawButtonBackground(this, bounds, updateRect, base, - flags); - - SetDrawingMode(B_OP_ALPHA); - - if (!IsEnabled()) { - SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); - SetHighColor(0, 0, 0, 120); - } - - if (fBitmap == NULL) - return; - BRect bitmapBounds(fBitmap->Bounds()); - BPoint bitmapLocation( - floorf((bounds.left + bounds.right - - (bitmapBounds.left + bitmapBounds.right)) / 2 + 0.5f), - floorf((bounds.top + bounds.bottom - - (bitmapBounds.top + bitmapBounds.bottom)) / 2 + 0.5f)); - - DrawBitmap(fBitmap, bitmapLocation); - } - -private: - BBitmap* fBitmap; -}; - - -// #pragma mark - IconView +// #pragma mark - PageIconView class URLInputGroup::PageIconView : public BView { diff --git a/src/apps/webpositive/support/BitmapButton.cpp b/src/apps/webpositive/support/BitmapButton.cpp new file mode 100644 index 0000000000..1b4a22cee0 --- /dev/null +++ b/src/apps/webpositive/support/BitmapButton.cpp @@ -0,0 +1,116 @@ +/* + * Copyright 2010 Stephan Aßmus . All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include "BitmapButton.h" + +#include + +#include +#include +#include + + +static const float kFrameInset = 2; + + +BitmapButton::BitmapButton(const char* resourceName, BMessage* message) + : + BButton("", message), + fBitmap(BTranslationUtils::GetBitmap(resourceName)), + fBackgroundMode(BUTTON_BACKGROUND) +{ +} + + +BitmapButton::BitmapButton(const uint8* bits, uint32 width, uint32 height, + color_space format, BMessage* message) + : + BButton("", message), + fBitmap(new BBitmap(BRect(0, 0, width - 1, height - 1), 0, format)), + fBackgroundMode(BUTTON_BACKGROUND) +{ + memcpy(fBitmap->Bits(), bits, fBitmap->BitsLength()); +} + + +BitmapButton::~BitmapButton() +{ + delete fBitmap; +} + + +BSize +BitmapButton::MinSize() +{ + BSize min(0, 0); + if (fBitmap) { + min.width = fBitmap->Bounds().Width(); + min.height = fBitmap->Bounds().Height(); + } + min.width += kFrameInset * 2; + min.height += kFrameInset * 2; + return min; +} + + +BSize +BitmapButton::MaxSize() +{ + return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); +} + + +BSize +BitmapButton::PreferredSize() +{ + return MinSize(); +} + + +void +BitmapButton::Draw(BRect updateRect) +{ + BRect bounds(Bounds()); + rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); + uint32 flags = be_control_look->Flags(this); + + if (fBackgroundMode == BUTTON_BACKGROUND || Value() == B_CONTROL_ON) { + be_control_look->DrawButtonBackground(this, bounds, updateRect, base, + flags); + } else { + be_control_look->DrawMenuBarBackground(this, bounds, updateRect, base, + flags); + } + + if (fBitmap == NULL) + return; + + SetDrawingMode(B_OP_ALPHA); + + if (!IsEnabled()) { + SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); + SetHighColor(0, 0, 0, 120); + } + + BRect bitmapBounds(fBitmap->Bounds()); + BPoint bitmapLocation( + floorf((bounds.left + bounds.right + - (bitmapBounds.left + bitmapBounds.right)) / 2 + 0.5f), + floorf((bounds.top + bounds.bottom + - (bitmapBounds.top + bitmapBounds.bottom)) / 2 + 0.5f)); + + DrawBitmap(fBitmap, bitmapLocation); +} + + +void +BitmapButton::SetBackgroundMode(uint32 mode) +{ + if (fBackgroundMode != mode) { + fBackgroundMode = mode; + Invalidate(); + } +} + diff --git a/src/apps/webpositive/support/BitmapButton.h b/src/apps/webpositive/support/BitmapButton.h new file mode 100644 index 0000000000..432adcb34e --- /dev/null +++ b/src/apps/webpositive/support/BitmapButton.h @@ -0,0 +1,44 @@ +/* + * Copyright 2010 Stephan Aßmus . All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef BITMAP_BUTTON_H +#define BITMAP_BUTTON_H + +#include + + +class BBitmap; + + +class BitmapButton : public BButton { +public: + enum { + BUTTON_BACKGROUND = 0, + MENUBAR_BACKGROUND, + }; + + BitmapButton(const char* resourceName, + BMessage* message); + + BitmapButton(const uint8* bits, uint32 width, + uint32 height, color_space format, + BMessage* message); + + virtual ~BitmapButton(); + + virtual BSize MinSize(); + virtual BSize MaxSize(); + virtual BSize PreferredSize(); + + virtual void Draw(BRect updateRect); + + void SetBackgroundMode(uint32 mode); + +private: + BBitmap* fBitmap; + uint32 fBackgroundMode; +}; + + +#endif // BITMAP_BUTTON_H