net.ctdp.rfdynhud.render
Class TransformableTexture

java.lang.Object
  extended by net.ctdp.rfdynhud.render.TransformableTexture

public class TransformableTexture
extends java.lang.Object

The TransformableTexture keeps one TextureImage2D and transformation parameters.

Author:
Marvin Froehlich (CTDP)

Nested Class Summary
static class TransformableTexture.Rectangle
           
 
Field Summary
static boolean DEFAULT_PIXEL_PERFECT_POSITIONING
           
static int MAX_NUM_TEXTURES
           
static float PI
           
static float PI_HALF
           
static int STRUCT_SIZE
           
static float TWO_PI
           
 
Constructor Summary
TransformableTexture(int width, int height)
           
TransformableTexture(int width, int height, boolean pixelPerfectPositioning, boolean usePowerOfTwoSizes)
           
TransformableTexture(int width, int height, boolean pixelPerfectPositioning, float transX, float transY, int rotCenterX, int rotCenterY, float rotation, float scaleX, float scaleY, boolean usePowerOfTwoSizes)
           
TransformableTexture(int width, int height, int transX, int transY, int rotCenterX, int rotCenterY, float rotation, float scaleX, float scaleY, boolean usePowerOfTwoSizes)
           
 
Method Summary
static java.nio.ByteBuffer createByteBuffer()
           
 void drawInEditor(java.awt.Graphics2D texCanvas, java.awt.geom.AffineTransform at, Rect2i transformedRect)
           
protected  int fillBuffer(boolean widgetVisibility, int offsetX, int offsetY, int index, int rectangleIndex, java.nio.ByteBuffer buffer)
           
protected  void generateRectanglesForOneBigTexture(LiveGameData gameData, boolean isEditorMode, WidgetsConfiguration widgetsConfig)
           
 Rect2i getClipRect(Rect2i r)
           
 java.nio.ByteBuffer getDirtyRectsBuffer()
           
 int getHeight()
           
 int getLocalZIndex()
          Gets the Widget-local z-index.
 java.lang.String getName()
           
protected  int getNumUsedRectangles()
           
 int getOffsetXToRootMasterWidget()
          Gets the x-offset relative to the master Widget.
 int getOffsetYToRootMasterWidget()
          Gets the y-offset relative to the master Widget.
static TransformableTexture getOrCreate(int width, int height, boolean pixelPerfectPositioning, TransformableTexture possibleResult, boolean tryToResize)
          Gets a TransformableTexture with this image drawn onto it.
 Widget getOwnerWidget()
           
 float getRotation()
           
 float getRotationInDegrees()
           
 int getRotCenterX()
          Gets the center location for rotation.
 int getRotCenterY()
          Gets the center location for rotation.
 float getScaleX()
           
 float getScaleY()
           
 TextureImage2D getTexture()
           
 Texture2DCanvas getTextureCanvas()
           
 byte[] getTextureData()
           
 Rect2i getTransformedRectForEditor(java.awt.geom.AffineTransform at)
           
 java.awt.geom.AffineTransform getTransformForEditor(int offsetX, int offsetY)
           
 float getTransX()
           
 float getTransY()
           
 int getWidth()
           
 boolean isDynamic()
          This flag must be set, if you intend to draw on this texture.
protected  boolean isRectangleVisible(int index)
           
 boolean isVisible()
           
 boolean isVisibleInEditor()
           
 void setClipRect(int x, int y, int width, int height, boolean toggleVisibilityBySize)
           
 void setDynamic(boolean dynamic)
          This flag must be set, if you intend to draw on this texture.
 void setLocalZIndex(int zIndex)
          Sets the Widget-local z-index.
protected  void setRectangleVisible(int index, boolean visible)
           
 void setRotation(float rotation)
           
 void setRotationCenter(int rotCenterX, int rotCenterY)
          Sets the center location for rotation.
 void setRotationInDegrees(float rotDeg)
           
 void setScale(float scaleX, float scaleY)
           
 void setTranslation(float transX, float transY)
          Set the sub texture's translation.
 void setVisible(boolean visible)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PIXEL_PERFECT_POSITIONING

public static final boolean DEFAULT_PIXEL_PERFECT_POSITIONING
See Also:
Constant Field Values

PI

public static final float PI
See Also:
Constant Field Values

TWO_PI

public static final float TWO_PI
See Also:
Constant Field Values

PI_HALF

public static final float PI_HALF
See Also:
Constant Field Values

MAX_NUM_TEXTURES

public static final int MAX_NUM_TEXTURES
See Also:
Constant Field Values

STRUCT_SIZE

public static final int STRUCT_SIZE
See Also:
Constant Field Values
Constructor Detail

TransformableTexture

public TransformableTexture(int width,
                            int height,
                            boolean pixelPerfectPositioning,
                            float transX,
                            float transY,
                            int rotCenterX,
                            int rotCenterY,
                            float rotation,
                            float scaleX,
                            float scaleY,
                            boolean usePowerOfTwoSizes)

TransformableTexture

public TransformableTexture(int width,
                            int height,
                            int transX,
                            int transY,
                            int rotCenterX,
                            int rotCenterY,
                            float rotation,
                            float scaleX,
                            float scaleY,
                            boolean usePowerOfTwoSizes)

