Class Canvas

(line 1265)

Description

Object
   |
   --Persistent
      |
      --Canvas

Located in File: /graphics.inc.php

Canvas provides an abstract drawing space for objects that must render their own images.

Use Canvas as a drawing surface for objects that draw an image of themselves. Standard controls such as edit controls or list boxes do not require a canvas, as they are drawn by the browser, but Graphic controls can use a canvas to generate an image in run-time

Canvas provides properties, events and methods that assist in creating an image by

Specifying the type of brush, pen and font to use.

Drawing and filling a variety of shapes and lines.

Writing text.

Rendering graphic images.

  1.  <?php
  2.    function PaintBox1Paint($sender$params)
  3.    {
  4.     $this->PaintBox1->Canvas->Pen->Color="#FF0000";
  5.     $this->PaintBox1->Canvas->Line(0,0,100,100);
  6.  
  7.     $this->PaintBox1->Canvas->Brush->Color="#00FF00";
  8.     $this->PaintBox1->Canvas->Rectangle(100,100,200,200);
  9.  
  10.     $this->PaintBox1->Canvas->TextOut(50,50"VCL for PHP Canvas");
  11.    }
  12.  ?>



Properties

Summary:
Brush Determines the color and pattern for filling graphical shapes and backgrounds.
Pen Specifies the kind of pen the canvas uses for drawing lines and outlining shapes.

Defined in class Persistent

NamePath Used to serialize/unserialize. It returns the full path to identify this component.
Owner Owner of the component.

property Brush (line 1716)

Brush Brush

Determines the color and pattern for filling graphical shapes and backgrounds.

Set the Brush property to specify the color and pattern to use when drawing the background or filling in graphical shapes. The value of Brush is a Brush object. Set the properties of the Brush object to specify the color and pattern or bitmap to use when filling in spaces on the canvas.

Note: Setting the Brush property replaces the specified Brush object, rather than copying the current Brush object.


property Pen (line 1743)

Pen Pen

Specifies the kind of pen the canvas uses for drawing lines and outlining shapes.

Set Pen to specify the pen to use for drawing lines and outlining shapes in the image. The value of Pen is a Pen object. Set the properties of the Pen object to specify the color, style, width, and mode of the pen.

Note: Setting the Pen property replaces the specified Pen object, rather than copying the current Pen object.


property NamePath

Used to serialize/unserialize. It returns the full path to identify this component.
This property is implemented in Persistent::NamePath

property Owner

Owner of the component.
This property is implemented in Persistent::Owner

Methods

Summary:
__construct Constructs an object and initializes its data before the object is first used. [Overrides Object::__construct()]
arc Draws an arc on the image along the perimeter of the ellipse bounded by the specified rectangle.
beginDraw Begins draw cycle.
bevelLine Draw the line using specified color
bevelRect Draw Bevel-like rectangle using specified colors
clear Clears the canvas
ellipse Draws the ellipse defined by a bounding rectangle on the canvas.
endDraw Ends draw cycle.
fillRect Fills the specified rectangle on the canvas using the current brush.
forceBrush Intermal method
forceFont Intermal method
forcePen Intermal method
frameRect Draws a rectangle using the Brush of the canvas to draw the border.
initLibrary This method dumps the .js required to initiate graphic library
line Draws a line on the canvas using specified coordinates
paint Paints the canvas
polygon Draws a series of lines on the canvas connecting the points passed in and closing the shape by drawing a line from the last point to the first point.
polyline Draws a series of lines on the canvas with the current pen, connecting each of the points passed to it in Points.
rectangle Draws a rectangle on the canvas.
roundRect Draws a rectangle with rounded corners on the canvas.
stretchDraw Draws the graphic specified by the image parameter in the rectangle specified by the coordinates.
textOut Writes a string on the canvas, starting at the point (X,Y)

Defined in class Persistent

serialize Stores this object into the session.
unserialize This method uses PHP reflection to iterate through published properties (the ones starting with get) and retrieve the properties stored by a previous serialize() call.

Defined in class Object

__construct Constructs an object and initializes its data before the object is first used.
className Returns a string indicating the type of the object instance (as opposed to the type of the variable passed as an argument).
classParent Returns the type of the immediate ancestor of a class.

Constructor __construct (line 1274)

Canvas __construct( [ $aowner = null])

Overrides : Object::__construct() Constructs an object and initializes its data before the object is first used.


