diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-01-11 10:36:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-11 10:36:15 +0100 |
commit | 57166cd2923cc6d32b37c34f6ca2f32f6941e4a8 (patch) | |
tree | 6ac41f0f717267a0164a869be76e941a3caeb9e9 /core/color.cpp | |
parent | bc26f905817945300d397696330d1ab04a1af33c (diff) | |
parent | 23381a530bb4a9c8e8c3e883a7d588bf832cd277 (diff) | |
download | redot-engine-57166cd2923cc6d32b37c34f6ca2f32f6941e4a8.tar.gz |
Merge pull request #7093 from bojidar-bg/named-colors
Add named colors to GDScript/Visual Script/core.
Diffstat (limited to 'core/color.cpp')
-rw-r--r-- | core/color.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/core/color.cpp b/core/color.cpp index e787282116..89accbb6d2 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -29,6 +29,8 @@ #include "color.h" #include "math_funcs.h" #include "print_string.h" +#include "map.h" +#include "color_names.inc" uint32_t Color::to_ARGB32() const { @@ -327,7 +329,25 @@ 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 + String name = p_name; + // Normalize name + name = name.replace(" ", ""); + name = name.replace("-", ""); + name = name.replace("_", ""); + name = name.replace("'", ""); + name = name.replace(".", ""); + name = name.to_lower(); + + const Map<String, Color>::Element* color = _named_colors.find(name); + if(color) { + return color->value(); + } else { + ERR_EXPLAIN("Invalid Color Name: "+p_name); + ERR_FAIL_V(Color()); + } +} String _to_hex(float p_val) { |