-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:
parent
6b1849d29b
commit
37f2222dd7
|
@ -1352,6 +1352,22 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
|
|||
valid=true;
|
||||
v->set_hsv(v->get_h(),v->get_s(),p_value);
|
||||
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) {
|
||||
|
||||
|
@ -2195,6 +2211,18 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
|
|||
} else if (*str=="v" ) {
|
||||
valid=true;
|
||||
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) {
|
||||
|
||||
|
@ -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,"s"));
|
||||
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;
|
||||
case IMAGE: { } break;
|
||||
|
|
|
@ -98,6 +98,7 @@ const char *GDFunctions::get_func_name(Function p_func) {
|
|||
"load",
|
||||
"inst2dict",
|
||||
"dict2inst",
|
||||
"Color8",
|
||||
"hash",
|
||||
"print_stack",
|
||||
"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);
|
||||
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;
|
||||
|
||||
case PRINT_STACK: {
|
||||
|
@ -1017,6 +1045,7 @@ bool GDFunctions::is_deterministic(Function p_func) {
|
|||
case TYPE_CONVERT:
|
||||
case TYPE_OF:
|
||||
case TEXT_STR:
|
||||
case COLOR8:
|
||||
// enable for debug only, otherwise not desirable - case GEN_RANGE:
|
||||
return true;
|
||||
default:
|
||||
|
@ -1360,6 +1389,12 @@ MethodInfo GDFunctions::get_info(Function p_func) {
|
|||
mi.return_val.type=Variant::INT;
|
||||
return mi;
|
||||
} 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: {
|
||||
MethodInfo mi("print_stack");
|
||||
|
|
|
@ -94,6 +94,7 @@ public:
|
|||
INST2DICT,
|
||||
DICT2INST,
|
||||
HASH,
|
||||
COLOR8,
|
||||
PRINT_STACK,
|
||||
INSTANCE_FROM_ID,
|
||||
FUNC_MAX
|
||||
|
|
Loading…
Reference in New Issue