Class Graphics
- java.lang.Object
-
- totalcross.ui.gfx.Graphics
-
public final class Graphics extends java.lang.ObjectGraphics draws on a surface.Surfaces are objects that implement the GfxSurface interface. MainWindow and Image are both examples of surfaces.
Here is an example that uses Graphics to draw a line:
public class MyProgram extends MainWindow { public void onPaint(Graphics g) { g.foreColor = 0x0000FF; g.drawLine(0, 0, 10, 10); g.backColor = Color.MAGENTA; g.fillCircle(50,50,20); ...- See Also:
Color,GfxSurface
-
-
Field Summary
Fields Modifier and Type Field Description intalphaAlpha value used on operations, shifted by 24 bits left.static byteARROW_DOWNused in the drawArrow methodstatic byteARROW_LEFTused in the drawArrow methodstatic byteARROW_RIGHTused in the drawArrow methodstatic byteARROW_UPused in the drawArrow methodintbackColorThe background color, in 0xRRGGBB format.intdrawOpDumb field to keep compilation compatibility with TC 1intforeColorThe foreground color, in 0xRRGGBB format.booleanisVerticalTextStates that the next calls to drawText will draw it vertically.static java.lang.ObjectmainWindowPixelsContains the pixels of the MainWindow.static booleanneedsUpdateDefines if the screen has been changed.static byteR3D_CHECKused in the draw3dRect methodstatic byteR3D_EDITused in the draw3dRect methodstatic byteR3D_FILLused in the draw3dRect methodstatic byteR3D_LOWEREDused in the draw3dRect methodstatic byteR3D_RAISEDused in the draw3dRect methodstatic byteR3D_SHADEDused in the draw3dRect method.protected GfxSurfacesurfaceThe surface where this Graphics will draw on.booleanuseAADeprecated.This is not used in OpenGL platforms
-
Constructor Summary
Constructors Constructor Description Graphics(GfxSurface surface)Constructs a graphics object which can be used to draw on the given surface.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclearClip()Clears the current clipping rectangle.booleanclip(Rect r)Clips the specified rectangle to the clipping bounds.static voidcompute3dColors(boolean enabled, int backColor, int foreColor, int[] fourColors)Prior to use draw3dRect, you must compute the colors.voidcopyImageRect(Image src, int x, int y, int width, int height, boolean doClip)Copies a part of the given source image to here at the given position with the given draw operation and back color.voidcopyImageRect(Image image, int x, int y, int width, int height, int drawOp, int backColor, boolean doClip)Dumb method to keep compilation compatibility with TC 1; parameters drawOp and backColor are ignored.voidcopyRect(GfxSurface surface, int x, int y, int width, int height, int dstX, int dstY)Copies a rectangular area from a surface to the given coordinates on the current surface.voiddither(int x, int y, int w, int h)Apply a 16-bit Floyd-Steinberg dithering on the give region of the surface.voiddither(int x, int y, int w, int h, int ignoreColor)Deprecated.TotalCross 2 no longer uses parameter ignoreColor.voiddraw3dRect(int x, int y, int width, int height, byte type, boolean yMirror, boolean simple, int[] fourColors)Draws a 3d rect, respecting the current user interface style.voiddrawArc(int xc, int yc, int r, double startAngle, double endAngle)Draws an arc, using the current foreground color as the outline color.voiddrawArrow(int x, int y, int h, byte type, boolean pressed, int foreColor)Draws an arrow using the current foreground color.voiddrawCircle(int xc, int yc, int r)Draws a circle, using the current foreground color as the outline color.voiddrawCircleAA(int xm, int ym, int r, boolean fill, boolean tl, boolean tr, boolean bl, boolean br)voiddrawCursor(int x, int y, int w, int h)Dumb method to keep compilation compatibility with TC 1voiddrawCylindricShade(int startColor, int endColor, int x, int y, int w, int h)Draws a cylindric shaded rectangle.voiddrawDots(int Ax, int Ay, int Bx, int By)Draws a dotted line in any direction.voiddrawDottedCursor(int x, int y, int w, int h)Dumb method to keep compilation compatibility with TC 1voiddrawDottedRect(int x, int y, int w, int h)Draws a dotted rectangle.voiddrawEllipse(int xc, int yc, int rx, int ry)Draws an Ellipse, using the current foreground color as the outline color.voiddrawEllipticalArc(int xc, int yc, int rx, int ry, double startAngle, double endAngle)Draws an elliptical arc, using the current foreground color as the outline color.voiddrawEllipticalPie(int xc, int yc, int rx, int ry, double startAngle, double endAngle)Draws an elliptical pie slice, using the current foreground color as the outline color.voiddrawHatchedRect(int x, int y, int width, int height, boolean top, boolean bottom)Draws a rectangle with hatched corners, using the current foreground color as the outline color.voiddrawHighLightFrame(int x, int y, int w, int h, int topLeftColor, int bottomRightColor, boolean yMirror)Dumb method to keep compilation compatibility with TC 1voiddrawImage(Image src, int x, int y)Draws an image at the given absolute x and y coordinates.voiddrawImage(Image image, int x, int y, boolean doClip)Draws the image in the given position with the given draw operation and back color.voiddrawImage(Image image, int x, int y, int drawOp, int backColor, boolean doClip)Dumb method to keep compilation compatibility with TC 1; parameters drawOp and backColor are ignored.voiddrawLine(int Ax, int Ay, int Bx, int By)Draws a line at any direction, using the current foreground color as the line color.voiddrawLines(int... p)Draws a set of connected lines from the given x,y coordinates array.voiddrawPie(int xc, int yc, int r, double startAngle, double endAngle)Draws a pie slice, using the current foreground color as the outline color.voiddrawPolygon(int[] xPoints, int[] yPoints, int nPoints)Draws a polygon, using the current foreground color as the outline color.voiddrawPolyline(int[] xPoints, int[] yPoints, int nPoints)Draws a sequence of connected lines, using the current foreground color as the outline color.voiddrawRect(int x, int y, int w, int h)Draws a rectangle, using the current foreground color as the outline color.voiddrawRoundGradient(int startX, int startY, int endX, int endY, int topLeftRadius, int topRightRadius, int bottomLeftRadius, int bottomRightRadius, int startColor, int endColor, boolean vertical)Draws a rectangle with a gradient fill and optional rounded cornersvoiddrawRoundRect(int x, int y, int width, int height, int r)Draws a rectangle with rounded corners, using the current foreground color as the outline color.voiddrawText(char[] chars, int chrStart, int chrCount, int x, int y)Draws a text with the current font and the current foregrount color.voiddrawText(char[] chars, int chrStart, int chrCount, int x, int y, boolean shadow, int shadowColor)voiddrawText(java.lang.StringBuffer sb, int chrStart, int chrCount, int x, int y)Dumb method to keep compilation compatibility with TC 1voiddrawText(java.lang.StringBuffer sb, int chrStart, int chrCount, int x, int y, boolean shadow, int shadowColor)voiddrawText(java.lang.StringBuffer sb, int chrStart, int chrCount, int x, int y, int justifyWidth)Dumb method to keep compilation compatibility with TC 1voiddrawText(java.lang.StringBuffer sb, int chrStart, int chrCount, int x, int y, int justifyWidth, boolean shadow, int shadowColor)voiddrawText(java.lang.String text, int x, int y)Draws a text with the current font and the current foregrount color.voiddrawText(java.lang.String text, int x, int y, boolean shadow, int shadowColor)voiddrawText(java.lang.String text, int x, int y, int justifyWidth)Draws a text with the current font and the current foregrount color, justifying it to the given width.voiddrawText(java.lang.String text, int x, int y, int justifyWidth, boolean shadow, int shadowColor)voiddrawThickLine(int x1, int y1, int x2, int y2, int t)Draws a thick line.voiddrawVerticalText(java.lang.String text, int x, int y)Draws a VERTICAL text with the current font and the current foregrount color.voiddrawVistaRect(int x, int y, int width, int height, int topColor, int rightColor, int bottomColor, int leftColor)Draws a shaded rectangle.voiddrawWindowBorder(int xx, int yy, int ww, int hh, int titleH, int footerH, int borderColor, int titleColor, int bodyColor, int footerColor, int thickness, boolean drawSeparators)voideraseRect(int x, int y, int w, int h)Dumb method to keep compilation compatibility with TC 1voideraseRect(int x, int y, int w, int h, int fromColor, int toColor, int textColor)Dumb method to keep compilation compatibility with TC 1voidexpandClipLimits(int dx1, int dy1, int dx2, int dy2)Expands the clipping limits.static voidfadeScreen(int fadeValue)Fades all window pixels with the given value.voidfillCircle(int xc, int yc, int r)Fills a circle, using the current background color as the fill color.voidfillCircleGradient(int xc, int yc, int r)Fills a circle, using a gradient from the foreground color to the background color.voidfillCursor(int x, int y, int w, int h)Dumb method to keep compilation compatibility with TC 1voidfillEllipse(int xc, int yc, int rx, int ry)Fills an Ellipse, using the current background color as the fill color.voidfillEllipseGradient(int xc, int yc, int rx, int ry)Fills a gradient Ellipse, using a gradient from the foreground color to the background color.voidfillEllipticalPie(int xc, int yc, int rx, int ry, double startAngle, double endAngle)Fills an elliptical pie slice, using the current background color as the fill color and the current foreground color as the outline color.voidfillEllipticalPieGradient(int xc, int yc, int rx, int ry, double startAngle, double endAngle)Fills an elliptical pie slice, using a gradient from the foreground color to the background color.voidfillHatchedRect(int x, int y, int width, int height, boolean top, boolean bottom)Fills a rectangle with hatched corners, using the current background color as the fill color.voidfillPie(int xc, int yc, int r, double startAngle, double endAngle)Fills a pie slice, using the current background color as the fill color and the current foreground color as the outline color.voidfillPieGradient(int xc, int yc, int r, double startAngle, double endAngle)Fills a pie slice, using a gradient from the foreground color to the background color.voidfillPolygon(int[] xPoints, int[] yPoints, int nPoints)Fills a polygon, using the current background color as the fill color.voidfillPolygonGradient(int[] xPoints, int[] yPoints, int nPoints)Fills a vertical gradient polygon, mixing from the foreground color to the background color.voidfillRect(int x, int y, int w, int h)Fills a rectangle, using the current background color as the fill color.voidfillRoundRect(int xx, int yy, int width, int height, int r)Fills a rectangle with rounded corners, using the current background color as the fill color.voidfillShadedRect(int x, int y, int width, int height, boolean invert, boolean rotate, int c1, int c2, int factor)Fills a shaded rectangle.voidfillVistaRect(int x, int y, int width, int height, int back, boolean invert, boolean rotate)Fills a shaded rectangle.voidgetAnglePoint(int xc, int yc, int rx, int ry, int angle, Coord out)Gets the coordinates where the specified point lies.RectgetClip(Rect r)Gets the current clipping rectangle.intgetClipHeight()Returns the clip's heightintgetClipWidth()Returns the clip's widthstatic int[]getPalette()Returns the palette used when the screen has 8 bpp.intgetPixel(int x, int y)Gets the pixel color at given position in the 0x00RRGGBB format.intgetRGB(int[] data, int offset, int x, int y, int w, int h)Gets raw RGB data from a rectangular region of the surface this graphic s drawing to and stores it in the provided array.CoordgetTranslation()Returns the current translation from the origin for this Graphics object.static int[]getVistaColors(int c)Dumb method to keep compilation compatibility with TC 1booleanisControlSurface()Returns true if the source surface is from a Control (if false, its an Image).voidplotLineAA(int x0, int y0, int x1, int y1)voidrefresh(int sx, int sy, int sw, int sh, int tx, int ty, Font f)Refreshes the clipping bounds, translation and font for this Graphics.voidsetClip(int x, int y, int w, int h)Sets the clipping rectangle, translated to the current translated origin.voidsetClip(Rect r)Sets the clipping rectangle, translated to the current translated origin.voidsetFont(Font font)Sets the current font for operations that draw text.voidsetPixel(int x, int y)Sets the pixel at the specified position, using the current foreground color as the pixel color.voidsetPixels(int[] xPoints, int[] yPoints, int nPoints)Draws a sequence of points, using the current foreground color.intsetRGB(int[] data, int offset, int x, int y, int w, int h)Sets raw RGB data of a rectangular region of the surface this graphic s drawing to copying it from the provided array.java.lang.StringtoString()voidtranslate(int dx, int dy)Translates the origin of the of the current coordinate system by the given dx and dy.
-
-
-
Field Detail
-
surface
protected GfxSurface surface
The surface where this Graphics will draw on.
-
foreColor
public int foreColor
The foreground color, in 0xRRGGBB format.
-
backColor
public int backColor
The background color, in 0xRRGGBB format.
-
useAA
@Deprecated public boolean useAA
Deprecated.This is not used in OpenGL platformsSet to true to use antialiase in all drawing operations that draw a diagonal line, such as drawPoligon and drawLine.
-
isVerticalText
public boolean isVerticalText
States that the next calls to drawText will draw it vertically. We decided to do this using a boolean instead of duplicating all the 10 drawText method calls, to keep it simple.- Since:
- TotalCross 1.7
- See Also:
drawVerticalText(String, int, int)
-
mainWindowPixels
public static java.lang.Object mainWindowPixels
Contains the pixels of the MainWindow.
-
R3D_EDIT
public static final byte R3D_EDIT
used in the draw3dRect method- See Also:
- Constant Field Values
-
R3D_LOWERED
public static final byte R3D_LOWERED
used in the draw3dRect method- See Also:
- Constant Field Values
-
R3D_RAISED
public static final byte R3D_RAISED
used in the draw3dRect method- See Also:
- Constant Field Values
-
R3D_CHECK
public static final byte R3D_CHECK
used in the draw3dRect method- See Also:
- Constant Field Values
-
R3D_SHADED
public static final byte R3D_SHADED
used in the draw3dRect method. Note that the simple parameter acts in anothe way: if is true, a menu shaded is drawn; if is false, a listbox shaded is drawn. Also note that the fore color must have been set.- See Also:
- Constant Field Values
-
R3D_FILL
public static final byte R3D_FILL
used in the draw3dRect method- See Also:
- Constant Field Values
-
ARROW_UP
public static final byte ARROW_UP
used in the drawArrow method- See Also:
- Constant Field Values
-
ARROW_DOWN
public static final byte ARROW_DOWN
used in the drawArrow method- See Also:
- Constant Field Values
-
ARROW_LEFT
public static final byte ARROW_LEFT
used in the drawArrow method- See Also:
- Constant Field Values
-
ARROW_RIGHT
public static final byte ARROW_RIGHT
used in the drawArrow method- See Also:
- Constant Field Values
-
needsUpdate
public static boolean needsUpdate
Defines if the screen has been changed.
-
alpha
public int alpha
Alpha value used on operations, shifted by 24 bits left. E.G.: to use an alpha value of 0x80, set this with 0x80000000, or 0x80<<24. The default value is 0xFF000000 and is used only when drawing on Images.
-
drawOp
public int drawOp
Dumb field to keep compilation compatibility with TC 1
-
-
Constructor Detail
-
Graphics
public Graphics(GfxSurface surface)
Constructs a graphics object which can be used to draw on the given surface.Only totalcross.ui.Control and totalcross.ui.image.Image classes can have a graphics. Trying to create it with another class will result in a runtime exception.
If you are trying to create a graphics object for drawing in a subclass of control, use the getGraphics() method in the Control class.
- See Also:
Control.getGraphics()
-
-
Method Detail
-
isControlSurface
public boolean isControlSurface()
Returns true if the source surface is from a Control (if false, its an Image).
-
fadeScreen
public static void fadeScreen(int fadeValue)
Fades all window pixels with the given value. The window is not repainted, so, if you fade it to bright, you will have to repaint the window to get the original pixels back. Also, don't forget to call updateWindow after this method. Here's a sample of how to fade the screen to black:for (int i = 0; i < 256; i++) { Graphics.fadeScreen(1); updateScreen(); }And now how to fade it back:for (int i = 256; --i >= 0;) { enableUpdateScreen = false; for (int j = 0, n = zStack.size(); j < n; j++) // repaints every window, from the nearest with the MainWindow size // to last parent ((Window) zStack.items[j]).repaintNow(); enableUpdateScreen = true; Graphics.fadeScreen(i); updateScreen(); }You may want to add a delay in the fade out, since its much faster than the fade in.
CAUTION: the code above does not work on Android.- Since:
- TotalCross 1.2
- See Also:
Window.fadeOtherWindows,Window.fadeValue
-
refresh
public void refresh(int sx, int sy, int sw, int sh, int tx, int ty, Font f)Refreshes the clipping bounds, translation and font for this Graphics.- Since:
- TotalCross 1.0
-
expandClipLimits
public void expandClipLimits(int dx1, int dy1, int dx2, int dy2)Expands the clipping limits. Used internally.
-
getPalette
public static int[] getPalette()
Returns the palette used when the screen has 8 bpp. You can view the palette online here. There's no need to convert your colors to these ones; this will be done on-the-fly by the vm.- Since:
- TotalCross 1.0
-
drawEllipse
public void drawEllipse(int xc, int yc, int rx, int ry)Draws an Ellipse, using the current foreground color as the outline color.- Parameters:
xc- x coordinate of the center of the ellipseyc- y coordinate of the center of the ellipserx- radix x of the ellipsery- radix y of the ellipse
-
fillEllipse
public void fillEllipse(int xc, int yc, int rx, int ry)Fills an Ellipse, using the current background color as the fill color.- Parameters:
xc- x coordinate of the center of the ellipseyc- y coordinate of the center of the ellipserx- radix x of the ellipsery- radix y of the ellipse
-
fillEllipseGradient
public void fillEllipseGradient(int xc, int yc, int rx, int ry)Fills a gradient Ellipse, using a gradient from the foreground color to the background color.- Parameters:
xc- x coordinate of the center of the ellipseyc- y coordinate of the center of the ellipserx- radix x of the ellipsery- radix y of the ellipse
-
drawArc
public void drawArc(int xc, int yc, int r, double startAngle, double endAngle)Draws an arc, using the current foreground color as the outline color. If startAngle < 0 and endAngle > 359 a whole circle is drawn. A pie differs from an arc so the pie connects the end points of the arc to the center, thus making a closed figure.- Parameters:
xc- x coordinate of the center of the circle that contains the arc.yc- y coordinate of the center of the circle that contains the arc.r- radix of the circle that contains the arcstartAngle- starting angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.endAngle- ending angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.
-
drawPie
public void drawPie(int xc, int yc, int r, double startAngle, double endAngle)Draws a pie slice, using the current foreground color as the outline color. If startAngle < 0 and endAngle > 359 a whole circle is drawn. A pie differs from an arc so the pie connects the end points of the arc to the center, thus making a closed figure.- Parameters:
xc- x coordinate of the center of the circle that contains the arc.yc- y coordinate of the center of the circle that contains the arc.r- radix of the circle that contains the piestartAngle- starting angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.endAngle- ending angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.
-
fillPie
public void fillPie(int xc, int yc, int r, double startAngle, double endAngle)Fills a pie slice, using the current background color as the fill color and the current foreground color as the outline color. If startAngle < 0 and endAngle > 359 a whole circle is filled.- Parameters:
xc- x coordinate of the center of the circle that contains the arc.yc- y coordinate of the center of the circle that contains the arc.r- radix of the circle that contains the piestartAngle- starting angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.endAngle- ending angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.
-
fillPieGradient
public void fillPieGradient(int xc, int yc, int r, double startAngle, double endAngle)Fills a pie slice, using a gradient from the foreground color to the background color. To draw the outline, you must call drawPie. If startAngle < 0 and endAngle > 359 a whole circle is filled.- Parameters:
xc- x coordinate of the center of the circle that contains the arc.yc- y coordinate of the center of the circle that contains the arc.r- radix of the circle that contains the piestartAngle- starting angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.endAngle- ending angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.
-
drawEllipticalArc
public void drawEllipticalArc(int xc, int yc, int rx, int ry, double startAngle, double endAngle)Draws an elliptical arc, using the current foreground color as the outline color. If startAngle < 0 and endAngle > 359 a whole circle is drawn. A pie differs from an arc so the pie connects the end points of the arc to the center, thus making a closed figure.- Parameters:
xc- x coordinate of the center of the circle that contains the arc.yc- y coordinate of the center of the circle that contains the arc.rx- x radix of the circle that contains the piery- y radix of the circle that contains the piestartAngle- starting angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.endAngle- ending angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.
-
drawEllipticalPie
public void drawEllipticalPie(int xc, int yc, int rx, int ry, double startAngle, double endAngle)Draws an elliptical pie slice, using the current foreground color as the outline color. If startAngle < 0 and endAngle > 359 a whole circle is drawn. A pie differs from an arc so the pie connects the end points of the arc to the center, thus making a closed figure.- Parameters:
xc- x coordinate of the center of the circle that contains the arc.yc- y coordinate of the center of the circle that contains the arc.rx- x radix of the circle that contains the piery- y radix of the circle that contains the piestartAngle- starting angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.endAngle- ending angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.
-
fillEllipticalPie
public void fillEllipticalPie(int xc, int yc, int rx, int ry, double startAngle, double endAngle)Fills an elliptical pie slice, using the current background color as the fill color and the current foreground color as the outline color. If startAngle < 0 and endAngle > 359 a whole circle is filled.- Parameters:
xc- x coordinate of the center of the circle that contains the arc.yc- y coordinate of the center of the circle that contains the arc.rx- x radix of the circle that contains the piery- y radix of the circle that contains the piestartAngle- starting angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.endAngle- ending angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.
-
fillEllipticalPieGradient
public void fillEllipticalPieGradient(int xc, int yc, int rx, int ry, double startAngle, double endAngle)Fills an elliptical pie slice, using a gradient from the foreground color to the background color. To draw the outline, you must call drawEllipticalPie. If startAngle < 0 and endAngle > 359 a whole circle is filled.- Parameters:
xc- x coordinate of the center of the circle that contains the arc.yc- y coordinate of the center of the circle that contains the arc.rx- x radix of the circle that contains the piery- y radix of the circle that contains the piestartAngle- starting angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.endAngle- ending angle of the arc. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.
-
drawCircle
public void drawCircle(int xc, int yc, int r)Draws a circle, using the current foreground color as the outline color.- Parameters:
xc- x coordinate of the center of the circleyc- y coordinate of the center of the circler- radix of the circle
-
fillCircle
public void fillCircle(int xc, int yc, int r)Fills a circle, using the current background color as the fill color.- Parameters:
xc- x coordinate of the center of the circleyc- y coordinate of the center of the circler- radix of the circle
-
fillCircleGradient
public void fillCircleGradient(int xc, int yc, int r)Fills a circle, using a gradient from the foreground color to the background color. To draw the outline, you must call drawCircle.- Parameters:
xc- x coordinate of the center of the circleyc- y coordinate of the center of the circler- radix of the circle
-
getPixel
public int getPixel(int x, int y)Gets the pixel color at given position in the 0x00RRGGBB format. Note that if the image has an alpha channel, the format is 0xAARRGGBB, where AA is the alpha value; to get the RRGGBB, usepixel & 0xFFFFFF.- Parameters:
x- x coordinate of the pixely- y coordinate of the pixel- Returns:
- the color of the pixel or -1 if the pixel lies outside the clip bounds.
-
setPixel
public void setPixel(int x, int y)Sets the pixel at the specified position, using the current foreground color as the pixel color.- Parameters:
x- x coordinate of the pixely- y coordinate of the pixel
-
drawLine
public void drawLine(int Ax, int Ay, int Bx, int By)Draws a line at any direction, using the current foreground color as the line color.- Parameters:
Ax- x coordinate of the start of the line.Ay- y coordinate of the start of the line.Bx- x coordinate of the end of the line.By- y coordinate of the end of the line.
-
drawDots
public void drawDots(int Ax, int Ay, int Bx, int By)Draws a dotted line in any direction. Uses the current foreground color as the 1st, 3rd, ... pixels and the background color as the 2nd, 4th, ... pixels.- Parameters:
Ax- x coordinate of the start of the line.Ay- y coordinate of the start of the line.Bx- x coordinate of the end of the line.By- y coordinate of the end of the line.
-
drawRect
public void drawRect(int x, int y, int w, int h)Draws a rectangle, using the current foreground color as the outline color.- Parameters:
x- left coordinate of the rectangley- top coordinate of the rectanglew- width of the rectangle. the rectangle is drawn from x to x+w-1.h- height of the rectangle. the rectangle is drawn from y to y+h-1.
-
fillRect
public void fillRect(int x, int y, int w, int h)Fills a rectangle, using the current background color as the fill color.- Parameters:
x- left coordinate of the rectangley- top coordinate of the rectanglew- width of the rectangle. the rectangle is filled from x to x+w-1.h- height of the rectangle. the rectangle is filled from y to y+h-1.
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)Fills a polygon, using the current background color as the fill color. The polygon can be convex or concave.- Parameters:
xPoints- the array with the x coordinate pointsyPoints- the array with the y coordinate pointsnPoints- the total number of point to be drawn
-
fillPolygonGradient
public void fillPolygonGradient(int[] xPoints, int[] yPoints, int nPoints)Fills a vertical gradient polygon, mixing from the foreground color to the background color. The polygon can be convex or concave.- Parameters:
xPoints- the array with the x coordinate pointsyPoints- the array with the y coordinate pointsnPoints- the total number of point to be drawn- Since:
- TotalCross 1.01
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)Draws a polygon, using the current foreground color as the outline color. The polygon is automatically closed.- Parameters:
xPoints- the array with the x coordinate pointsyPoints- the array with the y coordinate pointsnPoints- the total number of point to be drawn
-
drawDottedRect
public void drawDottedRect(int x, int y, int w, int h)Draws a dotted rectangle. Use the current foreground color as the 1st, 3rd, ... pixels and the background color as the 2nd, 4th, ... pixels.- Parameters:
x- left coordinate of the rectangley- top coordinate of the rectanglew- width of the rectangle. the rectangle is drawn from x to x+w-1.h- height of the rectangle. the rectangle is drawn from y to y+h-1.
-
drawPolyline
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)Draws a sequence of connected lines, using the current foreground color as the outline color. The lines are not closed.- Parameters:
xPoints- the array with the x coordinate pointsyPoints- the array with the y coordinate pointsnPoints- the total number of point to be drawn
-
setPixels
public void setPixels(int[] xPoints, int[] yPoints, int nPoints)Draws a sequence of points, using the current foreground color.- Parameters:
xPoints- the array with the x coordinate pointsyPoints- the array with the y coordinate pointsnPoints- the total number of point to be drawn
-
drawText
public void drawText(char[] chars, int chrStart, int chrCount, int x, int y, boolean shadow, int shadowColor)
-
drawText
public void drawText(java.lang.StringBuffer sb, int chrStart, int chrCount, int x, int y, boolean shadow, int shadowColor)
-
drawText
public void drawText(java.lang.StringBuffer sb, int chrStart, int chrCount, int x, int y, int justifyWidth, boolean shadow, int shadowColor)
-
drawText
public void drawText(java.lang.String text, int x, int y, boolean shadow, int shadowColor)
-
drawText
public void drawText(java.lang.String text, int x, int y, int justifyWidth, boolean shadow, int shadowColor)
-
drawText
public void drawText(char[] chars, int chrStart, int chrCount, int x, int y)Draws a text with the current font and the current foregrount color. On BlackBerry devices, this method is slower than drawText(String,x,y) because it convert the chars to a string.- Parameters:
chars- the character array to displaychrStart- the start position in arraychrCount- the number of characters to displayx- the left coordinate of the text's bounding boxy- the top coordinate of the text's bounding box
-
drawText
public void drawText(java.lang.String text, int x, int y)Draws a text with the current font and the current foregrount color.- Parameters:
text- the text to be drawnx- x coordinate of the texty- y coordinate of the text
-
drawVerticalText
public void drawVerticalText(java.lang.String text, int x, int y)Draws a VERTICAL text with the current font and the current foregrount color. This is a shorthand of:g.isVerticalText = true; g.drawText(text, x, y); g.isVerticalText = false;
- Parameters:
text- the text to be drawnx- x coordinate of the texty- y coordinate of the text
-
drawText
public void drawText(java.lang.String text, int x, int y, int justifyWidth)Draws a text with the current font and the current foregrount color, justifying it to the given width. The text can be vertical if you set the isVerticalText property. Note that vertical text does not allow justification. You can use the justifyWidth to adjust the kerning; depending on the characters you're using, you can decrease the distance usingfont.fm.height - font.fm.ascentas the justifyWidth.- Parameters:
text- the text to be drawnx- x coordinate of the texty- y coordinate of the textjustifyWidth- The width to justify the text to.- Since:
- TotalCross 1.0
- See Also:
isVerticalText,drawVerticalText(String, int, int)
-
drawRoundRect
public void drawRoundRect(int x, int y, int width, int height, int r)Draws a rectangle with rounded corners, using the current foreground color as the outline color.- Parameters:
x- left coordinate of the rectangley- top coordinate of the rectanglewidth- width of the rectangle. the rectangle is drawn from x to x+w-1.height- height of the rectangle. the rectangle is drawn from y to y+h-1.r- radix of the circle at the corners. If its greater than width/2 or greater than height/2, it will be adjusted to the minimum of both values.
-
fillRoundRect
public void fillRoundRect(int xx, int yy, int width, int height, int r)Fills a rectangle with rounded corners, using the current background color as the fill color.- Parameters:
xx- left coordinate of the rectangleyy- top coordinate of the rectanglewidth- width of the rectangle. the rectangle is filled from x to x+w-1.height- height of the rectangle. the rectangle is filled from y to y+h-1.r- radix of the circle at the corners. If its greater than width/2 or greater than height/2, it will be adjusted to the minimum of both values.
-
setClip
public void setClip(int x, int y, int w, int h)Sets the clipping rectangle, translated to the current translated origin. Anything drawn outside of the rectangular area specified will be clipped. Setting a clip overrides any previous clip. This clipping rectangle affects all the drawing operations.- Parameters:
x- left coordinate of the rectangley- top coordinate of the rectanglew- width of the rectangle. the rectangle is filled from x to x+w-1.h- height of the rectangle. the rectangle is filled from y to y+h-1.
-
setClip
public void setClip(Rect r)
Sets the clipping rectangle, translated to the current translated origin. Anything drawn outside of the rectangular area specified will be clipped. Setting a clip overrides any previous clip. This clipping rectangle affects all the drawing operations.- Parameters:
r- the rectangle with the clipping coordinates
-
getClip
public Rect getClip(Rect r)
Gets the current clipping rectangle.- Parameters:
r- a Rect object where the clip coordinates will be stored and returned.
-
getClipWidth
public int getClipWidth()
Returns the clip's width
-
getClipHeight
public int getClipHeight()
Returns the clip's height
-
clip
public boolean clip(Rect r)
Clips the specified rectangle to the clipping bounds.- Parameters:
r- The coordinates of the rectangle that are to be adjusted to match the clipping bounds.- Returns:
- false if the specified rectangle does not intersects the clipping bounds or the new coordinates of the clipped rectangle.
-
clearClip
public void clearClip()
Clears the current clipping rectangle. This allows drawing to occur anywhere on the current surface.
-
translate
public void translate(int dx, int dy)Translates the origin of the of the current coordinate system by the given dx and dy. The final translation coords cannot be lesser than 0.- Parameters:
dx- the delta x of the x coordinate translation. the new x origin coordinate will be x + dxdy- the delta y of the y coordinate translation. the new y origin coordinate will be y + dy
-
copyRect
public void copyRect(GfxSurface surface, int x, int y, int width, int height, int dstX, int dstY)
Copies a rectangular area from a surface to the given coordinates on the current surface. The copy operation is performed by combining pixels according to the setting of the current drawing operation. The same surface can be used as a source and destination to implement quick scrolling.- Parameters:
surface- the surface to copy fromx- the source x coordinatey- the source y coordinatewidth- the width of the area on the source surfaceheight- the height of the area on the source surfacedstX- the destination x location on the current surfacedstY- the destination y location on the current surface
-
setFont
public void setFont(Font font)
Sets the current font for operations that draw text.
-
getTranslation
public Coord getTranslation()
Returns the current translation from the origin for this Graphics object.
-
drawHatchedRect
public void drawHatchedRect(int x, int y, int width, int height, boolean top, boolean bottom)Draws a rectangle with hatched corners, using the current foreground color as the outline color. If both top and bottom are false, nothing is drawn.- Parameters:
x- left coordinate of the rectangley- top coordinate of the rectanglewidth- width of the rectangle. the rectangle is drawn from x to x+w-1.height- height of the rectangle. the rectangle is drawn from y to y+h-1.top- true if the top corners will be hatchedbottom- true if the bottom corners will be hatched
-
fillHatchedRect
public void fillHatchedRect(int x, int y, int width, int height, boolean top, boolean bottom)Fills a rectangle with hatched corners, using the current background color as the fill color. If both top and bottom are false, nothing is drawn.- Parameters:
x- left coordinate of the rectangley- top coordinate of the rectanglewidth- width of the rectangle. the rectangle is drawn from x to x+w-1.height- height of the rectangle. the rectangle is drawn from y to y+h-1.top- true if the top corners will be hatchedbottom- true if the bottom corners will be hatched
-
drawRoundGradient
public void drawRoundGradient(int startX, int startY, int endX, int endY, int topLeftRadius, int topRightRadius, int bottomLeftRadius, int bottomRightRadius, int startColor, int endColor, boolean vertical)Draws a rectangle with a gradient fill and optional rounded corners- Parameters:
startX- x coordinate of the top-left pixelstartY- y coordinate of the top-left pixelendX- x coordinate of the bottom-right pixelendY- y coordinate of the bottom-right pixeltopLeftRadius- Radius (in pixels) of the top-left corner. A value of zero means that this corner will not be roundedtopRightRadius- Radius (in pixels) of the top-right corner. A value of zero means that this corner will not be roundedbottomLeftRadius- Radius (in pixels) of the bottom-left corner. A value of zero means that this corner will not be roundedbottomRightRadius- Radius (in pixels) of the bottom-right corner. A value of zero means that this corner will not be roundedstartColor- The color value for the top of the rectangleendColor- The color value for the bottom of the rectanglevertical- True to be a vertical gradient, false to be a horizontal one- Since:
- TotalCross 1.0
-
drawImage
public void drawImage(Image image, int x, int y, boolean doClip)
Draws the image in the given position with the given draw operation and back color. Note that the current draw operation is not changed, neither the current back color.Deprecated use: backColor forces the transparentColor of the Image, and is ignored when drawOp is DRAW_PAINT.
Preferred use: when
backColoris -1, the transparentColor is the one which has been defined for this Image, usingImage.transparentColor. Note that for a GIF Image, the transparent pixel is automatically set from the image's information.The parameter doClip must be used with caution. If false, it will not do any clipping checks (what may improve drawings in 8%). Set it to true only when you're sure that the image will not pass the current surface bounds. Otherwise, be prepared to even hard-reset your device!
- Since:
- SuperWaba 3.3
-
copyImageRect
public void copyImageRect(Image src, int x, int y, int width, int height, boolean doClip)
Copies a part of the given source image to here at the given position with the given draw operation and back color. Note that the current draw operation is not changed, neither the current back color.Deprecated use: backColor forces the transparentColor of the Image, and is ignored when drawOp is DRAW_PAINT.
Preferred use: when
backColoris -1, the transparentColor is the one which has been defined for this Image, usingImage.transparentColor. Note that for a GIF Image, the transparent pixel is automatically set from the image's information.The parameter doClip must be used with caution. If false, it will not do any clipping checks (what may improve drawings in 8%). Set it to true only when you're sure that the image will not pass the current surface bounds. Otherwise, be prepared to even hard-reset your device!
- Since:
- SuperWaba 3.3
-
drawImage
public void drawImage(Image src, int x, int y)
Draws an image at the given absolute x and y coordinates. The x and y coordinates must be absolute values; LEFT/RIGHT/TOP/BOTTOM/CENTER are not allowed.
-
compute3dColors
public static void compute3dColors(boolean enabled, int backColor, int foreColor, int[] fourColors)Prior to use draw3dRect, you must compute the colors. This must be done everytime you change the enabled state or the fore/back colors. This can be easily achieved if you extend the onColorsChanged method (but don't forget to call super.onColorsChanged).
-
drawVistaRect
public void drawVistaRect(int x, int y, int width, int height, int topColor, int rightColor, int bottomColor, int leftColor)Draws a shaded rectangle.
-
fillVistaRect
public void fillVistaRect(int x, int y, int width, int height, int back, boolean invert, boolean rotate)Fills a shaded rectangle. Used to draw many Vista user interface style controls
-
fillShadedRect
public void fillShadedRect(int x, int y, int width, int height, boolean invert, boolean rotate, int c1, int c2, int factor)Fills a shaded rectangle. Used to draw many Android user interface style controls
-
draw3dRect
public void draw3dRect(int x, int y, int width, int height, byte type, boolean yMirror, boolean simple, int[] fourColors)Draws a 3d rect, respecting the current user interface style.- Parameters:
x- the x positiony- the y positionwidth- the width of the rectangleheight- the height of the rectangletype- one of the R3D constantsyMirror- no longer usedsimple- if true, a simple rectangle will be drawnfourColors- the four colors used if ui style is WinCE- See Also:
R3D_EDIT,R3D_LOWERED,R3D_RAISED,R3D_CHECK,R3D_SHADED
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
drawArrow
public void drawArrow(int x, int y, int h, byte type, boolean pressed, int foreColor)Draws an arrow using the current foreground color.- Parameters:
x- the x position from where the draw will starty- the y position from where the draw will starth- is the height (or width, if left/right arrows) in pixels. 1st line has 1 pixel, 2nd line has 3, 3rd line has 5, etc. Must be >= 2 or no arrow is drawn.type- one of the ARROW_ constants.pressed- if true, x and y are shifted by one pixelforeColor- the foreground color to be used. This Graphic's fore color is changed after this method is called.Example:
public void onPaint(Graphics g) { g.drawArrow(30,30,8, Graphics.ARROW_LEFT, false, Color.BLACK ); ...- See Also:
ARROW_DOWN,ARROW_LEFT,ARROW_RIGHT,ARROW_UP
-
getAnglePoint
public void getAnglePoint(int xc, int yc, int rx, int ry, int angle, Coord out)Gets the coordinates where the specified point lies. This is useful if you're drawing a pie chart and want to know where to draw the label. The computed values are cached to speedup the process.- Parameters:
xc- x coordinate of the center of the circleyc- y coordinate of the center of the circlerx- x radix of the circle that contains the point. Maximum rx value is 8000; above this, the result is unpredictable.ry- y radix of the circle that contains the point. Maximum ry value is 8000; above this, the result is unpredictable.angle- angle of the point. It should be between 0 and 360 (degrees). 0º is at 3 o'clock.out- the Coord with the x,y points
-
getRGB
public int getRGB(int[] data, int offset, int x, int y, int w, int h)Gets raw RGB data from a rectangular region of the surface this graphic s drawing to and stores it in the provided array.- Parameters:
data- Array where the RGB data will be stored.offset- Offset into the data array to start writing to.x- Left edge of the region to copy from.y- Top edge of the region to copy from.w- Width of the region to copy from.h- Height of the region to copy from.- Returns:
- The total number of pixels copied from the surface to the array.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- If the data array is not big enough to hold the RGB values.
-
setRGB
public int setRGB(int[] data, int offset, int x, int y, int w, int h)Sets raw RGB data of a rectangular region of the surface this graphic s drawing to copying it from the provided array.Important: the data is in RAW format, so this method only works if the data was retrieved using getRGB.
- Parameters:
data- Array where the RGB data is stored.offset- Offset into the data array to start reading from.x- Left edge of the region to copy to.y- Top edge of the region to copy to.w- Width of the region to copy to.h- Height of the region to copy to.- Returns:
- The total number of pixels copied from the array to the surface.
- Throws:
java.lang.ArrayIndexOutOfBoundsException- If the data array has not enough RGB values.
-
drawWindowBorder
public void drawWindowBorder(int xx, int yy, int ww, int hh, int titleH, int footerH, int borderColor, int titleColor, int bodyColor, int footerColor, int thickness, boolean drawSeparators)
-
drawCylindricShade
public void drawCylindricShade(int startColor, int endColor, int x, int y, int w, int h)Draws a cylindric shaded rectangle. Use it like:public void onPaint(Graphics g) { g.drawCylindricShade(0xB6D3E8, 0xF2F4F6, 0, 0, width, height); }- Since:
- TotalCross 1.53
-
dither
@Deprecated public void dither(int x, int y, int w, int h, int ignoreColor)Deprecated.TotalCross 2 no longer uses parameter ignoreColor.
-
dither
public void dither(int x, int y, int w, int h)Apply a 16-bit Floyd-Steinberg dithering on the give region of the surface. Don't use dithering if Settings.screenBPP is not equal to 16, like on desktop computers. In OpenGL platforms, does not work if the surface is the screen (in other words, works only for images).- Since:
- TotalCross 1.53
-
eraseRect
public void eraseRect(int x, int y, int w, int h)Dumb method to keep compilation compatibility with TC 1
-
eraseRect
public void eraseRect(int x, int y, int w, int h, int fromColor, int toColor, int textColor)Dumb method to keep compilation compatibility with TC 1
-
getVistaColors
public static int[] getVistaColors(int c)
Dumb method to keep compilation compatibility with TC 1
-
drawHighLightFrame
public void drawHighLightFrame(int x, int y, int w, int h, int topLeftColor, int bottomRightColor, boolean yMirror)Dumb method to keep compilation compatibility with TC 1
-
fillCursor
public void fillCursor(int x, int y, int w, int h)Dumb method to keep compilation compatibility with TC 1
-
drawCursor
public void drawCursor(int x, int y, int w, int h)Dumb method to keep compilation compatibility with TC 1
-
drawDottedCursor
public void drawDottedCursor(int x, int y, int w, int h)Dumb method to keep compilation compatibility with TC 1
-
copyImageRect
public void copyImageRect(Image image, int x, int y, int width, int height, int drawOp, int backColor, boolean doClip)
Dumb method to keep compilation compatibility with TC 1; parameters drawOp and backColor are ignored.
-
drawText
public void drawText(java.lang.StringBuffer sb, int chrStart, int chrCount, int x, int y)Dumb method to keep compilation compatibility with TC 1
-
drawText
public void drawText(java.lang.StringBuffer sb, int chrStart, int chrCount, int x, int y, int justifyWidth)Dumb method to keep compilation compatibility with TC 1
-
drawImage
public void drawImage(Image image, int x, int y, int drawOp, int backColor, boolean doClip)
Dumb method to keep compilation compatibility with TC 1; parameters drawOp and backColor are ignored.
-
drawThickLine
public void drawThickLine(int x1, int y1, int x2, int y2, int t)Draws a thick line. You should use odd values for t(hickness).
-
plotLineAA
public void plotLineAA(int x0, int y0, int x1, int y1)
-
drawCircleAA
public void drawCircleAA(int xm, int ym, int r, boolean fill, boolean tl, boolean tr, boolean bl, boolean br)
-
drawLines
public void drawLines(int... p)
Draws a set of connected lines from the given x,y coordinates array. You must provide at least 2 points (4 int numbers).
-
-