1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
//
// "$Id$"
//
// Graphics regions and clipping for the Fast Light Tool Kit (FLTK).
//
// Copyright 2018 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
/**
\file Fl_Android_Graphics_Clipping.H
\brief Graphics regions and clipping for the Fast Light Tool Kit (FLTK).
*/
#ifndef FL_ANDROID_GRAPHICS_CLIPPING_H
#define FL_ANDROID_GRAPHICS_CLIPPING_H
#include <FL/Fl_Graphics_Driver.H>
#include <limits.h>
class Fl_Android_Window_Driver;
/**
* The Fl_Rect_Region describes a rectangular clipping region.
*
* Contrary to common FLTK convention, rectangles are stored with coordinates
* instead of their width and height to accelerate calculations. The discreet
* constructor however uses the old convention for convenience.
*/
class Fl_Rect_Region
{
public:
enum Type {
EMPTY = 0, SAME, LESS, MORE, INFINITE
};
Fl_Rect_Region();
Fl_Rect_Region(int x, int y, int w, int h);
Fl_Rect_Region(const Fl_Rect_Region&);
Fl_Rect_Region(enum Type what);
virtual ~Fl_Rect_Region() { }
int x() const { return pLeft; }
int y() const { return pTop; }
int w() const { return pRight - pLeft; }
int h() const { return pBottom - pTop; }
int left() const { return pLeft; }
int top() const { return pTop; }
int right() const { return pRight; }
int bottom() const { return pBottom; }
bool is_empty() const;
bool is_infinite() const;
void set_empty();
void set(int x, int y, int w, int h);
void set_ltrb(int l, int t, int r, int b);
virtual void set(const Fl_Rect_Region &r);
virtual int intersect_with(const Fl_Rect_Region &r);
void add_to_bbox(const Fl_Rect_Region &r);
virtual void print(const char*) const;
protected:
int pLeft, pTop, pRight, pBottom;
private:
Fl_Rect_Region& operator = (const Fl_Rect_Region& other);
};
/**
* The Fl_Complex_Region represents a clipping region of any shape.
*
* This class is organized in a tree-like structure. If the region is
* rectangular, is_simple() returns 1 and the rectangle can be used just
* as in Fl_Rect_Region.
*
* If a more complex representation is needed, subregions are created which are
* guaranteed to lie within the bounding box of the current region. Subregions
* themselves can again contain sub-subregions to describe the entire clipping
* region, effectively creating a tree where the leafs contain the rectangles
* that together describe the clipping area.
*
* To make life easier, Fl_Complex_Region provides two types of iterator to
* travers the entire tree.
*
* 1. Fl_Complex_Region itself is compatible to C++11 range-based loops and
* can bewalked simply by writing ``for (auto &&it: rgn) { ... }``.
*
* 2. Fl_Complex_Region provides an alternative iterator that loop only through
* leafs that intersects with a given rectangle. The returned object
* provides access to the readily clipped rectangle.
*
* @code
* Fl_Complex_Region rgn(something);
* for (auto &&it: rgn.iterate(Fl_Rect_Region(0, 0, 100, 100)) {
* draw_something(it->rect());
* }
* @endcode
*
*/
class Fl_Complex_Region : public Fl_Rect_Region
{
class Iterator {
public:
Iterator(Fl_Complex_Region *r);
bool operator!= (const Iterator& other) const;
const Iterator& operator++ ();
Fl_Complex_Region *operator* () const;
Fl_Complex_Region *pRegion;
};
class Overlapping {
class OverlappingIterator {
public:
OverlappingIterator(Overlapping *ov);
bool operator!= (const OverlappingIterator& other) const;
const OverlappingIterator& operator++ ();
Overlapping *operator* () const;
Overlapping *pOv;
};
public:
Overlapping(Fl_Complex_Region *rgn, const Fl_Rect_Region &rect);
OverlappingIterator begin();
OverlappingIterator end();
Fl_Rect_Region &clipped_rect();
bool intersects();
bool find_intersecting();
bool find_next();
Fl_Complex_Region *pRegion;
Fl_Rect_Region pOriginalRect;
Fl_Rect_Region pClippedRect;
};
public:
Fl_Complex_Region();
Fl_Complex_Region(const Fl_Rect_Region&);
virtual ~Fl_Complex_Region() override;
virtual void set(const Fl_Rect_Region &r) override;
void set(const Fl_Complex_Region &r);
Fl_Complex_Region *subregion() const { return pSubregion; }
Fl_Complex_Region *next() const { return pNext; }
Fl_Complex_Region *parent() const { return pParent; }
char is_simple() const { return pSubregion==0; }
char is_complex() const { return pSubregion!=0; }
virtual int intersect_with(const Fl_Rect_Region &r) override;
int subtract(const Fl_Rect_Region &r);
virtual void print(const char*) const override;
Iterator begin();
Iterator end();
Overlapping overlapping(const Fl_Rect_Region &r);
protected:
void print_data(int indent) const;
int subtract_smaller_region(const Fl_Rect_Region &r);
Fl_Complex_Region *add_subregion();
void compress();
Fl_Complex_Region *pSubregion = 0L;
Fl_Complex_Region *pParent = 0L;
Fl_Complex_Region *pNext = 0L;
};
#endif // FL_ANDROID_GRAPHICS_CLIPPING_H
//
// End of "$Id$".
//
|