static void cxSpriteDirtyEvent(cxAny sender) { cxSprite this = sender; this->cbox.lb = this->cxView.color; this->cbox.rb = this->cxView.color; this->cbox.lt = this->cxView.color; this->cbox.rt = this->cxView.color; cxBox4f box = cxViewBox(this); this->vbox.lb = cxVec3fv(box.l, box.b, 0.0f); this->vbox.rb = cxVec3fv(box.r, box.b, 0.0f); this->vbox.lt = cxVec3fv(box.l, box.t, 0.0f); this->vbox.rt = cxVec3fv(box.r, box.t, 0.0f); this->tbox = this->texCoord; if(this->isFlipX){ this->tbox.lb.u = this->texCoord.rb.u; this->tbox.rb.u = this->texCoord.lb.u; this->tbox.lt.u = this->texCoord.rt.u; this->tbox.rt.u = this->texCoord.lt.u; } if(this->isFlipY){ this->tbox.lb.v = this->texCoord.lt.v; this->tbox.rb.v = this->texCoord.rt.v; this->tbox.lt.v = this->texCoord.lb.v; this->tbox.rt.v = this->texCoord.rb.v; } }
void cxAtlasUpdateScale9(cxAny pview) { cxAtlas this = pview; CX_RETURN(!this->scale9.enable); CX_ASSERT(!cxViewZeroSize(pview) && this->cxSprite.texture != NULL, "must set texture and size"); cxAtlasClean(pview); cxSize2f size = cxViewSize(this); cxRect4f tr = cxBoxTex2fToRect4f(this->cxSprite.texCoord); cxSize2f tsize = cxSize2fv(this->cxSprite.texture->size.w * tr.w, this->cxSprite.texture->size.h * tr.h); cxFloat txs[]={0.0f, this->scale9.box.l/tsize.w, (tsize.w - this->scale9.box.r)/tsize.w, 1.0f}; cxFloat tys[]={0.0f, this->scale9.box.t/tsize.h, (tsize.h - this->scale9.box.b)/tsize.h, 1.0f}; for(int i=0; i < 4; i++){ txs[i] = txs[i] * tr.w + tr.x; tys[i] = tys[i] * tr.h + tr.y; } cxFloat bxs[]={0.0f, this->scale9.box.l, size.w - this->scale9.box.r, size.w}; cxFloat bys[]={0.0f, this->scale9.box.r, size.h - this->scale9.box.b, size.h}; cxFloat tx1=0,ty1=0,tx2=0,ty2=0; cxFloat bx1=0,by1=0,bx2=0,by2=0; cxFloat offx=0,offy=0; cxColor4f color =cxViewColor(this); for(int i=0; i < 9;i++){ tx1 = txs[i%3]; tx2 = txs[i%3 + 1]; ty1 = tys[i/3]; ty2 = tys[i/3 + 1]; bx1 = bxs[i%3]; bx2 = bxs[i%3 + 1]; by1 = bys[i/3]; by2 = bys[i/3 + 1]; cxFloat hw = (bx2 - bx1)/2.0f; cxFloat hh = (by2 - by1)/2.0f; if(hw == 0 || hh == 0){ continue; } offx = (bx2 - bx1)/2.0f + bx1 - size.w/2.0f; offy = (size.h - (by2 - by1))/2.0f - by1; cxBoxPoint bp; bp.lb.colors = color; bp.lt.colors = color; bp.rb.colors = color; bp.rt.colors = color; bp.lb.vertices = cxVec3fv(-hw + offx, -hh + offy, 0.0f); bp.rb.vertices = cxVec3fv( hw + offx, -hh + offy, 0.0f); bp.lt.vertices = cxVec3fv(-hw + offx, hh + offy, 0.0f); bp.rt.vertices = cxVec3fv( hw + offx, hh + offy, 0.0f); bp.lb.texcoords = cxTex2fv(tx1, ty2); bp.rb.texcoords = cxTex2fv(tx2, ty2); bp.lt.texcoords = cxTex2fv(tx1, ty1); bp.rt.texcoords = cxTex2fv(tx2, ty1); cxAtlasAppend(this, &bp); } }
void cxAtlasSetItemPos(cxAny pview,cxInt idx,cxVec2f pos) { cxAtlas this = pview; cxBoxPoint *bp = &this->boxes[idx]; cxFloat wh = (bp->rb.vertices.x - bp->lt.vertices.x) / 2.0f; cxFloat hh = (bp->lt.vertices.y - bp->rb.vertices.y) / 2.0f; bp->lb.vertices = cxVec3fv(pos.x - wh, pos.y - hh, 0.0f); bp->lt.vertices = cxVec3fv(pos.x - wh, pos.y + hh, 0.0f); bp->rt.vertices = cxVec3fv(pos.x + wh, pos.y + hh, 0.0f); bp->rb.vertices = cxVec3fv(pos.x + wh, pos.y - hh, 0.0f); this->isDirty = true; }
CX_OBJECT_INIT(cxRotate, cxAction) { this->raxis = cxVec3fv(0.0f, 0.0f, 1.0f); cxObjectSetXMLReadFunc(this, cxRotateXMLReadAttr); CX_METHOD_SET(this->super.Init, cxRotateInit); CX_METHOD_SET(this->super.Step, cxRotateStep); }
static cxBool cxRotateXMLReadAttr(cxAny xmlAction,cxAny mAction, xmlTextReaderPtr reader) { cxActionXMLReadAttr(xmlAction, mAction, reader); cxRotate this = mAction; cxChar *sx = cxXMLAttr("cxRotate.x"); cxChar *sy = cxXMLAttr("cxRotate.y"); cxChar *sz = cxXMLAttr("cxRotate.z"); if(sx != NULL){ this->raxis = cxVec3fv(1.0f, 0.0f, 0.0f); this->newRadians = kmDegreesToRadians(atof(sx)); }else if(sy != NULL){ this->raxis = cxVec3fv(0.0f, 1.0f, 0.0f); this->newRadians = kmDegreesToRadians(atof(sy)); }else if(sz != NULL){ this->raxis = cxVec3fv(0.0f, 0.0f, 1.0f); this->newRadians = kmDegreesToRadians(atof(sz)); } xmlFree(sx); xmlFree(sy); xmlFree(sz); return true; }
cxBoxPoint cxAtlasCreateBoxPoint(cxVec2f pos,cxSize2f size,cxBoxTex2f tex,cxColor4f color) { cxBoxPoint rv; cxFloat wh = size.w/2.0f; cxFloat hh = size.h/2.0f; rv.lb.colors = color; rv.lb.texcoords = tex.lb; rv.lb.vertices = cxVec3fv(pos.x - wh, pos.y - hh, 0.0f); rv.lt.colors = color; rv.lt.texcoords = tex.lt; rv.lt.vertices = cxVec3fv(pos.x - wh, pos.y + hh, 0.0f); rv.rt.colors = color; rv.rt.texcoords = tex.rt; rv.rt.vertices = cxVec3fv(pos.x + wh, pos.y + hh, 0.0f); rv.rb.colors = color; rv.rb.texcoords = tex.rb; rv.rb.vertices = cxVec3fv(pos.x + wh, pos.y - hh, 0.0f); return rv; }
CX_OBJECT_INIT(cxView, cxObject) { this->super.cxBase = cxBaseTypeView; this->hideTop = true; this->isBorder = false; this->isVisible = true; this->isDirty = true; this->color = cxColor4fv(1.0f, 1.0f, 1.0f, 1.0f); this->size = cxSize2fv(0.0f, 0.0f); this->anchor = cxVec2fv(0.5f, 0.5f); this->raxis = cxVec3fv(0.0f, 0.0f, 1.0f); this->scale = cxVec2fv(1.0f, 1.0f); this->fixscale = cxVec2fv(1.0f, 1.0f); this->subViews = CX_ALLOC(cxList); CX_METHOD_OVERRIDE(this->IsTouch, cxViewIsTouch); CX_METHOD_OVERRIDE(this->IsOnKey, cxViewIsOnKey); cxObjectSetReadAttrFunc(this, cxViewReadAttr); this->actions = CX_ALLOC(cxHash); this->caches = CX_ALLOC(cxHash); this->removes = CX_ALLOC(cxArray); }