void Cursor::GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor) { unsigned initialSize = vertexData.Size(); const IntVector2& offset = shapeInfos_[shape_].hotSpot_; Vector2 floatOffset(-(float)offset.x_, -(float)offset.y_); BorderImage::GetBatches(batches, vertexData, currentScissor); for (unsigned i = initialSize; i < vertexData.Size(); i += 6) { vertexData[i] += floatOffset.x_; vertexData[i + 1] += floatOffset.y_; } }
void GUICanvas::_fillBuffer(UINT8* vertices, UINT32* indices, UINT32 vertexOffset, UINT32 indexOffset, UINT32 maxNumVerts, UINT32 maxNumIndices, UINT32 renderElementIdx) const { UINT8* uvs = vertices + sizeof(Vector2); UINT32 indexStride = sizeof(UINT32); Vector2I offset(mLayoutData.area.x, mLayoutData.area.y); Rect2I clipRect = mLayoutData.getLocalClipRect(); Vector2 floatOffset((float)offset.x, (float)offset.y); buildAllTriangleElementsIfDirty(floatOffset, clipRect); const CanvasElement& element = findElement(renderElementIdx); renderElementIdx -= element.renderElemStart; switch(element.type) { case CanvasElementType::Image: { UINT32 vertexStride = sizeof(Vector2) * 2; const Rect2I& area = mImageData[element.dataId].area; offset.x += area.x; offset.y += area.y; clipRect.x -= area.x; clipRect.y -= area.y; element.imageSprite->fillBuffer(vertices, uvs, indices, vertexOffset, indexOffset, maxNumVerts, maxNumIndices, vertexStride, indexStride, renderElementIdx, offset, clipRect); } break; case CanvasElementType::Text: { UINT32 vertexStride = sizeof(Vector2) * 2; const Vector2I& position = mTextData[element.dataId].position; offset += position; clipRect.x += position.x; clipRect.y += position.y; element.textSprite->fillBuffer(vertices, uvs, indices, vertexOffset, indexOffset, maxNumVerts, maxNumIndices, vertexStride, indexStride, renderElementIdx, offset, mLayoutData.getLocalClipRect()); } break; case CanvasElementType::Triangle: { UINT32 vertexStride = sizeof(Vector2) * 2; UINT32 startVert = vertexOffset; UINT32 startIndex = indexOffset; UINT32 maxVertIdx = maxNumVerts; UINT32 maxIndexIdx = maxNumIndices; UINT32 numVertices = element.clippedNumVertices; UINT32 numIndices = numVertices; assert((startVert + numVertices) <= maxVertIdx); assert((startIndex + numIndices) <= maxIndexIdx); UINT8* vertDst = vertices + startVert * vertexStride; UINT8* uvDst = uvs + startVert * vertexStride; UINT32* indexDst = indices + startIndex; Vector2 zeroUV; for(UINT32 i = 0; i < element.clippedNumVertices; i++) { memcpy(vertDst, &mClippedVertices[element.clippedVertexStart + i], sizeof(Vector2)); memcpy(uvDst, &zeroUV, sizeof(Vector2)); vertDst += vertexStride; uvDst += vertexStride; indexDst[i] = i; } } break; case CanvasElementType::Line: { UINT32 vertexStride = sizeof(Vector2); UINT32 startVert = vertexOffset; UINT32 startIndex = indexOffset; UINT32 maxVertIdx = maxNumVerts; UINT32 maxIndexIdx = maxNumIndices; UINT32 numVertices = element.clippedNumVertices; UINT32 numIndices = numVertices; assert((startVert + numVertices) <= maxVertIdx); assert((startIndex + numIndices) <= maxIndexIdx); UINT8* vertDst = vertices + startVert * vertexStride; UINT32* indexDst = indices + startIndex; for (UINT32 i = 0; i < element.clippedNumVertices; i++) { const Vector2& point = mClippedLineVertices[element.clippedVertexStart + i]; memcpy(vertDst, &point, sizeof(Vector2)); vertDst += vertexStride; indexDst[i] = i; } } break; } }