Annotation of researchv9/jtools/src/cip/cip.c, revision 1.1.1.1

1.1       root        1: /*
                      2:   %Z%  %M%  version %I% %Q%of %H% %T%
                      3:   Last Delta:  %G% %U% to %P%
                      4: */
                      5: 
                      6: #include "cip.h"
                      7: 
                      8: #define Xbut1 (Xbut+(Xmax-Xbut)/6)
                      9: #define Xbut2 ((Xmax+Xbut)>>1)
                     10: #define Xbut3 (Xmax-(Xmax-Xbut)/6)
                     11: #define Ybut123 (Ybut+((ButSize*3)>>2))
                     12: 
                     13: Point jchar();
                     14: 
                     15: int gridState = GRIDoff;
                     16: int videoState = WHITEfield;
                     17: Rectangle brushes[NUMBR+2];
                     18: int currentBrush = {-1};
                     19: 
                     20: int copyFlag = 0;
                     21: int thingSelected = 0;
                     22: int editDepth = 0;
                     23: int buttonState = 0;
                     24: fontBlk *fonts = {(fontBlk *)NULL};
                     25: 
                     26: char *but1text[numButtonStates] = 
                     27:   {"select","select","select","","","","select","select","no","center"};
                     28: char *but2text[numButtonStates] = 
                     29:   {"","draw","edit","draw","","draw box","copy","move","no","move box"};
                     30: char *but3text[numButtonStates] = 
                     31:   {"menu","menu","menu","end spline","","","menu","menu","yes",""};
                     32: extern insertFont ();
                     33: extern void message ();
                     34: extern struct macro *macroList;
                     35: extern Word *saveBase;
                     36: extern Rectangle saveScreenmap;
                     37: extern Cursor hourglass;
                     38: short noSpace;         /* Indicates out of initial amount of memory */
                     39: char *dgetenv();
                     40: char *strcat();
                     41: 
                     42: #define        HEIGHT  10.0
                     43: #define        WIDTH   7.0
                     44: #define        MM_INCH 25.4
                     45: #define        MINBORDER       20
                     46: 
                     47: #ifdef X11
                     48: jerqsizehints()
                     49: {
                     50:        double pix_inch;
                     51:        int width, height;
                     52: 
                     53:        pix_inch = (XDisplayHeight(dpy, 0) * MM_INCH)/XDisplayHeightMM(dpy, 0);
                     54:        width = pix_inch * WIDTH;
                     55:        if (width > (XDisplayWidth(dpy, 0) - MINBORDER))
                     56:                width = XDisplayWidth(dpy, 0) - MINBORDER;
                     57:        height = pix_inch * HEIGHT;
                     58:        if (height > XDisplayHeight(dpy, 0) - MINBORDER)
                     59:                height = XDisplayHeight(dpy, 0) - MINBORDER;
                     60:        setsizehints (width, height, 1);
                     61: }
                     62: #endif X11
                     63: 
                     64: main(argc, argv)
                     65: char *argv[];
                     66: {      
                     67:   register struct thing *currentThing =  TNULL ;
                     68: 
                     69:   request(MOUSE|KBD);
                     70:   initdisplay(argc, argv);
                     71:   initcursors();
                     72:   initFontList ();
                     73:   noSpace = 0;
                     74:   for (;;) {
                     75:     currentThing = doMouseButtons(currentThing,Pt(Xmin,YPIC));
                     76:     nap(2);
                     77:   }
                     78: }
                     79: 
                     80: brushInit()
                     81: {
                     82:   register int x; 
                     83:   register int i;
                     84: 
                     85:   x=Xmin; 
                     86:   for (i=0; i<NUMBR; i++) {
                     87:     brushes[i].origin.x = x;
                     88:     x += DXBR;
                     89:     brushes[i].corner.x = x-LW;
                     90:     brushes[i].origin.y = Ymin;
                     91:     brushes[i].corner.y = YBR;
                     92:   }
                     93:   brushes[PIC].origin.x = Xmin+LW;
                     94:   brushes[PIC].origin.y = YPIC+LW;
                     95:   brushes[PIC].corner.x = Xmax-LW;
                     96:   brushes[PIC].corner.y = YBOT-LW;
                     97:   brushes[ED].origin.x = XeditD;
                     98:   brushes[ED].origin.y = Ybut;
                     99:   brushes[ED].corner.x = Xbut - LW;
                    100:   brushes[ED].corner.y = Ymax;
                    101: }
                    102: 
                    103: drawFrame()
                    104: {
                    105:   register int i;
                    106: 
                    107:   for (i=0; i<NUMBR; i++) {
                    108:     rectf(&display, brushes[i],F_XOR);
                    109:     rectf(&display, inset(brushes[i],LW),F_XOR);
                    110:     drawBrush(i);
                    111:   }
                    112:   rectf(&display, brushes[PIC],F_XOR);
                    113:   rectf(&display, inset(brushes[PIC],-LW),F_XOR);
                    114:   /* Init message frame */
                    115:   rectf (&display, Rect(Xmin, Ybut, XeditD-LW, Ymax), F_XOR);
                    116:   rectf (&display, inset(Rect (Xmin, Ybut, XeditD-LW, Ymax),LW), F_XOR);
                    117:   Buttons();
                    118: }      
                    119: 
                    120: drawBrush(i) 
                    121: register int i;
                    122: {
                    123:   register int r;  
                    124:   Point m; 
                    125:   Point p[6];
                    126: 
                    127:   r = (YBR-Ymin)*3>>3;
                    128:   m = div( add( brushes[i].origin, brushes[i].corner), 2);
                    129:   switch (i) {
                    130:     case CIRCLE: {
                    131:       circle(&display, m,r,F_XOR);
                    132:       break;
                    133:     }
                    134:     case BOX: {
                    135:       box(Rect(m.x-r,m.y-r,m.x+r,m.y+r)); 
                    136:       break;
                    137:     }
                    138:     case ELLIPSE: {
                    139:       Ellipse(m,(r<<1),r*3);
                    140:       break;
                    141:     }
                    142:     case LINE: {
                    143:       segment(&display, Pt(m.x-r,m.y),Pt(m.x+r,m.y),F_XOR);
                    144:       break;
                    145:     }
                    146:     case ARC: {
                    147:       arc(&display, Pt(m.x,m.y+r),Pt(m.x+r,m.y),Pt(m.x-r,m.y),F_XOR);
                    148:       break;
                    149:     }
                    150:     case SPLINE: {
                    151:       p[1] = sub(m,Pt(r,r));
                    152:       p[2] = add(m,Pt(r>>1,-r));
                    153:       p[3] = sub(m,Pt(r>>1,-r));
                    154:       p[4] = add(m,Pt(r,r));
                    155:       spline(Pt(0,0),p,5);
                    156:       break;
                    157:     }
                    158:     case TEXT: {
                    159:       centeredText(sub(m,Pt(0,10)),"Text");
                    160:       break;
                    161:     }
                    162:   }
                    163: }
                    164: 
                    165: Rectangle *
                    166: Select(t, m, offset)
                    167: struct thing *t;
                    168: Point m;
                    169: Point offset;
                    170: {      
                    171:   register int i;
                    172: 
                    173:   for (i=0; ((i<NUMBR+2)&&(!ptinrect(m,brushes[i]))); i++) ;
                    174:   if (i==PIC) {
                    175:     return(&brushes[PIC]);  /* temporary */
                    176:   }
                    177:   else if (i==ED) {
                    178:     if (editDepth>0) {
                    179:       drawEDbutton(editDepth); /* Undraw edit button */
                    180:       if ((--editDepth)!=0) {
                    181:        drawEDbutton(editDepth);
                    182:       }
                    183:     }
                    184:     changeBrush(-1);   
                    185:     if (thingSelected) {
                    186:       drawSelectionLines (t, offset);
                    187:       thingSelected = 0;
                    188:     }
                    189:     changeButtons(INITbuttons);
                    190:     return( (Rectangle *) NULL);
                    191:   }
                    192:   else if (i==NUMBR+2) {
                    193:     changeBrush(-1);   
                    194:     changeButtons(INITbuttons);
                    195:     return( (Rectangle *) NULL);
                    196:   }
                    197:   else {
                    198:     changeBrush(i);
                    199:     return(&brushes[i]);
                    200:   }
                    201: }
                    202:     
                    203: Buttons()
                    204: {      
                    205:   rectf(&display, Rect(Xbut,Ybut,Xmax,Ymax),F_XOR);
                    206:   rectf(&display, inset(Rect(Xbut,Ybut,Xmax,Ymax),LW),F_XOR);
                    207:   centeredText(Pt(Xbut2,Ytext), "Mouse Buttons");
                    208:   writeButtonLabels(INITbuttons);
                    209:   buttonState = INITbuttons;
                    210: }
                    211:   
                    212: labeledButton(p,s) 
                    213: Point p; 
                    214: register char *s;
                    215: {
                    216:   register int w;
                    217: 
                    218:   w = (strwidth(&defont,s)+8)>>1;
                    219:   if (w<=4) {
                    220:     w=butHt;
                    221:   }
                    222:   centeredText(add(p,Pt(0,(butHt>>1)-10)),s);
                    223:   box(Rpt(sub(p,Pt(w,butHt)),add(p,Pt(w,butHt))));
                    224: }
                    225: 
                    226: Point PtCurrent;
                    227: void
                    228: jMoveTo (xy)
                    229: Point xy;
                    230: {
                    231:   PtCurrent = xy;
                    232: }
                    233: 
                    234: Point
                    235: jString(s)
                    236: register char *s;
                    237: {
                    238:   return PtCurrent=string(&defont,s,&display,PtCurrent,F_XOR);
                    239: }
                    240: 
                    241: Point 
                    242: jchar(c) 
                    243: register char c;
                    244: {
                    245:   char s[2];
                    246: 
                    247:   s[0]=c; s[1] = '\0';
                    248:   return(jString(s));
                    249: }
                    250:   
                    251: drawSelectionLines(t,p) 
                    252: register struct thing *t; 
                    253: Point p; 
                    254: {
                    255:   Point p1;
                    256: 
                    257:   if (t!=TNULL) {
                    258:     if (t->type==SPLINE) {
                    259:       drawZigZag(p,t->otherValues.spline.plist,
                    260:         t->otherValues.spline.used);
                    261:     }
                    262:     else if (t->type==ARC) {
                    263:       p1 = add(t->origin,p);
                    264:       xsegment(p1,add(p,t->otherValues.arc.start));
                    265:       xsegment(p1,add(p,t->otherValues.arc.end));
                    266:     }  
                    267:   }
                    268: }
                    269: 
                    270: drawGrid()
                    271: {      
                    272:   cursinhibit();
                    273:   texture(&display,inset (Rect(Xmin,YPIC,Xmax,YBOT), LW),&grid,F_XOR);
                    274:   cursallow();
                    275: }
                    276: 
                    277: drawEDbutton(depth) 
                    278: int depth;
                    279: {      
                    280:   char s[5]; 
                    281:   Point p;
                    282:   register int dy;
                    283: 
                    284:   rectf (&display, brushes[ED], F_XOR);
                    285:   rectf (&display, inset(brushes[ED],LW),F_XOR);
                    286:   p.x = (brushes[ED].corner.x + brushes[ED].origin.x)>>1;
                    287:   dy = (brushes[ED].corner.y - brushes[ED].origin.y)/3;
                    288:   p.y = brushes[ED].origin.y + dy - 10;
                    289:   centeredText(p,"edit depth");
                    290:   p.y = brushes[ED].origin.y + (dy<<1) - 10;
                    291:   sprintf(s,"%d",depth);
                    292:   centeredText(p,s);
                    293: }
                    294: 
                    295: changeBrush(new) 
                    296: register int new;
                    297: {
                    298:   if (currentBrush>-1) {
                    299:     flash(&brushes[currentBrush],Pt(0,0));
                    300:   }
                    301:   if (new>-1) {
                    302:     flash(&brushes[new],Pt(0,0));
                    303:   }
                    304:   currentBrush = new;
                    305: }
                    306: 
                    307: changeButtons(new) 
                    308: register int new;
                    309: {      
                    310:   if (buttonState != new) { 
                    311:     writeButtonLabels(buttonState);
                    312:     writeButtonLabels(new);
                    313:     buttonState = new;
                    314:   }
                    315: }
                    316:     
                    317: writeButtonLabels(i) 
                    318: register int i;
                    319: {
                    320:     labeledButton(Pt(Xbut1,Ybut123),but1text[i]);
                    321:     labeledButton(Pt(Xbut2,Ybut123),but2text[i]);
                    322:     labeledButton(Pt(Xbut3,Ybut123),but3text[i]);
                    323: }
                    324: 
                    325: beep()
                    326: {
                    327:   ringbell();
                    328: }
                    329: 
                    330: 
                    331: 
                    332: initFontList ()
                    333: {
                    334:   if ((fonts=(fontBlk *)getSpace(sizeof(fontBlk))) == (fontBlk *) NULL) {
                    335:     message ("No memory");
                    336:     sleep (5);
                    337:     exit (1);
                    338:   }
                    339:   fonts->f = &defont;
                    340:   fonts->ps = 10;
                    341:   fonts->num = DEFONT;
                    342:   fonts->useCount = 0;
                    343:   fonts->next = fonts;
                    344:   fonts->last = fonts;
                    345: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.