PulpCore

pulpcore.image
Class CoreGraphics

java.lang.Object
  extended by pulpcore.image.CoreGraphics

public class CoreGraphics
extends Object

Graphics rendering routines onto a CoreImage surface.

The default blend mode is BlendMode.SrcOver().

The clip is in view-space - not affected by the Transform.


Field Summary
static int EDGE_CLAMP_ALL
          Specifies that all edges of the image should be clamped (not antialiased).
static int EDGE_CLAMP_BOTTOM
          Specifies that the bottom edge of the image should be clamped (not antialiased).
static int EDGE_CLAMP_LEFT
          Specifies that the left edge of the image should be clamped (not antialiased).
static int EDGE_CLAMP_NONE
          Specifies that all edges of the image should be antialiased (not clamped).
static int EDGE_CLAMP_RIGHT
          Specifies that the right edge of the image should be clamped (not antialiased).
static int EDGE_CLAMP_TOP
          Specifies that the top edge of the image should be clamped (not antialiased).
static int INTERPOLATION_BILINEAR
          Bilinear interpolation method (used for image scaling).
static int INTERPOLATION_NEAREST_NEIGHBOR
          Nearest neighbor interpolation method (used for image scaling).
 
Method Summary
 void clear()
          Fills the area defined by the clip with the background color of the current drawing surface.
 void clearTransform()
          Sets the current transform to the identiy matrix.
 void clipRect(int x, int y, int w, int h)
          The clip is not affected by the transform.
 void clipRect(Rect r)
          The clip is not affected by the transform.
 void drawChar(char ch, int maxWidth)
          Internal method used to clip the TextField.
 void drawImage(CoreImage image)
           
 void drawImage(CoreImage image, int x, int y)
          Draws an image at a specific location.
 void drawImage(CoreImage image, int srcX, int srcY, int srcWidth, int srcHeight)
           
 void drawImage(CoreImage image, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight)
           
 void drawLine(double x1, double y1, double x2, double y2)
          Draws a line using the current color.
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line using the current color.
 void drawLineFixedPoint(int x1, int y1, int x2, int y2)
          Draws a line (at fixed-point coordinates) using the current color.
 void drawRect(int x, int y, int w, int h)
          Draws a rectangle using the current color.
 void drawRotatedImage(CoreImage image, int x, int y, int w, int h, int angle)
          Draws a rotated and scaled image.
 void drawRotatedImage(CoreImage image, int x, int y, int w, int h, int cosAngle, int sinAngle)
          Draws a rotated and scaled image using pre-computed cosine and sine of the angle.
 void drawRotatedImage(CoreImage image, int x, int y, int w, int h, int angle, int srcX, int srcY, int srcWidth, int srcHeight)
          Draws a rotated and scaled image.
 void drawRotatedImage(CoreImage image, int x, int y, int w, int h, int cosAngle, int sinAngle, int srcX, int srcY, int srcWidth, int srcHeight)
          Draws a rotated and scaled image using pre-computed cosine and sine of the angle.
 void drawRotatedString(String str, int x, int y, int w, int h, int angle)
           
 void drawRotatedString(String str, int x, int y, int w, int h, int cosAngle, int sinAngle)
           
 void drawScaledImage(CoreImage image, int x, int y, int w, int h)
           
 void drawScaledImage(CoreImage image, int x, int y, int w, int h, int srcX, int srcY, int srcWidth, int srcHeight)
           
 void drawScaledString(String str, int x, int y, int w, int h)
           
 void drawString(String str)
           
 void drawString(String str, int x, int y)
           
 void fill()
          Fills the entire surface with the current color.
 void fillRect(double x, double y, double w, double h)
          Fills a rectangle with the current color.
 void fillRect(int x, int y, int w, int h)
          Fills a rectangle with the current color.
 void fillRectFixedPoint(int fx, int fy, int fw, int fh)
          Fills a rectangle (at fixed-point coordinates) with the current color.
 int getAlpha()
           
 BlendMode getBlendMode()
           
 Rect getClip()
          Gets the current clip as a newly allocated Rect.
 void getClip(Rect rect)
          Copies the current clip into the specified Rect.
 int getClipHeight()
           
 int getClipWidth()
           
 int getClipX()
           
 int getClipY()
           
 int getColor()
          Returns the current color in ARGB format.
 int getEdgeClamp()
          Gets the edge clamp bitmask.
 CoreFont getFont()
           
 int getInterpolation()
           
 int[] getSurfaceData()
          Deprecated. This will be moved in 0.12.
 int getSurfaceHeight()
           
 int getSurfaceWidth()
           
 Transform getTransform()
          Returns the current transform.
 void popTransform()
          Removes (pops) the transform at the top of the transform stack and sets the current transform to that popped transform.
 void pushTransform()
          Adds (pushes) a copy of the current transform to the top of the transform stack.
 void removeClip()
           
 void reset()
          Resets the rendering attributes for this CoreGraphics object to the default values: No clip Identity transform (and the transform stack is cleared) color = BLACK alpha = 255 blendMode = BlendMode.SrcOver() interpolation = INTERPOLATION_BILINEAR edgeClamp = EDGE_CLAMP_NONE font = null
 void setAlpha(int alpha)
           
 void setBlendMode(BlendMode blendMode)
           
 void setClip(int x, int y, int w, int h)
          The clip is not affected by the transform.
 void setClip(Rect r)
          The clip is not affected by the transform.
 void setColor(int argbColor)
          Sets the current color.
 void setEdgeClamp(int edgeClamp)
          Sets the edge mode for bilinear interpolated scaled images.
 void setFont(CoreFont font)
           
 void setInterpolation(int interpolation)
           
 void setTransform(Transform newTransform)
          Sets the current transform to a copy of the specified transform.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERPOLATION_NEAREST_NEIGHBOR

