-Geometry NPatchVisual::CreateGridGeometry( Uint16Pair gridSize )
-{
- uint16_t gridWidth = gridSize.GetWidth();
- uint16_t gridHeight = gridSize.GetHeight();
-
- // Create vertices
- Vector< Vector2 > vertices;
- vertices.Reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) );
-
- for( int y = 0; y < gridHeight + 1; ++y )
- {
- for( int x = 0; x < gridWidth + 1; ++x )
- {
- AddVertex( vertices, x, y );
- }
- }
-
- // Create indices
- Vector< unsigned short > indices;
- indices.Reserve( gridWidth * gridHeight * 6 );
-
- unsigned int rowIdx = 0;
- unsigned int nextRowIdx = gridWidth + 1;
- for( int y = 0; y < gridHeight; ++y, ++nextRowIdx, ++rowIdx )
- {
- for( int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx )
- {
- AddQuadIndices( indices, rowIdx, nextRowIdx );
- }
- }
-
- return GenerateGeometry( vertices, indices );
-}
-
-Geometry NPatchVisual::CreateBorderGeometry( Uint16Pair gridSize )
-{
- uint16_t gridWidth = gridSize.GetWidth();
- uint16_t gridHeight = gridSize.GetHeight();
-
- // Create vertices
- Vector< Vector2 > vertices;
- vertices.Reserve( ( gridWidth + 1 ) * ( gridHeight + 1 ) );
-
- //top
- int y = 0;
- for(; y < 2; ++y)
- {
- for( int x = 0; x < gridWidth + 1; ++x )
- {
- AddVertex( vertices, x, y );
- }
- }
-
- for(; y < gridHeight - 1; ++y)
- {
- //left
- AddVertex( vertices, 0, y );
- AddVertex( vertices, 1, y );
-
- //right
- AddVertex( vertices, gridWidth - 1, y );
- AddVertex( vertices, gridWidth, y );
- }
-
- //bottom
- for(; y < gridHeight + 1; ++y)
- {
- for( int x = 0; x < gridWidth + 1; ++x )
- {
- AddVertex( vertices, x, y );
- }
- }
-
- // Create indices
- Vector< unsigned short > indices;
- indices.Reserve( gridWidth * gridHeight * 6 );
-
- //top
- unsigned int rowIdx = 0 ;
- unsigned int nextRowIdx = gridWidth + 1;
- for( int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx )
- {
- AddQuadIndices( indices, rowIdx, nextRowIdx );
- }
-
- if(gridHeight > 2)
- {
- rowIdx = gridWidth + 1;
- nextRowIdx = ( gridWidth + 1 ) * 2;
-
- unsigned increment = gridWidth - 1;
- if(gridHeight > 3)
- {
- increment = 2;
- //second row left
- AddQuadIndices( indices, rowIdx, nextRowIdx );
-
- rowIdx = gridWidth * 2;
- nextRowIdx = ( gridWidth + 1 ) * 2 + 2;
- //second row right
- AddQuadIndices( indices, rowIdx, nextRowIdx );
-
- //left and right
- rowIdx = nextRowIdx - 2;
- nextRowIdx = rowIdx + 4;
- for(int y = 2; y < 2*(gridHeight - 3); ++y, rowIdx += 2, nextRowIdx += 2)
- {
- AddQuadIndices( indices, rowIdx, nextRowIdx );
- }
- }
-
- //second row left
- AddQuadIndices( indices, rowIdx, nextRowIdx );
-
- rowIdx += increment;
- nextRowIdx += gridWidth - 1;
- //second row right
- AddQuadIndices( indices, rowIdx, nextRowIdx );
- }
-
- //bottom
- rowIdx = nextRowIdx - gridWidth + 1;
- nextRowIdx = rowIdx + gridWidth + 1;
- for( int x = 0; x < gridWidth; ++x, ++nextRowIdx, ++rowIdx )
- {
- AddQuadIndices( indices, rowIdx, nextRowIdx );
- }
-
- return GenerateGeometry( vertices, indices );
-}
-