8 p.x += screen->r.min.x + 4 - offscreen->r.min.x;
9 p.y += screen->r.min.y + 4 - offscreen->r.min.y;
18 dx = screen->r.min.x + 4 - offscreen->r.min.x;
19 dy = screen->r.min.y + 4 - offscreen->r.min.y;
28 * Clear the window from x0, y0 to x1, y1 (inclusive) to color c
31 m_clrwin(int x0, int y0, int x1, int y1, int c)
33 draw(offscreen, Rect(x0, y0, x1+1, y1+1), getcolor(c), nil, ZP);
34 if(offscreen != screen && !buffer)
35 draw(screen, xlr(Rect(x0, y0, x1+1, y1+1)), getcolor(c), nil, ZP);
38 * Draw text between pointers p and q with first character centered at x, y.
39 * Use color c. Centered if cen is non-zero, right-justified if right is non-zero.
40 * Returns the y coordinate for any following line of text.
43 m_text(int x, int y, char *p, char *q, int c, int cen, int right)
47 tsize = stringsize(font, p);
52 stringn(offscreen, Pt(x, y-tsize.y/2), getcolor(c), ZP, font, p, q-p);
53 if(offscreen != screen && !buffer)
54 stringn(screen, xlp(Pt(x, y-tsize.y/2)), getcolor(c), ZP, font, p, q-p);
61 m_dpt(double x, double y)
65 c = getcolor(e1->foregr);
66 draw(offscreen, Rect(SCX(x), SCY(y), SCX(x)+1, SCY(y)+1), c, nil, ZP);
67 if(offscreen != screen && !buffer)
68 draw(screen, xlr(Rect(SCX(x), SCY(y), SCX(x)+1, SCY(y)+1)), c, nil, ZP);
72 * Draw the vector from x0, y0 to x1, y1 in color c.
76 m_vector(int x0, int y0, int x1, int y1, int c)
78 line(offscreen, Pt(x0, y0), Pt(x1, y1), Endsquare, Endsquare, 0, getcolor(c), ZP);
79 if(offscreen != screen && !buffer)
80 line(screen, xlp(Pt(x0, y0)), xlp(Pt(x1, y1)), Endsquare, Endsquare, 0, getcolor(c), ZP);
83 * Startup initialization
85 void m_initialize(char*)
94 if(initdraw(nil, nil, "plot") < 0)
95 sysfatal("initdraw: %r");
97 offscreen = allocimage(display, insetrect(screen->r, 4), screen->chan, 0, -1);
99 sysfatal("Can't double buffer\n");
100 clipminx = mapminx = screen->r.min.x+4;
101 clipminy = mapminy = screen->r.min.y+4;
102 clipmaxx = mapmaxx = screen->r.max.x-5;
103 clipmaxy = mapmaxy = screen->r.max.y-5;
104 dx = clipmaxx-clipminx;
105 dy = clipmaxy-clipminy;
107 mapminx += (dx-dy)/2;
108 mapmaxx = mapminx+dy;
111 mapminy += (dy-dx)/2;
112 mapmaxy = mapminy+dx;
116 * Clean up when finished
124 draw(screen, insetrect(screen->r, 4), offscreen, nil, offscreen->r.min);
125 flushimage(display, 1);
133 * Use cache to avoid repeated allocation.
146 for(j=0; j<nelem(icache); j++)
147 if(icache[j].v==v && icache[j].i!=nil)
150 i = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, v);
152 sysfatal("plot: can't allocate image for color: %r");
153 for(j=0; j<nelem(icache); j++)
154 if(icache[j].i == nil){
159 if(j == nelem(icache))sysfatal("icache: too small");