Small clean-up.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35678 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström
2010-02-28 21:50:34 +00:00
parent ddf1c15bec
commit fb9a9911a8
3 changed files with 75 additions and 82 deletions
+16 -30
View File
@@ -35,37 +35,19 @@ All rights reserved.
#include "BmapButton.h"
#include <BeBuild.h>
#include <Bitmap.h>
#include <Autolock.h>
#include <Application.h>
#include <Autolock.h>
#include <Bitmap.h>
#include <ColorTools.h>
#include <Resources.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;
BLocker BmapButton::fBmCacheLock;
struct BitmapItem {
BBitmap* bm;
int32 id;
@@ -154,16 +136,18 @@ BmapButton::RetrieveBitmap(int32 id)
status_t
BmapButton::ReleaseBitmap(const BBitmap* bm)
{
// Lock access to the list
BAutolock lock(fBmCacheLock);
if (!lock.IsLocked())
return B_ERROR;
// Find the bitmap
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 it's no longer in use by any objects, free the resources
if (--item->openCount <= 0) {
fBitmapCache.RemoveItem(i);
delete item->bm;
@@ -257,8 +241,10 @@ BmapButton::Draw(BRect updateRect)
if (bm) {
fBitmapRect = bm->Bounds();
fBitmapRect.OffsetTo(0, 0);
fBitmapRect.OffsetBy((bounds.right-bounds.left-fBitmapRect.right-fBitmapRect.left)/2,
(bounds.bottom-bounds.top-labelHeight-fBitmapRect.bottom-fBitmapRect.top)/2);
fBitmapRect.OffsetBy((bounds.right - bounds.left - fBitmapRect.right
- fBitmapRect.left) / 2,
(bounds.bottom - bounds.top - labelHeight - fBitmapRect.bottom
- fBitmapRect.top) / 2);
// Update if within update rect
SetDrawingMode(B_OP_OVER);
@@ -294,8 +280,8 @@ BmapButton::GetPreferredSize(float *width, float *height)
labelWidth = renderFont.StringWidth(Label());
prefBounds.left = 0;
prefBounds.top = 0;
prefBounds.right = labelWidth > (bmBounds.right-bmBounds.left) ? labelWidth :
(bmBounds.right-bmBounds.left);
prefBounds.right = labelWidth > (bmBounds.right - bmBounds.left)
? labelWidth : (bmBounds.right - bmBounds.left);
prefBounds.bottom = labelHeight + (bmBounds.bottom - bmBounds.top);
} else
prefBounds = fEnabledBM->Bounds();
+11 -5
View File
@@ -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.
All rights reserved.
*/
#ifndef _BMAP_BUTTON_H
#define _BMAP_BUTTON_H
#include <Control.h>
#include <List.h>
#include <Locker.h>
#include <View.h>
class BBitmap;
class BResources;
class BmapButton : public BControl {
public:
BmapButton(BRect frame, const char *name, const char *label,
int32 enabledID, int32 disabledID, int32 rollID, int32 pressedID,
bool showLabel, BMessage *message, uint32 resizeMask,
BmapButton(BRect frame, const char* name,
const char* label, int32 enabledID,
int32 disabledID, int32 rollID, int32 pressedID,
bool showLabel, BMessage* message,
uint32 resizeMask,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
virtual ~BmapButton(void);
// Hooks
virtual void Draw(BRect updateRect);
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 MouseUp(BPoint where);
virtual void WindowActivated(bool active);
@@ -84,5 +89,6 @@ private:
static BLocker fBmCacheLock;
};
#endif // #ifndef _BMAP_BUTTON_H
+1
View File
@@ -4,6 +4,7 @@ if $(TARGET_PLATFORM) != haiku {
UsePublicHeaders mail ;
}
UsePrivateHeaders interface ;
UsePrivateHeaders mail ;
UsePrivateHeaders textencoding ;
UsePrivateHeaders shared ;