summaryrefslogtreecommitdiff
path: root/modules/gdscript
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 /modules/gdscript
parent7d1230a266f4eab3262ebfcbf4a89148dfcb3c48 (diff)
Add named colors to GDScript/Visual Script/core.
Names and values taken from https://en.wikipedia.org/wiki/X11_color_names
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gd_functions.cpp37
-rw-r--r--modules/gdscript/gd_functions.h1
2 files changed, 38 insertions, 0 deletions
diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp
index d3f7dcd35f..e4add4e574 100644
--- a/modules/gdscript/gd_functions.cpp
+++ b/modules/gdscript/gd_functions.cpp
@@ -105,6 +105,7 @@ const char *GDFunctions::get_func_name(Function p_func) {
"dict2inst",
"hash",
"Color8",
+ "ColorN",
"print_stack",
"instance_from_id",
};
@@ -1061,6 +1062,36 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
r_ret=color;
} break;
+ case COLORN: {
+
+ if (p_arg_count<1) {
+ r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument=1;
+ r_ret=Variant();
+ return;
+ }
+
+ if (p_arg_count>2) {
+ r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.argument=2;
+ r_ret=Variant();
+ return;
+ }
+
+ if (p_args[0]->get_type()!=Variant::STRING) {
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument=0;
+ r_ret=Variant();
+ } else {
+ Color color = Color::named(*p_args[0]);
+ if (p_arg_count==2) {
+ VALIDATE_ARG_NUM(1);
+ color.a=*p_args[1];
+ }
+ r_ret=color;
+ }
+
+ } break;
case PRINT_STACK: {
@@ -1522,6 +1553,12 @@ MethodInfo GDFunctions::get_info(Function p_func) {
mi.return_val.type=Variant::COLOR;
return mi;
} break;
+ case COLORN: {
+
+ MethodInfo mi("ColorN",PropertyInfo(Variant::STRING,"name"),PropertyInfo(Variant::REAL,"alpha"));
+ mi.return_val.type=Variant::COLOR;
+ return mi;
+ } break;
case PRINT_STACK: {
MethodInfo mi("print_stack");
diff --git a/modules/gdscript/gd_functions.h b/modules/gdscript/gd_functions.h
index f444bb3b5b..5c8b61db37 100644
--- a/modules/gdscript/gd_functions.h
+++ b/modules/gdscript/gd_functions.h
@@ -99,6 +99,7 @@ public:
DICT2INST,
HASH,
COLOR8,
+ COLORN,
PRINT_STACK,
INSTANCE_FROM_ID,
FUNC_MAX