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 / nav.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  18KB  |  762 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 the functions to handle MandelVroom's
  25.  * Zoom box which is used for navigation around in the complex plane.
  26.  */
  27.  
  28. #include "mandp.h"
  29.  
  30. SHORT BoxSizeX = 3, BoxSizeY = 3, DragSize = 3;
  31.  
  32. static SHORT HotSpotX, HotSpotY;
  33.  
  34. struct Picture *ZoomedPict;
  35.  
  36. #define MENUCODE(m,i,s) (SHIFTMENU(m)|SHIFTITEM(i)|SHIFTSUB(s))
  37.  
  38. /*
  39.  * Picture (project) related commands
  40.  */
  41.  
  42. ZoomInCmd(Msg)
  43.   struct IntuiMessage *Msg;
  44. {
  45.   struct Picture *Pict;
  46.  
  47.   Pict = (struct Picture *) Msg->IDCMPWindow->UserData;
  48.  
  49.   switch( Msg->Class ) {
  50.  
  51.     case GADGETDOWN:
  52.          ZoomedPict = Pict;
  53.  
  54.     case MENUPICK:
  55.          Pict->ZoomType = ZOOMIN;
  56.          if ( ! (Pict->Flags & SCROLL_HAPPENED)) {
  57.            CloseZoomBox(Pict);
  58.            SetToPointer();
  59.            State = ZOOMINSTATE;
  60.          }
  61.          break;
  62.  
  63.     case MOUSEBUTTONS:
  64.          if (Msg->Code == SELECTDOWN) {
  65.            if (ZoomedPict->pNode.ln_Type == Pict->pNode.ln_Type) {
  66.              StartZoomBox(ZoomedPict, Pict);
  67.              ResizeZoomCmd(Msg); /* Pass control off to resize routine */
  68.            }
  69.          }
  70.          break;
  71.   }
  72. }
  73.  
  74. /*
  75.  * StartZoomOut
  76.  */
  77. ZoomOutCmd( Msg )
  78.   struct IntuiMessage *Msg;
  79. {
  80.   register struct Picture *Pict;
  81.  
  82.   if (Msg->Class == MENUPICK) {
  83.     Pict = CurPict;
  84.   } else {
  85.     Pict = (struct Picture *) Msg->IDCMPWindow->UserData;
  86.   }
  87.   Pict->ZoomType = ZOOMOUT;
  88.  
  89.   AddHead( &Pict->zList, &Pict->zNode );
  90.  
  91.   Pict->Flags   |= ZOOM_BOX_OPEN;
  92.   Pict->DrawPict = Pict;
  93.  
  94.   Pict->NavLeft  = Pict->LeftMarg;
  95.   Pict->NavRight = Pict->CountX + Pict->NavLeft - 1;
  96.   Pict->NavTop   = Pict->TopMarg;
  97.   Pict->NavBot   = Pict->CountY + Pict->NavTop - 1;
  98.  
  99.   ZoomOnOff( Pict );
  100. }
  101.  
  102. ResizeZoomCmd(Msg)
  103.   struct IntuiMessage *Msg;
  104. {
  105.   struct Window  *Window;
  106.   struct Picture *Pict;
  107.  
  108.   Window = Msg->IDCMPWindow;
  109.   Pict   = (struct Picture *) Window->UserData;
  110.  
  111.   switch( Msg->Class ) {
  112.  
  113.     case MOUSEBUTTONS:
  114.          switch (Msg->Code) {
  115.  
  116.            case SELECTDOWN:
  117.  
  118.                 if (State != ZOOMINSTATE)
  119.                   ZoomExtras(ZoomedPict);
  120.                 AllocLensTemp( ZoomedPict );
  121.                 ModifyIDCMP(Window, Window->IDCMPFlags |  MOUSEMOVE);
  122.                 State = RESIZEZOOMSTATE;
  123.                 break;
  124.  
  125.            case SELECTUP:
  126.                 ModifyIDCMP(Window, Window->IDCMPFlags & ~MOUSEMOVE);
  127.                 FreeLensTemp();
  128.                 FinishResize(ZoomedPict);
  129.                 State = IDLESTATE;
  130.                 break;
  131.          }
  132.          break;
  133.  
  134.     case MOUSEMOVE:
  135.          StretchZoomBox( ZoomedPict );
  136.          break;
  137.   }
  138. }
  139.  
  140. ZoomDragCmd(Msg)
  141.   struct IntuiMessage *Msg;
  142. {
  143.   struct Window *Window;
  144.   struct Picture *Pict;
  145.  
  146.   Window = Msg->IDCMPWindow;
  147.   Pict = (struct Picture *) Window->UserData;
  148.  
  149.   switch( Msg->Class ) {
  150.  
  151.     case MOUSEBUTTONS:
  152.          ZoomExtras( ZoomedPict );            /* draw/undraw the extras */
  153.          switch( Msg->Code ) {
  154.  
  155.            case SELECTDOWN:                   /* start drag */
  156.                 AllocLensTemp( ZoomedPict );
  157.                 ModifyIDCMP(Window, Window->IDCMPFlags | MOUSEMOVE);
  158.                 State = ZOOMDRAGSTATE;
  159.                 break;
  160.  
  161.            case SELECTUP:                     /* stop slide */
  162.                 FreeLensTemp();
  163.                 ModifyIDCMP(Window, Window->IDCMPFlags & ~MOUSEMOVE);
  164.                 State = IDLESTATE;
  165.                 break;
  166.          }
  167.          break;
  168.  
  169.     case MOUSEMOVE:
  170.          DragZoomBox( ZoomedPict );
  171.          Lens( ZoomedPict );
  172.          break;
  173.   }
  174. }
  175.  
  176. PropResizeCmd(Msg)
  177.   struct IntuiMessage *Msg;
  178. {
  179.   struct Window *Window;
  180.   struct Picture *Pict;
  181.  
  182.   Window = Msg->IDCMPWindow;
  183.   Pict = (struct Picture *) Window->UserData;
  184.  
  185.   switch( Msg->Class ) {
  186.  
  187.     case MOUSEBUTTONS:
  188.          ZoomExtras( ZoomedPict );            /* draw/undraw the extras */
  189.          switch( Msg->Code ) {
  190.  
  191.            case SELECTDOWN:                   /* start resize */
  192.                 AllocLensTemp( ZoomedPict );
  193.                 StartPropStrech( ZoomedPict );
  194.                 ModifyIDCMP(Window, Window->IDCMPFlags | MOUSEMOVE);
  195.                 State = PROPRESIZESTATE;
  196.                 break;
  197.  
  198.            case SELECTUP:                     /* stop resize */
  199.                 FreeLensTemp();
  200.                 ModifyIDCMP(Window, Window->IDCMPFlags & ~MOUSEMOVE);
  201.                 State = IDLESTATE;
  202.                 break;
  203.          }
  204.          break;
  205.  
  206.     case MOUSEMOVE:
  207.          PropStretchBox( ZoomedPict );
  208.          Lens( ZoomedPict );
  209.          break;
  210.   }
  211. }
  212.  
  213. SetJuliaCmd(Msg)
  214.   struct IntuiMessage *Msg;
  215. {
  216.   switch( Msg->Class ) {
  217.  
  218.     case MENUPICK:
  219.          SetToPointer();
  220.          ZoomedPict = CurPict;
  221.          State = SETJULIASTATE;
  222.          break;
  223.  
  224.     case GADGETDOWN:
  225.          SetToPointer();
  226.          ZoomedPict = (struct Picture *) Msg->IDCMPWindow->UserData;
  227.          State = SETJULIASTATE;
  228.          break;
  229.  
  230.     case MOUSEBUTTONS:
  231.          if (Msg->Code == SELECTDOWN) {
  232.  
  233.            SetJuliaPt(ZoomedPict,
  234.                       (struct Picture *) Msg->IDCMPWindow->UserData);
  235.            State = IDLESTATE;
  236.          }
  237.          break;
  238.   }
  239. }
  240.  
  241. QueryHeightCmd(Msg)
  242.   struct IntuiMessage *Msg;
  243. {
  244.   struct Window *Window;
  245.   struct Picture *Pict;
  246.  
  247.   Window = Msg->IDCMPWindow;
  248.   Pict = (struct Picture *) Window->UserData;
  249.  
  250.   if (Pict->Flags & SCROLL_HAPPENED)
  251.     return;
  252.  
  253.   switch( Msg->Class ) {
  254.  
  255.     case MOUSEBUTTONS:
  256.          switch( Msg->Code ) {
  257.                                               /* start query */
  258.            case SELECTDOWN:
  259.                 if (Pict->Counts && !(Pict->Flags & NO_RAM_GENERATE)) {
  260.                   ShowContour( MouseX, MouseY, 1 );
  261.                   ModifyIDCMP(Window, Window->IDCMPFlags | MOUSEMOVE);
  262.                   State = QUERYHEIGHTSTATE;
  263.                 }
  264.                 break;
  265.  
  266.            case SELECTUP:                     /* stop query */
  267.                 ModifyIDCMP(Window, Window->IDCMPFlags & ~MOUSEMOVE);
  268.                 State = IDLESTATE;
  269.                 break;
  270.          }
  271.          break;
  272.  
  273.     case MOUSEMOVE:
  274.          ShowContour( MouseX, MouseY, 0);
  275.          break;
  276.   }
  277. }
  278.  
  279. static int OldHeight; /* used to detect title change */
  280.  
  281. ShowContour(MouseX,MouseY,Flag)
  282.   register int MouseX,MouseY;
  283.   register int Flag;
  284. {
  285.   register struct Picture *Pict;
  286.  
  287.   static char ScreenTitle[80];
  288.  
  289.   int Height;
  290.   float r, i;
  291.  
  292.   Pict = (struct Picture *) CurWind->UserData;
  293.  
  294.   if (Pict == NULL)
  295.     return;
  296.  
  297.   if (MouseX >= Pict->LeftMarg &&
  298.       MouseY >= Pict->TopMarg  &&
  299.       MouseX <  CurWind->Width  - Pict->RightMarg &&
  300.       MouseY <  CurWind->Height - Pict->BotMarg) {
  301.  
  302.     Height = HeightPicked(Pict,MouseX,MouseY);
  303.     r = Pict->RealLow + (MouseX - Pict->LeftMarg) * Pict->RealGap;
  304.     i = Pict->ImagLow + (MouseY - Pict->TopMarg) * Pict->ImagGap;
  305.  
  306.     sprintf(ScreenTitle,"Height %3d r %f i %f",
  307.                          Height, r, i);
  308.  
  309.     SetWindowTitles( CurWind, (long) -1, ScreenTitle );
  310.   }
  311. }
  312.  
  313. /*
  314.  * Start Zoom box
  315.  */
  316. StartZoomBox( NavPict, DrawPict )
  317.   register struct Picture *NavPict;
  318.   register struct Picture *DrawPict;
  319. {
  320.   register struct Window  *Window = DrawPict->Window;
  321.  
  322.   CloseZoomBox( NavPict);
  323.  
  324.   AddHead( &DrawPict->zList, &NavPict->zNode );
  325.  
  326.   NavPict->Flags    |= ZOOM_BOX_OPEN;
  327.   NavPict->DrawPict  = DrawPict;
  328.  
  329.   /* Draw first box */
  330.   NavPict->NavTop   = NavPict->NavBot   = MouseY;
  331.   NavPict->NavLeft  = NavPict->NavRight = MouseX;
  332.  
  333.   ZoomBox( NavPict );
  334. }
  335.  
  336. StretchZoomBox( Pict )
  337.   register struct Picture *Pict;
  338. {
  339.   register struct Picture  *DrawPict = Pict->DrawPict;
  340.   register LONG Left = DrawPict->CountX + DrawPict->LeftMarg;
  341.   register LONG Top  = DrawPict->CountY + DrawPict->TopMarg;
  342.  
  343.   ZoomBox( Pict );
  344.  
  345.   if ( MouseX < Pict->NavLeft )
  346.     MouseX = Pict->NavLeft;
  347.  
  348.   if ( MouseY < Pict->NavTop )
  349.     MouseY = Pict->NavTop;
  350.  
  351.   if ( MouseX > Left )
  352.     MouseX = Left-1;
  353.  
  354.   if ( MouseY > Top )
  355.     MouseY = Top-1;
  356.  
  357.   Pict->NavBot   = MouseY;
  358.   Pict->NavRight = MouseX;
  359.  
  360.   Lens( Pict );
  361.  
  362.   ZoomBox( Pict );
  363. }
  364.  
  365. static double ZoomAspectRatio;
  366.  
  367. StartPropStrech( Pict )
  368.   register struct Picture *Pict;
  369. {
  370.   ZoomAspectRatio = (double) (Pict->NavRight - Pict->NavLeft) /
  371.                    (double) (Pict->NavBot - Pict->NavTop);
  372. }
  373.  
  374. PropStretchBox( Pict )
  375.   register struct Picture *Pict;
  376. {
  377.   register LONG Left = Pict->LeftMarg;
  378.   register LONG Top  = Pict->DrawPict->CountY + Pict->TopMarg;
  379.  
  380.   register LONG CenterX = Pict->NavRight - Pict->NavLeft;
  381.   register LONG CenterY = Pict->NavBot - Pict->NavTop;
  382.  
  383.   LONG NewLeft,NewRight,NewTop;
  384.  
  385.   ZoomBox( Pict );
  386.  
  387.   CenterX = Pict->NavLeft + CenterX / 2;
  388.   CenterY = Pict->NavTop + CenterY / 2;
  389.  
  390.   if ( MouseX > CenterX-4 )  MouseX = CenterX-4;
  391.   if ( MouseY < CenterY+4 )  MouseY = CenterY+4;
  392.  
  393. #if 0
  394.   if ( MouseX < Left ) MouseX = Left;  /* don't let it flip */
  395.   if ( MouseY > Top )  MouseY = Top;
  396. #endif
  397.  
  398.   Top = MouseY - CenterY;
  399.   Left = (LONG) ((float) Top * ZoomAspectRatio);
  400.  
  401.   NewLeft = CenterX - Left;
  402.   NewRight = CenterX + Left;
  403.   NewTop = CenterY - Top;
  404.  
  405.   if (NewLeft  >= Pict->LeftMarg &&
  406.       NewRight <  Pict->DrawPict->Window->Width - Pict->RightMarg &&
  407.       NewTop   >= Pict->TopMarg ) {
  408.  
  409.     Pict->NavBot = MouseY;
  410.     Pict->NavTop = NewTop;
  411.     Pict->NavLeft  = NewLeft;
  412.     Pict->NavRight = NewRight;
  413.   }
  414.  
  415.   Lens( Pict );
  416.  
  417.   ZoomBox( Pict );
  418. }
  419.  
  420. #define MINXBOX (8 << XScale)
  421. #define MINYBOX (7 << YScale)
  422.  
  423. FinishResize( Pict )
  424.   struct Picture *Pict;
  425. {
  426.   register int t;
  427.  
  428.   if (Pict->NavBot < Pict->NavTop) {
  429.     t            = Pict->NavBot;
  430.     Pict->NavBot = Pict->NavTop;
  431.     Pict->NavTop = t;
  432.   }
  433.   if (Pict->NavRight < Pict->NavLeft) {
  434.     t              = Pict->NavRight;
  435.     Pict->NavRight = Pict->NavLeft;
  436.     Pict->NavLeft  = t;
  437.   }
  438.  
  439.   ZoomBox( Pict );
  440.  
  441.   if (Pict->NavRight - Pict->NavLeft < MINXBOX )
  442.     Pict->NavRight = Pict->NavLeft + MINXBOX;
  443.  
  444.   if (Pict->NavBot - Pict->NavTop < MINYBOX )
  445.     Pict->NavBot = Pict->NavTop + MINYBOX;
  446.  
  447.   ZoomOnOff( Pict );
  448. }
  449.  
  450. DragZoomBox( Pict )
  451.   register struct Picture *Pict;
  452. {
  453.   register struct Picture *DrawPict = Pict->DrawPict;
  454.   register LONG Width, Height;
  455.  
  456.   ZoomBox( Pict );
  457.  
  458.   Width  = Pict->NavRight - Pict->NavLeft - HotSpotX;
  459.   Height = Pict->NavBot -   Pict->NavTop - HotSpotY;
  460.  
  461.   if ( MouseY < 1 )
  462.     MouseY = 1;
  463.  
  464.   if ( MouseX - HotSpotX < DrawPict->LeftMarg )
  465.     MouseX = DrawPict->LeftMarg + HotSpotX;
  466.  
  467.   if ( MouseY - HotSpotY < DrawPict->TopMarg )
  468.     MouseY = DrawPict->TopMarg + HotSpotY;
  469.  
  470.   if ( MouseX + Width >= DrawPict->CountX + DrawPict->LeftMarg )
  471.     MouseX = DrawPict->CountX + DrawPict->LeftMarg - Width;
  472.  
  473.   if ( MouseY + Height >= DrawPict->CountY + DrawPict->TopMarg )
  474.     MouseY = DrawPict->CountY + DrawPict->TopMarg - Height;
  475.  
  476.   Pict->NavLeft  = MouseX - HotSpotX;
  477.   Pict->NavTop   = MouseY - HotSpotY;
  478.  
  479.   Pict->NavRight = MouseX + Width;
  480.   Pict->NavBot   = MouseY + Height;
  481.  
  482.   Lens( Pict );
  483.  
  484.   ZoomBox( Pict );
  485. }
  486.  
  487. CloseZoomBox( Pict )
  488.   struct Picture *Pict;
  489. {
  490.   if (Pict) {
  491.     if (Pict->Flags & ZOOM_BOX_OPEN) {
  492.       ZoomOnOff( Pict );
  493.       Remove( &Pict->zNode );
  494.       Pict->Flags &= ~ZOOM_BOX_OPEN;
  495.     }
  496.     Pict->DrawPict = NULL;
  497.   }
  498. }
  499.  
  500. ClearZoomBox(Pict)
  501.   struct Picture *Pict;
  502. {
  503.   CloseZoomBox( Pict );
  504.   ZoomedPict = NULL;
  505. }
  506.  
  507. ZoomBox( Pict )
  508.   register struct Picture *Pict;
  509. {
  510.   if ( Pict && Pict->DrawPict && Pict->DrawPict->Window) {
  511.  
  512.     ObtainSemaphore( &Pict->WindowSemi );
  513.     DrawBox( Pict->DrawPict->Window,
  514.              Pict->NavLeft,  Pict->NavTop,
  515.              Pict->NavRight, Pict->NavBot );
  516.     ReleaseSemaphore( &Pict->WindowSemi );
  517.   }
  518. }
  519.  
  520. ZoomExtras( Pict )
  521.   register struct Picture *Pict;
  522. {
  523.   if ( Pict && Pict->DrawPict && Pict->DrawPict->Window) {
  524.  
  525.  
  526.     ObtainSemaphore( &Pict->WindowSemi );
  527.     DrawExtras( Pict->DrawPict->Window,
  528.                 Pict->NavLeft,  Pict->NavTop,
  529.                 Pict->NavRight, Pict->NavBot );
  530.     ReleaseSemaphore( &Pict->WindowSemi );
  531.   }
  532. }
  533.  
  534. ZoomOnOff( Pict )
  535.   register struct Picture *Pict;
  536. {
  537.   ZoomBox( Pict );
  538.   ZoomExtras( Pict );
  539. }
  540.  
  541. DrawBox( Window, PLeft, PTop, PRight, PBottom)
  542.   struct Window *Window;
  543.   SHORT PTop, PLeft, PBottom, PRight;
  544. {
  545.   register struct RastPort *Rp;
  546.   register LONG Top, Left, Right, Bottom;
  547.  
  548.   Rp = Window->RPort;
  549.  
  550.   Top = PTop;
  551.   Left = PLeft;
  552.   Right = PRight;
  553.   Bottom = PBottom;
  554.  
  555.   SetDrMd(Rp, COMPLEMENT);
  556.   /*
  557.    * Draw the new box
  558.    */
  559.   Move(Rp, Left,  Top   );
  560.   Draw(Rp, Right, Top   );
  561.   Draw(Rp, Right, Bottom);
  562.   Draw(Rp, Left,  Bottom);
  563.   Draw(Rp, Left,  Top+1 );
  564.  
  565.   SetDrMd(Rp, JAM1);
  566. } /* DrawBox */
  567.  
  568. DrawExtras( Window, Left, Top, Right, Bottom)
  569.   struct Window *Window;
  570.   SHORT Top, Left, Bottom, Right;
  571. {
  572.   register struct RastPort *Rp = Window->RPort;
  573.   register LONG ResizeTop  = Bottom - ( BoxSizeY << YScale );
  574.   register LONG ResizeLeft = Right  - ( BoxSizeX << XScale );
  575.   register LONG BotDrag = Top + ( DragSize << YScale );
  576.  
  577.   SetDrMd(Rp, COMPLEMENT);
  578.   /*
  579.    * Draw Normal Resize gadget
  580.    */
  581.   Move(Rp, (long) Right - 1,  ResizeTop );
  582.   Draw(Rp, ResizeLeft, ResizeTop );
  583.   Draw(Rp, ResizeLeft, (long) Bottom - 1);
  584.  
  585.   /*
  586.    * Draw Proportional Resize gadget
  587.    */
  588.   ResizeLeft = Left + ( BoxSizeX << XScale );
  589.  
  590.   Move(Rp, (long) Left + 1,  ResizeTop );
  591.   Draw(Rp, ResizeLeft, ResizeTop );
  592.   Draw(Rp, ResizeLeft, (long) Bottom - 1);
  593.  
  594.   /*
  595.    * Drag bar bar / close gadget separator
  596.    */
  597.   Move(Rp, (long) Left  + 1,  BotDrag );
  598.   Draw(Rp, (long) Right - 1,  BotDrag );
  599.  
  600.   Move(Rp, (long) Left + (4 << XScale), (long) Top + 1);
  601.   Draw(Rp, (long) Left + (4 << XScale), BotDrag - 1 );
  602.  
  603.   SetDrMd(Rp, JAM1);
  604. } /* DrawExtras */
  605.  
  606. /*
  607.  * ZoomIn
  608.  */
  609. ZoomIn( NavPict )
  610.   register struct Picture *NavPict;
  611. {
  612.   register struct Picture *DrawPict = NavPict->DrawPict;
  613.   double left,  top;
  614.   double right, bot;
  615.  
  616.   double AspectRatio();
  617.  
  618.   double Gap;
  619.  
  620.   if (DrawPict) {
  621.  
  622.     left  = (double) (NavPict->NavLeft  - DrawPict->LeftMarg);
  623.     top   = (double) (NavPict->NavTop   - DrawPict->TopMarg);
  624.     right = (double) (NavPict->NavRight - DrawPict->LeftMarg);
  625.     bot   = (double) (NavPict->NavBot   - DrawPict->TopMarg);
  626.  
  627.     switch( NavPict->ZoomType ) {
  628.       case  ZOOMIN:
  629.  
  630.             NavPict->RealHigh = DrawPict->RealLow + DrawPict->RealGap*right;
  631.             NavPict->ImagHigh = DrawPict->ImagLow + DrawPict->ImagGap*bot;
  632.             NavPict->RealLow  = DrawPict->RealLow + DrawPict->RealGap*left;
  633.             NavPict->ImagLow  = DrawPict->ImagLow + DrawPict->ImagGap*top;
  634.  
  635.             NavPict->Real     = DrawPict->Real;
  636.             NavPict->Imag     = DrawPict->Imag;
  637.             break;
  638.  
  639.       case  ZOOMOUT:
  640.  
  641.             Gap = (DrawPict->ImagHigh - DrawPict->ImagLow) / (bot - top);
  642.  
  643.             NavPict->ImagLow  -= top * Gap;
  644.             NavPict->ImagHigh = NavPict->ImagLow +
  645.                                 (double) NavPict->CountY*Gap;
  646.  
  647.             NavPict->ImagGap = Gap;
  648.             NavPict->RealGap = Gap *= AspectRatio(NavPict);
  649.  
  650.             NavPict->RealLow  -= left * Gap;
  651.             NavPict->RealHigh = NavPict->RealLow +
  652.                                 (double) NavPict->CountX*Gap;
  653.     }
  654.  
  655.     CloseZoomBox( NavPict );
  656.   }
  657.   CalculateGaps( NavPict );
  658. } /* ZoomIn */
  659.  
  660. /*
  661.  * Calculate Gaps
  662.  */
  663. CalculateGaps( Pict )
  664.   register struct Picture *Pict;
  665. {
  666.   double AspectRatio();
  667.  
  668.   Pict->ImagGap = (Pict->ImagHigh - Pict->ImagLow) / (double) Pict->CountY;
  669.   Pict->RealGap = Pict->ImagGap * AspectRatio( Pict );
  670. }
  671.  
  672. /*
  673.  * Apsect Ratio - IEEE
  674.  */
  675. double
  676. AspectRatio( Pict )
  677.   register struct Picture *Pict;
  678. {
  679.   double aspectratio;
  680.  
  681.   if (Pict->ViewModes & HIRES)
  682.     if (Pict->ViewModes & INTERLACE)
  683.       aspectratio = 0.88;
  684.     else
  685.       aspectratio = 0.44;
  686.   else
  687.     if (Pict->ViewModes & INTERLACE)
  688.       aspectratio = 1.76;
  689.     else
  690.       aspectratio = 0.88;
  691.  
  692.   return( aspectratio );
  693. }
  694.  
  695. /*
  696.  * Simulate Zoom box gadgets
  697.  */
  698. int
  699. CheckPictZoomBox( NavPict )
  700.   register struct Picture  *NavPict;
  701. {
  702.   register struct Picture *DrawPict = NavPict->DrawPict;
  703.   register struct Window  *Window = DrawPict->Window;
  704.  
  705.   register LONG BoxX;
  706.  
  707.   BoxX = BoxSizeX << XScale;
  708.  
  709.   /* is it in the window box? */
  710.   if (MouseX >= NavPict->NavLeft && MouseX <= NavPict->NavRight &&
  711.       MouseY >= NavPict->NavTop  && MouseY <= NavPict->NavBot) {
  712.  
  713.     /* is it in the top part? */
  714.     if (MouseY <= NavPict->NavTop + (DragSize << YScale) ) {
  715.  
  716.       /* is it the drag bar? */
  717.       if (MouseX > NavPict->NavLeft + BoxX ) {
  718.  
  719.         HotSpotX = MouseX - NavPict->NavLeft;
  720.         HotSpotY = MouseY - NavPict->NavTop;
  721.         return(ZOOMDRAGHIT);
  722.  
  723.       } else {                     /* We got the close gadget */
  724.  
  725.         return(ZOOMCLOSEHIT);
  726.       }
  727.     } else {
  728.  
  729.       /* is it the Resize Gadget? */
  730.       if (MouseY >= NavPict->NavBot - ((BoxSizeY + 1) << YScale) ) {
  731.  
  732.         if ( MouseX > NavPict->NavRight - BoxX ) {
  733.  
  734.           return(ZOOMRESIZEHIT);
  735.  
  736.         } else
  737.         if ( MouseX <= NavPict->NavLeft + BoxX ) {
  738.  
  739.           return(PROPRESIZEHIT);
  740.         }
  741.       }
  742.     }
  743.   }
  744.   return(NOTHINGHIT);
  745. }
  746.  
  747. SetJuliaPt( ZoomedPict, Pict )
  748.   register struct Picture *ZoomedPict, *Pict;
  749. {
  750.   register LONG x,y;
  751.  
  752.   if (ZoomedPict && Pict &&
  753.       ZoomedPict->pNode.ln_Type != Pict->pNode.ln_Type) {
  754.  
  755.     x = MouseX - Pict->LeftMarg;
  756.     y = MouseY - Pict->TopMarg;
  757.  
  758.     ZoomedPict->Real = Pict->RealLow + x * Pict->RealGap;
  759.     ZoomedPict->Imag = Pict->ImagLow + y * Pict->ImagGap;
  760.   }
  761. }
  762.