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

  1. //========================================================================================
  2. //
  3. //    File:                FWGrUtil.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 FWGRUTIL_H
  13. #include "FWGrUtil.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. #ifndef FWGCONST_H
  29. #include "FWGConst.h"
  30. #endif
  31.  
  32. #ifndef SLREGION_H
  33. #include "SLRegion.h"
  34. #endif
  35.  
  36. #ifndef FWODGEOM_H
  37. #include "FWODGeom.h"
  38. #endif
  39.  
  40. #ifndef FWERRORS_H
  41. #include "FWErrors.h"
  42. #endif
  43.  
  44. // ----- Foundation Includes -----
  45.  
  46. #ifndef FWPRIDEB_H
  47. #include "FWPriDeb.h"
  48. #endif
  49.  
  50. // ----- OpenDoc Includes -----
  51.  
  52. #ifndef SOM_ODShape_xh
  53. #include <Shape.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODTransform_xh
  57. #include <Trnsform.xh>
  58. #endif
  59.  
  60. // ----- C Includes -----
  61.  
  62. #if defined(FW_BUILD_MAC) & !defined(__FP__)
  63. #include <FP.h>
  64. #endif
  65.  
  66. #if defined(FW_BUILD_WIN) & !defined(__MATH_H)
  67. #include <Math.h>
  68. #endif
  69.  
  70. #ifdef FW_DEBUG
  71. #include <stdio.h>        // for sprintf()
  72. #endif
  73.  
  74. // ------ Platform includes ------
  75.  
  76. #if defined(FW_BUILD_MAC) & !defined(__QDOFFSCREEN__)
  77. #include <QDOffscreen.h>
  78. #endif
  79.  
  80. //========================================================================================
  81. //    RunTime Info
  82. //========================================================================================
  83.  
  84. #ifdef FW_BUILD_MAC
  85. #pragma segment FWGraphx_GrUtil
  86. #endif
  87.  
  88. //========================================================================================
  89. //    Global Methods
  90. //========================================================================================
  91.  
  92. //-------------------------------------------------------------------------
  93. // FW_CreateLineODShape
  94. //-------------------------------------------------------------------------
  95.  
  96. ODShape* FW_CreateLineODShape(Environment *ev, const FW_CPoint& from, const FW_CPoint& to, FW_Fixed penSize)
  97. {
  98.     FW_CPoint lineThickness(penSize, penSize);
  99.     
  100.     ODShape* shape = ::FW_NewODShape(ev);
  101.     ODRgnHandle shapeRgn = ::FW_CreateLineRegion(from, to, lineThickness);
  102.     if(shapeRgn == nil)
  103.         FW_SetEvError(ev, FW_xRegionOverflow);
  104.     else
  105.         ::FW_SetShapeRegion(ev, shape, shapeRgn);
  106.     return shape;
  107. }
  108.  
  109. ODPolygon* FW_CreateODPolygon(Environment *ev, long inPointCount, const FW_SPoint* inPoints)
  110. {
  111. FW_UNUSED(ev);
  112.  
  113.     ODPolygon *poly = NULL;
  114.     ODPoint *points = new ODPoint[inPointCount];
  115.  
  116.     if(points != NULL)
  117.     {
  118.         poly = new ODPolygon;            
  119.  
  120.         if(poly != NULL)
  121.         {
  122.             for(long ixPoint = 0; ixPoint < inPointCount; ixPoint++)
  123.             {
  124.                 points[ixPoint].x = inPoints[ixPoint].x.fRep;
  125.                 points[ixPoint].y = inPoints[ixPoint].y.fRep;
  126.             }
  127.  
  128.             poly->SetVertices(inPointCount, points);
  129.         }
  130.         
  131.         delete [] points;
  132.     }
  133.     
  134.     return poly;
  135. }
  136.  
  137. ODShape* FW_CreatePolygonODShape(Environment *ev, long inPointCount, const FW_SPoint* inPoints)
  138. {
  139.     ODShape* shape = NULL;
  140.  
  141.     ODPolygon *poly = FW_CreateODPolygon(ev, inPointCount, inPoints);
  142.  
  143.     if(poly == NULL)
  144.         FW_SetEvError(ev, FW_xMemoryExhausted);
  145.     else
  146.     {
  147.         shape = ::FW_NewODShape(ev);
  148.         
  149.         if(shape != NULL)
  150.             shape = shape->SetPolygon(ev, poly);
  151.         else
  152.             delete poly;
  153.     }
  154.  
  155.     return shape;
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. //    FW_CreateOvalODShape
  160. //----------------------------------------------------------------------------------------
  161.  
  162. ODShape* FW_CreateOvalODShape(Environment *ev, const FW_CRect& rect)
  163. {
  164.     ODShape* shape = ::FW_NewODShape(ev);
  165.     ODRgnHandle shapeRgn = ::FW_CreateOvalRegion(rect);
  166.     if(shapeRgn == nil)
  167.         FW_SetEvError(ev, FW_xRegionOverflow);
  168.     else
  169.         ::FW_SetShapeRegion(ev, shape, shapeRgn);
  170.     return shape;
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. //    FW_CreateArcODShape
  175. //----------------------------------------------------------------------------------------
  176.  
  177. ODShape* FW_CreateArcODShape(Environment *ev, const FW_CRect& rect, short startAngle, short arcAngle)
  178. {
  179.     ODShape* shape = ::FW_NewODShape(ev);
  180.     ODRgnHandle shapeRgn = ::FW_CreateArcRegion(rect, startAngle, arcAngle);
  181.     if(shapeRgn == nil)
  182.         FW_SetEvError(ev, FW_xRegionOverflow);
  183.     else
  184.         ::FW_SetShapeRegion(ev, shape, shapeRgn);
  185.     return shape;
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    FW_CreateRoundRectODShape
  190. //----------------------------------------------------------------------------------------
  191.  
  192. ODShape* FW_CreateRoundRectODShape(Environment *ev, const FW_CRect& rect, const FW_CPoint& ovalSize)
  193. {
  194.     ODShape* shape = ::FW_NewODShape(ev);
  195.     ODRgnHandle shapeRgn = ::FW_CreateRoundRectRegion(rect, ovalSize);
  196.     if(shapeRgn == nil)
  197.         FW_SetEvError(ev, FW_xRegionOverflow);
  198.     else
  199.         ::FW_SetShapeRegion(ev, shape, shapeRgn);
  200.     return shape;
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. //    FW_OutlineODShape
  205. //----------------------------------------------------------------------------------------
  206.  
  207. void FW_OutlineODShape(Environment *ev, ODShape* odShapeToOutline, FW_Fixed outlineSize)
  208. {
  209.     ODShape* odTempShape = ::FW_NewODShape(ev, odShapeToOutline);
  210.     
  211.     if (outlineSize <= FW_kFixed0)
  212.         outlineSize = FW_kFixedPos1;
  213.         
  214.     odTempShape->Outset(ev, - FW_FixedToODFixed(outlineSize));
  215.     
  216.     odShapeToOutline->Subtract(ev, odTempShape);
  217.     odTempShape->Release(ev);
  218. }
  219.  
  220. #ifdef FW_BUILD_MAC
  221. //========================================================================================
  222. //    class FW_CMacTempPort
  223. //========================================================================================
  224.  
  225. FW_DEFINE_AUTO(FW_CMacTempPort)
  226.  
  227. //----------------------------------------------------------------------------------------
  228. //    FW_CMacTempPort::PrivSaveAndSet
  229. //----------------------------------------------------------------------------------------
  230.  
  231. void FW_CMacTempPort::PrivSaveAndSet(CGrafPtr tempPort, GDHandle tempDevice)
  232. {
  233.     ::GetGWorld(&fMacPort, &fGDevice);
  234.  
  235.     if (tempPort != NULL)
  236.         SetGWorld(tempPort, tempDevice);
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    FW_CMacTempPort::FW_CMacTempPort
  241. //----------------------------------------------------------------------------------------
  242.  
  243. FW_CMacTempPort::FW_CMacTempPort(CGrafPtr tempPort /* = NULL */, GDHandle tempDevice /* = NULL */)
  244. {
  245.     PrivSaveAndSet(tempPort, tempDevice);
  246.         
  247.     FW_END_CONSTRUCTOR
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    FW_CMacTempPort::FW_CMacTempPort
  252. //----------------------------------------------------------------------------------------
  253.  
  254. FW_CMacTempPort::FW_CMacTempPort(GrafPtr tempPort, GDHandle tempDevice /* = NULL */)
  255. {
  256.     PrivSaveAndSet((CGrafPtr) tempPort, tempDevice);
  257.         
  258.     FW_END_CONSTRUCTOR
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //    FW_CMacTempPort::~FW_CMacTempPort
  263. //----------------------------------------------------------------------------------------
  264.  
  265. FW_CMacTempPort::~FW_CMacTempPort()
  266. {
  267.     FW_START_DESTRUCTOR
  268.     
  269.     ::SetGWorld(fMacPort, fGDevice);
  270. }
  271.  
  272. #endif
  273.  
  274.