-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Refactor of ColorPicker #62075
Refactor of ColorPicker #62075
Conversation
ba983e2
to
a84ac3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some suggestions 😃
(the comment above was meant to be part of these but I accidentally hit add single comment :/ )
scene/gui/color_picker.cpp
Outdated
} | ||
|
||
HSlider **ColorPicker::get_sliders() { | ||
HSlider **hs = new HSlider *[5]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there's a way to avoid allocating memory on the heap, theoretically if it's just returning 5 pointers, then it shouldn't need to. Probably doesn't matter that much though.
Docs are failing because you need to update the class reference: https://docs.godotengine.org/en/stable/community/contributing/updating_the_class_reference.html#updating-the-documentation-template |
Thanks, will apply them :) |
a84ac3b
to
47a4c0c
Compare
For |
scene/gui/color_picker.cpp
Outdated
|
||
Ref<StyleBoxEmpty> style_box_empty(memnew(StyleBoxEmpty)); | ||
|
||
for (int i = 0; i < 4; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard coded, suggest using current_sliders_count
instead of 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to apply to all sliders. It could use a constant though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, it can be 4
, and there is no need to write the following alpha_scroll
separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alpha_scroll
is actually separate from the 4 sliders.
The 4th slider is unused for now. It's potentially useful for CMYK or other color mode with more sliders (if there is any...). Although maybe it could be removed for now 🤔 This would be trivial if 4 was a constant not hard-coded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's better to use current_sliders_count
, which is reset according to the mode in ColorPicker::_update_controls
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I define a constant with 3 as its value? we will change it to 4 in future if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alpha_scroll
is actually separate from the 4 sliders. The 4th slider is unused for now. It's potentially useful for CMYK or other color mode with more sliders (if there is any...). Although maybe it could be removed for now 🤔 This would be trivial if 4 was a constant not hard-coded.
What if element 0 was always used for the alpha slider, and then all the code duplication with the other sliders and the alpha slider wouldn't be necessary? Would that work? 🤔
scene/gui/color_picker.h
Outdated
const int HSV_MODE_INDEX = 1; | ||
const int OKHSL_MODE_INDEX = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't exist. Any code related to specific color modes should be handled by these modes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are checks for color mode being HSV or OKHSL in _w_input
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but this is more related to shapes than color modes. Maybe it's possible to handle it more nicely.
scene/gui/color_picker.cpp
Outdated
|
||
if (mode_option_button->get_selected() == HSV_MODE_INDEX || mode_option_button->get_selected() == OKHSL_MODE_INDEX) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this condition necessary?
You can set h/s/v even for modes that don't need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this as it was checking for HSV mode previously but the call to _set_pick_color
will do this anyway. Will remove this condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I looked through the code. Not all of it, but:
|
This will be done in a follow-up PR.
It was briefly discussed in #31679, but didn't gain much interest. |
Thanks for the review, will fix these bugs :) |
Is this still needs to done even if the OptionButton to change shape will be added?
Not able to reproduce this, am I doing something wrong?
This was happening before too, but I will see if I can fix this. |
eeba57f
to
67fbd7c
Compare
Yes I think so, because OKHSV only works with the circle shape. I'd expect that the shape would be temporarily overridden while in OKHSV mode and then go back whenever switching to another mode. If an OptionButton for changing shape is added, then the button should probably be
Ok, I'll try to figure out how to reproduce it. Maybe it only happens under certain conditions? |
I noticed that when you set picker shape to OKHSL circle and color mode to OKHSL in a ColorPicker node and then start the project, the picker will change to square when you change color mode at runtime. The problem is property order. Color mode comes before picker shape, so when ColorPicker is created, it assumes the square mode to be "last_shape". So setting picker shape has no effect. I see two solutions to this:
|
I looked through the whole code and aside from some comments I left (especially the one about |
In constructor of ColorPicker we were doing |
Unfortunately using |
ec38f9d
to
bc372f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there are no major problems left. Aside from the comments I just left, some details can still be improved later.
38cb759
to
bf1faf3
Compare
Last thing you'll probably want to do is squash the commits :) |
bf1faf3
to
0011d93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Thanks! |
This PR covers the refactoring part of Refactor and UX Updates of ColorPicker GSoC'22 project with @akien-mga and @KoBeWi as mentors. The original proposal for refactoring can be found here and the wireframes for UX updates can be found here.