]>
Commit | Line | Data |
---|---|---|
1fc25a89 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: constrnt.cpp | |
3 | // Purpose: OGL Constraint classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 12/07/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "constrnt.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
92a19c2e | 17 | #include "wx/wxprec.h" |
1fc25a89 JS |
18 | |
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include <wx/wx.h> | |
25 | #endif | |
26 | ||
7c9955d1 | 27 | #include <wx/deprecated/wxexpr.h> |
1fc25a89 JS |
28 | |
29 | #include <wx/ogl/basic.h> | |
30 | #include <wx/ogl/constrnt.h> | |
31 | #include <wx/ogl/canvas.h> | |
32 | ||
33 | wxList *wxOGLConstraintTypes = NULL; | |
34 | ||
35 | /* | |
36 | * Constraint type | |
37 | * | |
38 | */ | |
39 | ||
40 | IMPLEMENT_DYNAMIC_CLASS(wxOGLConstraintType, wxObject) | |
41 | ||
42 | wxOGLConstraintType::wxOGLConstraintType(int theType, const wxString& theName, const wxString& thePhrase) | |
43 | { | |
44 | m_type = theType; | |
45 | m_name = theName; | |
46 | m_phrase = thePhrase; | |
47 | } | |
48 | ||
49 | wxOGLConstraintType::~wxOGLConstraintType() | |
50 | { | |
51 | } | |
52 | ||
53 | void OGLInitializeConstraintTypes() | |
54 | { | |
55 | if (!wxOGLConstraintTypes) | |
56 | return; | |
57 | ||
58 | wxOGLConstraintTypes = new wxList(wxKEY_INTEGER); | |
59 | ||
60 | wxOGLConstraintTypes->Append(gyCONSTRAINT_CENTRED_VERTICALLY, | |
9e053640 | 61 | new wxOGLConstraintType(gyCONSTRAINT_CENTRED_VERTICALLY, wxT("Centre vertically"), wxT("centred vertically w.r.t."))); |
1fc25a89 JS |
62 | |
63 | wxOGLConstraintTypes->Append(gyCONSTRAINT_CENTRED_HORIZONTALLY, | |
9e053640 | 64 | new wxOGLConstraintType(gyCONSTRAINT_CENTRED_HORIZONTALLY, wxT("Centre horizontally"), wxT("centred horizontally w.r.t."))); |
1fc25a89 JS |
65 | |
66 | wxOGLConstraintTypes->Append(gyCONSTRAINT_CENTRED_BOTH, | |
9e053640 | 67 | new wxOGLConstraintType(gyCONSTRAINT_CENTRED_BOTH, wxT("Centre"), wxT("centred w.r.t."))); |
1fc25a89 JS |
68 | |
69 | wxOGLConstraintTypes->Append(gyCONSTRAINT_LEFT_OF, | |
9e053640 | 70 | new wxOGLConstraintType(gyCONSTRAINT_LEFT_OF, wxT("Left of"), wxT("left of"))); |
1fc25a89 JS |
71 | |
72 | wxOGLConstraintTypes->Append(gyCONSTRAINT_RIGHT_OF, | |
9e053640 | 73 | new wxOGLConstraintType(gyCONSTRAINT_RIGHT_OF, wxT("Right of"), wxT("right of"))); |
1fc25a89 JS |
74 | |
75 | wxOGLConstraintTypes->Append(gyCONSTRAINT_ABOVE, | |
9e053640 | 76 | new wxOGLConstraintType(gyCONSTRAINT_ABOVE, wxT("Above"), wxT("above"))); |
1fc25a89 JS |
77 | |
78 | wxOGLConstraintTypes->Append(gyCONSTRAINT_BELOW, | |
9e053640 | 79 | new wxOGLConstraintType(gyCONSTRAINT_BELOW, wxT("Below"), wxT("below"))); |
1fc25a89 JS |
80 | |
81 | // Alignment | |
82 | wxOGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_TOP, | |
9e053640 | 83 | new wxOGLConstraintType(gyCONSTRAINT_ALIGNED_TOP, wxT("Top-aligned"), wxT("aligned to the top of"))); |
1fc25a89 JS |
84 | |
85 | wxOGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_BOTTOM, | |
9e053640 | 86 | new wxOGLConstraintType(gyCONSTRAINT_ALIGNED_BOTTOM, wxT("Bottom-aligned"), wxT("aligned to the bottom of"))); |
1fc25a89 JS |
87 | |
88 | wxOGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_LEFT, | |
9e053640 | 89 | new wxOGLConstraintType(gyCONSTRAINT_ALIGNED_LEFT, wxT("Left-aligned"), wxT("aligned to the left of"))); |
1fc25a89 JS |
90 | |
91 | wxOGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_RIGHT, | |
9e053640 | 92 | new wxOGLConstraintType(gyCONSTRAINT_ALIGNED_RIGHT, wxT("Right-aligned"), wxT("aligned to the right of"))); |
1fc25a89 JS |
93 | |
94 | // Mid-alignment | |
95 | wxOGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_TOP, | |
9e053640 | 96 | new wxOGLConstraintType(gyCONSTRAINT_MIDALIGNED_TOP, wxT("Top-midaligned"), wxT("centred on the top of"))); |
1fc25a89 JS |
97 | |
98 | wxOGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_BOTTOM, | |
9e053640 | 99 | new wxOGLConstraintType(gyCONSTRAINT_MIDALIGNED_BOTTOM, wxT("Bottom-midaligned"), wxT("centred on the bottom of"))); |
1fc25a89 JS |
100 | |
101 | wxOGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_LEFT, | |
9e053640 | 102 | new wxOGLConstraintType(gyCONSTRAINT_MIDALIGNED_LEFT, wxT("Left-midaligned"), wxT("centred on the left of"))); |
1fc25a89 JS |
103 | |
104 | wxOGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_RIGHT, | |
9e053640 | 105 | new wxOGLConstraintType(gyCONSTRAINT_MIDALIGNED_RIGHT, wxT("Right-midaligned"), wxT("centred on the right of"))); |
1fc25a89 JS |
106 | } |
107 | ||
108 | void OGLCleanUpConstraintTypes() | |
109 | { | |
110 | if (!wxOGLConstraintTypes) | |
111 | return; | |
112 | ||
b9ac87bc | 113 | wxNode* node = wxOGLConstraintTypes->GetFirst(); |
1fc25a89 JS |
114 | while (node) |
115 | { | |
b9ac87bc | 116 | wxOGLConstraintType* ct = (wxOGLConstraintType*) node->GetData(); |
1fc25a89 | 117 | delete ct; |
b9ac87bc | 118 | node = node->GetNext(); |
1fc25a89 JS |
119 | } |
120 | delete wxOGLConstraintTypes; | |
121 | wxOGLConstraintTypes = NULL; | |
122 | } | |
123 | ||
124 | /* | |
125 | * Constraint Stuff | |
126 | * | |
127 | */ | |
128 | ||
129 | IMPLEMENT_DYNAMIC_CLASS(wxOGLConstraint, wxObject) | |
130 | ||
131 | wxOGLConstraint::wxOGLConstraint(int type, wxShape *constraining, wxList& constrained) | |
132 | { | |
133 | m_xSpacing = 0.0; | |
134 | m_ySpacing = 0.0; | |
135 | ||
136 | m_constraintType = type; | |
137 | m_constrainingObject = constraining; | |
138 | ||
139 | m_constraintId = 0; | |
9e053640 | 140 | m_constraintName = wxT("noname"); |
1fc25a89 | 141 | |
b9ac87bc | 142 | wxNode *node = constrained.GetFirst(); |
1fc25a89 JS |
143 | while (node) |
144 | { | |
b9ac87bc RD |
145 | m_constrainedObjects.Append(node->GetData()); |
146 | node = node->GetNext(); | |
1fc25a89 JS |
147 | } |
148 | } | |
149 | ||
150 | wxOGLConstraint::~wxOGLConstraint() | |
151 | { | |
152 | } | |
153 | ||
154 | bool wxOGLConstraint::Equals(double a, double b) | |
155 | { | |
156 | double marg = 0.5; | |
157 | ||
158 | bool eq = ((b <= a + marg) && (b >= a - marg)); | |
159 | return eq; | |
160 | } | |
161 | ||
162 | // Return TRUE if anything changed | |
163 | bool wxOGLConstraint::Evaluate() | |
164 | { | |
165 | double maxWidth, maxHeight, minWidth, minHeight, x, y; | |
166 | m_constrainingObject->GetBoundingBoxMax(&maxWidth, &maxHeight); | |
167 | m_constrainingObject->GetBoundingBoxMin(&minWidth, &minHeight); | |
168 | x = m_constrainingObject->GetX(); | |
169 | y = m_constrainingObject->GetY(); | |
170 | ||
171 | wxClientDC dc(m_constrainingObject->GetCanvas()); | |
172 | m_constrainingObject->GetCanvas()->PrepareDC(dc); | |
173 | ||
174 | switch (m_constraintType) | |
175 | { | |
176 | case gyCONSTRAINT_CENTRED_VERTICALLY: | |
177 | { | |
b9ac87bc | 178 | int n = m_constrainedObjects.GetCount(); |
1fc25a89 | 179 | double totalObjectHeight = 0.0; |
b9ac87bc | 180 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
181 | while (node) |
182 | { | |
b9ac87bc | 183 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
184 | |
185 | double width2, height2; | |
186 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
187 | totalObjectHeight += height2; | |
b9ac87bc | 188 | node = node->GetNext(); |
1fc25a89 JS |
189 | } |
190 | double startY; | |
191 | double spacingY; | |
192 | // Check if within the constraining object... | |
193 | if ((totalObjectHeight + (n + 1)*m_ySpacing) <= minHeight) | |
194 | { | |
195 | spacingY = (double)((minHeight - totalObjectHeight)/(n + 1)); | |
196 | startY = (double)(y - (minHeight/2.0)); | |
197 | } | |
198 | // Otherwise, use default spacing | |
199 | else | |
200 | { | |
201 | spacingY = m_ySpacing; | |
202 | startY = (double)(y - ((totalObjectHeight + (n+1)*spacingY)/2.0)); | |
203 | } | |
204 | ||
205 | // Now position the objects | |
206 | bool changed = FALSE; | |
b9ac87bc | 207 | node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
208 | while (node) |
209 | { | |
b9ac87bc | 210 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
211 | double width2, height2; |
212 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
213 | startY += (double)(spacingY + (height2/2.0)); | |
214 | if (!Equals(startY, constrainedObject->GetY())) | |
215 | { | |
216 | constrainedObject->Move(dc, constrainedObject->GetX(), startY, FALSE); | |
217 | changed = TRUE; | |
218 | } | |
219 | startY += (double)(height2/2.0); | |
b9ac87bc | 220 | node = node->GetNext(); |
1fc25a89 JS |
221 | } |
222 | return changed; | |
223 | } | |
224 | case gyCONSTRAINT_CENTRED_HORIZONTALLY: | |
225 | { | |
b9ac87bc | 226 | int n = m_constrainedObjects.GetCount(); |
1fc25a89 | 227 | double totalObjectWidth = 0.0; |
b9ac87bc | 228 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
229 | while (node) |
230 | { | |
b9ac87bc | 231 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
232 | |
233 | double width2, height2; | |
234 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
235 | totalObjectWidth += width2; | |
b9ac87bc | 236 | node = node->GetNext(); |
1fc25a89 JS |
237 | } |
238 | double startX; | |
239 | double spacingX; | |
240 | // Check if within the constraining object... | |
241 | if ((totalObjectWidth + (n + 1)*m_xSpacing) <= minWidth) | |
242 | { | |
243 | spacingX = (double)((minWidth - totalObjectWidth)/(n + 1)); | |
244 | startX = (double)(x - (minWidth/2.0)); | |
245 | } | |
246 | // Otherwise, use default spacing | |
247 | else | |
248 | { | |
249 | spacingX = m_xSpacing; | |
250 | startX = (double)(x - ((totalObjectWidth + (n+1)*spacingX)/2.0)); | |
251 | } | |
252 | ||
253 | // Now position the objects | |
254 | bool changed = FALSE; | |
b9ac87bc | 255 | node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
256 | while (node) |
257 | { | |
b9ac87bc | 258 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
259 | double width2, height2; |
260 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
261 | startX += (double)(spacingX + (width2/2.0)); | |
262 | if (!Equals(startX, constrainedObject->GetX())) | |
263 | { | |
264 | constrainedObject->Move(dc, startX, constrainedObject->GetY(), FALSE); | |
265 | changed = TRUE; | |
266 | } | |
267 | startX += (double)(width2/2.0); | |
b9ac87bc | 268 | node = node->GetNext(); |
1fc25a89 JS |
269 | } |
270 | return changed; | |
271 | } | |
272 | case gyCONSTRAINT_CENTRED_BOTH: | |
273 | { | |
b9ac87bc | 274 | int n = m_constrainedObjects.GetCount(); |
1fc25a89 JS |
275 | double totalObjectWidth = 0.0; |
276 | double totalObjectHeight = 0.0; | |
b9ac87bc | 277 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
278 | while (node) |
279 | { | |
b9ac87bc | 280 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
281 | |
282 | double width2, height2; | |
283 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
284 | totalObjectWidth += width2; | |
285 | totalObjectHeight += height2; | |
b9ac87bc | 286 | node = node->GetNext(); |
1fc25a89 JS |
287 | } |
288 | double startX; | |
289 | double spacingX; | |
290 | double startY; | |
291 | double spacingY; | |
292 | ||
293 | // Check if within the constraining object... | |
294 | if ((totalObjectWidth + (n + 1)*m_xSpacing) <= minWidth) | |
295 | { | |
296 | spacingX = (double)((minWidth - totalObjectWidth)/(n + 1)); | |
297 | startX = (double)(x - (minWidth/2.0)); | |
298 | } | |
299 | // Otherwise, use default spacing | |
300 | else | |
301 | { | |
302 | spacingX = m_xSpacing; | |
303 | startX = (double)(x - ((totalObjectWidth + (n+1)*spacingX)/2.0)); | |
304 | } | |
305 | ||
306 | // Check if within the constraining object... | |
307 | if ((totalObjectHeight + (n + 1)*m_ySpacing) <= minHeight) | |
308 | { | |
309 | spacingY = (double)((minHeight - totalObjectHeight)/(n + 1)); | |
310 | startY = (double)(y - (minHeight/2.0)); | |
311 | } | |
312 | // Otherwise, use default spacing | |
313 | else | |
314 | { | |
315 | spacingY = m_ySpacing; | |
316 | startY = (double)(y - ((totalObjectHeight + (n+1)*spacingY)/2.0)); | |
317 | } | |
318 | ||
319 | // Now position the objects | |
320 | bool changed = FALSE; | |
b9ac87bc | 321 | node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
322 | while (node) |
323 | { | |
b9ac87bc | 324 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
325 | double width2, height2; |
326 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
327 | startX += (double)(spacingX + (width2/2.0)); | |
328 | startY += (double)(spacingY + (height2/2.0)); | |
329 | ||
330 | if ((!Equals(startX, constrainedObject->GetX())) || (!Equals(startY, constrainedObject->GetY()))) | |
331 | { | |
332 | constrainedObject->Move(dc, startX, startY, FALSE); | |
333 | changed = TRUE; | |
334 | } | |
335 | ||
336 | startX += (double)(width2/2.0); | |
337 | startY += (double)(height2/2.0); | |
338 | ||
b9ac87bc | 339 | node = node->GetNext(); |
1fc25a89 JS |
340 | } |
341 | return changed; | |
342 | } | |
343 | case gyCONSTRAINT_LEFT_OF: | |
344 | { | |
345 | bool changed = FALSE; | |
346 | ||
b9ac87bc | 347 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
348 | while (node) |
349 | { | |
b9ac87bc | 350 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
351 | |
352 | double width2, height2; | |
353 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
354 | ||
355 | double x3 = (double)(x - (minWidth/2.0) - (width2/2.0) - m_xSpacing); | |
356 | if (!Equals(x3, constrainedObject->GetX())) | |
357 | { | |
358 | changed = TRUE; | |
359 | constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE); | |
360 | } | |
361 | ||
b9ac87bc | 362 | node = node->GetNext(); |
1fc25a89 JS |
363 | } |
364 | return changed; | |
365 | } | |
366 | case gyCONSTRAINT_RIGHT_OF: | |
367 | { | |
368 | bool changed = FALSE; | |
369 | ||
b9ac87bc | 370 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
371 | while (node) |
372 | { | |
b9ac87bc | 373 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
374 | |
375 | double width2, height2; | |
376 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
377 | ||
378 | double x3 = (double)(x + (minWidth/2.0) + (width2/2.0) + m_xSpacing); | |
379 | if (!Equals(x3, constrainedObject->GetX())) | |
380 | { | |
381 | changed = TRUE; | |
382 | constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE); | |
383 | } | |
384 | ||
b9ac87bc | 385 | node = node->GetNext(); |
1fc25a89 JS |
386 | } |
387 | return changed; | |
388 | ||
389 | return FALSE; | |
390 | } | |
391 | case gyCONSTRAINT_ABOVE: | |
392 | { | |
393 | bool changed = FALSE; | |
394 | ||
b9ac87bc | 395 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
396 | while (node) |
397 | { | |
b9ac87bc | 398 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
399 | |
400 | double width2, height2; | |
401 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
402 | ||
403 | double y3 = (double)(y - (minHeight/2.0) - (height2/2.0) - m_ySpacing); | |
404 | if (!Equals(y3, constrainedObject->GetY())) | |
405 | { | |
406 | changed = TRUE; | |
407 | constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE); | |
408 | } | |
409 | ||
b9ac87bc | 410 | node = node->GetNext(); |
1fc25a89 JS |
411 | } |
412 | return changed; | |
413 | } | |
414 | case gyCONSTRAINT_BELOW: | |
415 | { | |
416 | bool changed = FALSE; | |
417 | ||
b9ac87bc | 418 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
419 | while (node) |
420 | { | |
b9ac87bc | 421 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
422 | |
423 | double width2, height2; | |
424 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
425 | ||
426 | double y3 = (double)(y + (minHeight/2.0) + (height2/2.0) + m_ySpacing); | |
427 | if (!Equals(y3, constrainedObject->GetY())) | |
428 | { | |
429 | changed = TRUE; | |
430 | constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE); | |
431 | } | |
432 | ||
b9ac87bc | 433 | node = node->GetNext(); |
1fc25a89 JS |
434 | } |
435 | return changed; | |
436 | } | |
437 | case gyCONSTRAINT_ALIGNED_LEFT: | |
438 | { | |
439 | bool changed = FALSE; | |
440 | ||
b9ac87bc | 441 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
442 | while (node) |
443 | { | |
b9ac87bc | 444 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
445 | |
446 | double width2, height2; | |
447 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
448 | ||
449 | double x3 = (double)(x - (minWidth/2.0) + (width2/2.0) + m_xSpacing); | |
450 | if (!Equals(x3, constrainedObject->GetX())) | |
451 | { | |
452 | changed = TRUE; | |
453 | constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE); | |
454 | } | |
455 | ||
b9ac87bc | 456 | node = node->GetNext(); |
1fc25a89 JS |
457 | } |
458 | return changed; | |
459 | } | |
460 | case gyCONSTRAINT_ALIGNED_RIGHT: | |
461 | { | |
462 | bool changed = FALSE; | |
463 | ||
b9ac87bc | 464 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
465 | while (node) |
466 | { | |
b9ac87bc | 467 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
468 | |
469 | double width2, height2; | |
470 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
471 | ||
472 | double x3 = (double)(x + (minWidth/2.0) - (width2/2.0) - m_xSpacing); | |
473 | if (!Equals(x3, constrainedObject->GetX())) | |
474 | { | |
475 | changed = TRUE; | |
476 | constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE); | |
477 | } | |
478 | ||
b9ac87bc | 479 | node = node->GetNext(); |
1fc25a89 JS |
480 | } |
481 | return changed; | |
482 | ||
483 | return FALSE; | |
484 | } | |
485 | case gyCONSTRAINT_ALIGNED_TOP: | |
486 | { | |
487 | bool changed = FALSE; | |
488 | ||
b9ac87bc | 489 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
490 | while (node) |
491 | { | |
b9ac87bc | 492 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
493 | |
494 | double width2, height2; | |
495 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
496 | ||
497 | double y3 = (double)(y - (minHeight/2.0) + (height2/2.0) + m_ySpacing); | |
498 | if (!Equals(y3, constrainedObject->GetY())) | |
499 | { | |
500 | changed = TRUE; | |
501 | constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE); | |
502 | } | |
503 | ||
b9ac87bc | 504 | node = node->GetNext(); |
1fc25a89 JS |
505 | } |
506 | return changed; | |
507 | } | |
508 | case gyCONSTRAINT_ALIGNED_BOTTOM: | |
509 | { | |
510 | bool changed = FALSE; | |
511 | ||
b9ac87bc | 512 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
513 | while (node) |
514 | { | |
b9ac87bc | 515 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
516 | |
517 | double width2, height2; | |
518 | constrainedObject->GetBoundingBoxMax(&width2, &height2); | |
519 | ||
520 | double y3 = (double)(y + (minHeight/2.0) - (height2/2.0) - m_ySpacing); | |
521 | if (!Equals(y3, constrainedObject->GetY())) | |
522 | { | |
523 | changed = TRUE; | |
524 | constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE); | |
525 | } | |
526 | ||
b9ac87bc | 527 | node = node->GetNext(); |
1fc25a89 JS |
528 | } |
529 | return changed; | |
530 | } | |
531 | case gyCONSTRAINT_MIDALIGNED_LEFT: | |
532 | { | |
533 | bool changed = FALSE; | |
534 | ||
b9ac87bc | 535 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
536 | while (node) |
537 | { | |
b9ac87bc | 538 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
539 | |
540 | double x3 = (double)(x - (minWidth/2.0)); | |
541 | if (!Equals(x3, constrainedObject->GetX())) | |
542 | { | |
543 | changed = TRUE; | |
544 | constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE); | |
545 | } | |
546 | ||
b9ac87bc | 547 | node = node->GetNext(); |
1fc25a89 JS |
548 | } |
549 | return changed; | |
550 | } | |
551 | case gyCONSTRAINT_MIDALIGNED_RIGHT: | |
552 | { | |
553 | bool changed = FALSE; | |
554 | ||
b9ac87bc | 555 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
556 | while (node) |
557 | { | |
b9ac87bc | 558 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
559 | |
560 | double x3 = (double)(x + (minWidth/2.0)); | |
561 | if (!Equals(x3, constrainedObject->GetX())) | |
562 | { | |
563 | changed = TRUE; | |
564 | constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE); | |
565 | } | |
566 | ||
b9ac87bc | 567 | node = node->GetNext(); |
1fc25a89 JS |
568 | } |
569 | return changed; | |
570 | ||
571 | return FALSE; | |
572 | } | |
573 | case gyCONSTRAINT_MIDALIGNED_TOP: | |
574 | { | |
575 | bool changed = FALSE; | |
576 | ||
b9ac87bc | 577 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
578 | while (node) |
579 | { | |
b9ac87bc | 580 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
581 | |
582 | double y3 = (double)(y - (minHeight/2.0)); | |
583 | if (!Equals(y3, constrainedObject->GetY())) | |
584 | { | |
585 | changed = TRUE; | |
586 | constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE); | |
587 | } | |
588 | ||
b9ac87bc | 589 | node = node->GetNext(); |
1fc25a89 JS |
590 | } |
591 | return changed; | |
592 | } | |
593 | case gyCONSTRAINT_MIDALIGNED_BOTTOM: | |
594 | { | |
595 | bool changed = FALSE; | |
596 | ||
b9ac87bc | 597 | wxNode *node = m_constrainedObjects.GetFirst(); |
1fc25a89 JS |
598 | while (node) |
599 | { | |
b9ac87bc | 600 | wxShape *constrainedObject = (wxShape *)node->GetData(); |
1fc25a89 JS |
601 | |
602 | double y3 = (double)(y + (minHeight/2.0)); | |
603 | if (!Equals(y3, constrainedObject->GetY())) | |
604 | { | |
605 | changed = TRUE; | |
606 | constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE); | |
607 | } | |
608 | ||
b9ac87bc | 609 | node = node->GetNext(); |
1fc25a89 JS |
610 | } |
611 | return changed; | |
612 | } | |
613 | ||
614 | default: | |
615 | return FALSE; | |
616 | } | |
617 | return FALSE; | |
618 | } | |
619 |