1 /* Copyright (C) 2002-2005 RealVNC Ltd.  All Rights Reserved.
2  * Copyright 2016-2020 Pierre Ossman for Cendio AB
3  *
4  * This is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this software; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
17  * USA.
18  */
19 
20 // Region class wrapper around pixman's region operations
21 
22 #ifndef __RFB_REGION_INCLUDED__
23 #define __RFB_REGION_INCLUDED__
24 
25 #include <rfb/Rect.h>
26 #include <vector>
27 
28 struct pixman_region16;
29 
30 namespace rfb {
31 
32   class Region {
33   public:
34     // Create an empty region
35     Region();
36     // Create a rectangular region
37     Region(const Rect& r);
38 
39     Region(const Region& r);
40     Region &operator=(const Region& src);
41 
42     ~Region();
43 
44     // the following methods alter the region in place:
45 
46     void clear();
47     void reset(const Rect& r);
48     void translate(const rfb::Point& delta);
49 
50     void assign_intersect(const Region& r);
51     void assign_union(const Region& r);
52     void assign_subtract(const Region& r);
53 
54     // the following three operations return a new region:
55 
56     Region intersect(const Region& r) const;
57     Region union_(const Region& r) const;
58     Region subtract(const Region& r) const;
59 
60     bool equals(const Region& b) const;
61     int numRects() const;
is_empty()62     bool is_empty() const { return numRects() == 0; }
63 
64     bool get_rects(std::vector<Rect>* rects, bool left2right=true,
65                    bool topdown=true) const;
66     Rect get_bounding_rect() const;
67 
68     void debug_print(const char *prefix) const;
69 
70   protected:
71 
72     struct pixman_region16* rgn;
73   };
74 
75 };
76 
77 #endif // __RFB_REGION_INCLUDED__
78