|
|
1.1 root 1: /* Copyright (c) 1989, 1990 AT&T --- All Rights Reserved. */
2: /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T. */
3: /* The copyright notice does not imply actual or intended publication. */
4: /* AUTHORS: */
5: /* T. Thompson - ATT-BL HO - first versions */
6: #include <stdio.h>
7: #include <sys/types.h>
8: #include <sys/stat.h>
9: #include <sys/ioctl.h>
10: #include <pixrect/pixrect.h>
11: #include <pixrect/pixfont.h>
12: #include <suntool/sunview.h>
13: #include <suntool/canvas.h>
14: #include "met.h"
15: #include "boole.h"
16: #include "Coord.h"
17:
18: #define XYSCALE(x,y) (x=(x-obotx)*scx+botx),(y=(y-oboty)*scy+boty)
19:
20: struct pixrect *source_pixrect;
21:
22: Frame Mainframe;
23: Canvas Win;
24: int Winfd;
25: Pixwin *Pw;
26: int Key = -1;
27: int Mousex;
28: int Mousey;
29: int Colorval;
30:
31: /* CMAPSIZE MUST BE A POWER OF 2 (restriction in sun colormap stuff)*/
32: #define CMAPSIZE 8
33:
34: #define DEFAULTCOLOR (CMAPSIZE-1)
35:
36: #define S_WHITE 0
37: #define S_RED 1
38: #define S_GREEN 2
39: #define S_BLUE 3
40: #define S_GREY 4
41: #define S_AQUA 5
42: #define S_YELLOW 6
43: #define S_BLACK 7
44:
45: int mycolors[CMAPSIZE][3] = {
46: 255, 255, 255, /* white */
47: 230, 0, 75, /* red */
48: 0, 200, 0, /* green */
49: 0, 0, 200, /* blue */
50: 200, 200, 200, /* grey */
51: 0, 160, 170, /* aqua */
52: 250, 220, 0, /* yellow */
53: 0,0,0 /* foreground (black) */
54: };
55:
56:
57: void domouse();
58:
59: extern int Debug;
60:
61: extern event_proc();
62:
63: static int
64: boty = 32767, /* screen bottom y */
65: botx = 0, /* screen bottom x */
66: topx = 32767, /* screen top x */
67: topy = 0, /* screen top y */
68: oboty = 0, /* user's bottom y */
69: obotx = 0, /* user's bottom x */
70: otopy = 32767, /* user's top y */
71: otopx = 32767; /* user's top x */
72:
73: static double
74: scx = 1.0, /* scale factor x */
75: scy = 1.0 /* scale factor y */
76: ;
77: static int lastx = 0;
78: static int lasty = 0;
79: static int lmode = 3; /* drawing mode (default is xor)*/
80:
81: int Prevlmode = 3;
82:
83: #define signof(x) ((x)>=0.0?(1):(-1))
84: #define absof(x) ((x)>=0.0?(x):(-x))
85:
86: void flushout() { }
87:
88: short bsy_pixrect_data[] = {
89: /* Format_version=1, Width=16, Height=16, Depth=1, Valid_bits_per_item=16
90: */
91: 0x7FFE,0x4002,0x200C,0x1A38,0x0FF0,0x07E0,0x03C0,0x0180,
92: 0x0180,0x0240,0x0520,0x0810,0x1108,0x23C4,0x47E2,0x7FFE
93: };
94: mpr_static(busy_pixrect, 16, 16, 1, bsy_pixrect_data);
95:
96: int childpid;
97:
98: Rect sweeparect();
99:
100: om_open()
101: {
102: Rect r;
103:
104: r = sweeparect();
105:
106: notify_errno = NOTIFY_OK;
107:
108: Mainframe = window_create((Window)NULL, FRAME,
109: FRAME_LABEL, "ocr",
110: 0 );
111: Win = window_create(Mainframe, CANVAS, 0);
112: Pw = canvas_pixwin(Win);
113:
114: window_set(Mainframe, WIN_X, r.r_left,
115: WIN_Y, r.r_top, 0);
116: window_set(Win, WIN_WIDTH, r.r_width,
117: WIN_HEIGHT, r.r_height, 0);
118:
119: window_fit(Win);
120: window_fit(Mainframe);
121:
122: window_set(Mainframe, WIN_SHOW, TRUE, 0);
123:
124: Winfd = (int) window_get(Win, WIN_FD);
125:
126: if ( notify_errno != NOTIFY_OK ) {
127: notify_perror("ocr");
128: exit(1);
129: }
130:
131: setcolormap();
132:
133: set_color(DEFAULTCOLOR);
134: linemod("solid");
135:
136: window_set(Win,
137: WIN_CONSUME_PICK_EVENTS,
138: WIN_NO_EVENTS,
139: WIN_ASCII_EVENTS,
140: WIN_MOUSE_BUTTONS,
141: LOC_MOVE,
142: /* LOC_DRAG, */
143: LOC_WINEXIT, LOC_WINENTER,
144: LOC_RGNEXIT, LOC_RGNENTER, 0,
145: 0);
146:
147: window_set(Win, WIN_EVENT_PROC, event_proc, 0);
148:
149: space(0,0,M_WID,M_HGT);
150: interact();
151: }
152:
153: /***********************************************************/
154: /* The code below was taken from the 'dumpregion' program. */
155: /***********************************************************/
156:
157: /*
158: * Copyright Richard Tobin 1987. You may freely copy, modify and distribute
159: * this program in source form provided this comment remains intact.
160: *
161: * Richard Tobin, JANET: [email protected]
162: * AI Applications Institute, ARPA: R.Tobin%[email protected]
163: * Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin
164: */
165:
166: #include <sys/file.h>
167: #include <suntool/fullscreen.h>
168:
169: short nwdata[] = {
170: #include </usr/include/images/stretchNW.cursor>
171: };
172: mpr_static(nwpixrect, 16, 16, 1, nwdata);
173:
174: short sedata[] = {
175: #include </usr/include/images/stretchSE.cursor>
176: };
177: mpr_static(sepixrect, 16, 16, 1, sedata);
178:
179: Rect rect = {0,0,0,0};
180:
181: Rect
182: sweeparect()
183: {
184: int wfd, n;
185: struct fullscreen *fs;
186: Event event;
187: Pixwin *pw;
188: int left, right, top, bottom, temp;
189: Window win;
190: double w;
191: Rect r;
192:
193: win = window_create(0, FRAME,
194: FRAME_OPEN_RECT, &rect,
195: WIN_CONSUME_PICK_EVENTS,
196: WIN_ASCII_EVENTS,
197: LOC_MOVE, WIN_MOUSE_BUTTONS, 0,
198: 0);
199:
200: wfd = (int)window_get(win, WIN_FD);
201: fs = fullscreen_init(wfd);
202: pw = fs->fs_pixwin;
203:
204: window_set(win,
205: WIN_CURSOR, cursor_create(CURSOR_IMAGE, &nwpixrect,
206: CURSOR_XHOT, 0, CURSOR_YHOT, 0,
207: 0),
208: 0);
209:
210: for ( ;; ) {
211: n = window_read_event(win, &event);
212: if ( n < 0 )
213: continue;
214: if ( event_is_ascii(&event) ) {
215: if ( event_id(&event) == 'F' ) {
216: r.r_left = 10;
217: r.r_top = 10;
218: r.r_width = 900;
219: r.r_height = 900;
220: }
221: else {
222: r.r_left = 542;
223: r.r_top = 0;
224: r.r_width = 540;
225: r.r_height = 512;
226: }
227: goto getout;
228: }
229: if ( event_is_down(&event) && event_is_button(&event) )
230: break;
231: }
232:
233: right = left = event_x(&event);
234: bottom = top = event_y(&event);
235:
236: window_set(win,
237: WIN_CURSOR, cursor_create(CURSOR_IMAGE, &sepixrect,
238: CURSOR_XHOT, 15, CURSOR_YHOT, 15,
239: 0),
240: 0);
241:
242: drawbox(pw, left, top, right, bottom);
243:
244: while(window_read_event(win, &event) == -1 ||
245: !event_is_up(&event) ||
246: !event_is_button(&event))
247: {
248: drawbox(pw, left, top, right, bottom);
249: right = event_x(&event);
250: bottom = event_y(&event);
251: drawbox(pw, left, top, right, bottom);
252: }
253:
254: drawbox(pw, left, top, right, bottom);
255:
256: if(right < left)
257: {
258: temp = right;
259: right = left;
260: left = temp;
261: }
262: if(bottom < top)
263: {
264: temp = bottom;
265: bottom = top;
266: top = temp;
267: }
268: r.r_left = left;
269: r.r_top = top;
270: r.r_width = (right-left);
271: r.r_height = (bottom-top);
272: getout:
273: fullscreen_destroy(fs);
274:
275: window_set(win, FRAME_NO_CONFIRM, TRUE, 0);
276: window_destroy(win);
277: return r;
278: }
279:
280: drawbox(pw, left, top, right, bottom)
281: Pixwin *pw;
282: int left, top, right, bottom;
283: {
284: fullscreen_pw_vector(pw, left, top, right, top, PIX_NOT(PIX_DST), 0);
285: fullscreen_pw_vector(pw, right, top, right, bottom, PIX_NOT(PIX_DST), 0);
286: fullscreen_pw_vector(pw, right, bottom, left, bottom, PIX_NOT(PIX_DST), 0);
287: fullscreen_pw_vector(pw, left, bottom, left, top, PIX_NOT(PIX_DST), 0);
288: }
289:
290: ttygets(buff,len)
291: char *buff;
292: {
293: int x, y, n, key;
294: char *p = buff;
295:
296: for ( n=0; n<(len-1); n++ ) {
297: while ( (key=mouseorkey(&x,&y)) < 0 )
298: ;
299: if ( key == '\r' ) /* just in case */
300: key = '\n';
301: *p++ = key;
302: if ( key == '\n' || key == '\0' )
303: break;
304: }
305: *p++ = '\0';
306: }
307:
308: int mouseorkey(x,y)
309: int* x;
310: int* y;
311: {
312: Event anevent;
313: char c;
314: int n;
315:
316: Key = -1;
317:
318: notify_do_dispatch();
319: n = read(0,&c,1);
320: notify_no_dispatch();
321: if ( n == 1 ) {
322: /* character was typed in text (original) window */
323: /* ie. stdin */
324: Key = c;
325: *x = Mousex;
326: *y = Mousey;
327: xyunscale(x,y);
328: }
329: else if ( Key >= 0 ) {
330: /* character was typed in graphics window */
331: /* so it must be echoed. */
332: putchar(Key);
333: if ( Key == '\r' )
334: putchar('\n');
335: fflush(stdout);
336: *x = Mousex;
337: *y = Mousey;
338: xyunscale(x,y);
339: }
340: return(Key);
341: }
342:
343: interact()
344: {
345: (void) notify_dispatch();
346: }
347:
348: setcolormap()
349: {
350: u_char red[CMAPSIZE], green[CMAPSIZE], blue[CMAPSIZE];
351: int n;
352:
353: for(n=0;n<CMAPSIZE;n++) {
354: red[n] = mycolors[n][0];
355: green[n] = mycolors[n][1];
356: blue[n] = mycolors[n][2];
357: }
358: pw_setcmsname(Pw,"showcolor");
359: pw_putcolormap(Pw, 0, CMAPSIZE, red, green, blue);
360: }
361:
362: /*ARGSUSED*/
363: wait_proc(window,event,arg)
364: Window window;
365: Event *event;
366: caddr_t arg;
367: {
368: int id = event_id(event);
369:
370: if ( event_is_ascii(event) && id == 'q' )
371: notify_stop(0);
372: }
373:
374: om_close()
375: {
376: window_set(Win, WIN_EVENT_PROC, wait_proc, 0);
377: if ( fork() == 0 ) {
378: close(0);
379: close(1);
380: close(2);
381: /* This stuff doesn't seem to work. I'm trying to */
382: /* get the window to be able to repaint itself when */
383: /* uncovered. */
384: sleep(1);
385: window_main_loop(Mainframe);
386: exit(0);
387: }
388: }
389:
390: space(x0,y0,x1,y1)
391: int x0, y0, x1, y1;
392: {
393: int tx, ty;
394:
395: obotx = x0;
396: oboty = y0;
397: otopx = x1;
398: otopy = y1;
399:
400: boty = 0;
401: botx = 0;
402: tx = (int) window_get(Win,WIN_WIDTH);
403: ty = (int) window_get(Win,WIN_HEIGHT);
404: topx = tx;
405: topy = ty;
406: scx = (double)(topx-botx)/(otopx-obotx);
407: scy = (double)(topy-boty)/(otopy-oboty);
408: }
409:
410: #ifdef OLDSTUFF
411: xyscale(x, y)
412: int *x, *y;
413: {
414: *x = (*x-obotx)*scx+botx;
415: *y = (*y-oboty)*scy+boty;
416: }
417: #endif
418:
419: xyunscale(x, y)
420: int *x, *y;
421: {
422: /* map from device coordinates to space() coordinates */
423:
424: *x = ( (*x - botx)/scx + obotx );
425: *y = ( (*y - boty)/scy + oboty );
426: }
427:
428: wline(x1,y1,x2,y2)
429: int x1, y1, x2, y2;
430: {
431: lastx = x2;
432: lasty = y2;
433:
434: XYSCALE(x1, y1);
435: XYSCALE(x2, y2);
436:
437: arawline(x1,y1,x2,y2);
438: }
439:
440: wrect(x1,y1,x2,y2)
441: int x1, y1, x2, y2;
442: {
443: lastx = x2;
444: lasty = y2;
445:
446: XYSCALE(x1, y1);
447: XYSCALE(x2, y2);
448:
449: arawbox(x1,y1,x2,y2);
450: }
451:
452: arawbox(x1,y1,x2,y2)
453: int x1, y1, x2, y2;
454: {
455: arawline(x1,y1,x2,y1);
456: arawline(x2,y1,x2,y2);
457: arawline(x2,y2,x1,y2);
458: arawline(x1,y2,x1,y1);
459: }
460:
461: arawline(x1,y1,x2,y2)
462: int x1, y1, x2, y2;
463: {
464: int op, col;
465:
466: currentopcol(&op,&col);
467: /* fprintf(stderr,"calling pw_vector, %d,%d %d,%d currentop=%d Colorval=%d Pw=%ld\n",x1,y1,x2,y2,op,col,Pw); */
468: pw_vector(Pw, (int)x1,(int)y1, (int)x2,(int)y2, op, col);
469: interact();
470: }
471:
472: currentopcol(aop,acol)
473: int *aop, *acol;
474: {
475: if ( lmode == 1 && Colorval == S_WHITE ) {
476: *aop = (PIX_NOT(PIX_SRC) & PIX_DST);
477: *acol = S_BLACK;
478: }
479: else {
480: *acol = Colorval;
481: switch (lmode) {
482: case 0:
483: *aop = (PIX_NOT(PIX_SRC) & PIX_DST);
484: break;
485: case 1:
486: case 2:
487: /* *aop = (PIX_SRC | PIX_DST); */
488: *aop = PIX_SRC;
489: break;
490: case 3:
491: *aop = (PIX_SRC ^ PIX_DST);
492: break;
493: default:
494: *aop = (PIX_SRC | PIX_DST);
495: break;
496: }
497: }
498: }
499:
500: wt(s,scl,left,top,right,bot)
501: char *s;
502: {
503: int op, col;
504: /* fprintf(stderr,"wt() called, s=%s lastxy=%d,%d scl=%d left-top=%d,%d\n",
505: s,left,top,scl,left,top); */
506: currentopcol(&op,&col);
507: XYSCALE(left, top);
508: pw_ttext(Pw,(int)left,(int)top,op,NULL,s);
509: }
510:
511: Sp *
512: set_font(n)
513: {
514: static Sp chsz;
515: struct pr_size prs;
516: int x, y;
517:
518: prs = pf_textwidth(1,pf_default(),"x");
519: x = prs.x;
520: y = prs.y;
521: xyunscale(&x,&y);
522: chsz.x = ++x;
523: chsz.y = y;
524: return &chsz;
525: }
526:
527: #ifdef OLDSTUFF
528: textwidth(s)
529: {
530: struct pr_size prs;
531:
532: prs = pf_textwidth(bound,strlen(s),pf_default(),s);
533:
534:
535: prs = pf_textwidth(1,pf_default(),"x");
536: *ax = prs.x;
537: *ay = prs.y;
538: xyunscale(ax,ay);
539: }
540: #endif
541:
542: amove(x,y)
543: int x,y;
544: {
545: lastx = x;
546: lasty = y;
547: }
548:
549: cont(x,y)
550: int x,y;
551: {
552: wline(lastx,lasty,x,y);
553: /* last[xy] are then updated by line */
554: }
555:
556:
557: set_color(n)
558: int n;
559: {
560: switch(n){
561: case M_WHITE:
562: n = S_WHITE; break;
563: case M_PALE_GREY:
564: case M_GREY_7:
565: n = S_GREY; break;
566: case M_BLACK:
567: n = S_BLACK; break;
568: case M_YELLOW_13:
569: case M_YELLOW_11:
570: n = S_YELLOW; break;
571: case M_MAGENTA:
572: case M_CYAN:
573: case M_CYAN_14:
574: n = S_AQUA; break;
575: case M_GREEN:
576: case M_GREEN_7:
577: n = S_GREEN; break;
578: case M_BLUE:
579: n = S_BLUE; break;
580: case M_RED:
581: n = S_RED; break;
582: default:
583: fprintf(stderr,"Unknown color in set_color (%d)\n",n);
584: n = S_WHITE;
585: break;
586: }
587: Colorval = n;
588: /* fprintf(stderr,"set_color = (sun#) %d\n",n); */
589: }
590:
591: linemod(s)
592: char *s;
593: {
594: if ( strcmp(s,"erase")==0 )
595: lmode = 0;
596: else if ( strcmp(s,"dotted")==0 || strcmp(s,"hilight")==0 )
597: lmode = 2;
598: else if ( strcmp(s,"xor")==0 )
599: lmode = 3;
600: else { /* everything, including "solid" defaults to this */
601: lmode = 1;
602: }
603: }
604:
605: aerase()
606: {
607: pw_writebackground(Pw,0,0,(int)topx,(int)topy,PIX_SRC);
608: }
609:
610: wfrect(x1,y1,x2,y2)
611: int x1, y1, x2, y2;
612: {
613: int op, col;
614: int t;
615:
616: XYSCALE(x1, y1);
617: XYSCALE(x2, y2);
618:
619: currentopcol(&op,&col);
620:
621: if ( x1 > x2 ) {
622: t = x1;
623: x1 = x2;
624: x2 = t;
625: }
626: if ( y1 > y2 ) {
627: t = y1;
628: y1 = y2;
629: y2 = t;
630: }
631: /* fprintf(stderr,"wfrect(%d,%d to %d,%d lmode=%d op=%d col=%d)\n",
632: x1,y1,x2,y2,lmode,op,col); */
633: for ( t=y1; t<=y2; t++ ) {
634: pw_vector(Pw, x1,t, x2,t, op, col);
635: }
636: interact();
637: }
638:
639: /*ARGSUSED*/
640: event_proc(window,event,arg)
641: Window window;
642: Event *event;
643: caddr_t arg;
644: {
645: int id = event_id(event);
646:
647: if ( event_is_ascii(event) ) {
648: Key = id;
649: notify_stop(0);
650: return;
651: }
652: }
653:
654: /* trim a Metheus X coordinate to fit on screen */
655: int M_trimX(x)
656: int x;
657: { if(x<0) return(0);
658: else if(x>(topx-1)) return((topx-1));
659: return(x);
660: }
661:
662: /* trim a Metheus Y coordinate to fit on screen */
663: int M_trimY(y)
664: int y;
665: { if(y<0) return(0);
666: else if(y>(topy-1)) return((topy-1));
667: return(y);
668: }
669:
670: /* show Sp (Metheus coordinates) on Metheus,
671: enlarged to a `dot'-sided square */
672: sh_Mp(mpp,dot)
673: Sp *mpp;
674: int dot;
675: { int half_dot;
676: if(dot==1)
677: wfrect(mpp->x,mpp->y,mpp->x,mpp->y);
678: else {
679: half_dot=dot/2;
680: if((dot%2)==0)
681: wfrect( M_trimX(mpp->x-half_dot+1),
682: M_trimY(mpp->y-half_dot+1),
683: M_trimX(mpp->x+half_dot),
684: M_trimY(mpp->y+half_dot) );
685: else wfrect( M_trimX(mpp->x-half_dot),
686: M_trimY(mpp->y-half_dot),
687: M_trimX(mpp->x+half_dot),
688: M_trimY(mpp->y+half_dot) );
689: };
690: }
691:
692:
693: om_force(){}
694:
695: /* write "thick" line, two pixels wide */
696: wtline(x1,y1,x2,y2)
697: { int absdx, absdy;
698: wline(x1,y1,x2,y2);
699: absdx = (x1-x2)>=0 ? x1-x2 : x2-x1;
700: absdy = (y1-y2)>=0 ? y1-y2 : y2-y1;
701: if(absdx>absdy)
702: /* more horizontal -- thicken vertically */
703: wline(x1,M_trimY(y1+1),x2,M_trimY(y2+1));
704: else
705: /* more vertical -- thicken horizontally */
706: wline(M_trimX(x1+1),y1,M_trimX(x2+1),y2);
707: }
708:
709: /* write "fat" line, three pixels wide */
710: wfline(x1,y1,x2,y2)
711: { register int absdx, absdy;
712:
713: wline(x1,y1,x2,y2);
714: absdx = (x1-x2)>=0 ? x1-x2 : x2-x1;
715: absdy = (y1-y2)>=0 ? y1-y2 : y2-y1;
716: if(absdx>absdy) {
717: /* more horizontal -- thicken vertically */
718: wline(x1,M_trimY(y1+1),x2,M_trimY(y2+1));
719: wline(x1,M_trimY(y1-1),x2,M_trimY(y2-1));
720: }
721: else {
722: /* more vertical -- thicken horizontally */
723: wline(M_trimX(x1+1),y1,M_trimX(x2+1),y2);
724: wline(M_trimX(x1-1),y1,M_trimX(x2-1),y2);
725: };
726: }
727:
728:
729: om_wrpix()
730: {
731: printf("om_wrpix called\n");
732: }
733:
734: om_buffer(n) { }
735:
736: rreset() { }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.