home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / FakeAlert / WindUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-31  |  4.3 KB  |  164 lines  |  [TEXT/KAHL]

  1. #include    "WindUtils.h"
  2.  
  3. RGBColor        rgbblack = {0,0,0};
  4. RGBColor        rgbwhite = {0xFFFF,0xFFFF,0xFFFF};
  5. RGBColor        rgbdarkred = {0x7FFF,0x0000,0x0000};
  6. RGBColor        rgblitered = {0xFFFF,0x8FFF,0x8FFF};
  7.  
  8. Boolean    HasColorQD = false;    //other code segments can check here, without checking over and over again
  9.  
  10. static WindowPtr    savePort;
  11. static short        saveFont;
  12. static short        saveSize;
  13. static short        saveFace;
  14.  
  15. void    DrawShadowBox(Rect Box, Boolean Inside)    //draw a shadowed rectangle, with shadow either inside or outside
  16. {
  17.     if (Inside)
  18.     {
  19.         Box.top -= 1;
  20.         Box.left -= 1;
  21.     }
  22.     PenSize(1,1);
  23.     FrameRect(&Box);
  24.     if (Inside)
  25.     {
  26.         MoveTo(Box.left + 1, Box.top + 1);
  27.         LineTo(Box.right - 1, Box.top + 1);
  28.         MoveTo(Box.left + 1, Box.top + 1);
  29.         LineTo(Box.left + 1, Box.bottom - 1);
  30.     }
  31.     else
  32.     {
  33.         MoveTo(Box.left + 1, Box.bottom);
  34.         LineTo(Box.right, Box.bottom);
  35.         MoveTo(Box.right, Box.top + 1);
  36.         LineTo(Box.right, Box.bottom);
  37.     }
  38. }
  39.  
  40. void    SaveTextSettings(void)    //save the text settings for a window, 
  41. {
  42.     GetPort(&savePort);
  43.     saveFont = savePort->txFont;
  44.     saveSize = savePort->txSize;
  45.     saveFace = savePort->txFace;
  46. }
  47.  
  48. void    RestoreTextSettings(void)
  49. //resotore text settings.  Must follow a SaveTextSettings() with a RestoreTextSettings()
  50. //since only one set of settings is saved here in static variables
  51. {
  52.     TextFont(saveFont);
  53.     TextSize(saveSize);
  54.     TextFace(saveFace);
  55. }
  56.  
  57. short    MaxTextHeight(void)    //get maximum text height of current font and size
  58. {
  59. FontInfo    myFontInfo;
  60.  
  61.     GetFontInfo(&myFontInfo);
  62.     return(myFontInfo.ascent + myFontInfo.descent + myFontInfo.leading);
  63. }
  64.  
  65. /* ------------------------- SetMouse ------------------------- */
  66. /* some dangerous low-memory-global equates */
  67. extern  Point    MTemp           :   0x828;
  68. extern  Point    RawMouse        :   0x82c;
  69. extern  Point    Mouse        :0x830;
  70. extern  int    CrsrNewCouple   :   0x8ce;  /* both New & Couple */
  71. extern  Byte    CrsrNew         :   0x8ce;
  72. extern  Byte    CrsrCouple      :   0x8cf;
  73.  
  74. #define     Couple      0xff;   /* value for CrsrCouple */
  75. #define     Uncouple    0x00;   /* value for CrsrCouple */
  76.  
  77. void    SetMouse(Point   where)    //move mouse on-screen, in local coordinates
  78. {
  79. long    finaltick;
  80.     
  81.     HideCursor();
  82.     LocalToGlobal(&where);          /* Get ready to store mouse position */
  83.     RawMouse = where;               /* into RawMouse */
  84.     MTemp = where;                  /* and MTemp */
  85.     Mouse = where;                  /* and Mouse */
  86.     CrsrNewCouple = 0xFFFF;       /* Hit CrsrNew & CrsrCouple */
  87.     ShowCursor();
  88. }   /* SetMouse */
  89.  
  90. void    SetWindColors(WindowPtr wind, Boolean NotInvertColors)
  91. //if a color window, on a color mac, and screen depth is greater than 2,
  92. //set the fore and back pen colors to the ones in the default WCTB window color table resource
  93. //or the window's color table, if it has one.
  94. //if NotInverColors is false, it sets the colors inverted.
  95. {
  96. AuxWinHandle    wincolors;
  97. Boolean        UseColorQD = false;
  98.  
  99.     if (HasColorQD)
  100.     {
  101.         if ( ((CWindowPtr) wind)->portVersion & 0xC000)    //if a color grafport
  102.         {
  103.             if ((*( ((CWindowPtr) wind)->portPixMap))->pixelSize > 2) UseColorQD = true;
  104.         }
  105.     }
  106.     if (UseColorQD)
  107.     {
  108.         GetAuxWin(wind, &wincolors);
  109.         if (NotInvertColors)
  110.         {
  111.             RGBForeColor(& ( (*((*wincolors)->awCTable))->ctTable[wTextColor].rgb) );
  112.             RGBBackColor(& ( (*((*wincolors)->awCTable))->ctTable[wContentColor].rgb) );
  113.         }
  114.         else
  115.         {
  116.             RGBBackColor(& ( (*((*wincolors)->awCTable))->ctTable[wTextColor].rgb) );
  117.             RGBForeColor(& ( (*((*wincolors)->awCTable))->ctTable[wContentColor].rgb) );
  118.         }
  119.     }
  120.     else
  121.     {
  122.         if (NotInvertColors)
  123.         {
  124.             ForeColor(blackColor);
  125.             BackColor(whiteColor);
  126.         }
  127.         else
  128.         {
  129.             ForeColor(whiteColor);
  130.             BackColor(blackColor);
  131.         }    
  132.     }
  133. }
  134.  
  135. void    BlackNWhite(Boolean NotInvertColors)
  136. //set forecolor and backcolor to black'n'white
  137. //if NotInvertColors is false, sets to white'n'black instead
  138. {
  139.     if (NotInvertColors)
  140.     {
  141.         ForeColor(blackColor);
  142.         BackColor(whiteColor);
  143.     }
  144.     else
  145.     {
  146.         ForeColor(whiteColor);
  147.         BackColor(blackColor);
  148.     }
  149. }
  150.  
  151. void        ColorImplemented(void)
  152. //call at program startup, to update the public variable HasColorQD
  153. //then if a routine needs to know if the Mac has Color QD, it can check HasColorQD.
  154. {
  155. SysEnvRec    theWorld;
  156.  
  157.     HasColorQD = false; //Init to no color QuickDraw
  158.     SysEnvirons(1, &theWorld);    //Check how old this system is
  159.     if (theWorld.machineType >= 0)
  160.     {     //Negative means really old
  161.         HasColorQD = theWorld.hasColorQD;     //Flag for Color QuickDraw being available
  162.     }
  163. }
  164.