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

Use cached hue for color picker when saturation is 0 #77863

Merged
merged 1 commit into from
Jun 12, 2023

Conversation

dinoplane
Copy link
Contributor

Hue is cached when the saturation in hsv mode is nonzero. When the saturation is 0, the cached hue is set as the slider in _update_color. This is to prevent #76968 from happening.

Fixes #76968

@dinoplane dinoplane requested a review from a team as a code owner June 5, 2023 04:22
@KoBeWi KoBeWi added this to the 4.1 milestone Jun 5, 2023
@akien-mga
Copy link
Member

It seems you're a first time contributor, so welcome!

To ensure you can pass style checks from CI, we recommend running checks locally, using the tools described in https://docs.godotengine.org/en/latest/contributing/development/code_style_guidelines.html
There are notably pre-commit hooks in misc/hooks/ which you can set up locally if you want, to run checks on each commit.

Once the PR is ready, we'd typically ask you to squash the commits into one, you can see PR workflow for details.

Contributors familiar with the ColorPicker will review this as time permits.

@KoBeWi
Copy link
Member

KoBeWi commented Jun 5, 2023

Seems like this doesn't work correctly 🤔

fNb3gnZONT.mp4

The saturation bar is always red when it's 0 and changing to different color mode and back resets the hue slider. tbh I don't see any difference from the previous behavior.

Also I think the change could be done in ColorModeHSV class. We should avoid hard-coding mode-specific code in ColorPicker if possible.

@dinoplane
Copy link
Contributor Author

dinoplane commented Jun 5, 2023

Ok I shall make these changes immediately.

@dinoplane
Copy link
Contributor Author

dinoplane commented Jun 11, 2023

On second thought, I don't think its possible to completely isolate the fix in ColorModeHSV. This is because in color_picker, the slider values are updated using sliders[i]->set_value(modes[current_mode]->get_slider_value(i)); .

ColorModeHSV::get_slider_value() is a const function, which means we cannot update a cached value (that would be a member of ColorModeHSV) from there. There would need to be some intermediate function called by the color picker for HSV mode that updates the cached value of the hue.

But I'm not sure if that is a good idea if we wanted to isolate the fix in ColorModeHSV...

Update: It may be a horrible idea to add new functionality only to ColorModeHSV... so I think a hacky solution may be to store the cached hue in the ColorPicker and use that value in ColorModeHSV::get_slider_value().

@dinoplane dinoplane force-pushed the alien-color-changes branch from dfef7c1 to b33ca3e Compare June 11, 2023 12:49
@dinoplane
Copy link
Contributor Author

dinoplane commented Jun 11, 2023

I have fixed the issue with the slider color and the changing of hues when the color mode is changed. I've isolated most of the behavior in color_mode.cpp, though as I've mentioned before, it seems to be impossible to completely contain the solution there.

If someone may review my code and make sure everything is okay, that would be great ;)

scene/gui/color_mode.cpp Outdated Show resolved Hide resolved
@KoBeWi
Copy link
Member

KoBeWi commented Jun 11, 2023

ColorModeHSV::get_slider_value() is a const function, which means we cannot update a cached value (that would be a member of ColorModeHSV) from there.

You can change a member inside const function if it has mutable modifier. We do allow that for caching something.

scene/gui/color_picker.h Outdated Show resolved Hide resolved
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

Works correctly now.
The special case you added is next to another special case, so it's probably fine.

Left 2 style comments that need to be addressed.

@KoBeWi
Copy link
Member

KoBeWi commented Jun 11, 2023

You need to squash commits into 1. Also accepting changes from GitHub added me as co-author, so you need to remove that.

@dinoplane dinoplane force-pushed the alien-color-changes branch from 2842246 to 52f9e6e Compare June 11, 2023 23:06
@dinoplane
Copy link
Contributor Author

just squashed it all into one! Thank you very much!

@akien-mga akien-mga changed the title Cached hue is used for color picker when saturation is 0 Use cached hue for color picker when saturation is 0 Jun 12, 2023
@akien-mga akien-mga force-pushed the alien-color-changes branch from 52f9e6e to a374c7d Compare June 12, 2023 08:59
@akien-mga
Copy link
Member

I pushed a small update amending the commit message to make it more explicit about the bug being fixed.

@akien-mga akien-mga merged commit bcbc2fb into godotengine:master Jun 12, 2023
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

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.

Color Widget's HSV mode doesn't update the hue properly when saturation is 0.
3 participants