Page 1 of 1

[solved] Using videos as button?

Posted: Tue Mar 26, 2024 2:13 am
by Kia
I'm trying to use two videos for hover and idle states of a button. The normal route of using them as `background` and `hover_background` will cause them reset when the button is hovered.
As a workaround I've tried:

Code: Select all

screen video_test_screen:
    default over = 0
    add "video_idle"
    add "video_hover" at video_alpha(over)
    button:
        align (0.5, 0.5) background "#333" hover_background "#192"
        text "test"
        hovered SetScreenVariable("over", 1)
        unhovered SetScreenVariable("over", 0)
        action NullAction()
But looks like when two videos are played over each other, the top video stays visible despite it's alpha transform.
I wonder if anybody ever tried doing this and got something working?

Re: Using videos as button?

Posted: Tue Mar 26, 2024 4:21 am
by Ocelot
Interesting. Defining videos as

Code: Select all

image video_idle:
    animation
    Movie(play="images/MOV_Achenar_Page_00.mp4")
and using them as background/hover_background works with a single caveat: hover video is only started when button is hovered for the first time. Then it is played uninterrupted as intended. It won't work if you want to synchronize both videos, but if the only goal is to not restart animations each time, then it works. I alsotried using idle_child / hover_child in hope that it will keep animation timebase, but it seems that the problem lies in the fact that movies are not started until shown.

Re: Using videos as button?

Posted: Tue Mar 26, 2024 4:27 am
by Ocelot
A modified version of your approach seems to work:

Code: Select all

screen video_test_screen:
    default ap = 0.0
    button:
        action NullAction()
        hovered SetScreenVariable("ap", 1)
        unhovered SetScreenVariable("ap", 0)
        has fixed
        fit_first True
        add "video idle"
        add "video hover":
            alpha ap

Re: Using videos as button?

Posted: Thu Mar 28, 2024 2:06 am
by Kia
Thank you Ocelot, it works like a charm.
We have `side_mask` that ensures the video and its mask stay in sync, I imagine if we could do another split, we can fit two videos and two masks in the same video file, to use in buttons and such. But there aren't that many developers that are looking for a functionality like that.

Re: [solved] Using videos as button?

Posted: Thu Mar 28, 2024 2:26 am
by Imperf3kt
I personally would have just created a frame displaying the video, then placed an invisible button over top of that. With a little tweaking, this is also an option.

Re: [solved] Using videos as button?

Posted: Fri Mar 29, 2024 3:03 am
by Kia
Imperf3kt wrote: Thu Mar 28, 2024 2:26 am I personally would have just created a frame displaying the video, then placed an invisible button over top of that. With a little tweaking, this is also an option.
My test was kind of the same, but for some reason, two videos placed over each other causes some odd behaviors, when it comes to applying a transform to one of them.