[solved]imagebutton reacting to hover with mousekey pressed?

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
SONTSE
Regular
Posts: 95
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 8 VN's so far
Contact:

[solved]imagebutton reacting to hover with mousekey pressed?

#1 Post by SONTSE » Sat Nov 29, 2014 3:15 pm

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 :D
Last edited by SONTSE on Sun Nov 30, 2014 12:34 pm, edited 1 time in total.
Look! It's moving. It's alive. It's alive... IT'S ALIVE! Oh, in the name of God! Now I know what it feels like to be God!(@Henry_Frankenstein. Sums up my coding style)

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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?

#2 Post by PyTom » Sat Nov 29, 2014 7:02 pm

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
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
SONTSE
Regular
Posts: 95
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 8 VN's so far
Contact:

Re: imagebutton reacting to hover with mousekey pressed?

#3 Post by SONTSE » Sat Nov 29, 2014 8:50 pm

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:

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()
Where "leftmousebuttonpressed" and "rightmousebuttonpressed" are boolean functions i seek, they should be true anytime i keep mentioned mouse buttons pressed.

Thanks again! n_n
Look! It's moving. It's alive. It's alive... IT'S ALIVE! Oh, in the name of God! Now I know what it feels like to be God!(@Henry_Frankenstein. Sums up my coding style)

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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?

#4 Post by PyTom » Sun Nov 30, 2014 12:56 am

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
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
SONTSE
Regular
Posts: 95
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 8 VN's so far
Contact:

Re: imagebutton reacting to hover with mousekey pressed?

#5 Post by SONTSE » Sun Nov 30, 2014 10:31 am

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
Look! It's moving. It's alive. It's alive... IT'S ALIVE! Oh, in the name of God! Now I know what it feels like to be God!(@Henry_Frankenstein. Sums up my coding style)

User avatar
SONTSE
Regular
Posts: 95
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 8 VN's so far
Contact:

Re: imagebutton reacting to hover with mousekey pressed?

#6 Post by SONTSE » Sun Nov 30, 2014 12:32 pm

Just managed to work it out using a CDD

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    
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

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()
i would appreciate for any advice (maybe I doing something very wrong without notice)
Thanks, folks
Look! It's moving. It's alive. It's alive... IT'S ALIVE! Oh, in the name of God! Now I know what it feels like to be God!(@Henry_Frankenstein. Sums up my coding style)

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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

#7 Post by PyTom » Mon Dec 01, 2014 12:09 am

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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
SONTSE
Regular
Posts: 95
Joined: Sun Nov 24, 2013 10:49 pm
Completed: 8 VN's so far
Contact:

Re: [solved]imagebutton reacting to hover with mousekey pres

#8 Post by SONTSE » Mon Dec 01, 2014 1:28 am

PyTom wrote:My only suggestions would be to look at the event (ev) itself, rather than using mouse.get_pressed().
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.
Look! It's moving. It's alive. It's alive... IT'S ALIVE! Oh, in the name of God! Now I know what it feels like to be God!(@Henry_Frankenstein. Sums up my coding style)

Post Reply

Who is online

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