[Solved] Unfocusing screenshot button after click

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
plaster
Regular
Posts: 68
Joined: Thu Jul 11, 2013 1:03 am
Tumblr: plasterbrain
Soundcloud: plasterbrain
Location: Chicago
Contact:

[Solved] Unfocusing screenshot button after click

#1 Post by plaster » Mon Jul 09, 2018 12:45 am

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?
Last edited by plaster on Tue Jul 10, 2018 6:14 pm, edited 1 time in total.

User avatar
Remix
Eileen-Class Veteran
Posts: 1020
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Unfocusing screenshot button after click

#2 Post by Remix » Mon Jul 09, 2018 10:43 am

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...
Mad Scientist Todo List:
  • Finish Improved Event Handler
  • Implement DragonBones animation as a Creator Defined Container
  • Finish Catmull-Rom Spline pathing
  • Finish Bitmask collision and rebound vector system
  • Develop time based building mechanic
  • Others
  • *Find a superb artist and actually write a game*

User avatar
plaster
Regular
Posts: 68
Joined: Thu Jul 11, 2013 1:03 am
Tumblr: plasterbrain
Soundcloud: plasterbrain
Location: Chicago
Contact:

Re: Unfocusing screenshot button after click

#3 Post by plaster » Tue Jul 10, 2018 6:14 pm

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

User avatar
Remix
Eileen-Class Veteran
Posts: 1020
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: [Solved] Unfocusing screenshot button after click

#4 Post by Remix » Tue Jul 10, 2018 7:27 pm

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.
Mad Scientist Todo List:
  • Finish Improved Event Handler
  • Implement DragonBones animation as a Creator Defined Container
  • Finish Catmull-Rom Spline pathing
  • Finish Bitmask collision and rebound vector system
  • Develop time based building mechanic
  • Others
  • *Find a superb artist and actually write a game*

Post Reply

Who is online

Users browsing this forum: No registered users