home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / PLATSHPE.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  11KB  |  444 lines

  1. /* @(#)Z 1.12 os2/src/imaging/realshps/PlatShpe.h, odimaging, od96os2, odos29646d 96/11/15 15:49:04 (96/10/04 11:53:44) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odimaging
  6.  *
  7.  *   CLASSES: none
  8.  *
  9.  *   ORIGINS: 82,27
  10.  *
  11.  *
  12.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13.  *   All Rights Reserved
  14.  *   Licensed Materials - Property of IBM
  15.  *   US Government Users Restricted Rights - Use, duplication or
  16.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17.  *       
  18.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24.  *   OR PERFORMANCE OF THIS SOFTWARE.
  25.  */
  26. /*====END_GENERATED_PROLOG========================================
  27.  */
  28.  
  29. /********************************************************************/
  30. /*                                                                  */
  31. /* Copyright (C) Apple Computer, Inc., 1994                         */
  32. /*                                                                  */
  33. /********************************************************************/
  34.  
  35. #ifndef _PLATSHAPE_
  36. #define _PLATSHAPE_
  37.  
  38.  
  39. // The following is really ugly.  This was merged from the os/2 code
  40. // base of 02/13/96.  These redefines are there to limit the amount
  41. // of porting by redefining methods, variables and constants from the
  42. // Mac definition to the OS/2 definition.  jab 04/12/96 
  43.  
  44. #ifdef _PLATFORM_OS2_
  45.  
  46. #undef kODQuickDraw
  47. #define kODQuickDraw kODPM
  48.  
  49. #define AsQDPoint AsPOINTL
  50. #define AsQDRect AsRECTL
  51. #define AsQDPolygon AsPOLYGON
  52. #define GetQDOffset GetOffset
  53. #define IsQDOffset IsIntegerOffset
  54. #define h x
  55. #define v y
  56.  
  57. #endif  // _PLATFORM_OS2_
  58.  
  59.  
  60. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
  61. typedef HRGN RgnHandle;
  62. #endif
  63. #if defined(_PLATFORM_UNIX_)
  64. typedef Region RgnHandle;
  65. #endif
  66.  
  67. // Helper functions for Mac system calls
  68.  
  69.  
  70.  
  71. #ifdef _PLATFORM_OS2_
  72.  
  73. inline HPS GetPresSpace( ) {
  74.    return WinGetScreenPS( HWND_DESKTOP );
  75. }
  76.  
  77. inline void ReleasePresSpace( HPS hps ) {
  78.    WinReleasePS(hps);
  79. }
  80.  
  81. #endif  // _PLATFORM_OS2_
  82.  
  83. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
  84. inline void RectRgn( HRGN  hrgn, PRECTL prcl ) {
  85.  
  86. #ifdef _PLATFORM_OS2_
  87.    HPS hps = GetPresSpace();
  88.    RECTL rcl = *prcl;
  89.    GpiSetRegion( hps, hrgn, 1, &rcl );
  90.    ReleasePresSpace( hps );
  91. #endif  // _PLATFORM_OS2_
  92.  
  93. #ifdef _PLATFORM_WIN32_
  94.    hrgn = CreateRectRgn( prcl->left, prcl->top, 
  95.                            prcl->right, prcl->bottom );
  96. #endif  // _PLATFORM_WIN32_
  97.  
  98. }
  99. #endif
  100.  
  101. #if defined(_PLATFORM_UNIX_)
  102. inline void RectRgn( ODRgnHandle hrgn, Rect prcl ) {
  103.    XUnionRectWithRegion(&prcl, hrgn, hrgn);
  104. }
  105. #endif
  106.  
  107. inline ODRgnHandle NewRgn() {
  108.  
  109. #ifdef _PLATFORM_OS2_
  110.    HPS hps = GetPresSpace();
  111.    ODRgnHandle rgn = GpiCreateRegion( hps, 0, 0 );
  112.    ReleasePresSpace( hps );
  113.    return rgn;
  114. #endif  // _PLATFORM_OS2_
  115.  
  116. #ifdef _PLATFORM_WIN32_
  117.    ODRgnHandle rgn = CreateRectRgn( 0, 0, 0, 0 );
  118.    return rgn;
  119. #endif  // _PLATFORM_WIN32_
  120.  
  121. #ifdef _PLATFORM_UNIX_
  122.    ODRgnHandle rgn = XCreateRegion();
  123.    return rgn;
  124. #endif  // _PLATFORM_UNIX_
  125.  
  126. }
  127.  
  128.  
  129.  
  130. inline ODRgnHandle ODNewRgn() { return NewRgn(); }
  131.  
  132.  
  133.  
  134. #ifdef _PLATFORM_OS2_     
  135.  
  136. // SetRectRgn is defined as part of the standard Windows GDI library.
  137. // It's signature is:
  138. //    BOOL SetRectRgn( HRGN hrgn, int left, int top, int right, int bottom)
  139. //
  140. inline VOID SetRectRgn( ODRgnHandle rgn, int top, int left, int bottom, int right ) {
  141.    RECTL rcl;
  142.    rcl.xLeft = left;
  143.    rcl.xRight = right;
  144.    rcl.yTop = top;
  145.    rcl.yBottom = bottom;
  146.    HPS hps = GetPresSpace();
  147.    GpiSetRegion( hps, rgn, 1, &rcl );
  148.    ReleasePresSpace( hps );
  149.    
  150. }
  151.  
  152.  
  153. // EqualRgn is defined as part of the standard Windows GDI library.
  154. // It's signature is:
  155. //    BOOL EqualRgn( HRGN hrgn1, HRGN hrgn2)
  156. //
  157. inline BOOL EqualRgn( ODRgnHandle rgn1, ODRgnHandle rgn2 ) {
  158.    LONG lEquality;
  159.    HPS hps = GetPresSpace();
  160.    lEquality = GpiEqualRegion( hps, rgn1, rgn2 );
  161.    ReleasePresSpace( hps );
  162.    return ( lEquality == EQRGN_EQUAL );
  163. }
  164.  
  165. #endif  // _PLATFORM_OS2_
  166.  
  167. #ifdef _PLATFORM_UNIX_     
  168.  
  169. inline void SetRectRgn( ODRgnHandle rgn, int top, int left, int bottom, int right ) {
  170.    XRectangle rect;
  171.    rect.x = left;
  172.    rect.y = bottom;
  173.    rect.width = right - left;
  174.    rect.height = top - bottom;
  175.    XUnionRectWithRegion(&rect, rgn, rgn);
  176. }
  177.  
  178. inline ODBoolean EqualRgn( ODRgnHandle rgn1, ODRgnHandle rgn2 ) {
  179.    return ( XEqualRegion(rgn1, rgn2) );
  180. }
  181.  
  182. #endif  // _PLATFORM_UNIX_
  183.  
  184.  
  185. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
  186. inline BOOL EmptyRgn( ODRgnHandle rgn ) {
  187.  
  188. #ifdef _PLATFORM_OS2_     
  189.    RECTL rcl;
  190.    HPS hps = GetPresSpace();
  191.    LONG lComplexity = GpiQueryRegionBox( hps, rgn, &rcl );
  192.    ReleasePresSpace(hps);
  193.    return ( lComplexity == RGN_NULL || lComplexity == RGN_ERROR );
  194. #endif  // _PLATFORM_OS2_
  195.  
  196. #ifdef _PLATFORM_WIN32_
  197.    RECT rcl;
  198.    LONG lComplexity = GetRgnBox( rgn, &rcl );
  199.    return ( lComplexity == NULLREGION );
  200. #endif  // _PLATFORM_WIN32_
  201.  
  202. }
  203. #endif
  204.  
  205. #if defined(_PLATFORM_UNIX_)
  206. inline ODBoolean EmptyRgn( ODRgnHandle rgn ) {
  207.     return XEmptyRegion(rgn);
  208. }
  209. #endif
  210.  
  211.  
  212.  
  213. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
  214. inline BOOL PtInRgn( Point pt, ODRgnHandle rgn ) {
  215.  
  216. #ifdef _PLATFORM_OS2_     
  217.    HPS hps = GetPresSpace();
  218.    LONG lInside = GpiPtInRegion( hps, rgn, &pt );
  219.    ReleasePresSpace( hps );
  220.    return( lInside == PRGN_INSIDE ); 
  221. #endif  // _PLATFORM_OS2_
  222.  
  223. #ifdef _PLATFORM_WIN32_
  224.    return( PtInRegion( rgn, pt.x, pt.y ) );
  225. #endif  // _PLATFORM_WIN32_
  226.  
  227. }
  228. #endif
  229.  
  230. #if defined(_PLATFORM_UNIX_)
  231. inline ODBoolean PtInRgn( Point pt, ODRgnHandle rgn ) {
  232.     return XPointInRegion(rgn, pt.x, pt.y);
  233. }
  234. #endif
  235.  
  236.  
  237. inline void DisposeRgn( ODRgnHandle rgn ) {
  238.  
  239. #ifdef _PLATFORM_OS2_     
  240.    HPS hps = GetPresSpace();
  241.    GpiDestroyRegion( hps, rgn );
  242.    ReleasePresSpace( hps );
  243. #endif  // _PLATFORM_OS2_
  244.  
  245. #ifdef _PLATFORM_WIN32_
  246.    BOOL success = DeleteObject( rgn );
  247. #endif  // _PLATFORM_WIN32_
  248.  
  249. #ifdef _PLATFORM_UNIX_
  250.    XDestroyRegion(rgn);
  251. #endif  // _PLATFORM_UNIX_
  252.  
  253. }
  254.  
  255.  
  256.  
  257. #ifdef _PLATFORM_OS2_
  258.  
  259. // OffsetRgn is defined as part of the Windows GDI library.
  260. // It's signature is:
  261. //   int OffsetRgn( HRGN hrgn, int x, int y )
  262. //
  263. inline void OffsetRgn( ODRgnHandle rgn, int x, int y ) {
  264.    POINTL ptl = {x, y};
  265.    HPS hps = GetPresSpace();
  266.    GpiOffsetRegion( hps, rgn, &ptl );
  267.    ReleasePresSpace( hps );
  268.  
  269. }
  270.  
  271. #endif  // _PLATFORM_OS2_
  272.  
  273. #ifdef _PLATFORM_UNIX_
  274.  
  275. // OffsetRgn is defined as part of the Windows GDI library.
  276. // It's signature is:
  277. //   int OffsetRgn( HRGN hrgn, int x, int y )
  278. //
  279. inline void OffsetRgn( ODRgnHandle rgn, int x, int y ) {
  280.    XOffsetRegion(rgn, x, y);
  281. }
  282.  
  283. #endif  // _PLATFORM_UNIX_
  284.  
  285.  
  286.  
  287.  
  288.  
  289. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
  290. inline BOOL SectRect( Rect* r1, Rect* r2, Rect* sect ) {
  291.  
  292. #ifdef _PLATFORM_OS2_     
  293.    return WinIntersectRect( WinQueryAnchorBlock(HWND_DESKTOP), sect, r1, r2 );
  294. #endif  // _PLATFORM_OS2_
  295.  
  296. #ifdef _PLATFORM_WIN32_
  297.    return IntersectRect( sect, r1, r2 );
  298. #endif  // _PLATFORM_WIN32_
  299.  
  300. }
  301. #endif
  302.  
  303. #if defined(_PLATFORM_UNIX_)
  304.  
  305. #define max(a,b) (a)>(b) ? (a) : (b)
  306. #define min(a,b) (a)<(b) ? (a) : (b)
  307.  
  308. inline ODBoolean SectRect( Rect* r1, Rect* r2, Rect* sect ) {
  309.    int left1 = r1->x;
  310.    int bottom1 = r1->y;
  311.    int right1 = r1->x + r1->width;
  312.    int top1 = r1->y + r1->height;
  313.    int left2 = r2->x;
  314.    int bottom2 = r2->y;
  315.    int right2 = r2->x + r2->width;
  316.    int top2 = r2->y + r2->height;
  317.    int leftS = max(left1, left2);
  318.    int bottomS = max(bottom1, bottom2);
  319.    int rightS = min(right1, right2);
  320.    int topS = min(top1, top2);
  321.    
  322.    if ((leftS < rightS) && (bottomS < topS)) {
  323.      sect->x = leftS;
  324.      sect->y = bottomS;
  325.      sect->width = rightS - leftS;
  326.      sect->height = topS - bottomS;
  327.      return kODTrue;
  328.      }
  329.    else return kODFalse;
  330. }
  331.  
  332. #endif
  333.  
  334.  
  335.  
  336.  
  337.  
  338. inline void DiffRgn( ODRgnHandle srcRgn1, ODRgnHandle srcRgn2, ODRgnHandle dstRgn ) {
  339.  
  340. #ifdef _PLATFORM_OS2_     
  341.    HPS hps = GetPresSpace();
  342.    GpiCombineRegion( hps, dstRgn, srcRgn1, srcRgn2, CRGN_DIFF );
  343.    ReleasePresSpace( hps );
  344. #endif  // _PLATFORM_OS2_
  345.  
  346. #ifdef _PLATFORM_WIN32_
  347.    CombineRgn( dstRgn, srcRgn1, srcRgn2, RGN_DIFF );
  348. #endif  // _PLATFORM_WIN32_
  349.  
  350. #ifdef _PLATFORM_UNIX_
  351.    XSubtractRegion(srcRgn1, srcRgn2, dstRgn);
  352. #endif  // _PLATFORM_UNIX_
  353.  
  354. }
  355.  
  356.  
  357.  
  358.  
  359.  
  360. inline void UnionRgn( ODRgnHandle srcRgn1, ODRgnHandle srcRgn2, ODRgnHandle dstRgn ) {
  361.  
  362. #ifdef _PLATFORM_OS2_     
  363.    HPS hps = GetPresSpace();
  364.    GpiCombineRegion( hps, dstRgn, srcRgn1, srcRgn2, CRGN_OR );
  365.    ReleasePresSpace( hps );
  366. #endif  // _PLATFORM_OS2_
  367.  
  368. #ifdef _PLATFORM_WIN32_
  369.    CombineRgn( dstRgn, srcRgn1, srcRgn2, RGN_OR );
  370. #endif  // _PLATFORM_WIN32_
  371.  
  372. #ifdef _PLATFORM_UNIX_
  373.    XUnionRegion(srcRgn1, srcRgn2, dstRgn);
  374. #endif  // _PLATFORM_UNIX_
  375.  
  376. }
  377.  
  378.  
  379.  
  380.  
  381. inline void SectRgn( ODRgnHandle srcRgn1, ODRgnHandle srcRgn2, ODRgnHandle dstRgn ) {
  382.  
  383. #ifdef _PLATFORM_OS2_     
  384.    HPS hps = GetPresSpace();
  385.    GpiCombineRegion( hps, dstRgn, srcRgn1, srcRgn2, CRGN_AND );
  386.    ReleasePresSpace( hps );
  387. #endif  // _PLATFORM_OS2_
  388.  
  389. #ifdef _PLATFORM_WIN32_
  390.    CombineRgn( dstRgn, srcRgn1, srcRgn2, RGN_AND );
  391. #endif  // _PLATFORM_WIN32_
  392.  
  393. #ifdef _PLATFORM_UNIX_
  394.    XIntersectRegion(srcRgn1, srcRgn2, dstRgn);
  395. #endif  // _PLATFORM_UNIX_
  396.  
  397. }
  398.  
  399.  
  400. inline ODRgnHandle ODCopyRgnHandle( ODRgnHandle rgn ) {
  401.  
  402. #ifdef _PLATFORM_OS2_     
  403.    HPS hps = GetPresSpace();
  404.    HRGN hrgn = GpiCreateRegion(hps, 0, 0);
  405.    GpiCombineRegion(hps, hrgn, (RgnHandle)rgn, 0, CRGN_COPY);
  406.    ReleasePresSpace(hps);
  407.    return (ODRgnHandle)hrgn;
  408. #endif  // _PLATFORM_OS2_
  409.  
  410. #ifdef _PLATFORM_WIN32_
  411.    HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
  412.    CombineRgn( hrgn, rgn, 0, RGN_COPY );
  413.    return (ODRgnHandle)hrgn;
  414. #endif  // _PLATFORM_WIN32_
  415.  
  416. #ifdef _PLATFORM_UNIX_
  417.    Region newRgn = XCreateRegion();
  418.    XUnionRegion((Region)rgn, newRgn, newRgn);
  419.    return (ODRgnHandle)newRgn;
  420. #endif // _PLATFORM_UNIX_
  421. }
  422.  
  423. //
  424. // The following redefine of ODDebug was necessary as a temporary solution
  425. // to allow ASSERT, WARN, and other macros to be expanded.  Some conditions,
  426. // such as passing a NULL shape as input, were not detected at runtime and
  427. // the proper exceptions were not thrown.  The reason for this was that
  428. // the macros, as defined in ODDebug.h, are dependent on ODDebug being
  429. // equal to 1.  One of the system wide makefile defines ODDebug to 0.  The
  430. // following should override ODDebug and set it to 1.  This code was put
  431. // into this header file because it was common to the rest of the source
  432. // in the polyclip directory.  This code can be removed when the macros in
  433. // ODDebug.h are redesigned.  jab - 4/22/96.
  434. //
  435. #ifdef DEBUG
  436. #undef ODDebug
  437. #define ODDebug 1
  438. #endif
  439.  
  440. #endif // _PLATSHAPE_
  441.  
  442.  
  443.  
  444.