void cxSpriteSetTextureAttr(cxAny pview,cxTextureAttr attr) { CX_RETURN(attr == NULL); cxSpriteSetTexture(pview, attr->texture); cxSpriteSetBoxTex(pview, attr->box); // if(cxViewZeroSize(pview)){ cxViewSetSize(pview, attr->size); } }
static void cxViewRootReadRectToView(cxReaderAttrInfo *info) { cxView this = info->object; cxVec2f pos = cxXMLReadVec2fAttr(info, "cxView.position", this->position); pos.x = cxXMLReadFloatAttr(info, "cxView.x", pos.x); pos.y= cxXMLReadFloatAttr(info, "cxView.y", pos.y); cxViewSetPos(this, pos); cxViewSetOrder(this, cxXMLReadIntAttr(info, "cxView.z", this->zorder)); cxSize2f size = cxXMLReadSize2fAttr(info, "cxView.size", this->size); size.w = cxXMLReadFloatAttr(info, "cxView.w", size.w); size.h = cxXMLReadFloatAttr(info, "cxView.h", size.h); cxViewSetSize(this, size); }
static cxInt cxEventSetView(lua_State *L) { CX_LUA_DEF_THIS(cxView); cxConstChars viewid = NULL; lua_getfield(L, 2, "view"); if(lua_isstring(L, -1)){ viewid = lua_tostring(L, -1); } lua_pop(L, 1); cxView pview = cxViewRootGet(this, viewid); CX_RETURN(pview == NULL, 0); lua_getfield(L, 2, "scale"); if(lua_isstring(L, -1)){ cxVec2f vscale = pview->scale; cxReadFloats(lua_tostring(L, -1), &vscale.x); cxViewSetScale(pview, vscale); } lua_pop(L, 1); lua_getfield(L, 2, "size"); if(lua_isstring(L, -1)){ cxSize2f vsize = pview->size; cxReadFloats(lua_tostring(L, -1), &vsize.w); cxViewSetSize(pview, vsize); } lua_pop(L, 1); lua_getfield(L, 2, "position"); if(lua_isstring(L, -1)){ cxVec2f vposition = pview->position; cxReadFloats(lua_tostring(L, -1), &vposition.x); cxViewSetPos(pview, vposition); } lua_pop(L, 1); lua_getfield(L, 2, "degress"); if(lua_isnumber(L, -1)){ cxViewSetDegrees(pview, lua_tonumber(L, -1)); } lua_pop(L, 1); lua_getfield(L, 2, "anchor"); if(lua_isstring(L, -1)){ cxVec2f vanchor = pview->anchor; cxReadFloats(lua_tostring(L, -1), &vanchor.x); cxViewSetAnchor(pview, vanchor); } lua_pop(L, 1); return 0; }
void cxSpriteSetTextureKey(cxAny pview,cxConstChars key,cxBool equSize) { cxSprite this = pview; if(this->texture == NULL){ cxTexture texture = cxTextureFactoryLoadFile(key); cxSpriteSetTexture(pview, texture); }else{ this->texCoord = cxTextureBox(this->texture, key); } CX_ASSERT(this->texture != NULL, "sprite texture not load"); if(equSize){ cxViewSetSize(pview, cxTextureSize(this->texture, key)); } this->cxView.isDirty = true; }
static cxInt cxViewLuaSetSize(lua_State *L) { cxInt top = lua_gettop(L); CX_LUA_DEF_THIS(cxView); cxSize2f size = this->size; if(lua_istable(L, 2)){ size = cxLuaSize2fValue(L, 2, this->size); }else if(top == 3){ size.w = luaL_checknumber(L, 2); size.h = luaL_checknumber(L, 3); }else{ luaL_error(L, "args error"); } cxViewSetSize(this, size); lua_pushvalue(L, 1); return 1; }
void cxSpriteSetTextureURL(cxAny pview,cxConstChars url,cxBool useTexSize) { CX_RETURN(url == NULL); cxSprite this = pview; cxUrlPath path = cxUrlPathParse(url); CX_RETURN(path == NULL); cxTexture texture = cxTextureFactoryLoadFile(path->path); CX_ASSERT(texture != NULL, "texture load failed %s",path->path); cxSpriteSetTexture(this, texture); //use texture size cxBool uts = useTexSize; if(path->count > 1){ cxSpriteSetTextureKey(this, path->key, uts); }else if(uts){ cxViewSetSize(this, texture->size); } }
static cxInt cxViewLuaMake(lua_State *L) { CX_LUA_CREATE_THIS(cxView); if(!lua_istable(L, 1)){ CX_LUA_RET_THIS(cxView); } cxVec2f pos = this->position; lua_getfield(L, 1, "x"); if(lua_isnumber(L, -1)){ pos.x = lua_tonumber(L, -1); } lua_pop(L, 1); lua_getfield(L, 1, "y"); if(lua_isnumber(L, -1)){ pos.y = lua_tonumber(L, -1); } lua_pop(L, 1); cxViewSetPos(this, pos); cxSize2f size = this->size; lua_getfield(L, 1, "w"); if(lua_isnumber(L, -1)){ size.w = lua_tonumber(L, -1); } lua_pop(L, 1); lua_getfield(L, 1, "h"); if(lua_isnumber(L, -1)){ size.h = lua_tonumber(L, -1); } lua_pop(L, 1); cxViewSetSize(this, size); CX_LUA_RET_THIS(cxView); }
void cxEngineLayout(cxInt width,cxInt height) { CX_LOGGER("openGL layout width=%d height=%d",width,height); cxEngine engine = cxEngineInstance(); engine->winsize = cxSize2fv(width, height); cxViewSetSize(engine->window, engine->winsize); if(!cxSize2Zero(engine->dessize)){ engine->scale = cxVec2fv(engine->winsize.w/engine->dessize.w, engine->winsize.h/engine->dessize.h); } // if(!engine->isInit){ cxOpenGLCheckFeature(); cxEngineMain(engine); } // cxFloat zeye = engine->winsize.h / 1.1566f; kmMat4 perspective={0}; kmGLMatrixMode(KM_GL_PROJECTION); kmGLLoadIdentity(); // kmMat4PerspectiveProjection(&perspective, 60.0f, engine->winsize.w / engine->winsize.h, 0.0f, zeye * 2); kmGLMultMatrix(&perspective); kmGLMatrixMode(KM_GL_MODELVIEW); kmGLLoadIdentity(); // cxOpenGLViewport(cxBox4fv(0, engine->winsize.w, 0, engine->winsize.h)); // cxMatrix4f matrix; cxEngineLookAt(&matrix,cxVec2fv(0, 0)); kmGLMultMatrix(&matrix); // engine->lastTime = cxTimestamp(); if(!engine->isInit){ cxViewEnter(engine->window); } cxViewLayout(engine->window); engine->isInit = true; }