danger.ui
Class Pen

java.lang.Object
  |
  +--danger.ui.Pen

public abstract class Pen
extends java.lang.Object

Basic drawing primitives. This class implements the basic drawing primitives that would normally be found in the abstract windowing toolbox.


Constructor Summary
Pen()
           
 
Method Summary
abstract  Pen clonePen()
          Clone the current pen.
protected abstract  void copy(Pen from)
           
abstract  void drawBitmap(int x, int y, Bitmap bm)
          Draw a bitmap.
abstract  void drawBitmap(int x, int y, Bitmap inBitmap, boolean inInverted)
          Draw a bitmap that may be inverted.
abstract  void drawBitmap(int x, int y, Bitmap a, int wa, Bitmap b, int wb)
           
abstract  void drawBitmap(int x, int y, Bitmap bm, int left, int top, int right, int bottom)
          Draw a portion of a bitmap.
 void drawBitmap(int x, int y, Bitmap bm, Rect r)
           
abstract  int drawChar(int x, int y, char c)
          Draw a character.
abstract  void drawLine(int x1, int y1, int x2, int y2)
          Draw a line.
abstract  void drawOval(int left, int top, int right, int bottom)
          Draw an oval.
 void drawOval(Rect r)
          Draw an oval.
abstract  void drawPoint(int x, int y)
          Draw a point.
abstract  void drawPoly(int[] x, int[] y)
          Draw a convex polygon.
abstract  void drawRect(int left, int top, int right, int bottom)
          Draw a rectangle.
 void drawRect(Rect r)
          Draw a rectangle.
abstract  void drawRoundRect(int left, int top, int right, int bottom, int arcWidth, int arcHeight)
          Draw a round-cornered rectangle.
 void drawRoundRect(Rect r, int arcWidth, int arcHeight)
          Draw a round-cornered rectangle.
 int drawText(int x, int y, byte[] data, int offset, int length)
          Draw a string.
 int drawText(int x, int y, char[] data, int offset, int length)
          Draw a string.
abstract  int drawText(int x, int y, java.lang.String str)
          Draw a string.
 int drawText(int x, int y, java.lang.String s, int offset, int len)
           
abstract  void fillOval(int left, int top, int right, int bottom)
          Fill an oval.
 void fillOval(Rect r)
          Fill an oval.
abstract  void fillPoly(int[] x, int[] y)
          Fill a convex polygon.
abstract  void fillRect(int left, int top, int right, int bottom)
          Fill a rectangle.
 void fillRect(Rect r)
          Fill a rectangle.
abstract  void fillRoundRect(int left, int top, int right, int bottom, int arcWidth, int arcHeight)
          Fill a round-cornered rectangle.
 void fillRoundRect(Rect r, int arcWidth, int arcHeight)
          Fill a round-cornered rectangle.
abstract  Rect getClip()
          Get the clipping rectangle in local coordinates.
abstract  Rect getClipGlobal()
          Get the clipping rectangle in global coordinates.
abstract  int getColor()
           
abstract  Font getFont()
          Get the current font.
protected abstract  int getLeft()
          Get the horizontal offset of the pen.
abstract  int getTextOutlineColor()
           
protected abstract  int getTop()
          Get the vertical offset of the pen.
abstract  int getVisibleBottom()
          return the last visible line (in local coordinates)
abstract  void getVisibleRect(Rect r)
          return a rectangle that encloses all the visible points (in local coordinates)
abstract  int getVisibleTop()
          return the first visible line (in local coordinates)
 boolean isClipEmpty()
          returns true if *nothing* will be drawn with this pen
 int maxStack()
           
abstract  void offset(int dx, int dy)
          Offset coordinate space.
 void pop()
          Restores the last copy of this pen saved on the statestack.
 void popAll()
          Pops all saved state off the statestack
 void push()
          Saves a copy of this pen on the statestack.
 void setClip(int l, int t, int r, int b)
          Adjust the clip-rect of the Pen using local coordinates.
abstract  void setClipGlobal(int l, int t, int r, int b)
          Adjust the clip-rect of the Pen using global coordinates.
 void setColor(Color c)
           
 void setColor(int color)
           
 void setColor(int r, int g, int b)
           
 void setColor(int r, int g, int b, int a)
           
abstract  void setColorAlpha(int color)
          Set the pen drawing color.
abstract  void setFont(Font f)
          Set the current font.
abstract  void setSize(int inWidth, int inHeight)
          Set the current pen size.
 void setTextOutlineColor(Color c)
           
