1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2001-08-27 10:56:55 -04:00
|
|
|
// Name: wx/msw/region.h
|
1998-05-20 10:12:05 -04:00
|
|
|
// Purpose: wxRegion class
|
2003-03-17 05:34:04 -05:00
|
|
|
// Author: Julian Smart
|
1998-05-20 10:12:05 -04:00
|
|
|
// Modified by:
|
|
|
|
// Created: 01/02/97
|
|
|
|
// RCS-ID: $Id$
|
2004-05-23 10:56:36 -04:00
|
|
|
// Copyright: (c) 1997-2002 wxWidgets team
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:12:05 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-07 19:52:45 -04:00
|
|
|
#ifndef _WX_REGION_H_
|
|
|
|
#define _WX_REGION_H_
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
#include "wx/gdiobj.h"
|
1999-01-07 03:43:47 -05:00
|
|
|
#include "wx/gdicmn.h"
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
class WXDLLEXPORT wxRect;
|
|
|
|
class WXDLLEXPORT wxPoint;
|
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
enum wxRegionContain
|
|
|
|
{
|
|
|
|
wxOutRegion = 0,
|
|
|
|
wxPartRegion = 1,
|
|
|
|
wxInRegion = 2
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// So far, for internal use only
|
2001-08-27 10:56:55 -04:00
|
|
|
enum wxRegionOp
|
|
|
|
{
|
|
|
|
wxRGN_AND, // Creates the intersection of the two combined regions.
|
|
|
|
wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
|
|
|
|
wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
|
|
|
|
wxRGN_OR, // Creates the union of two combined regions.
|
|
|
|
wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
class WXDLLEXPORT wxRegion : public wxGDIObject
|
|
|
|
{
|
1998-05-20 10:12:05 -04:00
|
|
|
public:
|
2001-08-27 10:56:55 -04:00
|
|
|
wxRegion();
|
2000-02-06 07:12:25 -05:00
|
|
|
wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
|
1998-05-20 10:12:05 -04:00
|
|
|
wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
|
|
|
|
wxRegion(const wxRect& rect);
|
1998-07-27 05:47:57 -04:00
|
|
|
wxRegion(WXHRGN hRegion); // Hangs on to this region
|
2001-08-27 10:56:55 -04:00
|
|
|
wxRegion(size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
|
2004-06-03 17:13:52 -04:00
|
|
|
wxRegion( const wxBitmap& bmp)
|
|
|
|
{
|
|
|
|
Union(bmp);
|
|
|
|
}
|
2003-03-28 18:05:05 -05:00
|
|
|
wxRegion( const wxBitmap& bmp,
|
2004-06-03 17:13:52 -04:00
|
|
|
const wxColour& transColour, int tolerance = 0)
|
2003-03-28 18:05:05 -05:00
|
|
|
{
|
|
|
|
Union(bmp, transColour, tolerance);
|
|
|
|
}
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
virtual ~wxRegion();
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
// Modify region
|
2002-01-31 11:00:13 -05:00
|
|
|
// -------------
|
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
// Clear current region
|
2002-01-31 11:00:13 -05:00
|
|
|
void Clear();
|
|
|
|
|
|
|
|
// Move the region
|
|
|
|
bool Offset(wxCoord x, wxCoord y);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
// Union rectangle or region with this.
|
2002-01-31 11:00:13 -05:00
|
|
|
bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); }
|
|
|
|
bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); }
|
|
|
|
bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
// Intersect rectangle or region with this.
|
2002-01-31 11:00:13 -05:00
|
|
|
bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); }
|
|
|
|
bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); }
|
|
|
|
bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
// Subtract rectangle or region from this:
|
1998-05-20 10:12:05 -04:00
|
|
|
// Combines the parts of 'this' that are not part of the second region.
|
2002-01-31 11:00:13 -05:00
|
|
|
bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); }
|
|
|
|
bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); }
|
|
|
|
bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); }
|
2001-08-27 10:56:55 -04:00
|
|
|
|
|
|
|
// XOR: the union of two combined regions except for any overlapping areas.
|
2002-01-31 11:00:13 -05:00
|
|
|
bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); }
|
|
|
|
bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); }
|
|
|
|
bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); }
|
2001-08-27 10:56:55 -04:00
|
|
|
|
|
|
|
// Information on region
|
2002-01-31 11:00:13 -05:00
|
|
|
// ---------------------
|
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
// Outer bounds of region
|
|
|
|
void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
|
2002-12-04 09:11:26 -05:00
|
|
|
wxRect GetBox() const ;
|
2001-08-27 10:56:55 -04:00
|
|
|
|
|
|
|
// Is region empty?
|
2002-12-04 09:11:26 -05:00
|
|
|
bool Empty() const;
|
|
|
|
inline bool IsEmpty() const { return Empty(); }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
// Tests
|
|
|
|
// Does the region contain the point (x,y)?
|
|
|
|
wxRegionContain Contains(wxCoord x, wxCoord y) const;
|
|
|
|
// Does the region contain the point pt?
|
|
|
|
wxRegionContain Contains(const wxPoint& pt) const;
|
|
|
|
// Does the region contain the rectangle (x, y, w, h)?
|
|
|
|
wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
|
|
|
|
// Does the region contain the rectangle rect?
|
|
|
|
wxRegionContain Contains(const wxRect& rect) const;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2003-05-03 13:56:30 -04:00
|
|
|
// Convert the region to a B&W bitmap with the white pixels being inside
|
2003-03-28 18:05:05 -05:00
|
|
|
// the region.
|
|
|
|
wxBitmap ConvertToBitmap() const;
|
|
|
|
|
|
|
|
// Use the non-transparent pixels of a wxBitmap for the region to combine
|
2004-06-03 17:13:52 -04:00
|
|
|
// with this region. First version takes transparency from bitmap's mask,
|
|
|
|
// second lets the user specify the colour to be treated as transparent
|
2003-03-28 18:05:05 -05:00
|
|
|
// along with an optional tolerance value.
|
2004-06-03 17:13:52 -04:00
|
|
|
// NOTE: implemented in common/rgncmn.cpp
|
|
|
|
bool Union(const wxBitmap& bmp);
|
2003-03-28 18:05:05 -05:00
|
|
|
bool Union(const wxBitmap& bmp,
|
2004-06-03 17:13:52 -04:00
|
|
|
const wxColour& transColour, int tolerance = 0);
|
2003-03-28 18:05:05 -05:00
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
// Internal
|
2001-08-27 10:56:55 -04:00
|
|
|
bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);
|
|
|
|
bool Combine(const wxRegion& region, wxRegionOp op);
|
|
|
|
bool Combine(const wxRect& rect, wxRegionOp op);
|
1998-12-02 15:02:01 -05:00
|
|
|
|
|
|
|
// Get internal region handle
|
|
|
|
WXHRGN GetHRGN() const;
|
2001-08-27 10:56:55 -04:00
|
|
|
|
2002-01-31 11:00:13 -05:00
|
|
|
protected:
|
2002-02-03 07:31:32 -05:00
|
|
|
virtual wxObjectRefData *CreateRefData() const;
|
2002-02-03 20:34:18 -05:00
|
|
|
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
|
2002-01-31 11:00:13 -05:00
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
friend class WXDLLEXPORT wxRegionIterator;
|
2002-01-31 11:00:13 -05:00
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxRegion)
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
class WXDLLEXPORT wxRegionIterator : public wxObject
|
|
|
|
{
|
1998-05-20 10:12:05 -04:00
|
|
|
public:
|
2002-12-04 09:11:26 -05:00
|
|
|
wxRegionIterator() { Init(); }
|
2001-08-27 10:56:55 -04:00
|
|
|
wxRegionIterator(const wxRegion& region);
|
2004-09-16 18:36:12 -04:00
|
|
|
wxRegionIterator(const wxRegionIterator& ri) : wxObject(ri) { Init(); *this = ri; }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
wxRegionIterator& operator=(const wxRegionIterator& ri);
|
|
|
|
|
|
|
|
virtual ~wxRegionIterator();
|
|
|
|
|
|
|
|
void Reset() { m_current = 0; }
|
2001-08-27 10:56:55 -04:00
|
|
|
void Reset(const wxRegion& region);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
bool HaveRects() const { return (m_current < m_numRects); }
|
|
|
|
|
1999-01-15 19:13:58 -05:00
|
|
|
#ifndef __SALFORDC__
|
2002-12-04 09:11:26 -05:00
|
|
|
operator bool () const { return HaveRects(); }
|
1999-01-15 19:13:58 -05:00
|
|
|
#endif
|
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
wxRegionIterator& operator++();
|
|
|
|
wxRegionIterator operator++(int);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
wxCoord GetX() const;
|
|
|
|
wxCoord GetY() const;
|
|
|
|
wxCoord GetW() const;
|
|
|
|
wxCoord GetWidth() const { return GetW(); }
|
|
|
|
wxCoord GetH() const;
|
|
|
|
wxCoord GetHeight() const { return GetH(); }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
wxRect GetRect() const { return wxRect(GetX(), GetY(), GetW(), GetH()); }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
private:
|
2002-12-04 09:11:26 -05:00
|
|
|
// common part of all ctors
|
|
|
|
void Init();
|
|
|
|
|
2001-08-27 10:56:55 -04:00
|
|
|
long m_current;
|
|
|
|
long m_numRects;
|
|
|
|
wxRegion m_region;
|
1998-05-20 10:12:05 -04:00
|
|
|
wxRect* m_rects;
|
2001-08-27 10:56:55 -04:00
|
|
|
|
2003-08-05 15:20:51 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxRegionIterator)
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2001-08-27 10:56:55 -04:00
|
|
|
// _WX_REGION_H_
|