Macros


Macros in drawtool are simply external programs (awk scripts, shell scripts, binaries, perl scripts etc.) that are passed data and return vector information. Included with the program are a few simple examples of this. By combining the graphics primitives it is possible to add complex forms such as recursive figures or other graphic types without modifying the program itself.

Macros are added to the macro menu by adding an appropriate line in the drawtoolrc file. Each line consists of a nickname for the macro, a full pathname of the macro file and either 1 or 2 to indicate the script type (see below). For example, cross /home/me/macros/myCrossScript 2 would add a script called cross to the macro menu. To activate it, the user selects it from the menu, then draws it's bounding box in the drawing window.

On execution a macro script/program will be passed 7 integer arguments

If the script is specified as a type 2 macro in the drawtoolrc file then, the rectangle (x1,y1),(x2,y2) is the bounding box that the user selected. If it was a type 1 macro then, (x1,y1) contains the point where the user clicked, (x2,y2) should be ignored. In both cases r,g,b is the current colour chosen by the user.

Macros send vector data to drawtool by outputting it to standard output. This is piped into drawtool where it is interpreted.
The graphic primitives are as follows

So, for example, the string 0,10,20,0,0,0 would draw a single point at the coordinate (10,20) in the colour corresponding to (0,0,0) (black).
Similarly, the string 6,10,10,50,50,65535,0,0 would draw an elliptical frame in the box between (10,10) and (50,50) in the colour corresponding to (65535,0,0) (red).
These can be tested by echoing the strings into drawtool (echo string | drawtool)

Example Macro

#!/bin/sh
# draw a line from x1,y1 to x2,y2
echo 1,$1,$2,$3,$4,$5,$6,$7
# draw a line from x2,y1 to x1,y2
echo 1,$3,$2,$1,$4,$5,$6,$7

Given that (x1,y1),(x2,y2) is a bounding box, this script will connect the diagonals with two lines in the current colour forming an X pattern.


StdMacro Mini-SDK

Ok, I concede. That may be a slightly grandiose name. The StdMacro kit (found in macros/stdmacro provides the macro programmer with a quick kit in C for getting started.

All that a developer needs to do is fill out the doAction(...) function. To draw using drawtool's graphic primitives, all you need to do is to call the macros defined at the top of stdmacro.c

#define plot(x,y,r,g,b) printf("0,%d,%d,%d,%d,%d\n",x,y,r,g,b)
#define line(x1,y1,x2,y2,r,g,b) printf("1,%d,%d,%d,%d,%d,%d,%d",x1,y1,x2,y2,r,g,b)
#define rect(x1,y1,x2,y2,r,g,b) printf("2,%d,%d,%d,%d,%d,%d,%d",x1,y1,x2,y2,r,g,b)
#define fillrect(x1,y1,x2,y2,r,g,b) printf("3,%d,%d,%d,%d,%d,%d,%d",x1,y1,x2,y2,r,g,b)
#define circle(x1,y1,x2,y2,r,g,b) printf("4,%d,%d,%d,%d,%d,%d,%d",x1,y1,x2,y2,r,g,b)
#define fillcircle(x1,y1,x2,y2,r,g,b) printf("5,%d,%d,%d,%d,%d,%d,%d",x1,y1,x2,y2,r,g,b)
#define ellipse(x1,y1,x2,y2,r,g,b) printf("6,%d,%d,%d,%d,%d,%d,%d",x1,y1,x2,y2,r,g,b)
#define fillellipse(x1,y1,x2,y2,r,g,b) printf("7,%d,%d,%d,%d,%d,%d,%d",x1,y1,x2,y2,r,g,b)

So, for example plot(12,17,0,0,0) will plot a single black point at (12,17). Similarly line(10,10,20,20,0,65535,0) will draw a line from (10,10) to (20,20) in green.