CTC Drawing

Each CTC cell can contain track lines in one colour and one message text in its own colour. These can be set using the tracks pallette or using the script. In addition to these basic capabilities that date from the first issue of Tcc extra flexibility is now available in the form of a drawing that can be attached to each and every cell:

A cell can additionally contain a drawing which can consist of any number of coloured lines, rectangles, circles and text items. The drawing is assembled by using a list of commands using the drawShape method:

CtcWindows: ctc
ctc.drawShape (cellId, "cmd1", "cmd2", ...)

A single drawShape call can include any number of parameters that contain string format commands. Each command consists of a single letter and perhaps some comma-separated parameters.

A drawing maintains a current position (like a cursor) and some drawing commands may start drawing from that position and/or set the current position after that command is finished.

Mx,y

Move.

Set the current position to x,y

Lx,y

Line.

Draw a line from current position to x,y and leave current position set to x,y.

Position values (x & y) are all percentages of cell size. x and y range from 0 to 100 regardless of cell size. This means that a drawing will adjust to any cell size. Position 0,0 is top left and 100,100 is bottom right. To draw a triangle in the to left corner of cell 1,1 and using the same line width as track, you might use:

Ctc.drawShape (1,1, "M10,10", "L90,10", "L10,90", "L10,10")

You can control the colour and width of the line using:

Cred

Colour.

Use colour red, or as specified for any drawing elements.

Ww

Width.

Set line width to w% of cell size

Any predefined colour name can be used, and of course a substituted variable could refer to any colour:

Variables: c
… DO c=$RGB_80, Ctc.drawShape (1,1, "C@c", "W10", "M10,10", "L90,10", "L10,90", "L10,10")

Line widths are based upon the cell size which is the average of height and width so a line of width 50 would occupy half the width or height of the cell if the cell were square.

Circles, ovals, squares or rectangles can also be drawn. A zero line width makes a solid shape, otherwise an outline with the specified line width is drawn.

Sx,y

Square.

Draw a square (or rectangle) from current position size x,y. A negative x or y means that top or left is above or to left of starting position. Then update current position to the bottom right of the rectangle.

Rx,y,r

Round.

Draw a round (circle or oval) at x,y with radius r. This neither uses nor updates current position.

Ttext

Text.

Write some text starting at the current position for the baseline. This does not change current position. Line width is used for text height. There is presently no capability to change font.

A round drawn at position 50,50 with radius 50 will fill the cell. Squares and Rounds have an outer size as specified and a line width as specified inside that boundary.

Editing drawings.

Drawings maintain an insertion point where extra commands are inserted. By default the insertion point is at the end of the drawing. Subsequent parameters or subsequent calls to drawShape will insert commands into the drawing in that cell, at the insertion point, then update the insertion point.

Di,c

Delete.

Begin editing drawing, see below

Xq

Exit.

Quit drawing if q is non-zero

The delete command can be used to modify an existing drawing:

D

Clear the whole drawing

Di

Delete one command at index i and set insertion point to that position.

Di,n

Delete n commands from index i. The first is index 1.

Di,0

Just set insertion point at i

This allows previously added drawing commands to be removed and replaced with new ones.

Additionally the eXit command can be used to quit a drawing part way through. Replacing an X1 command with an X0 can be used to switch on and off the last part of a drawing. Functionally this is the same as deleting the rest of the drawing but is intended for debugging. If a drawing doesn't do exactly what you want you can add an X1 command part way through to check that it draws as expected upto that point. If so move the X1 along to test a bit more.

All the drawing commands summarised:

Mx,y

Move.

Move to position x,y

Lx,y

Line.

Draw a line from previous position to x,y

Cred

Colour.

Use colour red (or any other already-defined colour constant name

Ww

Width.

Set line width to w% of cell size

Sx,y

Square.

Draw a square (or rectangle) from previous position size x,y

Rx,y,r

Round.

Draw a round (circle or oval) at x,y with radius r

Ttext

Text.

Write some text starting at the current position (does not change current position)

Di,c

Delete.

Begin editing drawing, see below

Xq

Exit.

Quit drawing if q is non-zero

My test script:

WHEN $LOOPS=1 DO
    ctc.drawShape (1, 1, "Cgray", 'W1', "M20,0", "L20,100", "M40,0", "L40,100", "M60,0", "L60,100", "M80,0", "L80,100", "M0,20", "L100,20", "M0,40", "L100,40", "M0,60", "L100,60", "M0,80", "L100,80")	{ split cell 1,1 into 5*5 }
    ctc.drawShape (1, 1, "Cred", 'W20', "M45,18", "Ttext", 'X0', 'w5', "M20,20", "S20,20", "L70,70", "M80,80", "R80,20,20", 'W0', "S-20,-20", "R20,80,20")
ALWAYS DO wait 1, ctc.drawShape (1,1,"D23","X1"), wait 1,
	ctc.drawShape (1,1,"D23","X0")

I suggest making the ctc window have a small number of very large cells to view this clearly.

Last updated 23 June 2010

© Howard Amos 2019