home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / SAT 2.4.0 / SAT / Add-ons / Load faces / FaceFromText.c < prev    next >
Encoding:
Text File  |  1997-02-21  |  2.9 KB  |  120 lines  |  [TEXT/Rich]

  1. // **************************************
  2. // * C Translation by Richard Bannister *
  3. // *                                    *
  4. // * Titan Software                     *
  5. // * 76 Stillorgan Wood                 *
  6. // * Stillorgan, Co. Dublin             *
  7. // * Republic of Ireland                *
  8. // *                                    *
  9. // * titan@indigo.ie                    *
  10. // * http://aoife.indigo.ie/~titan/     *
  11. // **************************************
  12.  
  13. // A procedure for creating a face from a string. It uses the font, size
  14. and color from the current port.
  15.  
  16. #include "SAT.h"
  17.  
  18. #ifndef THINKC
  19. #define thePort qd.thePort
  20. #endif
  21.  
  22. pascal FacePtr FaceFromText (Str255 myString, short shadow);
  23.  
  24. pascal FacePtr FaceFromText (Str255 myString, short shadow)
  25. {
  26.         FacePtr theTextFace;
  27.         Rect r;
  28.         short height, width;
  29.  
  30.         FontInfo info;
  31.         short txFont;
  32.         Style txFace;
  33.         short txSize;
  34.         RGBColor txColor;
  35.         long txColor2;
  36.         SATPort savePort;
  37.  
  38.         SATGetPort(&savePort);
  39.  
  40.         // Get font, etc, from the current port.
  41.  
  42.         GetFontInfo(&info);
  43.  
  44.         width = StringWidth(myString) + shadow;
  45.         height = info.ascent + info.descent + shadow;
  46.  
  47.         txFont = thePort->txFont;
  48.         txSize = thePort->txSize;
  49.         txFace = thePort->txFace;
  50.  
  51.         if (gSAT.colorFlag)
  52.                 GetForeColor(&txColor);
  53.         else
  54.                 txColor2 = thePort->fgColor;
  55.  
  56.         // Create the face
  57.  
  58.         SetRect(&r, 0, 0, width, height);
  59.         theTextFace = SATNewFace(&r);
  60.  
  61.         SATSetPortFace(theTextFace);
  62.  
  63.         // Set up the face-port with the parameters we got above
  64.  
  65.         TextFont(txFont);
  66.         TextSize(txSize);
  67.         TextFace(txFace);
  68.  
  69.         if (gSAT.colorFlag)
  70.                 RGBForeColor(&txColor);
  71.         else
  72.                 ForeColor(txColor2);
  73.  
  74.         EraseRect(&theTextFace->iconMask.bounds);
  75.  
  76.         // Draw Shadow, if any
  77.  
  78.         if (shadow != 0)
  79.         {
  80.                 MoveTo(shadow, info.ascent + shadow);
  81.                 ForeColor(blackColor);
  82.                 DrawString(myString);
  83.         }
  84.  
  85.         // Draw Text
  86.  
  87.         if (gSAT.colorFlag)
  88.                 RGBForeColor(&txColor);
  89.         else
  90.                 ForeColor(txColor2);
  91.  
  92.         MoveTo(0, info.ascent);
  93.         DrawString(myString);
  94.  
  95.         // Set the forecolor to black before leaving!
  96.         ForeColor(blackColor);
  97.  
  98.         // Draw Mask
  99.  
  100.         SATSetPortMask(theTextFace);
  101.         TextFont(txFont);
  102.         TextSize(txSize);
  103.         TextFace(txFace);
  104.         EraseRect(&theTextFace->iconMask.bounds);
  105.         MoveTo(0, info.ascent);
  106.         DrawString(myString);
  107.         if (shadow != 0)
  108.         {
  109.                 MoveTo(shadow, info.ascent + shadow);
  110.                 DrawString(myString);
  111.         }
  112.  
  113.         // Set the port back
  114.  
  115.         SATSetPort(&savePort);
  116.         SATChangedFace(theTextFace);
  117.  
  118.         return theTextFace;
  119. }
  120.