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

  1. //========================================================================================
  2. //
  3. //    File:                FWRRcShp.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 FWRRCSHP_H
  13. #include "FWRRcShp.h"
  14. #endif
  15.  
  16. #ifndef FWGC_H
  17. #include "FWGC.h"
  18. #endif
  19.  
  20. #ifndef SLGRGLOB_H
  21. #include "SLGrGlob.h"
  22. #endif
  23.  
  24. #ifndef FWGRUTIL_H
  25. #include "FWGrUtil.h"
  26. #endif
  27.  
  28. #ifndef FWFXMATH_H
  29. #include "FWFxMath.h"
  30. #endif
  31.  
  32. #ifndef SLRENDER_H
  33. #include "SLRender.h"
  34. #endif
  35.  
  36. // ----- Foundation Includes -----
  37.  
  38. #ifndef FWSTREAM_H
  39. #include "FWStream.h"
  40. #endif
  41.  
  42. //========================================================================================
  43. // File scope definitions
  44. //========================================================================================
  45.  
  46. #ifdef FW_BUILD_MAC
  47. #pragma segment FWGraphics_RoundRectShape
  48. #endif
  49.  
  50. //========================================================================================
  51. //    class FW_CRoundRectShape
  52. //========================================================================================
  53.  
  54. FW_DEFINE_AUTO(FW_CRoundRectShape)
  55. FW_DEFINE_CLASS_M1(FW_CRoundRectShape, FW_CBoundedShape)
  56.  
  57. // This class is archivable, but we provide the archiving implementation in a separate
  58. // translation unit in order to enable deadstripping of the archiving-related code
  59. // in parts that do not use archiving with this class.
  60.  
  61. //----------------------------------------------------------------------------------------
  62. //    FW_CRoundRectShape::FW_CRoundRectShape
  63. //----------------------------------------------------------------------------------------
  64.  
  65. FW_CRoundRectShape::FW_CRoundRectShape(const FW_CRoundRectShape& other) :
  66.     FW_CBoundedShape(other),
  67.     fOvalSize(other.fOvalSize)
  68. {
  69.     FW_END_CONSTRUCTOR
  70. }
  71.  
  72. //----------------------------------------------------------------------------------------
  73. //    FW_CRoundRectShape::FW_CRoundRectShape
  74. //----------------------------------------------------------------------------------------
  75.  
  76. FW_CRoundRectShape::FW_CRoundRectShape(const FW_CRect& rect,
  77.                                        const FW_CPoint& ovalSize,
  78.                                        FW_ERenderVerbs renderVerb,
  79.                                        const FW_CInk& ink,
  80.                                        const FW_CStyle& style) :
  81.     FW_CBoundedShape(rect, renderVerb, ink, style, FW_kNormalFont),
  82.     fOvalSize(ovalSize)
  83. {
  84.     FW_END_CONSTRUCTOR
  85. }
  86.  
  87. //----------------------------------------------------------------------------------------
  88. //    FW_CRoundRectShape::FW_CRoundRectShape
  89. //----------------------------------------------------------------------------------------
  90.  
  91. FW_CRoundRectShape::FW_CRoundRectShape(FW_CReadableStream& stream) :
  92.     FW_CBoundedShape(stream)
  93. {
  94.     stream >> fOvalSize;
  95.     FW_END_CONSTRUCTOR
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    FW_CRoundRectShape::~FW_CRoundRectShape
  100. //----------------------------------------------------------------------------------------
  101.  
  102. FW_CRoundRectShape::~FW_CRoundRectShape()
  103. {
  104.     FW_START_DESTRUCTOR
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    FW_CRoundRectShape::operator=
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_CRoundRectShape& FW_CRoundRectShape::operator=(const FW_CRoundRectShape& other)
  112. {
  113.     if (this != &other)
  114.     {
  115.         FW_CBoundedShape::operator=(other);    
  116.         fOvalSize = other.fOvalSize;
  117.     }
  118.     
  119.     return *this;
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    FW_CRoundRectShape::Render
  124. //----------------------------------------------------------------------------------------
  125.  
  126. void FW_CRoundRectShape::Render(FW_CGraphicContext& gc) const
  127. {    
  128.     FW_PrivRenderRoundRect(gc.GetEnvironment(),
  129.         gc,
  130.         fRect, fOvalSize,
  131.         GetRenderVerb(),
  132.         fInk,
  133.         fStyle);
  134.     FW_FailOnEvError(gc.GetEnvironment());
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    FW_CRoundRectShape::RenderRoundRect
  139. //----------------------------------------------------------------------------------------
  140.  
  141. void FW_CRoundRectShape::RenderRoundRect(FW_CGraphicContext& gc,
  142.                                         const FW_CRect& rect, 
  143.                                         const FW_CPoint& ovalSize,
  144.                                         FW_ERenderVerbs renderVerb, 
  145.                                         const FW_CInk& ink,
  146.                                         const FW_CStyle& style)
  147. {    
  148.     FW_PrivRenderRoundRect(gc.GetEnvironment(),
  149.         gc,
  150.         rect, ovalSize,
  151.         renderVerb,
  152.         ink,
  153.         style);
  154.     FW_FailOnEvError(gc.GetEnvironment());
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. //    FW_CRoundRectShape::HitTest
  159. //----------------------------------------------------------------------------------------
  160.  
  161. FW_Boolean FW_CRoundRectShape::HitTest(FW_CGraphicContext& gc,
  162.                                        const FW_CPoint& test,
  163.                                        FW_Fixed tolerance) const
  164. {
  165. FW_UNUSED(gc);
  166.  
  167.     if(fRenderVerb == FW_kNoRendering)
  168.         return FALSE;
  169.  
  170.     FW_CRect bounds(fRect);
  171.     bounds.Inset(-tolerance, -tolerance);
  172.     
  173.     if(::FW_PtInRoundRect(bounds, fOvalSize, test))
  174.     {
  175.         if (fRenderVerb == FW_kFrame)
  176.         {            
  177.             FW_Fixed inset = tolerance + GetPenSize();
  178.             bounds = fRect;
  179.             bounds.Inset(inset, inset);
  180.             return !::FW_PtInRoundRect(bounds, fOvalSize, test);
  181.         }
  182.  
  183.         return TRUE;
  184.     }
  185.  
  186.     return FALSE;
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. //    FW_CRoundRectShape::Copy
  191. //----------------------------------------------------------------------------------------
  192.  
  193. FW_CShape* FW_CRoundRectShape::Copy() const
  194. {
  195.     return FW_NEW(FW_CRoundRectShape, (*this));
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    FW_CRoundRectShape::GetGeometry
  200. //----------------------------------------------------------------------------------------
  201.  
  202. void FW_CRoundRectShape::GetGeometry(FW_CRect& rect, FW_CPoint& ovalSize) const
  203. {
  204.     ovalSize = fOvalSize;
  205.     rect = fRect;
  206. }
  207.  
  208. //----------------------------------------------------------------------------------------
  209. //    FW_CRoundRectShape::SetGeometry
  210. //----------------------------------------------------------------------------------------
  211.  
  212. void FW_CRoundRectShape::SetGeometry(const FW_CRect& rect, const FW_CPoint& ovalSize)
  213. {
  214.     fOvalSize = ovalSize;
  215.     fRect = rect;
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    FW_CRoundRectShape::Flatten
  220. //----------------------------------------------------------------------------------------
  221.  
  222. void FW_CRoundRectShape::Flatten(FW_CWritableStream& stream) const
  223. {
  224.     FW_CBoundedShape::Flatten(stream);
  225.     stream << fOvalSize;
  226. }
  227.  
  228.