Advertisement

Zoom to mouse cursor and get mouse location on zoomed image

Started by May 13, 2020 03:36 PM
0 comments, last by JB3DG 4 years, 8 months ago

Hi guys

I have a image tool I am working on. I zoom to the mouse location using the following code:

float x = float(imgrender.mx - imgrender.bgx);

float y = float(imgrender.my - imgrender.bgy);

float pscale = imgrender.bgscale;

imgrender.bgscale = max(min(imgrender.bgscale + (zDelta > 0 ? 0.1f : -0.1f), 100.0f), 0.20f);

float newx = x * (imgrender.bgscale / pscale);

float newy = y * (imgrender.bgscale / pscale);

imgrender.bgx += (x - newx);

imgrender.bgy += (y - newy);

I then take the bgx/bgy values, and set them to my viewport Topleft X/Y coordinates, and the viewport size is multiplied by the bgscale value, before rendering the image here:

dx.SetViewport(bgx, bgy, float(bgw)*bgscale, float(bgh)*bgscale);

dx.DrawImage(bgimg, DXRectF(0, 0, float(width), float(height)), DXRectF(0, 0, bgimg->width, bgimg->height), 0);//First DXRectF is position and dimensions of image. Second DXRectF is UV coordinates of the quad on the image

Not sure if my zoom code is correct (it doesn't seem to keep the pixel I am zooming in on under the cursor) so could do with suggestions there, but my real challenge is finding out where the mouse is located on the zoomed image, so I can render selection rectangles. Any ideas?

Thanks

JB

This topic is closed to new replies.

Advertisement