Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ColorPicker's RAW mode colors and values #88072

Closed
wants to merge 1 commit into from

Conversation

WhalesState
Copy link
Contributor

@WhalesState WhalesState commented Feb 7, 2024

  • Makes RAW sliders colored same as RGB mode.
  • Fix RAW mode maximum values, from 100 to 1.0.
  • Allow RGB and RAW modes to have greater values for overbright.
  • Changes RAW step value to 1.0 / 255.0, to match the RGB mode values when changed.
  • Prevent OKHSL mode from overriding the picker shape.
  • Fix conversion between RAW and RGB modes when color is overbright.

@WhalesState WhalesState requested a review from a team as a code owner February 7, 2024 18:37
@AThousandShips AThousandShips added this to the 4.x milestone Feb 7, 2024
@WhalesState WhalesState force-pushed the color-picker branch 2 times, most recently from 9b7e6fe to a9acca2 Compare February 7, 2024 18:41
@WhalesState
Copy link
Contributor Author

Please add the bug label too, since it fixes three annoying issues.

@AThousandShips
Copy link
Member

AThousandShips commented Feb 7, 2024

Please open a bug report first :)

Remember you need to add "fixes" before each issue number

@WhalesState
Copy link
Contributor Author

Remember you need to add "fixes" before each issue number

Thanks ^^

@AThousandShips
Copy link
Member

@WhalesState
Copy link
Contributor Author

See also:

We share the same fix
from float slider_max[4] = { 100, 100, 100, 1 }; to float slider_max[4] = { 1, 1, 1, 1 };

@Cammymoop
Copy link
Contributor

Being able to set values greater than 1.0 in raw mode is a feature, not a bug. #62894 is about not restoring the maximum value of the slider when going back to RGB mode, not changing the max value in raw mode.

@WhalesState
Copy link
Contributor Author

WhalesState commented Feb 10, 2024

Being able to set values greater than 1.0 in raw mode is a feature, not a bug. #62894 is about not restoring the maximum value of the slider when going back to RGB mode, not changing the max value in raw mode.

we can still allow this feature by making the SpinBox able to set values higher than 1.0 by enabling allow_greater, but I still don't understand the use of it, since they will not be visualized correctly, is it for glow/emission strength to make some colors more brighter that others? maybe because the glow the strength is a global variable for each environment.

however, allowing both RGB and RAW mode to set greater values will fix this issue and keep the feature.

@Cammymoop
Copy link
Contributor

Cammymoop commented Feb 10, 2024

Yes, it is for colors that are overbright in cases such as emissive colors with glow effects, or using modulate to brighten something.

I wouldn't suggest using allow_greater on the RAW mode sliders and limiting them to 1, because afaik the main reason raw mode is used at all is for overbright colors. RGB mode uses code specifically (see get_slider_max *edit) to set different slider max values in the case where you switched from raw and still want to edit the overbright color I guess but I'm not sure that that part is usefull, and you could just as easily switch to HSV instead (which would be more helpful to edit an overbright color) now that raw is a separate tab from RGB, but HSV does clamp the overbright color so that's pointless currently.

A proper way to deal with overbright colors on all color modes (probably a separate intensity slider) is the only elegant fix I think, but I think making RGB mode use allow_greater or just making it clamp is the way to go for this bug. HSV could use allow_greater theoretically, but I don't think the internal conversion supports that properly, okhsl will definitely not work with unclamped lightness so don't bother with that one.

@WhalesState
Copy link
Contributor Author

WhalesState commented Feb 10, 2024

ok, after allowing both RGB and RAW modes to have greater values, we are back again to this issue #62894, for some reason the slider maximum value changes after converting from RAW to RGB.

!!!
image

The issue is now clear, maximum slider values are not defined for RGB, I think it do calculates it manually which causes this issue.

image

here it is.
image

@MajorMcDoom
Copy link
Contributor

Hi there, I was going to ask, while we're at it, is it difficult to make it possible to accept negative values as well? I know the most common use case is overbright colors, but negative colors are also used in many graphics tricks, and being able to export one would be great. The thing is that each component in Color can, in code, represent any float. But when exported in the inspector, the values are artificially being constrained by the UX of the ColorPicker. I think that's quite a shame, and it would be great if we could get over that hurdle with this PR. But if it's too difficult, I think getting over the limit of 100 is already a pretty big win.

@Calinou
Copy link
Member

Calinou commented May 12, 2024

Hi there, I was going to ask, while we're at it, is it difficult to make it possible to accept negative values as well? I know the most common use case is overbright colors, but negative colors are also used in many graphics tricks, and being able to export one would be great. The thing is that each component in Color can, in code, represent any float. But when exported in the inspector, the values are artificially being constrained by the UX of the ColorPicker. I think that's quite a shame, and it would be great if we could get over that hurdle with this PR. But if it's too difficult, I think getting over the limit of 100 is already a pretty big win.

