2 int mapminx, mapminy, mapmaxx, mapmaxy;
5 * Clear the window from x0, y0 to x1, y1 (inclusive) to color c
7 void m_clrwin(int x0, int y0, int x1, int y1, int c){
8 draw(offscreen, Rect(x0, y0, x1+1, y1+1), getcolor(c), nil, ZP);
11 * Draw text between pointers p and q with first character centered at x, y.
12 * Use color c. Centered if cen is non-zero, right-justified if right is non-zero.
13 * Returns the y coordinate for any following line of text.
15 int m_text(int x, int y, char *p, char *q, int c, int cen, int right){
18 tsize=stringsize(font, p);
19 if(cen) x -= tsize.x/2;
20 else if(right) x -= tsize.x;
21 stringn(offscreen, Pt(x, y-tsize.y/2), getcolor(c), ZP, font, p, q-p);
25 * Draw the vector from x0, y0 to x1, y1 in color c.
28 void m_vector(int x0, int y0, int x1, int y1, int c){
29 line(offscreen, Pt(x0, y0), Pt(x1, y1), Endsquare, Endsquare, 0, getcolor(c), ZP);
31 char *scanint(char *s, int *n){
32 while(*s<'0' || '9'<*s){
34 fprint(2, "plot: bad -Wxmin,ymin,xmax,ymax\n");
40 while('0'<=*s && *s<='9'){
46 char *rdenv(char *name){
54 fprint(2, "Can't malloc: %r\n");
64 * Startup initialization
66 void m_initialize(char *s){
71 if(initdraw(0,0,"plot") < 0)
72 sysfatal("plot: can't open display: %r");
74 clipminx=mapminx=screen->r.min.x+4;
75 clipminy=mapminy=screen->r.min.y+4;
76 clipmaxx=mapmaxx=screen->r.max.x-5;
77 clipmaxy=mapmaxy=screen->r.max.y-5;
93 * Clean up when finished
100 draw(screen, offscreen->r, offscreen, nil, offscreen->r.min);
101 flushimage(display, 1);
104 if(offscreen==screen){
105 offscreen=allocimage(display, insetrect(screen->r, 4), screen->chan, 0, -1);
107 fprintf(stderr, "Can't double buffer\n");
112 /* Assume colormap entry because
113 * Use cache to avoid repeated allocation.
126 for(j=0; j<nelem(icache); j++)
127 if(icache[j].v==v && icache[j].i!=nil)
130 i = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, v);
132 fprint(2, "plot: can't allocate image for color: %r\n");
135 for(j=0; j<nelem(icache); j++)
136 if(icache[j].i == nil){