openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
region.h
Go to the documentation of this file.
1 #ifndef __lib_gdi_region_h
2 #define __lib_gdi_region_h
3 
4 #include <lib/base/object.h>
5 #include <lib/gdi/erect.h>
6 #include <vector>
7 
8 class gRegion
9 {
10 private:
11  inline void FindBand(
12  std::vector<eRect>::const_iterator r,
13  std::vector<eRect>::const_iterator &rBandEnd,
14  std::vector<eRect>::const_iterator rEnd,
15  int &ry1)
16  {
17  ry1 = r->y1;
18  rBandEnd = r+1;
19  while ((rBandEnd != rEnd) && (rBandEnd->y1 == ry1))
20  rBandEnd++;
21  }
22 
23  inline void AppendRegions(
24  std::vector<eRect>::const_iterator r,
25  std::vector<eRect>::const_iterator rEnd)
26  {
27  rects.insert(rects.end(), r, rEnd);
28  }
29 
30  int do_coalesce(int prevStart, unsigned int curStart);
31  inline void coalesce(int &prevBand, unsigned int curBand)
32  {
33  if (curBand - prevBand == rects.size() - curBand) {
34  prevBand = do_coalesce(prevBand, curBand);
35  } else {
36  prevBand = curBand;
37  }
38  };
39  void appendNonO(std::vector<eRect>::const_iterator r,
40  std::vector<eRect>::const_iterator rEnd, int y1, int y2);
41 
42  void intersectO(
43  std::vector<eRect>::const_iterator r1,
44  std::vector<eRect>::const_iterator r1End,
45  std::vector<eRect>::const_iterator r2,
46  std::vector<eRect>::const_iterator r2End,
47  int y1, int y2,
48  int &overlap);
49  void subtractO(
50  std::vector<eRect>::const_iterator r1,
51  std::vector<eRect>::const_iterator r1End,
52  std::vector<eRect>::const_iterator r2,
53  std::vector<eRect>::const_iterator r2End,
54  int y1, int y2,
55  int &overlap);
56  void mergeO(
57  std::vector<eRect>::const_iterator r1,
58  std::vector<eRect>::const_iterator r1End,
59  std::vector<eRect>::const_iterator r2,
60  std::vector<eRect>::const_iterator r2End,
61  int y1, int y2,
62  int &overlap);
63  void regionOp(const gRegion &reg1, const gRegion &reg2, int opcode, int &overlap);
64 public:
65  std::vector<eRect> rects;
67 
68  enum
69  {
70  // note: bit 0 and bit 1 have special meanings
73  OP_UNION = 3
74  };
75 
76  gRegion(const eRect &rect);
77  gRegion();
78  virtual ~gRegion();
79 
80  gRegion operator&(const gRegion &r2) const;
81  gRegion operator-(const gRegion &r2) const;
82  gRegion operator|(const gRegion &r2) const;
83  gRegion &operator&=(const gRegion &r2);
84  gRegion &operator-=(const gRegion &r2);
85  gRegion &operator|=(const gRegion &r2);
86 
87  friend bool operator == (const gRegion &, const gRegion &);
88  friend bool operator != (const gRegion &, const gRegion &);
89 
90  void intersect(const gRegion &r1, const gRegion &r2);
91  void subtract(const gRegion &r1, const gRegion &r2);
92  void merge(const gRegion &r1, const gRegion &r2);
93 
94  void moveBy(ePoint offset);
95 
96  bool empty() const { return extends.empty(); }
97  bool valid() const { return extends.valid(); }
98 
100 
101  void scale(int x_n, int x_d, int y_n, int y_d);
102 };
103 
104 bool operator == (const gRegion &, const gRegion &);
105 bool operator != (const gRegion &, const gRegion &);
106 
107 #endif
Definition: epoint.h:9
Definition: erect.h:11
static eRect invalidRect()
Definition: erect.h:119
bool valid() const
Definition: erect.h:141
bool empty() const
Definition: erect.h:138
Definition: region.h:9
void intersect(const gRegion &r1, const gRegion &r2)
Definition: region.cpp:332
gRegion & operator&=(const gRegion &r2)
Definition: region.cpp:410
void merge(const gRegion &r1, const gRegion &r2)
Definition: region.cpp:367
void subtract(const gRegion &r1, const gRegion &r2)
Definition: region.cpp:355
virtual ~gRegion()
Definition: region.cpp:37
gRegion & operator|=(const gRegion &r2)
Definition: region.cpp:424
friend bool operator==(const gRegion &, const gRegion &)
Definition: region.cpp:446
std::vector< eRect > rects
Definition: region.h:65
friend bool operator!=(const gRegion &, const gRegion &)
Definition: region.cpp:460
@ OP_UNION
Definition: region.h:73
@ OP_SUBTRACT
Definition: region.h:72
@ OP_INTERSECT
Definition: region.h:71
gRegion operator-(const gRegion &r2) const
Definition: region.cpp:396
void moveBy(ePoint offset)
Definition: region.cpp:431
gRegion operator|(const gRegion &r2) const
Definition: region.cpp:403
eRect extends
Definition: region.h:66
void scale(int x_n, int x_d, int y_n, int y_d)
Definition: region.cpp:439
bool valid() const
Definition: region.h:97
gRegion & operator-=(const gRegion &r2)
Definition: region.cpp:417
gRegion()
Definition: region.cpp:33
bool empty() const
Definition: region.h:96
static gRegion invalidRegion()
Definition: region.h:99
gRegion operator&(const gRegion &r2) const
Definition: region.cpp:389
bool operator==(const gRegion &, const gRegion &)
Definition: region.cpp:446
bool operator!=(const gRegion &, const gRegion &)
Definition: region.cpp:460