Accessibility brightness and contrast options

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
Gouvernathor
Newbie
Posts: 23
Joined: Thu Aug 06, 2020 9:27 am
Github: Gouvernathor
Discord: Armise#6515
Contact:

Accessibility brightness and contrast options

#1 Post by Gouvernathor »

This is some code allowing the players to customize the brightness and contrast of the game.
Be warned that it forbids you the use of the camera and show-layer-at statements, and that passing excessive values will make the screen entirely black, white or gray and in that case you won't be able to change them using the GUI (which will be invisible).

Code: Select all

init python:
    import functools
    def layer_color_function(trans, st, at):
        trans.matrixcolor = BrightnessMatrix(persistent.brig)*ContrastMatrix(persistent.cont)
        return None

define layer_color = Transform(function=layer_color_function)

default persistent.brig = 0.
default persistent.cont = 1.

define config.after_default_callbacks += [functools.partial(renpy.show_layer_at, [layer_color], "screens", camera=True),
                                          functools.partial(renpy.show_layer_at, [layer_color], "master", camera=True)]
You will also need to add GUI access to those values, for example by adding this to your preferences screens, but I warn again : the excessive values at the extremes of the resulting bars will render the game essentially invisible. If you do that by mistake, click "delete persistent" in the launcher - but the players won't have that option.

Code: Select all

                    label _("Brightness")

                    bar value FieldValue(persistent, "brig", 2., style="slider_slider", offset=-1)

                    label _("Contrast")

                    bar value FieldValue(persistent, "cont", 2., style="slider_slider")
