[solved]imagebutton reacting to hover with mousekey pressed?
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.
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.
- SONTSE
- Regular
- Posts: 96
- Joined: Sun Nov 24, 2013 10:49 pm
- Completed: 11 VN's so far
- Discord: jkx0282_10798
- Contact:
[solved]imagebutton reacting to hover with mousekey pressed?
Hello, folks.
In my options menu i have a pattern of switches i would like to switch multiple at once simply by hovering over them.
And sometimes i want to hover over them without any action.
So hovering with key pressed would be an nice solution.
Ideally it should do no action with hovering and no key pressed,
trigger a switch-on with left key pressed,
and a switch-off with a right key pressed.
I hope my request is clear.
Thanks for bothering,
have a nice day
In my options menu i have a pattern of switches i would like to switch multiple at once simply by hovering over them.
And sometimes i want to hover over them without any action.
So hovering with key pressed would be an nice solution.
Ideally it should do no action with hovering and no key pressed,
trigger a switch-on with left key pressed,
and a switch-off with a right key pressed.
I hope my request is clear.
Thanks for bothering,
have a nice day
Last edited by SONTSE on Sun Nov 30, 2014 12:34 pm, edited 1 time in total.
- PyTom
- Ren'Py Creator
- Posts: 16088
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: imagebutton reacting to hover with mousekey pressed?
I don't really understand what you want.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- SONTSE
- Regular
- Posts: 96
- Joined: Sun Nov 24, 2013 10:49 pm
- Completed: 11 VN's so far
- Discord: jkx0282_10798
- Contact:
Re: imagebutton reacting to hover with mousekey pressed?
I'm sorry for such unclear explanation(perhaps due to my engrish)
I'll try another way to explain my needs omitting the actual purpose of desired solution.
Basically i need an imagebutton to do some stuff when it's in "hovered" state AND my mouse key is in pressed state. I assume the code would be something like that:
Where "leftmousebuttonpressed" and "rightmousebuttonpressed" are boolean functions i seek, they should be true anytime i keep mentioned mouse buttons pressed.
Thanks again! n_n
I'll try another way to explain my needs omitting the actual purpose of desired solution.
Basically i need an imagebutton to do some stuff when it's in "hovered" state AND my mouse key is in pressed state. I assume the code would be something like that:
Code: Select all
imagebutton idle "button.png" hover "button_h.png" hovered If(leftmousebuttonpressed, true = Function("DoThis"), false = If(rightmousebuttonpressed, true = Function("DoThat"))) action NullAction()
Thanks again! n_n
- PyTom
- Ren'Py Creator
- Posts: 16088
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: imagebutton reacting to hover with mousekey pressed?
Um... do you want it to do something when it becomes hovered, or when the button is pressed as it's hovered? The latter is doable, while the former will likely require a CDD.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- SONTSE
- Regular
- Posts: 96
- Joined: Sun Nov 24, 2013 10:49 pm
- Completed: 11 VN's so far
- Discord: jkx0282_10798
- Contact:
Re: imagebutton reacting to hover with mousekey pressed?
Thanks for suggest, PyTom. I'm afraid it is former. I would appreciate some CDD example that operates left and right mouse buttons. It can be not relevant to the issue (which i failed to explain anyway lol), i think i will be fine once i see the mechanism and syntax.
Thanks again n_n
Thanks again n_n
- SONTSE
- Regular
- Posts: 96
- Joined: Sun Nov 24, 2013 10:49 pm
- Completed: 11 VN's so far
- Discord: jkx0282_10798
- Contact:
Re: imagebutton reacting to hover with mousekey pressed?
Just managed to work it out using a CDD
and then i just add GetMouse() on my screen and on each imagebutton when hovered I verify if lclick or rclick are True (which they are when according buttons are pressed) and then proceed to action here is my imagebuttons
i would appreciate for any advice (maybe I doing something very wrong without notice)
Thanks, folks
Code: Select all
init python:
import pygame
lclick = False
mclick = False
rclick = False
class GetMouse(renpy.Displayable):
def __init__(self):
super(GetMouse, self).__init__()
def render(self, width, height, st, at):
rv = renpy.Render(width, height)
return rv
def event(self, ev, x, y, st):
global lclick,mclick,rclick
lclick,mclick,rclick = pygame.mouse.get_pressed()
return None
Code: Select all
for xx in range (0,10):
for yy in range (1,5):
imagebutton idle "1_percent_opaque.png" hover "1_percent_opaque.png" pos strp[(xx,yy)] anchor (0.5,1.0) hovered [If(lclick,true=SetDict(strb,yy*10+xx,True)),If(rclick,true=SetDict(strb,yy*10+xx,False))] action NullAction()
Thanks, folks
- PyTom
- Ren'Py Creator
- Posts: 16088
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: [solved]imagebutton reacting to hover with mousekey pres
My only suggestions would be to look at the event (ev) itself, rather than using mouse.get_pressed().
There's a very minor issue where if events get backlogged, x and y will have old position data, while get_pressed is always current.
There's a very minor issue where if events get backlogged, x and y will have old position data, while get_pressed is always current.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
- SONTSE
- Regular
- Posts: 96
- Joined: Sun Nov 24, 2013 10:49 pm
- Completed: 11 VN's so far
- Discord: jkx0282_10798
- Contact:
Re: [solved]imagebutton reacting to hover with mousekey pres
Well that was the plan but I ended up failing to fetch correct properties/values out of a pygame documentations, so i'm thankful for any further explanations. Will research this at my own once i end all my deadlines.PyTom wrote:My only suggestions would be to look at the event (ev) itself, rather than using mouse.get_pressed().
Who is online
Users browsing this forum: Ahrefs [Bot]