public static final int INTERPOLATION_NEAREST_NEIGHBOR
Nearest neighbor interpolation method (used for image scaling). Also known as "pixel scaling".

See Also:
Constant Field Values

INTERPOLATION_BILINEAR

public static final int INTERPOLATION_BILINEAR
Bilinear interpolation method (used for image scaling).

See Also:
Constant Field Values

EDGE_CLAMP_LEFT

public static final int EDGE_CLAMP_LEFT
Specifies that the left edge of the image should be clamped (not antialiased).

See Also:
setEdgeClamp(int), Constant Field Values

EDGE_CLAMP_RIGHT

public static final int EDGE_CLAMP_RIGHT
Specifies that the right edge of the image should be clamped (not antialiased).

See Also:
setEdgeClamp(int), Constant Field Values

EDGE_CLAMP_BOTTOM

public static final int EDGE_CLAMP_BOTTOM
Specifies that the bottom edge of the image should be clamped (not antialiased).

See Also:
setEdgeClamp(int), Constant Field Values

EDGE_CLAMP_TOP

public static final int EDGE_CLAMP_TOP
Specifies that the top edge of the image should be clamped (not antialiased).

See Also:
setEdgeClamp(int), Constant Field Values

EDGE_CLAMP_ALL

public static final int EDGE_CLAMP_ALL
Specifies that all edges of the image should be clamped (not antialiased).

See Also:
setEdgeClamp(int), Constant Field Values

EDGE_CLAMP_NONE

public static final int EDGE_CLAMP_NONE
Specifies that all edges of the image should be antialiased (not clamped).

See Also:
setEdgeClamp(int), Constant Field Values
Method Detail

getSurfaceData

public int[] getSurfaceData()
Deprecated. This will be moved in 0.12.

Gets the underlying data array of the surface image.


getSurfaceWidth

public int getSurfaceWidth()

getSurfaceHeight

public int getSurfaceHeight()

reset

public void reset()
Resets the rendering attributes for this CoreGraphics object to the default values:


setBlendMode

public void setBlendMode(BlendMode blendMode)

getBlendMode

public BlendMode getBlendMode()

setInterpolation

public void setInterpolation(int interpolation)

getInterpolation

public int getInterpolation()

setEdgeClamp

public void setEdgeClamp(int edgeClamp)
Sets the edge mode for bilinear interpolated scaled images. The default is EDGE_CLAMP_NONE. Valid values are a bitmask combination of EDGE_CLAMP_LEFT, EDGE_CLAMP_RIGHT, EDGE_CLAMP_BOTTOM, EDGE_CLAMP_TOP. A clamp edge appears "hard", and an unclamped edge appears "soft".

Parameters:
edgeClamp - A bitmask defining how the edges of an image are rendered.

getEdgeClamp

public int getEdgeClamp()
Gets the edge clamp bitmask.

See Also:
setEdgeClamp(int)

setFont

public void setFont(CoreFont font)

getFont

public CoreFont getFont()

pushTransform

public void pushTransform()
Adds (pushes) a copy of the current transform to the top of the transform stack.


popTransform

public void popTransform()
                  throws EmptyStackException
Removes (pops) the transform at the top of the transform stack and sets the current transform to that popped transform.

Throws:
EmptyStackException - if the stack is empty

getTransform

public Transform getTransform()
Returns the current transform. The returned instance will always be the current transform of this graphics context.


setTransform

public void setTransform(Transform newTransform)
Sets the current transform to a copy of the specified transform. If the specified transform is null, the current transform is cleared, i.e., set to the identity matrix.


clearTransform

public void clearTransform()
Sets the current transform to the identiy matrix.


removeClip

public void removeClip()

setClip

public void setClip(Rect r)
The clip is not affected by the transform.


setClip

public void setClip(int x,
                    int y,
                    int w,
                    int h)
The clip is not affected by the transform.


clipRect

public void clipRect(Rect r)
The clip is not affected by the transform.


clipRect

public void clipRect(int x,
                     int y,
                     int w,
                     int h)
The clip is not affected by the transform.


getClipX

public int getClipX()

getClipY

public int getClipY()

getClipWidth

public int getClipWidth()

getClipHeight

public int getClipHeight()

getClip

public Rect getClip()
Gets the current clip as a newly allocated Rect.


getClip

public void getClip(Rect rect)
Copies the current clip into the specified Rect.


setAlpha

public void setAlpha(int alpha)

