[solved] get click position on the button?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Kia
Eileen-Class Veteran
Posts: 1050
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

[solved] get click position on the button?

#1 Post by Kia »

I have a big button and I want to find out where it has been clicked in relation to it's top left.
So far I've been positioning it manually, that way I know where my button starts at all times, this limits the use of vbox, hbox, paddings and drags. I wonder is there's an easy way to find where on the button has been clicked, or at least where the button was when it was clicked?
Last edited by Kia on Sun Apr 28, 2024 11:42 am, edited 1 time in total.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1000
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: get click position on the button?

#2 Post by m_from_space »

Kia wrote: Sun Apr 28, 2024 3:54 am I have a big button and I want to find out where it has been clicked in relation to it's top left.
So far I've been positioning it manually, that way I know where my button starts at all times, this limits the use of vbox, hbox, paddings and drags. I wonder is there's an easy way to find where on the button has been clicked, or at least where the button was when it was clicked?
I guess you could just call a function the moment it is clicked. That function then utilizes renpy.get_mouse_pos() and calculates the rest depending on the position of the button and its size.

User avatar
Kia
Eileen-Class Veteran
Posts: 1050
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: get click position on the button?

#3 Post by Kia »

m_from_space wrote: Sun Apr 28, 2024 4:47 am I guess you could just call a function the moment it is clicked. That function then utilizes renpy.get_mouse_pos() and calculates the rest depending on the position of the button and its size.
That's what I've been doing.
But I want to have freedom to place my button in arbitrary positions, utilizing boxes, padding, margin and drags without having to take all of those into account in my calculations.

User avatar
Alex
Lemma-Class Veteran
Posts: 3097
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: get click position on the button?

#4 Post by Alex »

Kia wrote: Sun Apr 28, 2024 3:54 am I have a big button and I want to find out where it has been clicked in relation to it's top left.
So far I've been positioning it manually, that way I know where my button starts at all times, this limits the use of vbox, hbox, paddings and drags. I wonder is there's an easy way to find where on the button has been clicked, or at least where the button was when it was clicked?
What are you trying to achieve, why do you need such calculations? Maybe a set of overlapping imagebuttons with foces_mask property could do the trick?

philat
Eileen-Class Veteran
Posts: 1925
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: get click position on the button?

#5 Post by philat »

Wouldn't renpy.focus_coordinates (https://www.renpy.org/doc/html/other.ht ... oordinates ) be enough to get the info you need?

User avatar
Kia
Eileen-Class Veteran
Posts: 1050
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: get click position on the button?

#6 Post by Kia »

Alex wrote: Sun Apr 28, 2024 7:57 am What are you trying to achieve, why do you need such calculations? Maybe a set of overlapping imagebuttons with foces_mask property could do the trick?
When I have something like a chess board, instead of adding a hundred buttons, I usually add one and find out what cell is clicked by doing some math instead.
philat wrote: Sun Apr 28, 2024 11:00 am Wouldn't renpy.focus_coordinates (https://www.renpy.org/doc/html/other.ht ... oordinates ) be enough to get the info you need?
That's exactly what I've been looking for, thank you ^^

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]