home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / PRGrUtil.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.1 KB  |  217 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRGrUtil.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef PRGRUTIL_H
  13. #include "PRGrUtil.h"
  14. #endif
  15.  
  16. #ifndef FWRECT_H
  17. #include "FWRect.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifdef FW_BUILD_MAC
  29. #pragma segment FWGraphx_PrivateGrUtil
  30. #endif
  31.  
  32. #ifdef FW_BUILD_MAC
  33. //----------------------------------------------------------------------------------------
  34. //    FW_PrivMacGetPortTextStyle
  35. //----------------------------------------------------------------------------------------
  36.  
  37. void SL_API    FW_PrivMacGetPortTextStyle(TextStyle& theTextStyle)
  38. {
  39.     GrafPtr curPort = FW_QDGlobals.thePort;
  40.     theTextStyle.tsFont = curPort->txFont;
  41.     theTextStyle.tsFace = curPort->txFace;
  42.     theTextStyle.tsSize = curPort->txSize;
  43. }
  44. #endif
  45.  
  46. #ifdef FW_BUILD_MAC
  47. //----------------------------------------------------------------------------------------
  48. //    FW_PrivMacSetPortTextStyle
  49. //----------------------------------------------------------------------------------------
  50.  
  51. void SL_API    FW_PrivMacSetPortTextStyle(const TextStyle& theTextStyle)
  52. {
  53.     ::TextFont(theTextStyle.tsFont);
  54.     ::TextFace(theTextStyle.tsFace);
  55.     ::TextSize(theTextStyle.tsSize);
  56. #endif
  57.  
  58. #ifdef FW_BUILD_WIN
  59.  
  60. //----------------------------------------------------------------------------------------
  61. // FW_WinPrivGetDisplayColorInfo
  62. //----------------------------------------------------------------------------------------
  63.  
  64. void SL_API    FW_PrivWinGetDisplayColorInfo(short& planeCount, short& bitsPixel)
  65. {
  66.     static short gPlaneCount = -1;
  67.     static short gBitsPixel = -1;
  68.     
  69.     if(gPlaneCount == -1)
  70.     {
  71.         HDC hDC = ::GetDC(NULL);
  72.         gPlaneCount = (short) ::GetDeviceCaps(hDC, PLANES);
  73.         gBitsPixel = (short) ::GetDeviceCaps(hDC, BITSPIXEL);
  74.         ::ReleaseDC(NULL, hDC);
  75.     }
  76.     
  77.     planeCount = gPlaneCount;
  78.     bitsPixel = gBitsPixel;
  79. }
  80.  
  81. #endif
  82.  
  83. #ifdef FW_BUILD_MAC
  84. //----------------------------------------------------------------------------------------
  85. //    FW_PrivMacGetMacTransferMode
  86. //----------------------------------------------------------------------------------------
  87.  
  88. static const short FW_gTransferModes[] =
  89. {
  90.     patCopy,            //    FW_kCopy
  91.     notPatCopy,            //    FW_kNotCopy
  92.     patOr,                //    FW_kOr
  93.     notPatOr,            //    FW_kNotOr
  94.     patXor,                //    FW_kXOr
  95.     notPatXor,            //    FW_kNotXOr
  96.     patBic,                //    FW_kClear
  97.     notPatBic,            //    FW_kNotClear
  98.     hilitetransfermode,    //    FW_kHilite
  99.     patCopy,            //    FW_kErase
  100.     patCopy,            //    FW_kInvert
  101.     hilitetransfermode,    //    FW_kSystemHilite
  102. };
  103.  
  104. short FW_PrivMacGetMacTransferMode(FW_TransferModes transferMode)
  105. {
  106.     if ((transferMode & 0xFFFF0000) == 0)
  107.         return (short)transferMode;        // Native transfer mode
  108.     else
  109.     {
  110.         FW_ASSERT(transferMode <= FW_kPrivLastTransferMode);
  111.         return FW_gTransferModes[transferMode & 0x0000FFFF];
  112.     }
  113. }
  114. #endif
  115.  
  116. #ifdef FW_BUILD_WIN
  117. //----------------------------------------------------------------------------------------
  118. //    FW_PrivWinConvertRasterOp
  119. //----------------------------------------------------------------------------------------
  120. static const DWORD FW_gWinRasterOps[] =    
  121. {
  122.     SRCCOPY,        //    FW_kCopy
  123.     NOTSRCCOPY,        //     FW_kNotCopy
  124.     SRCPAINT,        //  FW_kOr
  125.     MERGEPAINT,        //    FW_kNotOr
  126.     SRCINVERT,        //    FW_kXOr
  127.     0x00990066UL,    //    FW_kNotXOr
  128.     SRCAND,            //    FW_kClear
  129.     0x00440328UL,    //    FW_kNotClear
  130.     SRCINVERT,         //    FW_kHilite
  131.     SRCCOPY,         //    FW_kErase
  132.     SRCINVERT         //    FW_kInvert
  133.     SRCINVERT,         //    FW_kSystemHilite
  134. };
  135.  
  136. DWORD FW_PrivWinConvertRasterOp(FW_TransferModes transferMode)
  137. {
  138.     if ((transferMode & 0xFFFF0000L) == 0)
  139.         return (DWORD)transferMode;        // Native Raster ops
  140.     else
  141.     {
  142.         FW_ASSERT(transferMode <= FW_kLastTransferMode);
  143.         return FW_gWinRasterOps[transferMode & 0x0000FFFFL];
  144.     }
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. //    FW_PrivWinROP2
  149. //----------------------------------------------------------------------------------------
  150.  
  151. //     Don't forget than on windows black and white are inverted.
  152. //    That's why it seems that the xxNOTxx is at the wrong place
  153. static const int FW_gTransferModes[] =
  154. {
  155.     R2_COPYPEN,            //    FW_kCopy
  156.     R2_NOTCOPYPEN,         //    FW_kNotCopy
  157.     R2_NOTMERGEPEN,     //    FW_kOr
  158.     R2_MERGEPEN,        //    FW_kNotOr
  159.     R2_NOTXORPEN,         //    FW_kXOr
  160.     R2_XORPEN,            //    FW_kNotXOr        
  161.     R2_NOTMASKPEN,         //    FW_kClear
  162.     R2_MASKPEN,            //    FW_kNotClear
  163.     R2_NOTXORPEN,         //    FW_kHilite
  164.     R2_COPYPEN,             //    FW_kErase
  165.     R2_NOTXORPEN         //    FW_kInvert
  166.     R2_NOTXORPEN,         //    FW_kSystemHilite
  167. };
  168.  
  169. int FW_PrivWinROP2(FW_TransferModes transferMode)
  170. {
  171.     if ((transferMode & 0xFFFF0000L) == 0)
  172.         return (int)transferMode;        // Native transfer mode
  173.     else
  174.     {
  175.         FW_ASSERT(transferMode <= FW_kLastTransferMode);
  176.         return FW_gTransferModes[transferMode & 0x0000FFFFL];
  177.     }
  178. }
  179.  
  180. #endif
  181.  
  182. //----------------------------------------------------------------------------------------
  183. //    FW_PrivCalcArcPoints
  184. //----------------------------------------------------------------------------------------
  185.  
  186. void SL_API FW_PrivCalcArcPoints(const FW_CPlatformRect& rect,
  187.                                  short angle,
  188.                                  FW_CPlatformPoint& arcPoint)
  189. {
  190.     FW_Fixed fxRad = (FW_IntToFixed(angle) * FW_kFixedPI) / FW_IntToFixed(180);
  191.  
  192.     FW_PlatformCoordinate middleX = ((long) rect.right + rect.left) / 2;
  193.     FW_PlatformCoordinate middleY = ((long) rect.bottom + rect.top) / 2;
  194.  
  195.     FW_Fixed halfX = FW_IntToFixed(((long) rect.right - rect.left) / 2);
  196.     FW_Fixed halfY = FW_IntToFixed(((long) rect.bottom - rect.top) / 2);
  197.  
  198.     short shortX =  FW_FixedToInt(halfX * FW_Sin(fxRad));
  199.     short shortY = -FW_FixedToInt(halfY * FW_Cos(fxRad));
  200.  
  201.     arcPoint.Set(shortX + middleX, shortY + middleY);
  202. }
  203.  
  204. #ifdef FW_BUILD_MAC
  205. //----------------------------------------------------------------------------------------
  206. //    FW_PrivMacSetStdColors
  207. //----------------------------------------------------------------------------------------
  208.  
  209. void SL_API FW_PrivMacSetStdColors()
  210. {
  211.     RGBColor macBlackColor = { 0x0000, 0x0000, 0x0000 };
  212.     ::RGBForeColor(&macBlackColor);
  213.     RGBColor macWhiteColor = { 0xFFFF, 0xFFFF, 0xFFFF };
  214.     ::RGBBackColor(&macWhiteColor);
  215. }
  216. #endif