Here, the brightness goes from -1. to 1.0 (from 0 to 2 with an offset of -1) an the contrast goes from .0 to 2., but you can make it go further up (I don't know up to what value though).


User avatar
neometalero
Regular
Posts: 198
Joined: Sun Oct 23, 2016 3:51 am
Completed: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Projects: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Deviantart: neometalero
Contact:

Re: Accessibility brightness and contrast options

#3 Post by neometalero »

Gouvernathor wrote: Fri Feb 24, 2023 9:10 am This is some code allowing the players to customize the brightness and contrast of the game.
Be warned that it forbids you the use of the camera and show-layer-at statements, and that passing excessive values will make the screen entirely black, white or gray and in that case you won't be able to change them using the GUI (which will be invisible).

Code: Select all

init python:
    import functools
    def layer_color_function(trans, st, at):
        trans.matrixcolor = BrightnessMatrix(persistent.brig)*ContrastMatrix(persistent.cont)
        return None

define layer_color = Transform(function=layer_color_function)

default persistent.brig = 0.
default persistent.cont = 1.

define config.after_default_callbacks += [functools.partial(renpy.show_layer_at, [layer_color], "screens", camera=True),
                                          functools.partial(renpy.show_layer_at, [layer_color], "master", camera=True)]
You will also need to add GUI access to those values, for example by adding this to your preferences screens, but I warn again : the excessive values at the extremes of the resulting bars will render the game essentially invisible. If you do that by mistake, click "delete persistent" in the launcher - but the players won't have that option.

Code: Select all

                    label _("Brightness")

                    bar value FieldValue(persistent, "brig", 2., style="slider_slider", offset=-1)

                    label _("Contrast")

                    bar value FieldValue(persistent, "cont", 2., style="slider_slider")
Here, the brightness goes from -1. to 1.0 (from 0 to 2 with an offset of -1) an the contrast goes from .0 to 2., but you can make it go further up (I don't know up to what value though).
Im getting the following error msj, any idea what could be wrong?

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/ByCSet.rpy", line 12, in script
    define config.after_default_callbacks += [functools.partial(renpy.show_layer_at, [layer_color], "screens", camera=True),
  File "game/ByCSet.rpy", line 12, in script
    define config.after_default_callbacks += [functools.partial(renpy.show_layer_at, [layer_color], "screens", camera=True),
  File "renpy/common/000namespaces.rpy", line 39, in get
    return getattr(self.nso, name)
Exception: config.after_default_callbacks is not a known configuration variable.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "C:\Renpy803\renpy-8.0.3-sdk\renpy\bootstrap.py", line 277, in bootstrap
    renpy.main.main()
  File "C:\Renpy803\renpy-8.0.3-sdk\renpy\main.py", line 558, in main
    renpy.game.context().run(node)
  File "game/ByCSet.rpy", line 12, in script
    define config.after_default_callbacks += [functools.partial(renpy.show_layer_at, [layer_color], "screens", camera=True),
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python3.9/site-packages/future/utils/__init__.py", line 441, in raise_
  File "game/ByCSet.rpy", line 12, in script
    define config.after_default_callbacks += [functools.partial(renpy.show_layer_at, [layer_color], "screens", camera=True),
  File "C:\Renpy803\renpy-8.0.3-sdk\renpy\ast.py", line 2441, in execute
    self.set()
  File "C:\Renpy803\renpy-8.0.3-sdk\renpy\ast.py", line 2462, in set
    base = ns.get(self.varname)
  File "renpy/common/000namespaces.rpy", line 39, in get
    return getattr(self.nso, name)
  File "C:\Renpy803\renpy-8.0.3-sdk\renpy\defaultstore.py", line 97, in __getattr__
    raise Exception('config.%s is not a known configuration variable.' % (name))
Exception: config.after_default_callbacks is not a known configuration variable.

Windows-10-10.0.22621 AMD64
Ren'Py 8.0.3.22090809
The Question 7.0
Tue May 16 16:36:06 2023
Working on many weird narrative games at Curse Box Studios
Image
https://www.curseboxstudios.com/

Gouvernathor
Newbie
Posts: 23
Joined: Thu Aug 06, 2020 9:27 am
Github: Gouvernathor
Discord: Armise#6515
Contact:

Re: Accessibility brightness and contrast options

#4 Post by Gouvernathor »

You're not using the last version of Ren'Py.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Accessibility brightness and contrast options

#5 Post by Imperf3kt »

You could always try Ren'Pys built in accessibility menu

Code: Select all

textbutton "accessibility" action Preference("accessibility menu")
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
neometalero
Regular
Posts: 198
Joined: Sun Oct 23, 2016 3:51 am
Completed: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Projects: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Deviantart: neometalero
Contact:

Re: Accessibility brightness and contrast options

#6 Post by neometalero »

Gouvernathor wrote: Tue May 16, 2023 4:44 pm You're not using the last version of Ren'Py.
That worked, tks!

I put it in the preferences menu and worked great. I leave the code here in case anyone else is having troubles.

Code: Select all

screen preferences():

    tag menu

    if renpy.mobile:
        $ cols = 2
    else:
        $ cols = 4

    use game_menu(_("Preferences"), scroll="viewport"):

        vbox:

            hbox:
                box_wrap True

                if renpy.variant("pc") or renpy.variant("web"):

                    vbox:
                        spacing 12

                        vbox:
                            style_prefix "radio"
                            label _("Display")
                            textbutton _("Window") action Preference("display", "window")
                            textbutton _("Fullscreen") action Preference("display", "fullscreen")

                        vbox:

                            style_prefix "check"
                            label _("Examples")
                            textbutton _("Translations") action ToggleField(persistent, "show_translation_marker")


                vbox:
                    style_prefix "check"
                    label _("Skip")
                    textbutton _("Unseen Text") action Preference("skip", "toggle")
                    textbutton _("After Choices") action Preference("after choices", "toggle")
                    textbutton _("Transitions") action InvertSelected(Preference("transitions", "toggle"))

                #Bright and Contrast controler---------------------------------------------------------
                vbox:
                    label _("Brightness")

                    bar value FieldValue(persistent, "brig", 2., style="slider_slider", offset=-1)

                    label _("Contrast")

                    bar value FieldValue(persistent, "cont", 2., style="slider_slider")

                #------------------------------------------------------------------------------------
Working on many weird narrative games at Curse Box Studios
Image
https://www.curseboxstudios.com/

User avatar
neometalero
Regular
Posts: 198
Joined: Sun Oct 23, 2016 3:51 am
Completed: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Projects: My Dream Sport Dating Simulator, Attack Helicopter Dating Simulator
Deviantart: neometalero
Contact:

Re: Accessibility brightness and contrast options

#7 Post by neometalero »

Imperf3kt wrote: Tue May 16, 2023 7:40 pm You could always try Ren'Pys built in accessibility menu

Code: Select all

textbutton "accessibility" action Preference("accessibility menu")
Im not familiar with that menu, but I will give it a try as well. Tks!
Working on many weird narrative games at Curse Box Studios
Image
https://www.curseboxstudios.com/

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]