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

  1. //========================================================================================
  2. //
  3. //    File:                FWBndShp.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 FWBNDSHP_H
  13. #include "FWBndShp.h"
  14. #endif
  15.  
  16. #ifndef SLGRGLOB_H
  17. #include "SLGrGlob.h"
  18. #endif
  19.  
  20. #ifndef FWGC_H
  21. #include "FWGC.h"
  22. #endif
  23.  
  24. // ----- OpenDoc Includes -----
  25.  
  26. #ifndef _TRANSFORM_
  27. #include <Trnsform.xh>
  28. #endif
  29.  
  30. //========================================================================================
  31. //    RunTime Info
  32. //========================================================================================
  33.  
  34. #ifdef FW_BUILD_MAC
  35. #pragma segment fwgraphxshape
  36. #endif
  37.  
  38. FW_DEFINE_AUTO(FW_CBoundedShape)
  39. FW_DEFINE_CLASS_M1(FW_CBoundedShape, FW_CShape)
  40.  
  41. //========================================================================================
  42. //    class FW_CBoundedShape
  43. //========================================================================================
  44.  
  45. //----------------------------------------------------------------------------------------
  46. //    FW_CBoundedShape::FW_CBoundedShape
  47. //----------------------------------------------------------------------------------------
  48.  
  49. FW_CBoundedShape::FW_CBoundedShape(const FW_CBoundedShape& other) :
  50.     FW_CShape(other),
  51.     fRect(other.fRect)
  52. {
  53.     FW_END_CONSTRUCTOR
  54. }
  55.  
  56. //----------------------------------------------------------------------------------------
  57. //    FW_CBoundedShape::FW_CBoundedShape
  58. //----------------------------------------------------------------------------------------
  59.  
  60. FW_CBoundedShape::FW_CBoundedShape(const FW_CRect& rect,
  61.                                    FW_ERenderVerbs renderVerb,
  62.                                    const FW_CInk& ink,
  63.                                    const FW_CStyle& style,
  64.                                    const FW_CFont& font) :
  65.     FW_CShape(renderVerb, ink, style, font),
  66.     fRect(rect)
  67. {
  68.     FW_END_CONSTRUCTOR
  69. }
  70.  
  71. //----------------------------------------------------------------------------------------
  72. // FW_CBoundedShape::FW_CBoundedShape
  73. //----------------------------------------------------------------------------------------
  74.  
  75. FW_CBoundedShape::FW_CBoundedShape(FW_CReadableStream& stream) :
  76.     FW_CShape(stream)
  77. {
  78.     stream >> fRect;
  79.     FW_END_CONSTRUCTOR
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. //    FW_CBoundedShape::~FW_CBoundedShape
  84. //----------------------------------------------------------------------------------------
  85.  
  86. FW_CBoundedShape::~FW_CBoundedShape()
  87. {
  88.     FW_START_DESTRUCTOR
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    FW_CBoundedShape::operator=
  93. //----------------------------------------------------------------------------------------
  94.  
  95. FW_CBoundedShape& FW_CBoundedShape::operator=(const FW_CBoundedShape& other)
  96. {
  97.     if (this != &other)
  98.     {
  99.         FW_CShape::operator=(other);    
  100.         fRect = other.fRect;
  101.     }
  102.     
  103.     return *this;
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. //    FW_CBoundedShape::HitTest
  108. //----------------------------------------------------------------------------------------
  109. //    Only test if the point is inside the bounds
  110.  
  111. FW_Boolean FW_CBoundedShape::HitTest(FW_CGraphicContext& gc,
  112.                                      const FW_CPoint& test,
  113.                                      FW_Fixed tolerance) const
  114. {
  115. FW_UNUSED(gc);
  116.     if(fRenderVerb == FW_kNoRendering)
  117.         return FALSE;
  118.  
  119.     FW_CRect bounds(fRect);
  120.     bounds.Inset(-tolerance, -tolerance);
  121.     return bounds.Contains(test);
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. //    FW_CBoundedShape::Transform
  126. //----------------------------------------------------------------------------------------
  127.  
  128. void FW_CBoundedShape::Transform(Environment *ev, ODTransform* transform)
  129. {
  130.     fRect.Transform(ev, transform);
  131. }
  132.  
  133. //----------------------------------------------------------------------------------------
  134. //    FW_CBoundedShape::Inset
  135. //----------------------------------------------------------------------------------------
  136.  
  137. void FW_CBoundedShape::Inset(FW_Fixed h, FW_Fixed v)
  138. {
  139.     fRect.Inset(h, v);
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_CBoundedShape::GetBounds
  144. //----------------------------------------------------------------------------------------
  145.  
  146. void FW_CBoundedShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
  147. {
  148. FW_UNUSED(gc);
  149.  
  150.     rect = fRect;
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154. //    FW_CBoundedShape::GetAnchorPoint
  155. //----------------------------------------------------------------------------------------
  156.  
  157. FW_CPoint FW_CBoundedShape::GetAnchorPoint() const
  158. {
  159.     return fRect.TopLeft();
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CBoundedShape::InverseTransform
  164. //----------------------------------------------------------------------------------------
  165.  
  166. void FW_CBoundedShape::InverseTransform(Environment *ev, ODTransform* transform)
  167. {
  168.     fRect.InverseTransform(ev, transform);
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. //    FW_CBoundedShape::MoveShape
  173. //----------------------------------------------------------------------------------------
  174.  
  175. void FW_CBoundedShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
  176. {
  177.     fRect.left += deltaX;
  178.     fRect.top += deltaY;
  179.     fRect.right += deltaX;
  180.     fRect.bottom += deltaY;
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    FW_CBoundedShape::MoveShapeTo
  185. //----------------------------------------------------------------------------------------
  186.  
  187. void FW_CBoundedShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
  188. {
  189.     fRect.right += x - fRect.left;
  190.     fRect.bottom += y - fRect.top;
  191.     fRect.left = x;
  192.     fRect.top = y;
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196. //    FW_CBoundedShape::Flatten
  197. //----------------------------------------------------------------------------------------
  198.  
  199. void FW_CBoundedShape::Flatten(FW_CWritableStream& stream) const
  200. {
  201.     FW_CShape::Flatten(stream);
  202.     stream << fRect;
  203. }
  204.  
  205.