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)
52 chan = strtochan(chanstr);
54 error("bad screen channel string");
57 gscreen = allocmemimage(r, chan);
59 snprint(buf, sizeof buf, "can't allocate screen image: %r");
63 offscreen = Pt(x + 100, y + 100);
64 cursorr = Rect(0, 0, CURSORDIM, CURSORDIM);
65 cursorset = allocmemimage(cursorr, GREY8);
66 cursorclear = allocmemimage(cursorr, GREY1);
67 if(cursorset == nil || cursorclear == nil){
68 freememimage(gscreen);
69 freememimage(cursorset);
70 freememimage(cursorclear);
74 snprint(buf, sizeof buf, "can't allocate cursor images: %r");
78 /* a lot of work to get a grey color */
79 curscol = allocmemimage(Rect(0,0,1,1), RGBA32);
80 curscol->flags |= Frepl;
81 curscol->clipr = gscreen->r;
82 memfillcolor(curscol, 0xff0000ff);
99 memfillcolor(gscreen, 0x888844FF);
101 memdefont = getmemdefont();
102 h = memdefont->height;
104 window = insetrect(gscreen->clipr, 20);
105 memimagedraw(gscreen, window, memblack, ZP, memopaque, ZP, S);
106 window = insetrect(window, 4);
107 memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);
109 /* a lot of work to get a grey color */
110 grey = allocmemimage(Rect(0,0,1,1), CMAP8);
111 grey->flags |= Frepl;
112 grey->clipr = gscreen->r;
113 memfillcolor(grey, 0xAAAAAAFF);
114 memimagedraw(gscreen, Rect(window.min.x, window.min.y,
115 window.max.x, window.min.y+h+5+6), grey, ZP, nil, ZP, S);
117 window = insetrect(window, 5);
119 greet = " Plan 9 Console ";
120 p = addpt(window.min, Pt(10, 0));
121 memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
124 window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
125 flushmemscreen(gscreen->r);
130 attachscreen(Rectangle* r, ulong* chan, int* d, int* width, int *softscreen)
134 *chan = gscreen->chan;
135 *width = gscreen->width;
138 gscreen->data->ref++;
139 return gscreen->data;
143 getcolor(ulong , ulong* pr, ulong* pg, ulong* pb)
151 setcolor(ulong , ulong , ulong , ulong )
157 * called with cursor unlocked, drawlock locked
160 cursordraw(Memimage *dst, Rectangle r)
162 static uchar set[CURSORDIM*CURSORDIM], clr[CURSORDIM*CURSORDIM/8];
167 if(ver != cursorver){
169 for(i = 0; i < CURSORDIM*CURSORDIM/8; i += CURSORDIM/8){
170 for(j = 0; j < CURSORDIM; j++){
171 if(cursset[i + (j >> 3)] & (1 << (7 - (j & 7))))
178 memmove(clr, cursclr, CURSORDIM*CURSORDIM/8);
181 loadmemimage(cursorset, cursorr, set, CURSORDIM*CURSORDIM);
182 loadmemimage(cursorclear, cursorr, clr, CURSORDIM*CURSORDIM/8);
185 memimagedraw(dst, r, memwhite, ZP, cursorclear, ZP, SoverD);
186 memimagedraw(dst, r, curscol, ZP, cursorset, ZP, SoverD);
190 * called with cursor locked, drawlock possibly unlocked
197 r.min.x = cursorpos.x + cursor.offset.x;
198 r.min.y = cursorpos.y + cursor.offset.y;
199 r.max.x = r.min.x + CURSORDIM;
200 r.max.y = r.min.y + CURSORDIM;
205 * called with cursor locked, drawlock possibly unlocked
208 setcursor(Cursor* curs)
211 memmove(cursset, curs->set, CURSORDIM*CURSORDIM/8);
212 memmove(cursclr, curs->clr, CURSORDIM*CURSORDIM/8);
218 cursorpos = mousexy();
224 cursorpos = offscreen;
228 blankscreen(int blank)
236 flushmemscreen(flushr);
237 flushr = Rect(10000, 10000, -10000, -10000);
241 addflush(Rectangle r)
243 if(flushr.min.x >= flushr.max.x)
246 combinerect(&flushr, r);
257 r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
258 p = Pt(window.min.x, window.min.y+o);
259 memimagedraw(gscreen, r, gscreen, p, nil, p, S);
260 r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
261 memimagedraw(gscreen, r, back, ZP, nil, ZP, S);
262 flushmemscreen(gscreen->clipr);
268 screenputc(char *buf)
274 static int xbuf[256];
276 if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
281 if(curpos.y+h >= window.max.y)
288 curpos.x = window.min.x;
291 p = memsubfontwidth(memdefont, " ");
294 pos = (curpos.x-window.min.x)/w;
296 r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h);
297 memimagedraw(gscreen, r, back, back->r.min, memopaque, ZP, S);
305 r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
306 memimagedraw(gscreen, r, back, back->r.min, memopaque, ZP, S);
313 p = memsubfontwidth(memdefont, buf);
316 if(curpos.x >= window.max.x-w)
320 r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y + h);
321 memimagedraw(gscreen, r, back, back->r.min, memopaque, ZP, S);
322 memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);
329 screenputs(char *s, int n)
331 static char rb[UTFmax+1];
339 if(nrb >= UTFmax || fullrune(rb, nrb)){