The label can be 1.0 to 2.0 in 0.1 steps. 1 is original Size and 2 would be 2x the original.
I am applying this to graphics. However, I shift the matrix depending on the scaling, as I want it centered to the screen. With this:
Code:
Dim TranRepairX As Decimal = CenterOfRotation.X - ((LabelScale) * CenterOfRotation.X)
Dim TranRepairY As Decimal = CenterOfRotation.Y - ((2 - LabelScale) * CenterOfRotation.Y)
CursorMatrix.Translate(TranRepairX, TranRepairY, MatrixOrder.Append)
This works great. The image is enlarged, and as it enlarges down and to the right in the coordinates, the above code moves it up and left so its always centered.
Here is where my problem is. When I draw on the image, the graphics are not going where the cursor is! I understand that this is because of the scaling. However, I cant figure out for the life of me how to get the graphics to go where the cursor is.
I did figure out that this would do it, but only when the scaling = 2:
Re: ScalingnMatrix is messing with cursor position!
Did you try not subtracting the transformed points from e.x and e.y.
The point was to transform e.x and e.y (device coordinates) into world coordinates, so once you have world coordinates it doesn't make sense to subtract them from the device coordinates, they aren't related.
Code:
Dim NewCursorPoints As Point() = {e.Location}
CursorMatrix.TransformPoints(NewCursorPoints )
NewPoint = newCursorPoints(0)
You may have to use an inverse matrix. In fact I'm pretty sure of it, since you're using the CursorMatrix to convert points (world coordinates) to points on the screen (device coordinates) for drawing.
Now you have screen coordinates (the mouse position), which you want to convert to your drawing coordinates (world coordinates), so that is the reverse direction.
I would have a form class scope matrix declared and at the point in your drawing where your matrix is in the state that matches your drawing window, save an inverted copy of that matrix in your class scope matrix.
Then use that matrix to do the TransformPoints call (will convert Mouse X,Y into World Coordinates).
I figure I have an example of that somewhere, but can't find it offhand.
Another method is instead of using the TransformPoints method of a matrix, use the TransformPoints method of a Graphics object.
An example of that I can find. It is a somewhat extensive example of using a Graphics object to transform the Mouse coordinates.
The example has a number of scrollbars that can scale, rotate and pan horizontally and vertically a drawing. There are some other controls as well, but I would have to look at the code again as it has been a while. Probably not the most complete from a user friendly GUI perspective.
At any point, you can use the mouse to draw on that drawing as an example of converting the mouse coordinates to the world coordinates of the drawing regardless of pan, scale or rotation.
It doesn't look like I've ever posted it on this forum before, so I'll post it here.