home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / sysext / init / beepshuf.sit / CShowINIT.c < prev   
Encoding:
C/C++ Source or Header  |  1990-01-09  |  5.9 KB  |  150 lines

  1. /*-------------------------------------------------------------------------
  2.   Filename: CShowINIT.c
  3.   Color ShowINIT, for use with LightspeedC
  4.   This translation by Ken McLeod (thecloud@dhw68k.cts.com)
  5.   Version of: Thursday, April 6, 1989 3:30:00 PM
  6.     Devolved by Alex Chaffee (chaffee@reed.uucp) 9 Jan '90 [ADC]
  7.     
  8.   INIT notification routine
  9.   by Paul Mercer, Darin Adler, and Paul Snively from an idea by Steve Capps
  10.   Version of: Friday, July 15, 1988 12:08:09 AM    (1.1B1)
  11.     -revved back to previous calling interface.
  12.     -you only need to call ShowINIT now and due to popular demand,
  13.      deltaX is back!
  14.     -also due to popular demand, color icons are now done automatically.
  15.     -note that the color icon is only used if 4 bits or more is available on
  16.      the main graphics device; the normal #ICN is used for all other cases.
  17.   
  18.   Converted back to a regular C function, for inclusion in a project [ADC]
  19.   
  20.     Prototype:
  21.       pascal void ShowINIT(short iconID, short moveX);
  22.   Usage:
  23.         ShowINIT(ICON_ID, -1);
  24.         
  25.   -------------------------------------------------------------------------*/
  26.  
  27. /* #include <MacHeaders> */
  28. #include <Color.h>
  29.  
  30. typedef struct QuickDraw {       /* struct to hold QuickDraw globals */
  31.   char private[76];
  32.   long randSeed;
  33.   BitMap screenBits;
  34.   Cursor arrow;
  35.   Pattern dkGray;
  36.   Pattern ltGray;
  37.   Pattern gray;
  38.   Pattern black;
  39.   Pattern white;
  40.   GrafPtr thePort;
  41. } QuickDraw;
  42.  
  43. /*extern short ROM85 : 0x28E;*/
  44. /*extern GDHandle MainDevice : 0x8A4;*/
  45.  
  46. extern short myH : 0x92C;        /* CurApName+28   */
  47. extern short myCheck: 0x92E;     /* CurApName+30   */
  48.  
  49. #define  firstX         8        /* left margin - offset to first icon */
  50. #define  bottomEdge     8        /* this far from bottom of screen */
  51. #define  iconWidth      32       /* size of icon (square normally) */
  52. #define  defaultMoveX   40       /* default amount to move icons */
  53. #define  checksumConst  0x1021   /* constant used for computing checksum */
  54. #define  minColorDepth  4        /* min. bits/pixel for drawing color icons */
  55. #define  maskOffset     128      /* offset to mask in ICN# resource */
  56. #define  iconRowBytes   32/8     /* 32/8 bits */
  57. #define  hasCQDBit      6        /* bit in ROM85 cleared if CQD available */
  58.  
  59. /*-------------------------------------------------------------------------
  60.   Display the ICN# (cicn when in 4 bit mode or higher) specified by iconID
  61.   and move the pen horizontally by moveX.  Pass a -1 in moveX to move the
  62.   standard amount (40 pixels).
  63.  
  64.   pascal void ShowINIT(iconID, moveX)
  65.     short iconID, moveX;
  66.     extern;
  67.  
  68.   -------------------------------------------------------------------------*/
  69.  
  70. pascal void ShowINIT(iconID, moveX)
  71. short iconID, moveX;
  72. {
  73.   Handle  theIconHdl;                      /* handle to the icon (or cicn) */
  74.   short     dh;                         /* for calculating horizontal offset */
  75.   short  colorFlag;             /* set if drawing a color icon */
  76.   short  theDepth;              /* depth of main screen; used for CQD only */
  77.   GDHandle theMainDevice;       /* handle to main screen device; CQD only */
  78.   Rect srcRect, destRect;       /* source & destination rectangles */
  79.   BitMap myBitMap;              /* icon bitmap; used for b/w icon only */
  80.   GrafPort myPort;              /* port we draw into */
  81.   QuickDraw qdGlobals;             /* our own personal QD globals... */
  82.   Ptr localA5;                  /* pointer to qdGlobals.thePort */
  83.   Ptr    savedA5;                                    /* storage for saved contents of A5 */
  84.   
  85.   asm {
  86.     move.l  A5,savedA5                    /* save "real" QD globals ptr */
  87.     lea          localA5,A5                    /* set up A5 to point to our globals */
  88.     move.l  A5,CurrentA5
  89.   }
  90.   InitGraf(&qdGlobals.thePort);    /* initialize our qdGlobals structure */
  91.   OpenPort(&myPort);
  92.   colorFlag = 0;                                /* default: no color */
  93.  
  94.   if (!(BitTst(&ROM85, 7-hasCQDBit))) {    /* does CQD exist? */
  95.     theMainDevice = MainDevice;                    /* yes; get handle to main device */
  96.         theDepth = (*(*theMainDevice)->gdPMap)->pixelSize;
  97.     if (theDepth >= minColorDepth)    {        /* deep enough to draw in color? */
  98.       if ((theIconHdl = (Handle)GetCIcon(iconID)) != 0L)
  99.         colorFlag = 1;                                    /* found a color icon; set flag */
  100.     }
  101.   }
  102.  
  103.   if (!(colorFlag))    {  /* no CQD, insufficient depth, or lack of 'cicn' */
  104.     if (!(theIconHdl = GetResource('ICN#',iconID))) {
  105.       SysBeep(3);  /* can't get b/w icon; signal error and bail out */
  106.       goto out;
  107.     }
  108.   }
  109.   dh = (myH << 1) ^ checksumConst;           /* checksum to find dh */
  110.   myH = ((dh == myCheck) ? (myH):(firstX));  /* reset if necessary */
  111.   /* notice that we stored the new horizontal value directly back into
  112.       the low-memory 'myH' location, rather than using a temporary variable.
  113.       This is the way the original ShowINIT works, and IconWrap relies on it. */
  114.  
  115.   destRect.bottom = myPort.portRect.bottom - bottomEdge;
  116.   destRect.left = myPort.portRect.left + myH;
  117.   destRect.top = destRect.bottom - iconWidth;
  118.   destRect.right = destRect.left + iconWidth;
  119.  
  120.   if (colorFlag) {                                /* draw color icon */
  121.       PlotCIcon(&destRect,(CIconHandle)theIconHdl);
  122.     DisposCIcon((CIconHandle)theIconHdl);
  123.   }
  124.   else {                                          /* draw b/w icon */
  125.     HLock(theIconHdl);
  126.     srcRect.top = srcRect.left = 0;
  127.     srcRect.bottom = srcRect.right = iconWidth;
  128.     myBitMap.rowBytes = iconRowBytes;
  129.     myBitMap.bounds = srcRect;
  130.     myBitMap.baseAddr = *theIconHdl + maskOffset; /* punch hole with mask */
  131.     CopyBits(&myBitMap, &myPort.portBits, &srcRect, &destRect, srcBic, 0L);
  132.     myBitMap.baseAddr = *theIconHdl;              /* now draw the icon */
  133.     CopyBits(&myBitMap, &myPort.portBits, &srcRect, &destRect, srcOr, 0L);
  134.     HUnlock(theIconHdl);
  135.     ReleaseResource(theIconHdl);
  136.   }
  137.   myH += ((moveX == -1) ? (defaultMoveX):(moveX));  /* advance for next time */
  138.   myCheck = (myH << 1) ^ checksumConst;             /* calc new checksum */
  139.  
  140. out:
  141.   ClosePort(&myPort);
  142.   asm {
  143.     move.l  savedA5,A5
  144.     move.l  A5,CurrentA5
  145.   }
  146.  
  147. }
  148.  
  149. /*-------------------------------------------------------------------------*/
  150.