Encapsulates drawing commands on a graphics object.
// create a new graphics sample form
var f = new MyForm("Graphics Example", 0, 0, 300, 300);
f.center();
f.show();
Application.run();
// create a custom control that displays a smile
class MyControl extends Control
{
function MyControl(x_pos, y_pos, width, height)
{
// call the Control constructor and connect
// the paint event handler
super(x_pos, y_pos, width, height);
this.paint.connect(this, onPaintCalled);
}
function onPaintCalled(sender, evt)
{
// when the paint event handler is called, get the
// graphics object associated with the control and
// draw a smile
// calculate some positions and dimensions based
// on the size of the control
var size = this.getSize();
var center_x = size.width/2;
var center_y = size.height/2;
var radius = Math.min(size.width, size.height)/2 - 2;
// get the graphics object associated with the control,
// set the color of the drawing pen to blue, and draw
// a smile
var gr = evt.graphics;
gr.setPen(new Pen(new Color(0, 0, 255)));
gr.drawCircle(center_x, center_y, radius);
gr.drawCircle(center_x - radius/3, center_y - radius/3, radius/10);
gr.drawCircle(center_x + radius/3, center_y - radius/3, radius/10);
var x = center_x - radius/3;
var y = center_y + radius/4;
var width = (radius*2)/3;
var height = radius/3;
gr.drawEllipticArc(x, y, width, height, -160, -20);
}
}
// define the graphics sample form
class MyForm extends Form
{
function MyForm(caption, x_pos, y_pos, width, height)
{
super(caption, x_pos, y_pos, width, height);
// add the smile control to the form
var client_size = this.getClientSize();
this.add(new MyControl(0, 0, client_size.width, client_size.height));
}
}
Draws an arc of a circle, centered at the point (x, y), starting from the point (x1, y1) on the edge of the circle and proceeding counter-clockwise to another point (x2, y2), also on the edge of the circle.
Draws a circle with the center at the point (x, y) and a radius of r.
Draws an elliptic arc contained on an ellipse that is bounded by a rectangle of a given width and height with an upper-left corner at the point (x, y), and where the arc of the bounded ellipse starts at an angle of deg1 degrees relative to a standard, positive x-axis and ends at an angle of deg2 degrees relative to the same axis.
Draws a bitmap at the position given by (x, y), with a given width and height.
Draws a line from the point (x1, y1) to the point (x2, y2).
Draws a rectangle with an upper-left at the position (x, y) and with a given width and height.
Draws the specified text at the position (x, y), using the currently set font.
Returns a new graphics object.
Creates a new graphics object from a specified bitmap.
Sets the current brush to use when drawing the background on the graphics object.
Sets the current font to use when drawing text on the graphics object.
Sets the current pen to use when drawing the foreground on the graphics object.
Sets the current color to use when drawing text on the graphics object.
Sets the current color to use when drawing text on the graphics object.