Closed janicebeinrot closed 9 months ago
Hello @janicebeinrot
Achieving zoom at fixed point is suprisingly tricky to do right, mainly because it is moving target. Changing zoom (scale) is easy enough. After doing that origin of the canvas need to be translated so local position under cursor does not change.
I did extract minimal example from NavigateAction
and included it in the example on develop
branch:
Code should work in on master
too.
Note that value of io.MousePos
is transformed to local position between Begin/End
calls.
@thedmd thanks for make the change, I'll give it a go shortly 😺
Hello,
I'm new to this stuff imgui and node-editor so please bear with me. I'm trying to add a simple zoom functionality to the canvas-example - As for now I would like to use the canvas itself but not the node functionality.
Specifically I've added some code here:
https://github.com/thedmd/imgui-node-editor/blob/master/examples/canvas-example/canvas-example.cpp#L176
As it is now - it works. However the current solution doesn't translate the view so that the location the mouse cursor on the canvas prior to the zoom is still the location/point after the zoom.
The following is a video of what is happening now:
https://github.com/thedmd/imgui-node-editor/assets/153146019/e0027532-48f7-4b60-b173-825b68d0d438
I've tried to recreate the effect as best I can using Gimp:
https://github.com/thedmd/imgui-node-editor/assets/153146019/2c2709da-7514-4dad-b358-b8ce4014bc46