com.hdcookbook.grin.animator
Class DrawRecord

java.lang.Object
  extended by com.hdcookbook.grin.animator.DrawRecord

public class DrawRecord
extends java.lang.Object

This class represents a record of drawing to a rectangular area. It helps in the calculation of an optimized erase/redraw set for a frame of animation, by allowing a convenient means to tracking what was drawn in the previous frame, and what is to be drawn in the current frame.

The animation framework attempts to minimize the area drawn to in each frame. One way it does this is by collecting all of the drawing operations that target an area of the screen into a single bounding rectangle for the screen draw, and a (possibly smaller) area that needs to be erased. DrawRecord represents one set of drawing operations contained within a rectangular area, and it remembers what was drawn in the previous frame, so that the previous frame will be automatically erased.

The drawing framework combines all of the DrawRecord drawing operations that target the same "render area target" into a single bounding rectangle.

See Also:
RenderContext, AnimationClient.addDisplayAreas(RenderContext)

Constructor Summary
DrawRecord()
          Create a new, empty DrawRecord
 
Method Summary
 void addClip(int x, int y, int width, int height)
          Applies a clip to the area to be drawn.
 void applyTranslation(int dx, int dy)
          Indicates that the area is subject to the given translation.
 void setArea(int x, int y, int width, int height)
          Set the area to be drawn to in this frame of animation.
 void setChanged()
          Flags that the contents of the area being drawn to has changed since the last frame.
 void setSemiTransparent()
          Flags that some of the pixels in the area to be drawn might be transparent or semi-transparent, either because they're not drawn to, or because they're drawn to in SrcOver mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DrawRecord

public DrawRecord()
Create a new, empty DrawRecord

Method Detail

setArea

public void setArea(int x,
                    int y,
                    int width,
                    int height)
Set the area to be drawn to in this frame of animation. After this is called, the other public methods of this class can be called to indicate the characteristics of this draw operation.

As with AWT, the pixels to be filled include the pixel at x,y, but not the pixel at x+width, y+height. If the width or height are negative, then x and y are adjusted by the negative value, and the dimension is negated. These rules make this method work like Graphics.drawImage taking a source and a dest rectangle.

Parameters:
x - x coordinate of upper left hand corner of drawing
y - y coordinate of upper left hand corner of drawing
width - width of drawing, may be negative
height - height of drawing, may be negative

setSemiTransparent

public void setSemiTransparent()
Flags that some of the pixels in the area to be drawn might be transparent or semi-transparent, either because they're not drawn to, or because they're drawn to in SrcOver mode. If this is called, then any redraw of the area will need to be erased, unless there is a guarantee from another DrawRecord that all of the pixels will be filled with source mode drawing.


setChanged

public void setChanged()
Flags that the contents of the area being drawn to has changed since the last frame. If this is called, then the area will be drawn; if it isn't, then the area will only be drawn to if that's required by a different DrawRecord.


applyTranslation

public void applyTranslation(int dx,
                             int dy)
Indicates that the area is subject to the given translation.

Parameters:
dx - Change in x coordinate
dy - Change in y coordinate

addClip

public void addClip(int x,
                    int y,
                    int width,
                    int height)
Applies a clip to the area to be drawn. This can reduce the area set by setArea().

Parameters:
x - x coordinate of the clip
y - y coordinate of the clip
width - width coordinate of the clip
height - height coordinate of the clip