TransformableTexture

public TransformableTexture(int width,
                            int height,
                            boolean pixelPerfectPositioning,
                            boolean usePowerOfTwoSizes)

TransformableTexture

public TransformableTexture(int width,
                            int height)
Method Detail

getName

public final java.lang.String getName()

getOwnerWidget

public final Widget getOwnerWidget()

getOffsetXToRootMasterWidget

public final int getOffsetXToRootMasterWidget()
Gets the x-offset relative to the master Widget.

Returns:
the x-offset relative to the master Widget.

getOffsetYToRootMasterWidget

public final int getOffsetYToRootMasterWidget()
Gets the y-offset relative to the master Widget.

Returns:
the y-offset relative to the master Widget.

createByteBuffer

public static java.nio.ByteBuffer createByteBuffer()

getTexture

public final TextureImage2D getTexture()

getTextureCanvas

public final Texture2DCanvas getTextureCanvas()

generateRectanglesForOneBigTexture

protected void generateRectanglesForOneBigTexture(LiveGameData gameData,
                                                  boolean isEditorMode,
                                                  WidgetsConfiguration widgetsConfig)

getNumUsedRectangles

protected final int getNumUsedRectangles()

setRectangleVisible

protected void setRectangleVisible(int index,
                                   boolean visible)

isRectangleVisible

protected final boolean isRectangleVisible(int index)

setDynamic

public void setDynamic(boolean dynamic)
This flag must be set, if you intend to draw on this texture.

Parameters:
dynamic - dynamic?

isDynamic

public final boolean isDynamic()
This flag must be set, if you intend to draw on this texture.

Returns:
dynamic or not

setLocalZIndex

public void setLocalZIndex(int zIndex)
Sets the Widget-local z-index. The only affects subtextures of a single Widget or AbstractAssembledWidget. Higher values make the sub texture be drawn later then those with smaller values.

Parameters:
zIndex - the new local z-index

getLocalZIndex

public final int getLocalZIndex()
Gets the Widget-local z-index. The only affects subtextures of a single Widget or AbstractAssembledWidget. Higher values make the sub texture be drawn later then those with smaller values.

Returns:
the local z-index.

setVisible

public void setVisible(boolean visible)

isVisible

public final boolean isVisible()

isVisibleInEditor

public final boolean isVisibleInEditor()

getWidth

public final int getWidth()

getHeight

public final int getHeight()

setTranslation

public void setTranslation(float transX,
                           float transY)
Set the sub texture's translation. Sub texture's are generally (and additionally to this) translated to the upper left of the host Widget plus its border.

Parameters:
transX -
transY -

getTransX

public final float getTransX()

getTransY

public final float getTransY()

setRotationCenter

public void setRotationCenter(int rotCenterX,
                              int rotCenterY)
Sets the center location for rotation. This is relative to the sub texture's upper left.

Parameters:
rotCenterX -
rotCenterY -

getRotCenterX

public final int getRotCenterX()
Gets the center location for rotation. This is relative to the sub texture's upper left.

Returns:
the center location for rotation.

getRotCenterY

public final int getRotCenterY()
Gets the center location for rotation. This is relative to the sub texture's upper left.

Returns:
the center location for rotation.

setRotation

public void setRotation(float rotation)

setRotationInDegrees

public final void setRotationInDegrees(float rotDeg)

getRotation

public final float getRotation()

getRotationInDegrees

public final float getRotationInDegrees()

setScale

public void setScale(float scaleX,
                     float scaleY)

getScaleX

public final float getScaleX()

getScaleY

public final float getScaleY()

setClipRect

public void setClipRect(int x,
                        int y,
                        int width,
                        int height,
                        boolean toggleVisibilityBySize)

getClipRect

public final Rect2i getClipRect(Rect2i r)

getDirtyRectsBuffer

public final java.nio.ByteBuffer getDirtyRectsBuffer()

getTextureData

public final byte[] getTextureData()

fillBuffer

protected int fillBuffer(boolean widgetVisibility,
                         int offsetX,
                         int offsetY,
                         int index,
                         int rectangleIndex,
                         java.nio.ByteBuffer buffer)

getTransformForEditor

public java.awt.geom.AffineTransform getTransformForEditor(int offsetX,
                                                           int offsetY)

getTransformedRectForEditor

public Rect2i getTransformedRectForEditor(java.awt.geom.AffineTransform at)

drawInEditor

public void drawInEditor(java.awt.Graphics2D texCanvas,
                         java.awt.geom.AffineTransform at,
                         Rect2i transformedRect)

getOrCreate

public static TransformableTexture getOrCreate(int width,
                                               int height,
                                               boolean pixelPerfectPositioning,
                                               TransformableTexture possibleResult,
                                               boolean tryToResize)
Gets a TransformableTexture with this image drawn onto it. If the possibleResult is non null and has the correct size, it is returned.

Parameters:
width - the desired width
height - the desired height
pixelPerfectPositioning - prepare for pixel perfect positioning
possibleResult - this instance is possibly retured, if it matches the parameters
tryToResize - if true, the passed in texture is resized to the given size, if the max size is sufficient. This is useful in editor mode avoid constant recreations.
Returns:
a TransformableTexture with this image drawn onto it.