-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZoomInfo.cpp
More file actions
372 lines (301 loc) · 7.88 KB
/
ZoomInfo.cpp
File metadata and controls
372 lines (301 loc) · 7.88 KB
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
// Indexes.cpp : implementation file
//
#include "stdafx.h"
#include "NewProject01View.h"
#include "ZoomInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CZoomInfo
//IMPLEMENT_DYNCREATE(CZoomInfo, CCmdTarget)
CZoomInfo::CZoomInfo(CSize size, CRect rc, bool bRightRect)
{
m_szImageSize = size;
m_rcZoomBoxRect = rc;
m_nZoomX = 1;
m_ptCP = CPoint( (int)(m_szImageSize.cx*0.5), (int)(m_szImageSize.cy*0.5));
m_nMaxZoomFactor = 2048;
m_bRightRect = bRightRect;
ZoomOut(CPoint(0, 0));
}
CZoomInfo::~CZoomInfo()
{
}
/*
BEGIN_MESSAGE_MAP(CZoomInfo, CCmdTarget)
//{{AFX_MSG_MAP(CZoomInfo)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
*/
/////////////////////////////////////////////////////////////////////////////
// CZoomInfo message handlers
void CZoomInfo::SetZoomX(int num)
{
m_nZoomX = num;
m_nWingX = m_szImageSize.cx/(2*m_nZoomX)-1;
m_nWingY = m_szImageSize.cy/(2*m_nZoomX)-1;
m_nDeltX = m_nWingX*2+1;
m_nDeltY = m_nWingY*2+1;
if( m_bRightRect ){
m_nWingY = m_nWingX;
m_nDeltY = m_nDeltX;
//m_fScaleY = m_fScaleX;
}
m_fScaleX = (float)m_nDeltX/(m_rcZoomBoxRect.Width()+1);
m_fScaleY = (float)m_nDeltY/(m_rcZoomBoxRect.Height()+1);
}
void CZoomInfo::SetCenterPoint(CPoint p)
{
/* int wingx = m_szImageSize.cx/(2*m_nZoomX)-1;
int wingy = m_szImageSize.cy/(2*m_nZoomX)-1;
int deltx = wingx*2+1;
int delty = wingy*2+1;
if( m_bRightRect ){
m_nWingY = m_nWingX;
m_nDeltY = m_nDeltX;
m_fScaleY = m_fScaleX;
}
*/
if( p.x-m_nWingX < 0 ) p.x = m_nWingX;
if( p.y-m_nWingY < 0 ) p.y = m_nWingY;
if( p.x+m_nWingX > m_szImageSize.cx-1 ) p.x = m_szImageSize.cx-1-m_nWingX;
if( p.y+m_nWingY > m_szImageSize.cy-1 ) p.y = m_szImageSize.cy-1-m_nWingY;
m_ptCP = p;
}
CPoint CZoomInfo::GetCenterPoint()
{
return m_ptCP;
}
int CZoomInfo::GetZoomX()
{
return m_nZoomX;
}
int CZoomInfo::IncreaseZoomX()
{
if( m_nZoomX < m_nMaxZoomFactor ) m_nZoomX *= 2;
m_nWingX = m_szImageSize.cx/(2*m_nZoomX)-1;
m_nWingY = m_szImageSize.cy/(2*m_nZoomX)-1;
m_nDeltX = m_nWingX*2+1;
m_nDeltY = m_nWingY*2+1;
if( m_bRightRect ){
m_nWingY = m_nWingX;
m_nDeltY = m_nDeltX;
//m_fScaleY = m_fScaleX;
}
m_fScaleX = (float)m_nDeltX/(m_rcZoomBoxRect.Width()+1);
m_fScaleY = (float)m_nDeltY/(m_rcZoomBoxRect.Height()+1);
return m_nZoomX;
}
int CZoomInfo::DecreaseZoomX()
{
if( m_nZoomX > 1 ) m_nZoomX /= 2;
m_nWingX = m_szImageSize.cx/(2*m_nZoomX)-1;
m_nWingY = m_szImageSize.cy/(2*m_nZoomX)-1;
m_nDeltX = m_nWingX*2+1;
m_nDeltY = m_nWingY*2+1;
if( m_bRightRect ){
m_nWingY = m_nWingX;
m_nDeltY = m_nDeltX;
//m_fScaleY = m_fScaleX;
}
m_fScaleX = (float)m_nDeltX/(m_rcZoomBoxRect.Width()+1);
m_fScaleY = (float)m_nDeltY/(m_rcZoomBoxRect.Height()+1);
return m_nZoomX;
}
CZoomInfo::CZoomInfo()
{
}
CRect CZoomInfo::GetSourceRect()
{
/* int wingx = m_szImageSize.cx/(2*m_nZoomX) -1;
int wingy = m_szImageSize.cy/(2*m_nZoomX) -1;
int deltx = 2*wingx+1;
int delty = 2*wingy+1;
CRect ret;
if( m_bRightRect ){
wingy = wingx;
delty = deltx;
}
*/
CRect ret;
ret = CRect(m_ptCP.x-m_nWingX, m_ptCP.y-m_nWingY, m_nDeltX, m_nDeltY);
return ret;
}
CPoint CZoomInfo::PToL(CPoint p)
{/*
int wingx = m_szImageSize.cx/(2*m_nZoomX)-1;
int wingy = m_szImageSize.cy/(2*m_nZoomX)-1;
int deltx = wingx*2+1;
int delty = wingy*2+1;
float scalex = (float)deltx/m_rcZoomBoxRect.Width();
float scaley = (float)delty/m_rcZoomBoxRect.Height();
CPoint ret;
if( m_bRightRect ){
wingy = wingx;
delty = deltx;
scaley = scalex;
}*/
/* if( p.x-m_nWingX < 0 ) p.x = m_nWingX;
if( p.y-m_nWingY < 0 ) p.y = m_nWingY;
if( p.x+m_nWingX > m_szImageSize.cx-1 ) p.x = m_szImageSize.cx-1-m_nWingX;
if( p.y+m_nWingY > m_szImageSize.cy-1 ) p.y = m_szImageSize.cy-1-m_nWingY;
*/
CPoint ret;
ret.x = (int)((m_ptCP.x-m_nWingX)+p.x*m_fScaleX);
ret.y = (int)((m_ptCP.y-m_nWingY)+p.y*m_fScaleY);
return ret;
}
int CZoomInfo::GetZoomBoxWidth()
{
return m_rcZoomBoxRect.Width()+1;
}
int CZoomInfo::GetZoomBoxHeight()
{
return m_rcZoomBoxRect.Height()+1;
}
bool CZoomInfo::IsInZoomBox(CPoint p)
{
if( m_rcZoomBoxRect.left > p.x ) return false;
if( m_rcZoomBoxRect.top > p.y ) return false;
if( m_rcZoomBoxRect.right < p.x ) return false;
if( m_rcZoomBoxRect.bottom < p.y ) return false;
return true;
}
void CZoomInfo::ZoomIn(CPoint p)
{
IncreaseZoomX();
SetCenterPoint(p);
}
CRect CZoomInfo::GetZoomBoxRect()
{
return m_rcZoomBoxRect;
}
void CZoomInfo::ZoomOut(CPoint p)
{
DecreaseZoomX();
SetCenterPoint(p);
}
CPoint CZoomInfo::LToP(CPoint p)
{
/* int wingx = m_szImageSize.cx/(2*m_nZoomX)-1;
int wingy = m_szImageSize.cy/(2*m_nZoomX)-1;
int deltx = wingx*2+1;
int delty = wingy*2+1;
float scalex = (float)deltx/m_rcZoomBoxRect.Width();
float scaley = (float)delty/m_rcZoomBoxRect.Height();
CPoint ret;
if( m_bRightRect ){
wingy = wingx;
delty = deltx;
scaley = scalex;
}
*/
CPoint ret;
ret.x = (int)(( p.x-(m_ptCP.x-m_nWingX) +0.5 )/m_fScaleX+0.5);
ret.y = (int)(( p.y-(m_ptCP.y-m_nWingY) +0.5 )/m_fScaleY+0.5);
return ret;
}
CPointFloat CZoomInfo::LToP(CPointFloat p)
{/*
int wingx = m_szImageSize.cx/(2*m_nZoomX)-1;
int wingy = m_szImageSize.cy/(2*m_nZoomX)-1;
int deltx = wingx*2+1;
int delty = wingy*2+1;
float scalex = (float)deltx/m_rcZoomBoxRect.Width();
float scaley = (float)delty/m_rcZoomBoxRect.Height();
CPointFloat ret;
if( m_bRightRect ){
wingy = wingx;
delty = deltx;
scaley = scalex;
}
*/
CPointFloat ret;
ret.x = (float)(( p.x-(m_ptCP.x-m_nWingX)+0.5)/m_fScaleX);
ret.y = (float)(( p.y-(m_ptCP.y-m_nWingY)+0.5)/m_fScaleY);
return ret;
}
void CZoomInfo::SetZoomBoxRect(CRect rect)
{
m_rcZoomBoxRect = rect;
m_nWingX = m_szImageSize.cx/(2*m_nZoomX)-1;
m_nWingY = m_szImageSize.cy/(2*m_nZoomX)-1;
m_nDeltX = m_nWingX*2+1;
m_nDeltY = m_nWingY*2+1;
if( m_bRightRect ){
m_nWingY = m_nWingX;
m_nDeltY = m_nDeltX;
}
m_fScaleX = (float)m_nDeltX/(m_rcZoomBoxRect.Width()+1);
m_fScaleY = (float)m_nDeltY/(m_rcZoomBoxRect.Height()+1);
// m_fScaleY = m_fScaleX;
}
CRect CZoomInfo::GetImageRect()
{
return CRect(0, 0, m_szImageSize.cx, m_szImageSize.cy);
}
CRect CZoomInfo::GetBound(CRect rect)
{
// returns physical bound of pixels defined by rect
/*
int wingx = m_szImageSize.cx/(2*m_nZoomX)-1;
int wingy = m_szImageSize.cy/(2*m_nZoomX)-1;
int deltx = wingx*2+1;
int delty = wingy*2+1;
float scalex = (float)deltx/m_rcZoomBoxRect.Width();
float scaley = (float)delty/m_rcZoomBoxRect.Height();
CPoint ret;
if( m_bRightRect ){
wingy = wingx;
delty = deltx;
scaley = scalex;
}
*/
rect.left = (int)(( rect.left-(m_ptCP.x-m_nWingX) )/m_fScaleX);
rect.top = (int)(( rect.top-(m_ptCP.y-m_nWingY) )/m_fScaleY);
rect.right = (int)(( rect.right-(m_ptCP.x-m_nWingX)+1 )/m_fScaleX)-1;
rect.bottom = (int)(( rect.bottom-(m_ptCP.y-m_nWingY)+1 )/m_fScaleY)-1;
// rect.top *= ((float)m_rcZoomBoxRect.Height()/m_rcZoomBoxRect.Width());
// rect.bottom *= ((float)m_rcZoomBoxRect.Height()/m_rcZoomBoxRect.Width());
return rect;
}
CPointFloat CZoomInfo::PToL_Float(CPoint p)
{/*
int wingx = m_szImageSize.cx/(2*m_nZoomX)-1;
int wingy = m_szImageSize.cy/(2*m_nZoomX)-1;
int deltx = wingx*2+1;
int delty = wingy*2+1;
float scalex = (float)deltx/m_rcZoomBoxRect.Width();
float scaley = (float)delty/m_rcZoomBoxRect.Height();
CPointFloat ret;
if( m_bRightRect ){
wingy = wingx;
delty = deltx;
scaley = scalex;
}
*/
CPointFloat ret;
ret.x = (float)(((m_ptCP.x-m_nWingX)+p.x*m_fScaleX)-0.5);
ret.y = (float)(((m_ptCP.y-m_nWingY)+p.y*m_fScaleY)-0.5);
return ret;
}
int CZoomInfo::GetImageWidth()
{
return m_szImageSize.cx;
}
int CZoomInfo::GetImageHeight()
{
return m_szImageSize.cy;
}
void CZoomInfo::SetMaxZoomFactor(int nFactor)
{
m_nMaxZoomFactor = nFactor;
}
CPoint CZoomInfo::GetWing()
{
return CPoint(m_nWingX, m_nWingY);
}