-
Notifications
You must be signed in to change notification settings - Fork 1
/
hitrectsur.cpp
207 lines (174 loc) · 4.67 KB
/
hitrectsur.cpp
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
#include "StdAfx.h"
#define PTINRECT(x,y) ((x) >= m_rcRect.left && (x) <= m_rcRect.right && (y) > m_rcRect.top && (y) < m_rcRect.bottom)
HitRectSur::HitRectSur(const HDC hdc, const float zoom, const float offx, const float offy, const int width, const int height, FRect * const prcRect, vector<ISelect*> * const pvsel) : Sur(hdc, zoom, offx, offy, width, height)
{
m_rcRect = *prcRect;
m_pvsel = pvsel;
if (m_rcRect.right < m_rcRect.left)
{
const float temp = m_rcRect.right;
m_rcRect.right = m_rcRect.left;
m_rcRect.left = temp;
}
if (m_rcRect.bottom < m_rcRect.top)
{
const float temp = m_rcRect.bottom;
m_rcRect.bottom = m_rcRect.top;
m_rcRect.top = temp;
}
SetObject(NULL);
}
HitRectSur::~HitRectSur()
{
}
void HitRectSur::Line(const float x, const float y, const float x2, const float y2)
{
if (m_fFailedAlready)
{
return;
}
if (!PTINRECT(x, y) || !PTINRECT(x2, y2))
{
FailObject();
}
}
void HitRectSur::Rectangle(const float x, const float y, const float x2, float y2)
{
if (m_fFailedAlready)
{
return;
}
if (!PTINRECT(x, y) || !PTINRECT(x2, y2))
{
FailObject();
}
}
void HitRectSur::Rectangle2(const int x, const int y, const int x2, const int y2)
{
}
void HitRectSur::Ellipse(const float centerx, const float centery, const float radius)
{
if (m_fFailedAlready)
{
return;
}
if (!PTINRECT(centerx - radius, centery - radius) || !PTINRECT(centerx + radius, centery + radius))
{
FailObject();
}
}
void HitRectSur::Ellipse2(const float centerx, const float centery, const int radius)
{
if (m_fFailedAlready)
{
return;
}
const int ix = SCALEXf(centerx);
const int iy = SCALEYf(centery);
const int circleleft = ix - radius;
const int circletop = iy - radius;
const int circleright = ix + radius;
const int circlebottom = iy + radius;
const int left = SCALEXf(m_rcRect.left);
const int top = SCALEYf(m_rcRect.top);
const int right = SCALEXf(m_rcRect.right);
const int bottom = SCALEYf(m_rcRect.bottom);
if (circleleft < left || circletop < top || circleright > right || circlebottom > bottom)
{
FailObject();
}
}
void HitRectSur::Polygon(const Vertex2D * const rgv, const int count)
{
if (m_fFailedAlready)
{
return;
}
for (int i = 0; i < count; ++i)
{
if (!PTINRECT(rgv[i].x, rgv[i].y))
{
FailObject();
return;
}
}
}
// copy-pasted from above
void HitRectSur::Polygon(const std::vector<RenderVertex> &rgv)
{
if (m_fFailedAlready)
{
return;
}
for (unsigned i = 0; i < rgv.size(); ++i)
{
if (!PTINRECT(rgv[i].x, rgv[i].y))
{
FailObject();
return;
}
}
}
void HitRectSur::PolygonImage(const std::vector<RenderVertex> &rgv, HBITMAP hbm, const float left, const float top, const float right, const float bottom, const int bitmapwidth, const int bitmapheight)
{
Polygon(rgv);
}
void HitRectSur::Polyline(const Vertex2D * const rgv, const int count)
{
}
void HitRectSur::Lines(const Vertex2D * const rgv, const int count)
{
}
void HitRectSur::Arc(const float x, const float y, const float radius, const float pt1x, const float pt1y, const float pt2x, const float pt2y)
{
}
void HitRectSur::Image(const float x, const float y, const float x2, const float y2, HDC hdcSrc, const int width, const int height)
{
}
void HitRectSur::SetObject(ISelect *psel)
{
m_pcur = psel;
if (m_pcur)
{
if (FindIndexOf(m_vselFailed, psel) != -1)
{
// Object failed previously - just skip this time
m_fFailedAlready = true;
}
else
{
const size_t index = FindIndexOf(*m_pvsel, psel);
if (index == -1)
{
// Object not in list yet - add it
m_indexcur = m_pvsel->size();
m_pvsel->push_back(psel);
}
else
{
m_indexcur = index;
}
m_fFailedAlready = false;
}
}
else
{
m_fFailedAlready = true;
}
}
void HitRectSur::FailObject()
{
m_fFailedAlready = true;
_ASSERTE(m_indexcur < m_pvsel->size());
m_pvsel->erase(m_pvsel->begin() + m_indexcur); // perf? Probably doesn't matter
m_vselFailed.push_back(m_pcur);
}
void HitRectSur::SetFillColor(const int rgb)
{
}
void HitRectSur::SetBorderColor(const int rgb, const bool fDashed, const int width)
{
}
void HitRectSur::SetLineColor(const int rgb, const bool fDashed, const int width)
{
}