/************************************************************************
*  Version 3.00  MANDELBROT - Self-Squared Dragon Generator  29-May-86  *
*  Commodore Amiga                 Menus                       MAND2.C  *
*************************************************************************
*         Copyright (c) 1986, Robert S. French and R. J. Mical          *
* --------------------------------------------------------------------- *
*  This program has been placed in the public domain.  A limited        *
*  license is hereby granted for the unlimited use and distribution of  *
*  this program, provided it is not used for commercial or profit-      *
*  making purposes.  Thank you.                                         *
*************************************************************************
*  Author information:            | Name:   R. J. Mical                 *
*                                 | USnail: Commodore-Amiga, Inc.       *
*  Name:   Robert S. French       |         983 University Avenue       *
*  USnail: 2740 Frankfort Avenue  |         Los Gatos, CA  95030        *
*          Louisville, KY  40206  \-------------------------------------*
*  Phone:  (502) 897-5096              UUCP: ihnp4!ptsfa!well!french    *
*  ARPA:   French#Robert%d@LLL-MFE or RFrench@MIT-MULTICS               *
*************************************************************************
*  Please send any comments, suggestions, or bugs to one of the above   *
*  addresses.                                                           *
************************************************************************/
 
#include "mand.h" 
#include "globals.h"

struct IntuiText ProjectText[PROJECT_COUNT],
                 OptionsText[OPTIONS_COUNT],
                 ZoomText[ZOOM_COUNT],
                 OptionsAnalText[OPTIONS_ANAL_COUNT],
                 Options3DText[OPTIONS_3D_COUNT];

struct MenuItem ProjectItems[PROJECT_COUNT],
                OptionsItems[OPTIONS_COUNT],
                ZoomItems[ZOOM_COUNT],
                OptionsAnalItems[OPTIONS_ANAL_COUNT],
                Options3DItems[OPTIONS_3D_COUNT];

struct item {
   char *name;
   char cmd;
};

struct item i_project[] = {
   { "Save Picture", 'S' },
   { "???? Title Bar", NULL },
   { "Print", NULL },
   { NULL, NULL }
};

struct item i_options[] = {
   { "1/16 size display", 'Q' },
   { "Full size display", 'F' },
   { "Display 2-D", 'R' },
   { "Display 3-D", NULL },
   { "Regenerate", 'G' },
   { "Modify colors", NULL },
   { "Analyze", NULL },
   { "Stop drawing", NULL },
   { "Close display", 'C' },
   { NULL, NULL }
};

struct item i_zoom[] = {
   { "Set Zoom Frame Center", NULL },
   { "Set Zoom Frame Size", NULL },
   { "Set Zoom Frame Proportional", NULL },
   { "Zoom to Current Frame", NULL },
   { "Zoom In x 10", NULL },
   { "Zoom Out x 2", NULL },
   { "Zoom Out x 10", NULL },
   { NULL, NULL }
};

struct item i_options_anal[] = {
   { "Lines", 'L' },
   { "Dots", 'D' },
   { NULL, NULL }
};

struct item i_options_3d[] = {
   { "No scaling", NULL },
   { "Divide by 2", NULL },
   { "Divide by 5", NULL },
   { "Divide by 10", NULL },
   { "Divide by 15", NULL },
   { NULL, NULL }
};

struct Menu MainMenu[MENU_COUNT] = {
   { MainMenu+1, 5, 0, 70, 8, MENUENABLED, "Project", ProjectItems,
     0, 0, 0, 0},
   { MainMenu+2, 75, 0, 70, 8, MENUENABLED, "Display", OptionsItems,
     0, 0, 0, 0},
   { NULL, 145, 0, 70, 8, MENUENABLED, "Zoom", ZoomItems,
     0, 0, 0, 0}
};


init_menus()
{
   create_menu(PROJECT_LEFT,PROJECT_WIDTH,ProjectText,ProjectItems,i_project,0,0);
   create_menu(OPTIONS_LEFT,OPTIONS_WIDTH,OptionsText,OptionsItems,i_options,0,0);
   create_menu(ZOOM_LEFT,ZOOM_WIDTH,ZoomText,ZoomItems,i_zoom,0,0);
   create_menu(OPTIONS_ANAL_LEFT,OPTIONS_ANAL_WIDTH,OptionsAnalText,
               OptionsAnalItems,i_options_anal,OptionsItems,OPTIONS_ANAL);
   create_menu(OPTIONS_3D_LEFT,OPTIONS_3D_WIDTH,Options3DText,
               Options3DItems,i_options_3d,OptionsItems,OPTIONS_3D);
}