Method arc (line 1412)

void arc( int $x1, int $y1, int $x2, int $y2, int $x3, int $y3, int $x4, int $y4)

Draws an arc on the image along the perimeter of the ellipse bounded by the specified rectangle.

Use Arc to draw an elliptically curved line with the current Pen. The arc traverses the perimeter of an ellipse that is bounded by the points (X1,Y1) and (X2,Y2).

The arc is drawn following the perimeter of the ellipse, counterclockwise, from the starting point to the ending point. The starting point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X3,Y3). The ending point is defined by the intersection of the ellipse and a line defined by the center of the ellipse and (X4, Y4).

Parameters

  • int $x1: The left point at pixel coordinates
  • int $y1: The top point at pixel coordinates
  • int $x2: The right point at pixel coordinates
  • int $y2: The bottom point at pixel coordinates
  • int $x3: The left intersection at pixel coordinates
  • int $y3: The top intersection at pixel coordinates
  • int $x4: The right intersection at pixel coordinates
  • int $y4: The bottom intersection at pixel coordinates

Method beginDraw (line 1368)

void beginDraw( )

Begins draw cycle.

In VCL for PHP, graphics are drawn on the browser using javascript, and this method is needed to dump the required code to initialize drawing objects and to establishes internal Canvas object.

Should be followed by EndDraw to push drawing to the page canvas.


Method bevelLine (line 1677)

void bevelLine( $color, $x1, $y1, $x2, $y2)

Draw the line using specified color

Parameters

  • $color:
  • $x1:
  • $y1:
  • $x2:
  • $y2:

Method bevelRect (line 1664)

void bevelRect( $x1, $y1, $x2, $y2, $color1, $color2)

Draw Bevel-like rectangle using specified colors

Parameters

  • $x1:
  • $y1:
  • $x2:
  • $y2:
  • $color1:
  • $color2:

Method clear (line 1688)

void clear( )

Clears the canvas

Use this method to erase all the drawings in the canvas


Method ellipse (line 1432)

void ellipse( int $x1, int $y1, int $x2, int $y2)

Draws the ellipse defined by a bounding rectangle on the canvas.

Call Ellipse to draw a circle or ellipse on the canvas. Specify the bounding rectangle by giving the top left point at pixel coordinates (X1, Y1) and the bottom right point at (X2, Y2).

If the bounding rectangle is a square, a circle is drawn.

The ellipse is outlined using the value of Pen, and filled using the value of Brush.

Parameters

  • int $x1: The left point at pixel coordinates
  • int $y1: The top point at pixel coordinates
  • int $x2: The right point at pixel coordinates
  • int $y2: The bottom point at pixel coordinates

Method endDraw (line 1383)

void endDraw( )

Ends draw cycle.

In VCL for PHP, graphics are drawn on the browser using javascript, and this method is needed to dump the required code to finalize drawing and to flush out all drawing commands.


Method fillRect (line 1450)

void fillRect( int $x1, int $y1, int $x2, int $y2)

Fills the specified rectangle on the canvas using the current brush.

Use FillRect to fill a rectangular region using the current brush. The region is filled including the top and left sides of the rectangle, but excluding the bottom and right edges.

Parameters

  • int $x1: The left point at pixel coordinates
  • int $y1: The top point at pixel coordinates
  • int $x2: The right point at pixel coordinates
  • int $y2: The bottom point at pixel coordinates

Method forceBrush (line 1292)

void forceBrush( )

Intermal method

This method is used to set the color for the canvas to the brush color if the brush has been modified.

Info

  • access - protected

Method forceFont (line 1325)

void forceFont( )

Intermal method

This method is used to set the font for the canvas to the font property

Info

  • access - protected

Method forcePen (line 1308)

void forcePen( )

Intermal method

This method is used to set the stroke color for the canvas to the pen color if the pen has been modified.

Info

  • access - protected

Method frameRect (line 1469)

void frameRect( int $x1, int $y1, int $x2, int $y2)

Draws a rectangle using the Brush of the canvas to draw the border.

Use FrameRect to draw a 1 pixel wide border around a rectangular region. FrameRect does not fill the interior of the rectangle with the Brush pattern.

To draw a boundary using the Pen instead, use the Polygon method.

Parameters

  • int $x1: The left point at pixel coordinates
  • int $y1: The top point at pixel coordinates
  • int $x2: The right point at pixel coordinates
  • int $y2: The bottom point at pixel coordinates

