1 #include "FormView.hpp"
2 #include "ScrollContainer.hpp"
3
SetFormSize(const Size & sz)4 void FormView::SetFormSize(const Size& sz)
5 {
6 FormLayout* l = GetCurrentLayout();
7 if (!l) return;
8 l->SetNumber("Form.Width", sz.cx);
9 l->SetNumber("Form.Height", sz.cy);
10 Layout();
11 if (_container)
12 _container->Layout();
13 }
14
RectToGrid(Rect & r)15 void FormView::RectToGrid(Rect& r)
16 {
17 Size g = GetGridSize();
18
19 if (r.left - r.left / g.cx * g.cx < g.cx / 2)
20 r.left -= r.left % g.cx;
21 else
22 r.left += g.cx - r.left % g.cx;
23
24 if (r.right - r.right / g.cx * g.cx < g.cx / 2)
25 r.right -= r.right % g.cx;
26 else
27 r.right += g.cx - r.right % g.cx;
28
29 if (r.top - r.top / g.cy * g.cy < g.cy / 2)
30 r.top -= r.top % g.cy;
31 else
32 r.top += g.cy - r.top % g.cy;
33
34 if (r.bottom - r.bottom / g.cy * g.cy < g.cy / 2)
35 r.bottom -= r.bottom % g.cy;
36 else
37 r.bottom += g.cy - r.bottom % g.cy;
38 }
39
PointToGrid(Point & r)40 void FormView::PointToGrid(Point& r)
41 {
42 Size g = GetGridSize();
43
44 if (r.x - r.x / g.cx * g.cx < g.cx / 2) r.x -= r.x % g.cx;
45 else r.x += g.cx - r.x % g.cx;
46 if (r.y - r.y / g.cy * g.cy < g.cy / 2) r.y -= r.y % g.cy;
47 else r.y += g.cy - r.y % g.cy;
48 }
49
XToGrid(int x,bool use)50 int FormView::XToGrid(int x, bool use)
51 {
52 Size g = GetGridSize();
53
54 if (!use) return x;
55 return (x - x / g.cx * g.cx < g.cx / 2)
56 ? x - x % g.cx
57 : x + g.cx - x % g.cx;
58 }
59
YToGrid(int y,bool use)60 int FormView::YToGrid(int y, bool use)
61 {
62 Size g = GetGridSize();
63
64 if (!use) return y;
65 return (y - y / g.cy * g.cy < g.cy / 2)
66 ? y - y % g.cy
67 : y + g.cy - y % g.cy;
68 }
69
IsObjectButton(Point p)70 bool FormView::IsObjectButton(Point p)
71 {
72 if (!IsLayout())
73 return false;
74
75 _frameResize = false;
76
77 Vector<int> sel = GetSelected();
78 if (sel.GetCount() == 1)
79 {
80 FormObject *pI = GetObject(sel[0]);
81 Rect r = Offseted(pI->GetRect());
82
83 if (Zoom(Rect( Point(r.right - 6, r.bottom - 6), Size(24, 24) ))
84 .Contains(p))
85 OverrideCursor(Image::SizeBottomRight);
86 else
87 {
88 OverrideCursor(_cursor);
89 return false;
90 }
91
92 return true;
93 }
94
95 if (sel.GetCount() != 0)
96 return false;
97
98 if (Zoom(Rect( Point(GetPageRect().right - 6, GetPageRect().bottom - 6), Size(24, 24) ))
99 .Contains(p))
100 {
101 OverrideCursor(Image::SizeBottomRight);
102 _frameResize = true;
103 return true;
104 }
105 else
106 {
107 OverrideCursor(_cursor);
108 return false;
109 }
110
111 OverrideCursor(_cursor);
112 return false;
113 }
114
IsGroupButton(Point p)115 dword FormView::IsGroupButton(Point p)
116 {
117 if (!IsLayout())
118 return TOOL_NONE;
119
120 _leftCur = 0;
121 _topCur = 0;
122 _rightCur = 0;
123 _bottomCur = 0;
124
125 Rect r = _groupRect;
126 Point p1;
127 Rect t;
128 int v;
129
130 p1 = r.TopLeft();
131 v = (r.BottomLeft().y >= GetRect().Height())
132 ? GetRect().Height() - (GetRect().Height() - r.TopLeft().y) / 2 - 16
133 : ((r.TopLeft().y < 0)
134 ? r.BottomLeft().y / 2 - 16
135 : r.CenterLeft().y - 16);
136 if (p1.x >= 20) // left tool
137 {
138 if ( Rect(Point(r.CenterLeft().x - 16, v), Size(24, 24)).Contains(p) )
139 {
140 _leftCur = 1; Refresh();
141 return TOOL_LEFT;
142 }
143 else
144 {
145 _leftCur = 0; Refresh();
146 }
147 }
148 else
149 {
150 if ( Rect(Point(0, v), Size(24, 24) ).Contains(p) )
151 {
152 _leftCur = 1; Refresh();
153 return TOOL_LEFT;
154 }
155 else
156 {
157 _leftCur = 0; Refresh();
158 }
159 }
160
161 v = (r.TopLeft().x < 0)
162 ? r.TopRight().x / 2 - 11
163 : (r.TopRight().x > GetRect().Width()
164 ? GetRect().Width() - (GetRect().Width() - r.TopLeft().x) / 2 - 11
165 : r.TopCenter().x - 11);
166 if (p1.y >= 20)
167 {
168 if ( Rect( Point(v, r.TopCenter().y - 16), Size(24, 24) ).Contains(p) )
169 {
170 _topCur = 1; Refresh();
171 return TOOL_TOP;
172 }
173 else
174 {
175 _topCur = 0; Refresh();
176 }
177 }
178 else
179 {
180 if ( Rect( Point(v, 2), Size(24, 24) ).Contains(p) )
181 {
182 _topCur = 1; Refresh();
183 return TOOL_TOP;
184 }
185 else
186 {
187 _topCur = 0; Refresh();
188 }
189 }
190
191 p1 = r.BottomRight();
192 v = (p1.y >= GetRect().Height())
193 ? GetRect().Height() - (GetRect().Height() - r.TopLeft().y) / 2 - 16
194 : ((r.TopLeft().y < 0)
195 ? r.BottomLeft().y / 2 - 16
196 : r.CenterLeft().y - 16);
197 if (p1.x <= GetRect().Width() - 20)
198 {
199 if ( Rect( Point(r.CenterRight().x - 6, v), Size(24, 24) ).Contains(p) )
200 {
201 _rightCur = 1; Refresh();
202 return TOOL_RIGHT;
203 }
204 else
205 {
206 _rightCur = 0; Refresh();
207 }
208 }
209 else
210 {
211 if ( Rect( Point(GetRect().Width() - 16, v), Size(24, 24) ).Contains(p) )
212 {
213 _rightCur = 1; Refresh();
214 return TOOL_RIGHT;
215 }
216 else
217 {
218 _rightCur = 0; Refresh();
219 }
220 }
221
222
223 v = (r.TopLeft().x < 0)
224 ? r.TopRight().x / 2 - 11
225 : (r.TopRight().x > GetRect().Width()
226 ? GetRect().Width() - (GetRect().Width() - r.TopLeft().x) / 2 - 11
227 : r.TopCenter().x - 11);
228 if (p1.y <= GetRect().Height() - 20)
229 {
230 if ( Rect( Point(v, r.BottomCenter().y - 8), Size(24, 24) ).Contains(p) )
231 {
232 _bottomCur = 1; Refresh();
233 return TOOL_BOTTOM;
234 }
235 else
236 {
237 _bottomCur = 0; Refresh();
238 }
239 }
240 else
241 {
242 if ( Rect( Point(v, GetRect().Height() - 16), Size(24, 24) ).Contains(p) )
243 {
244 _bottomCur = 1; Refresh();
245 return TOOL_BOTTOM;
246 }
247 else
248 {
249 _bottomCur = 0; Refresh();
250 }
251 }
252
253 return TOOL_NONE;
254 }
255