Godot: ColorPicker: alpha can still be set in hex value if "edit alpha" is off

Created on 4 Oct 2018  路  4Comments  路  Source: godotengine/godot

Godot version:

3.06 stable

OS/device including version:

Antergos Linux

Issue description:

In a ColorPicker node, after setting "edit alpha" to false, the colour's alpha value can still be set through the hex value. Not sure if this is intentional.

Steps to reproduce:
Add Colorpicker node. Set "edit alpha" to false. In the running project, add 00 in front of the hex value.
peek 2018-10-04 13-44

bug junior job core

Most helpful comment

I think it should be fixed. In the editor it's not a big issue, but ColorPicker can also be used in games and there, if the developer decided to disable alpha edit, players should not be allowed to work it around.

All 4 comments

The color picker does not check if alpha is enabled or not when entering html.
Is this expected behaviour or shall I try to fix it?

I think it should be fixed. In the editor it's not a big issue, but ColorPicker can also be used in games and there, if the developer decided to disable alpha edit, players should not be allowed to work it around.

So I looked into it and got two solutions that work.
1:
Saving the previous alpha and reset it after the input is done in ColorPicker::_html_entered:

  float last_alpha = color.a;
  color = Color::html(p_html);
  if (!is_editing_alpha())
    color.a = last_alpha;
  1. Changing Color::html to have a second parameter (not optimal I guess)

in Color.h:
static Color html(const String &p_color, bool p_use_alpha=true);
in Color.cpp:

//in Color::html
  int a = 255;
  if (alpha && p_use_alpha) {
    a = _parse_col(color, 0);
    if (a < 0) {
      ERR_EXPLAIN("Invalid Color Code: " + p_color);
      ERR_FAIL_V(Color());
    }
  }

and finally in Colorpicker.cpp:

color = Color::html(p_html, is_editing_alpha());

Solution (1) seems good to me.

Was this page helpful?
0 / 5 - 0 ratings