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
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
#!/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.
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.