My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
NAMESPACE_UPP

class PlotterDragDrop;

class PlotterCtrl : public DragDropCtrl, public CtrlFrame
{
public:
class ViewPlot : public Plotter
{
public:
ViewPlot(PlotterCtrl& ctrl, int extra_gap = 0);
ViewPlot(PlotterCtrl& ctrl, Pointf scale, Pointf delta, int extra_gap = 0);
ViewPlot(PlotterCtrl& ctrl, const Matrixf& preform, int extra_gap = 0);

private:
ViewDraw viewdraw;
};
friend class ViewPlot;

typedef PlotterCtrl CLASSNAME;
PlotterCtrl();
virtual ~PlotterCtrl();

virtual void FrameAdd(Ctrl& ctrl);
virtual void FrameRemove();
virtual void FrameLayout(Rect& rc);
virtual void FrameAddSize(Size& sz);

virtual void Layout();
virtual void Paint(Draw& draw);
// void AsyncPaint();
bool IsPainting() const { return is_painting; }

virtual void LostFocus() { ResetPush(); }

ImageDraw& BeginBufferPaint();
virtual void EndBufferPaint();

virtual void Plot(Plotter& plotter) = 0;
virtual void AbortPlot() {}

void BufferPaint(bool bp = true) { buffer_paint = bp; RefreshBuffer(); }
bool IsBufferPaint() const { return buffer_paint; }
void RefreshBuffer();
void RefreshBuffer(const Rect& rc);

void BufferPan(bool bp = true) { buffer_pan = bp; }
bool IsBufferPan() const { return buffer_pan; }
void PanOffset(Point o);
void ClearPanOffset() { PanOffset(Point(0, 0)); }
Point GetPanOffset() const { return pan_offset; }

void ShowScroll(bool ssc) { show_scroll = ssc; Layout(); }
bool IsScrollShown() const { return show_scroll; }

void MaxScale(double d) { max_scale.cx = max_scale.cy = d; }
void MaxScale(Sizef ms) { max_scale = ms; }
Sizef GetMaxScale() const { return max_scale; }

void Gap(Rect g) { gap = g; Layout(); }
void Gap(int i) { gap = Rect(i, i, i, i); Layout(); }
Rect GetGap() const { return gap; }

virtual Image CursorImage(Point pt, dword keyflags);
virtual bool Push(Point pt, dword keyflags);
virtual void Drag(Point start, Point prev, Point curr, dword keyflags);
virtual void Drop(Point start, Point end, dword keyflags);
virtual void Click(Point pt, dword keyflags);
virtual void Cancel();
virtual bool Key(dword key, int repcnt);
virtual void MouseWheel(Point p, int zdelta, dword keyflags);
virtual void MouseMove(Point pt, dword keyflags);

virtual void RefreshPos() {}
virtual void RefreshDragDrop() { RefreshBuffer(); }

Pointf FromClient(Point pt) const { return (Pointf(pt) - delta) / scale; }
Pointf FromClientNull(Point pt) const { return IsNull(pt) ? Pointf(Null) : FromClient(pt); }
Rectf FromClient(const Rect& rc) const;

Pointf FromPushClient(Point pt) const { return (Pointf(pt) - push_delta) / push_scale; }
Pointf FromPushClientNull(Point pt) const { return IsNull(pt) ? Pointf(Null) : FromPushClient(pt); }

Point ToClient(Pointf pt) const { return PointfToPoint(Sizef(pt) * scale + delta); }
Point ToClientNull(Pointf pt) const { return IsNull(pt) ? Point(Null) : PointfToPoint(Sizef(pt) * scale + delta); }
Rect ToClient(const Rectf& rc) const;

Point ToPushClient(Pointf pt) const { return PointfToPoint(Sizef(pt) * push_scale + push_delta); }
Point ToPushClientNull(Pointf pt) const { return IsNull(pt) ? Point(Null) : ToPushClient(pt); }

void SyncPush();

void SetExtent(const Rectf& extent);
const Rectf& GetExtent() const { return extent; }

Rectf GetViewRect() const { return FromClient(Rect(GetSize()).Deflated(gap)); }

void ScrollInto(Rectf rc);
void ScrollInto(Pointf pt);

void SetAspectRatio(double aspect);
void NoAspectRatio() { SetAspectRatio(0); }
double GetAspectRatio() const { return aspect; }
bool IsAspectRatio() const { return aspect != 0; }

void SetAspectLock(bool a = true);
void NoAspectLock() { SetAspectLock(false); }
bool IsAspectLock() const { return aspect_lock; }
bool IsAspectLocked() const { return IsAspectRatio() || IsAspectLock(); }

void EnableLock(bool e = true);
void DisableLock() { EnableLock(false); }
bool IsLockEnabled() const { return enable_lock; }\

void SetScale(Sizef scale);
void SetDelta(Pointf delta);
void SetZoom(Sizef scale, Pointf delta);
void SetZoom(double scale, Pointf delta);
void SetZoomSc(Sizef scale);
void SetZoomSc(double sx, double sy) { SetZoomSc(Pointf(sx, sy)); }
void SetZoomSc(double z);

Sizef GetScale() const { return scale; }
Sizef GetPushScale() const { return push_scale; }
double GetAvgScale() const;
Pointf GetDelta() const { return delta; }
Pointf GetPushDelta() const { return push_delta; }

bool IsReversedX() const { return rev_x; }
bool IsReversedY() const { return rev_y; }

bool IsReversing() const { return scale.cx * scale.cy < 0; }

Sizef GetPhysicalZoom() const;

void AdjustPos(Pointf& delta, Point scpos) const;
Sizef AdjustScale(Sizef sc) const;

Pointf GetSc() const;
void SetSc(Pointf center);

void ZoomInX();
void ZoomOutX();
void ZoomFullX() { if(extent.left < extent.right) ZoomX(extent.left, extent.right); }
void ZoomX(double min, double max, bool add_gap = true);
void ZoomInY();
void ZoomOutY();
void ZoomFullY() { if(extent.top < extent.bottom) ZoomY(extent.right, extent.bottom); }
void ZoomY(double min, double max, bool add_gap = true);
void ZoomIn() { ZoomInX(); ZoomInY(); }
void ZoomOut() { ZoomOutX(); ZoomOutY(); }
void ZoomFull() { Zoom(extent, false); }
void Zoom(const Rectf& rc, bool keep_ratio = true, bool add_gap = true);

void UserZoomInX();
void UserZoomOutX();
void UserZoomFullX();
void UserZoomX(double min, double max);
void UserZoomInY();
void UserZoomOutY();
void UserZoomFullY();
void UserZoomY(double min, double max);
void UserZoomIn();
void UserZoomOut();
virtual void UserZoomFull();
void UserAspectLock();
void UserZoom(const Rectf& rc, bool keep_ratio = true);

void PickDragDrop(One<PlotterDragDrop> dd);
One<PlotterDragDrop> ClearDragDrop();
PlotterDragDrop *GetDragDrop() { return ~drag_drop; }
const PlotterDragDrop *GetDragDrop() const { return ~drag_drop; }

void UpdateMousePos();
Pointf GetMousePos() const { return mouse_pos; }

void DoSetFocus() { SetWantFocus(); }

void ResetPush() { reset_push = true; }

TOOL(View)
TOOL(ViewZoomInX)
TOOL(ViewZoomOutX)
TOOL(ViewZoomFullX)
TOOL(ViewZoomInY)
TOOL(ViewZoomOutY)
TOOL(ViewZoomFullY)
TOOL(ViewZoomIn)
TOOL(ViewZoomOut)
TOOL(ViewZoomFull)
TOOL(ViewAspectLock)
TOOL(ViewPan)

void PostRefresh();

public:
Callback WhenRescan;
Callback WhenZoom;
Callback WhenUserZoom;
Callback WhenMousePos;

protected:
void AdjustPos(Point scpos, int xymask); // 1 = x, 2 = y

protected:
bool rev_x, rev_y, aspect_lock, enable_lock;
Rect gap;
Alignment halign, valign;
Color background;
Sizef scale;
Pointf delta;
Sizef push_scale;
Pointf push_delta;
Sizef max_scale;
Pointf mouse_pos;
Rectf extent;
double aspect;

Image paint_buffer;
One<ImageDraw> paint_draw;
bool is_painting;
bool abort_repaint;
bool buffer_paint;
bool buffer_pan;
Point pan_offset;

private:
void OnHScroll();
void OnVScroll();
void Refresh0() { RefreshBuffer(); }

private:
TimeCallback tcb_refresh;
Size old_size;
One<PlotterDragDrop> drag_drop;
Pointf drag_start;
HScrollBar hscroll;
VScrollBar vscroll;
Button horz_in, horz_out, horz_full;
Button vert_in, vert_out, vert_full;
Button full;
bool reset_push;
bool show_scroll;
bool lock_drag_drop;
bool lock_short_drag_drop;
int drag_mode;
enum { DRAG_NONE, DRAG_CUSTOM, DRAG_PAN, DRAG_ZOOM_IN, DRAG_ZOOM_OUT };
};

