Mouse: let the mouse scale with the font size.
* It's really confusing that SetOrigin() ignores the current scaling.
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include "MouseView.h"
|
#include "MouseView.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
@@ -95,6 +97,7 @@ MouseView::MouseView(const MouseSettings &settings)
|
|||||||
fOldButtons(0)
|
fOldButtons(0)
|
||||||
{
|
{
|
||||||
SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
|
SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
|
||||||
|
fScaling = std::max(1.0f, be_plain_font->Size() / 12.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,9 +132,9 @@ void
|
|||||||
MouseView::GetPreferredSize(float* _width, float* _height)
|
MouseView::GetPreferredSize(float* _width, float* _height)
|
||||||
{
|
{
|
||||||
if (_width != NULL)
|
if (_width != NULL)
|
||||||
*_width = kMouseDownWidth + 2;
|
*_width = fScaling * (kMouseDownWidth + 2);
|
||||||
if (_height != NULL)
|
if (_height != NULL)
|
||||||
*_height = 104;
|
*_height = fScaling * 104;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -157,8 +160,7 @@ void
|
|||||||
MouseView::MouseUp(BPoint)
|
MouseView::MouseUp(BPoint)
|
||||||
{
|
{
|
||||||
fButtons = 0;
|
fButtons = 0;
|
||||||
Invalidate(BRect(0, kButtonTop, kMouseDownWidth,
|
Invalidate(_ButtonsRect());
|
||||||
kButtonTop + kMouseDownHeight));
|
|
||||||
fOldButtons = fButtons;
|
fOldButtons = fButtons;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,17 +184,14 @@ MouseView::MouseDown(BPoint where)
|
|||||||
GetClippingRegion(&clipping);
|
GetClippingRegion(&clipping);
|
||||||
|
|
||||||
if (fOldButtons != fButtons) {
|
if (fOldButtons != fButtons) {
|
||||||
Invalidate(BRect(0, kButtonTop, kMouseDownWidth, kButtonTop
|
Invalidate(_ButtonsRect());
|
||||||
+ kMouseDownHeight));
|
|
||||||
fOldButtons = fButtons;
|
fOldButtons = fButtons;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
if (_ButtonRect(offset, i).Contains(where)) {
|
||||||
kButtonTop + kMouseDownHeight);
|
|
||||||
if (frame.Contains(where)) {
|
|
||||||
button = i;
|
button = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -229,7 +228,7 @@ MouseView::Draw(BRect updateFrame)
|
|||||||
{
|
{
|
||||||
SetDrawingMode(B_OP_ALPHA);
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
||||||
SetScale(1.8);
|
SetScale(fScaling * 1.8);
|
||||||
|
|
||||||
BShape mouseShape;
|
BShape mouseShape;
|
||||||
mouseShape.MoveTo(BPoint(16, 12));
|
mouseShape.MoveTo(BPoint(16, 12));
|
||||||
@@ -245,12 +244,12 @@ MouseView::Draw(BRect updateFrame)
|
|||||||
mouseShape.Close();
|
mouseShape.Close();
|
||||||
|
|
||||||
// Draw the shadow
|
// Draw the shadow
|
||||||
SetOrigin(-17, -11);
|
SetOrigin(-17 * fScaling, -11 * fScaling);
|
||||||
SetHighColor(kMouseShadowColor);
|
SetHighColor(kMouseShadowColor);
|
||||||
FillShape(&mouseShape, B_SOLID_HIGH);
|
FillShape(&mouseShape, B_SOLID_HIGH);
|
||||||
|
|
||||||
// Draw the body
|
// Draw the body
|
||||||
SetOrigin(-21, -14);
|
SetOrigin(-21 * fScaling, -14 * fScaling);
|
||||||
BGradientRadial bodyGradient(28, 24, 128);
|
BGradientRadial bodyGradient(28, 24, 128);
|
||||||
bodyGradient.AddColor(kMouseBodyTopColor, 0);
|
bodyGradient.AddColor(kMouseBodyTopColor, 0);
|
||||||
bodyGradient.AddColor(kMouseBodyBottomColor, 255);
|
bodyGradient.AddColor(kMouseBodyBottomColor, 255);
|
||||||
@@ -258,7 +257,7 @@ MouseView::Draw(BRect updateFrame)
|
|||||||
FillShape(&mouseShape, bodyGradient);
|
FillShape(&mouseShape, bodyGradient);
|
||||||
|
|
||||||
// Draw the outline
|
// Draw the outline
|
||||||
SetPenSize(1 / 1.8);
|
SetPenSize(1 / 1.8 / fScaling);
|
||||||
SetDrawingMode(B_OP_OVER);
|
SetDrawingMode(B_OP_OVER);
|
||||||
SetHighColor(kMouseOutlineColor);
|
SetHighColor(kMouseOutlineColor);
|
||||||
|
|
||||||
@@ -279,8 +278,8 @@ MouseView::Draw(BRect updateFrame)
|
|||||||
// Separator between the buttons
|
// Separator between the buttons
|
||||||
const int32* offset = getButtonOffsets(fType);
|
const int32* offset = getButtonOffsets(fType);
|
||||||
for (int32 i = 1; i < fType; i++) {
|
for (int32 i = 1; i < fType; i++) {
|
||||||
StrokeLine(BPoint(offset[i], kButtonTop),
|
BRect buttonRect = _ButtonRect(offset, i);
|
||||||
BPoint(offset[i], kButtonTop + kMouseDownHeight));
|
StrokeLine(buttonRect.LeftTop(), buttonRect.LeftBottom());
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse_map map;
|
mouse_map map;
|
||||||
@@ -299,16 +298,16 @@ MouseView::Draw(BRect updateFrame)
|
|||||||
if (pressed) {
|
if (pressed) {
|
||||||
SetDrawingMode(B_OP_ALPHA);
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
SetHighColor(kButtonPressedColor);
|
SetHighColor(kButtonPressedColor);
|
||||||
FillRect(BRect(offset[i], kButtonTop, offset[i + 1] - 1,
|
FillRect(_ButtonRect(offset, i));
|
||||||
kButtonTop + kMouseDownHeight));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BRect border(offset[i] + 1, kButtonTop + 5, offset[i + 1] - 1,
|
BRect border(fScaling * (offset[i] + 1), fScaling * (kButtonTop + 5),
|
||||||
kButtonTop + kMouseDownHeight - 4);
|
fScaling * offset[i + 1] - 1,
|
||||||
|
fScaling * (kButtonTop + kMouseDownHeight - 4));
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
border.left += 5;
|
border.left += fScaling * 5;
|
||||||
if (i == fType - 1)
|
if (i == fType - 1)
|
||||||
border.right -= 4;
|
border.right -= fScaling * 4;
|
||||||
|
|
||||||
char number[2] = {0};
|
char number[2] = {0};
|
||||||
number[0] = getMappingNumber(map.button[_ConvertFromVisualOrder(i)])
|
number[0] = getMappingNumber(map.button[_ConvertFromVisualOrder(i)])
|
||||||
@@ -327,6 +326,23 @@ MouseView::Draw(BRect updateFrame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
MouseView::_ButtonsRect() const
|
||||||
|
{
|
||||||
|
return BRect(0, fScaling * kButtonTop, fScaling * kMouseDownWidth,
|
||||||
|
fScaling * (kButtonTop + kMouseDownHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
MouseView::_ButtonRect(const int32* offsets, int index) const
|
||||||
|
{
|
||||||
|
return BRect(fScaling * offsets[index], fScaling * kButtonTop,
|
||||||
|
fScaling * offsets[index + 1] - 1,
|
||||||
|
fScaling * (kButtonTop + kMouseDownHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
MouseView::_ConvertFromVisualOrder(int32 i)
|
MouseView::_ConvertFromVisualOrder(int32 i)
|
||||||
{
|
{
|
||||||
@@ -349,8 +365,8 @@ void
|
|||||||
MouseView::_CreateButtonsPicture()
|
MouseView::_CreateButtonsPicture()
|
||||||
{
|
{
|
||||||
BeginPicture(&fButtonsPicture);
|
BeginPicture(&fButtonsPicture);
|
||||||
SetScale(1.8);
|
SetScale(1.8 * fScaling);
|
||||||
SetOrigin(-21, -14);
|
SetOrigin(-21 * fScaling, -14 * fScaling);
|
||||||
|
|
||||||
BShape mouseShape;
|
BShape mouseShape;
|
||||||
mouseShape.MoveTo(BPoint(48, 12));
|
mouseShape.MoveTo(BPoint(48, 12));
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ public:
|
|||||||
virtual void Draw(BRect frame);
|
virtual void Draw(BRect frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BRect _ButtonsRect() const;
|
||||||
|
BRect _ButtonRect(const int32* offsets,
|
||||||
|
int index) const;
|
||||||
int32 _ConvertFromVisualOrder(int32 button);
|
int32 _ConvertFromVisualOrder(int32 button);
|
||||||
void _CreateButtonsPicture();
|
void _CreateButtonsPicture();
|
||||||
|
|
||||||
@@ -46,6 +49,7 @@ private:
|
|||||||
BPicture fButtonsPicture;
|
BPicture fButtonsPicture;
|
||||||
int32 fDigitBaseline;
|
int32 fDigitBaseline;
|
||||||
int32 fDigitHeight;
|
int32 fDigitHeight;
|
||||||
|
float fScaling;
|
||||||
|
|
||||||
int32 fType;
|
int32 fType;
|
||||||
uint32 fButtons;
|
uint32 fButtons;
|
||||||
|
|||||||
Reference in New Issue
Block a user