Graphics - Kirix Documentation

Developer Resources

Graphics

Overview

Encapsulates drawing commands on a graphics object.

Methods

Graphics.drawArc
Draws an arc on the graphics object.
Graphics.drawCircle
Draws a circle on the graphics object.
Graphics.drawEllipticArc
Draws an elliptic arc on the graphics object.
Graphics.drawImage
Draws an image on the graphics object.
Graphics.drawLine
Draws a line on the graphics object.
Graphics.drawRectangle
Draws a rectangle on the graphics object.
Graphics.drawText
Draws text on the graphics object.
Graphics.fromBitmap
Creates a new graphics object from a specified bitmap.
Graphics.setBrush
Sets the current brush to use when drawing the background on the graphics object.
Graphics.setFont
Sets the current font to use when drawing text on the graphics object.
Graphics.setPen
Sets the current pen to use when drawing the foreground on the graphics object.
Graphics.setTextBackground
Sets the background color to use when drawing text on the graphics object.
Graphics.setTextForeground
Sets the foreground color to use when drawing text on the graphics object.

Example

// 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));
    }
}

Graphics.drawArc

function Graphics.drawArc(x : Integer, y : Integer, x1 : Integer, y1 : Integer, x2 : Integer, y2 : Integer)

Arguments

x
The x position of the center of the circle which contains the arc.
y
The y position of the center of the circle which contains the arc.
x1
The x position of the start of the arc.
y1
The y position of the start of the arc.
x2
The x position of the end of the arc.
y2
The y position of the end of the arc.

Description

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.

Graphics.drawCircle

function Graphics.drawCircle(x : Integer, y : Integer, r : Integer)

Arguments

x
The x position of the center of the circle.
y
The y position of the center of the circle.
r
The radius of the circle.

Description

Draws a circle with the center at the point (x, y) and a radius of r.

Graphics.drawEllipticArc

function Graphics.drawEllipticArc(x : Integer, y : Integer, width : Integer, height : Integer, deg1 : Integer, deg2 : Integer)

Arguments

x
The upper-left x position of the bounding rectangle.
y
The upper-left y position of the bounding rectangle.
width
The width of the bounding rectangle.
height
The height of the bounding rectangle.
deg1
The start of the arc in degrees, relative to a standard, positive x-axis.
deg2
The end of the arc in degrees, relative to a standard, positive x-axis.

Description

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.

Graphics.drawImage

function Graphics.drawImage(bitmap : Bitmap, x : Integer, y : Integer, width : Integer, height : Integer)
function Graphics.drawImage(graphics : Graphics, x : Integer, y : Integer, width : Integer, height : Integer)

Arguments

bitmap
The bitmap to draw.
graphics
The graphics object to blit to this graphics object.
x
The upper-left x position of the bitmap.
y
The upper-left y position of the bitmap.
width
The width of the bitmap.
height
The height of the bitmap.

Description

Draws a bitmap at the position given by (x, y), with a given width and height.

Graphics.drawLine

function Graphics.drawLine(x1 : Integer, y1 : Integer, x2 : Integer, y2 : Integer)

Arguments

x1
The x position of the start of the line.
y1
The y position of the start of the line.
x2
The x position of the end of the line.
y2
The y position of the end of the line.

Description

Draws a line from the point (x1, y1) to the point (x2, y2).

Graphics.drawRectangle

function Graphics.drawRectangle(x : Integer, y : Integer, width : Integer, height : Integer)

Arguments

x
The upper-left x position of the rectangle.
y
The upper-left y position of the rectangle.
width
The width of the rectangle.
height
The height of the rectangle.

Description

Draws a rectangle with an upper-left at the position (x, y) and with a given width and height.

Graphics.drawText

function Graphics.drawText(text : String, x : Integer, y : Integer)

Arguments

text
The text to draw.
x
The upper-left x position of the text.
y
The upper-left y position of the text.

Description

Draws the specified text at the position (x, y), using the currently set font.

Graphics.fromBitmap

static function Graphics.fromBitmap(bitmap : Bitmap)

Returns

Returns a new graphics object.

Description

Creates a new graphics object from a specified bitmap.

Graphics.setBrush

function Graphics.setBrush(brush : Brush)

Arguments

brush
The brush to use when drawing the foreground on the graphics object.

Description

Sets the current brush to use when drawing the background on the graphics object.

Graphics.setFont

function Graphics.setFont(font : Font)

Arguments

font
The font to use when drawing text on the graphics object.

Description

Sets the current font to use when drawing text on the graphics object.

Graphics.setPen

function Graphics.setPen(pen : Pen)

Arguments

pen
The pen to use when drawing the foreground on the graphics object.

Description

Sets the current pen to use when drawing the foreground on the graphics object.

Graphics.setTextBackground

function Graphics.setTextBackground(color : Color)

Arguments

color
The color to use when drawing text on the graphics object.

Description

Sets the current color to use when drawing text on the graphics object.

Graphics.setTextForeground

function Graphics.setTextForeground(color : Color)

Arguments

color
The color to use when drawing text on the graphics object.

Description

Sets the current color to use when drawing text on the graphics object.