Mandelbrot: mouse wheel zooming.

Fixes #9533.
This commit is contained in:
Adrien Destugues
2014-11-20 15:01:45 +01:00
parent c2a13372aa
commit b0ee8bf20a
2 changed files with 50 additions and 21 deletions
+39 -11
View File
@@ -26,15 +26,10 @@
/*------------------------------------------------------------*/ /*------------------------------------------------------------*/
TShowBit *tsbb; static TShowBit *tsbb;
static long niter = 256;
static uchar palette[256];
/*------------------------------------------------------------*/
long niter = 256;
/*------------------------------------------------------------*/
uchar palette[256];
/*------------------------------------------------------------*/
void TShowBit::MouseDown(BPoint where) void TShowBit::MouseDown(BPoint where)
{ {
@@ -54,7 +49,41 @@ void TShowBit::MouseDown(BPoint where)
redraw_mand(); redraw_mand();
} }
/*------------------------------------------------------------*/
void
TShowBit::MessageReceived(BMessage* message)
{
switch(message->what) {
case B_MOUSE_WHEEL_CHANGED:
{
//float factor = 1;
float change = message->FindFloat("be:wheel_delta_y");
BPoint where;
GetMouse(&where, 0, 0);
selection = Bounds();
if (change < 0) {
// zoom in
selection.top = (where.y + selection.top) / 2;
selection.bottom = (where.y + selection.bottom) / 2;
selection.left = (where.x + selection.left) / 2;
selection.right = (where.x + selection.right) / 2;
} else {
// zoom out
selection.top = - where.y + selection.top * 2;
selection.bottom = - where.y + selection.bottom * 2;
selection.left = - where.x + selection.left * 2;
selection.right = - where.x + selection.right * 2;
}
redraw_mand();
break;
}
default:
BView::MessageReceived(message);
}
}
void TShowBit::redraw_mand() void TShowBit::redraw_mand()
{ {
@@ -66,8 +95,7 @@ void TShowBit::redraw_mand()
px -= (scale / 2.0); px -= (scale / 2.0);
py -= (scale / 2.0); py -= (scale / 2.0);
scale *= 2.0; scale *= 2.0;
} } else {
else {
px0 = px + (scale * (selection.left / (1.0*size_x))); px0 = px + (scale * (selection.left / (1.0*size_x)));
py0 = py + (scale * (selection.top / (1.0*size_x))); py0 = py + (scale * (selection.top / (1.0*size_x)));
scale0 = scale * ((selection.bottom-selection.top) / (1.0*size_x)); scale0 = scale * ((selection.bottom-selection.top) / (1.0*size_x));
+1
View File
@@ -37,6 +37,7 @@ public:
virtual ~TShowBit(); virtual ~TShowBit();
virtual void Draw(BRect); virtual void Draw(BRect);
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
void MessageReceived(BMessage* message);
virtual void Pulse(); virtual void Pulse();
void mand(double vx, double vy, double sx, double sy); void mand(double vx, double vy, double sx, double sy);
long limit_v(long v); long limit_v(long v);