Page 1 of 1

[SOLVED] Where is my mouse positioned?

Posted: Tue Nov 16, 2021 4:34 am
by felsenstern
Hiya,

is there a simple way to get the mouse cursor location inside a Ren'Py screen?

Re: Where is my mouse positioned?

Posted: Tue Nov 16, 2021 4:47 am
by philat
https://www.renpy.org/doc/html/other.ht ... _mouse_pos

You can find several examples using this if you search the forums as well.

Re: Where is my mouse positioned?

Posted: Tue Nov 16, 2021 5:45 am
by felsenstern
philat wrote:
Tue Nov 16, 2021 4:47 am
You can find several examples using this if you search the forums as well.
Sometimes I wish you guys could see a log of all my search queries and pondering I've done before having to beg for information in this forum and of course getting exactly the RTF quote.

Thanks for the info anyways.

Re: [SOLVED] Where is my mouse positioned?

Posted: Tue Nov 16, 2021 8:52 am
by philat
Chill, dude. I meant the documentation doesn't show you how to use it, so if you need examples, search the forum. Obviously I have no idea what you searched for, but fyi the in-forum search isn't great and I tend to find google with site:lemmasoft.renai.us turns up better results. :shrug:

Re: [SOLVED] Where is my mouse positioned?

Posted: Wed Nov 24, 2021 11:54 am
by zmook
Here's the code I use, which I of course hacked together from code elsewhere on these forums:

Code: Select all

default mousex = 0
default mousey = 0

init python:

    # create a 1x1 invisible Displayable to listen for Mouse motion events
    # updates store.mouse_pos every time the mouse moves
    class getMousePosition(renpy.Displayable):

        def __init__(self):
            renpy.Displayable.__init__(self)

        def event(self, ev, x, y, st):
            import pygame

            if ev.type == pygame.MOUSEMOTION: # Updates the position of the mouse every time the player moves it
                store.mouse_pos = (x,y)
                renpy.restart_interaction()

        def render(self, width, height, st, at):
            return renpy.Render(1, 1)

    store.mousePosition= getMousePosition()

    def checkEvent():
        ui.add(mousePosition)
        
    if debug:
        config.overlay_functions.append(checkEvent) # This adds a 1*1 invisible displayable on every screen
Alternately, if you just want to know the position of a Drag:

Code: Select all

screen metadata_overlay():
            drag:
                pos start_pos
                dragged caption_dragged
                textbutton gallerytitle style "gallerytitle"

init python:
    def caption_dragged(drags,drop):
        renpy.log("dragged to %d,%d" % (drags[0].x,drags[0].y) )
        return None