java.lang.Object | |
↳ | com.neomades.graphics.Graphics |
The Graphics class handles all the drawing primitives functions that can be
called from the paint method of a CanvasScreen
. Those drawing methods
are similar to MIDP:
There are also setters to change states of various elements during the drawing:
Neomad graphics generality and philosophy:
Neomad graphics is power by openGLES and as a consequence the Graphics class inherit from all the pros and cons of OpenGLES. Thus, all drawing methods have to be used gently with good practices to not overflow communication between CPU and GPU. If one part in the rendering of the drawing area is costly, all the rendering will be penalized, and so the application.
Neomad handles the case where images are lost after a Suspend/Resume and will automatically re-upload them when the Suspend/Resume is over. You do not have to handle it yourself. To sort out this known issue with some technologies, the selected solution is to re-upload the necessary images just before the 1st drawing after the Suspend/Resume is finished (in order not to reload all textures just after the Suspend/Resume and impose a potentially long loading time before re-accessing your application). The only side effect using this method might be a few hiccups during a few seconds coming back from the Suspend/Resume but the performances should stabilize themselves quickly.
How to maximize performances of your application?
All the following needs to be taken into consideration when creating your graphic engine or needs to be considered in order to port your game from another technology to Neomad carefully. Mainly, to maximize performances, the drawing methods must be called grouped (if possible) by categories written above. More precisely, it is a good advice to regroup drawing call in three parts:
The clear(int) method must be called at the beginning of the paint method to clear the previous drawings before a new one.
Engine/Technology limitations and warnings:
Line and filled based primitives: It is very important to understand that OpenGLES isn't really designed to maximize performances for Line based primitives and filled primitives. Those functions are nevertheless present for compatibility reasons and should be efficient enough to keep performances but they aren't the core features OpenGLES is efficient with.
Image primitives: In order to draw Images and Regions, the methods use OpenGL textures to render images. The texture is created in the Image object constructor and the image data are uploaded on the GPU before the next following paint call. Please refer to the Image section to read more about OpenGLES Texture constraints. For a big number of image creations, it is a good practice to spread the texture creation/upload on several paints in order to prevent the application from running out of memory. Keep in mind that there is a need to allocate temporary heap bitmap memory to store the image to upload during the next paint. If you load a lot of Images at the time, the Bitmap memory can be easily overloaded.
To reach the best performances with Images and Regions of images, the best is to regrouping drawing calls using the same image to avoid texture swapping. The best is to create several big textures (1024x1024 for instance) containing multiple images and transferred to screen using drawRegion operations. Regroup the texture using the order they are drawn on the screen as much as you can and try only to swap the textures when necessary.
Memory management: Depending on the Image you create, the Bitmap memory might or might not be recycled (and may stay in the main heap bitmap memory). Only Images coming from resources are recycled (i.e. only images loaded with the resource manager). Otherwise, the bitmap is kept in memory in order to reload textures in case of application Suspend/Resume. So loading images by resource manager is preferable for a minimum of memory usage.
String and Char functions: Draw Char and String: these methods are slower than others since the hardware rendering do not support font rendering natively. Drawing a string has the same cost than drawing a Char so draw char method should not used to draw string. Each string is loaded on the GPU as a texture and a String cache is used to optimize the rendering of string that doesn't change between frames. If you want to draw a String once every 2 frames, the best is to keep the call to draw the string but drawing it off-screen to keep the string in the caches (this will save a Bitmap/Texture creation when the String is displayed again).
In order to avoid garbage collecting, do not use the new keyword in
the paint(Graphics) method implementation. For example, do not call
"new Point(x, y)"
as parameter of graphics methods.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | DOTTED | ||||||||||
int | SOLID |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
clear(Color color)
Clears the entire graphics area to the parameter color.
| ||||||||||
void |
clear(int color)
Clear the screen with the given ARGB color.
| ||||||||||
void |
clipRect(int x, int y, int width, int height)
Set a clip region in the Screen.
| ||||||||||
void |
drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
Draws the outline of a circular or elliptical arc covering the specified
rectangle.
| ||||||||||
void |
drawArc(Rect rectangle, int startAngle, int arcAngle)
Draws the outline of a circular or elliptical arc covering the specified
rectangle, using the current color and stroke style.
| ||||||||||
void |
drawChar(char character, int x, int y, int anchor)
This method draw a char at screen coordinates x and y according to anchor.
| ||||||||||
void |
drawChar(char character, Point location, int anchor)
Draws the specified character using the current font and color.
| ||||||||||
void |
drawChars(char[] data, int offset, int length, int x, int y, int anchor)
This method draw length char of an array of char starting from position
offset at screen coordinates x and y according to anchor.
| ||||||||||
void |
drawChars(char[] data, int offset, int length, Point position, int anchor)
Draws the specified characters using the current font and color.
| ||||||||||
void |
drawImage(Image image, Point point, int anchor)
Draws an image at the given point.
| ||||||||||
void |
drawImage(Image image, int x, int y, int angle, int anchor)
Draw the specified source image at a specified destination point and
according to an anchoring mechanism.
| ||||||||||
void |
drawImage(Image image, int x, int y, int destWidth, int destHeight, int angle, int anchor)
Draw the specified source image at a specified destination using an anchor
mechanism, possibly zooming and rotating the image.
| ||||||||||
void |
drawImage(Image src, int x, int y, int anchor)
Draws the specified image by using the anchor point.
| ||||||||||
void |
drawImage(Image image, int x, int y, int destWidth, int destHeight, int anchor)
Draw the specified source image at a specified destination and according to
an anchoring mechanism.
| ||||||||||
void |
drawImage(Image image, Point p)
Draw the specified source image at the specified destination point
| ||||||||||
void |
drawImage(Image image, int xSrc, int ySrc, int width, int height, int xDest, int yDest, int anchor)
Copies a region of the specified source image at a location on screen
according to an anchor mechanism.
| ||||||||||
void |
drawImageRegion(Image image, Rect region, Point dest, int anchor)
Draws a region of the image at the given point
| ||||||||||
void |
drawImageRegion(Image src, int xSrc, int ySrc, int width, int height, int x, int y, int anchor)
Copies a region of the specified source image at a specified destination.
| ||||||||||
void |
drawImageRegion(Image image, Rect region, Point dest)
Copies a region of the specified source image at a specified destination.
| ||||||||||
void |
drawLine(Point p1, Point p2)
Draw a line segment (with a border of 1px) between two points
p1
and p2 . | ||||||||||
void |
drawLine(int x1, int y1, int x2, int y2)
Draws a line, using the current color, between the points (x1, y1) and (x2,
y2) in this graphics context's coordinate system.
| ||||||||||
void |
drawRGB(int[] rgbData, int offset, int scanlength, Rect rect, boolean processAlpha)
Treat the specified array of colors as a bitmap, and draw it.
| ||||||||||
void |
drawRGB(int[] rgbData, int offset, int scanlength, int x, int y, int width, int height, boolean processAlpha)
Treat the specified array of colors as a bitmap, and draw it.
| ||||||||||
void |
drawRect(int x, int y, int width, int height)
Draws the outline of the specified rectangle.
| ||||||||||
void |
drawRect(Rect rect)
Draw a rectangle (with a border of 1px).
| ||||||||||
void |
drawRegion(Image image, int xSrc, int ySrc, int width, int height, int transformation, int xDest, int yDest, int angle, int anchor)
Copies a region of the specified source image at a location on screen
according to an anchoring mechanism.
| ||||||||||
void |
drawRegion(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int transformation, int destX, int destY, int anchor)
Copies a region of the specified source image to a location within the
destination, possibly transforming (rotating and reflecting) the image data
using the chosen transform function.
| ||||||||||
void |
drawRegion(Image image, int xSrc, int ySrc, int width, int height, int transformation, int xDest, int yDest, int widthDest, int heightDest, int angle, int anchor)
Copies a region of the specified source image to a location within the
destination at anchor point.
| ||||||||||
void |
drawRegion(Image image, int xSrc, int ySrc, int width, int height, int transformation, int xDest, int yDest, int widthDest, int heightDest, int anchor)
Copies a region of the specified source image at a location on screen
according to an anchoring mechanism.
| ||||||||||
void |
drawRoundRect(int x, int y, int width, int height, int rx, int ry)
Draws an outlined round-cornered rectangle using this graphics context's
current color.
| ||||||||||
void |
drawRoundRect(Rect rect, int rx, int ry)
Draws an outlined round-cornered rectangle using this graphics context's
current color.
| ||||||||||
void |
drawString(String str, Point p)
Draw a string at point coordinates.
| ||||||||||
void |
drawString(String str, Point p, int anchor)
Draws a string at point coordinates according to the anchor.
| ||||||||||
void |
drawString(String str, int x, int y, int anchor)
Draw a string with at screen coordinates x and y according to anchor.
| ||||||||||
void |
drawSubstring(String str, int offset, int len, int x, int y, int anchor)
This method draws a substring of a string starting from position offset with
length len.
| ||||||||||
void |
drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
Draw a triangle using three points.
| ||||||||||
void |
drawTriangle(Point p1, Point p2, Point p3)
Draw a triangle using three points.
| ||||||||||
void |
enableColorBlending(boolean enable)
Enable or disable the color blending with the current draw color.
| ||||||||||
void |
fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
Fills a circular or elliptical arc covering the specified rectangle.
| ||||||||||
void |
fillArc(Point center, int radius, int start, int end)
Fills a circular or elliptical arc covering the specified rectangle.
| ||||||||||
void |
fillRect(Rect rect)
Draws a filled rectangle.
| ||||||||||
void |
fillRect(int x, int y, int width, int height)
Fills the specified rectangle.
| ||||||||||
void |
fillRoundRect(int x, int y, int width, int height, int rx, int ry)
Fills the specified rounded corner rectangle with the current color.
| ||||||||||
void |
fillRoundRect(Rect rect, int rw, int rh)
Fills the specified rounded corner rectangle with the current color.
| ||||||||||
void |
fillTriangle(Point p1, Point p2, Point p3)
Fills the specified triangle with the current color.
| ||||||||||
void |
fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
Fills the specified triangle with the current color.
| ||||||||||
int |
getClipHeight()
Returns the current clipping height.
| ||||||||||
int |
getClipWidth()
Returns the current clipping width.
| ||||||||||
int |
getClipX()
Gets the x offset of the current clipping area, relative to the coordinate
system origin of this graphics context.
| ||||||||||
int |
getClipY()
Gets the y offset of the current clipping area, relative to the coordinate
system origin of this graphics context.
| ||||||||||
Rect |
getClipping()
Returns the clipping area.
| ||||||||||
Color |
getColor()
Gets the current color
| ||||||||||
Font |
getFont()
Gets the current font.
| ||||||||||
Point |
getTranslate()
Gets the coordinates of the translated origin of this graphics context.
| ||||||||||
int |
getTranslateX()
Gets the x coordinate of the translated origin of this graphics context.
| ||||||||||
int |
getTranslateY()
Gets the y coordinate of the translated origin of this graphics context.
| ||||||||||
void |
reset()
Resets the clip and translate values for the current graphics.
| ||||||||||
void |
setAlphaBlending(int alpha)
Sets the alpha blending value.
| ||||||||||
void |
setClip(int x, int y, int width, int height)
Set a clip region in the Screen.
| ||||||||||
void |
setClip(Rect clipping)
Sets the clip for this graphics The clipping is reset after each paint.
| ||||||||||
void |
setColor(int red, int green, int blue)
Set the current color for all drawing methods by assing each 8 bits component
of a RGB color
| ||||||||||
void |
setColor(Color color)
Sets the current color for all drawing methods.
| ||||||||||
void |
setColor(int color)
Sets the current color for all drawing methods.
| ||||||||||
void |
setFont(Font fnt)
Sets the current font of the graphics.
| ||||||||||
void |
setStrokeStyle(int style)
Sets the stroke style used for drawing lines, arcs, rectangles, and rounded
rectangles.
| ||||||||||
void |
translate(int x, int y)
s Translates the coordinates of the origins.
| ||||||||||
void |
translate(Point p)
Translates the coordinates of the origins.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Clears the entire graphics area to the parameter color.
Note: the setColor(Color)
is not modified by this method.
color | color to draw for clear |
---|
NullPointerException | if the color parameter is null |
---|
Clear the screen with the given ARGB color. You should called this method at the beginning of the paint method to clear drawings of the previous frame.
color | the color to clear the screen as an ARGB integer with 8 bits by component. |
---|
Set a clip region in the Screen. Only drawing in the specified region will be
visible but all drawing calls will be rendered. Any previous screen
translation (translate(int, int)
) are taken into account.
x | the x coordinate of the upper left corner of the region to clip |
---|---|
y | the y coordinate of the upper left corner of the region to clip |
width | the width of the region to clip |
height | the height of the region to clip |
Draws the outline of a circular or elliptical arc covering the specified rectangle. The resulting arc begins at startAngle and extends for arcAngle degrees, using the current color. 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.
The center of the arc is the center of the rectangle whose origin is (x, y) and whose size is specified by the width and height arguments.
The resulting arc covers an area width + 1 pixels wide by height + 1 pixels tall.
The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.
x | the x coordinate of the upper-left corner of the arc to be drawn. |
---|---|
y | the y coordinate of the upper-left corner of the arc to be drawn. |
width | the width of the arc to be drawn. |
height | the height of the arc to be drawn. |
startAngle | the beginning angle. |
arcAngle | the angular extent of the arc, relative to the start angle. |
Draws the outline of a circular or elliptical arc covering the specified rectangle, using the current color and stroke style.
rectangle | the angle of the arc |
---|---|
startAngle | the start of the arc |
arcAngle | the end of the arc |
NullPointerException | if the rectangle parameter is null |
---|
This method draw a char at screen coordinates x and y according to anchor.
Note: This function is very slow when used for drawing string. You should
used instead drawString(String, Point)
or
drawChars(char[], int, int, Point, int)
.
character | character to draw |
---|---|
x | the x coordinate of the anchor point in the destination drawing area |
y | the y coordinate of the anchor point in the destination drawing area |
anchor | the anchor point for positioning the region within the destination image |
IllegalArgumentException | if the anchor is not valid |
---|
Draws the specified character using the current font and color.
character | the character to draw |
---|---|
location | destination position |
anchor | anchor point |
IllegalArgumentException | if anchor is not a legal value |
---|---|
NullPointerException | if the location parameter is null |
This method draw length char of an array of char starting from position offset at screen coordinates x and y according to anchor.
data | the array of char |
---|---|
offset | the start position in the array |
length | the number of char to draw |
x | the x coordinate of the anchor point in the destination drawing area |
y | the y coordinate of the anchor point in the destination drawing area |
anchor | the anchor point for positioning the region within the destination image |
IllegalArgumentException | if the anchor is invalid |
---|---|
NullPointerException | data is null |
Draws the specified characters using the current font and color.
The offset
and length
parameters must specify a
valid range of characters within the character array data. The
offset
parameter must be within the range
[0..(data.length)]
, inclusive.
The length
parameter must be a non-negative integer such that
(offset + length) <= data.length
.
data | the array of characters to be drawn |
---|---|
offset | the start offset in the data |
length | the number of characters to be drawn |
position | the anchor point position |
anchor | the anchor point for positioning the text |
IllegalArgumentException | if anchor is not a legal value |
---|---|
NullPointerException | if the data parameter is null |
Draws an image at the given point.
image | the image |
---|---|
point | the point where to draw the image. The top-left point of the image will be drawn at the this point |
anchor | the anchor parameter to position the image according to the destination point |
IllegalArgumentException | if anchor is not a legal value |
---|---|
NullPointerException | if the image, point parameter is null |
Draw the specified source image at a specified destination point and according to an anchoring mechanism. The image can be rotated if requested. The rotation is done according to the center of the image and the angle in degrees.
image | the source image to draw |
---|---|
x | the x coordinate of the anchor point in the destination drawing area |
y | the y coordinate of the anchor point in the destination drawing area |
angle | rotation angle in degrees. Interval is [-360, 360]. |
anchor | the anchor mechanism for positioning the image at the destination point |
Draw the specified source image at a specified destination using an anchor mechanism, possibly zooming and rotating the image. Zooming is done by setting destination width and height with different values that the original size of the image. Rotation is done according to the center of the image and the angle in degrees.
image | the source image to draw |
---|---|
x | the x coordinate of the anchor point in the destination drawing area |
y | the y coordinate of the anchor point in the destination drawing area |
destWidth | the width of the image in the drawing area. Can be different than the original width to zoom in or out. |
destHeight | the height of the image in the drawing area. Can be different than the original height to zoom in or out. |
angle | rotation angle in degrees. 2PI is 360. |
anchor | the anchor point for positioning the image within the destination image |
Draws the specified image by using the anchor point.
The image can be drawn in different positions relative to the anchor point by passing the appropriate position constants.
If the source image contains transparent pixels, the corresponding pixels in the destination image must be left untouched. If the source image contains partially transparent pixels, a compositing operation must be performed with the destination pixels, leaving all pixels of the destination image fully opaque.
src | the specified image to be drawn |
---|---|
x | the x coordinate of the anchor point |
y | the y coordinate of the anchor point |
anchor | the anchor point for positioning the image |
IllegalArgumentException | if anchor is not a legal value |
---|---|
NullPointerException | if the src parameter is null |
Draw the specified source image at a specified destination and according to an anchoring mechanism. The image can be zoomed if needed. Zooming is done by setting destination width and height with different values than the original image size.
This method uses internally
drawImage(Image, int, int, int, int, int, int)
image | the source image to draw |
---|---|
x | the x coordinate of the anchor point in the destination drawing area |
y | the y coordinate of the anchor point in the destination drawing area |
destWidth | the final width of the image when drawn on screen. Can be different than the original width to zoom in or out. |
destHeight | the final height of the image when drawn on screen. Can be different than the original height to zoom in or out. |
anchor | the anchor point for positioning the image according to the destination point |
Draw the specified source image at the specified destination point
image | the source image to draw |
---|---|
p | the destination point where to display the image (top left) |
NullPointerException | if the image or point parameter is null |
---|
Copies a region of the specified source image at a location on screen according to an anchor mechanism.
The (xSrc, ySrc) coordinates are relative to the upper left corner of the source image. The xSrc, ySrc, width, and height parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image.
The (xDest, yDest) coordinates are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.
image | the source image to copy from |
---|---|
xSrc | the x coordinate of the upper left corner of the region within the source image to copy |
ySrc | the y coordinate of the upper left corner of the region within the source image 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 drawing area |
yDest | the y coordinate of the anchor point in the destination drawing area |
anchor | the anchor parameter to position the image according to the destination point |
IllegalArgumentException | if the anchor is invalid |
---|---|
NullPointerException | if the image is null |
Draws a region of the image at the given point
image | image the image |
---|---|
region | a rectangle representing the region of image to draw |
dest | the point where to draw the image. The top-left point of the image will be drawn ath this point |
anchor | the anchor point for positioning the region within the destination image |
IllegalArgumentException | if anchor is not a legal value |
---|---|
NullPointerException |
Copies a region of the specified source image at a specified destination.
The x and y coordinates of the region are relative to the upper left corner of the source image. The region parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image.
The x and y coordinates of the destination point are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.
src | the source image to copy from |
---|---|
xSrc | the x coordinate of the upper left corner of the region within the source image to copy |
ySrc | the y coordinate of the upper left corner of the region within the source image to copy |
width | the width of the region to copy |
height | the height of the region to copy |
x | the x coordinate of the anchor point in the destination drawing area |
y | the y coordinate of the anchor point in the destination drawing area |
anchor | the anchor point for positioning the region within the destination image |
IllegalArgumentException | if anchor is not a legal value |
---|---|
NullPointerException | if the src parameter is null |
Copies a region of the specified source image at a specified destination.
The x and y coordinates of the region are relative to the upper left corner of the source image. The region parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image.
The x and y coordinates of the destination point are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.
image | the source image to copy from |
---|---|
region | the region to copy |
dest | the destination point in the drawing area |
NullPointerException | if a parameter is null |
---|
Draw a line segment (with a border of 1px) between two points p1
and p2
.
p1 | the start of the line |
---|---|
p2 | the end of the line |
NullPointerException |
---|
Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
x1 | the first point's x coordinate. |
---|---|
y1 | the first point's y coordinate. |
x2 | the second point's x coordinate. |
y2 | the second point's y coordinate. |
Treat the specified array of colors as a bitmap, and draw it. This gives the same result as first creating a bitmap from the array, and then drawing it, but this method avoids explicitly creating a bitmap object which can be more efficient if the colors are changing often.
rgbData | Array of colors representing the pixels of the bitmap |
---|---|
offset | Offset into the array of colors for the first pixel |
scanlength | The number of colors in the array between rows (must be >= width or <= -width). |
rect | the area where to draw the bitmap |
processAlpha | True if the alpha channel of the colors contains valid values. If false, the alpha byte is ignored (assumed to be 0xFF for every pixel). |
NullPointerException | if the rgbData or rect parameter is null |
---|
Treat the specified array of colors as a bitmap, and draw it. This gives the same result as first creating a bitmap from the array, and then drawing it, but this method avoids explicitly creating a bitmap object which can be more efficient if the colors are changing often.
rgbData | Array of colors representing the pixels of the bitmap |
---|---|
offset | Offset into the array of colors for the first pixel |
scanlength | The number of colors in the array between rows (must be >= width or <= -width). |
x | The X coordinate where to draw the bitmap. |
y | The Y coordinate where to draw the bitmap |
width | The width of the bitmap. |
height | The height of the bitmap |
processAlpha | True if the alpha channel of the colors contains valid values. If false, the alpha byte is ignored (assumed to be 0xFF for every pixel). |
NullPointerException | if the rgbData parameter is null |
---|
Draws the outline of the specified rectangle. The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height. The rectangle is drawn using the graphics context's current color.
x | the x coordinate of the rectangle to be drawn. |
---|---|
y | the y coordinate of the rectangle to be drawn. |
width | the width of the rectangle to be drawn. |
height | the height of the rectangle to be drawn |
Draw a rectangle (with a border of 1px).
rect | the rectangle to draw |
---|
NullPointerException |
---|
Copies a region of the specified source image at a location on screen according to an anchoring mechanism.
Possible transformations:
The (xSrc, ySrc) coordinates are relative to the upper left corner of the source image. The xSrc, ySrc, width, and height parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image.
The (xDest, yDest) coordinates are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.
The transform is applied to the image data from the region of the source image, and the result is rendered with its anchor point positioned at location (xDest, yDest) in the destination.
A free rotation in degrees can be applied in addition to the rotation specified by the transform parameter. The two rotations are added.
image | the source image to copy from |
---|---|
xSrc | the x coordinate of the upper left corner of the region within the source image to copy |
ySrc | the y coordinate of the upper left corner of the region within the source image to copy |
width | the width of the region to copy |
height | the height of the region to copy |
transformation | the desired transformation for the selected region being copied |
xDest | the x coordinate of the anchor point in the destination drawing area |
yDest | the y coordinate of the anchor point in the destination drawing area |
angle | the rotation angle in degrees. 2PI is equal to 360. |
anchor | the anchor parameter to position the image according to the destination point |
Copies a region of the specified source image to a location within the destination, possibly transforming (rotating and reflecting) the image data using the chosen transform function.
The destination, if it is an image, must not be the same image as the source image. If it is, an exception is thrown. This restriction is present in order to avoid ill-defined behaviors that might occur if overlapped, transformed copies were permitted.
The (srcX, srcY) coordinates are relative to the upper left corner of the source image. The srcX, srcY, srcWidth, and srcHeight parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image.
The (destX, destY) coordinates are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.
The transform is applied to the image data from the region of the source image, and the result is rendered with its anchor point positioned at location (destX, destY) in the destination.
image | the source image to copy from |
---|---|
srcX | the x coordinate of the upper left corner of the region within the source image to copy |
srcY | the y coordinate of the upper left corner of the region within the source image to copy |
srcWidth | the width of the region to copy |
srcHeight | the height of the region to copy |
transformation | the desired transformation for the selected region being copied |
destX | the X coordinate of the anchor point in the destination drawing area |
destY | the Y coordinate of the anchor point in the destination drawing area |
anchor | the anchor point for positioning the region within the destination image |
IllegalArgumentException | if anchor is not a legal value |
---|---|
NullPointerException | if the image parameter is null |
Copies a region of the specified source image to a location within the destination at anchor point.
Possible transformations:
The (xSrc, ySrc) coordinates are relative to the upper left corner of the source image. The xSrc, ySrc, width, and height parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image.
The (xDest, yDest) coordinates are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.
The transform is applied to the image data from the region of the source image, and the result is rendered with its anchor point positioned at location (xDest, yDest) in the destination.
The (widthDest, heightDest) size is used to specified zoom in/out of the rectangular region drawn within the destination.
A free rotation in degrees can be applied in addition to the rotation specified by the transform parameter. The two rotations are added.
image | the source image to copy from |
---|---|
xSrc | the x coordinate of the upper left corner of the region within the source image to copy |
ySrc | the y coordinate of the upper left corner of the region within the source image to copy |
width | the width of the region to copy |
height | the height of the region to copy |
transformation | the desired transformation for the selected region being copied |
xDest | the x coordinate of the anchor point in the destination drawing area |
yDest | the y coordinate of the anchor point in the destination drawing area |
widthDest | the width of the image in the drawing area. Can be different than the original width to zoom in or out. |
heightDest | the height of the image in the drawing area. Can be different than the original height to zoom in or out. |
angle | rotation angle in degrees. Interval is [-360, 360]. |
anchor | the anchor point for positioning the region within the destination image |
Copies a region of the specified source image at a location on screen according to an anchoring mechanism.
Possible transformations:
The (xSrc, ySrc) coordinates are relative to the upper left corner of the source image. The xSrc, ySrc, width, and height parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image.
The (xDest, yDest) coordinates are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.
The transform is applied to the image data from the region of the source image, and the result is rendered with its anchor point positioned at location (xDest, yDest) in the destination.
The (widthDest, heightDest) size is used to specified zoom in/out of the rectangular region drawn within the destination.
image | the source image to copy from |
---|---|
xSrc | the x coordinate of the upper left corner of the region within the source image to copy |
ySrc | the y coordinate of the upper left corner of the region within the source image to copy |
width | the width of the region to copy |
height | the height of the region to copy |
transformation | the desired transformation for the selected region being copied |
xDest | the x coordinate of the anchor point in the destination drawing area |
yDest | the y coordinate of the anchor point in the destination drawing area |
widthDest | the width of the image in the drawing area. Can be different than the original width to zoom in or out. |
heightDest | the height of the image in the drawing area. Can be different than the original height to zoom in or out. |
anchor | the anchor parameter to position the image according to the destination point |
Draws an outlined round-cornered rectangle using this graphics context's current color. The left and right edges of the rectangle are at x and x + width, respectively. The top and bottom edges of the rectangle are at y and y + height.
x | the x coordinate of the rectangle to be drawn. |
---|---|
y | the y coordinate of the rectangle to be drawn. |
width | the width of the rectangle to be drawn. |
height | the height of the rectangle to be drawn. |
rx | the horizontal diameter of the arc at the four corners. |
ry | the vertical diameter of the arc at the four corners. |
Draws an outlined round-cornered rectangle using this graphics context's current color.
rect | the rectangle to draw |
---|---|
rx | the horizontal diameter of the arc at the four corners |
ry | the vertical diameter of the arc at the four corners |
NullPointerException |
---|
Draw a string at point coordinates.
str | the string to draw |
---|---|
p | the coordinates of the destination drawing area |
NullPointerException | if the str or p parameter is null |
---|
Draws a string at point coordinates according to the anchor.
str | the String to draw |
---|---|
p | the point where to draw the string. The top-left point of the string will be drawn ath this point |
anchor | the anchor point for positioning the region within the destination image |
IllegalArgumentException | if anchor is not a legal value |
---|---|
NullPointerException | if the str or p parameter is null |
Draw a string with at screen coordinates x and y according to anchor. The string is automatically added to an intern string cache to optimize further drawing in case of the same string is drawn along several successive frames.
str | the string to draw |
---|---|
x | the x coordinate of the anchor point in the destination drawing area |
y | the y coordinate of the anchor point in the destination drawing area |
anchor | the anchor point for positioning the region within the destination image |
NullPointerException | if str is null |
---|
This method draws a substring of a string starting from position offset with length len. The substring is drawn at screen coordinates x and y according to anchor.
str | the source string |
---|---|
offset | the start position of the substring |
len | the length of the substring |
x | the x coordinate of the destination point on screen |
y | the y coordinate of the destination point on screen |
anchor | the anchor for positioning the string relatively to the destination point |
Draw a triangle using three points.
x1 | the x coordinate of the first point |
---|---|
y1 | the y coordinate of the first point |
x2 | the x coordinate of the second point |
y2 | the y coordinate of the second point |
x3 | the x coordinate of the third point |
y3 | the y coordinate of the third point |
Draw a triangle using three points.
p1 | first point |
---|---|
p2 | second point |
p3 | third point |
NullPointerException |
---|
Enable or disable the color blending with the current draw color. Color blending is applied on Image and Font type primitives which use OpenGL ES textures. Color blending is done by changing the texture mode in GL_REPLACE if disabled and to GL_MODULATE if enabled.
enable | set at True to enable the color blending. At False to disable. |
---|
Fills a circular or elliptical arc covering the specified rectangle. The resulting arc begins at startAngle and extends for arcAngle degrees. 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.
The center of the arc is the center of the rectangle whose origin is (x, y) and whose size is specified by the width and height arguments.
The resulting arc covers an area width + 1 pixels wide by height + 1 pixels tall.
The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.
x | the x coordinate of the upper-left corner of the arc to be filled. |
---|---|
y | the y coordinate of the upper-left corner of the arc to be filled. |
width | the width of the arc to be filled. |
height | the height of the arc to be filled. |
startAngle | the beginning angle. |
arcAngle | the angular extent of the arc, relative to the start angle. |
Fills a circular or elliptical arc covering the specified rectangle.
center | the center of the arc |
---|---|
radius | the angle of the arc |
start | the start of the arc |
end | the end of the arc |
NullPointerException | if the center parameter is null |
---|
Draws a filled rectangle.
rect | the rectangle to draw |
---|
NullPointerException | if the rect parameter is null |
---|
Fills the specified rectangle. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1. The resulting rectangle covers an area width pixels wide by height pixels tall. The rectangle is filled using the graphics context's current color.
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. |
Fills the specified rounded corner rectangle with the current color. The left and right edges of the rectangle are at x and x + width - 1, respectively. The top and bottom edges of the rectangle are at y and y + height - 1.
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. |
rx | the horizontal diameter of the arc at the four corners. |
ry | the vertical diameter of the arc at the four corners. |
Fills the specified rounded corner rectangle with the current color.
rect | the rectangle to fill |
---|---|
rw | the horizontal diameter of the arc at the four corners. |
rh | the vertical diameter of the arc at the four corners. |
NullPointerException |
---|
Fills the specified triangle with the current color. The lines connecting each pair of points are included in the filled triangle.
p1 | first point |
---|---|
p2 | second point |
p3 | third point |
NullPointerException |
---|
Fills the specified triangle with the current color. The lines connecting each pair of points are included in the filled triangle.
x1 | the x coordinate of the first point |
---|---|
y1 | the y coordinate of the first point |
x2 | the x coordinate of the second point |
y2 | the y coordinate of the second point |
x3 | the x coordinate of the third point |
y3 | the y coordinate of the third point |
Returns the current clipping height.
Returns the current clipping width.
Gets the x offset of the current clipping area, relative to the coordinate system origin of this graphics context.
Gets the y offset of the current clipping area, relative to the coordinate system origin of this graphics context.
Gets the coordinates of the translated origin of this graphics context.
Gets the x coordinate of the translated origin of this graphics context.
Gets the y coordinate of the translated origin of this graphics context.
Resets the clip and translate values for the current graphics.
Sets the alpha blending value.
alpha | (0 - 255) |
---|
Set a clip region in the Screen. Only drawing in the specified region will be
visible but all drawing calls will be rendered. Any previous screen
translation (translate(int, int)
) are taken into account.
x | the x coordinate of the upper left corner of the region to clip |
---|---|
y | the y coordinate of the upper left corner of the region to clip |
width | the width of the region to clip |
height | the height of the region to clip |
Sets the clip for this graphics The clipping is reset after each paint.
clipping | the clipping rectangle |
---|
Set the current color for all drawing methods by assing each 8 bits component of a RGB color
red | the red component as an 8 bits int, so in range [0, 255]. |
---|---|
green | the green component as an 8 bits int, so in range [0, 255]. |
blue | the blue component as an 8 bits int, so in range [0, 255]. |
Sets the current color for all drawing methods.
color | the color to set |
---|
Sets the current color for all drawing methods.
color | ARGB color |
---|
Sets the current font of the graphics. This font will be used to draw strings.
fnt | the font to set |
---|
s Translates the coordinates of the origins. Theses coordinates are reset after each paint.
x | the x coordinate of the new translation origin |
---|---|
y | the y coordinate of the new translation origin |
Translates the coordinates of the origins. Theses coordinates are reset after each paint.
p | the coordinates of the new translation origin |
---|