Moved BitmapButton into it's own file.

git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@483 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi
2012-07-03 15:44:03 +02:00
committed by Alexandre Deckner
parent f157030d2e
commit 095c4241ef
3 changed files with 162 additions and 85 deletions
+2 -85
View File
@@ -16,13 +16,13 @@
#include <PopUpMenu.h>
#include <SeparatorView.h>
#include <TextView.h>
#include <TranslationUtils.h>
#include <Window.h>
#include <stdio.h>
#include <stdlib.h>
#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 {
@@ -0,0 +1,116 @@
/*
* Copyright 2010 Stephan Aßmus <[email protected]>. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "BitmapButton.h"
#include <string.h>
#include <Bitmap.h>
#include <ControlLook.h>
#include <TranslationUtils.h>
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();
}
}
@@ -0,0 +1,44 @@
/*
* Copyright 2010 Stephan Aßmus <[email protected]>. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef BITMAP_BUTTON_H
#define BITMAP_BUTTON_H
#include <Button.h>
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