-Added Color8(r8,g8,b8,a8) function as well as .r8,.g8,.b8,.a8 members to Color, to deal with colors in the 0-255 range. Closes #2345

This commit is contained in:
Juan Linietsky 2015-12-31 18:26:49 -03:00
parent 6b1849d29b
commit 37f2222dd7
3 changed files with 68 additions and 0 deletions

View File

@ -1352,6 +1352,22 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
valid=true; valid=true;
v->set_hsv(v->get_h(),v->get_s(),p_value); v->set_hsv(v->get_h(),v->get_s(),p_value);
return; return;
} else if (*str=="r8" ) {
valid=true;
v->g=float(p_value)/255.0;
return;
} else if (*str=="g8" ) {
valid=true;
v->g=float(p_value)/255.0;
return;
} else if (*str=="b8" ) {
valid=true;
v->b=float(p_value)/255.0;
return;
} else if (*str=="a8" ) {
valid=true;
v->a=float(p_value)/255.0;
return;
} }
} else if (p_index.get_type()==Variant::INT) { } else if (p_index.get_type()==Variant::INT) {
@ -2195,6 +2211,18 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
} else if (*str=="v" ) { } else if (*str=="v" ) {
valid=true; valid=true;
return v->get_v(); return v->get_v();
} else if (*str=="r8") {
valid=true;
return v->r*255.0;
} else if (*str=="g8" ) {
valid=true;
return v->g*255.0;
} else if (*str=="b8" ) {
valid=true;
return v->b*255.0;
} else if (*str=="a8" ) {
valid=true;
return v->a*255.0;
} }
} else if (p_index.get_type()==Variant::INT) { } else if (p_index.get_type()==Variant::INT) {
@ -2866,6 +2894,10 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back( PropertyInfo(Variant::REAL,"h")); p_list->push_back( PropertyInfo(Variant::REAL,"h"));
p_list->push_back( PropertyInfo(Variant::REAL,"s")); p_list->push_back( PropertyInfo(Variant::REAL,"s"));
p_list->push_back( PropertyInfo(Variant::REAL,"v")); p_list->push_back( PropertyInfo(Variant::REAL,"v"));
p_list->push_back( PropertyInfo(Variant::INT,"r8"));
p_list->push_back( PropertyInfo(Variant::INT,"g8"));
p_list->push_back( PropertyInfo(Variant::INT,"b8"));
p_list->push_back( PropertyInfo(Variant::INT,"a8"));
} break; } break;
case IMAGE: { } break; case IMAGE: { } break;

View File

@ -98,6 +98,7 @@ const char *GDFunctions::get_func_name(Function p_func) {
"load", "load",
"inst2dict", "inst2dict",
"dict2inst", "dict2inst",
"Color8",
"hash", "hash",
"print_stack", "print_stack",
"instance_from_id", "instance_from_id",
@ -937,6 +938,33 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_COUNT(1); VALIDATE_ARG_COUNT(1);
r_ret=p_args[0]->hash(); r_ret=p_args[0]->hash();
} break;
case COLOR8: {
if (p_arg_count<3) {
r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument=3;
return;
}
if (p_arg_count>4) {
r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
r_error.argument=4;
return;
}
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
Color color(*p_args[0],*p_args[1],*p_args[2]);
if (p_arg_count==4) {
VALIDATE_ARG_NUM(3);
color.a=*p_args[3];
}
r_ret=color;
} break; } break;
case PRINT_STACK: { case PRINT_STACK: {
@ -1017,6 +1045,7 @@ bool GDFunctions::is_deterministic(Function p_func) {
case TYPE_CONVERT: case TYPE_CONVERT:
case TYPE_OF: case TYPE_OF:
case TEXT_STR: case TEXT_STR:
case COLOR8:
// enable for debug only, otherwise not desirable - case GEN_RANGE: // enable for debug only, otherwise not desirable - case GEN_RANGE:
return true; return true;
default: default:
@ -1360,6 +1389,12 @@ MethodInfo GDFunctions::get_info(Function p_func) {
mi.return_val.type=Variant::INT; mi.return_val.type=Variant::INT;
return mi; return mi;
} break; } break;
case COLOR8: {
MethodInfo mi("Color8",PropertyInfo(Variant::INT,"r8"),PropertyInfo(Variant::INT,"g8"),PropertyInfo(Variant::INT,"b8"),PropertyInfo(Variant::INT,"a8"));
mi.return_val.type=Variant::COLOR;
return mi;
} break;
case PRINT_STACK: { case PRINT_STACK: {
MethodInfo mi("print_stack"); MethodInfo mi("print_stack");

View File

@ -94,6 +94,7 @@ public:
INST2DICT, INST2DICT,
DICT2INST, DICT2INST,
HASH, HASH,
COLOR8,
PRINT_STACK, PRINT_STACK,
INSTANCE_FROM_ID, INSTANCE_FROM_ID,
FUNC_MAX FUNC_MAX