23 static Memimage *back;
24 static Memimage *conscol;
25 static Memimage *curscol;
27 static Memsubfont *memdefont;
28 static Rectangle flushr;
29 static Rectangle window;
33 static Rectangle cursorr;
34 static Point offscreen;
35 static uchar cursset[CURSORDIM*CURSORDIM/8];
36 static uchar cursclr[CURSORDIM*CURSORDIM/8];
37 static int cursdrawvers = -1;
38 static Memimage *cursorset;
39 static Memimage *cursorclear;
40 static Cursor screencursor;
43 screeninit(int x, int y, char *chanstr)
55 chan = strtochan(chanstr);
57 error("bad screen channel string");
60 gscreen = allocmemimage(r, chan);
62 snprint(buf, sizeof buf, "can't allocate screen image: %r");
66 offscreen = Pt(x + 100, y + 100);
67 cursorr = Rect(0, 0, CURSORDIM, CURSORDIM);
68 cursorset = allocmemimage(cursorr, GREY8);
69 cursorclear = allocmemimage(cursorr, GREY1);
70 if(cursorset == nil || cursorclear == nil){
71 freememimage(gscreen);
72 freememimage(cursorset);
73 freememimage(cursorclear);
77 snprint(buf, sizeof buf, "can't allocate cursor images: %r");
84 * set up goo for screenputs
86 memdefont = getmemdefont();
91 /* a lot of work to get a grey color */
92 curscol = allocmemimage(Rect(0,0,1,1), RGBA32);
93 curscol->flags |= Frepl;
94 curscol->clipr = gscreen->r;
95 memfillcolor(curscol, 0xff0000ff);
97 memfillcolor(gscreen, 0x444488FF);
99 w = memdefont->info[' '].width;
100 h = memdefont->height;
102 window.min = addpt(gscreen->r.min, Pt(20,20));
103 window.max.x = window.min.x + Dx(gscreen->r)*3/4-40;
104 window.max.y = window.min.y + Dy(gscreen->r)*3/4-100;
106 memimagedraw(gscreen, window, memblack, ZP, memopaque, ZP, S);
107 window = insetrect(window, 4);
108 memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);
110 /* a lot of work to get a grey color */
111 grey = allocmemimage(Rect(0,0,1,1), CMAP8);
112 grey->flags |= Frepl;
113 grey->clipr = gscreen->r;
114 memfillcolor(grey, 0xAAAAAAFF);
115 memimagedraw(gscreen, Rect(window.min.x, window.min.y,
116 window.max.x, window.min.y+h+5+6), grey, ZP, nil, ZP, S);
118 window = insetrect(window, 5);
120 greet = " Plan 9 Console ";
121 p = addpt(window.min, Pt(10, 0));
122 q = memsubfontwidth(memdefont, greet);
123 memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
126 window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
127 flushmemscreen(gscreen->r);
135 attachscreen(Rectangle* r, ulong* chan, int* d, int* width, int *softscreen)
139 *chan = gscreen->chan;
140 *width = gscreen->width;
143 return gscreen->data->bdata;
147 getcolor(ulong , ulong* pr, ulong* pg, ulong* pb)
155 setcolor(ulong , ulong , ulong , ulong )
161 * called with cursor unlocked, drawlock locked
164 cursordraw(Memimage *dst, Rectangle r)
166 static uchar set[CURSORDIM*CURSORDIM], clr[CURSORDIM*CURSORDIM/8];
171 if(ver != cursorver){
173 for(i = 0; i < CURSORDIM*CURSORDIM/8; i += CURSORDIM/8){
174 for(j = 0; j < CURSORDIM; j++){
175 if(cursset[i + (j >> 3)] & (1 << (7 - (j & 7))))
182 memmove(clr, cursclr, CURSORDIM*CURSORDIM/8);
185 loadmemimage(cursorset, cursorr, set, CURSORDIM*CURSORDIM);
186 loadmemimage(cursorclear, cursorr, clr, CURSORDIM*CURSORDIM/8);
189 memimagedraw(dst, r, memwhite, ZP, cursorclear, ZP, SoverD);
190 memimagedraw(dst, r, curscol, ZP, cursorset, ZP, SoverD);
194 * called with cursor locked, drawlock possibly unlocked
201 r.min.x = cursorpos.x + cursor.offset.x;
202 r.min.y = cursorpos.y + cursor.offset.y;
203 r.max.x = r.min.x + CURSORDIM;
204 r.max.y = r.min.y + CURSORDIM;
209 * called with cursor locked, drawlock possibly unlocked
212 setcursor(Cursor* curs)
215 memmove(cursset, curs->set, CURSORDIM*CURSORDIM/8);
216 memmove(cursclr, curs->clr, CURSORDIM*CURSORDIM/8);
222 cursorpos = mousexy();
228 cursorpos = offscreen;
232 blankscreen(int blank)
240 flushmemscreen(flushr);
241 flushr = Rect(10000, 10000, -10000, -10000);
245 addflush(Rectangle r)
247 if(flushr.min.x >= flushr.max.x)
250 combinerect(&flushr, r);
261 r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
262 p = Pt(window.min.x, window.min.y+o);
263 memimagedraw(gscreen, r, gscreen, p, nil, p, S);
264 r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
265 memimagedraw(gscreen, r, back, ZP, nil, ZP, S);
266 flushmemscreen(gscreen->r);
272 screenputc(char *buf)
278 static int xbuf[256];
280 if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
285 if(curpos.y+h >= window.max.y)
292 curpos.x = window.min.x;
295 p = memsubfontwidth(memdefont, " ");
298 pos = (curpos.x-window.min.x)/w;
300 r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h);
301 memimagedraw(gscreen, r, back, back->r.min, memopaque, ZP, S);
309 r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
310 memimagedraw(gscreen, r, back, back->r.min, memopaque, ZP, S);
317 p = memsubfontwidth(memdefont, buf);
320 if(curpos.x >= window.max.x-w)
324 r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y + h);
325 memimagedraw(gscreen, r, back, back->r.min, memopaque, ZP, S);
326 memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);
333 screenputs(char *s, int n)
335 static char rb[UTFmax+1];
343 if(nrb >= UTFmax || fullrune(rb, nrb)){