Page 1 of 1

Accessibility brightness and contrast options

Posted: Fri Feb 24, 2023 9:10 am
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).

Re: Accessibility brightness and contrast options

Posted: Sat Feb 25, 2023 1:59 pm
by Andredron
Good code, thanks!

Re: Accessibility brightness and contrast options

Posted: Tue May 16, 2023 3:39 pm
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

Re: Accessibility brightness and contrast options

Posted: Tue May 16, 2023 4:44 pm
by Gouvernathor
You're not using the last version of Ren'Py.

Re: Accessibility brightness and contrast options

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

Code: Select all

textbutton "accessibility" action Preference("accessibility menu")

Re: Accessibility brightness and contrast options

Posted: Tue May 16, 2023 8:32 pm
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")

                #------------------------------------------------------------------------------------

Re: Accessibility brightness and contrast options

Posted: Tue May 16, 2023 8:32 pm
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!