summaryrefslogtreecommitdiffstats
path: root/core/color.cpp
diff options
context:
space:
mode:
authorBojidar Marinov <bojidar.marinov.bg@gmail.com>2016-11-10 23:06:00 +0200
committerBojidar Marinov <bojidar.marinov.bg@gmail.com>2016-12-17 11:14:53 +0200
commit23381a530bb4a9c8e8c3e883a7d588bf832cd277 (patch)
treed05a019bc06ad68c00f4d30cd1c18642b0e74782 /core/color.cpp
parent7d1230a266f4eab3262ebfcbf4a89148dfcb3c48 (diff)
downloadredot-engine-23381a530bb4a9c8e8c3e883a7d588bf832cd277.tar.gz
Add named colors to GDScript/Visual Script/core.
Names and values taken from https://en.wikipedia.org/wiki/X11_color_names
Diffstat (limited to 'core/color.cpp')
-rw-r--r--core/color.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/core/color.cpp b/core/color.cpp
index bf9c94462f..532c1bd1c2 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) {