template <class T>
inline const T *GetDragDrop(const PlotterCtrl *ctrl, T * = 0)
{
if(const T *p = dynamic_cast<const T *>(ctrl->GetShortDragDrop()))
return p;
return dynamic_cast<const T *>(ctrl->GetDragDrop());
}

template <class T>
inline T *GetDragDrop(PlotterCtrl *ctrl, T * = 0)
{
return dynamic_cast<T *>(ctrl->GetDragDrop());
}

template <class T>
inline bool IsDragDrop(const PlotterCtrl *ctrl, T * = 0)
{
return dynamic_cast<const T *>(ctrl->GetDragDrop());;
}
// make member template as soon as possible

class PlotterDragDrop
{
public:
virtual ~PlotterDragDrop() {}

virtual PlotterCtrl& GetOwner() = 0;

virtual void Plot(Plotter& plotter) {}
virtual bool Push(Pointf pt, dword keyflags) { return true; }
virtual Image Cursor(Pointf pt, dword keyflags, bool dragging) const { return Image::Arrow(); }
virtual void Drag(Pointf pt, Pointf prev, Pointf curr, dword keyflags);
virtual void DragRect(const Rectf& prev, const Rectf& curr, dword keyflags);
virtual void Drop(Pointf pt, Pointf end, dword keyflags);
virtual void DropRect(const Rectf& rc, dword keyflags) {}
virtual void Click(Pointf pt, dword keyflags) {}
virtual bool Key(dword key) { return false; }
virtual void Cancel() {}
};

