Small clean-up.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35678 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ddf1c15bec
commit
fb9a9911a8
@ -35,53 +35,35 @@ All rights reserved.
|
|||||||
|
|
||||||
#include "BmapButton.h"
|
#include "BmapButton.h"
|
||||||
|
|
||||||
#include <BeBuild.h>
|
|
||||||
#include <Bitmap.h>
|
|
||||||
#include <Autolock.h>
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
#include <Autolock.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
#include <ColorTools.h>
|
||||||
#include <Resources.h>
|
#include <Resources.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
#if !defined(HAIKU_TARGET_PLATFORM_DANO)
|
|
||||||
static rgb_color
|
|
||||||
mix_color(rgb_color color1, rgb_color color2, float portion)
|
|
||||||
{
|
|
||||||
rgb_color ret;
|
|
||||||
ret.red = uint8(color1.red*portion + color2.red*(1-portion) + .5);
|
|
||||||
ret.green = uint8(color1.green*portion + color2.green*(1-portion) + .5);
|
|
||||||
ret.blue = uint8(color1.blue*portion + color2.blue*(1-portion) + .5);
|
|
||||||
ret.alpha = uint8(color1.alpha*portion + color2.alpha*(1-portion) + .5);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline rgb_color
|
|
||||||
disable_color(rgb_color color, rgb_color background)
|
|
||||||
{
|
|
||||||
return mix_color(color, background, .5);
|
|
||||||
}
|
|
||||||
#endif // #if older versions of BeOS, like R5.
|
|
||||||
|
|
||||||
BList BmapButton::fBitmapCache;
|
BList BmapButton::fBitmapCache;
|
||||||
BLocker BmapButton::fBmCacheLock;
|
BLocker BmapButton::fBmCacheLock;
|
||||||
|
|
||||||
|
|
||||||
struct BitmapItem {
|
struct BitmapItem {
|
||||||
BBitmap *bm;
|
BBitmap* bm;
|
||||||
int32 id;
|
int32 id;
|
||||||
int32 openCount;
|
int32 openCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
BmapButton::BmapButton(BRect frame,
|
BmapButton::BmapButton(BRect frame,
|
||||||
const char *name,
|
const char* name,
|
||||||
const char *label,
|
const char* label,
|
||||||
int32 enabledID,
|
int32 enabledID,
|
||||||
int32 disabledID,
|
int32 disabledID,
|
||||||
int32 rollID,
|
int32 rollID,
|
||||||
int32 pressedID,
|
int32 pressedID,
|
||||||
bool showLabel,
|
bool showLabel,
|
||||||
BMessage *message,
|
BMessage* message,
|
||||||
uint32 resizeMask,
|
uint32 resizeMask,
|
||||||
uint32 flags) :
|
uint32 flags) :
|
||||||
BControl(frame, name, label, message, resizeMask, flags),
|
BControl(frame, name, label, message, resizeMask, flags),
|
||||||
@ -107,7 +89,7 @@ BmapButton::~BmapButton(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const BBitmap *
|
const BBitmap*
|
||||||
BmapButton::RetrieveBitmap(int32 id)
|
BmapButton::RetrieveBitmap(int32 id)
|
||||||
{
|
{
|
||||||
// Lock access to the list
|
// Lock access to the list
|
||||||
@ -116,8 +98,8 @@ BmapButton::RetrieveBitmap(int32 id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// Check for the bitmap in the cache first
|
// Check for the bitmap in the cache first
|
||||||
BitmapItem *item;
|
BitmapItem* item;
|
||||||
for (int32 i=0; (item=(BitmapItem *)fBitmapCache.ItemAt(i)) != NULL; i++) {
|
for (int32 i=0; (item=(BitmapItem*)fBitmapCache.ItemAt(i)) != NULL; i++) {
|
||||||
if (item->id == id) {
|
if (item->id == id) {
|
||||||
item->openCount++;
|
item->openCount++;
|
||||||
return item->bm;
|
return item->bm;
|
||||||
@ -129,7 +111,7 @@ BmapButton::RetrieveBitmap(int32 id)
|
|||||||
if (!res) return NULL;
|
if (!res) return NULL;
|
||||||
|
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
const void * data = res->LoadResource('BMAP', id, &size);
|
const void* data = res->LoadResource('BMAP', id, &size);
|
||||||
if (!data) return NULL;
|
if (!data) return NULL;
|
||||||
BMemoryIO mio(data, size);
|
BMemoryIO mio(data, size);
|
||||||
BMessage arch;
|
BMessage arch;
|
||||||
@ -142,7 +124,7 @@ BmapButton::RetrieveBitmap(int32 id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
item = (BitmapItem *)malloc(sizeof(BitmapItem));
|
item = (BitmapItem*)malloc(sizeof(BitmapItem));
|
||||||
item->bm = bm;
|
item->bm = bm;
|
||||||
item->id = id;
|
item->id = id;
|
||||||
item->openCount = 1;
|
item->openCount = 1;
|
||||||
@ -152,18 +134,20 @@ BmapButton::RetrieveBitmap(int32 id)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BmapButton::ReleaseBitmap(const BBitmap *bm)
|
BmapButton::ReleaseBitmap(const BBitmap* bm)
|
||||||
{
|
{
|
||||||
// Lock access to the list
|
|
||||||
BAutolock lock(fBmCacheLock);
|
BAutolock lock(fBmCacheLock);
|
||||||
if (!lock.IsLocked())
|
if (!lock.IsLocked())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
// Find the bitmap
|
BitmapItem* item;
|
||||||
BitmapItem *item;
|
for (int32 i = 0;; i++)
|
||||||
for (int32 i=0; (item=(BitmapItem *)fBitmapCache.ItemAt(i)) != NULL; i++) {
|
{
|
||||||
|
item = static_cast<BitmapItem*>(fBitmapCache.ItemAt(i));
|
||||||
|
if (item == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
if (item->bm == bm) {
|
if (item->bm == bm) {
|
||||||
// If it's no longer in use by any objects, free the resources
|
|
||||||
if (--item->openCount <= 0) {
|
if (--item->openCount <= 0) {
|
||||||
fBitmapCache.RemoveItem(i);
|
fBitmapCache.RemoveItem(i);
|
||||||
delete item->bm;
|
delete item->bm;
|
||||||
@ -200,14 +184,14 @@ BmapButton::Draw(BRect updateRect)
|
|||||||
labelWidth = renderFont.StringWidth(Label());
|
labelWidth = renderFont.StringWidth(Label());
|
||||||
|
|
||||||
BRect textRect;
|
BRect textRect;
|
||||||
textRect.left = (bounds.right-bounds.left-labelWidth+1)/2;
|
textRect.left = (bounds.right - bounds.left - labelWidth + 1) / 2;
|
||||||
textRect.right = textRect.left+labelWidth;
|
textRect.right = textRect.left + labelWidth;
|
||||||
textRect.bottom = bounds.bottom;
|
textRect.bottom = bounds.bottom;
|
||||||
textRect.top = textRect.bottom-fheight.descent-fheight.ascent-1;
|
textRect.top = textRect.bottom - fheight.descent - fheight.ascent - 1;
|
||||||
|
|
||||||
// Only draw if it's within the update rect
|
// Only draw if it's within the update rect
|
||||||
if (updateRect.Intersects(textRect)) {
|
if (updateRect.Intersects(textRect)) {
|
||||||
float baseLine = textRect.bottom-fheight.descent;
|
float baseLine = textRect.bottom - fheight.descent;
|
||||||
|
|
||||||
if (IsFocus() && fActive)
|
if (IsFocus() && fActive)
|
||||||
SetHighColor(0, 0, 255);
|
SetHighColor(0, 0, 255);
|
||||||
@ -219,7 +203,7 @@ BmapButton::Draw(BRect updateRect)
|
|||||||
if (IsEnabled())
|
if (IsEnabled())
|
||||||
SetHighColor(0, 0, 0);
|
SetHighColor(0, 0, 0);
|
||||||
else {
|
else {
|
||||||
const rgb_color black = { 0, 0, 0, 255 };
|
const rgb_color black = {0, 0, 0, 255};
|
||||||
SetHighColor(disable_color(black, ViewColor()));
|
SetHighColor(disable_color(black, ViewColor()));
|
||||||
}
|
}
|
||||||
MovePenTo(textRect.left, baseLine);
|
MovePenTo(textRect.left, baseLine);
|
||||||
@ -237,7 +221,7 @@ BmapButton::Draw(BRect updateRect)
|
|||||||
// Draw Bitmap
|
// Draw Bitmap
|
||||||
|
|
||||||
// Select the bitmap to use
|
// Select the bitmap to use
|
||||||
const BBitmap *bm;
|
const BBitmap* bm;
|
||||||
|
|
||||||
if (!IsEnabled())
|
if (!IsEnabled())
|
||||||
bm = fDisabledBM;
|
bm = fDisabledBM;
|
||||||
@ -257,8 +241,10 @@ BmapButton::Draw(BRect updateRect)
|
|||||||
if (bm) {
|
if (bm) {
|
||||||
fBitmapRect = bm->Bounds();
|
fBitmapRect = bm->Bounds();
|
||||||
fBitmapRect.OffsetTo(0, 0);
|
fBitmapRect.OffsetTo(0, 0);
|
||||||
fBitmapRect.OffsetBy((bounds.right-bounds.left-fBitmapRect.right-fBitmapRect.left)/2,
|
fBitmapRect.OffsetBy((bounds.right - bounds.left - fBitmapRect.right
|
||||||
(bounds.bottom-bounds.top-labelHeight-fBitmapRect.bottom-fBitmapRect.top)/2);
|
- fBitmapRect.left) / 2,
|
||||||
|
(bounds.bottom - bounds.top - labelHeight - fBitmapRect.bottom
|
||||||
|
- fBitmapRect.top) / 2);
|
||||||
// Update if within update rect
|
// Update if within update rect
|
||||||
|
|
||||||
SetDrawingMode(B_OP_OVER);
|
SetDrawingMode(B_OP_OVER);
|
||||||
@ -276,7 +262,7 @@ BmapButton::Draw(BRect updateRect)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BmapButton::GetPreferredSize(float *width, float *height)
|
BmapButton::GetPreferredSize(float* width, float* height)
|
||||||
{
|
{
|
||||||
BRect prefBounds;
|
BRect prefBounds;
|
||||||
|
|
||||||
@ -294,9 +280,9 @@ BmapButton::GetPreferredSize(float *width, float *height)
|
|||||||
labelWidth = renderFont.StringWidth(Label());
|
labelWidth = renderFont.StringWidth(Label());
|
||||||
prefBounds.left = 0;
|
prefBounds.left = 0;
|
||||||
prefBounds.top = 0;
|
prefBounds.top = 0;
|
||||||
prefBounds.right = labelWidth > (bmBounds.right-bmBounds.left) ? labelWidth :
|
prefBounds.right = labelWidth > (bmBounds.right - bmBounds.left)
|
||||||
(bmBounds.right-bmBounds.left);
|
? labelWidth : (bmBounds.right - bmBounds.left);
|
||||||
prefBounds.bottom = labelHeight + (bmBounds.bottom-bmBounds.top);
|
prefBounds.bottom = labelHeight + (bmBounds.bottom - bmBounds.top);
|
||||||
} else
|
} else
|
||||||
prefBounds = fEnabledBM->Bounds();
|
prefBounds = fEnabledBM->Bounds();
|
||||||
} else
|
} else
|
||||||
@ -308,7 +294,7 @@ BmapButton::GetPreferredSize(float *width, float *height)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BmapButton::MouseMoved(BPoint where, uint32 code, const BMessage *msg)
|
BmapButton::MouseMoved(BPoint where, uint32 code, const BMessage* msg)
|
||||||
{
|
{
|
||||||
// eliminate unused parameter warnings
|
// eliminate unused parameter warnings
|
||||||
(void)where;
|
(void)where;
|
||||||
|
@ -31,58 +31,64 @@ of Be Incorporated in the United States and other countries. Other brand product
|
|||||||
names are registered trademarks or trademarks of their respective holders.
|
names are registered trademarks or trademarks of their respective holders.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _BMAP_BUTTON_H
|
#ifndef _BMAP_BUTTON_H
|
||||||
#define _BMAP_BUTTON_H
|
#define _BMAP_BUTTON_H
|
||||||
|
|
||||||
|
|
||||||
#include <Control.h>
|
#include <Control.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
class BBitmap;
|
class BBitmap;
|
||||||
class BResources;
|
class BResources;
|
||||||
|
|
||||||
|
|
||||||
class BmapButton : public BControl {
|
class BmapButton : public BControl {
|
||||||
public:
|
public:
|
||||||
BmapButton(BRect frame, const char *name, const char *label,
|
BmapButton(BRect frame, const char* name,
|
||||||
int32 enabledID, int32 disabledID, int32 rollID, int32 pressedID,
|
const char* label, int32 enabledID,
|
||||||
bool showLabel, BMessage *message, uint32 resizeMask,
|
int32 disabledID, int32 rollID, int32 pressedID,
|
||||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
bool showLabel, BMessage* message,
|
||||||
virtual ~BmapButton(void);
|
uint32 resizeMask,
|
||||||
|
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||||
|
virtual ~BmapButton(void);
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
virtual void GetPreferredSize(float *width, float *height);
|
virtual void GetPreferredSize(float* width, float* height);
|
||||||
virtual void MouseMoved(BPoint where, uint32 code, const BMessage *msg);
|
virtual void MouseMoved(BPoint where, uint32 code,
|
||||||
virtual void MouseDown(BPoint point);
|
const BMessage* msg);
|
||||||
virtual void MouseUp(BPoint where);
|
virtual void MouseDown(BPoint point);
|
||||||
virtual void WindowActivated(bool active);
|
virtual void MouseUp(BPoint where);
|
||||||
|
virtual void WindowActivated(bool active);
|
||||||
|
|
||||||
void InvokeOnButton(uint32 button);
|
void InvokeOnButton(uint32 button);
|
||||||
void ShowLabel(bool show);
|
void ShowLabel(bool show);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const BBitmap *RetrieveBitmap(int32 id);
|
const BBitmap* RetrieveBitmap(int32 id);
|
||||||
status_t ReleaseBitmap(const BBitmap *bm);
|
status_t ReleaseBitmap(const BBitmap* bm);
|
||||||
|
|
||||||
const BBitmap *fEnabledBM;
|
const BBitmap* fEnabledBM;
|
||||||
const BBitmap *fDisabledBM;
|
const BBitmap* fDisabledBM;
|
||||||
const BBitmap *fRollBM;
|
const BBitmap* fRollBM;
|
||||||
const BBitmap *fPressedBM;
|
const BBitmap* fPressedBM;
|
||||||
int32 fPressing;
|
int32 fPressing;
|
||||||
int32 fIsInBounds;
|
int32 fIsInBounds;
|
||||||
uint32 fButtons;
|
uint32 fButtons;
|
||||||
bool fShowLabel;
|
bool fShowLabel;
|
||||||
bool fActive;
|
bool fActive;
|
||||||
BRect fBitmapRect;
|
BRect fBitmapRect;
|
||||||
BPoint fWhere;
|
BPoint fWhere;
|
||||||
uint32 fIButtons;
|
uint32 fIButtons;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static BList fBitmapCache;
|
static BList fBitmapCache;
|
||||||
static BLocker fBmCacheLock;
|
static BLocker fBmCacheLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef _BMAP_BUTTON_H
|
#endif // #ifndef _BMAP_BUTTON_H
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ if $(TARGET_PLATFORM) != haiku {
|
|||||||
UsePublicHeaders mail ;
|
UsePublicHeaders mail ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UsePrivateHeaders interface ;
|
||||||
UsePrivateHeaders mail ;
|
UsePrivateHeaders mail ;
|
||||||
UsePrivateHeaders textencoding ;
|
UsePrivateHeaders textencoding ;
|
||||||
UsePrivateHeaders shared ;
|
UsePrivateHeaders shared ;
|
||||||
|
Loading…
Reference in New Issue
Block a user