The issue is that many properties can't handle negative colors by design (or it'll result in unintended effects). We'd need additional property hints to denote that specific properties can't use negative colors, similar to the existing PROPERTY_HINT_COLOR_NO_ALPHA. Once this hint is added, we'd then have to comb through all the existing properties of type Color and add hints as required. It's a lot of work for a feature that won't be needed often, as some nodes like Light3D already have a Negative property.

@WhalesState WhalesState marked this pull request as draft June 9, 2024 07:50
@WhalesState WhalesState marked this pull request as ready for review June 9, 2024 08:25
@KoBeWi KoBeWi removed this from the 4.3 milestone Aug 1, 2024
@WhalesState WhalesState marked this pull request as ready for review October 26, 2024 22:21
@KoBeWi KoBeWi removed the archived label Oct 26, 2024
@KoBeWi KoBeWi added this to the 4.4 milestone Oct 26, 2024
@WhalesState WhalesState marked this pull request as draft January 3, 2025 22:06
@WhalesState WhalesState force-pushed the color-picker branch 2 times, most recently from 359646e to ce4e330 Compare January 3, 2025 22:52
@WhalesState WhalesState marked this pull request as ready for review January 3, 2025 22:52
@@ -276,7 +276,6 @@ class ColorPicker : public VBoxContainer {
void _copy_color_to_hsv();
void _copy_hsv_to_color();

PickerShapeType _get_actual_shape() const;
Copy link
Member

@KoBeWi KoBeWi Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like unrelated change.
EDIT:
It's covered by #99662
It's better to keep PRs more focused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is here for nearly a year now, and #99662 has merge conflict and was opened 9 months after this PR.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 23, 2025

Still not convinced about slider max value change. While it's possible to input bigger number in the SpinBox, you lose ability to adjust overbright via dragging, and I know some people like doing that. Not to mention that pressing Enter to accept SpinBox value will close the popup.

@WhalesState
Copy link
Contributor Author

WhalesState commented Jan 25, 2025

Still not convinced about slider max value change. While it's possible to input bigger number in the SpinBox, you lose ability to adjust overbright via dragging, and I know some people like doing that. Not to mention that pressing Enter to accept SpinBox value will close the popup.

For RAW and RGB modes, We can allow dragging using the SpinBox, they can click and hold the up/down button and move the mouse up or down to change the value, we just need to change the maximum value for the SpinBox only and not the sliders to not lose the colorized sliders for RAW mode, also a maximum value of 10 can be more usable than 100. We can add ColorMode::get_spinbox_max to solve this.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 25, 2025

With all these get() methods in ColorMode, I wonder if we shouldn't just introduce a single ColorModeConfig struct, which would hold all these parameters (not in this PR).
get_spinbox_max() would solve the problem. I think it should have some default return value, like -1, which would make it match the slider max.

@WhalesState
Copy link
Contributor Author

WhalesState commented Jan 25, 2025

Maybe i can use this to return the slider max value by default virtual float get_spinbox_max(int idx) const override { return get_slider_max(idx); }.

@KoBeWi
Copy link
Member

KoBeWi commented Jan 25, 2025

Makes sense.

@WhalesState
Copy link
Contributor Author

Failed because Spinbox and Slider are shared, will have to update them manually for this to work.

@WhalesState
Copy link
Contributor Author

WhalesState commented Jan 25, 2025

Added a new class OverbrightSpinbox and used it for RGB and RAW modes.

First i have tried to disconnect the value_changed and connects it again after updating the slider but I was afraid if it will be slow, so i just connected the value_changed of the slider to OverbrightSpinbox::_update which will return early to avoid calling set_value_no_signal twice.

Didn't test it yet since it's still building after the rebase, Just need to know if this approach looks fine.

Also I can reuse ColorMode::can_allow_greater instead of ColorMode::has_overbright_spinbox since both are for overbright.

@WhalesState
Copy link
Contributor Author

Works as expected.

Only the alpha slider shares it's value with the alpha spinbox, I ended up using the new OverBrightSpinBox for all the other SpinBoxes to avoid deleting/recreating spinboxes.

Screencast.from.01-26-2025.02.34.15.AM.webm

@@ -106,20 +112,21 @@ class ColorModeRGB : public ColorMode {
class ColorModeRAW : public ColorMode {
public:
String labels[3] = { "R", "G", "B" };
float slider_max[4] = { 100, 100, 100, 1 };
float slider_max[4] = { 1, 1, 1, 1 };
float spinbox_max[4] = { 10, 10, 10, 255 };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The 4th value is never used because we don't apply this to the alpha SpinBox. Maybe i can reduce the array size to 3.

@WhalesState WhalesState deleted the color-picker branch January 28, 2025 15:15
@AThousandShips AThousandShips removed this from the 4.4 milestone Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switching to RAW mode and then to RGB will change slider max value until refreshed
6 participants