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

Add named colors to GDScript/Visual Script/core. #7093

Merged
merged 1 commit into from
Jan 11, 2017

Conversation

bojidar-bg
Copy link
Contributor

@bojidar-bg bojidar-bg commented Nov 10, 2016

Color names and values shamelessly stolen from @SuperUserNameMan...
Now from https://en.wikipedia.org/wiki/X11_color_names

Closes #6195!

@@ -0,0 +1,1230 @@
// Names from https://en.wikipedia.org/wiki/List_of_colors (through https://raw.githubusercontent.com/SuperUserNameMan/color_to_name/616a7cddafefda91478b7bc26167de97fb5badb1/godot_version.gd), slightly edited and normalized
static Map<String, Color> _named_colors;
static void _populate_named_colors() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dragons be here.

_named_colors.insert("pastelviolet", Color(0.80, 0.60, 0.79 ));
_named_colors.insert("pastelyellow", Color(0.99, 0.99, 0.59 ));
_named_colors.insert("patriarch", Color(0.50, 0.00, 0.50 ));
_named_colors.insert("payne'sgrey", Color(0.33, 0.41, 0.47 ));
Copy link
Contributor

Choose a reason for hiding this comment

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

is this OK using ' for color name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bla... seems like my grepping/sedding skills failed me!

_named_colors.insert("cinereous", Color(0.60, 0.51, 0.48 ));
_named_colors.insert("cinnabar", Color(0.89, 0.26, 0.20 ));
_named_colors.insert("cinnamonsatin", Color(0.80, 0.38, 0.49 ));
_named_colors.insert("cinnamon[citationneeded]", Color(0.82, 0.41, 0.12 ));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@volzhs That's a better example though.

@@ -327,7 +329,24 @@ bool Color::html_is_valid(const String& p_color) {

}


Color Color::named(const String &p_name) {
if(_named_colors.empty()) _populate_named_colors(); // from color_names.inc
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance to use space after if? I hope in 3.0 there will be some codestyle enforced. In other files you're using this space after if...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, probably missed adding it.

name = name.to_lower();
const Map<String, Color>::Element* color = _named_colors.find(name);
if(color) {
return color->value();
Copy link
Contributor

Choose a reason for hiding this comment

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

if (color)...

static Map<String, Color> _named_colors;
static void _populate_named_colors() {
if(!_named_colors.empty()) return;
_named_colors.insert("absolutezero", Color(0.00, 0.28, 0.73 ));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think almost all of these colors should be thrown away and replaced by HTML ones. I found info that all modern browsers support about 140 common colors. I don't think that "awsome", "absolutezero" (no, that's not 0,0,0) or "maximumgreen" with green set to 55 percent is good choice. So maybe use these 140 standard ones instead of 1200+?

Copy link
Member

Choose a reason for hiding this comment

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

I also agree that only the HTML colors should be kept. The intention is to make it more user-friendly. Using ColorN('fuzzywuzzy') won't help with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, ... would fix it some time later

@@ -64,6 +64,7 @@ const char* VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
"str2var",
"var2bytes",
"bytes2var",
"color_named",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like leaving comma after the last element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a comma on the previous last element, so I followed the style. I'm not changing it since "you don't like it", sorry (but, feel free to fix it everywhere when refactoring starts).

Copy link
Member

@akien-mga akien-mga Nov 22, 2016

Choose a reason for hiding this comment

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

I think it's good style to keep a comma after the last element. Then when you add an element, you do a 0,+1 change and not a -1,+2.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a bad habit, as long as it compiles it can be left as is, but imagine you also add commas after last function param just because it's possible that you'll add an argument in future...
JSON forbids such syntax and I think it's good.
Commas should be used to separate elements and there is no element to be separated at the end.
Code should be as readible as possible and this -1, +2 is not a problem as review of such a change is trivial.
I should not use so many shoulds in my post. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pkowal1982 Or maybe, we should use the elm-lang approach?

something =
{ "1"
, "2"
, "3"
};

That way we both have no trailing commas, and we don't have a -1+2 change..

Copy link
Contributor

Choose a reason for hiding this comment

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

Just leave this comma as it is and shorten the list of colors. :)


Color color = Color::named(*p_inputs[0]);
color.a=*p_inputs[1];

Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes you use spaces around equity sign and sometimes you do not. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, @akien-mga would fix them anyway 😛

Anyway, that's done like so everywhere in the code -- spaces around declarations of new variables only, so decided to follow that one for the case... 😄

@akien-mga
Copy link
Member

I'd also be for reducing the list of colors to a smaller list of a hundred or so. 1200+ colors with names noone understands don't bring us any closer to being user friendly - best let people check a color directory on the Internet and use the HTML codes if they need a very specific color.

@SuperUserNameMan
Copy link
Contributor

SuperUserNameMan commented Nov 26, 2016

@bojidar-bg : I also think that this list of colors names you picked from my experimental test project is really too long to be included as is into Godot.

Also, I'm wondering if such addon could not just be implemented as a simple asset script instead of being made default to Godot core. (edit : though, as you mentioned the Visual scripting thing, maybe it could not be implemented as an asset anyway ........)

@bojidar-bg
Copy link
Contributor Author

@SuperUserNameMan I see no problem for it to be in core...
About the length of the color list, I'm going to revise this PR one day...... (.....)

@bojidar-bg
Copy link
Contributor Author

Ok, @akien-mga I revised the list (using colors from https://en.wikipedia.org/wiki/X11_color_names). 😄

@akien-mga akien-mga merged commit 57166cd into godotengine:master Jan 11, 2017
@bojidar-bg bojidar-bg deleted the named-colors branch March 30, 2017 10:39
@aaronfranke
Copy link
Member

Could a similar strategy, using .insert(), be used for creating default Vectors? #7317

@bojidar-bg
Copy link
Contributor Author

bojidar-bg commented Jul 9, 2018

Not really, since it is currently implemented as another Color constructor + GDScript/VSScript function.

@aaronfranke aaronfranke added this to the 3.0 milestone Jan 26, 2020
@Vivraan
Copy link
Contributor

Vivraan commented Aug 3, 2020

Please make these follow UPPERCASE_NAMING.

@aaronfranke
Copy link
Member

@SHIVAMMUKHERJEE Thanks for the reminder, I plan to make a PR proposing replacing Color.red with Colors.RED, but I haven't gotten around to doing this yet. I just added this to my TODO list.

@Vivraan
Copy link
Contributor

Vivraan commented Aug 4, 2020

How hard could it be? I'll put this on TODO as well.

@Vivraan
Copy link
Contributor

Vivraan commented Aug 4, 2020

@aaronfranke some colours names are incorrect, such as "cornflower" instead of "cornflowerblue" and a lot of C# constants aren't named according to the Wikipedia names. I've fixed these in one commit.

How have the constants been placed under Colors? I simply can't find anywhere the Godot constants have been derived from.

@Vivraan
Copy link
Contributor

Vivraan commented Aug 4, 2020

I've made a PR for some incorrectly named color constants on both C++ and C#, but I can't wrap my head around how the color names get added to the GDScript Color description.

#41019

@bojidar-bg
Copy link
Contributor Author

Please make these follow UPPERCASE_NAMING.

Necro-bumping a 2 year old PR, when an issue (or a proposal) can explain the problem better is generally not considered a good practice.

This aside, it would be better if such a comment is directed at #14704 (comment), not here, as this PR did not add Color.red, just the older ColorN("red").

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.

Suggestion : add predefined colors
9 participants