Page 1 of 1

[Solved] Unfocusing screenshot button after click

Posted: Mon Jul 09, 2018 12:45 am
by plaster
Hi... So I'm using the homemade screenshot function described in this thread -- i.e., using take_screenshot() and get_screenshot() to retrieve an image of the screen.

Right now, I have a camera button on screen that you click to take a screenshot. It has a hover style (the button turns yellow) and a tooltip that shows up underneath when you hover it. Unfortunately these hover elements also show up in all the screenshots and it looks pretty dumb!

What I would like is for those hover styles to work... until the user clicks to take a screenshot. There's got to be something I'm misunderstanding though, because no matter how I try to unset the styles or even just hide the quickmenu screen during the screenshot (just to see if that would work), take_screenshot() always captures the screen while the button is focused.

When I wrap the screenshot functionality in a conditional, like

Code: Select all

renpy.hide_screen("topbar")
if not renpy.get_screen("topbar"):
    renpy.take_screenshot((1280, 720))
    photo = renpy.game.interface.get_screenshot()
or even

Code: Select all

button = renpy.display.focus.get_focused()
renpy.hide_screen("topbar")
enpy.display.focus.clear_focus() #???
renpy.restart_interaction() #?????????????

if renpy.display.focus.get_focused != button:
    renpy.take_screenshot((1280, 720))
    photo = renpy.game.interface.get_screenshot()
...Ren'Py will evaluate the statement as true, take the screenshot first, and then hide the screen after. I've also tried plugging some of this stuff into the action of the button itself with the same results.

What do I have to do to unfocus the button during the screenshot?

Re: Unfocusing screenshot button after click

Posted: Mon Jul 09, 2018 10:43 am
by Remix
This seems to work for the keymap version ( tested screenshot show the idle image and hover still works )

Code: Select all

screen shot():
    default sshot = False
    fixed:
        imagebutton:
            idle "images/180.png"
            hover ("images/180.png" if sshot else "images/181.png")
            action [ SetScreenVariable('sshot', True), QueueEvent("screenshot") ]
            unhovered SetScreenVariable('sshot', False)

label start:

    show screen shot
    "..."
Setting the hovered to a conditional test using a variable that toggles True, False then using the QueueEvent action to slightly delay the capture.
You could test to see if the QueueEvent is really needed (basically whether Ren'Py can/does a redraw between button actions) and maybe just call your function rather than the normal screenshot one.
If Ren'Py does not naturally redraw between actions, I doubt there is an easy way around that even using restart_interaction or RestartStatement...

Re: Unfocusing screenshot button after click

Posted: Tue Jul 10, 2018 6:14 pm
by plaster
QueueEvent was what I was missing. You're a lifesaver, thank you!

Got it to work with this in options.rpy:

Code: Select all

config.keymap['topbar_photo'] = 'K_F12'
def topbar_photo():
	#custom screenshot function here
config.underlay.append(renpy.Keymap(topbar_photo = topbar_photo))
...and this in screens.rpy:

Code: Select all

imagebutton:
	idle photo_button + "idle.png"
	hover (photo_button + "idle.png" if taking_photo else photo_button + "hover.png")
        hovered SetScreenVariable("topbar_tt_xpos", 281)
        unhovered SetScreenVariable("taking_photo", False)
        action [SetScreenVariable("taking_photo", True), QueueEvent("topbar_photo")]
        tooltip (None if taking_photo else "Take a Screenshot")
        style photo_style

Re: [Solved] Unfocusing screenshot button after click

Posted: Tue Jul 10, 2018 7:27 pm
by Remix
Nice. I didn't really know you could so easily call your own functions through the keymap like that, will have to remember that one.

Glad you got it working.