com.WorldLibAndroid
Class CanvasPanel

java.lang.Object
  extended by View
      extended by com.WorldLibAndroid.CanvasPanel
All Implemented Interfaces:
ICanvas

public class CanvasPanel
extends View
implements ICanvas

A panel to hold the drawings.


Constructor Summary
CanvasPanel(Context context, int width, int height)
          The constructor to create an object with a specific width and height.
 
Method Summary
 void cleanCanvas()
          Clears the canvas.
 void drawBitmap(int[] colors, int offset, int stride, float x, float y, int width, int height, boolean hasAlpha)
          Treat the specified array of colors as a bitmap, and draw it.
 void drawCircle(float x, float y, float radius, IColor p)
          Draws a filled circle.
 void drawDrawable(Drawable image)
          Draws the specified drawable image.
 void drawLine(float x1, float y1, float x2, float y2, IColor p)
          Draws a line.
 void drawRect(float x1, float y1, float x2, float y2, IColor p)
          Draws a filled rectangle.
 void drawText(java.lang.String m, float x, float y, IColor p)
          Draws a text.
 Canvas getAndroidCanvas()
          Get the canvas.
 void onDraw(Canvas canvas)
          Method to draw the figures on the canvas panel.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CanvasPanel

public CanvasPanel(Context context,
                   int width,
                   int height)
The constructor to create an object with a specific width and height.

Parameters:
context - allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.
width - of the canvas.
height - of the canvas.
Method Detail

onDraw

public void onDraw(Canvas canvas)
Method to draw the figures on the canvas panel.

Parameters:
canvas - host the draw calls (writing into the bitmap).

drawCircle

public void drawCircle(float x,
                       float y,
                       float radius,
                       IColor p)
Draws a filled circle.

Specified by:
drawCircle in interface ICanvas
Parameters:
x - coordinate of the canvas panel.
y - coordinate of the canvas panel.
radius - of the circle.
p - object that holds the color of the circle.

drawLine

public void drawLine(float x1,
                     float y1,
                     float x2,
                     float y2,
                     IColor p)
Draws a line.

Specified by:
drawLine in interface ICanvas
Parameters:
x1 - coordinate of the beginning of the line.
y1 - coordinate of the beginning of the line.
x2 - coordinate of the end of the line.
y2 - coordinate of the end of the line.
p - object that holds the color of the line.

drawRect

public void drawRect(float x1,
                     float y1,
                     float x2,
                     float y2,
                     IColor p)
Draws a filled rectangle.

Specified by:
drawRect in interface ICanvas
Parameters:
x1 - The left side of the rectangle to be drawn.
y1 - The top side of the rectangle to be drawn.
x2 - The right side of the rectangle to be drawn.
y2 - The bottom side of the rectangle to be drawn.
p - object that holds the color of the rectangle.

drawText

public void drawText(java.lang.String m,
                     float x,
                     float y,
                     IColor p)
Draws a text.

Specified by:
drawText in interface ICanvas
Parameters:
m - The text to be drawn.
x - The x-coordinate of the origin of the text being drawn.
y - The y-coordinate of the origin of the text being drawn.
p - object that holds the color of the text.

cleanCanvas

public void cleanCanvas()
Clears the canvas.

Specified by:
cleanCanvas in interface ICanvas

drawBitmap

public void drawBitmap(int[] colors,
                       int offset,
                       int stride,
                       float x,
                       float y,
                       int width,
                       int height,
                       boolean hasAlpha)
Treat the specified array of colors as a bitmap, and draw it. This gives the same result as first creating a bitmap from the array, and then drawing it, but this method avoids explicitly creating a bitmap object which can be more efficient if the colors are changing often.

Specified by:
drawBitmap in interface ICanvas
Parameters:
colors - Array of colors representing the pixels of the bitmap.
offset - into the array of colors for the first pixel.
stride - The number of colors in the array between rows (must be >= width or <= -width).
x - The X coordinate for where to draw the bitmap.
y - The Y coordinate for where to draw the bitmap.
width - The width of the bitmap.
height - The height of the bitmap.
hasAlpha - True if the alpha channel of the colors contains valid values. If false, the alpha byte is ignored (assumed to be 0xFF for every pixel).

drawDrawable

public void drawDrawable(Drawable image)
Description copied from interface: ICanvas
Draws the specified drawable image.

Specified by:
drawDrawable in interface ICanvas
Parameters:
image - the Drawable to be drawn

getAndroidCanvas

public Canvas getAndroidCanvas()
Get the canvas.

Specified by:
getAndroidCanvas in interface ICanvas
Returns:
c canvas object