region.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/region.h
  3. // Purpose:
  4. // Author: Robert Roebling
  5. // Copyright: (c) 1998 Robert Roebling
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_GTK_REGION_H_
  9. #define _WX_GTK_REGION_H_
  10. #ifdef __WXGTK3__
  11. typedef struct _cairo_region cairo_region_t;
  12. #endif
  13. // ----------------------------------------------------------------------------
  14. // wxRegion
  15. // ----------------------------------------------------------------------------
  16. class WXDLLIMPEXP_CORE wxRegion : public wxRegionBase
  17. {
  18. public:
  19. wxRegion() { }
  20. wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
  21. {
  22. InitRect(x, y, w, h);
  23. }
  24. wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight )
  25. {
  26. InitRect(topLeft.x, topLeft.y,
  27. bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
  28. }
  29. wxRegion( const wxRect& rect )
  30. {
  31. InitRect(rect.x, rect.y, rect.width, rect.height);
  32. }
  33. wxRegion( size_t n, const wxPoint *points,
  34. wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
  35. #if wxUSE_IMAGE
  36. wxRegion( const wxBitmap& bmp)
  37. {
  38. Union(bmp);
  39. }
  40. wxRegion( const wxBitmap& bmp,
  41. const wxColour& transColour, int tolerance = 0)
  42. {
  43. Union(bmp, transColour, tolerance);
  44. }
  45. #endif // wxUSE_IMAGE
  46. virtual ~wxRegion();
  47. // wxRegionBase methods
  48. virtual void Clear();
  49. virtual bool IsEmpty() const;
  50. #ifdef __WXGTK3__
  51. cairo_region_t* GetRegion() const;
  52. #else
  53. wxRegion(const GdkRegion* region);
  54. GdkRegion *GetRegion() const;
  55. #endif
  56. protected:
  57. virtual wxGDIRefData *CreateGDIRefData() const;
  58. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  59. // wxRegionBase pure virtuals
  60. virtual bool DoIsEqual(const wxRegion& region) const;
  61. virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const;
  62. virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const;
  63. virtual wxRegionContain DoContainsRect(const wxRect& rect) const;
  64. virtual bool DoOffset(wxCoord x, wxCoord y);
  65. virtual bool DoUnionWithRect(const wxRect& rect);
  66. virtual bool DoUnionWithRegion(const wxRegion& region);
  67. virtual bool DoIntersect(const wxRegion& region);
  68. virtual bool DoSubtract(const wxRegion& region);
  69. virtual bool DoXor(const wxRegion& region);
  70. // common part of ctors for a rectangle region
  71. void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
  72. private:
  73. DECLARE_DYNAMIC_CLASS(wxRegion)
  74. };
  75. // ----------------------------------------------------------------------------
  76. // wxRegionIterator: decomposes a region into rectangles
  77. // ----------------------------------------------------------------------------
  78. class WXDLLIMPEXP_CORE wxRegionIterator: public wxObject
  79. {
  80. public:
  81. wxRegionIterator();
  82. wxRegionIterator(const wxRegion& region);
  83. wxRegionIterator(const wxRegionIterator& ri) : wxObject(ri) { Init(); *this = ri; }
  84. ~wxRegionIterator();
  85. wxRegionIterator& operator=(const wxRegionIterator& ri);
  86. void Reset() { m_current = 0u; }
  87. void Reset(const wxRegion& region);
  88. bool HaveRects() const;
  89. operator bool () const { return HaveRects(); }
  90. wxRegionIterator& operator ++ ();
  91. wxRegionIterator operator ++ (int);
  92. wxCoord GetX() const;
  93. wxCoord GetY() const;
  94. wxCoord GetW() const;
  95. wxCoord GetWidth() const { return GetW(); }
  96. wxCoord GetH() const;
  97. wxCoord GetHeight() const { return GetH(); }
  98. wxRect GetRect() const;
  99. private:
  100. void Init();
  101. void CreateRects( const wxRegion& r );
  102. wxRegion m_region;
  103. wxRect *m_rects;
  104. int m_numRects;
  105. int m_current;
  106. DECLARE_DYNAMIC_CLASS(wxRegionIterator)
  107. };
  108. #endif
  109. // _WX_GTK_REGION_H_