1*11982Sslatteng /* @(#)menu.c 1.2 04/18/83
211957Sslatteng *
311957Sslatteng * Copyright -C- 1982 Barry S. Roitblat
411957Sslatteng *
511957Sslatteng *
611957Sslatteng * This file contains the routines for initializing and displaying
711957Sslatteng * the graphics menu.
811957Sslatteng */
911957Sslatteng
1011957Sslatteng #include "gremlin.h"
1111957Sslatteng
1211957Sslatteng /* imports from graphics1.c */
1311957Sslatteng
1411957Sslatteng extern GRchex(); /* hex conversion routine */
1511957Sslatteng extern GRsetpos(); /* sets the current access position */
1611957Sslatteng extern GRVector(); /* vector drawing primitive */
1711957Sslatteng extern int GrXMax, GrYMax; /* screen dimensions */
1811957Sslatteng extern FILE *display; /* graphics display stream */
1911957Sslatteng extern GRDisableTablet(); /* disable graphics tablet */
2011957Sslatteng
2111957Sslatteng /* imports from long.c */
2211957Sslatteng
2311957Sslatteng extern LGCommand(), LGPoint(), LGUndo(), LGDeletePoint();
2411957Sslatteng
2511957Sslatteng /* imports from short.c */
2611957Sslatteng
2711957Sslatteng extern SHCommand();
2811957Sslatteng
2911957Sslatteng /* imports from main.c */
3011957Sslatteng
3111957Sslatteng extern float PX, PY; /* X and Y of last points specified */
3211957Sslatteng
3311957Sslatteng #define horiz 0
3411957Sslatteng #define vert 1
3511957Sslatteng #define menusize 32
3611957Sslatteng #define menuspace 30
3711957Sslatteng #define origin 10
3811957Sslatteng #define margin 25
3911957Sslatteng #define itemxsize 16
4011957Sslatteng #define itemysize 16
4111957Sslatteng #define fontsize (itemxsize * itemysize/8)
4211957Sslatteng #define itemlength (itemxsize * itemysize/4 + 1)
4311957Sslatteng #define maxchars 8
4411957Sslatteng #define smask 1
4511957Sslatteng #define columns 2
4611957Sslatteng #define border 395
4711957Sslatteng
48*11982Sslatteng
4911957Sslatteng /* bytewise definitions of menu symbols (special fonts), left to right,
5011957Sslatteng * top to bottom. See textcommand array for corresponding commands.
5111957Sslatteng */
5211957Sslatteng
5311957Sslatteng static char menu[menusize][itemlength] =
5411957Sslatteng {
5511957Sslatteng /* 1 */ "07F00080008000800080008000800080008000800080008000800080008007F0",
5611957Sslatteng /* 2 */ "08100810082008200840084008800F0008C00820081008100810082008C00F00",
5711957Sslatteng /* 3 */ "0000000000000000000000000000FFFFFFFFFFFF000000000000000000000000",
5811957Sslatteng /* 4 */ "0000000000000000000000000000E4E4E4E40000000000000000000000000000",
5911957Sslatteng /* 5 */ "0000000000000000000000000000924992490000000000000000000000000000",
6011957Sslatteng /* 6 */ "FFFF8001800187E18401840183018081804180218421842183C180018001FFFF",
6111957Sslatteng /* 7 */ "FFFF80018001808180818081808180818081808182818181808180018001FFFF",
6211957Sslatteng /* 8 */ "008001C002A0008000800080008000800080008000800080008002A001C00080",
6311957Sslatteng /* 9 */ "00000000000000000000000020044002FFFF4002200400000000000000000000",
6411957Sslatteng /* 10 */ "000080028002400440042008183007C0FFFF07C0183020084004400480028002",
6511957Sslatteng /* 11 */ "20002000FFFC2704288430443044304428842704200427C424443FFF044407C4",
6611957Sslatteng /* 12 */ "FFFF804080E0815080408080808081008600F800800080008000800080008000",
6711957Sslatteng /* 13 */ "00FF008100810081008100810E8106FF0A00100020000000F00090009000F000",
6811957Sslatteng /* 14 */ "FFFF8001A001900180018401820180018001804180218001800980058001FFFF",
6911957Sslatteng /* 15 */ "000000000000000030001C000B800460021804600B801C003000000000000000",
7011957Sslatteng /* 16 */ "00000000000000001C02220143018101808180C2804440380000000000000000",
7111957Sslatteng /* 17 */ "03C004200010001000100010002003C004000800080008000800042003C00000",
7211957Sslatteng /* 18 */ "0F0008C008200810081008100810082008C00F0008C008200820082008C00F00",
7311957Sslatteng /* 19 */ "00000000000000000000000000000000FFFFFFFF000000000000000000000000",
7411957Sslatteng /* 20 */ "00000000000000000000000000000000FFFF0000000000000000000000000000",
7511957Sslatteng /* 21 */ "00000000000000000000000000000000F87C0000000000000000000000000000",
7611957Sslatteng /* 22 */ "FFFF800180018041804180418041804187E1844184418441804180018001FFFF",
7711957Sslatteng /* 23 */ "FFFF80018001838184418821802180418181804180218821844183818001FFFF",
7811957Sslatteng /* 24 */ "80028002400440042008183007C001000280044008201EF00280028002800280",
7911957Sslatteng /* 25 */ "000400023FFF2002200420002000200020002000200020002000A80070002000",
8011957Sslatteng /* 26 */ "20042004FFFF2004200420042004200420042004200420042004FFFF20042004",
8111957Sslatteng /* 27 */ "FFFF9C39A245C183C183C183A2459C3981C18221841184118411822181C1FFFF",
8211957Sslatteng /* 28 */ "800140023FFC300C28142424224421842184224424242814300C3FFC40028001",
8311957Sslatteng /* 29 */ "000000000000000F00090009F04F902097F0F02F00490009000F000000000000",
8411957Sslatteng /* 30 */ "F00090009000F000080004000200014000C001C00000001E00120012001E0000",
8511957Sslatteng /* 31 */ "000007C0183020084004400480028002810280028002400440042008183007C0",
8611957Sslatteng /* 32 */ "02000100FF80018002400040002000200010001000082019400EFFFC40002000"
8711957Sslatteng };
8811957Sslatteng
8911957Sslatteng /* menu item color map */
9011957Sslatteng
9111957Sslatteng static int mencolor[menusize] = {
9211957Sslatteng 4, 1, 3, 1, 1, 6, 6, 1, 1, 5, 5, 5, 5, 3, 3, 3, 6, 5, 2, 1, 1, 6, 6, 1, 1, 1,
9311957Sslatteng 5, 5, 5, 5, 3, 3 };
9411957Sslatteng
9511957Sslatteng /* menu equivalent text commands */
9611957Sslatteng
9711957Sslatteng static char textcommand[menusize][maxchars] =
9811957Sslatteng {
9911957Sslatteng /* 1 */ ":f,2", /* font,2 */
10011957Sslatteng /* 2 */ ":f,1", /* font,1 */
10111957Sslatteng /* 3 */ ":br,3", /* brush,3 */
10211957Sslatteng /* 4 */ ":br,2", /* brush,2 */
10311957Sslatteng /* 5 */ ":br,1", /* brush,1 */
10411957Sslatteng /* 6 */ ":buf,2", /* set buffer 2 */
10511957Sslatteng /* 7 */ ":buf,1", /* set buffer 1 */
10611957Sslatteng /* 8 */ ":vadj", /* vertical adjust */
10711957Sslatteng /* 9 */ ":hadj", /* horizontal adjust */
10811957Sslatteng /* 10 */ ":mi", /* mirror */
10911957Sslatteng /* 11 */ "f", /* select area in current set */
11011957Sslatteng /* 12 */ "r", /* rotate current set */
11111957Sslatteng /* 13 */ "s", /* scale current set */
11211957Sslatteng /* 14 */ "x", /* rectangle from 2 points */
11311957Sslatteng /* 15 */ "w", /* arrow heads */
11411957Sslatteng /* 16 */ "b", /* draw curve */
11511957Sslatteng /* 17 */ ":f,4", /* font,4 */
11611957Sslatteng /* 18 */ ":f,3", /* font,3 */
11711957Sslatteng /* 19 */ ":br,6", /* brush,6 */
11811957Sslatteng /* 20 */ ":br,5", /* brush,5 */
11911957Sslatteng /* 21 */ ":br,4", /* brush,4 */
12011957Sslatteng /* 22 */ ":buf,4", /* set buffer 4 */
12111957Sslatteng /* 23 */ ":buf,3", /* set buffer 3 */
12211957Sslatteng /* 24 */ "g", /* gravity */
12311957Sslatteng /* 25 */ "z", /* manhattan adjust */
12411957Sslatteng /* 26 */ "q", /* grid */
12511957Sslatteng /* 27 */ "d", /* define current set */
12611957Sslatteng /* 28 */ "e", /* erase */
12711957Sslatteng /* 29 */ "c", /* copy current set */
12811957Sslatteng /* 30 */ "t", /* translate current set */
12911957Sslatteng /* 31 */ "a", /* draw arc */
13011957Sslatteng /* 32 */ "v", /* draw vector */
13111957Sslatteng };
13211957Sslatteng
13311957Sslatteng /* screen map for menu symbols */
13411957Sslatteng
13511957Sslatteng struct bounds
13611957Sslatteng {
13711957Sslatteng int lowx, lowy, hix, hiy;
13811957Sslatteng };
13911957Sslatteng
14011957Sslatteng static struct bounds area[menusize];
14111957Sslatteng
14211957Sslatteng /* Following is a map of brushes and mode made available to the
14311957Sslatteng * outside world for selection of these items for highlighting.
14411957Sslatteng * The numbers indicate the items location in the menu.
14511957Sslatteng */
14611957Sslatteng
14711957Sslatteng int HiMen[4] = { 6, 5, 22, 21 }; /* user symbols */
14811957Sslatteng int HiFont[4] = { 1, 0, 17, 16}; /* fonts */
14911957Sslatteng int HiBrush[6] = { 4, 3, 2, 20, 19, 18 }; /* brushes */
15011957Sslatteng int HiMode[4] = { 8, 7, 24, 23 }; /* horz, vert, man, grav. */
15111957Sslatteng
15211957Sslatteng static int xorig, yorig, deltax, deltay;
15311957Sslatteng static POINT bord1, bord2;
15411957Sslatteng
15511957Sslatteng /* forward references within this file */
15611957Sslatteng
15711957Sslatteng extern MNHighLt(), MNUnHighLt();
15811957Sslatteng /* variables to save previous command */
15911957Sslatteng
16011957Sslatteng static char *last;
16111957Sslatteng static lastint;
16211957Sslatteng
MNIcon()16311957Sslatteng MNIcon()
16411957Sslatteng /*
16511957Sslatteng * This routine initializatizes the menu symbols by defining to
16611957Sslatteng * the AED each menu symbol as a special font. The special fonts are
16711957Sslatteng * defined by a series of bytes in the array menu which is initialized.
16811957Sslatteng * they could also be read in from an external file.
16911957Sslatteng */
17011957Sslatteng
17111957Sslatteng {
17211957Sslatteng int i;
17311957Sslatteng
17411957Sslatteng #ifndef FASTIO
17511957Sslatteng char s1[3], s2[3], s3[3], s4[3];
17611957Sslatteng #else
17711957Sslatteng int c, k;
17811957Sslatteng #endif
17911957Sslatteng
18011957Sslatteng /* add code here to read in special fonts if
18111957Sslatteng desired. */
18211957Sslatteng
18311957Sslatteng for (i=1; i<=menusize; ++i)
18411957Sslatteng {
18511957Sslatteng putc('7',display); /* define special font */
18611957Sslatteng
18711957Sslatteng #ifndef FASTIO
18811957Sslatteng GRchex(i,s1,2);
18911957Sslatteng GRchex(itemxsize,s2,2);
19011957Sslatteng GRchex(itemysize,s3,2);
19111957Sslatteng GRchex(mencolor[i-1],s4,2);
19211957Sslatteng fprintf(display,"%s%s%s%s%s00",s1,s2,s3,s4,menu[i-1]);
19311957Sslatteng #else
19411957Sslatteng fprintf(display,"%c%c%c%c",i&0377, itemxsize&0377,
19511957Sslatteng itemysize&0377, mencolor[i-1]&0377);
19611957Sslatteng for (k=0; k<itemlength-1; k+=2)
19711957Sslatteng {
19811957Sslatteng (void) sscanf(&(menu[i-1][k]),"%2x",&c);
19911957Sslatteng putc(c&0377,display);
20011957Sslatteng }; /* end for k */
20111957Sslatteng putc('\0',display);
20211957Sslatteng #endif
20311957Sslatteng
20411957Sslatteng }; /* end for i */
20511957Sslatteng (void) fflush(display);
20611957Sslatteng }; /* end Icon */
20711957Sslatteng
208*11982Sslatteng
MNInitMenu(orientation)20911957Sslatteng MNInitMenu(orientation)
21011957Sslatteng int orientation; /* orientation of work space */
21111957Sslatteng /*
21211957Sslatteng * This routine initializatizes the spacing and orientation of
21311957Sslatteng * the menu so that elements can be properly displayed and selected.
21411957Sslatteng */
21511957Sslatteng
21611957Sslatteng {
21711957Sslatteng int xcum, ycum, i;
21811957Sslatteng
21911957Sslatteng last = textcommand[0];
22011957Sslatteng lastint = 0;
22111957Sslatteng
22211957Sslatteng if (orientation == horiz) /* set up spacing for menu display */
22311957Sslatteng {
22411957Sslatteng xorig = GrXMax - origin - menuspace;
22511957Sslatteng yorig = GrYMax - menuspace;
22611957Sslatteng deltax = -menuspace;
22711957Sslatteng deltay = 0;
22811957Sslatteng bord1.y = bord2.y = border;
22911957Sslatteng bord1.x = 0;
23011957Sslatteng bord2.x = GrXMax;
23111957Sslatteng }
23211957Sslatteng else
23311957Sslatteng {
23411957Sslatteng xorig = margin ;
23511957Sslatteng yorig = origin;
23611957Sslatteng deltax = 0;
23711957Sslatteng deltay = menuspace;
23811957Sslatteng bord1.x = bord2.x = GrXMax - border;
23911957Sslatteng bord1.y = 0;
24011957Sslatteng bord2.y = GrYMax;
24111957Sslatteng };
24211957Sslatteng xcum = xorig - (menuspace - itemxsize)/2;
24311957Sslatteng ycum = yorig - (menuspace - itemysize)/2;
24411957Sslatteng
24511957Sslatteng for (i=0; i<menusize; ++i) /* store boundaries for each menu item */
24611957Sslatteng {
24711957Sslatteng area[i].lowx = xcum;
24811957Sslatteng area[i].lowy = ycum;
24911957Sslatteng area[i].hix = xcum + menuspace;
25011957Sslatteng area[i].hiy = ycum + menuspace;
25111957Sslatteng xcum += deltax;
25211957Sslatteng ycum += deltay;
25311957Sslatteng if (((i+1)%(menusize/columns)) == 0) /* end of row/col */
25411957Sslatteng {
25511957Sslatteng xcum = xorig + deltay - (menuspace - itemxsize)/2;
25611957Sslatteng ycum = yorig + deltax - (menuspace - itemysize)/2;
25711957Sslatteng } /* end if */;
25811957Sslatteng } /* end for */;
25911957Sslatteng } /* end initmenu */
26011957Sslatteng
261*11982Sslatteng
MNDisplayMenu()26211957Sslatteng MNDisplayMenu()
26311957Sslatteng /*
26411957Sslatteng * This routine displays the menu defined by initmenu
26511957Sslatteng */
26611957Sslatteng
26711957Sslatteng {
26811957Sslatteng int i;
26911957Sslatteng
27011957Sslatteng #ifndef FASTIO
27111957Sslatteng char s1[3], s2[3], s3[3];
27211957Sslatteng #endif
27311957Sslatteng
27411957Sslatteng GRsetpos(xorig, yorig);
27511957Sslatteng putc('8',display); /* write special font */
27611957Sslatteng for (i=1; i<=menusize; ++i)
27711957Sslatteng {
27811957Sslatteng
27911957Sslatteng #ifndef FASTIO
28011957Sslatteng GRchex(i,s1,2);
28111957Sslatteng GRchex(deltax,s2,2);
28211957Sslatteng GRchex(deltay,s3,2);
28311957Sslatteng fprintf(display,"%s%s%s", s1, s2, s3);
28411957Sslatteng #else
28511957Sslatteng fprintf(display,"%c%c%c",i&0377, deltax&0377, deltay&0377);
28611957Sslatteng #endif
28711957Sslatteng (void) fflush(display);
28811957Sslatteng if ((i%(menusize/columns)) == 0) /* new row/col */
28911957Sslatteng {
29011957Sslatteng
29111957Sslatteng #ifndef FASTIO
29211957Sslatteng fputs("00",display);
29311957Sslatteng #else
29411957Sslatteng putc('\00',display);
29511957Sslatteng #endif
29611957Sslatteng
29711957Sslatteng GRsetpos(xorig+deltay, yorig+deltax); /* reposition */
29811957Sslatteng putc('8',display);
29911957Sslatteng } /* end if */;
30011957Sslatteng } /* end for */
30111957Sslatteng
30211957Sslatteng #ifndef FASTIO
30311957Sslatteng fputs("00",display);
30411957Sslatteng #else
30511957Sslatteng putc('\00',display);
30611957Sslatteng #endif
30711957Sslatteng
30811957Sslatteng GRsetwmask(linemask);
30911957Sslatteng GRVector(&bord1, &bord2, bordstyle);
31011957Sslatteng } /* end displaymenu */;
31111957Sslatteng
312*11982Sslatteng
MNFindMenuItem(x,y)31311957Sslatteng char *MNFindMenuItem(x,y)
31411957Sslatteng int x, y;
31511957Sslatteng /*
31611957Sslatteng * returns a pointer to the text string equivalent of the selected
31711957Sslatteng * menu item.
31811957Sslatteng */
31911957Sslatteng
32011957Sslatteng {
32111957Sslatteng int i;
32211957Sslatteng
32311957Sslatteng for (i=0; i<menusize; ++i)
32411957Sslatteng if (x < area[i].hix)
32511957Sslatteng if (y < area[i].hiy)
32611957Sslatteng if (x > area[i].lowx)
32711957Sslatteng if (y > area[i].lowy)
32811957Sslatteng {
32911957Sslatteng last = textcommand[i];
33011957Sslatteng lastint = i;
33111957Sslatteng return(textcommand[i]);
33211957Sslatteng } /* end, nested if */;
33311957Sslatteng
33411957Sslatteng return(last); /* cursor out of menu area */
33511957Sslatteng } /* end findmenuitem */
33611957Sslatteng
MNHighLt(sym,color)33711957Sslatteng MNHighLt(sym,color)
33811957Sslatteng int sym, color;
33911957Sslatteng /*
34011957Sslatteng * This routine highlights the specified menu item by drawing a
34111957Sslatteng * box around it in the highlighting color.
34211957Sslatteng */
34311957Sslatteng
34411957Sslatteng {
34511957Sslatteng POINT p1, p2, p3, p4;
34611957Sslatteng
34711957Sslatteng GRsetwmask(himask);
34811957Sslatteng p1.x = area[sym].lowx;
34911957Sslatteng p1.y = area[sym].lowy;
35011957Sslatteng p2.x = area[sym].lowx;
35111957Sslatteng p2.y = area[sym].hiy - 1;
35211957Sslatteng p3.x = area[sym].hix - 1;
35311957Sslatteng p3.y = area[sym].hiy - 1;
35411957Sslatteng p4.x = area[sym].hix - 1;
35511957Sslatteng p4.y = area[sym].lowy;
35611957Sslatteng GRVector(&p1, &p2, color);
35711957Sslatteng GRVector(&p2, &p3, color);
35811957Sslatteng GRVector(&p3, &p4, color);
35911957Sslatteng GRVector(&p4, &p1, color);
36011957Sslatteng } /* end MNHighLt */
36111957Sslatteng
MNUnHighLt(sym)36211957Sslatteng MNUnHighLt(sym)
36311957Sslatteng int sym;
36411957Sslatteng /*
36511957Sslatteng * This routine unhighlights the specified symbol by calling
36611957Sslatteng * MNHighLt with the erase color specified.
36711957Sslatteng */
36811957Sslatteng
36911957Sslatteng {
37011957Sslatteng MNHighLt(sym, eraseany);
37111957Sslatteng }
37211957Sslatteng
373*11982Sslatteng
MNInterpretCursor(button,cx,cy)37411957Sslatteng MNInterpretCursor(button, cx, cy)
37511957Sslatteng int cx, cy, button;
37611957Sslatteng /*
37711957Sslatteng * This routine interprets the cursor button function and calls
37811957Sslatteng * the appropriate command interpretation routines.
37911957Sslatteng */
38011957Sslatteng
38111957Sslatteng {
38211957Sslatteng char *cmd;
38311957Sslatteng
38411957Sslatteng PX = cx;
38511957Sslatteng PY = cy;
38611957Sslatteng if (button == 0)
38711957Sslatteng {
38811957Sslatteng cmd = MNFindMenuItem(cx, cy);
38911957Sslatteng if (*cmd == ':') LGCommand(++cmd);
39011957Sslatteng else SHCommand(cmd);
39111957Sslatteng }
39211957Sslatteng if (button == 1) LGDeletePoint(++cmd);
39311957Sslatteng if (button == 2) LGUndo(++cmd);
39411957Sslatteng if (button == 3)
39511957Sslatteng {
39611957Sslatteng LGPoint(++cmd);
39711957Sslatteng }
39811957Sslatteng }
399