home *** CD-ROM | disk | FTP | other *** search
- /* handle user`s input (PlotMap) */
-
- #include "PlotMap.h"
-
-
- #define MENU_PROJECT 0
- #define MENU_PREFERENCES 1
- #define MENU_COLORS 2
- #define MENU_MAPS 3
- #define MENU_EDIT 4
-
- #define ITEM_HELP 0
- #define ITEM_SAVE_MAP 2
- #define ITEM_SAVE_CONFIG 3
- #define ITEM_PRINT_MAP 5
- #define ITEM_ABOUT 7
- #define ITEM_QUIT 9
-
- #define ITEM_VFACTOR 0
- #define SUB_SET 0
- #define SUB_USE_DEFAULT 1
- #define ITEM_CLS_BEFORE_DRAW 2
- #define ITEM_COORD_WINDOW 4
- #define ITEM_COORD_MOUSEXY 5
- #define ITEM_COORD_DEGREE 6
- #define ITEM_PLOTMAP_MIN 8
- #define ITEM_PLOTMAP_MAX 13
- #define ITEM_DETAIL_LEVEL 15
-
- #define ITEM_PLANE 0
- #define SUB_FLAT 0
- #define SUB_MERCATOR 1
- #define ITEM_BOX 1
- #define SUB_BOX1 0
- #define SUB_BOX2 1
- #define SUB_BOX_ZOOM_IN 3
- #define SUB_BOX_ZOOM_OUT 4
- #define ITEM_SPHERE 2
- #define SUB_GLOBE 0
- #define SUB_ORBITAL 1
- #define SUB_SPHERE_ZOOM_IN 3
- #define SUB_SPHERE_ZOOM_OUT 4
- #define ITEM_REDRAW 4
-
- #define ITEM_PALETTE 0
- #define ITEM_BG_COLOR 2
- #define ITEM_OCEAN_COLOR 3
- #define ITEM_MAP_COLOR_MIN 5
- #define ITEM_MAP_COLOR_MAX 10
- #define ITEM_GRID_COLOR 12
- #define ITEM_GRIDHIGH_COLOR 13
- #define ITEM_SHADOW_COLOR 14
- #define ITEM_LINE_COLOR 16
- #define ITEM_BOX_COLOR 17
- #define ITEM_TEXT_COLOR 18
- #define ITEM_FLOOD_COLOR 19
-
- #define ITEM_CLEAR_SCREEN 0
- #define ITEM_FILL_OCEANS 1
- #define ITEM_GRID 2
- #define ITEM_SHADOW 3
- #define ITEM_TOGGLE_TITLE 4
- #define ITEM_DRAW_LINE 6
- #define ITEM_DRAW_BOX 7
- #define ITEM_DRAW_FILLEDBOX 8
- #define ITEM_TEXT 9
- #define ITEM_FLOOD_FILL 10
-
-
- #define SET_VFAC_STRING 1
- #define SET_VFAC_DEFAULT 2
- #define SET_VFAC_OK 3
- #define SET_VFAC_CANCEL 4
-
- /********** externals **********/
-
- extern struct config config;
- extern struct Menu *menu;
- extern struct Screen *screen;
- extern struct TextAttr myfont;
- extern struct RastPort *rp;
- extern APTR vinfo;
- extern BOOL ende;
- extern double act_vfactor, m_vfactor;
- extern UWORD old_maptype;
-
- extern void save_config(void);
- extern void draw_fullmap(UWORD), draw_boxmap(UWORD), draw_globemap(UWORD);
- extern void refresh_coord(WORD, WORD), set_coord_window_size(void);
- extern void open_coord_window(void), close_coord_window(void);
- extern void fill_oceans(void), draw_grid(void), draw_shadow(void);
- extern void draw_line(void), text(void), flood_fill(void);
- extern BOOL draw_box(BOOL, int);
-
- /********** Variablen, Daten **********/
-
- /* Data for about requester */
- static struct EasyStruct AboutES =
- {sizeof(struct EasyStruct), 0, "About...",
- "PlotMap V"VERSION" ("DATE")\n\
- (c) 1992 Thies Wellpott\n\
- This program is freely distributable\n\n\
- This program has been developed with\n\
- help of the source code of DrawMap 4.0\n\
- by Bryan Brown", "Ok"};
-
- struct Gadget *gad_list;
- struct Window *wd = NULL;
-
- /********** Routinen **********/
-
- BOOL open_window(int width, int height, UBYTE *title)
- /* => TRUE: all ok, => FALSE: error */
- {
- if (!(wd = OpenWindowTags(NULL,
- WA_Left,main_wd->MouseX - width/2,
- WA_Top,main_wd->MouseY,
- WA_CustomScreen,screen, WA_Title,title,
- WA_IDCMP, IDCMP_REFRESHWINDOW | IDCMP_VANILLAKEY |
- IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_MOUSEMOVE |
- IDCMP_ACTIVEWINDOW,
- WA_Flags, WFLG_SIMPLE_REFRESH | WFLG_RMBTRAP | WFLG_ACTIVATE |
- WFLG_DRAGBAR,
- WA_InnerWidth,width, WA_InnerHeight,height,
- WA_AutoAdjust,TRUE, WA_Gadgets, gad_list, TAG_DONE)))
- {
- FreeGadgets(gad_list);
- TITLE_ERROR("Can`t open window!");
- return(FALSE);
- }
-
- GT_RefreshWindow(wd, NULL);
- ClearMenuStrip(main_wd); /* clear menu strip, so user can`t select */
- IDCMP(0);
- return(TRUE);
- }
-
-
- void close_window(void)
- {
- if (wd)
- {
- CloseWindow(wd);
- wd = NULL;
- FreeGadgets(gad_list);
- IDCMP(NORMAL_IDCMP);
- SetMenuStrip(main_wd, menu); /* reattach menu */
- }
- }
-
-
- static void help(void)
- /* open window with help items */
- {
- }
-
-
- static void save_map(void)
- /* open file requester and save map as IFF-picture */
- {
- }
-
-
- static void print_map(void)
- /* print map via DUMP_RPORT */
- {
- }
-
-
- void set_vfac_menu(void)
- {
- ClearMenuStrip(main_wd);
-
- sprintf( ((struct IntuiText *)ItemAddress(menu,
- FULLMENUNUM(1,0,NOSUB))->ItemFill)->IText,
- "Vert. factor %3.2f", act_vfactor);
- sprintf( ((struct IntuiText *)ItemAddress(menu,
- FULLMENUNUM(1,0,1))->ItemFill)->IText,
- "Use default %3.2f", config.vfac);
-
- LayoutMenuItems(ItemAddress(menu, FULLMENUNUM(1,0,NOSUB)), vinfo,
- GTMN_Menu, menu, TAG_DONE);
- SetMenuStrip(main_wd, menu);
- m_vfactor = (double)(screen->Height) / 5.90 / act_vfactor;
- }
-
-
- static void set_vfac(void)
- /* open window; Use as default, Ok, Cancel */
- {
- struct NewGadget new_gad;
- struct Gadget *gad, *str_gad;
- int font_h, char_w;
- BOOL wd_ende = FALSE;
- char istr[5];
-
- font_h = myfont.ta_YSize;
- char_w = TextLength(rp, "M", 1);
- sprintf(istr, "%3.2f", act_vfactor);
-
- gad_list = NULL;
- gad = CreateContext(&gad_list);
-
- new_gad.ng_LeftEdge = screen->WBorLeft + 4 + 14*char_w;
- new_gad.ng_TopEdge = screen->WBorTop + myfont.ta_YSize + 3;
- new_gad.ng_Width = 5*char_w + 12;
- new_gad.ng_Height = font_h + 6;
- new_gad.ng_GadgetText = "_Vert. factor:";
- new_gad.ng_GadgetID = SET_VFAC_STRING;
- new_gad.ng_TextAttr = &myfont;
- new_gad.ng_Flags = PLACETEXT_LEFT;
- new_gad.ng_VisualInfo = vinfo;
- new_gad.ng_UserData = NULL;
- str_gad = gad = CreateGadget(STRING_KIND, gad, &new_gad,
- GT_Underscore,'_', GTST_String,istr, GTST_MaxChars,4,
- TAG_DONE);
-
- new_gad.ng_LeftEdge -= 14*char_w;
- new_gad.ng_TopEdge += font_h + 6 + INTERHEIGHT;
- new_gad.ng_Width = 14*char_w + 8;
- new_gad.ng_Height = font_h + 4;
- new_gad.ng_GadgetText = "Use as _default";
- new_gad.ng_GadgetID = SET_VFAC_DEFAULT;
- new_gad.ng_Flags = PLACETEXT_IN;
- gad = CreateGadget(BUTTON_KIND, gad, &new_gad,
- GT_Underscore,'_', TAG_DONE);
-
- new_gad.ng_LeftEdge += 14*char_w + 8 + INTERWIDTH;
- new_gad.ng_Width = 6*char_w + 8;
- new_gad.ng_GadgetText = "_Ok";
- new_gad.ng_GadgetID = SET_VFAC_OK;
- gad = CreateGadget(BUTTON_KIND, gad, &new_gad,
- GT_Underscore,'_', TAG_DONE);
-
- new_gad.ng_LeftEdge += 6*char_w + 8 + INTERWIDTH;
- new_gad.ng_GadgetText = "_Cancel";
- new_gad.ng_GadgetID = SET_VFAC_CANCEL;
- gad = CreateGadget(BUTTON_KIND, gad, &new_gad,
- GT_Underscore,'_', TAG_DONE);
-
- if (!gad)
- {
- FreeGadgets(gad_list);
- TITLE_ERROR("Can`t create gadgets!");
- return;
- }
-
- if (!open_window(26*char_w + 24 + 2 * INTERWIDTH + 8,
- 2*font_h + 10 + INTERHEIGHT + 4, "Set vert. factor"))
- return;
-
- while (!wd_ende)
- {
- struct IntuiMessage *msg;
- ULONG class;
- UWORD code;
- BOOL def_flag = FALSE, error = FALSE;
- int i;
- char *str = ((struct StringInfo *)str_gad->SpecialInfo)->Buffer;
-
- WaitPort(wd->UserPort);
- while (!wd_ende && (msg = GT_GetIMsg(wd->UserPort)))
- {
- class = msg->Class;
- code = msg->Code;
- gad = (struct Gadget *)msg->IAddress;
- GT_ReplyIMsg(msg);
-
- switch (class)
- {
- case IDCMP_ACTIVEWINDOW:
- ActivateGadget(str_gad, wd, NULL);
- break;
- case IDCMP_GADGETUP:
- switch (gad->GadgetID)
- {
- case SET_VFAC_STRING:
- error = FALSE;
- for (i = 0; i < strlen(str); i++)
- {
- if (i == 1)
- {
- if (str[i] != '.')
- error = TRUE;
- }
- else
- {
- if (str[i] < '0' || str[i] > '9')
- error = TRUE;
- }
- } /* for (i) */
- if (error)
- {
- DisplayBeep(NULL);
- SetWindowTitles(wd, "Wrong input!", (UBYTE *)-1);
- ActivateGadget(str_gad, wd, NULL);
- }
- else
- SetWindowTitles(wd, "Set vert. factor", (UBYTE *)-1);
- break;
- case SET_VFAC_DEFAULT:
- def_flag = TRUE;
- case SET_VFAC_OK:
- if (!error)
- act_vfactor = afp(str); /* FFP only! */
- if (def_flag)
- config.vfac = act_vfactor;
- wd_ende = TRUE;
- break;
- case SET_VFAC_CANCEL:
- wd_ende = TRUE;
- break;
- } /* switch (GadgetID) */
- break;
- case IDCMP_VANILLAKEY:
- switch (code)
- {
- case 'v':
- case 'V':
- ActivateGadget(str_gad, wd, NULL);
- break;
- case 'd':
- case 'D':
- def_flag = TRUE;
- case 'o':
- case 'O':
- if (!error)
- act_vfactor = afp(str);
- if (def_flag)
- config.vfac = act_vfactor;
- wd_ende = TRUE;
- break;
- case 'c':
- case 'C':
- wd_ende = TRUE;
- break;
- } /* switch (code) */
- break;
- case IDCMP_REFRESHWINDOW:
- GT_BeginRefresh(wd);
- GT_EndRefresh(wd, TRUE);
- break;
- } /* switch (class) */
- } /* while (GT_GetIMsg) */
- } /* while (!wd_ende) */
-
- close_window(); /* also frees gadgets */
- set_vfac_menu();
- }
-
-
- static void palette(void)
- {
- }
-
-
- static void redraw(void)
- /* redraw current map */
- {
- if (old_maptype != ~0)
- {
- if (old_maptype & MAP_PLANE)
- draw_fullmap(old_maptype & MAP_MASK);
- if (old_maptype & MAP_BOX)
- draw_boxmap(old_maptype & MAP_MASK);
- if (old_maptype & MAP_SPHERE)
- draw_globemap(old_maptype & MAP_MASK);
- }
- else
- TITLE_ERROR("Can`t redraw: no previous map drawn!");
- }
-
-
- void handleIDCMP(void)
- {
- struct IntuiMessage *msg;
- ULONG class;
- UWORD code, menunum, itemnum, subnum;
- WORD mx,my, oldx=-1,oldy=-1;
- struct MenuItem *item;
-
- /* IMPORTANT!!! FIRST check for end, THEN get message, otherwise you get
- * a message but WILL NOT reply it (because while loop will be broken if
- * flag ende is set) !! */
- while (!ende && (msg = (struct IntuiMessage *)GetMsg(main_wd->UserPort)))
- {
- class = msg->Class;
- code = msg->Code;
- mx = msg->MouseX;
- my = msg->MouseY;
- ReplyMsg((struct Message *)msg);
-
- switch (class)
- {
- case IDCMP_INTUITICKS:
- if ((oldx != mx) || (oldy != my)) /* avoid flicker */
- {
- refresh_coord(mx,my);
- oldx = mx;
- oldy = my;
- }
- break;
- case IDCMP_MENUPICK:
- TITLE_NORMAL;
- while (code != MENUNULL)
- {
- menunum = MENUNUM(code);
- itemnum = ITEMNUM(code);
- subnum = SUBNUM(code);
- item = ItemAddress(menu, code); /* get item address */
-
- switch (menunum)
- {
- case MENU_PROJECT:
- switch (itemnum)
- {
- case ITEM_HELP:
- help();
- break;
- case ITEM_SAVE_MAP:
- save_map();
- break;
- case ITEM_SAVE_CONFIG:
- save_config();
- break;
- case ITEM_PRINT_MAP:
- print_map();
- break;
- case ITEM_ABOUT:
- EasyRequest(main_wd, &AboutES, NULL, NULL);
- break;
- case ITEM_QUIT:
- ende = TRUE;
- break;
- } /* switch (itemnum) */
- break;
- case MENU_PREFERENCES:
- switch (itemnum)
- {
- case ITEM_VFACTOR:
- switch (subnum)
- {
- case SUB_SET:
- set_vfac();
- break;
- case SUB_USE_DEFAULT:
- act_vfactor = config.vfac;
- set_vfac_menu();
- break;
- } /* switch (subnum) */
- break;
- case ITEM_CLS_BEFORE_DRAW:
- config.cls_before_draw ^= TRUE;
- break;
- case ITEM_COORD_WINDOW:
- if (item->Flags & CHECKED)
- {
- open_coord_window();
- config.coord_window = TRUE;
- }
- else
- {
- close_coord_window();
- config.coord_window = FALSE;
- }
- break;
- case ITEM_COORD_MOUSEXY:
- config.coord_mousexy ^= TRUE;
- set_coord_window_size();
- break;
- case ITEM_COORD_DEGREE:
- config.coord_degree ^= TRUE;
- set_coord_window_size();
- break;
- case ITEM_PLOTMAP_MIN+0:
- case ITEM_PLOTMAP_MIN+1:
- case ITEM_PLOTMAP_MIN+2:
- case ITEM_PLOTMAP_MIN+3:
- case ITEM_PLOTMAP_MIN+4:
- case ITEM_PLOTMAP_MIN+5:
- config.plotmap[itemnum - ITEM_PLOTMAP_MIN] ^= TRUE;
- break;
- case ITEM_DETAIL_LEVEL:
- config.detail_level = subnum + 1;
- break;
- } /* switch (itemnum) */
- break;
- case MENU_COLORS:
- switch (itemnum)
- {
- case ITEM_PALETTE:
- palette();
- break;
- case ITEM_BG_COLOR:
- config.bg_color = subnum;
- break;
- case ITEM_OCEAN_COLOR:
- config.ocean_color = subnum;
- break;
- case ITEM_MAP_COLOR_MIN+0:
- case ITEM_MAP_COLOR_MIN+1:
- case ITEM_MAP_COLOR_MIN+2:
- case ITEM_MAP_COLOR_MIN+3:
- case ITEM_MAP_COLOR_MIN+4:
- case ITEM_MAP_COLOR_MIN+5:
- config.mapcolor[itemnum-ITEM_MAP_COLOR_MIN] = subnum;
- break;
- case ITEM_GRID_COLOR:
- config.grid_color = subnum;
- break;
- case ITEM_GRIDHIGH_COLOR:
- config.gridhigh_color = subnum;
- break;
- case ITEM_SHADOW_COLOR:
- config.shadow_color = subnum;
- break;
- case ITEM_LINE_COLOR:
- config.line_color = subnum;
- break;
- case ITEM_BOX_COLOR:
- config.box_color = subnum;
- break;
- case ITEM_TEXT_COLOR:
- config.text_color = subnum;
- break;
- case ITEM_FLOOD_COLOR:
- config.flood_color = subnum;
- break;
- } /* switch (itemnum) */
- break;
- case MENU_MAPS:
- switch (itemnum)
- {
- case ITEM_PLANE:
- switch (subnum)
- {
- case SUB_FLAT:
- draw_fullmap(MAP_FLAT);
- break;
- case SUB_MERCATOR:
- draw_fullmap(MAP_MERCATOR);
- break;
- } /* switch (subnum) */
- break;
- case ITEM_BOX:
- if (old_maptype & (MAP_PLANE | MAP_BOX))
- {
- switch (subnum)
- {
- case SUB_BOX1:
- if (draw_box(FALSE, 1))
- draw_boxmap(old_maptype & MAP_MASK);
- break;
- case SUB_BOX2:
- if (draw_box(FALSE, 2))
- draw_boxmap(old_maptype & MAP_MASK);
- break;
- case SUB_BOX_ZOOM_IN:
- if (old_maptype & MAP_BOX)
- {
- }
- break;
- case SUB_BOX_ZOOM_OUT:
- if (old_maptype & MAP_BOX)
- {
- }
- break;
- } /* switch (subnum) */
- } /* if (MAP_PLANE | MAP_BOX) */
- break;
- case ITEM_SPHERE:
- switch (subnum)
- {
- case SUB_GLOBE:
- draw_globemap(MAP_GLOBE);
- break;
- case SUB_ORBITAL:
- draw_globemap(MAP_ORBITAL);
- break;
- case SUB_SPHERE_ZOOM_IN:
- if (old_maptype & MAP_SPHERE)
- {
- }
- break;
- case SUB_SPHERE_ZOOM_OUT:
- if (old_maptype & MAP_SPHERE)
- {
- }
- break;
- } /* switch (subnum) */
- break;
- case ITEM_REDRAW:
- redraw();
- break;
- } /* switch (itemnum) */
- break;
- case MENU_EDIT:
- switch (itemnum)
- {
- case ITEM_CLEAR_SCREEN:
- SetRast(rp, config.bg_color);
- break;
- case ITEM_FILL_OCEANS:
- fill_oceans();
- break;
- case ITEM_GRID:
- draw_grid();
- break;
- case ITEM_SHADOW:
- draw_shadow();
- break;
- case ITEM_TOGGLE_TITLE:
- ShowTitle(screen, !(screen->Flags & SHOWTITLE));
- break;
- case ITEM_DRAW_LINE:
- draw_line();
- break;
- case ITEM_DRAW_BOX:
- draw_box(FALSE, 0);
- break;
- case ITEM_DRAW_FILLEDBOX:
- draw_box(TRUE, 0);
- break;
- case ITEM_TEXT:
- text();
- break;
- case ITEM_FLOOD_FILL:
- flood_fill();
- break;
- } /* switch (itemnum) */
- break;
- } /* switch (menunum) */
-
- if ((item->NextSelect != code) && (MENUNUM(item->NextSelect) < 5))
- code = item->NextSelect; /* get next selected item */
- else /* only if different! */
- code = MENUNULL;
- } /* while (code != MENUNULL) */
- break;
- } /* switch (class) */
- } /* while (GetMsg()) */
- }
-
-