Small fixes/changes:
- added destructor that deletes the mouse bitmaps - the invalidated region in Pulse() is now large enough - it's now completely independent from the image in MouseBitmap.h - just put the correct images into the resources, and update the bitmap creation and it'll work - it's now always working correctly (even visually) if one or both bitmaps are missing. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5975 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -39,7 +39,6 @@ static const int32 kOneButtonOffsets[4] = {0, 55};
|
|||||||
static const int32 kTwoButtonOffsets[4] = {0, 27, 55};
|
static const int32 kTwoButtonOffsets[4] = {0, 27, 55};
|
||||||
static const int32 kThreeButtonOffsets[4] = {0, 18, 36, 55};
|
static const int32 kThreeButtonOffsets[4] = {0, 18, 36, 55};
|
||||||
|
|
||||||
static const int32 kButtonHeight = 26;
|
|
||||||
static const int32 kButtonTop = 6;
|
static const int32 kButtonTop = 6;
|
||||||
|
|
||||||
static const rgb_color kButtonPressedColor = {120, 120, 120};
|
static const rgb_color kButtonPressedColor = {120, 120, 120};
|
||||||
@@ -95,6 +94,22 @@ MouseView::MouseView(BRect rect, const MouseSettings &settings)
|
|||||||
|
|
||||||
fMouseDownBitmap = new BBitmap(BRect(0, 0, kMouseDownWidth - 1, kMouseDownHeight - 1), B_CMAP8);
|
fMouseDownBitmap = new BBitmap(BRect(0, 0, kMouseDownWidth - 1, kMouseDownHeight - 1), B_CMAP8);
|
||||||
fMouseDownBitmap->SetBits(kMouseDownBits, sizeof(kMouseDownBits), 0, kMouseDownColorSpace);
|
fMouseDownBitmap->SetBits(kMouseDownBits, sizeof(kMouseDownBits), 0, kMouseDownColorSpace);
|
||||||
|
|
||||||
|
// ToDo: move these images to the resources as well
|
||||||
|
//fMouseBitmap = BTranslationUtils::GetBitmap('PNG ', "mouse_bmap");
|
||||||
|
//fMouseDownBitmap = BTranslationUtils::GetBitmap('PNG ', "pressed_mouse_bmap");
|
||||||
|
|
||||||
|
if (fMouseDownBitmap != NULL)
|
||||||
|
fMouseDownBounds = fMouseDownBitmap->Bounds();
|
||||||
|
else
|
||||||
|
fMouseDownBounds.Set(0, 0, 55, 29);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MouseView::~MouseView()
|
||||||
|
{
|
||||||
|
delete fMouseBitmap;
|
||||||
|
delete fMouseDownBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -102,9 +117,9 @@ void
|
|||||||
MouseView::GetPreferredSize(float *_width, float *_height)
|
MouseView::GetPreferredSize(float *_width, float *_height)
|
||||||
{
|
{
|
||||||
if (_width)
|
if (_width)
|
||||||
*_width = kMouseWidth;
|
*_width = fMouseBitmap != NULL ? fMouseBitmap->Bounds().Width() : 57;
|
||||||
if (_height)
|
if (_height)
|
||||||
*_height = kMouseHeight;
|
*_height = fMouseBitmap != NULL ? fMouseBitmap->Bounds().Height() : 82;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +129,8 @@ MouseView::MouseDown(BPoint where)
|
|||||||
const int32 *offset = getButtonOffsets(fType);
|
const int32 *offset = getButtonOffsets(fType);
|
||||||
int32 button = -1;
|
int32 button = -1;
|
||||||
for (int32 i = 0; i <= fType; i++) {
|
for (int32 i = 0; i <= fType; i++) {
|
||||||
BRect frame(offset[i], kButtonTop, offset[i + 1] - 1, kButtonTop + kButtonHeight);
|
BRect frame(offset[i], kButtonTop, offset[i + 1] - 1,
|
||||||
|
kButtonTop + fMouseDownBounds.Height());
|
||||||
if (frame.Contains(where)) {
|
if (frame.Contains(where)) {
|
||||||
button = i;
|
button = i;
|
||||||
break;
|
break;
|
||||||
@@ -162,7 +178,8 @@ MouseView::Pulse()
|
|||||||
GetMouse(&point, &fButtons, true);
|
GetMouse(&point, &fButtons, true);
|
||||||
|
|
||||||
if (fOldButtons != fButtons) {
|
if (fOldButtons != fButtons) {
|
||||||
Invalidate(BRect(0, kButtonTop, kMouseWidth, kButtonTop + kButtonHeight));
|
Invalidate(BRect(0, kButtonTop,
|
||||||
|
fMouseDownBounds.Width(), kButtonTop + fMouseDownBounds.Height()));
|
||||||
fOldButtons = fButtons;
|
fOldButtons = fButtons;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,9 +190,9 @@ MouseView::Draw(BRect updateFrame)
|
|||||||
{
|
{
|
||||||
inherited::Draw(updateFrame);
|
inherited::Draw(updateFrame);
|
||||||
|
|
||||||
SetDrawingMode(B_OP_OVER);
|
|
||||||
|
|
||||||
// Draw the mouse top
|
// Draw the mouse top
|
||||||
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
|
if (fMouseBitmap != NULL)
|
||||||
DrawBitmapAsync(fMouseBitmap, updateFrame, updateFrame);
|
DrawBitmapAsync(fMouseBitmap, updateFrame, updateFrame);
|
||||||
|
|
||||||
mouse_map map;
|
mouse_map map;
|
||||||
@@ -185,14 +202,22 @@ MouseView::Draw(BRect updateFrame)
|
|||||||
bool middlePressed = fType == 3 && (map.button[2] & fButtons) != 0;
|
bool middlePressed = fType == 3 && (map.button[2] & fButtons) != 0;
|
||||||
|
|
||||||
for (int32 i = 0; i < fType; i++) {
|
for (int32 i = 0; i < fType; i++) {
|
||||||
BRect border(offset[i] + 1, kButtonTop + 2, offset[i + 1] - 1, kButtonTop + kButtonHeight - 2);
|
BRect border(offset[i] + 1, kButtonTop + 2, offset[i + 1] - 1,
|
||||||
|
kButtonTop + fMouseDownBounds.Height() - 4);
|
||||||
bool pressed = (fButtons & map.button[ConvertFromVisualOrder(i)]) != 0;
|
bool pressed = (fButtons & map.button[ConvertFromVisualOrder(i)]) != 0;
|
||||||
// is button currently pressed?
|
// is button currently pressed?
|
||||||
|
|
||||||
if (pressed) {
|
if (pressed) {
|
||||||
BRect frame(offset[i], 0, offset[i + 1], kMouseDownHeight + 1);
|
BRect frame(offset[i], 0, offset[i + 1], fMouseDownBounds.Height() + 1);
|
||||||
|
if (fMouseDownBitmap != NULL)
|
||||||
DrawBitmapAsync(fMouseDownBitmap, frame, frame.OffsetByCopy(0, kButtonTop));
|
DrawBitmapAsync(fMouseDownBitmap, frame, frame.OffsetByCopy(0, kButtonTop));
|
||||||
|
else if (fMouseBitmap == NULL) {
|
||||||
|
SetHighColor(kButtonPressedColor);
|
||||||
|
SetDrawingMode(B_OP_OVER);
|
||||||
|
FillRect(frame.OffsetByCopy(0, kButtonTop));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
SetDrawingMode(B_OP_OVER);
|
||||||
|
|
||||||
if (i > 0 && fType > i) {
|
if (i > 0 && fType > i) {
|
||||||
// left border
|
// left border
|
||||||
@@ -202,6 +227,8 @@ MouseView::Draw(BRect updateFrame)
|
|||||||
// draw separator
|
// draw separator
|
||||||
BRect separator = border.OffsetByCopy(-1, -1);
|
BRect separator = border.OffsetByCopy(-1, -1);
|
||||||
separator.bottom += 2;
|
separator.bottom += 2;
|
||||||
|
if (!middlePressed)
|
||||||
|
border.top++;
|
||||||
|
|
||||||
SetHighColor(middlePressed ?
|
SetHighColor(middlePressed ?
|
||||||
kButtonPressedSeparatorColor : kButtonReleasedSeparatorColor);
|
kButtonPressedSeparatorColor : kButtonReleasedSeparatorColor);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class MouseSettings;
|
|||||||
class MouseView : public BView {
|
class MouseView : public BView {
|
||||||
public:
|
public:
|
||||||
MouseView(BRect frame, const MouseSettings &settings);
|
MouseView(BRect frame, const MouseSettings &settings);
|
||||||
|
virtual ~MouseView();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
@@ -45,6 +46,7 @@ class MouseView : public BView {
|
|||||||
|
|
||||||
const MouseSettings &fSettings;
|
const MouseSettings &fSettings;
|
||||||
BBitmap *fMouseBitmap, *fMouseDownBitmap;
|
BBitmap *fMouseBitmap, *fMouseDownBitmap;
|
||||||
|
BRect fMouseDownBounds;
|
||||||
mouse_map fCurrentMouseMap;
|
mouse_map fCurrentMouseMap;
|
||||||
|
|
||||||
int32 fType;
|
int32 fType;
|
||||||
|
|||||||
Reference in New Issue
Block a user