From 5a946df8fd812570826f267d4123b59d79c97cf7 Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * Original image-size stored in this tile-renderer is unmodified.
+ *
+ * Method resets internal state and {@link #TR_ROWS} {@link #TR_COLUMNS} count.
+ *
+ * If a image-size is clipped via {@link #clipImageSize(int, int)},
+ * method returns:
+ *
+ *
+ * min( image-clipping, image-size )
, otherwise image-size
+ * The clipping width and height can be retrieved via {@link #TR_IMAGE_CLIPPING_WIDTH} + * {@link #TR_IMAGE_CLIPPING_HEIGHT}. + *
+ */ + public final DimensionImmutable getClippedImageSize() { + if( null != imageClippingDim ) { + return new Dimension(Math.min(imageClippingDim.getWidth(), imageSize.getWidth()), + Math.min(imageClippingDim.getHeight(), imageSize.getHeight()) ); + } else { + return imageSize; + } + } + /** * Sets the size of the tiles to use in rendering. The actual * effective size of the tile depends on the border size, ie ( * width - 2*border ) * ( height - 2 * border ) + *+ * Method resets internal state and {@link #TR_ROWS} {@link #TR_COLUMNS} count. + *
* * @param width * The width of the tiles. Must not be larger than the GL @@ -167,8 +240,10 @@ public class TileRenderer extends TileRendererBase { } /** - * Sets an xy offset for the resulting tile - * {@link TileRendererBase#TR_CURRENT_TILE_X_POS x-pos} and {@link TileRendererBase#TR_CURRENT_TILE_Y_POS y-pos}. + * Sets an xy offset for the resulting tiles + * {@link TileRendererBase#TR_CURRENT_TILE_X_POS x-pos} and {@link TileRendererBase#TR_CURRENT_TILE_Y_POS y-pos}. + * @see #TR_TILE_X_OFFSET + * @see #TR_TILE_Y_OFFSET **/ public void setTileOffset(int xoff, int yoff) { offsetX = xoff; @@ -179,8 +254,9 @@ public class TileRenderer extends TileRendererBase { * Sets up the number of rows and columns needed */ private final void setup() throws IllegalStateException { - columns = ( imageSize.getWidth() + tileSizeNB.getWidth() - 1 ) / tileSizeNB.getWidth(); - rows = ( imageSize.getHeight() + tileSizeNB.getHeight() - 1 ) / tileSizeNB.getHeight(); + final DimensionImmutable clippedImageSize = getClippedImageSize(); + columns = ( clippedImageSize.getWidth() + tileSizeNB.getWidth() - 1 ) / tileSizeNB.getWidth(); + rows = ( clippedImageSize.getHeight() + tileSizeNB.getHeight() - 1 ) / tileSizeNB.getHeight(); currentTile = 0; currentTileXPos = 0; currentTileYPos = 0; @@ -202,32 +278,42 @@ public class TileRenderer extends TileRendererBase { @Override public final int getParam(int pname) { switch (pname) { + case TR_IMAGE_WIDTH: + return imageSize.getWidth(); + case TR_IMAGE_HEIGHT: + return imageSize.getHeight(); + case TR_CURRENT_TILE_X_POS: + return currentTileXPos; + case TR_CURRENT_TILE_Y_POS: + return currentTileYPos; + case TR_CURRENT_TILE_WIDTH: + return currentTileWidth; + case TR_CURRENT_TILE_HEIGHT: + return currentTileHeight; + case TR_IMAGE_CLIPPING_WIDTH: + return null != imageClippingDim ? imageClippingDim.getWidth() : 0; + case TR_IMAGE_CLIPPING_HEIGHT: + return null != imageClippingDim ? imageClippingDim.getHeight() : 0; case TR_TILE_WIDTH: return tileSize.getWidth(); case TR_TILE_HEIGHT: return tileSize.getHeight(); case TR_TILE_BORDER: return tileBorder; - case TR_IMAGE_WIDTH: - return imageSize.getWidth(); - case TR_IMAGE_HEIGHT: - return imageSize.getHeight(); + case TR_TILE_X_OFFSET: + return offsetX; + case TR_TILE_Y_OFFSET: + return offsetY; case TR_ROWS: return rows; case TR_COLUMNS: return columns; + case TR_CURRENT_TILE_NUM: + return currentTile; case TR_CURRENT_ROW: return currentRow; case TR_CURRENT_COLUMN: return currentColumn; - case TR_CURRENT_TILE_X_POS: - return currentTileXPos; - case TR_CURRENT_TILE_Y_POS: - return currentTileYPos; - case TR_CURRENT_TILE_WIDTH: - return currentTileWidth; - case TR_CURRENT_TILE_HEIGHT: - return currentTileHeight; case TR_ROW_ORDER: return rowOrder; default: @@ -271,19 +357,20 @@ public class TileRenderer extends TileRendererBase { int border = tileBorder; + final DimensionImmutable clippedImageSize = getClippedImageSize(); int tH, tW; /* Compute actual size of this tile with border */ if (currentRow < rows - 1) { tH = tileSize.getHeight(); } else { - tH = imageSize.getHeight() - ( rows - 1 ) * ( tileSizeNB.getHeight() ) + 2 * border; + tH = clippedImageSize.getHeight() - ( rows - 1 ) * ( tileSizeNB.getHeight() ) + 2 * border; } if (currentColumn < columns - 1) { tW = tileSize.getWidth(); } else { - tW = imageSize.getWidth() - ( columns - 1 ) * ( tileSizeNB.getWidth() ) + 2 * border; + tW = clippedImageSize.getWidth() - ( columns - 1 ) * ( tileSizeNB.getWidth() ) + 2 * border; } currentTileXPos = currentColumn * tileSizeNB.getWidth() + offsetX; @@ -301,7 +388,7 @@ public class TileRenderer extends TileRendererBase { // Do not forget to issue: // reshape( 0, 0, tW, tH ); - // which shall reflect tile renderer fileds: currentTileXPos, currentTileYPos and imageSize + // which shall reflect tile renderer tiles: currentTileXPos, currentTileYPos and imageSize beginCalled = true; } -- cgit v1.2.3