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

Increase precision of RAW mode in ColorPicker #83851

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scene/gui/color_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ColorMode {

virtual int get_slider_count() const { return 3; };
virtual float get_slider_step() const = 0;
virtual float get_spinbox_arrow_step() const { return get_slider_step(); };
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also be const = 0;

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking it should have a default value so that individual color modes aren't required to implement this method.

Copy link
Contributor

@aXu-AP aXu-AP Oct 23, 2023

Choose a reason for hiding this comment

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

0 is the default value for SpinBox.custom_arrow_step, it will be ignored. From docs:

float custom_arrow_step = 0.0
If not 0, value will always be rounded to a multiple of custom_arrow_step when interacting with the arrow buttons of the SpinBox.

But defining it explicitly doesn't hurt either, I'm happy either way 🙂

virtual String get_slider_label(int idx) const = 0;
virtual float get_slider_max(int idx) const = 0;
virtual float get_slider_value(int idx) const = 0;
Expand Down Expand Up @@ -109,7 +110,8 @@ class ColorModeRAW : public ColorMode {

virtual String get_name() const override { return "RAW"; }

virtual float get_slider_step() const override { return 0.01; }
virtual float get_slider_step() const override { return 0.001; }
virtual float get_spinbox_arrow_step() const override { return 0.01; }
virtual String get_slider_label(int idx) const override;
virtual float get_slider_max(int idx) const override;
virtual float get_slider_value(int idx) const override;
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,11 @@ void ColorPicker::_update_color(bool p_update_sliders) {

if (p_update_sliders) {
float step = modes[current_mode]->get_slider_step();
float spinbox_arrow_step = modes[current_mode]->get_spinbox_arrow_step();
for (int i = 0; i < current_slider_count; i++) {
sliders[i]->set_max(modes[current_mode]->get_slider_max(i));
sliders[i]->set_step(step);
values[i]->set_custom_arrow_step(spinbox_arrow_step);
sliders[i]->set_value(modes[current_mode]->get_slider_value(i));
}
alpha_slider->set_max(modes[current_mode]->get_slider_max(current_slider_count));
Expand Down