create_menu(left,width,text,items,itemlist,submenu_item,submenu_element)
int left,width,submenu_element;
struct IntuiText *text;
struct MenuItem *items,*submenu_item;
struct item *itemlist;
{
   int i;

   i=0;

   if (submenu_item)
      submenu_item[submenu_element].SubItem = items;

   while (itemlist[i].name) {

      if (i)
         items[i-1].NextItem = items+i;

      text[i].FrontPen = 0;
      text[i].BackPen = 1;
      text[i].DrawMode = JAM2;
      text[i].LeftEdge = 1;
      text[i].TopEdge = 1;
      text[i].ITextFont = NULL;
      text[i].IText = itemlist[i].name;
      text[i].NextText = NULL;

      items[i].LeftEdge = left;
      items[i].TopEdge = i * ITEM_HEIGHT + ((submenu_item) ? ITEM_HEIGHT/2 : 0);
      items[i].Width = width;
      items[i].Height = ITEM_HEIGHT;
      items[i].Flags = ITEMTEXT | HIGHBOX;
      items[i].MutualExclude = NULL;
      items[i].ItemFill = (APTR) (text+i);
      items[i].Command = NULL;
      if (itemlist[i].cmd) {
         items[i].Flags |= COMMSEQ;
         items[i].Command = itemlist[i].cmd;
      }
      items[i].SubItem = NULL;
      items[i].NextSelect = NULL;

      i++;
   }
}

enable_all()
{
   int i;

   for (i=0;i<PROJECT_COUNT;i++)
      ProjectItems[i].Flags |= ITEMENABLED;
   for (i=0;i<OPTIONS_COUNT;i++)
      OptionsItems[i].Flags |= ITEMENABLED;
   for (i=0;i<ZOOM_COUNT;i++)
      ZoomItems[i].Flags |= ITEMENABLED;
   for (i=0;i<OPTIONS_ANAL_COUNT;i++)
      OptionsAnalItems[i].Flags |= ITEMENABLED;
   for (i=0;i<OPTIONS_3D_COUNT;i++)
      Options3DItems[i].Flags |= ITEMENABLED;
}

disable_some(menu1,menu2,menu3)
unsigned int menu1,menu2,menu3;
{
   int i;

   for (i=0;i<PROJECT_COUNT;i++)
      if (menu1 & (1 << i))
         ProjectItems[i].Flags &= ~ITEMENABLED;

   for (i=0;i<OPTIONS_COUNT;i++)
      if (menu2 & (1 << i))
         OptionsItems[i].Flags &= ~ITEMENABLED;

   for (i=0;i<ZOOM_COUNT;i++)
      if (menu3 & (1 << i))
         ZoomItems[i].Flags &= ~ITEMENABLED;
}

reset_menus()
{
   enable_all();
   disable_some(0,1<<OPTIONS_STOP,0);
   if (!(color_mode & NOT_HOLDANDMODIFY))
      disable_some(1<<PROJECT_SAVEPICTURE,
                  (1<<OPTIONS_ANAL)|(1<<OPTIONS_COLORS)|(1<<OPTIONS_3D),
                   ~0);
   if (v_fp == NULL)
      disable_some(0,(1<<OPTIONS_REDRAW)|(1<<OPTIONS_3D)|(1<<OPTIONS_ANAL),
                   0);
   if (threed_stat)
      disable_some(0,(1<<OPTIONS_ANAL),~0);
   reset_title();
   SetMenuStrip(w,MainMenu);
}

reset_draw()
{
   enable_all();
   disable_some(~(1<<PROJECT_TITLE),
                ~((1<<OPTIONS_STOP)|(1<<OPTIONS_CLOSE)),~0);
   reset_title();
   SetMenuStrip(w,MainMenu);
}

/* This is perhaps a little kludgy... */

reset_title()
{
   if (title_displayed)
      ProjectText[PROJECT_TITLE].IText = "Hide Title Bar";
   else
      ProjectText[PROJECT_TITLE].IText = "Show Title Bar";
}

/*
reset_print()
{
   enable_all();
   disable_some(~(1<<PROJECT_PRINT),~0,~0);
   ProjectText[PROJECT_PRINT].IText = "Stop print";
}

done_print()
{
   ProjectText[PROJECT_PRINT].IText = "Print";
}
*/
