- disabled gui for a moment
[vuplus_dvbapp] / lib / gdi / region.h
1 #ifndef __lib_gdi_region_h
2 #define __lib_gdi_region_h
3
4 #include <lib/base/object.h>
5 #include <vector>
6
7 class gRegion
8 {
9 private:
10         inline void FindBand(
11                         std::vector<eRect>::const_iterator r,
12                         std::vector<eRect>::const_iterator &rBandEnd,
13                         std::vector<eRect>::const_iterator rEnd,
14                         int &ry1)
15         {
16                 ry1 = r->y1;
17                 rBandEnd = r+1;
18                 while ((rBandEnd != rEnd) && (rBandEnd->y1 == ry1))
19                         rBandEnd++;
20         }
21         
22         inline void AppendRegions(
23                 std::vector<eRect>::const_iterator r,
24                 std::vector<eRect>::const_iterator rEnd)
25         {
26                 rects.insert(rects.end(), r, rEnd);
27         }
28
29         int do_coalesce(int prevStart, unsigned int curStart);
30         inline void coalesce(int &prevBand, unsigned int curBand)
31         {
32                 if (curBand - prevBand == rects.size() - curBand) {
33                         prevBand = do_coalesce(prevBand, curBand);
34                 } else {
35                         prevBand = curBand;
36                 }
37         };
38         void appendNonO(std::vector<eRect>::const_iterator r, 
39                         std::vector<eRect>::const_iterator rEnd, int y1, int y2);
40
41         void intersectO(
42                         std::vector<eRect>::const_iterator r1,
43                         std::vector<eRect>::const_iterator r1End,
44                         std::vector<eRect>::const_iterator r2,
45                         std::vector<eRect>::const_iterator r2End,
46                         int y1, int y2,
47                         int &overlap);
48         void subtractO(
49                         std::vector<eRect>::const_iterator r1,
50                         std::vector<eRect>::const_iterator r1End,
51                         std::vector<eRect>::const_iterator r2,
52                         std::vector<eRect>::const_iterator r2End,
53                         int y1, int y2,
54                         int &overlap);
55         void mergeO(
56                         std::vector<eRect>::const_iterator r1,
57                         std::vector<eRect>::const_iterator r1End,
58                         std::vector<eRect>::const_iterator r2,
59                         std::vector<eRect>::const_iterator r2End,
60                         int y1, int y2,
61                         int &overlap);
62         void regionOp(const gRegion &reg1, const gRegion &reg2, int opcode, int &overlap);
63 public:
64         std::vector<eRect> rects;
65         eRect extends;
66         
67         enum
68         {
69                         // note: bit 0 and bit 1 have special meanings
70                 OP_INTERSECT = 0,
71                 OP_SUBTRACT  = 1,
72                 OP_UNION     = 3
73         };
74         
75         gRegion(const eRect &rect);
76         gRegion();
77         virtual ~gRegion();
78
79         gRegion operator&(const gRegion &r2) const;
80         gRegion operator-(const gRegion &r2) const;
81         gRegion operator|(const gRegion &r2) const;
82         gRegion &operator&=(const gRegion &r2);
83         gRegion &operator-=(const gRegion &r2);
84         gRegion &operator|=(const gRegion &r2);
85         
86         void intersect(const gRegion &r1, const gRegion &r2);
87         void subtract(const gRegion &r1, const gRegion &r2);
88         void merge(const gRegion &r1, const gRegion &r2);
89         
90         void moveBy(ePoint offset);
91 };
92
93 #endif