home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WRECT.HPP < prev    next >
C/C++ Source or Header  |  1996-10-18  |  6KB  |  204 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. /*************************************************************************
  12.  *
  13.  * WRect --
  14.  *
  15.  *************************************************************************/
  16.  
  17. #ifndef _WRECT_HPP_INCLUDED
  18. #define _WRECT_HPP_INCLUDED
  19.  
  20. #ifndef _WNO_PRAGMA_PUSH
  21. #pragma pack(push,8);
  22. #pragma enum int;
  23. #endif
  24.  
  25. #ifndef _WDEF_HPP_INCLUDED
  26. #  include "wdef.hpp"
  27. #endif
  28. #ifndef _WPOINT_HPP_INCLUDED
  29. #  include "wpoint.hpp"
  30. #endif
  31. #ifndef _WSIZE_HPP_INCLUDED
  32. #  include "wsize.hpp"
  33. #endif
  34.  
  35. #ifdef _WIN16
  36. #ifndef _WINDEF_
  37. typedef struct tagRECT
  38. {
  39.     WInt     left;
  40.     WInt     top;
  41.     WInt     right;
  42.     WInt     bottom;
  43. } RECT, *PRECT;
  44. typedef const RECT FAR* LPCRECT;
  45. #endif
  46. typedef struct _RECTL 
  47. {
  48.     WLong    left;
  49.     WLong    top;
  50.     WLong    right;
  51.     WLong    bottom;
  52. } RECTL, *PRECTL, *LPRECTL;
  53. typedef const RECTL FAR* LPCRECTL;
  54. #else
  55. #ifndef _WINDEF_
  56. typedef struct tagRECT
  57. {
  58.     WLong    left;
  59.     WLong    top;
  60.     WLong    right;
  61.     WLong    bottom;
  62. } RECT, *PRECT;
  63. typedef const RECT FAR* LPCRECT;
  64.  
  65. typedef struct _RECTL 
  66. {
  67.     WLong    left;
  68.     WLong    top;
  69.     WLong    right;
  70.     WLong    bottom;
  71. } RECTL, *PRECTL, *LPRECTL;
  72. typedef const RECTL FAR* LPCRECTL;
  73. #endif
  74. #endif
  75.  
  76. class WCMCLASS WRect {
  77.  
  78.         /**********************************************************
  79.          * Data members
  80.          *********************************************************/
  81.  
  82.     public:
  83.     
  84.         WInt x;
  85.         WInt y;
  86.         WInt w;
  87.         WInt h;
  88.  
  89.     public:
  90.  
  91.         /**********************************************************
  92.          * Constructors and Destructors
  93.          *********************************************************/
  94.  
  95.         WRect() { x = y = w = h = 0; }
  96.         WRect( WInt nx, WInt ny, WInt nw, WInt nh )
  97.                  { x = nx; y = ny; w = nw; h = nh; }
  98.         WRect( const WRect & o ) { x = o.x; y = o.y; w = o.w; h = o.h; }
  99.         WRect( const RECT & o ); // WCMINLINE
  100.         WRect( const RECTL & o ); // WCMINLINE
  101.  
  102.         // Note: no destructor is defined and none will be generated
  103.         // because the class has simple types as data and no virtual
  104.         // functions and does not inherit from anyone.
  105.  
  106.         /**********************************************************
  107.          * Properties
  108.          *********************************************************/
  109.  
  110.         // RECT 
  111.         //
  112.         //    Convert to/from the Windows RECT type.
  113.  
  114.         RECT  GetRECT() const;
  115.         void  SetRECT( const RECT & r );
  116.  
  117.         // RECTL
  118.         //
  119.         //    Convert to/from the Windows RECTL type.
  120.  
  121.         RECTL GetRECTL() const; // WCMINLINE
  122.         void  SetRECTL( const RECTL & r ); // WCMINLINE
  123.  
  124.         /**********************************************************
  125.          * Methods
  126.          *********************************************************/
  127.  
  128.         // Contains
  129.         //
  130.         //    True if a point is contained within a rectangle.
  131.  
  132.         WBool Contains( const WPoint & point ) const; // WCMINLINE
  133.     
  134.         // Create
  135.         //
  136.         //    Initialize the rectangle.
  137.  
  138.         void Create() { x = y = w = h = 0; }
  139.         void Create( WInt nx, WInt ny, WInt nw, WInt nh )
  140.                { x = nx; y = ny; w = nw; h = nh; }
  141.         void Create( const WRect & o )
  142.                { x = o.x; y = o.y; w = o.w; h = o.h; }
  143.         void Create( const RECT & o ); // WCMINLINE
  144.         void Create( const RECTL & o ); // WCMINLINE
  145.  
  146.         // Inflate -- relative grow
  147.  
  148.         WBool Inflate( const WSize & s ); // WCMINLINE
  149.  
  150.         // Normalize
  151.  
  152.         WBool Normalize();
  153.  
  154.         // Translate -- relative move
  155.  
  156.         void Translate( const WPoint & pt ); // WCMINLINE
  157.  
  158.         // UnionWith
  159.  
  160.         void UnionWith( const WRect & rectangle );
  161.  
  162.         // IntersectWith
  163.  
  164.         WBool IntersectWith( const WRect & rectangle );
  165.     
  166.         // Intersects
  167.  
  168.         WBool Intersects( const WRect & rectangle ) const;
  169.     
  170.         /**********************************************************
  171.          * Operators
  172.          *********************************************************/
  173.  
  174.         // == operator
  175.  
  176.         int operator==( const WRect & o ) const; // WCMINLINE
  177.  
  178.         // != operator
  179.  
  180.         int operator!=( const WRect & o ) const; // WCMINLINE
  181.     
  182.         // = operator
  183.  
  184.         WRect & operator=( const WRect & o )
  185.             { x = o.x; y = o.y; w = o.w; h = o.h; return *this; }
  186.         WRect & operator=( const RECT & o ); // WCMINLINE
  187.         WRect & operator=( const RECTL & o ); // WCMINLINE
  188.  
  189. };
  190.  
  191. #ifdef WCM_ENABLE_INLINES
  192.   #ifndef WCM_NO_WRECT_INLINES
  193.     #define WCMINLINE inline
  194.     #include "wrect.inl"
  195.   #endif
  196. #endif
  197.  
  198. #ifndef _WNO_PRAGMA_PUSH
  199. #pragma enum pop;
  200. #pragma pack(pop);
  201. #endif
  202.  
  203. #endif // _WRECT_HPP_INCLUDED
  204.