Page 1 of 1

[solved]imagebutton reacting to hover with mousekey pressed?

Posted: Sat Nov 29, 2014 3:15 pm
by SONTSE
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

Re: imagebutton reacting to hover with mousekey pressed?

Posted: Sat Nov 29, 2014 7:02 pm
by PyTom
I don't really understand what you want.

Re: imagebutton reacting to hover with mousekey pressed?

Posted: Sat Nov 29, 2014 8:50 pm
by SONTSE
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

Re: imagebutton reacting to hover with mousekey pressed?

Posted: Sun Nov 30, 2014 12:56 am
by PyTom
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.

Re: imagebutton reacting to hover with mousekey pressed?

Posted: Sun Nov 30, 2014 10:31 am
by SONTSE
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

Re: imagebutton reacting to hover with mousekey pressed?

Posted: Sun Nov 30, 2014 12:32 pm
by SONTSE
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

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

Posted: Mon Dec 01, 2014 12:09 am
by PyTom
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.

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

Posted: Mon Dec 01, 2014 1:28 am
by SONTSE
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.