abstract  void setTextOutlineColor(int color)
          Set the current outline text color.
 void setTextOutlineColor(int r, int g, int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pen

public Pen()
Method Detail

drawPoint

public abstract void drawPoint(int x,
                               int y)
Draw a point. Draws a single point/pixel using current pen color.

drawLine

public abstract void drawLine(int x1,
                              int y1,
                              int x2,
                              int y2)
Draw a line. Draws a line using the current pen color. x1 must be less than x2 and y1 must be less than y2. If x1 equals x2 or y1 equals y2 then nothing will be drawn.
Parameters:
x1 - An integer specifying the beginning x location in pixels.
x2 - An integer specifying the ending x location in pixels.
y1 - An integer specifying the beginning y location in pixels.
y2 - An integer specifying the ending y location in pixels.

drawRect

public abstract void drawRect(int left,
                              int top,
                              int right,
                              int bottom)
Draw a rectangle. Draw a rectangle using the current pen color. If left equals right or top equals bottom, a 2 pixel-wide line will be drawn. If left equals right and top equals bottom a single pixel will be drawn.
Parameters:
left - An integer specifying the left coordinate of the rectangle.
top - An integer specifying the top coordinate of the rectangle.
right - An integer specifying the right coordinate of the rectangle.
bottom - An integer specifying the bottom coordinate of the rectangle.

fillRect

public abstract void fillRect(int left,
                              int top,
                              int right,
                              int bottom)
Fill a rectangle. Fill a rectangle using the current pen color. Note that this method fills a rectangle that fits inside of the rectangle framed by DrawRect. If left equals right or top equals bottom, nothing is drawn.
Parameters:
left - An integer specifying the left coordinate of the rectangle.
top - An integer specifying the top coordinate of the rectangle.
right - An integer specifying the right coordinate of the rectangle.
bottom - An integer specifying the bottom coordinate of the rectangle.

drawOval

public abstract void drawOval(int left,
                              int top,
                              int right,
                              int bottom)
Draw an oval. Draw an oval using the current pen color.
Parameters:
left - An integer specifying the left coordinate of the oval.
top - An integer specifying the top coordinate of the oval.
right - An integer specifying the right coordinate of the oval.
bottom - An integer specifying the bottom coordinate of the oval.

fillOval

public abstract void fillOval(int left,
                              int top,
                              int right,
                              int bottom)
Fill an oval. Fill an oval using the current pen color. Note that this method fills an oval that fits inside of the oval framed by DrawOval.
Parameters:
left - An integer specifying the left coordinate of the oval.
top - An integer specifying the top coordinate of the oval.
right - An integer specifying the right coordinate of the oval.
bottom - An integer specifying the bottom coordinate of the oval.

drawChar

public abstract int drawChar(int x,
                             int y,
                             char c)
Draw a character. Draw the character specified by c at the location specified by x and y.
Parameters:
x - An integer specifying the x location for the character in pixels.
y - An integer specifying the y location for the character in pixels.
c - A char specifying the Unicode character to be drawn.

drawText

public abstract int drawText(int x,
                             int y,
                             java.lang.String str)
Draw a string. Draw the string specified by str at the location specified by x and y.
Parameters:
x - An integer specifying the x location for the string in pixels.
y - An integer specifying the y location for the string in pixels.
str - A String specifying the Unicode character string to be drawn.

drawText

public int drawText(int x,
                    int y,
                    java.lang.String s,
                    int offset,
                    int len)

drawText

public int drawText(int x,
                    int y,
                    byte[] data,
                    int offset,
                    int length)
Draw a string. Draw the string specified by str at the location specified by x and y.
Parameters:
x - An integer specifying the x location for the string in pixels.
y - An integer specifying the y location for the string in pixels.
data - Array of UTF-8 encoded Unicode chars to draw
offset - Offset into chars array
length - Number of chars in chars array to draw

drawText

public int drawText(int x,
                    int y,
                    char[] data,
                    int offset,
                    int length)
Draw a string. Draw the string specified by str at the location specified by x and y.
Parameters:
x - An integer specifying the x location for the string in pixels.
y - An integer specifying the y location for the string in pixels.
data - Array of Unicode chars to draw
offset - Offset into chars array
length - Number of chars in chars array to draw

drawBitmap

public abstract void drawBitmap(int x,
                                int y,
                                Bitmap bm)
Draw a bitmap. Draw the bitmap specified by bm at the location specified by x and y.
Parameters:
x - An integer specifying the x location for the bitmap in pixels.
y - An integer specifying the y location for the bitmap in pixels.
bm - A Bitmap specifying the bitmap to be drawn.

drawBitmap

public abstract void drawBitmap(int x,
                                int y,
                                Bitmap bm,
                                int left,
                                int top,
                                int right,
                                int bottom)
Draw a portion of a bitmap. Draw only the portion of the bitmap specified in the rectangle.
Parameters:
x - An integer specifying the x location for the bitmap in pixels.
y - An integer specifying the y location for the bitmap in pixels.
bm - A Bitmap specifying the bitmap to be drawn.
left - An integer specifying the left coordinate of the source rectangle.
top - An integer specifying the top coordinate of the source rectangle.
right - An integer specifying the right coordinate of the source rectangle.
bottom - An integer specifying the bottom coordinate of the source rectangle.

drawBitmap

public void drawBitmap(int x,
                       int y,
                       Bitmap bm,
                       Rect r)

drawBitmap

public abstract void drawBitmap(int x,
                                int y,
                                Bitmap inBitmap,
                                boolean inInverted)
Draw a bitmap that may be inverted. Draw the bitmap specified by bm at the location specified by x and y. If inInverted is true, the bitmap will be inverted exclusive or'ing the pixels. Note that pixels that are the same color as the transparent color are not inverted.
Parameters:
x - An integer specifying the x location for the bitmap in pixels.
y - An integer specifying the y location for the bitmap in pixels.
inBitmap - A Bitmap specifying the bitmap to be drawn.
inInverted - A boolean specifying whether or not to invert the bitmap.

drawBitmap

public abstract void drawBitmap(int x,
                                int y,
                                Bitmap a,
                                int wa,
                                Bitmap b,
                                int wb)

drawRoundRect

public abstract void drawRoundRect(int left,
                                   int top,
                                   int right,
                                   int bottom,
                                   int arcWidth,
                                   int arcHeight)
Draw a round-cornered rectangle. Draw a round-cornered rectangle using the current pen color. The roundness of the corners is specified by the arcWidth and arcHeight parameters. Except for the rounding of the corners, this method behaves exactly the same as the DrawRect method.
Parameters:
left - An integer specifying the left coordinate of the rectangle.
top - An integer specifying the top coordinate of the rectangle.
right - An integer specifying the right coordinate of the rectangle.
bottom - An integer specifying the bottom coordinate of the rectangle.
arcWidth - An integer specifying the width of the arc to be used for the corners.
arcHeight - An integer specifying the height of the arc to be used for the corners.

fillRoundRect

public abstract void fillRoundRect(int left,
                                   int top,
                                   int right,
                                   int bottom,
                                   int arcWidth,
                                   int arcHeight)
Fill a round-cornered rectangle. Fill a round-cornered rectangle using the current pen color. The roundness of the corners is specified by the arcWidth and arcHeight parameters. Except for the rounding of the corners, this method behaves exactly the same as the FillRect method.
Parameters:
left - An integer specifying the left coordinate of the rectangle.
top - An integer specifying the top coordinate of the rectangle.
right - An integer specifying the right coordinate of the rectangle.
bottom - An integer specifying the bottom coordinate of the rectangle.
arcWidth - An integer specifying the width of the arc to be used for the corners.
arcHeight - An integer specifying the height of the arc to be used for the corners.

drawRect

public void drawRect(Rect r)
Draw a rectangle. Draw a rectangle using the current pen color. If r.left equals r.right or r.top equals r.bottom, a 2 pixel-wide line will be drawn. If r.left equals r.right and r.top equals r.bottom a single pixel will be drawn.
Parameters:
r - A Rect specifying the coordinates of the rectangle.

fillRect

public void fillRect(Rect r)
Fill a rectangle. Fill a rectangle using the current pen color. Note that this method fills a rectangle that fits inside of the rectangle framed by DrawRect. If r.left equals r.right or r.top equals r.bottom, nothing is drawn.
Parameters:
r - A Rect specifying the coordinates of the rectangle.

drawOval

public void drawOval(Rect r)
Draw an oval. Draw an oval using the current pen color.
Parameters:
r - A Rect specifying the coordinates of the rectangle.

fillOval

public void fillOval(Rect r)
Fill an oval. Fill an oval using the current pen color.
Parameters:
r - A Rect specifying the coordinates of the rectangle.

drawRoundRect

public void drawRoundRect(Rect r,
                          int arcWidth,
                          int arcHeight)
Draw a round-cornered rectangle. Draw a round-cornered rectangle using the current pen color. The roundness of the corners is specified by the arcWidth and arcHeight parameters. Except for the rounding of the corners, this method behaves exactly the same as the DrawRect method.
Parameters:
r - A Rect specifying the coordinates of the rectangle.
arcWidth - An integer specifying the width of the arc to be used for the corners.
arcHeight - An integer specifying the height of the arc to be used for the corners.

fillRoundRect

public void fillRoundRect(Rect r,
                          int arcWidth,
                          int arcHeight)
Fill a round-cornered rectangle. Fill a round-cornered rectangle using the current pen color. The roundness of the corners is specified by the arcWidth and arcHeight parameters. Except for the rounding of the corners, this method behaves exactly the same as the FillRect method.
Parameters:
r - A Rect specifying the coordinates of the rectangle.
arcWidth - An integer specifying the width of the arc to be used for the corners.
arcHeight - An integer specifying the height of the arc to be used for the corners.

drawPoly

public abstract void drawPoly(int[] x,
                              int[] y)
Draw a convex polygon. Draw a convex polygon formed from a loop of the coordinates passed in using the current pen color.
Parameters:
x - An integer array of x coordinates.
y - An integer array of y coordinates.

fillPoly

public abstract void fillPoly(int[] x,
                              int[] y)
Fill a convex polygon. Fill a convex polygon formed from a loop of the coordinates passed in using the current pen color.
Parameters:
x - An integer array of x coordinates.
y - An integer array of y coordinates.

offset

public abstract void offset(int dx,
                            int dy)
Offset coordinate space. Offset the coordinate space by the amount specified by dx and dy. This offset is applied to the coordinates passed to all drawing routines of the Pen class. For example, after calling Offset(10, 10), a call to DrawPoint(0, 0) will cause a point to be drawn at (10,10).
Parameters:
dx - An integer specifying the delta for the x origin.
dy - An integer specifying the delta for the y origin.

getClipGlobal

public abstract Rect getClipGlobal()
Get the clipping rectangle in global coordinates. Returns the current clipping rectangle in global coordinates. These coordinates are not affected by the size of the view or the current offset of the coordinate system.
Returns:
A Rect specifying the clipping rectangle.

getClip

public abstract Rect getClip()
Get the clipping rectangle in local coordinates. Returns the current clipping rectangle in local coordinates. These coordinates are relative to the size of the view and the current offset.
Returns:
A Rect specifying the clipping rectangle.

setColorAlpha

public abstract void setColorAlpha(int color)
Set the pen drawing color. This color is used to draw all graphic objects until a subsequent call to SetColor is made. For 16 bit color devices, the color components are shifted from 24 to 16 bit colorspace. For 4 bit grayscale devices, the 0-15 intensity of the pixel is computed as follows: i = [ (R + 2*G + B) / 4 ] * [ 16 / 256 ] 0x000000 is black 0xffffff is white.
Parameters:
color - A packed RGB integer specifying the color.

setColor

public void setColor(int color)

setColor

public void setColor(int r,
                     int g,
                     int b)

setColor

public void setColor(int r,
                     int g,
                     int b,
                     int a)

setColor

public void setColor(Color c)

getColor

public abstract int getColor()

setTextOutlineColor

public abstract void setTextOutlineColor(int color)
Set the current outline text color.

setTextOutlineColor

public void setTextOutlineColor(int r,
                                int g,
                                int b)

setTextOutlineColor

public void setTextOutlineColor(Color c)

getTextOutlineColor

public abstract int getTextOutlineColor()

setFont

public abstract void setFont(Font f)
Set the current font. Set the current font to be the font specified by f. All text will be drawn in this font until the next call to SetFont.
Parameters:
f - A Font specifying the font to be used.

getFont

public abstract Font getFont()
Get the current font. Returns the font specified by the last call to SetFont. Returns null if no previous call to SetFont has been made.
Returns:
A Font containing the current font.

setSize

public abstract void setSize(int inWidth,
                             int inHeight)
Set the current pen size. Sets the current pen size used by all but the text drawing methods. inWidth and inHeight specify the width and height of the pen respectively.
Parameters:
inWidth - An int specifying the width for the pen.
inHeight - An int specifying the height for the pen.

setClipGlobal

public abstract void setClipGlobal(int l,
                                   int t,
                                   int r,
                                   int b)
Adjust the clip-rect of the Pen using global coordinates. The clip-rect can never be made *larger* than it currently is.

isClipEmpty

public boolean isClipEmpty()
returns true if *nothing* will be drawn with this pen

setClip

public void setClip(int l,
                    int t,
                    int r,
                    int b)
Adjust the clip-rect of the Pen using local coordinates. The clip-rect can never be made *larger* than it currently is.

getTop

protected abstract int getTop()
Get the vertical offset of the pen.

getLeft

protected abstract int getLeft()
Get the horizontal offset of the pen.

clonePen

public abstract Pen clonePen()
Clone the current pen. Returns a new Pen object that is an exact clone of the current Pen.
Returns:
A Pen that is a duplicate of the current pen.

getVisibleRect

public abstract void getVisibleRect(Rect r)
return a rectangle that encloses all the visible points (in local coordinates)

getVisibleTop

public abstract int getVisibleTop()
return the first visible line (in local coordinates)

getVisibleBottom

public abstract int getVisibleBottom()
return the last visible line (in local coordinates)

copy

protected abstract void copy(Pen from)

push

public void push()
Saves a copy of this pen on the statestack.

pop

public void pop()
Restores the last copy of this pen saved on the statestack. Throws a UIException if the stack is empty

maxStack

public int maxStack()

popAll

public void popAll()
Pops all saved state off the statestack


Danger Confidential. Copyright © 2000-2003, Danger Inc.