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 / FWPat.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.6 KB  |  283 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPat.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 FWPAT_H
  13. #include "FWPat.h"
  14. #endif
  15.  
  16. #ifndef FWCOLOR_H
  17. #include "FWColor.h"
  18. #endif
  19.  
  20. #ifndef FWSTRMRW_H
  21. #include "FWStrmRW.h"
  22. #endif
  23.  
  24. //========================================================================================
  25. // Runtime Informations
  26. //========================================================================================
  27.  
  28. #ifdef FW_BUILD_MAC
  29. #pragma segment FWGraphics_Pattern
  30. #endif
  31.  
  32. //========================================================================================
  33. //    Template instantiation
  34. //========================================================================================
  35.  
  36. #include "FWGrRef.tpp"
  37.  
  38. FW_DEFINE_AUTO_TEMPLATE(FW_TGrRefPtr, FW_HPattern)
  39.  
  40. #ifdef FW_USE_TEMPLATE_PRAGMAS
  41.  
  42. #pragma template_access public
  43. #pragma template FW_TGrRefPtr<FW_HPattern>
  44.  
  45. #else
  46.  
  47. template class FW_TGrRefPtr<FW_HPattern>;
  48.  
  49. #endif
  50.  
  51. //========================================================================================
  52. //    class FW_CPattern
  53. //========================================================================================
  54.  
  55. FW_DEFINE_AUTO(FW_CPattern)
  56.     
  57. //----------------------------------------------------------------------------------------
  58. //    FW_PrivAcquireGrRep
  59. //----------------------------------------------------------------------------------------
  60.  
  61. void FW_PrivAcquireGrRep(FW_HPattern rep)
  62. {
  63.     if (rep != 0)
  64.         FW_PrivPattern_Acquire(rep);
  65. }
  66.  
  67. //----------------------------------------------------------------------------------------
  68. //    FW_PrivReleaseGrRep
  69. //----------------------------------------------------------------------------------------
  70.  
  71. void FW_PrivReleaseGrRep(FW_HPattern rep)
  72. {
  73.     if (rep != 0)
  74.         FW_PrivPattern_Release(rep);
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. //    FW_CPattern::FW_CPattern
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_CPattern::FW_CPattern()
  82. {
  83.     FW_END_CONSTRUCTOR
  84. }
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    FW_CPattern::FW_CPattern
  88. //----------------------------------------------------------------------------------------
  89.  
  90. FW_CPattern::FW_CPattern(FW_HPattern rep)
  91. {
  92.     SetRep(rep);
  93.     FW_END_CONSTRUCTOR
  94. }
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    FW_CPattern::FW_CPattern
  98. //----------------------------------------------------------------------------------------
  99.  
  100. FW_CPattern::FW_CPattern(const FW_BitPattern& bits)
  101. {
  102.     FW_PlatformError error;
  103.     FW_HPattern rep = FW_PrivPattern_CreateBW(bits, &error);
  104.     FW_FailOnError(error);
  105.     SetRep(rep);
  106.     FW_END_CONSTRUCTOR
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CPattern::FW_CPattern
  111. //----------------------------------------------------------------------------------------
  112.  
  113. FW_CPattern::FW_CPattern(const FW_PixelPattern& pixels, short nbColors, const FW_CColor* colorTable)
  114. {
  115.     FW_PlatformError error;
  116.     FW_HPattern rep = FW_PrivPattern_CreateColor(pixels, nbColors, colorTable, &error);
  117.     FW_FailOnError(error);
  118.     SetRep(rep);
  119.     FW_END_CONSTRUCTOR
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    FW_CPattern::FW_CPattern
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_CPattern::FW_CPattern(FW_PlatformColorPattern pattern)
  127. {
  128.     FW_PlatformError error;
  129.     FW_HPattern rep = FW_PrivPattern_CreateFromPlatformColorPattern(pattern, &error);
  130.     FW_FailOnError(error);
  131.     SetRep(rep);
  132.     FW_END_CONSTRUCTOR
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_CPattern::FW_CPattern
  137. //----------------------------------------------------------------------------------------
  138.  
  139. FW_CPattern::FW_CPattern(const FW_CPattern& other) :
  140.     FW_TGrRefPtr<FW_HPattern>(other)
  141. {
  142.     FW_END_CONSTRUCTOR
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CPattern::FW_CPattern
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CPattern::~FW_CPattern()
  150. {
  151.     FW_START_DESTRUCTOR
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. //    FW_CPattern::operator=
  156. //----------------------------------------------------------------------------------------
  157.  
  158. FW_CPattern& FW_CPattern::operator=(const FW_CPattern& other)
  159. {
  160.     FW_TGrRefPtr<FW_HPattern>::operator=(other);
  161.     return *this;
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. //    FW_CPattern::operator=
  166. //----------------------------------------------------------------------------------------
  167.  
  168. FW_CPattern& FW_CPattern::operator=(const FW_BitPattern& bits)
  169. {
  170.     FW_PlatformError error;
  171.     FW_HPattern rep = FW_PrivPattern_CreateBW(bits, &error);
  172.     FW_FailOnError(error);
  173.     SetRep(rep);
  174.     return *this;
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. //    FW_CPattern::Copy
  179. //----------------------------------------------------------------------------------------
  180.  
  181. FW_CPattern    FW_CPattern::Copy() const
  182. {
  183.     FW_PlatformError error;
  184.     FW_HPattern rep = FW_PrivPattern_Copy(fRep, &error);
  185.     FW_FailOnError(error);
  186.     
  187.     FW_CPattern pattern;
  188.     pattern.SetRep(rep);
  189.     return pattern;
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    FW_CPattern::Invert
  194. //----------------------------------------------------------------------------------------
  195.  
  196. void FW_CPattern::Invert()
  197. {
  198.     FW_FailOnError(FW_PrivPattern_Invert(fRep));
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    FW_CPattern::FlipHorizontally
  203. //----------------------------------------------------------------------------------------
  204.  
  205. void FW_CPattern::FlipHorizontally()
  206. {
  207.     FW_FailOnError(FW_PrivPattern_FlipHorizontally(fRep));
  208. }
  209. //----------------------------------------------------------------------------------------
  210. //    FW_CPattern::FlipVertically
  211. //----------------------------------------------------------------------------------------
  212.  
  213. void FW_CPattern::FlipVertically()
  214. {
  215.     FW_FailOnError(FW_PrivPattern_FlipVertically(fRep));
  216. }
  217.     
  218. //----------------------------------------------------------------------------------------
  219. //    FW_CPattern::ShiftUp
  220. //----------------------------------------------------------------------------------------
  221.  
  222. void FW_CPattern::ShiftUp()
  223. {
  224.     FW_FailOnError(FW_PrivPattern_ShiftUp(fRep));
  225. }
  226.  
  227. //----------------------------------------------------------------------------------------
  228. //    FW_CPattern::ShiftDown
  229. //----------------------------------------------------------------------------------------
  230.  
  231. void FW_CPattern::ShiftDown()
  232. {
  233.     FW_FailOnError(FW_PrivPattern_ShiftDown(fRep));
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. //    FW_CPattern::ShiftLeft
  238. //----------------------------------------------------------------------------------------
  239.  
  240. void FW_CPattern::ShiftLeft()
  241. {
  242.     FW_FailOnError(FW_PrivPattern_ShiftLeft(fRep));
  243. }
  244.  
  245. //----------------------------------------------------------------------------------------
  246. //    FW_CPattern::ShiftRight
  247. //----------------------------------------------------------------------------------------
  248.  
  249. void FW_CPattern::ShiftRight()
  250. {
  251.     FW_FailOnError(FW_PrivPattern_ShiftRight(fRep));
  252. }
  253.  
  254. //========================================================================================
  255. //    Stream I/O
  256. //========================================================================================
  257.  
  258. //----------------------------------------------------------------------------------------
  259. //    operator>>
  260. //----------------------------------------------------------------------------------------
  261.  
  262. FW_CReadableStream& operator>>(FW_CReadableStream& stream, FW_CPattern& pattern)
  263. {
  264.     FW_PlatformError error;
  265.     FW_HPattern rep = FW_PrivPattern_Read(stream, &error);
  266.     FW_FailOnError(error);
  267.     pattern.SetRep(rep);
  268.     return stream;
  269. }
  270.  
  271. //----------------------------------------------------------------------------------------
  272. //    operator<<
  273. //----------------------------------------------------------------------------------------
  274.  
  275. FW_CWritableStream& operator<<(FW_CWritableStream& stream, const FW_CPattern& pattern)
  276. {
  277.     FW_PlatformError error;
  278.     FW_PrivPattern_Write(pattern.fRep, stream, &error);
  279.     FW_FailOnError(error);
  280.     return stream;
  281. }
  282.  
  283.