class EmptyDragDrop : public PlotterDragDrop
{
public:
EmptyDragDrop(PlotterCtrl& owner) : owner(owner) {}

virtual PlotterCtrl& GetOwner() { return owner; }

virtual bool Push(Pointf pt, dword keyflags) { return false; }

private:
PlotterCtrl& owner;
};

class ZoomInDragDrop : public PlotterDragDrop
{
public:
ZoomInDragDrop(PlotterCtrl& owner) : owner(owner) {}

virtual PlotterCtrl& GetOwner() { return owner; }

virtual Image Cursor(Pointf pt, dword keyflags, bool dragging) const;
virtual void DropRect(const Rectf& rc, dword keyflags);
virtual void Click(Pointf pt, dword keyflags);

private:
PlotterCtrl& owner;
};

class ZoomOutDragDrop : public PlotterDragDrop
{
public:
ZoomOutDragDrop(PlotterCtrl& owner) : owner(owner) {}

virtual PlotterCtrl& GetOwner() { return owner; }

virtual Image Cursor(Pointf pt, dword keyflags, bool dragging) const;
virtual bool Push(Pointf pt, dword keyflags);
virtual void DropRect(const Rectf& rc, dword keyflags);
virtual void Click(Pointf pt, dword keyflags);

private:
PlotterCtrl& owner;
};

class PanDragDrop : public PlotterDragDrop
{
public:
PanDragDrop(PlotterCtrl& owner) : owner(owner) {}

virtual PlotterCtrl& GetOwner() { return owner; }

virtual Image Cursor(Pointf pt, dword keyflags, bool dragging) const;
virtual bool Push(Pointf pt, dword keyflags);
virtual void Drag(Pointf start, Pointf prev, Pointf curr, dword keyflags);
virtual void Drop(Pointf start, Pointf end, dword keyflags);
virtual void Cancel();

private:
PlotterCtrl& owner;
};

END_UPP_NAMESPACE

Change log

r4179 by rylek on Nov 16, 2011   Diff
Geom/Ctrl/PlotterCtrl: delayed refresh bug
fix
Go to: 
Project members, sign in to write a code review

Older revisions

r4100 by rylek on Oct 24, 2011   Diff
Geom/Ctrl/PlotterCtrl: new methods to
check for reversed orientation of
coordinate axes
plugin/jpg/jpgupp.cpp: support for
EXIM image orientation metadata
...
r3788 by rylek on Aug 26, 2011   Diff
*Web/httpsrv.cpp: fixed bug concerning
reading long SAPI requests
r3757 by rylek on Aug 9, 2011   Diff
.RichText: added \n support to DeQtf;
fixed ParseQtf to ignore control
characters which break the packed
paragraph format
.Geom/Draw/hrr.cpp: fixed coordinate
...
All revisions of this file

File info

Size: 14151 bytes, 351 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting