|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
DirectGraphics contains some graphics extensions to MIDP Graphics: drawing triangles, drawing manipulated images (rotated, flipped) and drawing raw pixel array directly to graphics context.
DirectUtils class can be used to convert standard Graphics to proprietary DirectGraphics object:
DirectGraphics dg = DirectUtils.getDirectGraphics(g);The operations to DirectGraphics reference will affect also original graphics context, for example, setting color of DirectGraphics will change current painting color of Graphics and vice versa. In fact developer can see DirectGraphics as a new way to do call to Graphics. DirectGraphics doesn't inherit standard Graphics because of API dependency reasons.
ARGB values used with some methods of this interface are interpreted with the least significant eight bits giving the blue component, the next eight more significant bits giving the green component, the next eight more significant bits giving the red component and the next eight more significant bits giving the alpha component. That is to say, the color component is specified in the form of 0xAARRGGBB. This correspons to native format specified by { @link DirectGraphics#TYPE_ARGB_8888 }.
Manipulation parameters to drawPixels are formed by bitwise ORring FLIP_HORIZONTAL or FLIP_VERTICAL with a degree value: ROTATE_90, ROTATE_180 or ROTATE_270. Currently only these constant defined degree values are supported when rotating images.
Copyright (c) 2001 Nokia Mobile Phones
Field Summary | |
static int |
FLIP_HORIZONTAL
Constant for horizontal image flipping. |
static int |
FLIP_VERTICAL
Constant for vertical image flipping. |
static int |
FORM_CHOICE_HIGHLIGHT_BORDER_TYPE
Constant for drawing the Form's Choice element highlight border type. |
static int |
FORM_ITEM_BORDER_TYPE
Constant for drawing the Form's item border type. |
static int |
FORM_TEXT_FIELD_BORDER_TYPE
Constant for drawing the Form's TextField border type. |
static int |
ROTATE_180
Constant for rotating image 180 degrees counter-clockwise. |
static int |
ROTATE_270
Constant for rotating image 270 degrees counter-clockwise. |
static int |
ROTATE_90
Constant for rotating image 90 degrees counter-clockwise. |
static int |
TYPE_BYTE_1_GRAY
1 bit format, 2 distinct color values (on/off), stored as a byte. |
static int |
TYPE_BYTE_1_GRAY_VERTICAL
1 bit format, 2 distinct color values (on/off), stored as a byte. |
static int |
TYPE_BYTE_2_GRAY
2 bit format, 4 gray scale colors. |
static int |
TYPE_BYTE_332_RGB
3 bits for red, 3 bits for green, and 2 bits for blue component in a pixel, stored as a byte. |
static int |
TYPE_BYTE_4_GRAY
4 bit format, 16 gray scale colors. |
static int |
TYPE_BYTE_8_GRAY
8 bit format, 256 gray scale colors. |
static int |
TYPE_INT_888_RGB
8 bits for red, green and blue component in a pixel (0x00RRGGBB). |
static int |
TYPE_INT_8888_ARGB
8 bits for alpha, red, green and blue component in a pixel (0xAARRGGBB). |
static int |
TYPE_USHORT_1555_ARGB
1 bit for alpha, 5 bits for red, green and blue component in a pixel. |
static int |
TYPE_USHORT_444_RGB
4 bits for red, green and blue component in a pixel, stored as a short (0x0RGB). |
static int |
TYPE_USHORT_4444_ARGB
4 bits for alpha, red, green and blue component in a pixel, stored as a short (0xARGB). |
static int |
TYPE_USHORT_555_RGB
5 bits for red, green and blue component in a pixel. |
static int |
TYPE_USHORT_565_RGB
5 bits for red, 6 bits for green and 5 bits for blue component in a pixel. |
Method Summary | |
void |
clearClippedArea(boolean useBackgroundImage,
boolean transparentFill)
Clears the graphics area bounded by the current clip area, subject to the currently set clipArea. |
void |
drawElementBorder(int x,
int y,
int w,
int h,
int borderType,
boolean withFocus)
Draws the specified border type at the specified coordinates. |
void |
drawHighlight(int x,
int y,
int w,
int h,
int d)
Draws a highlight at the specified coordinates. |
void |
drawImage(javax.microedition.lcdui.Image img,
int x,
int y,
int anchor,
int manipulation)
Draws image to the graphics context. |
void |
drawPixels(byte[] pixels,
byte[] transparencyMask,
int offset,
int scanlength,
int x,
int y,
int width,
int height,
int manipulation,
int format)
Copies or draws the pixel data directly to graphics context to specific location. |
void |
drawPixels(int[] pixels,
boolean transparency,
int offset,
int scanlength,
int x,
int y,
int width,
int height,
int manipulation,
int format)
Copies or draws the pixel data directly to graphics context to specific location from the array starting from specified offset. |
void |
drawPixels(short[] pixels,
boolean transparency,
int offset,
int scanlength,
int x,
int y,
int width,
int height,
int manipulation,
int format)
Copies or draws the pixel data directly to graphics context to specific location. |
void |
drawPolygon(int[] xPoints,
int xOffset,
int[] yPoints,
int yOffset,
int nPoints,
int argbColor)
Draws a closed polygon defined by arrays of x and y coordinates. |
void |
drawTriangle(int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int argbColor)
Draws closed triangle defined by coordinates. |
void |
fillPolygon(int[] xPoints,
int xOffset,
int[] yPoints,
int yOffset,
int nPoints,
int argbColor)
Fills a closed polygon defined by arrays of x and y coordinates. |
void |
fillTriangle(int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int argbColor)
Fills closed triangle defined by coordinates. |
int |
getAlphaComponent()
Gets the alpha component of the current color. |
int |
getNativePixelFormat()
Returns the native color format used, for example, DirectGraphics#TYPE_BYTE_GRAY_1 or
DirectGraphics#TYPE_USHORT_ARGB_4444 . |
void |
getPixels(byte[] pixels,
byte[] transparencyMask,
int offset,
int scanlength,
int x,
int y,
int width,
int height,
int format)
Gets the pixel (including any transparency mask) values of an image to an array of byte values from specific screen location. |
void |
getPixels(int[] pixels,
int offset,
int scanlength,
int x,
int y,
int width,
int height,
int format)
Gets the pixel values of an image to an array of ARGB values. |
void |
getPixels(short[] pixels,
int offset,
int scanlength,
int x,
int y,
int width,
int height,
int format)
Gets the pixel values of an image to an array of short values from specific screen location. |
void |
setARGBColor(int argbColor)
Sets the current color to the specified ARGB value. |
Field Detail |
public static final int FLIP_HORIZONTAL
drawImage(Image img, int x, int y, int anchor, int manipulation)
,
Constant Field Valuespublic static final int FLIP_VERTICAL
drawImage(Image img, int x, int y, int anchor, int manipulation)
,
Constant Field Valuespublic static final int ROTATE_90
(ROTATE_90 * 2) results 180 degree rotate.
(ROTATE_90 * 3) results 270 degree rotate.
drawImage(Image img, int x, int y, int anchor, int manipulation)
,
Constant Field Valuespublic static final int ROTATE_180
drawImage(Image img, int x, int y, int anchor, int manipulation)
,
Constant Field Valuespublic static final int ROTATE_270
drawImage(Image img, int x, int y, int anchor, int manipulation)
,
Constant Field Valuespublic static final int TYPE_BYTE_1_GRAY_VERTICAL
BYTE 0 1 2 3 4 5 6 7 LSB + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MSB + + + + byte [] byteArray = new byte[8] byteArray[0] = 0xFF // binary 11111111 byteArray[1] = 0xFF // binary 11111111 byteArray[2] = 0x0E // binary 00001110 byteArray[3] = 0x1C // binary 00011100 byteArray[4] = 0x38 // binary 00111000 byteArray[5] = 0x70 // binary 01110000 byteArray[5] = 0xFF // binary 11111111 byteArray[7] = 0xFF // binary 11111111
public static final int TYPE_BYTE_1_GRAY
public static final int TYPE_BYTE_2_GRAY
public static final int TYPE_BYTE_4_GRAY
public static final int TYPE_BYTE_8_GRAY
public static final int TYPE_BYTE_332_RGB
public static final int TYPE_USHORT_4444_ARGB
public static final int TYPE_USHORT_444_RGB
public static final int TYPE_USHORT_555_RGB
public static final int TYPE_USHORT_1555_ARGB
public static final int TYPE_USHORT_565_RGB
public static final int TYPE_INT_888_RGB
public static final int TYPE_INT_8888_ARGB
public static final int FORM_ITEM_BORDER_TYPE
public static final int FORM_TEXT_FIELD_BORDER_TYPE
public static final int FORM_CHOICE_HIGHLIGHT_BORDER_TYPE
Method Detail |
public int getAlphaComponent()
public void setARGBColor(int argbColor)
argbColor
- the color being setpublic void drawImage(javax.microedition.lcdui.Image img, int x, int y, int anchor, int manipulation)
img
- the specified image to be drawnx
- the x coordinate of the anchor pointy
- the y coordinate of the anchor pointanchor
- the anchor point for positioning the imagemanipulation
- flip or rotate value or a combination of values, 0 if
none
java.lang.IllegalArgumentException
- if anchor is not a legal value or
manipulation is not supported
java.lang.NullPointerException
- if img is nullImage
,
FLIP_VERTICAL
,
FLIP_HORIZONTAL
,
ROTATE_90
public void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argbColor)
Note that the method uses the color passed as a parameter for drawing the triangle and not the current active color of graphics context. This is due to efficiency reasons as it is expected that the method may be called several times in each repaint cycle, thus separate calls to setColor would create unnecessary overhead. The call won't change the current active drawing color of graphics context.
x1
- the x coordinate of first vertexy1
- the y coordinate of first vertexx2
- the x coordinate of second vertexy2
- the y coordinate of second vertexx3
- the x coordinate of third vertexy3
- the y coordinate of third vertexargbColor
- the ARGB color value used painting the trianglepublic void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argbColor)
Note that the method uses the color passed as a parameter for drawing the triangle and not the current active color of graphics context. This is due to efficiency reasons as it is expected that the method may be called several times in each repaint cycle, thus separate calls to setColor would create unnecessary overhead. The call won't change the current active drawing color of graphics context.
x1
- the x coordinate of first vertexy1
- the y coordinate of first vertexx2
- the x coordinate of second vertexy2
- the y coordinate of second vertexx3
- the x coordinate of third vertexy3
- the y coordinate of third vertexargbColor
- the ARGB color value used painting the trianglepublic void drawPolygon(int[] xPoints, int xOffset, int[] yPoints, int yOffset, int nPoints, int argbColor)
This method draws the polygon defined by nPoint line segments, where the first nPoint - 1 line segments are line segments from (xPoints[xOffset + i - 1], yPoints[yOffset + i - 1]) to (xPoints[xOffset + i], yPoints[yOffset + i]), for 1 <= i <= nPoints. The figure is automatically closed by drawing a line connecting the final point to the first point, if those points are different.
xPoints
- an array of x coordinatesxOffset
- an offset to first x point in xPointsyPoints
- an array of y coordinatesyOffset
- an offset to first y point in yPointsnPoints
- the total number of pointsargbColor
- the ARGB color value used painting the polygonpublic void fillPolygon(int[] xPoints, int xOffset, int[] yPoints, int yOffset, int nPoints, int argbColor)
This method draws the polygon defined by nPoint line segments, where the first nPoint - 1 line segments are line segments from (xPoints[xOffset + i - 1], yPoints[yOffset + i - 1]) to (xPoints[xOffset + i], yPoints[yOffset + i]), for 1 <= i <= nPoints. The figure is automatically closed by drawing a line connecting the final point to the first point, if those points are different.
The area inside the polygon is defined using an even-odd fill rule, also known as the alternating rule.
xPoints
- an array of x coordinatesxOffset
- an offset to first x point in xPointsyPoints
- an array of y coordinatesyOffset
- an offset to first y point in yPointsnPoints
- the total number of pointsargbColor
- the ARGB color value used painting the polygonpublic void drawPixels(int[] pixels, boolean transparency, int offset, int scanlength, int x, int y, int width, int height, int manipulation, int format)
pixels
- an array of pixel values (0xAARRGGBB)transparency
- true if the pixel's transparency value will be checkedoffset
- the index of the first pixel valuescanlength
- the relative array offset between the corresponding
pixels in consecutive rowsx
- the horizontal rendering location on graphics contexty
- the vertical rendering location on graphics contextwidth
- the width of the region to the renderedheight
- the height of the region to the renderedmanipulation
- the manipulation done to the image before the draw,
0 means none.format
- the display format used
java.lang.NullPointerException
- if pixels is null
java.lang.ArrayIndexOutOfBoundsException
- if requested to access
java.lang.IllegalArgumentException
- if foramt is not supported
pixels beyond the length of array or with negative indexpublic void getPixels(int[] pixels, int offset, int scanlength, int x, int y, int width, int height, int format)
pixels
- an array in which the image pixel information will be storedoffset
- the index into the array where the first pixel value will be
storedscanlength
- the relative offset in the array between corresponding
pixels in consecutive rowsx
- the x-coordinate of the upper left corner of the regiony
- the y-coordinate of the upper left corner of the regionwidth
- the width of the regionheight
- the height of the regionformat
- the display format used
java.lang.NullPointerException
- if pixels is null
java.lang.ArrayIndexOutOfBoundsException
- if array size is too small
java.lang.IllegalArgumentException
- if foramt is not supported
for the image pixels or negative index access is attempted, contents of
the array remain unchangedpublic void getPixels(byte[] pixels, byte[] transparencyMask, int offset, int scanlength, int x, int y, int width, int height, int format)
This method is used getting pixel data from the graphics context in native formats. Pixels are returned in format defined by getNativePixelFormat() method. If the native format is not byte based then this method converts the pixel data to TYPE_BYTE_GRAY_1 format and returns that.
pixels
- an array in which the image pixel information will be storedtransparencyMask
- an array in which the transparency mask will be
storedoffset
- the index into the array where the first pixel and mask value
will be storedscanlength
- the relative offset in the array between corresponding
pixels and mask value in consecutive rowsx
- the x-coordinate of the upper left corner of the regiony
- the y-coordinate of the upper left corner of the regionwidth
- the width of the regionheight
- the height of the regionformat
- the display format used
java.lang.NullPointerException
- if pixels is null
java.lang.ArrayIndexOutOfBoundsException
- if array size is too small
java.lang.IllegalArgumentException
- if foramt is not supported
for the image pixels or negative index access is attempted, contents of
the array remain unchangedpublic void getPixels(short[] pixels, int offset, int scanlength, int x, int y, int width, int height, int format)
This method is used getting pixel data from the graphics context in native formats. Pixels are returned in format defined by getNativePixelFormat() method. If the native format is not short based then this method converts the pixel data to TYPE_USHORT_ARGB_4444 format and returns that.
pixels
- an array in which the image pixel information will be storedoffset
- the index into the array where the first pixel value will be
storedscanlength
- the relative offset in the array between corresponding
pixels in consecutive rowsx
- the x-coordinate of the upper left corner of the regiony
- the y-coordinate of the upper left corner of the regionwidth
- the width of the regionheight
- the height of the regionformat
- the display format used
java.lang.NullPointerException
- if pixels is null
java.lang.ArrayIndexOutOfBoundsException
- if array size is too small
java.lang.IllegalArgumentException
- if foramt is not supported
for the image pixels or negative index access is attempted, contents of
the array remain unchangedpublic void drawPixels(byte[] pixels, byte[] transparencyMask, int offset, int scanlength, int x, int y, int width, int height, int manipulation, int format)
pixels
- an array of pixel valuestransparencyMask
- an array defining transparency maskoffset
- the index of the first pixel and mask valuescanlength
- the relative array offset between the corresponding
pixels and mask value in consecutive rowsx
- the horizontal rendering location on graphics contexty
- the vertical rendering location on graphics contextwidth
- the width of the region to the renderedheight
- the height of the region to the renderedmanipulation
- the manipulation done to the image before the draw,
0 means none.format
- the display format used
java.lang.NullPointerException
- if pixels is null
java.lang.ArrayIndexOutOfBoundsException
- if requested to access
java.lang.IllegalArgumentException
- if foramt is not supported
beyond the length of array or with negative indexpublic void drawPixels(short[] pixels, boolean transparency, int offset, int scanlength, int x, int y, int width, int height, int manipulation, int format)
pixels
- an array of pixel valuestransparency
- true if the pixel's transparency value will be checkedoffset
- the index of the first pixel valuescanlength
- the relative array offset between the corresponding
pixels in consecutive rowsx
- the horizontal rendering location on graphics contexty
- the vertical rendering location on graphics contextwidth
- the width of the region to the renderedheight
- the height of the region to the renderedmanipulation
- the manipulation done to the image before the draw,
0 means none.format
- the display format used
java.lang.NullPointerException
- if pixels is null
java.lang.ArrayIndexOutOfBoundsException
- if requested to access
java.lang.IllegalArgumentException
- if foramt is not supported
beyond the length of array or with negative indexpublic int getNativePixelFormat()
DirectGraphics#TYPE_BYTE_GRAY_1
or
DirectGraphics#TYPE_USHORT_ARGB_4444
.
Application can check the expected by drawPixels and
returned from getPixels methods of this interface.
public void drawHighlight(int x, int y, int w, int h, int d)
IdleItem#paint(Graphics, int, int, boolean)
and will draw a highlighted
area in the colour and style determined by the current theme.
x
- the x coordinate for the highlight areay
- the y coordinate for the highlight areaw
- the width of the highlight areah
- the height of the highlight aread
- the direction to scroll (0 - undefined, 1 - scroll up, 2 scroll down)public void clearClippedArea(boolean useBackgroundImage, boolean transparentFill)
useBackgroundImage
- If true, the default Java background image
is copied to the screen. If the background
image is invalid, then the clip area is
cleared with the default background color.transparentFill
- If true, the pixmap is filled with fully
transparent pixels. Note: this field is
used if, and only if useBackgroundImage
is set to false.
public void drawElementBorder(int x, int y, int w, int h, int borderType, boolean withFocus)
x
- the x coordinate of the border to be drawny
- the y coordinate of the border to be drawnborderType
- the border type to draw.
java.lang.IllegalArgumentException
- if the specified border type is invalid.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |