9 static int checkmouse(void);
10 static int buttondown(void);
11 static char *getmousestr(void);
12 static char *getkbdstr(int);
22 if(initdraw(0, 0, "proof") < 0){
23 fprint(2, "proof: initdraw failed: %r\n");
26 einit(Ekeyboard|Emouse);
32 draw(screen, screen->r, display->black, nil, ZP);
36 screenprint(char *fmt, ...)
43 vseprint(buf, &buf[sizeof buf], fmt, args);
45 p = Pt(screen->clipr.min.x+40, screen->clipr.max.y-40);
46 string(screen, p, display->black, ZP, font, buf);
56 static ulong timekey = 0;
62 timekey = etimer(0, 5000);
75 if ((e & Emouse) && ev.mouse.buttons) {
78 } else if (e & Ekeyboard)
79 return getkbdstr(ev.kbdc); /* sadly, no way to unget */
80 else if (e & timekey) {
81 if((dir = dirstat(track)) != nil){
82 if(tracktm < dir->mtime){
103 screenprint("%s", buf);
104 for (p = buf+1; (c = ekbd()) != '\n' && c != '\r' && c != -1 && c != Viewkey; ) {
105 if (c == '\b' && p > buf) {
111 screenprint("%s", buf);
118 #define button3(b) ((b) & 4)
119 #define button2(b) ((b) & 2)
120 #define button1(b) ((b) & 1)
121 #define button23(b) ((b) & 6)
122 #define button123(b) ((b) & 7)
124 #define butcvt(b) (1 << ((b) - 1))
126 int waitdown(void) /* wait until some button is down */
128 while (!(mouse.buttons & 7))
130 return mouse.buttons & 7;
135 while (mouse.buttons & 7)
137 return mouse.buttons & 7;
140 char *m3[] = { "next", "prev", "page n", "again", "bigger", "smaller", "pan", "quit?", 0 };
143 enum { Next = 0, Prev, Page, Again, Bigger, Smaller, Pan, Quit };
145 Menu mbut3 = { m3, 0, 0 };
146 Menu mbut2 = { m2, 0, 0 };
153 Point dd, xy, lastxy, min, max;
161 dd = subpt(mouse.xy, lastxy);
162 min = addpt(screen->clipr.min, dd);
163 max = addpt(screen->clipr.max, dd);
164 draw(screen, rectaddpt(screen->r, subpt(mouse.xy, lastxy)),
165 screen, nil, screen->r.min);
166 if(mouse.xy.x < lastxy.x) /* moved left, clear right */
167 draw(screen, Rect(max.x, screen->r.min.y, screen->r.max.x, screen->r.max.y),
168 display->white, nil, ZP);
169 else /* moved right, clear left*/
170 draw(screen, Rect(screen->r.min.x, screen->r.min.y, min.x, screen->r.max.y),
171 display->white, nil, ZP);
172 if(mouse.xy.y < lastxy.y) /* moved up, clear down */
173 draw(screen, Rect(screen->r.min.x, max.y, screen->r.max.x, screen->r.max.y),
174 display->white, nil, ZP);
175 else /* moved down, clear up */
176 draw(screen, Rect(screen->r.min.x, screen->r.min.y, screen->r.max.x, min.y),
177 display->white, nil, ZP);
178 flushimage(display, 1);
179 }while(mouse.buttons);
181 xyoffset = addpt(xyoffset, subpt(mouse.xy, xy));
194 return "p"; /* repaint after panning */
197 } else if (last_but == 3) {
204 screenprint("page? ");
209 snprint(buf, sizeof buf, "m%g", mag * 1.1);
212 snprint(buf, sizeof buf, "m%g", mag / 1.1);
221 } else { /* button 1 or bail out */
227 checkmouse(void) /* return button touched if any */
231 extern int confirm(int);
238 last_hit = emenuhit(3, &mouse, &mbut3);
240 } else if (button2(b)) {
241 last_hit = emenuhit(2, &mouse, &mbut2);
243 } else { /* button1() */
248 if (last_but == 3 && last_hit >= 0) {
250 c = p[strlen(p) - 1];
252 if (c == '?' && !confirm(last_but))
258 { 0, 0}, /* offset */
259 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260 0x00, 0x00, 0x00, 0x0C, 0x00, 0x82, 0x04, 0x41,
261 0xFF, 0xE1, 0x5F, 0xF1, 0x3F, 0xFE, 0x17, 0xF0,
262 0x03, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },
263 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264 0x00, 0x00, 0x00, 0x0C, 0x00, 0x82, 0x04, 0x41,
265 0xFF, 0xE1, 0x5F, 0xF1, 0x3F, 0xFE, 0x17, 0xF0,
266 0x03, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }
271 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
272 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
273 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
274 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, },
275 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
276 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
277 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
278 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }
283 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03,
284 0xE7, 0xE7, 0x3F, 0xFC, 0x0F, 0xF0, 0x0D, 0xB0,
285 0x07, 0xE0, 0x06, 0x60, 0x37, 0xEC, 0xE4, 0x27,
286 0xC3, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },
287 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03,
288 0xE7, 0xE7, 0x3F, 0xFC, 0x0F, 0xF0, 0x0D, 0xB0,
289 0x07, 0xE0, 0x06, 0x60, 0x37, 0xEC, 0xE4, 0x27,
290 0xC3, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }
293 confirm(int but) /* ask for confirmation if menu item ends with '?' */
296 static int but_cvt[8] = { 0, 1, 2, 0, 3, 0, 0, 0 };
302 return but == but_cvt[c];