getAlpha

public int getAlpha()

setColor

public void setColor(int argbColor)
Sets the current color. The color is used for drawing rectangles and lines.

See Also:
Colors

getColor

public int getColor()
Returns the current color in ARGB format.

See Also:
Colors

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a line using the current color.


drawLine

public void drawLine(double x1,
                     double y1,
                     double x2,
                     double y2)
Draws a line using the current color.


drawLineFixedPoint

public void drawLineFixedPoint(int x1,
                               int y1,
                               int x2,
                               int y2)
Draws a line (at fixed-point coordinates) using the current color.


drawRect

public void drawRect(int x,
                     int y,
                     int w,
                     int h)
Draws a rectangle using the current color. This method draws rectangles at integer coordinates.

Note, this method is different from java.awt.Graphics.drawRect() which draws a rectangle with a width of (w+1) and a height of (h+1).


fill

public void fill()
Fills the entire surface with the current color. Same as calling fillRect(0, 0, surfaceWidth, surfaceHeight) with the identity transform.


clear

public void clear()
Fills the area defined by the clip with the background color of the current drawing surface. For opaque surfaces, the background color is black. For surfaces with alpha, the background color is transparent. The current blend mode is ignored - the area if filled using the Porter-Duff Source rule.


fillRect

public void fillRect(int x,
                     int y,
                     int w,
                     int h)
Fills a rectangle with the current color.


fillRect

public void fillRect(double x,
                     double y,
                     double w,
                     double h)
Fills a rectangle with the current color.


fillRectFixedPoint

public void fillRectFixedPoint(int fx,
                               int fy,
                               int fw,
                               int fh)
Fills a rectangle (at fixed-point coordinates) with the current color.


drawString

public void drawString(String str)

drawChar

public void drawChar(char ch,
                     int maxWidth)
Internal method used to clip the TextField. The problem is the clip is limited to View Space, but the TextField needs clipping to occur in Local Space. This method can be removed if, in future versions, CoreGraphics objects can be clipped in Local Space.


drawString

public void drawString(String str,
                       int x,
                       int y)

drawScaledString

public void drawScaledString(String str,
                             int x,
                             int y,
                             int w,
                             int h)

drawRotatedString

public void drawRotatedString(String str,
                              int x,
                              int y,
                              int w,
                              int h,
                              int angle)

drawRotatedString

public void drawRotatedString(String str,
                              int x,
                              int y,
                              int w,
                              int h,
                              int cosAngle,
                              int sinAngle)

drawImage

public void drawImage(CoreImage image)

drawImage

public void drawImage(CoreImage image,
                      int srcX,
                      int srcY,
                      int srcWidth,
                      int srcHeight)

drawImage

public void drawImage(CoreImage image,
                      int x,
                      int y)
Draws an image at a specific location. The image is drawn using the current clip, transform, alpha value, and blend mode. If the image is null, no action is taken and no exception is thrown.

Parameters:
image - the image to draw.
x - the x coordinate.
y - the y coordinate.

drawImage

public void drawImage(CoreImage image,
                      int x,
                      int y,
                      int srcX,
                      int srcY,
                      int srcWidth,
                      int srcHeight)

drawScaledImage

public void drawScaledImage(CoreImage image,
                            int x,
                            int y,
                            int w,
                            int h)

drawScaledImage

public void drawScaledImage(CoreImage image,
                            int x,
                            int y,
                            int w,
                            int h,
                            int srcX,
                            int srcY,
                            int srcWidth,
                            int srcHeight)

drawRotatedImage

public void drawRotatedImage(CoreImage image,
                             int x,
                             int y,
                             int w,
                             int h,
                             int angle)
Draws a rotated and scaled image. The image is rotated around it's center.

Parameters:
angle - a fixed-point angle, typically in the range from 0 to 2 * CoreMath.PI.

drawRotatedImage

public void drawRotatedImage(CoreImage image,
                             int x,
                             int y,
                             int w,
                             int h,
                             int angle,
                             int srcX,
                             int srcY,
                             int srcWidth,
                             int srcHeight)
Draws a rotated and scaled image. The image is rotated around it's center.

Parameters:
angle - a fixed-point angle, typically in the range from 0 to 2 * CoreMath.PI.

drawRotatedImage

public void drawRotatedImage(CoreImage image,
                             int x,
                             int y,
                             int w,
                             int h,
                             int cosAngle,
                             int sinAngle)
Draws a rotated and scaled image using pre-computed cosine and sine of the angle. The image is rotated around it's center.

Parameters:
cosAngle - The fixed-point cosine of the angle.
sinAngle - The fixed-point sine of the angle.

drawRotatedImage

public void drawRotatedImage(CoreImage image,
                             int x,
                             int y,
                             int w,
                             int h,
                             int cosAngle,
                             int sinAngle,
                             int srcX,
                             int srcY,
                             int srcWidth,
                             int srcHeight)
Draws a rotated and scaled image using pre-computed cosine and sine of the angle. The image is rotated around it's center.

Parameters:
cosAngle - The fixed-point cosine of the angle.
sinAngle - The fixed-point sine of the angle.

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.