home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff214.lzh / MandelVroom / src / menu.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  11KB  |  542 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents: this file contains functions to decode Intuition Menu messages.
  25.  */
  26.  
  27. #include "mandp.h"
  28.  
  29. extern struct NewScreen NewScreen;
  30.  
  31. extern int Num_vp_Colors;
  32.  
  33. char File[80] = "", Path[80] = "Mandelbrot:PROJECTS";
  34.  
  35. HandleMenuPick( Msg )
  36.   register struct IntuiMessage *Msg;
  37. {
  38.   register struct MenuItem *Item;
  39.   register USHORT code = Msg->Code;
  40.  
  41.   if (code == MENUNULL) {
  42.     return;
  43.   }
  44.  
  45.   if (State == HELPSTATE) {
  46.     HelpMenuCmd(Msg);
  47.     State = IDLESTATE;
  48.     return;
  49.   } else {
  50.     State = IDLESTATE;
  51.   }
  52.  
  53.   while (code != MENUNULL) {
  54.  
  55.     switch ( MENUNUM( code ) ) {
  56.  
  57.       case PROJECTMENU:
  58.            ProjectMenu( Msg, code );
  59.            break;
  60.  
  61.       case DISPLAYMENU:
  62.            DisplayMenu( Msg, code );
  63.            break;
  64.  
  65.       case CALCULATEMENU:
  66.            CalculateMenu( Msg, code );
  67.            break;
  68.  
  69.       case SPECIALMENU:
  70.            SpecialMenu( Msg, code );
  71.            break;
  72.     }
  73.     Item = ItemAddress( (struct Menu *) &Menu[0], (long) code);
  74.     code = Item->NextSelect;
  75.   }
  76.   MaybeNewScreen();
  77. }
  78.  
  79. /*
  80.  * Decide what to do for Project menu's Items
  81.  */
  82. ProjectMenu(Msg,code)
  83.   struct IntuiMessage *Msg;
  84.   USHORT code;
  85. {
  86.   char Name[160];
  87.   char *p;
  88.  
  89.   register struct Picture *Pict = CurPict;
  90.   register struct Picture *LoadPict;
  91.   register struct Window  *Window;
  92.   register SHORT  Type;
  93.  
  94.   struct Picture *NewPict();
  95.  
  96.   if (Pict) {
  97.     Window = Pict->Window;
  98.   } else {
  99.     Window = BackWind;
  100.   }
  101.  
  102.   switch (ITEMNUM(code)) {
  103.  
  104.     case NEWITEM:
  105.  
  106.          switch( SUBNUM(code) ) {
  107.  
  108.            case 0:
  109.                 Type = MANDPICT;
  110.                 break;
  111.  
  112.            case 1:
  113.                 Type = JULIAPICT;
  114.                 break;
  115.          }
  116.  
  117.          if ( Pict )
  118.            ClonePict( Pict, Type );
  119.          else
  120.            NewPreset( -1, Type );
  121.          break;
  122.  
  123.     case CURITEM:
  124.          MakeCurProj( (struct Picture *) Msg->IDCMPWindow->UserData );
  125.          break;
  126.  
  127.     case CLOSEPROJ:
  128.          CloseWinds( CurPict->Window );
  129.          break;
  130.  
  131.     case HELPITEM:
  132.          SetWithPointer();
  133.          State = HELPSTATE;
  134.          break;
  135.  
  136.     case SAVEPROJ:
  137.          strcpy( File, Pict->Title+2 );
  138.  
  139.     case LOADITEM:
  140.     case SAVEILBM:
  141.  
  142.          switch( ITEMNUM(code) ) {
  143.            case  LOADITEM: p = "Load Project"; break;
  144.            case  SAVEPROJ: p = "Save Project"; break;
  145.            case  SAVEILBM: p = "Save ILBM";    break;
  146.          }
  147.  
  148.          if (get_fname(BackWind, screen, p, File, Path)) {
  149.  
  150.            SetSleepyPointer();
  151.  
  152.            strcpy(Name,Path);
  153.            if (Name[0] != '\0' && Name[strlen(Name)-1] != ':') {
  154.              strcat(Name,"/");
  155.            }
  156.            strcat(Name,File);
  157.  
  158.            switch( ITEMNUM(code) ) {
  159.  
  160.              case  LOADITEM:
  161.                    (void) LoadPicture( Name );
  162.                    RefreshContours();
  163.  
  164.                    RefreshContours();
  165.                    CalcHist(CurPict);
  166.                    ShowStats(CurPict);
  167.                    SetDirGadget(CurPict);
  168.                    ModifySpeedPot();
  169.                    break;
  170.  
  171.              case  SAVEPROJ:
  172.  
  173.                    PauseChild( Pict );
  174.  
  175.                    strncpy( Pict->Title+2, File, sizeof(Pict->Title)-3);
  176.                    (void) SaveCounts(Name,Pict);
  177.  
  178.                    AwakenChild( Pict );
  179.                    break;
  180.  
  181.              case  SAVEILBM:
  182.                    SaveILBM(Name, Pict->Crngs, 4);
  183.                    break;
  184.            }
  185.            SetNormPointer();
  186.          }
  187.  
  188.     case CANCELITEM:
  189.          State = IDLESTATE;
  190.          break;
  191.  
  192.     case QUITITEM:
  193.          if (DispErrMsg("Really quit?",1)) {
  194.  
  195.            QuitScreen = TRUE;
  196.          }
  197.     }
  198. } /* ProjectMenu */
  199.  
  200. /*
  201.  * Decide what to do for Display menu's Items
  202.  */
  203. DisplayMenu(Msg,code)
  204.   struct IntuiMessage *Msg;
  205.   USHORT code;
  206. {
  207.   double gapy,gapx;
  208.   extern UBYTE  ScreenSizeChanged;
  209.   extern UBYTE  StandardSize;
  210.   extern UBYTE  NewDepth;
  211.   extern USHORT NewViewModes;
  212.   extern struct MenuItem ScreenSizeSubs[];
  213.   extern struct MenuItem BorderSubs[];
  214.  
  215.   switch (ITEMNUM(code)) {
  216.  
  217.     case COLORITEM:
  218.          OpenPalWind();
  219.          break;
  220.  
  221.     case CYCLEITEM:
  222.          OpenCycWind();
  223.          break;
  224.  
  225.     case CONTOURITEM:
  226.          OpenContWind();
  227.          break;
  228.  
  229.     case HISTOGRAMITEM:
  230.          OpenHistWind();
  231.          break;
  232.  
  233.     case AUTOCNTRITEM:
  234.          AutoContour(CurPict,SUBNUM(code));
  235.          break;
  236.  
  237.     case DEPTHITEM:
  238.          NewDepth = SUBNUM(code) + 1;
  239.  
  240.          if (CurPict)
  241.            CurPict->Depth = NewDepth;
  242.          break;
  243.  
  244.     case VIEWMODEITEM:
  245.          EditScreenViewModes(code);
  246.  
  247.          if (CurPict) {
  248.            CurPict->ViewModes = NewViewModes;
  249.            if (NewViewModes & HIRES && CurPict->Depth > 4) {
  250.              CurPict->Depth = 4;
  251.            }
  252.          }
  253.          break;
  254.  
  255.     case SCREENITEM:
  256.          StandardSize = (ScreenSizeSubs[0].Flags & CHECKED) == CHECKED;
  257.          ScreenSizeChanged = 1;
  258.          break;
  259.  
  260.     case BORDERITEM:
  261.          if (CurPict) {
  262.            int Changed;
  263.  
  264.            Changed = 0;
  265.  
  266.            if ((BorderSubs[0].Flags & CHECKED) == CHECKED) {
  267.  
  268.              /* Make it bordered */
  269.  
  270.              if (CurPict->Flags & BORDERLESS_PROJ &&
  271.                  CurPict->CountX+LEFTMARG+RIGHTMARG <= screen->Width &&
  272.                  CurPict->CountY+TOPMARG+BOTMARG    <= screen->Height) {
  273.  
  274.                CurPict->Flags &= ~BORDERLESS_PROJ;
  275.                Changed = 1;
  276.              }
  277.            } else {
  278.  
  279.              if (!(CurPict->Flags & BORDERLESS_PROJ)) {
  280.                CurPict->Flags |=  BORDERLESS_PROJ;
  281.                Changed = 1;
  282.              }
  283.            }
  284.  
  285.            InitBorderSubs();
  286.  
  287.            if (Changed) {
  288.  
  289.              if ( CurPict->cTask ) {
  290.  
  291.                KillReColor( CurPict );
  292.              }
  293.  
  294.              PauseChild( CurPict );
  295.  
  296.              ClosePicture(CurPict);
  297.              OpenPicture(CurPict);
  298.  
  299.              if (CurPict->Counts)
  300.                ReColor(CurPict);
  301.  
  302.              AwakenChild(CurPict);
  303.            }
  304.          }
  305.          break;
  306.     }
  307. } /* DisplayMenu */
  308.  
  309. /*
  310.  * Decide what to do for Calculate Menu's Items
  311.  */
  312. CalculateMenu(Msg,code)
  313.   struct IntuiMessage *Msg;
  314.   USHORT code;
  315. {
  316.   extern struct Picture *ZoomedPict;
  317.   extern struct MenuItem LensSub[];
  318.  
  319.   double gapy,gapx;
  320.   LONG   Temp;
  321.   extern UBYTE  LensOn;
  322.  
  323.   switch (ITEMNUM(code)) {
  324.  
  325.     case GENERATORITEM:   /* generator type */
  326.          if (CurPict)
  327.            CurPict->MathMode = SUBNUM(code);
  328.          break;
  329.  
  330.     case ZOOMITEM:
  331.          CurPict->ZoomType = SUBNUM(code);
  332.          DoZoom( Msg );
  333.          break;
  334.  
  335.     case SCROLLITEM:
  336.          ScrollPictCmd(Msg);
  337.          break;
  338.  
  339.     case LENSITEM:
  340.          LensOn = (LensSub[0].Flags & CHECKED) == CHECKED;
  341.          break;
  342.  
  343.     case GENERATEITEM:
  344.          GenerateCmd(Msg);
  345.          break;
  346.  
  347.     case COUNTITEM:
  348.  
  349.          Temp = CurPict->MaxIteration;
  350.  
  351.          if ( GetInt( "Max Iteration", &Temp) == 1 ) {
  352.  
  353.            if (Temp > 1023) Temp = 1023;
  354.  
  355.            CurPict->MaxIteration = Temp;
  356.          }
  357.          break;
  358.  
  359.     case STATSITEM:
  360.  
  361. #ifndef DEVELOPMENT
  362.  
  363.          OpenStatsWind( CurPict );
  364. #else
  365.          { char Name[80];
  366.            char VD0[80];
  367.  
  368.            strcpy( VD0, "ram:");
  369.  
  370.            if (get_fname(BackWind, screen, "Preset", File, VD0)) {
  371.  
  372.              strcpy(Name,VD0);
  373.  
  374.              if (Name[strlen(Name)-1] != ':') {
  375.                strcat(Name,"/");
  376.              }
  377.              strcat(Name,File);
  378.  
  379.              SavePreset( Name, CurPict );
  380.            }
  381.          }
  382. #endif
  383.          break;
  384.   }
  385. } /* CalculateMenu */
  386.  
  387. DoZoom( Msg )
  388.   struct IntuiMessage *Msg;
  389. {
  390.   register struct Picture *Pict = CurPict;
  391.  
  392.   if (Pict == NULL)
  393.     return;
  394.  
  395.   CloseZoomBox( Pict );
  396.  
  397.   ZoomedPict = Pict;   /* Save this so we can use it later */
  398.  
  399.   switch ( SUBNUM(Msg->Code)) {
  400.  
  401.     case ZOOMIN:
  402.          ZoomInCmd(Msg);
  403.          break;
  404.  
  405.     case ZOOMOUT:
  406.          ZoomOutCmd(Msg);
  407.          break;
  408.  
  409.     case ZOOMOFF:
  410.          ClearZoomBox( ZoomedPict );
  411.          break;
  412.  
  413.     case ZOOMJULIA:
  414.          SetJuliaCmd(Msg);
  415.          break;
  416.   }
  417. }
  418.  
  419. USHORT NewViewModes;
  420. UBYTE  NewDepth = 5;
  421.  
  422. /*
  423.  * Modify the NewScreens ViewModes to match the menu
  424.  */
  425. EditScreenViewModes(code)
  426.   USHORT code;
  427. {
  428.   switch (SUBNUM(code))
  429.     {
  430.     case HIRESSUB:
  431.          NewViewModes ^= HIRES;
  432.          break;
  433.  
  434.     case INTERLACESUB:
  435.          NewViewModes ^= INTERLACE;
  436.          break;
  437.  
  438.     case HALFBRITESUB:
  439.          NewViewModes ^= EXTRA_HALFBRITE;
  440.          break;
  441.     }
  442. } /* EditScreenViewMode */
  443.  
  444. /*
  445.  * Decide what to do for Special Menu's Items
  446.  */
  447. SpecialMenu(Msg, code)
  448.   struct IntuiMessage *Msg;
  449.   USHORT code;
  450. {
  451.   extern SHORT MaxOrbit;
  452.  
  453.   LONG   Temp;
  454.   int    rc;
  455.  
  456.   rc = SUCCESSFUL;
  457.  
  458.   switch (ITEMNUM(code)) {
  459.  
  460.     case ORBITITEM:
  461.          OpenOrbitWind();
  462.          break;
  463.  
  464.     case MAXORBITEM:
  465.          Temp = MaxOrbit;
  466.  
  467.          if ( GetInt( "Max Iteration", &Temp) == 1 ) {
  468.  
  469.            if (Temp > 1023) Temp = 1023;
  470.  
  471.            MaxOrbit = Temp;
  472.          }
  473.          break;
  474.  
  475.     case ORBITMATHITEM:
  476.          ConfOrbMode( SUBNUM(code) );
  477.          break;
  478.  
  479.     case PRESETITEM:
  480.          rc = SetPreset( SUBNUM( code ) );
  481.  
  482.          if (rc == UNSUCCESSFUL)
  483.            DispErrMsg("Can't open preset. Out of RAM",0);
  484.          else
  485.          if (CurPict->Flags & NO_RAM_GENERATE)
  486.            rc = UNSUCCESSFUL;
  487.  
  488.          RefreshContours();
  489.   }
  490.   return( rc );
  491. } /* SpecialMenu */
  492.  
  493. LoadPicture( Name )
  494.   char Name[];
  495. {
  496.   struct Picture *LoadPict;
  497.  
  498.   LoadPict = NewPict( MANDPICT );
  499.  
  500.   if ( LoadPict ) {
  501.     if ( LoadCounts( Name, LoadPict ) == UNSUCCESSFUL ) {
  502.  
  503.       ThrowPict( LoadPict );
  504.       GetCurPict();
  505.       return(UNSUCCESSFUL);
  506.  
  507.     }
  508.   } else {
  509.     ErrNoPict();
  510.     return(UNSUCCESSFUL);
  511.   }
  512.   return(SUCCESSFUL);
  513. }
  514.  
  515. char *
  516. ExtractName( FullPath )
  517.   char *FullPath;
  518. {
  519.   char *File,*rindex(),*p;
  520.  
  521.   File = rindex( FullPath, '/' );
  522.  
  523.   if (File == NULL)
  524.  
  525.     File = rindex( FullPath, ':' );
  526.  
  527.   if (File)
  528.     File += 1;
  529.  
  530.   /* Save a copy of it */
  531.  
  532.   strcpy( Path, FullPath );
  533.  
  534.   p = &Path[ File - FullPath - 1 ];
  535.  
  536.   if (*p == '/') *p = '\0';
  537.   if (*p == ':') *(p+1) = '\0';
  538.  
  539.   return( File );
  540. }
  541.  
  542.