public class GraphicsContext
extends java.lang.Object
GraphicsContext
class offers basic drawing facilities, to render lines, rectangles, polygons, arcs
and text.GraphicsContext
uses 24-bit RGB color. Each color: red, green and blue is defined with an 8-bit value.
GraphicsContext
object may be used either to
paint(GraphicsContext)
methods), or
Display
, the paint
method is given a
GraphicsContext
as argument and should use it to render the visible object.GraphicsContext
may be requested for a mutable image. This graphics context can be used to draw in the
image.GraphicsContext
with
Display.getNewGraphicsContext()
or Display.getNewExplicitFlush()
. Using this mechanism does not
ensure drawings will be performed before, during or after the current paint()
, since it bypasses the
serialization system events.drawChar
,
drawChars
, drawString
or drawSubstring
. Characters are drawn with the current color
of the GraphicsContext
object.(0,0), (1,0), (1,1) and (0,1)
. The call (where g is a
GraphicsContext
) g.fillRect(1,0,2,3)
paints six pixels.SOLID
or
DOTTED
. Stroke style has no effect on fill, text and image handling.SOLID
stroke style allows drawing with a one-pixel wide pen. Drawing at a specific coordinate fills
the adjacent down-right pixel. For instance, although the next line has a width of 1,
g.drawLine(0,0,1,0)
draws 2 pixels: the upper-left corner of the display and its adjacent right pixel.
DOTTED
stroke style allows drawing a subset of the pixels that would have been drawn with the
SOLID
stroke style. Length and frequency of dots is implementation dependent and, as a result, so are
the drawn pixels. Note that end of lines or end of arcs, as well as the corner of rectangles may not be drawn with
the DOTTED
stroke style.drawRect(x,y,w,h);
drawLine(x,y,x+w,y);
drawLine(x+w,y,x+w,y+h);
drawLine(x+w,y+h,x,y+h);
drawLine(x,y+h,x,y);
fillRect(x,y,w,h);
drawRect(x,y,w,h)
. Indeed,
the filled area counts w*h
pixels, whereas the area delimited by drawRect(x,y,w,h)
counts
(w+1)*(h+1)
pixels.drawLine()
and drawArc()
are implementation
dependent.GraphicsContext
defines a clipping zone which specifies the destination area that can be modified by
calls to the GraphicsContext
. The clipping zone can be set by the application but is more commonly set
by the UI framework. The clipping zone may be empty (i.e. its size is zero), in that case, every rendering operation
will have no effect. It may also be out of the bounds of the destination, in which case every rendering operation out
of the range of the destination is ignored. Modification of the coordinate system (with the method
translate
for instance) has no effect on the clipping zone.(x,y)
location or anchor point is used. In addition it is possible to express how the object is set around the anchor
point. Several constants have been thus defined; they can be combined bit-wise to precisely define how the object is
set around the anchor point. For instance,g.drawString("test",x,y,TOP|LEFT);
(x,y)
as the upper left point of the text zone.g.drawString("test",x,y,TOP|HCENTER);
"test"
above and centered on (x,y)
.LEFT
,
HCENTER
, RIGHT
) and one of the vertical constants (TOP
, BASELINE
for text positioning exclusively, VCENTER
, BOTTOM
). The default anchor position, obtained
with value 0
, matches the TOP | LEFT
constant combination.Modifier and Type | Field and Description |
---|---|
static int |
BASELINE
Constant for positioning the baseline of the text at the anchor point.
|
static int |
BOTTOM
Constant for positioning the bottom of the drawing at the anchor point.
|
static int |
DOTTED
Constant for the
DOTTED stroke style. |
static int |
HCENTER
Constant for centering drawing horizontally around the anchor point.
|
static int |
HCENTER_BOTTOM
Equivalent to
HCENTER | BOTTOM . |
static int |
HCENTER_TOP
Equivalent to
HCENTER | TOP . |
static int |
HCENTER_VCENTER
Equivalent to
HCENTER | VCENTER . |
static int |
LEFT
Constant for positioning the left side of the drawing at the anchor point.
|
static int |
LEFT_BOTTOM
Equivalent to
LEFT | BOTTOM . |
static int |
LEFT_TOP
Equivalent to
LEFT | TOP . |
static int |
LEFT_VCENTER
Equivalent to
LEFT | VCENTER . |
static int |
OPAQUE
Maximal opacity.
|
static int |
RIGHT
Constant for positioning the right side of the drawing at the anchor point.
|
static int |
RIGHT_BOTTOM
Equivalent to
RIGHT | BOTTOM . |
static int |
RIGHT_TOP
Equivalent to
RIGHT | TOP . |
static int |
RIGHT_VCENTER
Equivalent to
RIGHT | VCENTER . |
static int |
SOLID
Constant for the
SOLID stroke style. |
static int |
TOP
Constant for positioning the top of the drawing at the anchor point.
|
static int |
TRANSPARENT
Minimal opacity.
|
static int |
VCENTER
Constant for centering the drawing vertically around the anchor point.
|
Modifier and Type | Method and Description |
---|---|
void |
clipRect(int x,
int y,
int width,
int height)
Sets the clipping area to be the intersection of the specified rectangle with the current clipping rectangle.
|
void |
drawChar(char character,
int x,
int y,
int anchor)
Draws a character using the current font and color.
The text anchor point is at position (x,y) . |
void |
drawChars(char[] data,
int offset,
int length,
int x,
int y,
int anchor)
Draws some characters using the current font and color.
The text anchor point is at position (x,y) . |
void |
drawCircle(int x,
int y,
int diameter)
Draws the outline of a circle covering the rectangle specified by its diameter, using the current color and
stroke style.
|
void |
drawCircleArc(int x,
int y,
int diameter,
int startAngle,
int arcAngle)
Draws the outline of a circular arc covering the specified square, using the current color and stroke style.
|
void |
drawEllipse(int x,
int y,
int width,
int height)
Draws the outline of a ellipse covering the specified rectangle, using the current color and stroke style.
|
void |
drawEllipseArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Draws the outline of a elliptical arc covering the specified rectangle, using the current color and stroke style.
|
void |
drawHorizontalLine(int x,
int y,
int width)
Draws an horizontal line from
(x,y) to (x+width,y) using the current color and stroke
style. |
void |
drawImage(Image img,
int x,
int y,
int anchor)
Draws an image at the given anchor point.
|
void |
drawImage(Image img,
int x,
int y,
int anchor,
int alpha)
Draws an image at the given anchor point.
|
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line from
(x1,y1) to (x2,y2) using the current color and stroke style. |
void |
drawPixel(int x,
int y)
Draws a pixel at
(x,y) using the current color. |
void |
drawPolygon(int[] xys)
Draws the closed polygon which is defined by the array of integer coordinates, using the current color and stroke
style.
|
void |
drawPolygon(int[] xys,
int offset,
int length)
Draws the closed polygon which is defined by the array of integer coordinates, using the current color and stroke
style.
|
void |
drawRect(int x,
int y,
int width,
int height)
Draws the outline of the specified rectangle using the current color and stroke style.
|
void |
drawRegion(Display display,
int xSrc,
int ySrc,
int width,
int height,
int xDest,
int yDest,
int anchor)
Draws a region of a display.
|
void |
drawRegion(Display display,
int xSrc,
int ySrc,
int width,
int height,
int xDest,
int yDest,
int anchor,
int alpha)
Draws a region of a display.
|
void |
drawRegion(Image src,
int xSrc,
int ySrc,
int width,
int height,
int xDest,
int yDest,
int anchor)
Draws a region of an image.
|
void |
drawRegion(Image src,
int xSrc,
int ySrc,
int width,
int height,
int xDest,
int yDest,
int anchor,
int alpha)
Draws a region of an image.
|
void |
drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Draws the outline of the specified rounded corner rectangle using the current color and stroke style.
|
void |
drawString(java.lang.String str,
int x,
int y,
int anchor)
Draws the string using the current font and color.
The text anchor point is at position (x,y) . |
void |
drawSubstring(java.lang.String str,
int offset,
int len,
int x,
int y,
int anchor)
Draws the string from
offset to offset+length using the current font and color. |
void |
drawVerticalLine(int x,
int y,
int height)
Draws a vertical line from
(x,y) to (x,y+height-1) using the current color and stroke
style. |
void |
fillCircle(int x,
int y,
int diameter)
Fills a circle covering the rectangle specified by its diameter with the current color.
|
void |
fillCircleArc(int x,
int y,
int diameter,
int startAngle,
int arcAngle)
Fills a circular arc covering the specified square with the current color.
|
void |
fillEllipse(int x,
int y,
int width,
int height)
Fills a ellipse covering the specified rectangle with the current color.
|
void |
fillEllipseArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Fills an elliptical arc covering the specified rectangle with the current color.
|
void |
fillPolygon(int[] xys)
Fills the closed polygon which is defined by the array of integer coordinates, using the current color.
|
void |
fillPolygon(int[] xys,
int offset,
int length)
Fills the closed polygon which is defined by the array of integer coordinates, using the current color.
|
void |
fillRect(int x,
int y,
int width,
int height)
Fills the specified rectangle with the current color.
|
void |
fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Fills the specified rounded corner rectangle with the current color.
|
static int |
getAlpha(int opacityPercent)
Gets the alpha level for the given opacity.
|
void |
getARGB(int[] argbData,
int offset,
int scanlength,
int x,
int y,
int width,
int height)
Obtains ARGB pixel data from the specified region of this graphics context and stores it in the provided array of
integers.
|
int |
getBackgroundColor()
Gets the current background color.
|
int |
getClipHeight()
Gets the height of the current clipping zone.
|
int |
getClipWidth()
Gets the width of the current clipping zone.
|
int |
getClipX()
Gets the x offset of the current clipping zone, relative to the graphics context's origin.
|
int |
getClipY()
Gets the y offset of the current clipping zone, relative to graphics context's origin.
|
int |
getColor()
Gets the current color: a 24-bits value interpreted as:
0xRRGGBB , that is, the eight least
significant bits give the blue color, the next eight bits the green value and the next eight bits the red color. |
Display |
getDisplay()
Gets the display associated with the GraphicsContext.
|
int |
getDisplayColor(int color)
Gets the color that will be displayed if the specified color is requested.
For example, with a monochrome display, this method will return either 0xFFFFFF (white) or 0x000000 (black) depending on the brightness of the specified color. |
boolean |
getEllipsis()
Gets whether the truncation mechanism is enabled or not.
|
Font |
getFont()
Gets the current font.
|
int |
getStrokeStyle()
|
int |
getTranslateX()
Gets the x coordinate of the translated origin of the graphics context.
|
int |
getTranslateY()
Gets the y coordinate of the translated origin of the graphics context.
|
boolean |
hasBackgroundColor()
Gets whether there us a background color.
|
int |
readPixel(int x,
int y)
Obtains the ARGB color of the pixel at
(x,y) . |
void |
removeBackgroundColor()
Removes the current background color.
|
void |
setBackgroundColor(int rgbColor)
Sets the current background color.
Given value rgbColor is interpreted as a 24-bit RGB color, where the eight least significant bits
matches the blue component, the next eight more significant bits matches the green component and the next eight
more significant bits matches the red component.The background color is used by several drawings: draw text, draw anti-aliased line etc. |
void |
setClip(int x,
int y,
int width,
int height)
Sets the current clipping zone to the rectangle defined by the given location
(x,y) and size
(width,height) . |
void |
setColor(int rgbColor)
Sets the current color.
Given value rgbColor is interpreted as a 24-bit RGB color, where the eight least significant bits
matches the blue component, the next eight more significant bits matches the green component and the next eight
more significant bits matches the red component. |
void |
setEllipsis(boolean enable)
Enables (disables) truncation when rendering characters.
|
void |
setFont(Font font)
Sets the font for subsequent text operations.
|
void |
setStrokeStyle(int style)
Sets the stroke style of this graphics context.
|
void |
translate(int x,
int y)
Translates the
GraphicsContext origin with the given vector (x,y) . |
public static final int HCENTER
Value 1
is assigned to HCENTER
.
public static final int VCENTER
Value 2
is assigned to VCENTER
.
public static final int LEFT
Value 4
is assigned to LEFT
.
public static final int RIGHT
Value 8
is assigned to RIGHT
.
public static final int TOP
Value 16
is assigned to TOP
.
public static final int BOTTOM
Value 32
is assigned to BOTTOM
.
public static final int BASELINE
Value 64
is assigned to BASELINE
.
public static final int LEFT_TOP
LEFT | TOP
.public static final int LEFT_VCENTER
LEFT | VCENTER
.public static final int LEFT_BOTTOM
LEFT | BOTTOM
.public static final int HCENTER_TOP
HCENTER | TOP
.public static final int HCENTER_VCENTER
HCENTER | VCENTER
.public static final int HCENTER_BOTTOM
HCENTER | BOTTOM
.public static final int RIGHT_TOP
RIGHT | TOP
.public static final int RIGHT_VCENTER
RIGHT | VCENTER
.public static final int RIGHT_BOTTOM
RIGHT | BOTTOM
.public static final int SOLID
SOLID
stroke style.
Value 0
is assigned to SOLID
.
public static final int DOTTED
DOTTED
stroke style.
Value 1
is assigned to DOTTED
.
public static final int OPAQUE
drawImage(Image, int, int, int, int)
,
Constant Field Valuespublic static final int TRANSPARENT
drawImage(Image, int, int, int, int)
,
Constant Field Valuespublic static int getAlpha(int opacityPercent)
It can be used to draw transparent images.
opacityPercent
- the expected opacity in percentage.drawImage(Image, int, int, int, int)
public final void translate(int x, int y)
GraphicsContext
origin with the given vector (x,y)
. Subsequent rendering
operations on the graphics context will be relative to the new origin.
This method can be used to set an absolute origin to a GraphicsContext
. For instance, the following
code:
g.translate(ax-g.getTranslateX(),ay-g.getTranslateY());
will set the origin of g
at (ax,ay)
.
x
- the translation for the x coordinate.y
- the translation for the y coordinate.public final int getTranslateX()
public final int getTranslateY()
public final void setColor(int rgbColor)
rgbColor
is interpreted as a 24-bit RGB color, where the eight least significant bits
matches the blue component, the next eight more significant bits matches the green component and the next eight
more significant bits matches the red component.rgbColor
- the color to set.public final void setBackgroundColor(int rgbColor)
rgbColor
is interpreted as a 24-bit RGB color, where the eight least significant bits
matches the blue component, the next eight more significant bits matches the green component and the next eight
more significant bits matches the red component.rgbColor
- the color to set.public final void removeBackgroundColor()
public final int getColor()
0xRRGGBB
, that is, the eight least
significant bits give the blue color, the next eight bits the green value and the next eight bits the red color.public final int getBackgroundColor()
public final boolean hasBackgroundColor()
true
if there is a background color, false
otherwise.public final int getDisplayColor(int color)
color
- the desired color in 0x00RRGGBB format.public final void setStrokeStyle(int style)
public final int getStrokeStyle()
public void setFont(Font font)
null
, the
GraphicsContext
's font is set to DisplayFont.getDefaultFont()
.font
- the new font to use.public final Font getFont()
public final void clipRect(int x, int y, int width, int height)
x
- the x coordinate of the rectangle.y
- the y coordinate of the rectangle.width
- the width of the rectangle.height
- the height of the rectangle.public final void setClip(int x, int y, int width, int height)
(x,y)
and size
(width,height)
. Given width or height may be zero or negative, in that case the clip is considered
to be empty, i.e. it contains no pixels. Nothing is done when drawing in an empty clip. Rendering operations have
no effect outside of the clipping area.x
- the x coordinate of the new clip rectangle.y
- the y coordinate of the new clip rectangle.width
- the width of the new clip rectangle.height
- the height of the new clip rectangle.public final int getClipX()
public final int getClipY()
public final int getClipWidth()
public final int getClipHeight()
public final void drawPixel(int x, int y)
(x,y)
using the current color.x
- the x coordinate of the pixel.y
- the y coordinate of the pixel.public final int readPixel(int x, int y)
(x,y)
. The read color may be different than the drawing
color. It is screen dependent, according to the number of bits per pixels (see Display.getBPP()
).x
- the x coordinate of the pixel.y
- the y coordinate of the pixel.java.lang.IllegalArgumentException
- if the pixel coordinates are out of bounds of the source graphics context.public final void drawHorizontalLine(int x, int y, int width)
(x,y)
to (x+width,y)
using the current color and stroke
style. The drawn line counts (width+1)
pixels.width
is negative, nothing is drawn.x
- the x coordinate of the start of the line.y
- the y coordinate of the start of the line.width
- the width of the horizontal line to draw.public final void drawVerticalLine(int x, int y, int height)
(x,y)
to (x,y+height-1)
using the current color and stroke
style. The drawn line counts (height+1)
pixels.height
is negative, nothing is drawn.x
- the x coordinate of the start of the line.y
- the y coordinate of the start of the line.height
- the width of the vertical line to draw.public final void drawLine(int x1, int y1, int x2, int y2)
(x1,y1)
to (x2,y2)
using the current color and stroke style.x1
- the x coordinate of the start of the line.y1
- the y coordinate of the start of the line.x2
- the x coordinate of the end of the line.y2
- the y coordinate of the end of the line.public final void drawRect(int x, int y, int width, int height)
(width+1)*(height+1)
pixels.width
or height
is negative, nothing is drawn.x
- the x coordinate of the rectangle to draw.y
- the y coordinate of the rectangle to draw.width
- the width of the rectangle to draw.height
- the height of the rectangle to draw.public final void fillRect(int x, int y, int width, int height)
width
or height
is
negative or zero, nothing is drawn.x
- the x coordinate of the rectangle to be filled.y
- the y coordinate of the rectangle to be filled.width
- the width of the rectangle to be filled.height
- the height of the rectangle to be filled.public final void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
width+1
-pixel wide and height+1
-pixel high. If either width
or height
is negative, nothing is drawn.x
- the x coordinate of the rectangle to draw.y
- the y coordinate of the rectangle to draw.width
- the width of the rectangle to draw.height
- the height of the rectangle to draw.arcWidth
- the horizontal diameter of the arc at the corners.arcHeight
- the vertical diameter of the arc at the corners.public final void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
width
or
height
is negative or zero, nothing is drawn.x
- the x coordinate of the rectangle to fill.y
- the y coordinate of the rectangle to fill.width
- the width of the rectangle to fill.height
- the height of the rectangle to fill.arcWidth
- the horizontal diameter of the arc at the corners.arcHeight
- the vertical diameter of the arc at the corners.public final void drawPolygon(int[] xys)
xys
- the array of coordinates : x1,y1,......xn,yn.java.lang.NullPointerException
- if the given array is null
.java.lang.IllegalArgumentException
- if the given array length is odd.public final void drawPolygon(int[] xys, int offset, int length)
xys
- the array of coordinates : x1,y1,......xn,yn.offset
- the x1
index in xys
.length
- the number of coordinates, must be even.java.lang.NullPointerException
- if the given array is null
.java.lang.IllegalArgumentException
- if the given array length is odd.java.lang.ArrayIndexOutOfBoundsException
- the wanted data is outside the array bounds.public final void fillPolygon(int[] xys)
fillPolygon(xys,0,xys.length);
xys
- the array of coordinates : x1,y1,......xn,yn.java.lang.NullPointerException
- if the given array is null
.java.lang.IllegalArgumentException
- if the given array length is odd.public final void fillPolygon(int[] xys, int offset, int length)
fillPolygon(xys,0,xys.length);
xys
- the array of coordinates : x1,y1,......xn,yn.offset
- the x1
index in xys
.length
- the number of coordinates, must be even.java.lang.ArrayIndexOutOfBoundsException
- if offset
and length
do not specify a valid range within xys
.java.lang.NullPointerException
- if the xys
array is null.java.lang.IllegalArgumentException
- if the xys
length is odd.public final void drawCircleArc(int x, int y, int diameter, int startAngle, int arcAngle)
The arc is drawn from startAngle
up to arcAngle
degrees. The center of the arc is
defined as the center of the rectangle whose origin is at (x,y)
(upper-left corner) and whose
dimension is given by diameter
.
Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation.
If the given diameter is negative, nothing is drawn.
The angles are given relative to the rectangle. For instance an angle of 45 degrees is always defined by the line from the center of the rectangle to the upper right corner of the rectangle. Thus for a non squarred rectangle angles are skewed along either height or width.
x
- the x coordinate of the upper-left corner of the rectangle where the arc is drawny
- the y coordinate of the upper-left corner of the rectangle where the arc is drawndiameter
- the diameter of the arc to drawstartAngle
- the beginning angle of the arc to drawarcAngle
- the angular extent of the arc from startAngle
public final void drawEllipseArc(int x, int y, int width, int height, int startAngle, int arcAngle)
The arc is drawn from startAngle
up to arcAngle
degrees. The center of the arc is
defined as the center of the rectangle whose origin is at (x,y)
(upper-left corner) and whose
dimension is given by width
and height
.
Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation.
If either the given width or height is negative, nothing is drawn.
The angles are given relative to the rectangle. For instance an angle of 45 degrees is always defined by the line from the center of the rectangle to the upper right corner of the rectangle. Thus for a non squarred rectangle angles are skewed along either height or width.
x
- the x coordinate of the upper-left corner of the rectangle where the arc is drawny
- the y coordinate of the upper-left corner of the rectangle where the arc is drawnwidth
- the width of the arc to drawheight
- the height of the arc to drawstartAngle
- the beginning angle of the arc to drawarcAngle
- the angular extent of the arc from startAngle
public final void fillCircleArc(int x, int y, int diameter, int startAngle, int arcAngle)
The arc is drawn from startAngle
up to arcAngle
degrees. The center of the arc is
defined as the center of the rectangle whose origin is at (x,y)
(upper-left corner) and whose
dimension is given by diameter
.
Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation.
This method fills the area bounded from the center of the arc to the arc itself.
If the given diameter is negative, nothing is drawn.
The angles are given relatively to the rectangle. That is to say that the angle of 45 degrees is always defined by the line from the center of the rectangle to the upper-right corner of the rectangle. Thus for a non squarred rectangle angles are skewed along either height or width.
x
- the x coordinate of the upper-left corner of the rectangle where the arc is filled.y
- the y coordinate of the upper-left corner of the rectangle where the arc is filled.diameter
- the diameter of the arc to fillstartAngle
- the beginning angle of the arc to drawarcAngle
- the angular extent of the arc from startAngle
public final void fillEllipseArc(int x, int y, int width, int height, int startAngle, int arcAngle)
The arc is drawn from startAngle
up to arcAngle
degrees. The center of the arc is
defined as the center of the rectangle whose origin is at (x,y)
(upper-left corner) and whose
dimension is given by width
and height
.
Angles are interpreted such that 0 degrees is at the 3 o'clock position. A positive value indicates a counter-clockwise rotation while a negative value indicates a clockwise rotation.
This method fills the area bounded from the center of the arc to the arc itself.
If either the given width or height is negative, nothing is drawn.
The angles are given relatively to the rectangle. That is to say that the angle of 45 degrees is always defined by the line from the center of the rectangle to the upper-right corner of the rectangle. Thus for a non squared rectangle angles are skewed along either height or width.
x
- the x coordinate of the upper-left corner of the rectangle where the arc is filled.y
- the y coordinate of the upper-left corner of the rectangle where the arc is filled.width
- the width of the arc to fill.height
- the height of the arc to fill.startAngle
- the beginning angle of the arc to draw.arcAngle
- the angular extent of the arc from the given start angle.public final void drawCircle(int x, int y, int diameter)
The center of the circle is defined as the center of the rectangle whose origin is at the given coordinates (upper-left corner) and whose dimension is given by the diameter parameter.
If the given diameter is negative, nothing is drawn.
x
- the x coordinate of the upper-left corner of the rectangle where the circle is drawn.y
- the y coordinate of the upper-left corner of the rectangle where the circle is drawn.diameter
- the diameter of the circle to draw.public final void fillCircle(int x, int y, int diameter)
The center of the circle is defined as the center of the rectangle whose origin is at the given coordinates (upper-left corner) and whose dimension is given by the diameter parameter.
If the given diameter is negative, nothing is drawn.
x
- the x coordinate of the upper-left corner of the rectangle where the circle is filled.y
- the y coordinate of the upper-left corner of the rectangle where the circle is filled.diameter
- the diameter of the circle to fill.public final void drawEllipse(int x, int y, int width, int height)
The center of the ellipse is defined as the center of the rectangle whose origin is at the given coordinates (upper-left corner) and whose dimension is given by the width and height parameters.
If either the given width or height is negative, nothing is drawn.
x
- the x coordinate of the upper-left corner of the rectangle where the ellipse is drawn.y
- the y coordinate of the upper-left corner of the rectangle where the ellipse is drawn.width
- the width of the ellipse to draw.height
- the height of the ellipse to draw.public final void fillEllipse(int x, int y, int width, int height)
The center of the ellipse is defined as the center of the rectangle whose origin is at the given coordinates (upper-left corner) and whose dimension is given by the width and height parameters.
If either the given width or height is negative, nothing is drawn.
x
- the x coordinate of the upper-left corner of the rectangle where the ellipse is filled.y
- the y coordinate of the upper-left corner of the rectangle where the ellipse is filled.width
- the width of the ellipse to fill.height
- the height of the ellipse to fill.public final void drawImage(Image img, int x, int y, int anchor)
The image anchor point is at the given position. Position constants may be given to specify the precise location of the image around the anchor point.
Equivalent to calling drawImage(Image, int, int, int, int)
with OPAQUE
as alpha.
img
- the image to draw.x
- the x coordinate of the anchor point.y
- the y coordinate of the anchor point.anchor
- position of the image around the anchor point.java.lang.IllegalArgumentException
- if the given anchor is not a valid value (BASELINE
is illegal).java.lang.NullPointerException
- if the given image is null
.public final void drawImage(Image img, int x, int y, int anchor, int alpha)
drawImage(Image, int, int, int)
, this method
allows to specify the global opacity value to apply during the image rendering.img
- the image to draw.x
- the x coordinate of the anchor point.y
- the y coordinate of the anchor point.anchor
- position of the image around the anchor point.alpha
- the global opacity rendering value.java.lang.IllegalArgumentException
- if the given anchor is not a valid value (BASELINE
is illegal).java.lang.IllegalArgumentException
- if the given alpha is not a value between TRANSPARENT
and OPAQUE
.java.lang.NullPointerException
- if the given image is null
.public final void drawRegion(Image src, int xSrc, int ySrc, int width, int height, int xDest, int yDest, int anchor)
Equivalent to calling drawRegion(Image, int, int, int, int, int, int, int, int)
with OPAQUE
as
alpha.
src
- the image to copy from.xSrc
- the x coordinate of the upper-left corner of the region to copy.ySrc
- the y coordinate of the upper-left corner of the region to copy.width
- the width of the region to copy.height
- the height of the region to copy.xDest
- the x coordinate of the anchor point in the destination.yDest
- the y coordinate of the anchor point in the destination.anchor
- the position of the region around the anchor point.java.lang.NullPointerException
- if the given image is null
.java.lang.IllegalArgumentException
- if the given anchor is not a valid value (BASELINE
is illegal).public final void drawRegion(Image src, int xSrc, int ySrc, int width, int height, int xDest, int yDest, int anchor, int alpha)
The region of the image to draw is given relative to the image (origin at the upper-left corner) as a rectangle.
The image region anchor point in destination is at the given relative position. Position constants may be given to specify the precise location of the image around the anchor point.
If the specified source region exceeds the image bounds, the copied region is limited to the image boundary. If the copied region goes out of the bounds of the graphics context area, pixels out of the range will not be drawn.
This method allows to specify the opacity value to apply during the image rendering.
src
- the image to copy from.xSrc
- the x coordinate of the upper-left corner of the region to copy.ySrc
- the y coordinate of the upper-left corner of the region to copy.width
- the width of the region to copy.height
- the height of the region to copy.xDest
- the x coordinate of the anchor point in the destination.yDest
- the y coordinate of the anchor point in the destination.anchor
- the position of the region around the anchor point.alpha
- the alpha to apply to the region.java.lang.NullPointerException
- if the given image is null
.java.lang.IllegalArgumentException
- if the given anchor is not a valid value (BASELINE
is illegal).java.lang.IllegalArgumentException
- if the given alpha is not a value between TRANSPARENT
and OPAQUE
.public void drawRegion(Display display, int xSrc, int ySrc, int width, int height, int xDest, int yDest, int anchor)
Equivalent to calling drawRegion(Display, int, int, int, int, int, int, int, int)
with OPAQUE
as alpha.
display
- the display to copy from.xSrc
- the x coordinate of the upper-left corner of the region to copy.ySrc
- the y coordinate of the upper-left corner of the region to copy.width
- the width of the region to copy.height
- the height of the region to copy.xDest
- the x coordinate of the anchor point in the destination.yDest
- the y coordinate of the anchor point in the destination.anchor
- the position of the region around the anchor point.java.lang.NullPointerException
- if the given display is null
.java.lang.IllegalArgumentException
- if the given anchor is not a valid value (BASELINE
is illegal).Display.getScreenshot()
,
Display.getScreenshot(int, int, int, int)
public void drawRegion(Display display, int xSrc, int ySrc, int width, int height, int xDest, int yDest, int anchor, int alpha)
The region of the display to draw is given relative to the display (origin at the upper-left corner) as a rectangle.
If the specified source region exceeds the image bounds, the copied region is limited to the image boundary. If the copied region goes out of the bounds of the graphics context area, pixels out of the range will not be drawn.
This method allows to specify the opacity value to apply during the display content rendering.
display
- the display to copy from.xSrc
- the x coordinate of the upper-left corner of the region to copy.ySrc
- the y coordinate of the upper-left corner of the region to copy.width
- the width of the region to copy.height
- the height of the region to copy.xDest
- the x coordinate of the anchor point in the destination.yDest
- the y coordinate of the anchor point in the destination.anchor
- the position of the region around the anchor point.alpha
- the alpha to apply to the region.java.lang.NullPointerException
- if the given display is null
.java.lang.IllegalArgumentException
- if the given anchor is not a valid value (BASELINE
is illegal).java.lang.IllegalArgumentException
- if the given alpha is not a value between TRANSPARENT
and OPAQUE
.Display.getScreenshot()
,
Display.getScreenshot(int, int, int, int)
public final void getARGB(int[] argbData, int offset, int scanlength, int x, int y, int width, int height)
Color values may be resampled to reflect the display capabilities of the device (for example, red, green or blue pixels may all be represented by the same gray value on a grayscale device).
The scan length specifies the relative offset within the array between the corresponding pixels of consecutive rows. In order to prevent rows of stored pixels from overlapping, the absolute value of scan length must be greater than or equal to the given width. Negative values of scan length are allowed. In all cases, this must result in every reference being within the bounds of the ARGB pixel data array.
argbData
- an array of integers in which the ARGB pixel data is stored.offset
- the index into the array where the first ARGB value is stored.scanlength
- the relative offset in the array between corresponding pixels in consecutive rows of the region.x
- the x-coordinate of the upper left corner of the region.y
- the y-coordinate of the upper left corner of the region.width
- the width of the region.height
- the height of the region.java.lang.ArrayIndexOutOfBoundsException
- if the requested operation would attempt to access an element in the given ARGB pixel data array
whose index is either negative or beyond its length (the contents of the array are unchanged).java.lang.IllegalArgumentException
- if the area being retrieved exceeds the bounds of the source graphics context.java.lang.IllegalArgumentException
- if the absolute value of the given scan length is less than the given width.java.lang.NullPointerException
- if the given ARGB pixel data is @{code null}.public final void drawString(java.lang.String str, int x, int y, int anchor)
(x,y)
. Position constants may be given to specify the precise
location of the text around the anchor point.
See GraphicsContext
for details of anchors.
str
- the string to draw.x
- the x coordinate of the anchor point.y
- the y coordinate of the anchor point.anchor
- position of the text around the anchor point.java.lang.NullPointerException
- if the given string is null
.java.lang.IllegalArgumentException
- if anchor is not a valid value.public final void drawSubstring(java.lang.String str, int offset, int len, int x, int y, int anchor)
offset
to offset+length
using the current font and color.
The text anchor point is at position (x,y)
. Position constants may be given to specify the precise
location of the text around the anchor point.
See GraphicsContext
for details of anchors.
str
- the string to draw.offset
- index of the first character in the string to draw.len
- number of characters to draw from the given offset.x
- the x coordinate of the anchor point.y
- the y coordinate of the anchor point.anchor
- position of the string text around the anchor point.java.lang.StringIndexOutOfBoundsException
- if the given offset and length do not specify a valid range within the given string.java.lang.IllegalArgumentException
- if anchor is not a valid value.java.lang.NullPointerException
- if the given string is null
.public final void drawChar(char character, int x, int y, int anchor)
(x,y)
. Position constants may be given to specify the precise
location of the character around the anchor point.character
- the character to draw.x
- the x coordinate of the anchor point.y
- the y coordinate of the anchor point.anchor
- position of the character around the anchor point.java.lang.IllegalArgumentException
- if the given anchor is not a valid value.public final void drawChars(char[] data, int offset, int length, int x, int y, int anchor)
(x,y)
. Position constants may be given to specify the precise
location of the text around the anchor point.data
- the array of characters to draw.offset
- offset of the first character to draw in the char array.length
- the number of characters to draw from the offset.x
- the x coordinate of the anchor point.y
- the y coordinate of the anchor point.anchor
- position of the text around the anchor point.java.lang.IndexOutOfBoundsException
- if the given offset and length do not specify a valid range within the given char array.java.lang.IllegalArgumentException
- if the given anchor is not a valid value.java.lang.NullPointerException
- if the given char array is null
.public void setEllipsis(boolean enable)
enable
- true
to enable the ellipsis mode, false
otherwise.public Display getDisplay()
public boolean getEllipsis()
true
if the truncation mechanism is enabled, false
otherwise.