Esempio n. 1
0
//{"x":0,"y":0}
cxVec2f cxJsonToVec2f(cxJson json,cxVec2f dv)
{
    CX_ASSERT_THIS(json, cxJson);
    this = cxJsonParseRegisterValue(this);
    if(cxJsonIsNumber(this) || cxJsonIsStr(this)){
        dv.x = cxJsonToDouble(this, dv.x);
        dv.y = cxJsonToDouble(this, dv.y);
    }else{
        dv.x = cxJsonDouble(this, "x", dv.x);
        dv.y = cxJsonDouble(this, "y", dv.y);
    }
    return dv;
}
Esempio n. 2
0
//{"w":0,"h":0}
cxSize2f cxJsonToSize2f(cxJson json,cxSize2f dv)
{
    CX_ASSERT_THIS(json, cxJson);
    this = cxJsonParseRegisterValue(this);
    if(cxJsonIsNumber(this) || cxJsonIsStr(this)){
        dv.w = cxJsonToDouble(this, dv.w);
        dv.h = cxJsonToDouble(this, dv.h);
    }else{
        dv.w = cxJsonDouble(this, "w", dv.w);
        dv.h = cxJsonDouble(this, "h", dv.h);
    }
    return dv;
}
Esempio n. 3
0
/*
 {
    "func":"timeConvert",
    "args":60
 }
 
 {
    "func":"timeConvert",
    "args":[1,3,4,5]
 }
 */
static cxConstChars jsonStrConvert(json_t *v)
{
    cxJson json = cxJsonReference(v);
    cxStr txt = cxJsonDump(json);
    cxConstChars funcName = cxJsonConstChars(json, "func");
    if(!cxConstCharsOK(funcName)){
        return cxStrBody(txt);
    }
    cxConvert convert = cxGetConvert(funcName);
    if(convert == NULL){
        return cxStrBody(txt);
    }
    CX_ASSERT(convert->func != NULL, "convert error");
    cxStr ret = NULL;
    cxJson args = cxJsonAny(json, "args");
    if(args == NULL){
        ret = ((cxStr (*)(void))convert->func)();
    }else if(cxJsonIsStr(args)){
        cxConstChars a1 = cxJsonToConstChars(args);
        ret = ((cxStr (*)(cxConstChars))convert->func)(a1);
    }else if(cxJsonIsInt(args)){
        cxInt a1 = cxJsonToInt(args, 0);
        ret = ((cxStr (*)(cxInt))convert->func)(a1);
    }else if(cxJsonIsDouble(args)){
        cxDouble a1 = cxJsonToDouble(args, 0);
        ret = ((cxStr (*)(cxDouble))convert->func)(a1);
    }else if(cxJsonIsBool(args)){
        cxBool a1 = cxJsonToBool(args, false);
        ret = ((cxStr (*)(cxBool))convert->func)(a1);
    }else{
        ret = ((cxStr (*)(cxJson))convert->func)(args);
    }
    return ret == NULL ? NULL : cxStrBody(ret);
}
Esempio n. 4
0
CX_SETTER_DEF(cxTimeLine, times)
{
    cxJson times = cxJsonToArray(value);
    CX_JSON_ARRAY_EACH_BEG(times, item)
    {
        cxFloat time = cxJsonToDouble(item, -1);
        CX_CONTINUE(time < 0);
        cxTimeLineSet(this, time);
    }
Esempio n. 5
0
CX_SETTER_DEF(cxButton, movement)
{
    this->movement = cxJsonToDouble(value, this->movement);
}