home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 11 / AMUG BBS in a Box Volume XI (April 1994) (MacWizards).iso / Files / System7 tools / Frontier / Frontier SDK 2.1.sit / Frontier SDK 2.1 / Toolkits / Applet Toolkit / appletzoom.c / appletzoom.c
Encoding:
C/C++ Source or Header  |  1992-10-11  |  2.6 KB  |  159 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletdefs.h"
  6. #include "appletquickdraw.h"
  7. #include "appletzoom.h"
  8.  
  9. #define zoomfixer 65536L
  10.  
  11. #define zoomsteps 16
  12.  
  13. Fixed zoomfract;
  14.  
  15.  
  16.  
  17.  
  18. static short zoomblend (short i1, short i2) {
  19.  
  20.     Fixed smallFix,bigFix,tempFix;
  21.  
  22.     smallFix = zoomfixer * i1;
  23.     
  24.     bigFix = zoomfixer * i2;
  25.     
  26.     tempFix = FixMul (zoomfract, bigFix) + FixMul (zoomfixer-zoomfract, smallFix);
  27.     
  28.     return (FixRound (tempFix));
  29.     } /*zoomblend*/
  30.     
  31.  
  32. static void zoomrect (Rect *smallrect, Rect *bigrect, Boolean zoomup) {
  33.  
  34.     Fixed factor;
  35.     Rect rect1,rect2,rect3,rect4;
  36.     GrafPtr savePort,deskPort;
  37.     short i;
  38.     
  39.     GetPort (&savePort);
  40.     
  41.     OpenPort (deskPort = (GrafPtr) NewPtr (sizeof (GrafPort)));
  42.     
  43.     InitPort (deskPort);
  44.     
  45.     SetPort (deskPort);
  46.     
  47.     PenPat (quickdrawglobal (gray));
  48.     
  49.     PenMode (notPatXor);
  50.     
  51.     if (zoomup) {
  52.     
  53.         rect1 = *smallrect;
  54.         
  55.         factor = FixRatio(6,5);
  56.         
  57.         zoomfract = FixRatio(541,10000);
  58.         }
  59.     else {
  60.         rect1 = *bigrect;
  61.         
  62.         factor = FixRatio(5,6);
  63.         
  64.         zoomfract = zoomfixer;
  65.         }
  66.         
  67.     rect2 = rect1;
  68.     
  69.     rect3 = rect1;
  70.     
  71.     FrameRect (&rect1);
  72.     
  73.     for (i = 1; i<= zoomsteps; i++) {
  74.     
  75.         rect4.left = zoomblend (smallrect->left, bigrect->left);
  76.         
  77.         rect4.right = zoomblend (smallrect->right, bigrect->right);
  78.         
  79.         rect4.top = zoomblend (smallrect->top, bigrect->top);
  80.         
  81.         rect4.bottom = zoomblend (smallrect->bottom, bigrect->bottom);
  82.         
  83.         FrameRect (&rect4);
  84.         
  85.         FrameRect (&rect1);
  86.         
  87.         rect1 = rect2;
  88.         
  89.         rect2 = rect3;
  90.         
  91.         rect3 = rect4;
  92.          
  93.         zoomfract = FixMul (zoomfract,factor);
  94.         } /*for*/
  95.         
  96.     FrameRect (&rect1);
  97.     
  98.     FrameRect (&rect2);
  99.     
  100.     FrameRect (&rect3);
  101.     
  102.     ClosePort (deskPort);
  103.     
  104.     DisposPtr ((Ptr)deskPort);
  105.     
  106.     PenNormal ();
  107.     
  108.     SetPort (savePort);
  109.     } /*zoomrect*/
  110.     
  111.     
  112. void zoomport (WindowPtr w, boolean flup) {
  113.  
  114.     /*
  115.     Zooms the window referenced by "w" either from an inivisible
  116.     state to a visible state, or vice versa.  Pass true in the "flup"
  117.     boolean parameter to zoom a window to open, an false to zoom
  118.     it close.  The WindowPtr must have already been created elsewhere,
  119.     and zooming the window invisible only hides the window, it does
  120.     not destroy the WindowPtr data.
  121.     */
  122.     
  123.     Rect r1, r2, r3;
  124.  
  125.     SetPort (w);
  126.     
  127.     SetRect (&r1, 0, 20, 0, 20);
  128.     
  129.     r3 = (*w).portRect;
  130.     
  131.     r2 = r3;
  132.     
  133.     InsetRect (&r2, (r3.right - r3.left + 20) / 2, (r3.bottom - r3.top + 20) / 2);
  134.  
  135.     localtoglobalrect (&r2);
  136.     
  137.     localtoglobalrect (&r3);
  138.  
  139.     if (flup) {
  140.     
  141.         zoomrect (&r1, &r2, true);
  142.         
  143.         zoomrect (&r2, &r3, true);
  144.         
  145.         ShowWindow (w);
  146.         
  147.         SetPort (w);
  148.         }
  149.     else {
  150.         HideWindow (w);
  151.         
  152.         zoomrect (&r2, &r3, false);
  153.         
  154.         zoomrect (&r1, &r2, false);
  155.         }
  156.     } /*zoomport*/
  157.     
  158.     
  159.