Page 1 of 1

Zoom in and center at cursor position? [Solved!]

Posted: Fri Sep 03, 2021 3:52 pm
by omranpanda
Hello!

As what the title says.
Does anyone know of a way to make it so that using the renpy.get_mouse_pos() function and the zoom ATL to zoom in and center at the mouse position?

Re: Zoom in and center at cursor position?

Posted: Fri Sep 03, 2021 5:51 pm
by Alex
omranpanda wrote:
Fri Sep 03, 2021 3:52 pm
Hello!

As what the title says.
Does anyone know of a way to make it so that using the renpy.get_mouse_pos() function and the zoom ATL to zoom in and center at the mouse position?
Check this recipe - viewtopic.php?f=51&t=62550

Re: Zoom in and center at cursor position?

Posted: Sat Sep 11, 2021 3:51 pm
by omranpanda
Alex wrote:
Fri Sep 03, 2021 5:51 pm
omranpanda wrote:
Fri Sep 03, 2021 3:52 pm
Hello!

As what the title says.
Does anyone know of a way to make it so that using the renpy.get_mouse_pos() function and the zoom ATL to zoom in and center at the mouse position?
Check this recipe - viewtopic.php?f=51&t=62550
Thanks for this, however this is kinda too overkill for what I needed (And I was unable to implement it for my use case ;!;).

After spending a couple of days I was able to create the equation to solve this problem!

Basically this is what I got and it works perfectly for me. Sorry if my comments are bad ;!;

Code: Select all

python:
        curx, cury = renpy.get_mouse_pos() ## Get cursor position and store in x and y variables.

        zoom_factor = 4.0 ## Must be a float number. 4.0 zoom factor means that the image would be enlarged by 4 times, numbers smaller than 1.0 such as 0.5 could be
                          ## used to shrink instead of enlarge.

	## Adjust for the displacement caused by the zooming and cursor position.
        dx = (config.screen_width/2) - int(curx*zoom_factor)
        dy = (config.screen_height/2) - int(cury*zoom_factor) ## int function used because pixels can't be in float (You can't have half a pixel :p)

camera:

        parallel:
            linear 2.0 zoom zoom_factor

        parallel:
            linear 2.0 pos(dx, dy)