-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
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
Add constants for commonly used colors #61202
base: master
Are you sure you want to change the base?
Conversation
I agree on principle, but shouldn't we make named colors accessible from C++ instead? We already have a set of over 200 named colors accessible via constants in GDScript. Also, it might be worth adding named colors for "transparent black" ( |
I actually forgot that there are already named colors (and they are accesible from C++). EDIT: Adding "transparent black" and "transparent white" would definitely make sense, there are over 120 occurrences of Color(0, 0, 0, 0) and Color(1, 1, 1, 0) together. |
Could we make those actual constants with some C++ macro/template magic? I agree we should avoid strings here (even StringNames, as they don't have autocompletion and are prone to typos). |
Why are they methods instead of just |
9a4d863
to
8af8e19
Compare
8af8e19
to
2c4b389
Compare
@LightningAA Unfortunately, just using However, as I wasn't happy with it too, I changed it to the approach used by SFML (static const declaration and initialization in the implementation file). See the updated top comment for details. |
2c4b389
to
8d6d259
Compare
8d6d259
to
218131c
Compare
Why have |
@@ -90,7 +99,7 @@ struct _NO_DISCARD_ Color { | |||
|
|||
bool is_equal_approx(const Color &p_color) const; | |||
|
|||
Color clamp(const Color &p_min = Color(0, 0, 0, 0), const Color &p_max = Color(1, 1, 1, 1)) const; | |||
Color clamp(const Color &p_min = Color::TRANSPARENT_BLACK, const Color &p_max = Color(1, 1, 1, 1)) const; |
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.
The latter could be Color::WHITE
, but also I don't think it actually improves readability in this case, so I think keeping the numbers makes more sense.
@@ -2027,7 +2027,7 @@ void RasterizerSceneGLES3::render_scene(RID p_render_buffers, const CameraData * | |||
bool keep_color = false; | |||
|
|||
if (get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW) { | |||
clear_color = Color(0, 0, 0, 1); //in overdraw mode, BG should always be black | |||
clear_color = Color::BLACK; //in overdraw mode, BG should always be black |
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.
clear_color = Color::BLACK; //in overdraw mode, BG should always be black | |
clear_color = Color::BLACK; // In overdraw mode, BG should always be black. |
You could fix the comment if you are editing this.
The PR makes sense, but the list of colors is to be assessed. White color is by far the most commonly used one, but e.g. blue seems to be used 8 times. Although it's a primary color, so maybe makes sense to have it anyway, idk. Also I support the idea that transparent colors can be simply achieved with |
This PR aims to improve readability by introducing constants for the most used/basic colors (red, green, blue, white, black, transparent white and transparent black).
Color::WHITE
Color::BLACK
Color::TRANSPARENT_WHITE
Color::TRANSPARENT_BLACK
Color::RED
Color::GREEN
Color::BLUE