Page 1 of 1

[solved] get click position on the button?

Posted: Sun Apr 28, 2024 3:54 am
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?

Re: get click position on the button?

Posted: Sun Apr 28, 2024 4:47 am
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.

Re: get click position on the button?

Posted: Sun Apr 28, 2024 5:37 am
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.

Re: get click position on the button?

Posted: Sun Apr 28, 2024 7:57 am
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?

Re: get click position on the button?

Posted: Sun Apr 28, 2024 11:00 am
by philat
Wouldn't renpy.focus_coordinates (https://www.renpy.org/doc/html/other.ht ... oordinates ) be enough to get the info you need?

Re: get click position on the button?

Posted: Sun Apr 28, 2024 11:42 am
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 ^^