Method initLibrary (line 1335)

void initLibrary( )

This method dumps the .js required to initiate graphic library

Method line (line 1486)

void line( int $x1, int $y1, int $x2, int $y2)

Draws a line on the canvas using specified coordinates

Use Line to draw a 1 pixel wide line from a point (x1,y2) to another point (x2,y2) using the current Pen

Parameters

  • int $x1: The left point at pixel coordinates
  • int $y1: The top point at pixel coordinates
  • int $x2: The right point at pixel coordinates
  • int $y2: The bottom point at pixel coordinates

Method paint (line 1699)

void paint( )

Paints the canvas

After drawing this does the actual painting of the canvas. Only needed when drawing from JavaScript events or from outside this canvas owner OnPaint event.


Method polygon (line 1502)

void polygon( array $points)

Draws a series of lines on the canvas connecting the points passed in and closing the shape by drawing a line from the last point to the first point.

Use Polygon to draw a closed, many-sided shape on the canvas, using the value of Pen. After drawing the complete shape, Polygon fills the shape using the value of Brush.

The Points parameter is an array of points that give the vertices of the polygon.

Parameters

  • array $points: An array of x, y interleaved coordinates

Method polyline (line 1533)

void polyline( array $points)

Draws a series of lines on the canvas with the current pen, connecting each of the points passed to it in Points.

Use Polyline to connect a set of points on the canvas. If you specify only two points, Polyline draws a single line.

The Points parameter is an array of points to be connected.

Parameters

  • array $points: An array of x, y interleaved coordinates

Method rectangle (line 1569)

void rectangle( int $x1, int $y1, int $x2, int $y2)

Draws a rectangle on the canvas.

Use Rectangle to draw a rectangle using Pen and fill it with Brush. Specify the rectangle’s coordinates giving four coordinates that define the upper left corner at the point (X1, Y1) and the lower right corner at the point (X2, Y2).

To fill a rectangular region without drawing the boundary in the current pen, use FillRect. To outline a rectangular region without filling it, use FrameRect or Polygon. To draw a rectangle with rounded corners, use RoundRect.

Parameters

  • int $x1: The left point at pixel coordinates
  • int $y1: The top point at pixel coordinates
  • int $x2: The right point at pixel coordinates
  • int $y2: The bottom point at pixel coordinates

Method roundRect (line 1593)

void roundRect( int $x1, int $y1, int $x2, int $y2, int $w, int $h)

Draws a rectangle with rounded corners on the canvas.

Use RoundRect to draw a rounded rectangle using Pen and fill it with Brush. The rectangle will have edges defined by the points (X1,Y1), (X2,Y1), (X2,Y2), (X1,Y2), but the corners will be shaved to create a rounded appearance. The curve of the rounded corners matches the curvature of an ellipse with width W and height H.

To draw an ellipse instead, use Ellipse. To draw a true rectangle, use Rectangle.

Parameters

  • int $x1: The left point at pixel coordinates
  • int $y1: The top point at pixel coordinates
  • int $x2: The right point at pixel coordinates
  • int $y2: The bottom point at pixel coordinates
  • int $w: Width of the ellipse for rounded corners
  • int $h: Height of the ellipse for rounded corners

Method stretchDraw (line 1642)

void stretchDraw( int $x1, int $y1, int $x2, int $y2, string $image)

Draws the graphic specified by the image parameter in the rectangle specified by the coordinates.

Call StretchDraw to draw a graphic on the canvas so that the image fits in the specified rectangle. This may involve changing magnification and/or aspect ratio.

Parameters

  • int $x1: The left point at pixel coordinates
  • int $y1: The top point at pixel coordinates
  • int $x2: The right point at pixel coordinates
  • int $y2: The bottom point at pixel coordinates
  • string $image: URL to the image to draw

Method textOut (line 1656)

void textOut( int $x, int $y, string $text)

Writes a string on the canvas, starting at the point (X,Y)

Use TextOut to write a string onto the canvas. The string will be written using the current value of Font.

Parameters

  • int $x: The left point at pixel coordinates
  • int $y: The top point at pixel coordinates
  • string $text: Text to write to the canvas

Events

Summary:

[none]

Javascript Events

Summary:

[none]

Documentation generated on Fri, 26 Dec 2008 11:45:28 +0100 by phpDocumentor 1.4.0a2