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;
44 { 0xFF, 0xFF, 0x80, 0x01, 0x80, 0x02, 0x80, 0x0C,
45 0x80, 0x10, 0x80, 0x10, 0x80, 0x08, 0x80, 0x04,
46 0x80, 0x02, 0x80, 0x01, 0x80, 0x02, 0x8C, 0x04,
47 0x92, 0x08, 0x91, 0x10, 0xA0, 0xA0, 0xC0, 0x40,
49 { 0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFC, 0x7F, 0xF0,
50 0x7F, 0xE0, 0x7F, 0xE0, 0x7F, 0xF0, 0x7F, 0xF8,
51 0x7F, 0xFC, 0x7F, 0xFE, 0x7F, 0xFC, 0x73, 0xF8,
52 0x61, 0xF0, 0x60, 0xE0, 0x40, 0x40, 0x00, 0x00,
57 screeninit(int x, int y, char *chanstr)
69 chan = strtochan(chanstr);
71 error("bad screen channel string");
74 gscreen = allocmemimage(r, chan);
76 snprint(buf, sizeof buf, "can't allocate screen image: %r");
80 offscreen = Pt(x + 100, y + 100);
81 cursorr = Rect(0, 0, CURSORDIM, CURSORDIM);
82 cursorset = allocmemimage(cursorr, GREY8);
83 cursorclear = allocmemimage(cursorr, GREY1);
84 if(cursorset == nil || cursorclear == nil){
85 freememimage(gscreen);
86 freememimage(cursorset);
87 freememimage(cursorclear);
91 snprint(buf, sizeof buf, "can't allocate cursor images: %r");
98 * set up goo for screenputs
100 memdefont = getmemdefont();
105 /* a lot of work to get a grey color */
106 curscol = allocmemimage(Rect(0,0,1,1), RGBA32);
107 curscol->flags |= Frepl;
108 curscol->clipr = gscreen->r;
109 memfillcolor(curscol, 0xff0000ff);
111 memfillcolor(gscreen, 0x444488FF);
113 w = memdefont->info[' '].width;
114 h = memdefont->height;
116 window.min = addpt(gscreen->r.min, Pt(20,20));
117 window.max.x = window.min.x + Dx(gscreen->r)*3/4-40;
118 window.max.y = window.min.y + Dy(gscreen->r)*3/4-100;
120 memimagedraw(gscreen, window, memblack, ZP, memopaque, ZP, S);
121 window = insetrect(window, 4);
122 memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);
124 /* a lot of work to get a grey color */
125 grey = allocmemimage(Rect(0,0,1,1), CMAP8);
126 grey->flags |= Frepl;
127 grey->clipr = gscreen->r;
128 memfillcolor(grey, 0xAAAAAAFF);
129 memimagedraw(gscreen, Rect(window.min.x, window.min.y,
130 window.max.x, window.min.y+h+5+6), grey, ZP, nil, ZP, S);
132 window = insetrect(window, 5);
134 greet = " Plan 9 Console ";
135 p = addpt(window.min, Pt(10, 0));
136 q = memsubfontwidth(memdefont, greet);
137 memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
140 window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
141 flushmemscreen(gscreen->r);
149 attachscreen(Rectangle* r, ulong* chan, int* d, int* width, int *softscreen)
153 *chan = gscreen->chan;
154 *width = gscreen->width;
157 return gscreen->data->bdata;
161 getcolor(ulong , ulong* pr, ulong* pg, ulong* pb)
169 setcolor(ulong , ulong , ulong , ulong )
175 * called with cursor unlocked, drawlock locked
178 cursordraw(Memimage *dst, Rectangle r)
180 static uchar set[CURSORDIM*CURSORDIM], clr[CURSORDIM*CURSORDIM/8];
185 if(ver != cursorver){
187 for(i = 0; i < CURSORDIM*CURSORDIM/8; i += CURSORDIM/8){
188 for(j = 0; j < CURSORDIM; j++){
189 if(cursset[i + (j >> 3)] & (1 << (7 - (j & 7))))
196 memmove(clr, cursclr, CURSORDIM*CURSORDIM/8);
199 loadmemimage(cursorset, cursorr, set, CURSORDIM*CURSORDIM);
200 loadmemimage(cursorclear, cursorr, clr, CURSORDIM*CURSORDIM/8);
203 memimagedraw(dst, r, memwhite, ZP, cursorclear, ZP, SoverD);
204 memimagedraw(dst, r, curscol, ZP, cursorset, ZP, SoverD);
208 * called with cursor locked, drawlock possibly unlocked
215 r.min.x = cursorpos.x + cursor.offset.x;
216 r.min.y = cursorpos.y + cursor.offset.y;
217 r.max.x = r.min.x + CURSORDIM;
218 r.max.y = r.min.y + CURSORDIM;
223 * called with cursor locked, drawlock possibly unlocked
226 setcursor(Cursor* curs)
229 memmove(cursset, curs->set, CURSORDIM*CURSORDIM/8);
230 memmove(cursclr, curs->clr, CURSORDIM*CURSORDIM/8);
238 cursorpos = mousexy();
246 cursoroff(int dolock)
250 cursorpos = offscreen;
256 blankscreen(int blank)
264 flushmemscreen(flushr);
265 flushr = Rect(10000, 10000, -10000, -10000);
269 addflush(Rectangle r)
271 if(flushr.min.x >= flushr.max.x)
274 combinerect(&flushr, r);
285 r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
286 p = Pt(window.min.x, window.min.y+o);
287 memimagedraw(gscreen, r, gscreen, p, nil, p, S);
288 r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
289 memimagedraw(gscreen, r, back, ZP, nil, ZP, S);
290 flushmemscreen(gscreen->r);
296 screenputc(char *buf)
302 static int xbuf[256];
304 if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
309 if(curpos.y+h >= window.max.y)
316 curpos.x = window.min.x;
319 p = memsubfontwidth(memdefont, " ");
322 pos = (curpos.x-window.min.x)/w;
324 r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h);
325 memimagedraw(gscreen, r, back, back->r.min, memopaque, ZP, S);
333 r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
334 memimagedraw(gscreen, r, back, back->r.min, memopaque, ZP, S);
341 p = memsubfontwidth(memdefont, buf);
344 if(curpos.x >= window.max.x-w)
348 r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y + h);
349 memimagedraw(gscreen, r, back, back->r.min, memopaque, ZP, S);
350 memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);
357 screenputs(char *s, int n)
359 static char rb[UTFmax+1];
367 if(nrb >= UTFmax || fullrune(rb, nrb)){