/** * parentMat: null -> no change * same pointer -> parent transform changed * diff pointer -> parent changed */ public static void Draw(Group *self, float *parentMat, bool isParentTransformDirty) { var childLst = &self->childLst; int childCount = childLst->count; void **childArr = childLst->arr; // sort by depth if any child depth is changed for (int i = 0; i < childCount; i += 1) { if (Node.IsDepthDirty(childArr[i])) { Algo.MergeSort(childArr, childCount, Node.DepthCmp); break; } } float *mat = self->mat; float *concatMat = self->concatMat; bool isTransformDirty = self->isTransformDirty; if (isTransformDirty) { self->isTransformDirty = false; Mat2D.FromScalingRotationTranslation(mat, self->pos, self->scl, self->rot); } if (isParentTransformDirty) { self->parentMat = parentMat; } if (isTransformDirty || isParentTransformDirty) { isParentTransformDirty = true; if (parentMat == null) { Mat2D.Copy(concatMat, mat); } else { Mat2D.Mul(concatMat, parentMat, mat); } } for (int i = 0; i < childCount; i += 1) { Node.Draw(childArr[i], concatMat, isParentTransformDirty); } }
public static void Draw(TpSprite *self, float *parentMat, bool isParentTransformDirty) { #if FDB Should.NotNull("self", self); Should.TypeEqual("self", self->type, Type); Should.NotNull("self->spriteMeta", self->spriteMeta); #endif var bat = DrawCtx.GetBatch(self->spriteMeta->atlas->name); int vertIdx = bat.vertCount, triIdx = bat.triCount; bat.RequestQuota(4, 6); float *verts = self->verts; float *uvs = self->uvs; if (self->isTransformDirty) { float *mat = stackalloc float[6]; Mat2D.FromScalingRotationTranslation(mat, self->pos, self->scl, self->rot); TpSpriteMeta.FillQuad(self->spriteMeta, mat, self->verts); } var bVerts = bat.verts; var bUvs = bat.uvs; float z = self->pos[2]; bVerts[vertIdx].Set(verts[0], verts[1], z); bVerts[vertIdx + 1].Set(verts[2], verts[3], z); bVerts[vertIdx + 2].Set(verts[4], verts[5], z); bVerts[vertIdx + 3].Set(verts[6], verts[7], z); bUvs[vertIdx].Set(uvs[0], uvs[1]); bUvs[vertIdx + 1].Set(uvs[2], uvs[3]); bUvs[vertIdx + 2].Set(uvs[4], uvs[5]); bUvs[vertIdx + 3].Set(uvs[6], uvs[7]); float *color = self->color; var bColor = Vec4.Color(color, 0.5f); var bColors = bat.colors; bColors[vertIdx] = bColor; bColors[vertIdx + 1] = bColor; bColors[vertIdx + 2] = bColor; bColors[vertIdx + 3] = bColor; var bTris = bat.tris; bTris[triIdx] = vertIdx; bTris[triIdx + 1] = vertIdx + 1; bTris[triIdx + 2] = vertIdx + 2; bTris[triIdx + 3] = vertIdx; bTris[triIdx + 4] = vertIdx + 2; bTris[triIdx + 5] = vertIdx + 3; }
public virtual void CacheTransform() { transformDirty = false; bool useParentSize = parent != null && parent.useLayout; if (useParentSize) { cachedPos = Axes.Calc(relativePosAxes, pos, parent.cachedSize); cachedSize = Axes.Calc(relativeSizeAxes, size, parent.cachedSize); } else { cachedPos = Axes.Calc(relativePosAxes, pos); cachedSize = Axes.Calc(relativeSizeAxes, size); } if (useLayout) { cachedPivot = cachedSize * Align.Calc(pivotAlign, customPivotAlign); cachedPos.x += margin.l; cachedPos.y += margin.b; cachedSize.x -= margin.l + margin.r; cachedSize.y -= margin.b + margin.t; cachedMat.FromTranslation(-cachedPivot); cachedMat.ScaleRotateTranslate(scl, rot, cachedPos); } else { cachedMat.FromScalingRotationTranslation(scl, rot, cachedPos); } if (useParentSize) { cachedAnchor = parent.cachedSize * Align.Calc(anchorAlign, customAnchorAlign); cachedMat.Translate(cachedAnchor); } cachedMatConcat = parent == null ? cachedMat : parent.cachedMatConcat * cachedMat; if (needMatConcatInverse) { cachedMatConcatInverse.FromInverse(cachedMatConcat); } if (needScreenAabb) { cachedScreenAabb = (cachedMatConcat * new Quad(0, 0, cachedSize.x, cachedSize.y)).GetAabb(); } }