Class RasterFloatGraphics
- java.lang.Object
-
- com.nerius.grafx.d2.RasterFloatGraphics
-
- All Implemented Interfaces:
FloatGraphics
public class RasterFloatGraphics extends java.lang.Object implements FloatGraphics
An implementation ofFloatGraphics
that converts operations into pixel data.
-
-
Constructor Summary
Constructors Constructor Description RasterFloatGraphics(int[] pix, int width, int height)
Arraypix
will be used to store pixel information; the array's length must therefore be at leastwidth*height
.RasterFloatGraphics(RasterFloatPixBuff pixBuff)
Exposes a level of abstraction for deciding on how to handle turning on of pixels; in particular this way of constructing the graphics context potentially gives it the capability for handling translucent colors.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Paints the current clip area with the current color.void
drawLine(double x0, double y0, double x1, double y1)
Draws a line segment between two endpoints, namely(x0,y0)
and(x1,y1)
.void
drawPoint(double x, double y)
Affects exactly one pixel, assuming that it's not outside of the clip area.void
fillPolygon(double[] xPts, double[] yPts, int offset, int numPts)
Uses the even-odd fill rule for self-intersecting polygons.ClipRectangle
getClip()
The return value of this method is not necessarily equal to the clip previously set bysetClip()
; the clip returned here is no larger than the entire area that is visible by this graphics context.FloatColor
getColor()
Returns the color that was previously set viasetColor()
.int
getIntColor()
Returns the color previously set viasetIntColor(int)
.java.awt.Rectangle
getModifiedArea()
Returns a which is as small as possible and which, for every pixelRectangle iRect
(n,m)
modified since the last call tostartModifiedAreaCalculation(iRect)
, returnstrue
in the call toiRect.contains(n,m)
.void
setClip(ClipRectangle clip)
The clip determines how much of an object [to be rendered] is visible.void
setColor(FloatColor color)
For drawing points, drawing lines, and filling polygons, how non-opaque colors are handled is up to the implementation of this interface.void
setIntColor(int color)
Sets the ARGB color directly, for more control in native representation.void
setRectClip(java.awt.Rectangle rect)
Sets the clip area to be such that only pixels(n,m)
for which are allowed to be modified.rect.contains(n,m) == true
void
startModifiedAreaCalculation(java.awt.Rectangle rect)
Starts a modified area calculation ifrect
is not null, or stops such a calculation ifrect
is null.
-
-
-
Constructor Detail
-
RasterFloatGraphics
public RasterFloatGraphics(int[] pix, int width, int height)
Arraypix
will be used to store pixel information; the array's length must therefore be at leastwidth*height
.Orientation:
. The values stored inimagePixel(x,y) = pix[y*width + x]
pix
represent color in the ARGB format: in each 32 bit integer, bits 24-31 (the high bits) are alpha, bits 16-23 are red, bits 8-15 are green, and bits 0-7 (the low bits) are blue. For example, an integer0xff0000ff
represents the fully opaque color bright blue.Pixel data is written through; no alpha blending is done. For custom alpha blending logic, you must subclass
RasterFloatPixBuff
and use the other constructor.- See Also:
RasterFloatGraphics(RasterFloatPixBuff)
-
RasterFloatGraphics
public RasterFloatGraphics(RasterFloatPixBuff pixBuff)
Exposes a level of abstraction for deciding on how to handle turning on of pixels; in particular this way of constructing the graphics context potentially gives it the capability for handling translucent colors.
-
-
Method Detail
-
startModifiedAreaCalculation
public void startModifiedAreaCalculation(java.awt.Rectangle rect)
Starts a modified area calculation ifrect
is not null, or stops such a calculation ifrect
is null. If either ofrect.width
orrect.height
are positive nonzero, thenrect
will be used to represent the initial area that has been modified. CallgetModifiedArea()
after any sequence of drawing operations to get an area that has been modified since this method was last called. Please note that no copy of input rectangle is made; it is kept by reference.There is a tiny bit of extra overhead in calculating the modified area in each of the drawing operations; these calculations are only performed if
rect
isn't null.- See Also:
getModifiedArea()
-
getModifiedArea
public java.awt.Rectangle getModifiedArea()
Returns a which is as small as possible and which, for every pixelRectangle iRect
(n,m)
modified since the last call tostartModifiedAreaCalculation(iRect)
, returnstrue
in the call toiRect.contains(n,m)
. (If the initialstartModifiedAreaCalculation()
rectangle represented a nonempty area, then all pixel points contained in that rectangle count as modified as well).The return value is equal by reference to the rectangle that was previously passed into
startModifiedAreaCalculation()
. Returns null if no modified area calculations are taking place.- See Also:
startModifiedAreaCalculation(Rectangle)
-
setColor
public void setColor(FloatColor color)
Description copied from interface:FloatGraphics
For drawing points, drawing lines, and filling polygons, how non-opaque colors are handled is up to the implementation of this interface.- Specified by:
setColor
in interfaceFloatGraphics
-
getColor
public FloatColor getColor()
Description copied from interface:FloatGraphics
Returns the color that was previously set viasetColor()
.- Specified by:
getColor
in interfaceFloatGraphics
-
setIntColor
public void setIntColor(int color)
Sets the ARGB color directly, for more control in native representation. High bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue. For example, bright opaque green is0xff00ff00
.
-
getIntColor
public int getIntColor()
Returns the color previously set viasetIntColor(int)
.
-
setClip
public void setClip(ClipRectangle clip)
Description copied from interface:FloatGraphics
The clip determines how much of an object [to be rendered] is visible. The clip does not necessarily force objects to be clipped against it before they are rendered; rather, you can think of objects being rendered onto an infinite [blank] canvas, with the clip being applied to the canvas to determine how much of the object is visible; the visible portion would then be actually painted. This principle is important for objects such as lines, for example, which are represented by an infinitely thin concept but may, when rendered, have some thickness.setClip(null)
sets the clip to the maximum possible area that is visible by this context.- Specified by:
setClip
in interfaceFloatGraphics
-
setRectClip
public void setRectClip(java.awt.Rectangle rect)
Sets the clip area to be such that only pixels(n,m)
for which are allowed to be modified. Basically an invocation makes the following call internally:rect.contains(n,m) == true
setClip(rect == null ? null : new ClipRectangle(rect.x, rect.y, rect.x + Math.max(0, rect.width), rect.y + Math.max(0, rect.height)));
This method is compatible with
getModifiedArea()
in thatsetRectClip(getModifiedArea())
will set the clip to be exactly the smallest possible rectangle which contains all of the modified pixels.
-
getClip
public ClipRectangle getClip()
Description copied from interface:FloatGraphics
The return value of this method is not necessarily equal to the clip previously set bysetClip()
; the clip returned here is no larger than the entire area that is visible by this graphics context.For example, to find out the maximum possible area that is visible by this context, first
setClip(null)
and then inspect the return value of this method.This method never returns null.
- Specified by:
getClip
in interfaceFloatGraphics
-
clear
public void clear()
Description copied from interface:FloatGraphics
Paints the current clip area with the current color. This is not necessarily equivalent to filling a rectangle of clip area becauseclear()
is required to clobber all visual information in the current clip, whereas filling a polygon may handle transparent or translucent colors in a special way.- Specified by:
clear
in interfaceFloatGraphics
-
drawPoint
public void drawPoint(double x, double y)
Affects exactly one pixel, assuming that it's not outside of the clip area. The decision of which pixel to affect interplays well withfillPolygon()
. InfillPolygon()
, pixel(i,j)
is turned on if and only if the polygon "contains" imaginary point(i+0.5,j+0.5)
, where the "contains" is necessarily open on the upper bound and isn't necessarily open on the lower bound, for each of the x and y directions. On the other hand indrawPoint()
, pixel(i,j)
is turned on if and only if the x coordinate lies in the interval(i,i+1]
and the y coordinate lies in the interval(j,j+1]
. There are certain casts made between 64 bit floating point space and 32 bit floating point space before these comparisons are made however, in the same way that such casts take place in all of the operations (lines included) which affect pixels.- Specified by:
drawPoint
in interfaceFloatGraphics
-
drawLine
public void drawLine(double x0, double y0, double x1, double y1)
Description copied from interface:FloatGraphics
Draws a line segment between two endpoints, namely(x0,y0)
and(x1,y1)
.- Specified by:
drawLine
in interfaceFloatGraphics
-
fillPolygon
public void fillPolygon(double[] xPts, double[] yPts, int offset, int numPts)
Uses the even-odd fill rule for self-intersecting polygons.- Specified by:
fillPolygon
in interfaceFloatGraphics
-
-