4 * Clear the window from x0, y0 to x1, y1 (inclusive) to color c
6 void m_clrwin(int x0, int y0, int x1, int y1, int c){
7 draw(offscreen, Rect(x0, y0, x1+1, y1+1), getcolor(c), nil, ZP);
10 * Draw text between pointers p and q with first character centered at x, y.
11 * Use color c. Centered if cen is non-zero, right-justified if right is non-zero.
12 * Returns the y coordinate for any following line of text.
14 int m_text(int x, int y, char *p, char *q, int c, int cen, int right){
17 tsize=stringsize(font, p);
18 if(cen) x -= tsize.x/2;
19 else if(right) x -= tsize.x;
20 stringn(offscreen, Pt(x, y-tsize.y/2), getcolor(c), ZP, font, p, q-p);
24 * Draw the vector from x0, y0 to x1, y1 in color c.
27 void m_vector(int x0, int y0, int x1, int y1, int c){
28 line(offscreen, Pt(x0, y0), Pt(x1, y1), Endsquare, Endsquare, 0, getcolor(c), ZP);
30 char *scanint(char *s, int *n){
31 while(*s<'0' || '9'<*s){
33 fprint(2, "plot: bad -Wxmin,ymin,xmax,ymax\n");
39 while('0'<=*s && *s<='9'){
45 char *rdenv(char *name){
53 fprint(2, "Can't malloc: %r\n");
63 * Startup initialization
65 void m_initialize(char *s){
70 if(initdraw(0,0,"plot") < 0)
71 sysfatal("initdraw: %r");
73 clipminx=mapminx=screen->r.min.x+4;
74 clipminy=mapminy=screen->r.min.y+4;
75 clipmaxx=mapmaxx=screen->r.max.x-5;
76 clipmaxy=mapmaxy=screen->r.max.y-5;
92 * Clean up when finished
99 draw(screen, offscreen->r, offscreen, nil, offscreen->r.min);
100 flushimage(display, 1);
103 if(offscreen==screen){
104 offscreen=allocimage(display, insetrect(screen->r, 4), screen->chan, 0, -1);
106 fprintf(stderr, "Can't double buffer\n");
111 /* Assume colormap entry because
112 * Use cache to avoid repeated allocation.
125 for(j=0; j<nelem(icache); j++)
126 if(icache[j].v==v && icache[j].i!=nil)
129 i = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, v);
131 fprint(2, "plot: can't allocate image for color: %r\n");
134 for(j=0; j<nelem(icache); j++)
135 if(icache[j].i == nil){