|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface XGraphics
The XGraphics interface offers a variety of enhancements over the Graphics interface. Apart from offering more drawing methods (such as for drawing polygons or ovals), it has two fundamental changes:
Clipping and translation allows to reduce the area in the framebuffer that
is possible to draw on. Furthermore, through translation, it's possible to
define, in a very limited sense, local coordinate systems, simply by moving
the translation point to the desired coordinate origin. All drawing methods
of XGraphics classes will add this origin position to the locations
specified in their calls.
For example, setting the translation point to (0,0) and then drawing an
image to location (100,100) has the same effect as setting the translation
point to (100,100) and drawing the image to location (0,0).
This comes in handy in creating user interfaces, where before drawing
a widget the translation point is adjusted accordingly. This allows the
implementation of the widget's graphical appearance to imply that the
point (0,0) lies in it's upper left corner, thus making the implementation
independent (and more readable) from the widget's position.
By defining a clipping rectangle before drawing, it's also possible to limit
the area a widget can draw in. This can prevent from drawing outside the
area, that a widget actually covers.
While the possibility of having multiple instances is not a requirement for
Graphics
objects, it is one for XGraphics
objects.
In a multi threading environment, this feature can be used to have more than
one thread drawing on a display simulatously without having to take care
of the synchronization in the main application.
Important note: When setting drawing and
background colors, it's important to know that the color format is ARGB, which
means that 8 bits are used for defining a color's translucency, where 0 means
that a color is fully transparent (invisible) and 255 means that a color is
opaque. When simply using RGB values in setColor
or setBackground
,
like 0xFF0000
for red, the translucency value is 0 always, which
means that the color is invisible. The right way to define an opaque color is to
supply a 0xFF in the value's high byte, e.g. 0xFFFF0000
for red or
0xFF00FFFF
for cyan.
Field Summary | |
---|---|
static int |
ANCHOR_BASELINE
anchor for aligning text |
static int |
ANCHOR_BOTTOM
anchor for aligning text and images |
static int |
ANCHOR_HCENTER
anchor for aligning text and images |
static int |
ANCHOR_LEFT
anchor for aligning text and images |
static int |
ANCHOR_RIGHT
anchor for aligning text and images |
static int |
ANCHOR_TOP
anchor for aligning text and images |
static int |
ANCHOR_VCENTER
anchor for aligning text and images |
static int |
DRAWMODE_AND
drawmode: logical AND |
static int |
DRAWMODE_INVERSE
drawmode: inverse (use background color for drawing and foreground color for clearing) |
static int |
DRAWMODE_MASK
drawmode: masked (draw masked text and JCIF1 images (i.e. background doesn't get cleared) |
static int |
DRAWMODE_NORMAL
drawmode: replace pixels |
static int |
DRAWMODE_OR
drawmode: logical OR |
static int |
DRAWMODE_XOR
drawmode: logical XOR |
static int |
MAX_BRIGHTNESS
maximum backlight brightness |
static int |
MAX_CONTRAST
maximum backlight contrast |
static int |
MIN_BRIGHTNESS
minimum backlight brightness |
static int |
MIN_CONTRAST
minimum backlight contrast |
static int |
STROKEMODE_DOTTED
strokemode: draw dotted (or broken) lines (rects, ovals, etc.) |
static int |
STROKEMODE_SOLID
strokemode: draw solid lines (rects, ovals, etc.) |
Fields inherited from interface jcontrol.io.Graphics |
---|
AND, INVERSE, NORMAL, OR, XOR |
Method Summary | |
---|---|
boolean |
clipRect(int x,
int y,
int width,
int height)
Downsizes the current clipping rectangle by intersection with the given rectangle. |
XGraphics |
cloneXGraphics()
Creates a clone of this XGraphics object that has the same settings as this one, but acts independently. |
void |
copyArea(int x,
int y,
int width,
int height,
int dx,
int dy)
Copies an area within the framebuffer. |
void |
drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Draws an elliptic arc. |
int |
drawChar(char c,
int x,
int y)
Draws a single character with the currently set font. |
int |
drawChar(char c,
int x,
int y,
int anchor)
Draws a single character with the currently set font. |
void |
drawImage(Object drawable,
int x,
int y,
int anchor)
Draws an image. |
void |
drawOval(int x,
int y,
int width,
int height)
Draws an ellipse. |
void |
drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
Draws a closed polyline. |
void |
drawPolyline(int[] xPoints,
int[] yPoints,
int nPoints)
Draws a polyline. |
void |
drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Draws a rounded rectangle. |
void |
drawString(String s,
int x,
int y,
int anchor)
Draws a text string with the currently set font. |
void |
fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Draws a filled elliptic arc, which is similar to a pie charts element. |
void |
fillOval(int x,
int y,
int width,
int height)
Draws a filled ellipse. |
void |
fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
Draws a polygon. |
void |
fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Draws a filled rounded rectangle. |
int |
getBackground()
Returns the ARGB value of the current background color. |
int |
getClipHeight()
Returns the current clipping rectangle's height. |
int |
getClipWidth()
Returns the current clipping rectangle's width. |
int |
getClipX()
Returns the current clipping rectangle's x-location relatively to the translation point. |
int |
getClipY()
Returns the current clipping rectangle's y-location relatively to the translation point. |
int |
getColor()
Returns the ARGB value of the current drawing color. |
Object |
getFont()
Returns the currently set font. |
int |
getStrokeMode()
Returns the current stroke mode. |
int |
getTranslateX()
Get's the translation point's x-location. |
int |
getTranslateY()
Get's the translation point's y-location. |
boolean |
isClipRectEmpty()
Checks, if the current clipping rectangle is empty (i.e. doesn't cover any pixel). |
boolean |
isOverlapping(int x,
int y,
int width,
int height)
Checks, if the given rectangle overlaps (or - mathematically spoken - intersects) with the current clipping rectangle. |
void |
scroll(int dx,
int dy)
Scrolls the area specified by the clipping rectangle. |
void |
setBackground(Color c)
Sets the background color. |
void |
setBackground(int c)
Sets the background color. |
void |
setClip(int x,
int y,
int width,
int height)
Sets the clipping rectangle. |
void |
setColor(Color c)
Sets the drawing color. |
void |
setColor(int c)
Sets the drawing color. |
void |
setStrokeMode(int mode)
Sets the stroke mode. |
void |
swapColors()
Swaps drawing and background color. |
void |
translate(int dx,
int dy)
Moves the translation (origin) point. |
Methods inherited from interface jcontrol.io.Graphics |
---|
clearRect, drawImage, drawImage, drawLine, drawRect, drawString, drawString, fillRect, getDrawMode, getFontHeight, getPixel, getTextWidth, setDrawMode, setFont, setPixel |
Field Detail |
---|
static final int DRAWMODE_NORMAL
static final int DRAWMODE_AND
static final int DRAWMODE_OR
static final int DRAWMODE_XOR
static final int DRAWMODE_INVERSE
static final int DRAWMODE_MASK
static final int ANCHOR_TOP
static final int ANCHOR_BOTTOM
static final int ANCHOR_VCENTER
static final int ANCHOR_BASELINE
static final int ANCHOR_LEFT
static final int ANCHOR_RIGHT
static final int ANCHOR_HCENTER
static final int STROKEMODE_SOLID
static final int STROKEMODE_DOTTED
static final int MIN_BRIGHTNESS
static final int MAX_BRIGHTNESS
static final int MIN_CONTRAST
static final int MAX_CONTRAST
Method Detail |
---|
void setStrokeMode(int mode)
stroke
- mode (STROKEMODE_SOLID or STROKEMODE_DOTTED)int getStrokeMode()
void scroll(int dx, int dy)
dx
- horizontal scrolling offsetdy
- vertical scrolling offsetvoid drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
x
- x-location of the underlying ellipsey
- y-location of the underlying ellipsewidth
- width of the underlying ellipseheight
- height of the underlying ellipsestartAngle
- angle from where to start drawing (in degrees)arcAngle
- angle along which the arc has to be drawn (in degrees)void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
x
- x-location of the underlying ellipsey
- y-location of the underlying ellipsewidth
- width of the underlying ellipseheight
- height of the underlying ellipsestartAngle
- angle from where to start drawing (in degrees)arcAngle
- angle along which the arc has to be drawn (in degrees)void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
x
- x-locationy
- y-locationwidth
- widthheight
- heightarcWidth
- arcHeight
- void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
x
- x-locationy
- y-locationwidth
- widthheight
- heightarcWidth
- arcHeight
- void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
xPoints
- x-locations of the polyline's pointsyPoints
- y-locations of the polyline's pointsnPoints
- number of pointsdrawPolyline(int[], int[], int)
void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
xPoints
- x-locations of the polyline's pointsyPoints
- y-locations of the polyline's pointsnPoints
- number of pointsdrawPolygon(int[], int[], int)
void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
xPoints
- x-locations of the polygon's pointsyPoints
- y-locations of the polygon's pointsnPoints
- number of pointsvoid drawOval(int x, int y, int width, int height)
x
- x-locationy
- y-locationwidth
- widthheight
- heightvoid fillOval(int x, int y, int width, int height)
x
- x-locationy
- y-locationwidth
- widthheight
- heightvoid setColor(int c)
setColor
in interface Graphics
c
- new drawing color (ARGB value)void setColor(Color c)
c
- new drawing colorint getColor()
void setBackground(int c)
setBackground
in interface Graphics
c
- new background color (ARGB value)void setBackground(Color c)
c
- new background colorint getBackground()
void swapColors()
int drawChar(char c, int x, int y)
drawChar
in interface Graphics
c
- character to drawx
- x-locationy
- y-location
Graphics.setFont(Object)
,
Graphics.drawString(String, int, int)
int drawChar(char c, int x, int y, int anchor)
c
- character to drawx
- x-locationy
- y-locationanchor
- character alignment (e.g. ANCHOR_HCENTER or ANCHOR_BASELINE, ...)
void drawString(String s, int x, int y, int anchor)
s
- text to drawx
- x-locationy
- y-locationanchor
- text alignment (e.g. ANCHOR_HCENTER or ANCHOR_BASELINE, ...)Object getFont()
void drawImage(Object drawable, int x, int y, int anchor)
drawable
- drawable object (e.g. Image
or a Resource
containing
a bitmap image)x
- x-locationy
- y-locationanchor
- image alignment (e.g. ANCHOR_HCENTER or ANCHOR_TOP, ...)void setClip(int x, int y, int width, int height)
x
- new x-location of the clipping rectangley
- new x-location of the clipping rectanglewidth
- new width of the clipping rectangleheight
- new height of the clipping rectangleboolean clipRect(int x, int y, int width, int height)
x
- x-location of intersection rectangley
- y-location of intersection rectanglewidth
- width of intersection rectangleheight
- height of intersection rectangle
int getClipX()
int getClipY()
int getClipWidth()
int getClipHeight()
boolean isOverlapping(int x, int y, int width, int height)
x
- x-location of rectangle to testy
- y-location of rectangle to testwidth
- width of rectangle to testheight
- height of rectangle to test
boolean isClipRectEmpty()
void copyArea(int x, int y, int width, int height, int dx, int dy)
x
- x-location of area to copyy
- y-location of area to copywidth
- width of area to copyheight
- height of area to copydx
- destination x-locationdy
- destination y-locationvoid translate(int dx, int dy)
dx
- horizontal translationdy
- vertical translationint getTranslateX()
int getTranslateY()
XGraphics cloneXGraphics()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |