waba.fx
Class Graphics

java.lang.Object
  |
  +--waba.fx.Graphics

public class Graphics
extends Object

Graphics draws on a surface.

Since SuperWaba 2.0: now the Graphics class is much more improved, with lots of new methods. It also supports Grayscale in all Palm OS operating system versions. In grayscale mode, color can be from 0 to 3, where 0 = no color and 3 = darker color.

Surfaces are objects that implement the ISurface 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.setForeColor(new Color(0, 0, 255));
  g.drawLine(0, 0, 10, 10);
  g.setBackColor(new Color(255,0,255));
  g.fillCircle(50,50,20);
 ...
 

See Also:
Color

Field Summary
static byte ARROW_DOWN
          used in the drawArrow method
static byte ARROW_LEFT
          used in the drawArrow method
static byte ARROW_RIGHT
          used in the drawArrow method
static byte ARROW_UP
          used in the drawArrow method
protected static int[] currentPalette
           
static int DRAW_ERASE
          The constant for a draw operation where the destination is cleared where source pixels are off (AND mode).
static int DRAW_INVERT
          The constant for a draw operation where the destination is inverted where source pixels are on (XOR mode).
static int DRAW_MASK
          The constant for a draw operation where the destination is cleared where source pixels are on (AND NOT mode).
static int DRAW_OVERLAY
          The constant for a draw operation where the destination set only where source pixels are on (OR mode).
static int DRAW_PAINT
          The constant for a draw operation where the destination is replaced with source pixels (copy mode).
static int DRAW_PAINT_INVERSE
          The constant for a draw operation where the destination is replaced with inverted source (copy NOT mode).
static int DRAW_REPLACE_COLOR
          The constant for a draw operation where the destination is replaced with foreground color if source pixels different of background color.
static int DRAW_SPRITE
          The constant for a draw operation where the destination is replaced if source pixels !
static int DRAW_SWAP_COLORS
          The constant for a draw operation where the foreground color is swaped with the background color.
protected  int drawOp
           
 Font lastFont
           
static byte R3D_CHECK
          used in the draw3dRect method
static byte R3D_EDIT
          used in the draw3dRect method
static byte R3D_LOWERED
          used in the draw3dRect method
static byte R3D_RAISED
          used in the draw3dRect method
static byte R3D_SHADED
          used in the draw3dRect method.
protected static Palette ScreenPalette
           
protected  ISurface surface
           
 
Constructor Summary
Graphics(ISurface surface)
          Constructs a graphics object which can be used to draw on the given surface.
 
Method Summary
protected static void _applyPalette(int[] palrgb, int startIndex, int endIndex)
           
static void applyPalette(Palette pal, int startIndex, int endIndex)
          apply the palette. since theres only one applied palette at any time, this method is static.
 void clearClip()
          Clears the current clipping rectangle.
 void clearScreen()
          Clears the screen bounded by this graphics object using the background color as the clear color.
 boolean clip(Rect r)
          Clips the specified rectangle to the clipping bounds.
 boolean collisionDetect(ISurface surface, int x1, int y1, Image img, int x2, int y2)
          Tests if a surface collides with an image.
static void compute3dColors(boolean enabled, Color backColor, Color foreColor, Color[] fourColors)
          Prior to use draw3dRect, you must compute the colors.
 void copyImageRect(Image image, int x, int y, int width, int height, int drawOp, Color backColor, boolean doClip)
           
 void copyRect(ISurface 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.
 void copyScreen(ISurface src, int ySrc, int yDst, int height)
          Copies the given surface to this surface.
 void draw3dRect(int x, int y, int width, int height, byte type, boolean yMirror, boolean simple, Color[] fourColors)
          draws a 3d rect, defined by the R3D_xxx constants.
 void drawArc(int xc, int yc, int r, float startAngle, float endAngle)
          Draws an arc, using the current foreground color as the outline color.
 void drawArrow(int x, int y, int h, byte type, boolean pressed, boolean enabled, Color fore)
          Draws an arrow. use the ARROW_xxx type. h 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. h must be >= 2 or no arrow is drawn.
 void drawCircle(int xc, int yc, int r)
          Draws a circle, using the current foreground color as the outline color.
 void drawCursor(int x, int y, int w, int h)
          Draws a rectangle using the xor operation.
 void drawCursorOutline(int x, int y, int w, int h)
          Draws a rectangle outline using the xor operation.
 void drawDots(int Ax, int Ay, int Bx, int By)
          Draws a dotted line in any direction, using the current foreground color as the 1st, 3rd, ... pixels and the background color as the 2nd, 4th, ... pixels.
 void drawDottedRect(int x, int y, int w, int h)
          Draws a dotted rectangle, using the current foreground color as the 1st, 3rd, ... pixels and the background color as the 2nd, 4th, ... pixels.
 void drawEllipse(int xc, int yc, int rx, int ry)
          Draws an Ellipse, using the current foreground color as the outline color.
 void drawEllipticalArc(int xc, int yc, int rx, int ry, float startAngle, float endAngle)
          Draws an elliptical arc, using the current foreground color as the outline color.
 void drawEllipticalPie(int xc, int yc, int rx, int ry, float startAngle, float endAngle)
          Draws an elliptical pie slice, using the current foreground color as the outline color.
 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.
 void drawHighLightFrame(int x, int y, int w, int h, Color topLeft, Color bottomRight, boolean yMirror)
          used to draw the topleft lines of a rect with one color and the bottomright with another color. if yMirror, draws the borders mirrowed.
 void drawImage(Image image, int x, int y)
          Draws an image at the given x and y coordinates.
 void drawImage(Image image, int x, int y, int drawOp, Color backColor, boolean doClip)
          Draws the image in the given position with the given draw operation and back color.
 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.
 void drawPie(int xc, int yc, int r, float startAngle, float endAngle)
          Draws a pie slice, using the current foreground color as the outline color.
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Draws a polygon, using the current foreground color as the outline color.
 void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
          Draws a sequence of connected lines, using the current foreground color as the outline color.
 void drawRect(int x, int y, int w, int h)
          Draws a rectangle, using the current foreground color as the outline color.
 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.
 void drawText(char[] chars, int start, int count, int x, int y)
          Draws a text with the current font and the current foregrount color.
 void drawText(String text, int x, int y)
          Draws a text with the current font and the current foregrount color.
 void eraseRect(int x, int y, int w, int h)
          Changes all the pixels with the current foreground color to the current background color
 void fillCircle(int xc, int yc, int r)
          Fills a circle, using the current background color as the fill color.
 void fillEllipse(int xc, int yc, int rx, int ry)
          Fills an Ellipse, using the current background color as the fill color.
 void fillEllipticalPie(int xc, int yc, int rx, int ry, float startAngle, float endAngle)
          Fills an elliptical pie slice, using the current background color as the fill color and the current foreground color as the outline color.
 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.
 void fillPie(int xc, int yc, int r, float startAngle, float endAngle)
          Fills a pie slice, using the current background color as the fill color and the current foreground color as the outline color.
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Fills a polygon, using the current background color as the fill color.
 void fillRect(int x, int y, int w, int h)
          Fills a rectangle, using the current background color as the outline and fill colors.
 void fillRoundRect(int x, int y, int width, int height, int r)
          Fills a rectangle with rounded corners, using the current background color as the fill color.
 void free()
          Frees any system resources (native device contexts) associated with the graphics object.
 Coord getAnglePoint(int xc, int yc, int rx, int ry, float angle)
          Gets the coordinates where the specified point lies.
 Rect getClip(Rect r)
          Gets the current clipping rectangle.
 Font getFont()
          Returns the last font set with setFont
 int getPixel(int x, int y)
          Gets the pixel color index at given position
 Coord getTranslation()
          Returns the current translation from the origin for this Graphics object
 void setBackColor(Color c)
          Sets the current color for background and 2nd color operations.
 void setBackColor(int r, int g, int b)
          Sets the current color for background and 2nd color operations.
 void setClip(int x, int y, int w, int h)
          Sets the clipping rectangle, translated to the current translated origin.
 void setClip(Rect r)
          Sets the clipping rectangle, translated to the current translated origin.
 void setColor(int r, int g, int b)
          Deprecated. Use setForeColor and setBackColor instead.
 void setColors(Color c)
          Sets the current color as the foreground and background colors.
 void setDrawOp(int drawOp)
          Sets the drawing operation.
 void setFont(Font font)
          Sets the current font for operations that draw text.
 void setForeColor(Color c)
          Sets the current color for border and drawing operations.
 void setForeColor(int r, int g, int b)
          Sets the current color for border and drawing operations.
 void setPixel(int x, int y)
          Sets the pixel at the specified position, using the current foreground color as the pixel color.
 String toString()
          Returns the string representation of the object, that is full_class_name@internal_address_hex.
 void translate(int dx, int dy)
          Translates the origin of the of the current coordinate system by the given dx and dy.
 void translateTo(int x, int y)
          Sets the origin of the current coordinate system to x and y.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, wait, wait
 

Field Detail

lastFont

public Font lastFont

drawOp

protected int drawOp

surface

protected ISurface surface

R3D_EDIT

public static final byte R3D_EDIT
used in the draw3dRect method

R3D_LOWERED

public static final byte R3D_LOWERED
used in the draw3dRect method

R3D_RAISED

public static final byte R3D_RAISED
used in the draw3dRect method

R3D_CHECK

public static final byte R3D_CHECK
used in the draw3dRect method

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 drawed; if is false, a listbox shaded is drawed. Also note that the fore color must have been set.

ARROW_UP

public static final byte ARROW_UP
used in the drawArrow method

ARROW_DOWN

public static final byte ARROW_DOWN
used in the drawArrow method

ARROW_LEFT

public static final byte ARROW_LEFT
used in the drawArrow method

ARROW_RIGHT

public static final byte ARROW_RIGHT
used in the drawArrow method

DRAW_PAINT

public static final int DRAW_PAINT
The constant for a draw operation where the destination is replaced with source pixels (copy mode).

DRAW_ERASE

public static final int DRAW_ERASE
The constant for a draw operation where the destination is cleared where source pixels are off (AND mode).

DRAW_MASK

public static final int DRAW_MASK
The constant for a draw operation where the destination is cleared where source pixels are on (AND NOT mode).

DRAW_INVERT

public static final int DRAW_INVERT
The constant for a draw operation where the destination is inverted where source pixels are on (XOR mode).

DRAW_OVERLAY

public static final int DRAW_OVERLAY
The constant for a draw operation where the destination set only where source pixels are on (OR mode).

DRAW_PAINT_INVERSE

public static final int DRAW_PAINT_INVERSE
The constant for a draw operation where the destination is replaced with inverted source (copy NOT mode).

DRAW_SPRITE

public static final int DRAW_SPRITE
The constant for a draw operation where the destination is replaced if source pixels != background color (simulating transparent color).

DRAW_REPLACE_COLOR

public static final int DRAW_REPLACE_COLOR
The constant for a draw operation where the destination is replaced with foreground color if source pixels different of background color. Note that in WindowsCE this operation can be very slow for big images.

DRAW_SWAP_COLORS

public static final int DRAW_SWAP_COLORS
The constant for a draw operation where the foreground color is swaped with the background color. Note that in WindowsCE this operation can be very slow for big images.

currentPalette

protected static int[] currentPalette

ScreenPalette

protected static Palette ScreenPalette
Constructor Detail

Graphics

public Graphics(ISurface surface)
Constructs a graphics object which can be used to draw on the given surface. For the sake of the methods in this class, the given surface is known as the "current surface".

If you are trying to create a graphics object for drawing in a subclass of control, use the createGraphics() method in the Control class. It creates a graphics object and translated the origin to the origin of the control.

Method Detail

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 ellipse
yc - y coordinate of the center of the ellipse
rx - radix x of the ellipse
ry - 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 ellipse
yc - y coordinate of the center of the ellipse
rx - radix x of the ellipse
ry - radix y of the ellipse

drawArc

public void drawArc(int xc,
                    int yc,
                    int r,
                    float startAngle,
                    float 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 arc
startAngle - 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,
                    float startAngle,
                    float 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 pie
startAngle - 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,
                    float startAngle,
                    float 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 pie
startAngle - 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,
                              float startAngle,
                              float 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 pie
ry - y radix of the circle that contains the pie
startAngle - 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,
                              float startAngle,
                              float 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 pie
ry - y radix of the circle that contains the pie
startAngle - 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,
                              float startAngle,
                              float 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 pie
ry - y radix of the circle that contains the pie
startAngle - 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 circle
yc - y coordinate of the center of the circle
r - 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 circle
yc - y coordinate of the center of the circle
r - radix of the circle

getPixel

public int getPixel(int x,
                    int y)
Gets the pixel color index at given position
Parameters:
x - x coordinate of the pixel
y - y coordinate of the pixel
Returns:
the color index of the pixel or -1 if the pixel lies outside the clip bounds. To get the corresponding color, you can use Palette.getColor(g.getPixel(x,y)) for color devices, and (Settings.maxColor-1-g.getPixel(x,y)) for gray scale devices. Note that if the pixel is from an image, you must use the image's palette like here: img.getPalette().getColor(g.getPixel(x,y)) (be sure to read Image.getPalette docs).

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 pixel
y - y coordinate of the pixel

eraseRect

public void eraseRect(int x,
                      int y,
                      int w,
                      int h)
Changes all the pixels with the current foreground color to the current background color

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. The drawLine method is smart, so it calls the fastest methods drawHLine/drawVLine if the line is horizontal/vertical.
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.

clearScreen

public void clearScreen()
Clears the screen bounded by this graphics object using the background color as the clear color.

drawDots

public void drawDots(int Ax,
                     int Ay,
                     int Bx,
                     int By)
Draws a dotted line in any direction, using 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.

drawCursor

public void drawCursor(int x,
                       int y,
                       int w,
                       int h)
Draws a rectangle using the xor operation. So, if drawed twice, the original colors are placed back.
Parameters:
x - left coordinate of the rectangle
y - top coordinate of the rectangle
w - 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.

drawCursorOutline

public void drawCursorOutline(int x,
                              int y,
                              int w,
                              int h)
Draws a rectangle outline using the xor operation. So, if drawed twice, the original colors are placed back.
Parameters:
x - left coordinate of the rectangle
y - top coordinate of the rectangle
w - 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.
Since:
SuperWaba2.0beta4

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 rectangle
y - top coordinate of the rectangle
w - 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 outline and fill colors. If the coords are equal to the device screen size, it uses the faster clearScreen.
Parameters:
x - left coordinate of the rectangle
y - top coordinate of the rectangle
w - 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.

drawDottedRect

public void drawDottedRect(int x,
                           int y,
                           int w,
                           int h)
Draws a dotted rectangle, using the current foreground color as the 1st, 3rd, ... pixels and the background color as the 2nd, 4th, ... pixels.
Parameters:
x - left coordinate of the rectangle
y - top coordinate of the rectangle
w - width of the rectangle. the rectangle is drawed from x to x+w-1.
h - height of the rectangle. the rectangle is drawed 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 points
yPoints - the array with the y coordinate points
nPoints - the total number of point to be drawn.

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 points
yPoints - the array with the y coordinate points
nPoints - the total number of point to be drawn.

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 points
yPoints - the array with the y coordinate points
nPoints - the total number of point to be drawn.

getAnglePoint

public Coord getAnglePoint(int xc,
                           int yc,
                           int rx,
                           int ry,
                           float angle)
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.
Parameters:
xc - x coordinate of the center of the circle
yc - y coordinate of the center of the circle
rx - x radix of the circle that contains the point
ry - y radix of the circle that contains the point
angle - angle of the point. It must be between 0 and 360 (degrees). 0º is at 3 o'clock.
Returns:
the Coord
See Also:
Coord

drawText

public void drawText(char[] chars,
                     int start,
                     int count,
                     int x,
                     int y)
Draws a text with the current font and the current foregrount color. This method is slower than drawText(String,x,y) because it convert the chars to a string.
Parameters:
chars - the character array to display
start - the start position in array
count - the number of characters to display
x - the left coordinate of the text's bounding box
y - the top coordinate of the text's bounding box

drawText

public void drawText(String text,
                     int x,
                     int y)
Draws a text with the current font and the current foregrount color.
Parameters:
text - the text to be drawn
x - x coordinate of the text
y - y coordinate of the text

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 rectangle
y - top coordinate of the rectangle
w - 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.
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 x,
                          int y,
                          int width,
                          int height,
                          int r)
Fills a rectangle with rounded corners, using the current background color as the fill color.
Parameters:
x - left coordinate of the rectangle
y - top coordinate of the rectangle
w - 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.
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 rectangle
y - top coordinate of the rectangle
w - 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.

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 + dx
dy - the delta y of the y coordinate translation. the new y origin coordinate will be y + dy

copyRect

public void copyRect(ISurface 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.

Not all combinations of surfaces are supported on all platforms. Java doesn't allow copying from an Window surface to an Image.

If the bitmap surface being transferred has the width of the screen and starts at x=0, the drawing occurs almost instantaneously.

Parameters:
surface - the surface to copy from
x - the source x coordinate
y - the source y coordinate
width - the width of the area on the source surface
height - the height of the area on the source surface
dstX - the destination x location on the current surface
dstY - the destination y location on the current surface
See Also:
setDrawOp(int)

free

public void free()
Frees any system resources (native device contexts) associated with the graphics object. After calling this function, the graphics object can no longer be used to draw. Calling this method is not required since any system resources allocated will be freed when the object is garbage collected. However, if a program uses many graphics objects, free() should be called whenever one is no longer needed to prevent allocating too many system resources before garbage collection can occur. Note that calling free on Graphics created from Image objects is useless.

setColor

public void setColor(int r,
                     int g,
                     int b)
Deprecated. Use setForeColor and setBackColor instead.

For backward compatibility only. This method is slower

setForeColor

public void setForeColor(Color c)
Sets the current color for border and drawing operations.
Parameters:
c - the Color object with the r,g,b values

setBackColor

public void setBackColor(Color c)
Sets the current color for background and 2nd color operations.
Parameters:
c - the Color object with the r,g,b values

setForeColor

public void setForeColor(int r,
                         int g,
                         int b)
Sets the current color for border and drawing operations.
Parameters:
r - the red value (0..255)
g - the green value (0..255)
b - the blue value (0..255)

setBackColor

public void setBackColor(int r,
                         int g,
                         int b)
Sets the current color for background and 2nd color operations.
Parameters:
r - the red value (0..255)
g - the green value (0..255)
b - the blue value (0..255)

setFont

public void setFont(Font font)
Sets the current font for operations that draw text.

collisionDetect

public boolean collisionDetect(ISurface surface,
                               int x1,
                               int y1,
                               Image img,
                               int x2,
                               int y2)
Tests if a surface collides with an image. Note that the surface *can* also be an image. The coordinates of both images are tested relative to the same origin.
Parameters:
surface - one image or Window to test for collision
x1 - the left position where this image is "drawn"
y1 - the top position where this Image is "drawn"
img2 - the other image to test for collision
x2 - the left position where the other image is "drawn"
y2 - the top position where the other Image is "drawn"
Returns:
true if both image bounds intersects and if there are pixels whose color is different of the current background color in both images

getTranslation

public Coord getTranslation()
Returns the current translation from the origin for this Graphics object

applyPalette

public static void applyPalette(Palette pal,
                                int startIndex,
                                int endIndex)
apply the palette. since theres only one applied palette at any time, this method is static. If you had modified only few colors in the palette, specify its indexes or specify -1,-1 to apply all indexes of the palette. To get the current applied palette, create a palette with the default constructor, eg: new Palette().

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 rectangle
y - top coordinate of the rectangle
w - 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.
top - true if the top corners will be hatched
bottom - 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 rectangle
y - top coordinate of the rectangle
w - 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.
top - true if the top corners will be hatched
bottom - true if the bottom corners will be hatched

drawHighLightFrame

public void drawHighLightFrame(int x,
                               int y,
                               int w,
                               int h,
                               Color topLeft,
                               Color bottomRight,
                               boolean yMirror)
used to draw the topleft lines of a rect with one color and the bottomright with another color. if yMirror, draws the borders mirrowed.

translateTo

public void translateTo(int x,
                        int y)
Sets the origin of the current coordinate system to x and y. 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 + dx
dy - the delta y of the y coordinate translation. the new y origin coordinate will be y + dy

drawImage

public void drawImage(Image image,
                      int x,
                      int y,
                      int drawOp,
                      Color backColor,
                      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. A cache is made comparing the last back color with the current one. This comparision is by reference, so, be sure to use the same color instead of creating a new one with "new Color(xxx)"; otherwise, the cache will never be used. If drawOp is DRAW_PAINT, backGround can be null. If drawOp is DRAW_SPRITE, you must provide the background color. 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 image,
                          int x,
                          int y,
                          int width,
                          int height,
                          int drawOp,
                          Color backColor,
                          boolean doClip)

copyScreen

public void copyScreen(ISurface src,
                       int ySrc,
                       int yDst,
                       int height)
Copies the given surface to this surface. This will ignore any clippings and also will use the fastest transfer method. It will transfer the areas 0, ySrc, Settings.screenWidth, height to 0, yDst, Settings.screenWidth, height. The draw operation will be DRAW_PAINT.

drawImage

public void drawImage(Image image,
                      int x,
                      int y)
Draws an image at the given x and y coordinates. Note: you can pass waba.ui.Control.CENTER as parameter to x and/or y. You can also pass waba.ui.Control.CENTER+delta, where delta is a number greater or lower than 0 to place the image relative from the center place. EG: CENTER+2 (place at the center + 2 pixels to right or bottom, depending on which parameter you're using). You can also use LEFT,RIGHT,TOP and BOTTOM.
See Also:
copyRect(waba.fx.ISurface, int, int, int, int, int, int)

setColors

public void setColors(Color c)
Sets the current color as the foreground and background colors. This method has the same effect as calling setForeColor(c) and setBackColor(c).
Parameters:
c - the Color object with the r,g,b values

setDrawOp

public void setDrawOp(int drawOp)
Sets the drawing operation. The setting determines the raster operation to use when drawing lines, rectangles, text and images on the current surface. It also determines how pixels are combined when copying one surface to another. The setting of DRAW_OVER, where any drawing simply draws over the pixels on a surface, is the default.

Not all operations are supported on all platforms. When used with Java, DRAW_OVER is supported for all types of drawing and DRAW_XOR is supported for drawing lines, rectangles, text and images. However, DRAW_XOR is not supported when copying surface areas and the DRAW_AND and DRAW_OR operations aren't supported at all under Java.

PalmOS platforms supports all the drawing operations when drawing images and copying surface regions. However, only the DRAW_OVER operation is supported when drawing lines, rectangles and text. If you need to use the XOR drawing operation for drawing lines under PalmOS, you can draw the line into an image and then draw the image with an XOR drawing operation.

Win32 and Windows CE platforms support all the drawing operations except when drawing text. Only DRAW_OVER is supported when drawing text. If you need to draw XOR'ed text, you can draw the text into an image and then draw the image with an XOR draw operation.

When calculating the result of XOR, AND and OR drawing, the value of the color black is all 1's (fully set) in binary and white is all 0's (fully unset).

Parameters:
op - drawing operation
See Also:
DRAW_PAINT, DRAW_ERASE, DRAW_MASK, DRAW_INVERT, DRAW_OVERLAY, DRAW_PAINT_INVERSE, DRAW_SPRITE, DRAW_REPLACE_COLOR, DRAW_SWAP_COLORS

getFont

public Font getFont()
Returns the last font set with setFont

compute3dColors

public static void compute3dColors(boolean enabled,
                                   Color backColor,
                                   Color foreColor,
                                   Color[] 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).

draw3dRect

public void draw3dRect(int x,
                       int y,
                       int width,
                       int height,
                       byte type,
                       boolean yMirror,
                       boolean simple,
                       Color[] fourColors)
draws a 3d rect, defined by the R3D_xxx constants. Note that if oldStyle is true, the 3d rect turns back to the control style

toString

public String toString()
Description copied from class: Object
Returns the string representation of the object, that is full_class_name@internal_address_hex. Note that, differently from JDK, the package separator is / instead of .
Overrides:
toString in class Object

drawArrow

public void drawArrow(int x,
                      int y,
                      int h,
                      byte type,
                      boolean pressed,
                      boolean enabled,
                      Color fore)
Draws an arrow. use the ARROW_xxx type. h 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. h must be >= 2 or no arrow is drawn. The fore and back colors are changed after this method is called.

Example:

 public void onPaint(Graphics g)
 {
    g.drawArrow(30,30,8, g.ARROW_LEFT, false,true, Color.BLACK );
 ...
 

_applyPalette

protected static void _applyPalette(int[] palrgb,
                                    int startIndex,
                                    int endIndex)