public void InsertChild(CCSprite pobSprite, int uIndex) { pobSprite.BatchNode = this; pobSprite.AtlasIndex = uIndex; pobSprite.Dirty = true; if (m_pobTextureAtlas.TotalQuads == m_pobTextureAtlas.Capacity) { IncreaseAtlasCapacity(); } m_pobTextureAtlas.InsertQuad(ref pobSprite.m_sQuad, uIndex); m_pobDescendants.Insert(uIndex, pobSprite); // update indices CCSprite[] delements = m_pobDescendants.Elements; for (int i = uIndex + 1, count = m_pobDescendants.count; i < count; i++) { delements[i].AtlasIndex++; } // add children recursively CCRawList <CCNode> pChildren = pobSprite.Children; if (pChildren != null && pChildren.count > 0) { CCNode[] elements = pChildren.Elements; for (int j = 0, count = pChildren.count; j < count; j++) { var pChild = (CCSprite)elements[j]; uIndex = AtlasIndexForChild(pChild, pChild.ZOrder); InsertChild(pChild, uIndex); } } }
/// <summary> /// Inserts a Quad (texture, vertex and color) at a certain index /// index must be between 0 and the atlas capacity - 1 /// @since v0.8 /// </summary> public void InsertQuad(ref CCV3F_C4B_T2F_Quad quad, int index) { Debug.Assert(index < m_pQuads.Capacity, "insertQuadWithTexture: Invalid index"); m_pQuads.Insert(index, quad); Dirty = true; }
public static ivec4 AllocateRegion(int width, int height) { ivec3 node, prev; ivec4 region = new ivec4() { x = 0, y = 0, width = width, height = height }; int i; int bestHeight = int.MaxValue; int bestIndex = -1; int bestWidth = int.MaxValue; for (i = 0; i < m_pNodes.Count; ++i) { int y = Fit(i, width, height); if (y >= 0) { node = m_pNodes[i]; if (((y + height) < bestHeight) || (((y + height) == bestHeight) && (node.z < bestWidth))) { bestHeight = y + height; bestIndex = i; bestWidth = node.z; region.x = node.x; region.y = y; } } } if (bestIndex == -1) { region.x = -1; region.y = -1; region.width = 0; region.height = 0; return(region); } //New node node.x = region.x; node.y = region.y + height; node.z = width; m_pNodes.Insert(bestIndex, node); for (i = bestIndex + 1; i < m_pNodes.Count; ++i) { node = m_pNodes[i]; prev = m_pNodes[i - 1]; if (node.x < (prev.x + prev.z)) { int shrink = prev.x + prev.z - node.x; node.x += shrink; node.z -= shrink; if (node.z <= 0) { m_pNodes.RemoveAt(i); --i; } else { m_pNodes[i] = node; break; } } else { break; } } Merge(); m_nUsed += width * height; return(region); }