Small clean-up.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35678 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -35,37 +35,19 @@ 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;
|
||||||
@@ -154,16 +136,18 @@ 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; (item=(BitmapItem *)fBitmapCache.ItemAt(i)) != NULL; i++) {
|
for (int32 i = 0;; 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;
|
||||||
@@ -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);
|
||||||
@@ -294,8 +280,8 @@ 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();
|
||||||
|
|||||||
@@ -31,30 +31,35 @@ 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,
|
||||||
|
bool showLabel, BMessage* message,
|
||||||
|
uint32 resizeMask,
|
||||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||||
virtual ~BmapButton(void);
|
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,
|
||||||
|
const BMessage* msg);
|
||||||
virtual void MouseDown(BPoint point);
|
virtual void MouseDown(BPoint point);
|
||||||
virtual void MouseUp(BPoint where);
|
virtual void MouseUp(BPoint where);
|
||||||
virtual void WindowActivated(bool active);
|
virtual void WindowActivated(bool active);
|
||||||
@@ -84,5 +89,6 @@ private:
|
|||||||
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 ;
|
||||||
|
|||||||
Reference in New Issue
Block a user