1 /*
2  * Project: VizKit
3  * Version: 2.3
4 
5  * Date: 20090823
6  * File: VisualStageBox.cpp
7  *
8  */
9 
10 /***************************************************************************
11 
12 Copyright (c) 2004-2009 Heiko Wichmann (http://www.imagomat.de/vizkit)
13 
14 
15 This software is provided 'as-is', without any expressed or implied warranty.
16 In no event will the authors be held liable for any damages
17 arising from the use of this software.
18 
19 Permission is granted to anyone to use this software for any purpose,
20 including commercial applications, and to alter it and redistribute it
21 freely, subject to the following restrictions:
22 
23 1. The origin of this software must not be misrepresented;
24    you must not claim that you wrote the original software.
25    If you use this software in a product, an acknowledgment
26    in the product documentation would be appreciated
27    but is not required.
28 
29 2. Altered source versions must be plainly marked as such,
30    and must not be misrepresented as being the original software.
31 
32 3. This notice may not be removed or altered from any source distribution.
33 
34  ***************************************************************************/
35 
36 #include "VisualStageBox.h"
37 #include "VisualGraphics.h"
38 #include "VisualErrorHandling.h"
39 #include "VisualGraphicTypes.h"
40 #include "VisualVertex.h"
41 #include "VisualAsset.h"
42 #include "VisualImage.h"
43 #include "VisualCamera.h"
44 
45 using namespace VizKit;
46 
47 
VisualStageBox(VisualAsset * anAssetRef)48 VisualStageBox::VisualStageBox(VisualAsset* anAssetRef) {
49 
50 	topCoord = 0.0;
51 	leftCoord = 0.0;
52 	bottomCoord = 0.0;
53 	rightCoord = 0.0;
54 
55 	this->coordWidth = 0.0;
56 	unscaledCoordWidth = 0.0;
57 	this->coordHeight = 0.0;
58 	unscaledCoordHeight = 0.0;
59 	coordDepth = 0.0;
60 	unscaledCoordDepth = 0.0;
61 
62 	contentPixelWidth = 0;
63 	contentPixelHeight = 0;
64 
65 	scalingBehaviour = kPreserveAspectRatio;
66 	scaleFactor = 1.0;
67 
68 	hasLayout = false;
69 
70 	assetRef = anAssetRef;
71 
72 	if (anAssetRef == NULL) {
73 		char errLog[64];
74 		sprintf(errLog, "ERR: assetRef == NULL in file: %s (line: %d) [%s])", __FILE__, __LINE__, __FUNCTION__);
75 		writeLog(errLog);
76 	}
77 
78 	debugMode = false;
79 
80 	// initially 2-D
81 	VisualCamera aCamera;
82 	aCamera.setOrthographicProjection();
83 	frontPosition = aCamera.getMaxNearPos();
84 	backPosition = aCamera.getMaxNearPos();
85 
86 }
87 
88 
~VisualStageBox()89 VisualStageBox::~VisualStageBox() {
90 	removeAllVertexChains();
91 }
92 
93 
VisualStageBox(const VisualStageBox & other)94 VisualStageBox::VisualStageBox(const VisualStageBox& other) {
95 	copy(other);
96 }
97 
98 
operator =(const VisualStageBox & other)99 VisualStageBox& VisualStageBox::operator=(const VisualStageBox& other) {
100 
101 	if (this == &other) return *this;
102 
103 	this->removeAllVertexChains();
104 	this->copy(other);
105 
106 	return *this;
107 }
108 
109 
copy(const VisualStageBox & other)110 void VisualStageBox::copy(const VisualStageBox& other) {
111 	this->topCoord = other.topCoord;
112 	this->leftCoord = other.leftCoord;
113 	this->bottomCoord = other.bottomCoord;
114 	this->rightCoord = other.rightCoord;
115 
116 	this->coordWidth = other.coordWidth;
117 	this->unscaledCoordWidth = other.unscaledCoordWidth;
118 	this->coordHeight = other.coordHeight;
119 	this->unscaledCoordHeight = other.unscaledCoordHeight;
120 	this->coordDepth = other.coordDepth;
121 	this->unscaledCoordDepth = other.unscaledCoordDepth;
122 
123 	this->contentPixelWidth = other.contentPixelWidth;
124 	this->contentPixelHeight = other.contentPixelHeight;
125 
126 	this->stagePosition = other.stagePosition;
127 	this->scalingBehaviour = other.scalingBehaviour;
128 	this->scaleFactor = other.scaleFactor;
129 
130 	this->hasLayout = other.hasLayout;
131 
132 	for (ConstVertexChainMapIterator mapIt = other.vertexChainMap.begin(); mapIt != other.vertexChainMap.end(); mapIt++) {
133 		VisualItemIdentifier mapId = mapIt->first;
134 		this->vertexChainMap[mapId] = new VertexChain;
135 		for (ConstVertexChainIterator chainIt = mapIt->second->begin(); chainIt != mapIt->second->end(); chainIt++) {
136 			this->vertexChainMap[mapId]->push_back(new VisualVertex(**chainIt));
137 		}
138 	}
139 
140 	this->assetRef = other.assetRef;
141 
142 	this->debugMode = other.debugMode;
143 }
144 
145 
setContentPixelWidth(uint32 pixelWidth)146 void VisualStageBox::setContentPixelWidth(uint32 pixelWidth) {
147 	if (this->contentPixelWidth != pixelWidth) {
148 		this->contentPixelWidth = pixelWidth;
149 		this->hasLayout = false;
150 	}
151 }
152 
153 
setContentPixelHeight(uint32 pixelHeight)154 void VisualStageBox::setContentPixelHeight(uint32 pixelHeight) {
155 	if (this->contentPixelHeight != pixelHeight) {
156 		this->contentPixelHeight = pixelHeight;
157 		this->hasLayout = false;
158 	}
159 }
160 
161 
setCoordDepth(double aCoordDepth)162 void VisualStageBox::setCoordDepth(double aCoordDepth) {
163 	if (this->coordDepth != aCoordDepth) {
164 		this->coordDepth = aCoordDepth;
165 		this->unscaledCoordDepth = aCoordDepth;
166 		this->hasLayout = false;
167 	}
168 }
169 
170 
setFrontPosition(double aFrontPosition)171 void VisualStageBox::setFrontPosition(double aFrontPosition) {
172 	if (this->frontPosition != aFrontPosition) {
173 		this->frontPosition = aFrontPosition;
174 		this->hasLayout = false;
175 	}
176 }
177 
178 
getFrontPosition()179 double VisualStageBox::getFrontPosition() {
180 	if (this->hasLayout == false) {
181 		this->calcCoords(this->assetRef->getCamera());
182 	}
183 	return this->frontPosition;
184 }
185 
186 
setBackPosition(double aBackPosition)187 void VisualStageBox::setBackPosition(double aBackPosition)  {
188 	if (this->backPosition != aBackPosition) {
189 		this->backPosition = aBackPosition;
190 		this->hasLayout = false;
191 	}
192 }
193 
194 
getBackPosition(void)195 double VisualStageBox::getBackPosition(void) {
196 	if (this->hasLayout == false) {
197 		this->calcCoords(this->assetRef->getCamera());
198 	}
199 	return this->backPosition;
200 }
201 
202 
setVisualStagePosition(const VisualStagePosition & aPosition)203 void VisualStageBox::setVisualStagePosition(const VisualStagePosition& aPosition) {
204 	if (this->stagePosition != aPosition) {
205 		this->stagePosition = aPosition;
206 		this->hasLayout = false;
207 	}
208 }
209 
210 
setScalingBehaviour(ScalingBehaviour aScalingBehaviour)211 void VisualStageBox::setScalingBehaviour(ScalingBehaviour aScalingBehaviour) {
212 	if (aScalingBehaviour != this->scalingBehaviour) {
213 		this->scalingBehaviour = aScalingBehaviour;
214 		this->hasLayout = false;
215 	}
216 }
217 
218 
setScaleFactor(double aScaleFactor)219 void VisualStageBox::setScaleFactor(double aScaleFactor) {
220 	if (aScaleFactor != this->scaleFactor) {
221 		this->scaleFactor = aScaleFactor;
222 		this->hasLayout = false;
223 	}
224 }
225 
226 
setDirty()227 void VisualStageBox::setDirty() {
228 	this->hasLayout = false;
229 }
230 
231 
update()232 void VisualStageBox::update() {
233 	this->hasLayout = false;
234 	this->calcCoords(this->assetRef->getCamera());
235 }
236 
237 
updateIfNeeded()238 void VisualStageBox::updateIfNeeded() {
239 	if (this->hasLayout == false) {
240 		this->calcCoords(this->assetRef->getCamera());
241 	}
242 }
243 
244 
calcCoords(const VisualCamera & aCamera)245 void VisualStageBox::calcCoords(const VisualCamera& aCamera) {
246 
247 	double top = 0.0;
248 	double left = 0.0;
249 	double bottom = 0.0;
250 	double right = 0.0;
251 
252 	double marginLeftCoord = 0.0;
253 	double marginRightCoord = 0.0;
254 	double marginTopCoord = 0.0;
255 	double marginBottomCoord = 0.0;
256 	double minMarginLeftCoord = 0.0;
257 	double minMarginRightCoord = 0.0;
258 	double minMarginTopCoord = 0.0;
259 	double minMarginBottomCoord = 0.0;
260 
261 	double finalMarginLeftCoord = 0.0;
262 	double finalMarginRightCoord = 0.0;
263 	double finalMarginTopCoord = 0.0;
264 	double finalMarginBottomCoord = 0.0;
265 
266 	double prevCoordVal = 0.0;
267 
268 	//printf("hwtest finalMarginLeftCoord1: %f\n", finalMarginLeftCoord);
269 
270 	VisualGraphics* theVisualGraphics = VisualGraphics::getInstance();
271 
272 	//printf("hwtest contentPixelWidth: %f, getCanvasPixelWidth: %f, getCanvasCoordWidth: %f\n", (double)this->contentPixelWidth, (double)theVisualGraphics->getCanvasPixelWidth(), size.width);
273 
274 	//printf("hwtest coordWidth1: %f\n", this->coordWidth);
275 	//this->contentPixelWidth = 0;
276 	//printf("hwtesthwtest: %ld, %f\n", this->contentPixelWidth, (double)this->contentPixelWidth);
277 
278 	CoordSize3D size = aCamera.getSize();
279 	this->coordWidth = size.width * ((double)this->contentPixelWidth / (double)theVisualGraphics->getCanvasPixelWidth());
280 	//printf("hwtest coordWidth2: %f\n", this->coordWidth);
281 	this->coordHeight = size.height * ((double)this->contentPixelHeight / (double)theVisualGraphics->getCanvasPixelHeight());
282 
283 	// calc margin values
284 	if (this->stagePosition.marginBottom != 0.0) {
285 		if (this->stagePosition.marginBottomUnit == kPercent) {
286 			marginBottomCoord = size.height * (this->stagePosition.marginBottom / 100.0);
287 		} else if (this->stagePosition.marginBottomUnit == kPixel) {
288 			marginBottomCoord = theVisualGraphics->yPixelToCoord((uint16)this->stagePosition.marginBottom, aCamera);
289 		}
290 	}
291 
292 	if (this->stagePosition.marginTop != 0.0) {
293 		if (this->stagePosition.marginBottomUnit == kPercent) {
294 			marginTopCoord = size.height * (this->stagePosition.marginBottom / 100.0);
295 		} else if (this->stagePosition.marginTopUnit == kPixel) {
296 			marginTopCoord = theVisualGraphics->yPixelToCoord((uint16)this->stagePosition.marginTop, aCamera);
297 		}
298 	}
299 
300 	if (this->stagePosition.marginLeft != 0.0) {
301 		if (this->stagePosition.marginLeftUnit == kPercent) {
302 			marginLeftCoord = size.width * (this->stagePosition.marginLeft / 100.0);
303 		} else if (this->stagePosition.marginLeftUnit == kPixel) {
304 			marginLeftCoord = theVisualGraphics->xPixelToCoord((uint16)this->stagePosition.marginLeft, aCamera);
305 		}
306 	}
307 
308 	if (this->stagePosition.marginRight != 0.0) {
309 		if (this->stagePosition.marginRightUnit == kPercent) {
310 			marginRightCoord = size.width * (this->stagePosition.marginRight / 100.0);
311 		} else if (this->stagePosition.marginRightUnit == kPixel) {
312 			marginRightCoord = theVisualGraphics->xPixelToCoord((uint16)this->stagePosition.marginRight, aCamera);
313 		}
314 	}
315 
316 	if (this->stagePosition.minMarginBottom != 0.0) {
317 		if (this->stagePosition.minMarginBottomUnit == kPercent) {
318 			minMarginBottomCoord = size.height * (this->stagePosition.minMarginBottom / 100.0);
319 		} else if (this->stagePosition.minMarginBottomUnit == kPixel) {
320 			minMarginBottomCoord = theVisualGraphics->yPixelToCoord((uint16)this->stagePosition.minMarginBottom, aCamera);
321 		}
322 	}
323 
324 	if (this->stagePosition.minMarginTop != 0.0) {
325 		if (this->stagePosition.minMarginTopUnit == kPercent) {
326 			minMarginTopCoord = size.height * (this->stagePosition.minMarginTop / 100.0);
327 		} else if (this->stagePosition.minMarginTopUnit == kPixel) {
328 			minMarginTopCoord = theVisualGraphics->yPixelToCoord((uint16)this->stagePosition.minMarginTop, aCamera);
329 		}
330 	}
331 
332 	if (this->stagePosition.minMarginLeft != 0.0) {
333 		if (this->stagePosition.minMarginLeftUnit == kPercent) {
334 			minMarginLeftCoord = size.width * (this->stagePosition.minMarginLeft / 100.0);
335 		} else if (this->stagePosition.minMarginLeftUnit == kPixel) {
336 			minMarginLeftCoord = theVisualGraphics->xPixelToCoord((uint16)this->stagePosition.minMarginLeft, aCamera);
337 		}
338 	}
339 
340 	if (this->stagePosition.minMarginRight != 0.0) {
341 		if (this->stagePosition.minMarginRightUnit == kPercent) {
342 			minMarginRightCoord = size.width * (this->stagePosition.minMarginRight / 100.0);
343 		} else if (this->stagePosition.minMarginRightUnit == kPixel) {
344 			minMarginRightCoord = theVisualGraphics->xPixelToCoord((uint16)this->stagePosition.minMarginRight, aCamera);
345 		}
346 	}
347 
348 	//printf("hwtest finalMarginLeftCoord2: %f\n", finalMarginLeftCoord);
349 	//printf("hwtest coordWidth102: %f\n", this->coordWidth);
350 
351 	// calc finalMarginValues
352 	if (marginTopCoord > 0.0) {
353 		finalMarginTopCoord = marginTopCoord;
354 	}
355 	if (marginLeftCoord > 0.0) {
356 		finalMarginLeftCoord = marginLeftCoord;
357 	}
358 	if (marginBottomCoord > 0.0) {
359 		finalMarginBottomCoord = marginBottomCoord;
360 	}
361 	if (marginRightCoord > 0.0) {
362 		finalMarginRightCoord = marginRightCoord;
363 	}
364 	// wider than canvas
365 	if (this->coordWidth > (size.width - minMarginRightCoord - minMarginLeftCoord)) {
366 		prevCoordVal = this->coordWidth;
367 		this->coordWidth = size.width - minMarginRightCoord - minMarginLeftCoord;
368 		if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
369 			if (prevCoordVal > 0.0) {
370 				this->coordHeight = this->coordHeight * (this->coordWidth / prevCoordVal);
371 			}
372 		}
373 		finalMarginLeftCoord = minMarginLeftCoord;
374 		finalMarginRightCoord = minMarginRightCoord;
375 	}
376 	// higher than canvas
377 	if (this->coordHeight > (size.height - minMarginTopCoord - minMarginBottomCoord)) {
378 		prevCoordVal = this->coordHeight;
379 		this->coordHeight = size.height - minMarginTopCoord - minMarginBottomCoord;
380 		if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
381 			if (prevCoordVal > 0.0) {
382 				this->coordWidth = this->coordWidth * (this->coordHeight / prevCoordVal);
383 			}
384 		}
385 		finalMarginTopCoord = minMarginTopCoord;
386 		finalMarginBottomCoord = minMarginBottomCoord;
387 	}
388 
389 	if (this->coordWidth == 0.0) {
390 		this->coordWidth = size.width - finalMarginLeftCoord - finalMarginRightCoord;
391 	}
392 	if (this->coordHeight == 0.0) {
393 		this->coordHeight = size.height - finalMarginTopCoord - finalMarginBottomCoord;
394 	}
395 
396 	// calc coordWidth and coordHeight
397 	if ((this->scalingBehaviour & kScalingAllowed) == kScalingAllowed) {
398 
399 		// < minWidth
400 		if (this->stagePosition.minWidth > 0.0) {
401 			prevCoordVal = this->coordWidth;
402 			if ((this->stagePosition.minWidthUnit == kPercent) && ((this->coordWidth / size.width * 100.0) < this->stagePosition.minWidth)) {
403 				this->coordWidth = this->stagePosition.minWidth * size.width / 100.0;
404 				if (this->coordWidth > (size.width - (minMarginLeftCoord + minMarginRightCoord))) {
405 					this->coordWidth -= (minMarginLeftCoord + minMarginRightCoord);
406 				} else {
407 					this->coordWidth -= (finalMarginLeftCoord + finalMarginRightCoord);
408 				}
409 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
410 					if (prevCoordVal > 0.0) {
411 						this->coordHeight = this->coordHeight * (this->coordWidth / prevCoordVal);
412 					}
413 				}
414 			} else if ((this->stagePosition.minWidthUnit == kPixel) && (static_cast<double>(theVisualGraphics->xCoordToPixel(this->coordWidth, aCamera)) < this->stagePosition.minWidth)) {
415 				this->coordWidth = theVisualGraphics->xPixelToCoord((uint16)this->stagePosition.minWidth, aCamera);
416 				if (this->coordWidth > (size.width - (minMarginLeftCoord + minMarginRightCoord))) {
417 					this->coordWidth -= (minMarginLeftCoord + minMarginRightCoord);
418 				} else {
419 					this->coordWidth -= (finalMarginLeftCoord + finalMarginRightCoord);
420 				}
421 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
422 					if (prevCoordVal > 0.0) {
423 						this->coordHeight = this->coordHeight * (this->coordWidth / prevCoordVal);
424 					}
425 				}
426 			}
427 		}
428 
429 		//printf("hwtest coordWidth103: %f (%f)\n", this->coordWidth, this->stagePosition.minHeight);
430 
431 		// < minHeight
432 		if (this->stagePosition.minHeight > 0.0) {
433 			prevCoordVal = this->coordHeight;
434 			if ((this->stagePosition.minHeightUnit == kPercent) && ((this->coordHeight / size.height * 100.0) < this->stagePosition.minHeight)) {
435 				this->coordHeight = this->stagePosition.minHeight * size.height / 100.0;
436 				if (this->coordHeight > (size.height - (minMarginTopCoord + minMarginBottomCoord))) {
437 					this->coordHeight -= (minMarginTopCoord + minMarginBottomCoord);
438 				} else {
439 					this->coordHeight -= (finalMarginTopCoord + finalMarginBottomCoord);
440 				}
441 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
442 					if (prevCoordVal > 0.0) {
443 						this->coordWidth = this->coordWidth * (this->coordHeight / prevCoordVal);
444 						//printf("hwtest coordWidth103a: %f\n", this->coordWidth);
445 					}
446 				}
447 			} else if ((this->stagePosition.minHeightUnit == kPixel) && (static_cast<double>(theVisualGraphics->yCoordToPixel(this->coordHeight, aCamera)) < this->stagePosition.minHeight)) {
448 				this->coordHeight = theVisualGraphics->xPixelToCoord((uint16)this->stagePosition.minHeight, aCamera);
449 				if (this->coordHeight > (size.height - (minMarginTopCoord + minMarginBottomCoord))) {
450 					this->coordHeight -= (minMarginTopCoord + minMarginBottomCoord);
451 				} else {
452 					this->coordHeight -= (finalMarginTopCoord + finalMarginBottomCoord);
453 				}
454 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
455 					if (prevCoordVal > 0.0) {
456 						this->coordWidth = this->coordWidth * (this->coordHeight / prevCoordVal);
457 						//printf("hwtest coordWidth103b: %f\n", this->coordWidth);
458 					}
459 				}
460 			}
461 		}
462 
463 		// > maxWidth
464 		if (this->stagePosition.maxWidth > 0.0) {
465 			prevCoordVal = this->coordWidth;
466 			if ((this->stagePosition.maxWidthUnit == kPercent) && ((this->coordWidth / size.width * 100.0) > this->stagePosition.maxWidth)) {
467 				this->coordWidth = this->stagePosition.maxWidth * size.width / 100.0;
468 				//printf("hwtest coordWidth103c: %f\n", this->coordWidth);
469 				if (this->coordWidth > (size.width - (minMarginLeftCoord + minMarginRightCoord))) {
470 					this->coordWidth -= (minMarginLeftCoord + minMarginRightCoord);
471 					//printf("hwtest coordWidth103d: %f\n", this->coordWidth);
472 				} else {
473 					this->coordWidth -= (finalMarginLeftCoord + finalMarginRightCoord);
474 					//printf("hwtest coordWidth103e: %f\n", this->coordWidth);
475 				}
476 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
477 					if (prevCoordVal > 0.0) {
478 						this->coordHeight = this->coordHeight * (this->coordWidth / prevCoordVal);
479 					}
480 				}
481 			} else if ((this->stagePosition.maxWidthUnit == kPixel) && (static_cast<double>(theVisualGraphics->xCoordToPixel(this->coordWidth, aCamera)) > this->stagePosition.maxWidth)) {
482 				this->coordWidth = theVisualGraphics->xPixelToCoord((uint16)this->stagePosition.maxWidth, aCamera);
483 				if (this->coordWidth > (size.width - (minMarginLeftCoord + minMarginRightCoord))) {
484 					this->coordWidth -= (minMarginLeftCoord + minMarginRightCoord);
485 					//printf("hwtest coordWidth103f: %f\n", this->coordWidth);
486 				} else {
487 					this->coordWidth -= (finalMarginLeftCoord + finalMarginRightCoord);
488 					//printf("hwtest coordWidth103g: %f\n", this->coordWidth);
489 				}
490 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
491 					if (prevCoordVal > 0.0) {
492 						this->coordHeight = this->coordHeight * (this->coordWidth / prevCoordVal);
493 					}
494 				}
495 			}
496 		}
497 
498 		//printf("hwtest coordWidth104: %f\n", this->coordWidth);
499 
500 		// > maxHeight
501 		if (this->stagePosition.maxHeight > 0.0) {
502 			prevCoordVal = this->coordHeight;
503 			if ((this->stagePosition.maxHeightUnit == kPercent) && ((this->coordHeight / size.height * 100.0) > this->stagePosition.maxHeight)) {
504 				this->coordHeight = this->stagePosition.maxHeight * size.height / 100.0;
505 				if (this->coordHeight > (size.height - (minMarginTopCoord + minMarginBottomCoord))) {
506 					this->coordHeight -= (minMarginTopCoord + minMarginBottomCoord);
507 				} else {
508 					this->coordHeight -= (finalMarginTopCoord + finalMarginBottomCoord);
509 				}
510 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
511 					if (prevCoordVal > 0.0) {
512 						this->coordWidth = this->coordWidth * (this->coordHeight / prevCoordVal);
513 					}
514 				}
515 			} else if ((this->stagePosition.maxHeightUnit == kPixel) && (static_cast<double>(theVisualGraphics->yCoordToPixel(this->coordHeight, aCamera)) > this->stagePosition.maxHeight)) {
516 				this->coordHeight = theVisualGraphics->xPixelToCoord((uint16)this->stagePosition.maxHeight, aCamera);
517 				if (this->coordHeight > (size.height - (minMarginTopCoord + minMarginBottomCoord))) {
518 					this->coordHeight -= (minMarginTopCoord + minMarginBottomCoord);
519 				} else {
520 					this->coordHeight -= (finalMarginTopCoord + finalMarginBottomCoord);
521 				}
522 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
523 					if (prevCoordVal > 0.0) {
524 						//this->coordWidth = this->coordWidth * (this->coordHeight / prevCoordVal * (size.width / size.height));
525 						this->coordWidth = this->coordWidth * (this->coordHeight / prevCoordVal);
526 					}
527 				}
528 			}
529 		}
530 
531 		//printf("hwtest coordWidth105: %f\n", this->coordWidth);
532 
533 		//printf("hwtest finalMarginLeftCoord3: %f\n", finalMarginLeftCoord);
534 
535 		if (!((this->scalingBehaviour & kClippingAllowed) == kClippingAllowed)) {
536 			if (this->coordWidth > (size.width - (minMarginLeftCoord + minMarginRightCoord))) {
537 				prevCoordVal = this->coordWidth;
538 				this->coordWidth = size.width - (minMarginLeftCoord + minMarginRightCoord);
539 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
540 					if (prevCoordVal > 0.0) {
541 						this->coordHeight = this->coordHeight * (this->coordWidth / prevCoordVal);
542 					}
543 				}
544 			}
545 			if (this->coordHeight > (size.height - (minMarginTopCoord + minMarginBottomCoord))) {
546 				prevCoordVal = this->coordHeight;
547 				this->coordHeight = size.height - (minMarginTopCoord + minMarginBottomCoord);
548 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
549 					if (prevCoordVal > 0.0) {
550 						this->coordWidth = this->coordWidth * (this->coordHeight / prevCoordVal);
551 					}
552 				}
553 			}
554 		}
555 
556 /*
557 		if (!((this->scalingBehaviour & kClippingAllowed) == kClippingAllowed)) {
558 			double aspectRatioCanvas = size.width / size.height;
559 			double aspectRatioCover = coverArtTextureContainer->getImageWidth() / coverArtTextureContainer->getImageHeight();
560 			coordWidthUnscaled = (double)size.width * ((double)coverArtTextureContainer->getImageWidth() / (double)theVisualGraphics->getCanvasPixelWidth());
561 			coordHeightUnscaled = (double)size.height * ((double)coverArtTextureContainer->getImageHeight() / (double)theVisualGraphics->getCanvasPixelHeight());
562 			if (aspectRatioCanvas > aspectRatioCover) {
563 				prevCoordVal = this->coordWidth;
564 				this->coordWidth = (double)size.width;
565 				this->coordHeight = coordHeightUnscaled * (this->coordWidth / coordWidthUnscaled);
566 			} else {
567 				this->coordHeight = (double)size.height;
568 				this->coordWidth = coordWidthUnscaled * (this->coordHeight / coordHeightUnscaled);
569 			}
570 		}
571 */
572 	}
573 
574 	//printf("hwtest finalMarginLeftCoord4: %f\n", finalMarginLeftCoord);
575 
576 	//printf("this->coordHeight: %f, this->coordWidth: %f\n", this->coordHeight, this->coordWidth);
577 
578 	// recalc finalMarginCoords
579 	if (this->stagePosition.verticalAlignment == kTopAligned) {
580 		if (minMarginTopCoord > marginTopCoord) {
581 			finalMarginTopCoord = minMarginTopCoord;
582 		} else {
583 			finalMarginTopCoord = marginTopCoord;
584 		}
585 		if (minMarginBottomCoord > marginBottomCoord) {
586 			finalMarginBottomCoord = minMarginBottomCoord;
587 		} else {
588 			finalMarginBottomCoord = marginBottomCoord;
589 		}
590 		if (this->coordHeight < (size.height - (finalMarginTopCoord + finalMarginBottomCoord))) {
591 			finalMarginBottomCoord = 0.0;
592 		}
593 	} else if (this->stagePosition.verticalAlignment == kMiddleAligned) {
594 		finalMarginTopCoord = (size.height / 2.0) - (this->coordHeight / 2.0) - marginTopCoord;
595 		finalMarginBottomCoord = (size.height / 2.0) - (this->coordHeight / 2.0) - marginBottomCoord;
596 		if (finalMarginTopCoord < minMarginTopCoord) {
597 			finalMarginTopCoord = minMarginTopCoord;
598 		}
599 		if (finalMarginBottomCoord < minMarginBottomCoord) {
600 			finalMarginBottomCoord = minMarginBottomCoord;
601 		}
602 		if ((this->coordHeight / 2.0) >= (size.height / 2.0) - minMarginBottomCoord) {
603 			finalMarginBottomCoord = minMarginBottomCoord;
604 			finalMarginTopCoord = size.height - (finalMarginBottomCoord + this->coordHeight);
605 			if ((finalMarginTopCoord + this->coordHeight + finalMarginBottomCoord) > size.height) {
606 				finalMarginTopCoord = minMarginTopCoord;
607 				prevCoordVal = this->coordHeight;
608 				this->coordHeight = size.height - finalMarginTopCoord - finalMarginBottomCoord;
609 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
610 					if (prevCoordVal > 0.0) {
611 						this->coordWidth = this->coordWidth * (this->coordHeight / prevCoordVal);
612 					}
613 				}
614 			}
615 		}
616 		//printf("hwtest coordWidth106: %f\n", this->coordWidth);
617 	} else if (this->stagePosition.verticalAlignment == kBottomAligned) {
618 		if (minMarginBottomCoord > marginBottomCoord) {
619 			finalMarginBottomCoord = minMarginBottomCoord;
620 		} else {
621 			finalMarginBottomCoord = marginBottomCoord;
622 		}
623 		if (minMarginTopCoord > marginTopCoord) {
624 			finalMarginTopCoord = minMarginTopCoord;
625 		} else {
626 			finalMarginTopCoord = marginTopCoord;
627 		}
628 		if (this->coordHeight < (size.height - (finalMarginTopCoord + finalMarginBottomCoord))) {
629 			finalMarginTopCoord = 0.0;
630 		}
631 	}
632 
633 	if (this->stagePosition.horizontalAlignment == kLeftAligned) {
634 		//printf("hwtest finalMarginLeftCoord4a: %f\n", finalMarginLeftCoord);
635 		if (minMarginLeftCoord > marginLeftCoord) {
636 			finalMarginLeftCoord = minMarginLeftCoord;
637 		} else {
638 			finalMarginLeftCoord = marginLeftCoord;
639 		}
640 		if (minMarginRightCoord > marginRightCoord) {
641 			finalMarginRightCoord = minMarginRightCoord;
642 		} else {
643 			finalMarginRightCoord = marginRightCoord;
644 		}
645 		if (this->coordWidth < (size.width - (finalMarginLeftCoord + finalMarginRightCoord))) {
646 			finalMarginRightCoord = 0.0;
647 		}
648 		//printf("hwtest finalMarginLeftCoord4b: %f\n", finalMarginLeftCoord);
649 	} else if (this->stagePosition.horizontalAlignment == kCenterAligned) {
650 /*
651 		if (this->coordWidth >= (size.width - (minMarginLeftCoord + minMarginRightCoord))) {
652 			finalMarginLeftCoord = minMarginLeftCoord;
653 			finalMarginRightCoord = minMarginRightCoord;
654 		} else {
655 			finalMarginLeftCoord = (size.width / 2.0) - (this->coordWidth / 2.0) - marginLeftCoord;
656 			finalMarginRightCoord = (size.width / 2.0) - (this->coordWidth / 2.0) - marginRightCoord;
657 		}
658 */
659 		//printf("hwtest finalMarginLeftCoord4c1: %f , %f , %f\n", finalMarginLeftCoord, this->coordWidth, marginLeftCoord);
660 		finalMarginLeftCoord = (size.width / 2.0) - (this->coordWidth / 2.0) - marginLeftCoord;
661 		//printf("hwtest finalMarginLeftCoord4c2: %f\n", finalMarginLeftCoord);
662 		finalMarginRightCoord = (size.width / 2.0) - (this->coordWidth / 2.0) - marginRightCoord;
663 		if (finalMarginLeftCoord < minMarginLeftCoord) {
664 			finalMarginLeftCoord = minMarginLeftCoord;
665 			//printf("hwtest finalMarginLeftCoord4c3: %f\n", finalMarginLeftCoord);
666 		}
667 		if (finalMarginRightCoord < minMarginRightCoord) {
668 			finalMarginRightCoord = minMarginRightCoord;
669 		}
670 		//printf("hwtest finalMarginLeftCoord4d: %f\n", finalMarginLeftCoord);
671 		if ((this->coordWidth / 2.0) >= (size.width / 2.0) - minMarginRightCoord) {
672 			finalMarginRightCoord = minMarginRightCoord;
673 			finalMarginLeftCoord = size.width - (finalMarginRightCoord - this->coordWidth);
674 			if ((finalMarginLeftCoord + this->coordWidth + finalMarginRightCoord) > size.width) {
675 				finalMarginLeftCoord = minMarginLeftCoord;
676 				prevCoordVal = this->coordWidth;
677 				this->coordWidth = size.width - finalMarginLeftCoord - finalMarginRightCoord;
678 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
679 					if (prevCoordVal > 0.0) {
680 						this->coordWidth = this->coordWidth * (this->coordWidth / prevCoordVal);
681 					}
682 				}
683 			}
684 		}
685 		//printf("hwtest finalMarginLeftCoord4e: %f\n", finalMarginLeftCoord);
686 	} else if (this->stagePosition.horizontalAlignment == kRightAligned) {
687 		//printf("hwtest finalMarginLeftCoord4f: %f\n", finalMarginLeftCoord);
688 		if (minMarginRightCoord > marginRightCoord) {
689 			finalMarginRightCoord = minMarginRightCoord;
690 		} else {
691 			finalMarginRightCoord = marginRightCoord;
692 		}
693 		if (minMarginLeftCoord > marginLeftCoord) {
694 			finalMarginLeftCoord = minMarginLeftCoord;
695 		} else {
696 			finalMarginLeftCoord = marginLeftCoord;
697 		}
698 		if (this->coordWidth < (size.height - (finalMarginLeftCoord + finalMarginRightCoord))) {
699 			finalMarginLeftCoord = 0.0;
700 		}
701 		//printf("hwtest finalMarginLeftCoord4g: %f\n", finalMarginLeftCoord);
702 	}
703 
704 	//printf("hwtest finalMarginLeftCoord5: %f\n", finalMarginLeftCoord);
705 
706 
707 	//printf("hwtest left1: %f\n", left);
708 	//printf("hwtest a: %f, b: %f\n", aCamera.getMaxLeftCoord(), finalMarginLeftCoord);
709 
710 	// position
711 	if (this->stagePosition.horizontalAlignment == kLeftAligned) {
712 		left = aCamera.getMaxLeftCoord() + finalMarginLeftCoord;
713 		right = left + this->coordWidth;
714 	} else if (this->stagePosition.horizontalAlignment == kCenterAligned) {
715 		left = aCamera.getMaxLeftCoord() + finalMarginLeftCoord;
716 		right = aCamera.getMaxRightCoord() - finalMarginRightCoord;
717 	} else if (this->stagePosition.horizontalAlignment == kRightAligned) {
718 		right = aCamera.getMaxRightCoord() - finalMarginRightCoord;
719 		left = right - this->coordWidth;
720 	}
721 
722 	//printf("hwtest left2: %f\n", left);
723 
724 	if (this->stagePosition.verticalAlignment == kTopAligned) {
725 		top = aCamera.getMaxTopCoord() - finalMarginTopCoord;
726 		bottom = top - this->coordHeight;
727 	} else if (this->stagePosition.verticalAlignment == kMiddleAligned) {
728 		//printf("hwtest aCamera.getMaxTopCoord(): %f, aCamera.getMaxBottomCoord(): %f\n", aCamera.getMaxTopCoord(), aCamera.getMaxBottomCoord());
729 		//printf("finalMarginTopCoord: %f\n", finalMarginTopCoord);
730 		top = aCamera.getMaxTopCoord() - finalMarginTopCoord;
731 		bottom = aCamera.getMaxBottomCoord() + finalMarginBottomCoord;
732 	} else if (this->stagePosition.verticalAlignment == kBottomAligned) {
733 		bottom = aCamera.getMaxBottomCoord() + finalMarginBottomCoord;
734 		top = bottom + this->coordHeight;
735 	}
736 
737 	//printf("hwtest coordWidth2a: %f, coordHeight2a: %f\n", this->coordWidth, this->coordHeight);
738 	//printf("hwtest top1: %f, bottom1: %f, left1: %f, right1: %f\n", top, bottom, left, right);
739 
740 /*
741 	if (this->stagePosition.verticalAlignment == kTop) {
742 		bottom = aCamera.getMaxTopCoord() - this->coordHeight - finalMarginTopCoord;
743 	} else if (this->stagePosition.verticalAlignment == kMiddle) {
744 		bottom = aCamera.getMaxBottomCoord() + finalMarginBottomCoord + (((size.height - finalMarginBottomCoord) / 2.0) - (this->coordHeight / 2.0));
745 		if ((minMarginBottomCoord > marginBottomCoord) && ((aCamera.getMaxBottomCoord() - bottom) < minMarginBottomCoord)) {
746 			//bottom = aCamera.getMaxBottomCoord() + minMarginBottomCoord;
747 		}
748 	} else if (this->stagePosition.verticalAlignment == kBottom) {
749 		bottom = aCamera.getMaxBottomCoord() + finalMarginBottomCoord;
750 	}
751 	top = bottom + this->coordHeight;
752 */
753 /*
754 	if (this->stagePosition.horizontalAlignment == kLeft) {
755 		left = aCamera.getMaxLeftCoord() + finalMarginLeftCoord;
756 	} else if (this->stagePosition.horizontalAlignment == kCenter) {
757 		left = (aCamera.getMaxLeftCoord() + finalMarginLeftCoord + (size.width / 2.0)) - (this->coordWidth / 2.0);
758 	} else if (this->stagePosition.horizontalAlignment == kRight) {
759 		left = aCamera.getMaxRightCoord() - this->coordWidth - finalMarginRightCoord;
760 	}
761 	right = left + this->coordWidth;
762 */
763 	// adjust bounds to current bounding rect
764 	if ((this->scalingBehaviour & kScalingAllowed) == kScalingAllowed) {
765 
766 		// positioning
767 /*
768 		if (this->stagePosition.verticalAlignment == kTop) {
769 			bottom = aCamera.getMaxTopCoord() - this->coordHeight - finalMarginTopCoord;
770 		} else if (this->stagePosition.verticalAlignment == kMiddle) {
771 			bottom = aCamera.getMaxBottomCoord() + ((size.height / 2.0) - (this->coordHeight / 2.0));
772 		} else if (this->stagePosition.verticalAlignment == kBottom) {
773 			bottom = aCamera.getMaxBottomCoord() + finalMarginBottomCoord;
774 		}
775 		top = bottom + this->coordHeight;
776 */
777 /*
778 		if (this->stagePosition.horizontalAlignment == kLeft) {
779 			left = aCamera.getMaxLeftCoord() + finalMarginLeftCoord;
780 		} else if (this->stagePosition.horizontalAlignment == kCenter) {
781 			left = aCamera.getMaxLeftCoord() + ((size.width / 2.0) - (this->coordWidth / 2.0));
782 		} else if (this->stagePosition.horizontalAlignment == kRight) {
783 			left = aCamera.getMaxRightCoord() - this->coordWidth - finalMarginRightCoord;
784 		}
785 		right = left + this->coordWidth;
786 */
787 		// calc distances
788 		double distanceBottom = 0.0;
789 		if (bottom > 0.0) {
790 			distanceBottom = (size.height / 2.0) + bottom;
791 		} else {
792 			distanceBottom = (aCamera.getMaxBottomCoord() - bottom) * -1.0;
793 		}
794 		double distanceTop = 0.0;
795 		if (top > 0.0) {
796 			distanceTop = aCamera.getMaxTopCoord() - top;
797 		} else {
798 			distanceTop = (size.height / 2.0) + (top * -1.0);
799 		}
800 		double distanceLeft = 0.0;
801 		if (left > 0.0) {
802 			distanceLeft = (size.width / 2.0) + left;
803 		} else {
804 			distanceLeft = (aCamera.getMaxLeftCoord() - left) * -1.0;
805 		}
806 		double distanceRight = 0.0;
807 		if (right > 0.0) {
808 			distanceRight = aCamera.getMaxRightCoord() - right;
809 		} else {
810 			distanceRight = (size.width / 2.0) + (right * -1.0);
811 		}
812 		// rescale because minMargin is exceeded?
813 		//if ((distanceBottom < minMarginBottomCoord) || (distanceTop < minMarginTopCoord) || (distanceLeft < minMarginLeftCoord) || (distanceRight < minMarginRightCoord)) {
814 		if (1 == 2) {
815 			prevCoordVal = bottom;
816 			if (this->stagePosition.verticalAlignment == kTopAligned) {
817 				bottom = aCamera.getMaxTopCoord() - this->coordHeight - marginTopCoord;
818 			} else if (this->stagePosition.verticalAlignment == kMiddleAligned) {
819 				bottom = aCamera.getMaxBottomCoord() + marginBottomCoord + (((size.height - marginBottomCoord) / 2.0) - (this->coordHeight / 2.0));
820 				if ((minMarginBottomCoord > marginBottomCoord) && ((aCamera.getMaxBottomCoord() - bottom) < minMarginBottomCoord)) {
821 					bottom = aCamera.getMaxBottomCoord() + minMarginBottomCoord;
822 				}
823 			} else if (this->stagePosition.verticalAlignment == kBottomAligned) {
824 				bottom = aCamera.getMaxBottomCoord() + marginBottomCoord;
825 			}
826 			top -= (prevCoordVal - bottom);
827 
828 			prevCoordVal = left;
829 			if (this->stagePosition.horizontalAlignment == kLeftAligned) {
830 				left = aCamera.getMaxLeftCoord() + minMarginLeftCoord;
831 			} else if (this->stagePosition.horizontalAlignment == kCenterAligned) {
832 				left = aCamera.getMaxLeftCoord() + marginLeftCoord + (((size.width - marginLeftCoord) / 2.0) - (this->coordWidth / 2.0));
833 				if ((minMarginLeftCoord > marginLeftCoord) && ((aCamera.getMaxLeftCoord() - left) < minMarginLeftCoord)) {
834 					left = aCamera.getMaxLeftCoord() + minMarginLeftCoord;
835 				}
836 			} else if (this->stagePosition.horizontalAlignment == kRightAligned) {
837 				left = aCamera.getMaxRightCoord() - this->coordWidth - marginRightCoord;
838 			}
839 			right -= (prevCoordVal - left);
840 
841 			// scale?
842 			if (top > (aCamera.getMaxTopCoord() - minMarginTopCoord)) {
843 				prevCoordVal = this->coordHeight;
844 				this->coordHeight = size.height - minMarginTopCoord - minMarginBottomCoord;
845 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
846 					if (prevCoordVal > 0.0) {
847 						this->coordWidth = this->coordWidth * (this->coordHeight / prevCoordVal);
848 					}
849 					if (this->stagePosition.horizontalAlignment == kLeftAligned) {
850 						left = aCamera.getMaxLeftCoord() + marginLeftCoord;
851 					} else if (this->stagePosition.horizontalAlignment == kCenterAligned) {
852 						left = (aCamera.getMaxLeftCoord() + marginLeftCoord + (size.width / 2.0)) - (this->coordWidth / 2.0);
853 						//left = aCamera.getMaxLeftCoord() + marginLeftCoord + (this->coordWidth / 2.0);
854 					} else if (this->stagePosition.horizontalAlignment == kRightAligned) {
855 						left = aCamera.getMaxRightCoord() - this->coordWidth - marginRightCoord;
856 					}
857 					right = left + this->coordWidth;
858 				}
859 				top = bottom + this->coordHeight;
860 			}
861 			if (right < (aCamera.getMaxRightCoord() - minMarginRightCoord)) {
862 				prevCoordVal = this->coordWidth;
863 				//this->coordWidth = size.width - minMarginLeftCoord - minMarginRightCoord;
864 				/*
865 				if ((this->scalingBehaviour & kPreserveAspectRatio) == kPreserveAspectRatio) {
866 					this->coordHeight = this->coordHeight * (this->coordWidth / prevCoordVal);
867 					if (this->stagePosition.verticalAlignment == kTop) {
868 						top = aCamera.getMaxTopCoord() - marginTopCoord;
869 					} else if (this->stagePosition.verticalAlignment == kMiddle) {
870 						top = (aCamera.getMaxTopCoord() - marginTopCoord - (size.height / 2.0)) + (this->coordHeight / 2.0);
871 					} else if (this->stagePosition.verticalAlignment == kBottom) {
872 						top = aCamera.getMaxBottomCoord() + this->coordHeight + marginBottomCoord;
873 					}
874 					bottom = top - this->coordHeight;
875 				}
876 				*/
877 				//left = aCamera.getMaxLeftCoord() + minMarginLeftCoord;
878 				//right = left + this->coordWidth;
879 			}
880 		}
881 	}
882 
883 	//printf("hwtest coordWidth2b: %f, coordHeight2b: %f\n", this->coordWidth, this->coordHeight);
884 	//printf("hwtest top2: %f, bottom2: %f, left2: %f, right2: %f\n", top, bottom, left, right);
885 
886 	this->topCoord = top;
887 	this->bottomCoord = bottom;
888 	this->leftCoord = left;
889 	this->rightCoord = right;
890 
891 	if (this->stagePosition.depthAlignment == kFrontAligned) {
892 		this->frontPosition = aCamera.getMaxNearPos();
893 		this->frontPosition += 0.01;
894 		this->frontPosition *= -1.0;
895 		this->backPosition = this->frontPosition - this->unscaledCoordDepth;
896 	} else if (this->stagePosition.depthAlignment == kDepthCenterAligned) {
897 		/*
898 		double zCoordAmount = aCamera.getMaxFarPos() - aCamera.getMaxNearPos();
899 		double zCenter = aCamera.getMaxNearPos() + (zCoordAmount / 2.0);
900 		this->frontPosition = zCenter - (this->coordDepth / 2.0);
901 		this->backPosition = zCenter + (this->coordDepth / 2.0);
902 		*/
903 
904 		this->frontPosition = 0.0 + (this->unscaledCoordDepth / 2.0);
905 		this->backPosition = 0.0 - (this->unscaledCoordDepth / 2.0);
906 		//printf("hwtest: kDepthCenterAligned1 font: %f, back: %f\n", this->frontPosition, this->backPosition);
907 	} else if (this->stagePosition.depthAlignment == kBackAligned) {
908 		this->backPosition = aCamera.getMaxFarPos();
909 		this->frontPosition = this->backPosition - this->unscaledCoordDepth;
910 	}
911 
912 	this->coordWidth = this->rightCoord - this->leftCoord;
913 	this->unscaledCoordWidth = this->coordWidth;
914 	this->coordHeight = this->topCoord - this->bottomCoord;
915 	this->unscaledCoordHeight = this->coordHeight;
916 
917 	this->leftCoord += this->stagePosition.horizontalCoordOffset;
918 	this->rightCoord += this->stagePosition.horizontalCoordOffset;
919 	this->bottomCoord += this->stagePosition.verticalCoordOffset;
920 	this->topCoord += this->stagePosition.verticalCoordOffset;
921 
922 	//printf("hwtest coordWidth2z: %f, coordHeight2z: %f\n", this->coordWidth, this->coordHeight);
923 
924 	//printf("hwtest top3: %f, bottom3: %f, left3: %f, right3: %f\n", this->topCoord, this->bottomCoord, this->leftCoord, this->rightCoord);
925 
926 	this->applyScaleFactor();
927 
928 	//printf("hwtest top4: %f, bottom4: %f, left4: %f, right4: %f\n", this->topCoord, this->bottomCoord, this->leftCoord, this->rightCoord);
929 
930 	this->hasLayout = true;
931 
932 	this->updateVertices();
933 
934 	//printf("hwtest top5: %f, bottom5: %f, left5: %f, right5: %f\n", this->topCoord, this->bottomCoord, this->leftCoord, this->rightCoord);
935 
936 	//printf("hwtest coordWidth3: %f, coordHeight3: %f\n", this->coordWidth, this->coordHeight);
937 
938 }
939 
940 
applyScaleFactor()941 void VisualStageBox::applyScaleFactor() {
942 
943 	double top = this->topCoord;
944 	double left = this->leftCoord;
945 	double bottom = this->bottomCoord;
946 	double right = this->rightCoord;
947 	double front = this->frontPosition;
948 	double back = this->backPosition;
949 
950 	if (this->stagePosition.horizontalAlignment == kLeftAligned) {
951 		right = left + (this->unscaledCoordWidth * this->scaleFactor);
952 	} else if (this->stagePosition.horizontalAlignment == kCenterAligned) {
953 		double widthDelta = this->unscaledCoordWidth - (this->unscaledCoordWidth * this->scaleFactor);
954 		widthDelta /= 2.0;
955 		left = this->leftCoord + widthDelta;
956 		right = this->rightCoord - widthDelta;
957 		//printf("hwtest left: %f, right: %f\n", left, right);
958 	} else if (this->stagePosition.horizontalAlignment == kRightAligned) {
959 		left = right - (this->unscaledCoordWidth * this->scaleFactor);
960 	}
961 
962 	if (this->stagePosition.verticalAlignment == kTopAligned) {
963 		bottom = top - (this->unscaledCoordHeight * this->scaleFactor);
964 	} else if (this->stagePosition.verticalAlignment == kMiddleAligned) {
965 		double heightDelta = this->unscaledCoordHeight - (this->unscaledCoordHeight * this->scaleFactor);
966 		heightDelta /= 2.0;
967 		bottom = this->bottomCoord + heightDelta;
968 		top = this->topCoord - heightDelta;
969 	} else if (this->stagePosition.verticalAlignment == kBottomAligned) {
970 		top = bottom + (this->unscaledCoordHeight * this->scaleFactor);
971 	}
972 
973 	if (this->stagePosition.depthAlignment == kFrontAligned) {
974 		back = front - (this->unscaledCoordDepth * this->scaleFactor);
975 	} else if (this->stagePosition.depthAlignment == kDepthCenterAligned) {
976 		//printf("hwtest: kDepthCenterAligned1: front: %f, back: %f\n", front, back);
977 		double value = this->unscaledCoordDepth / 2.0 * this->scaleFactor;
978 		front = 0.0 + (value);
979 		back = 0.0 - (value);
980 		//printf("hwtest: kDepthCenterAligned2: front: %f, back: %f\n", front, back);
981 	} else if (this->stagePosition.depthAlignment == kBackAligned) {
982 		front = back + (this->unscaledCoordDepth * this->scaleFactor);
983 	}
984 
985 	this->topCoord = top;
986 	this->leftCoord = left;
987 	this->bottomCoord = bottom;
988 	this->rightCoord = right;
989 	this->frontPosition = front;
990 	this->backPosition = back;
991 
992 	this->coordWidth = this->rightCoord - this->leftCoord;
993 	this->coordHeight = this->topCoord - this->bottomCoord;
994 	this->coordDepth = this->backPosition - this->frontPosition;
995 
996 }
997 
998 
getScalingBehaviour() const999 ScalingBehaviour VisualStageBox::getScalingBehaviour() const {
1000 	return this->scalingBehaviour;
1001 }
1002 
1003 
getScaleFactor() const1004 double VisualStageBox::getScaleFactor() const {
1005 	return this->scaleFactor;
1006 }
1007 
1008 
getCoordWidth()1009 double VisualStageBox::getCoordWidth() {
1010 	if (this->hasLayout == false) {
1011 		this->calcCoords(this->assetRef->getCamera());
1012 	}
1013 	return this->coordWidth;
1014 }
1015 
1016 
getUnscaledCoordWidth()1017 double VisualStageBox::getUnscaledCoordWidth() {
1018 	if (this->hasLayout == false) {
1019 		this->calcCoords(this->assetRef->getCamera());
1020 	}
1021 	return this->unscaledCoordWidth;
1022 }
1023 
1024 
getCoordHeight()1025 double VisualStageBox::getCoordHeight() {
1026 	if (this->hasLayout == false) {
1027 		this->calcCoords(this->assetRef->getCamera());
1028 	}
1029 	return this->coordHeight;
1030 }
1031 
1032 
getUnscaledCoordHeight()1033 double VisualStageBox::getUnscaledCoordHeight() {
1034 	if (this->hasLayout == false) {
1035 		this->calcCoords(this->assetRef->getCamera());
1036 	}
1037 	return this->unscaledCoordHeight;
1038 }
1039 
1040 
getCoordDepth()1041 double VisualStageBox::getCoordDepth() {
1042 	if (this->hasLayout == false) {
1043 		this->calcCoords(this->assetRef->getCamera());
1044 	}
1045 	return this->coordDepth;
1046 }
1047 
1048 
getUnscaledCoordDepth()1049 double VisualStageBox::getUnscaledCoordDepth() {
1050 	if (this->hasLayout == false) {
1051 		this->calcCoords(this->assetRef->getCamera());
1052 	}
1053 	return this->unscaledCoordDepth;
1054 }
1055 
1056 
getTopCoord(const VisualItemIdentifier * const vertexChainName)1057 double VisualStageBox::getTopCoord(const VisualItemIdentifier* const vertexChainName) {
1058 	double top = 0.0;
1059 	if (this->hasLayout == false) {
1060 		this->calcCoords(this->assetRef->getCamera());
1061 	}
1062 	if (vertexChainName == NULL) {
1063 		top = this->topCoord;
1064 	} else {
1065 		VertexChain* vertexChain = this->getVertexChain(*vertexChainName);
1066 		if (vertexChain != NULL) {
1067 			for (VertexChainIterator chainIt = vertexChain->begin(); chainIt != vertexChain->end(); chainIt++) {
1068 				if ((*chainIt)->vertexPosition.coord.y > top) {
1069 					top = (*chainIt)->vertexPosition.coord.y;
1070 				}
1071 			}
1072 		}
1073 	}
1074 	return top;
1075 }
1076 
1077 
getLeftCoord(const VisualItemIdentifier * const vertexChainName)1078 double VisualStageBox::getLeftCoord(const VisualItemIdentifier* const vertexChainName) {
1079 	double left = 0.0;
1080 	if (this->hasLayout == false) {
1081 		this->calcCoords(this->assetRef->getCamera());
1082 	}
1083 	if (vertexChainName == NULL) {
1084 		left = this->leftCoord;
1085 	} else {
1086 		VertexChain* vertexChain = this->getVertexChain(*vertexChainName);
1087 		if (vertexChain != NULL) {
1088 			for (VertexChainIterator chainIt = vertexChain->begin(); chainIt != vertexChain->end(); chainIt++) {
1089 				if ((*chainIt)->vertexPosition.coord.x < left) {
1090 					left = (*chainIt)->vertexPosition.coord.x;
1091 				}
1092 			}
1093 		}
1094 	}
1095 	return left;
1096 }
1097 
1098 
getBottomCoord(const VisualItemIdentifier * const vertexChainName)1099 double VisualStageBox::getBottomCoord(const VisualItemIdentifier* const vertexChainName) {
1100 	double bottom = 0.0;
1101 	if (this->hasLayout == false) {
1102 		this->calcCoords(this->assetRef->getCamera());
1103 	}
1104 	if (vertexChainName == NULL) {
1105 		bottom = this->bottomCoord;
1106 	} else {
1107 		VertexChain* vertexChain = this->getVertexChain(*vertexChainName);
1108 		if (vertexChain != NULL) {
1109 			for (VertexChainIterator chainIt = vertexChain->begin(); chainIt != vertexChain->end(); chainIt++) {
1110 				if ((*chainIt)->vertexPosition.coord.y < bottom) {
1111 					bottom = (*chainIt)->vertexPosition.coord.x;
1112 				}
1113 			}
1114 		}
1115 	}
1116 	return bottom;
1117 }
1118 
1119 
getRightCoord(const VisualItemIdentifier * const vertexChainName)1120 double VisualStageBox::getRightCoord(const VisualItemIdentifier* const vertexChainName) {
1121 	double right = 0.0;
1122 	if (this->hasLayout == false) {
1123 		this->calcCoords(this->assetRef->getCamera());
1124 	}
1125 	if (vertexChainName == NULL) {
1126 		right = this->rightCoord;
1127 	} else {
1128 		VertexChain* vertexChain = this->getVertexChain(*vertexChainName);
1129 		if (vertexChain != NULL) {
1130 			for (VertexChainIterator chainIt = vertexChain->begin(); chainIt != vertexChain->end(); chainIt++) {
1131 				if ((*chainIt)->vertexPosition.coord.x > right) {
1132 					right = (*chainIt)->vertexPosition.coord.x;
1133 				}
1134 			}
1135 		}
1136 	}
1137 	return right;
1138 }
1139 
1140 
getContentPixelWidth() const1141 uint32 VisualStageBox::getContentPixelWidth() const {
1142 	return this->contentPixelWidth;
1143 }
1144 
1145 
getContentPixelHeight() const1146 uint32 VisualStageBox::getContentPixelHeight() const {
1147 	return this->contentPixelHeight;
1148 }
1149 
1150 
getVisualStagePosition() const1151 VisualStagePosition VisualStageBox::getVisualStagePosition() const {
1152 	return this->stagePosition;
1153 }
1154 
1155 
initializeVertexChain(const VisualItemIdentifier & vertexChainName)1156 void VisualStageBox::initializeVertexChain(const VisualItemIdentifier& vertexChainName) {
1157 	this->vertexChainMap[vertexChainName] = new VertexChain;
1158 }
1159 
1160 
addVertexToChain(const VisualItemIdentifier & vertexChainName,VisualVertex * aVertex)1161 void VisualStageBox::addVertexToChain(const VisualItemIdentifier& vertexChainName, VisualVertex* aVertex) {
1162 	this->hasLayout = false;
1163 	this->vertexChainMap[vertexChainName]->push_back(aVertex);
1164 }
1165 
1166 
getVertexChain(const VisualItemIdentifier & vertexChainName)1167 VertexChain* VisualStageBox::getVertexChain(const VisualItemIdentifier& vertexChainName) {
1168 	if (this->hasLayout == false) {
1169 		this->calcCoords(this->assetRef->getCamera());
1170 	}
1171 	VertexChain* vertexChainRef = NULL;
1172 	ConstVertexChainMapIterator mapIt = this->vertexChainMap.find(vertexChainName);
1173 	if (mapIt != this->vertexChainMap.end()) {
1174 		vertexChainRef = mapIt->second;
1175 	} else {
1176 		char errLog[64];
1177 		sprintf(errLog, "unable to find vertex chain to return in file: %s (line: %d) [%s])", __FILE__, __LINE__, __FUNCTION__);
1178 		writeLog(errLog);
1179 	}
1180 	return vertexChainRef;
1181 }
1182 
1183 
getVertexChain(size_t vertexIdx)1184 VertexChain* VisualStageBox::getVertexChain(size_t vertexIdx) {
1185 	if (this->hasLayout == false) {
1186 		this->calcCoords(this->assetRef->getCamera());
1187 	}
1188 	if (vertexIdx > this->vertexChainMap.size() - 1) return NULL;
1189 	size_t count = 0;
1190 	for (VertexChainMapIterator mapIt = this->vertexChainMap.begin(); mapIt != this->vertexChainMap.end(); mapIt++) {
1191 		if (count == vertexIdx) {
1192 			return mapIt->second;
1193 		}
1194 		count++;
1195 	}
1196 	return NULL;
1197 }
1198 
1199 
getVertexChainIdentifier(size_t vertexIdx)1200 const VisualItemIdentifier& VisualStageBox::getVertexChainIdentifier(size_t vertexIdx) {
1201 	if (vertexIdx > this->vertexChainMap.size() - 1) return this->notFoundIdentifier;
1202 	size_t count = 0;
1203 	for (VertexChainMapIterator mapIt = this->vertexChainMap.begin(); mapIt != this->vertexChainMap.end(); mapIt++) {
1204 		if (count == vertexIdx) {
1205 			return mapIt->first;
1206 		}
1207 		count++;
1208 	}
1209 	return this->notFoundIdentifier;
1210 }
1211 
1212 
getNumberOfVertexChains(void) const1213 size_t VisualStageBox::getNumberOfVertexChains(void) const {
1214 	return this->vertexChainMap.size();
1215 }
1216 
1217 
hasVertexChain(const VisualItemIdentifier & vertexChainName) const1218 bool VisualStageBox::hasVertexChain(const VisualItemIdentifier& vertexChainName) const {
1219 	bool result = false;
1220 	ConstVertexChainMapIterator mapIt = this->vertexChainMap.find(vertexChainName);
1221 	if (mapIt != this->vertexChainMap.end()) {
1222 		result = true;
1223 	}
1224 	return result;
1225 }
1226 
1227 
removeAllVertexChains()1228 void VisualStageBox::removeAllVertexChains() {
1229 	for (VertexChainMapIterator mapIt = this->vertexChainMap.begin(); mapIt != this->vertexChainMap.end(); mapIt++) {
1230 		for (VertexChainIterator chainIt = mapIt->second->begin(); chainIt != mapIt->second->end(); chainIt++) {
1231 			delete *chainIt;
1232 			*chainIt = NULL;
1233 		}
1234 		mapIt->second->clear();
1235 	}
1236 	this->vertexChainMap.clear();
1237 }
1238 
1239 
removeVertexChain(const VisualItemIdentifier & vertexChainName)1240 void VisualStageBox::removeVertexChain(const VisualItemIdentifier& vertexChainName) {
1241 	VertexChainMapIterator mapIt = this->vertexChainMap.find(vertexChainName);
1242 	if (mapIt != this->vertexChainMap.end()) {
1243 		for (VertexChainIterator chainIt = mapIt->second->begin(); chainIt != mapIt->second->end(); chainIt++) {
1244 			delete *chainIt;
1245 			*chainIt = NULL;
1246 		}
1247 		mapIt->second->clear();
1248 		this->vertexChainMap.erase(mapIt);
1249 	}
1250 }
1251 
1252 
getMinSRelTexCoord()1253 double VisualStageBox::getMinSRelTexCoord() {
1254 	double minSRelCoord = 1.0;
1255 	size_t numberOfVertexChains = this->getNumberOfVertexChains();
1256 	for (size_t i = 0; i < numberOfVertexChains; i++) {
1257 		VertexChain* chain = this->getVertexChain(i);
1258 		for (VertexChainConstIterator chain_it = chain->begin(); chain_it != chain->end(); chain_it++) {
1259 			if ((*chain_it)->texCoordPosition.relCoord.s < minSRelCoord) {
1260 				minSRelCoord = (*chain_it)->texCoordPosition.relCoord.s;
1261 			}
1262 		}
1263 	}
1264 	return minSRelCoord;
1265 }
1266 
1267 
getMinTRelTexCoord()1268 double VisualStageBox::getMinTRelTexCoord() {
1269 	double minTRelCoord = 1.0;
1270 	size_t numberOfVertexChains = this->getNumberOfVertexChains();
1271 	for (size_t i = 0; i < numberOfVertexChains; i++) {
1272 		VertexChain* chain = this->getVertexChain(i);
1273 		for (VertexChainConstIterator chain_it = chain->begin(); chain_it != chain->end(); chain_it++) {
1274 			if ((*chain_it)->texCoordPosition.relCoord.t < minTRelCoord) {
1275 				minTRelCoord = (*chain_it)->texCoordPosition.relCoord.t;
1276 			}
1277 		}
1278 	}
1279 	return minTRelCoord;
1280 }
1281 
1282 
getMaxSRelTexCoord()1283 double VisualStageBox::getMaxSRelTexCoord() {
1284 	double maxSRelCoord = 0.0;
1285 	size_t numberOfVertexChains = this->getNumberOfVertexChains();
1286 	for (size_t i = 0; i < numberOfVertexChains; i++) {
1287 		VertexChain* chain = this->getVertexChain(i);
1288 		for (VertexChainConstIterator chain_it = chain->begin(); chain_it != chain->end(); chain_it++) {
1289 			if ((*chain_it)->texCoordPosition.relCoord.s > maxSRelCoord) {
1290 				maxSRelCoord = (*chain_it)->texCoordPosition.relCoord.s;
1291 			}
1292 		}
1293 	}
1294 	return maxSRelCoord;
1295 }
1296 
1297 
getMaxTRelTexCoord()1298 double VisualStageBox::getMaxTRelTexCoord() {
1299 	double maxTRelCoord = 0.0;
1300 	size_t numberOfVertexChains = this->getNumberOfVertexChains();
1301 	for (size_t i = 0; i < numberOfVertexChains; i++) {
1302 		VertexChain* chain = this->getVertexChain(i);
1303 		for (VertexChainConstIterator chain_it = chain->begin(); chain_it != chain->end(); chain_it++) {
1304 			if ((*chain_it)->texCoordPosition.relCoord.t > maxTRelCoord) {
1305 				maxTRelCoord = (*chain_it)->texCoordPosition.relCoord.t;
1306 			}
1307 		}
1308 	}
1309 	return maxTRelCoord;
1310 }
1311 
1312 
setOpacityValue(double anOpacityValue)1313 void VisualStageBox::setOpacityValue(double anOpacityValue) {
1314 	for (ConstVertexChainMapIterator mapIt = this->vertexChainMap.begin(); mapIt != this->vertexChainMap.end(); ++mapIt) {
1315 		for (ConstVertexChainIterator chainIt = mapIt->second->begin(); chainIt != mapIt->second->end(); chainIt++) {
1316 			(*chainIt)->vertexColor.r = (*chainIt)->vertexColor.red * anOpacityValue;
1317 			(*chainIt)->vertexColor.g = (*chainIt)->vertexColor.green * anOpacityValue;
1318 			(*chainIt)->vertexColor.b = (*chainIt)->vertexColor.blue * anOpacityValue;
1319 			(*chainIt)->vertexColor.a = (*chainIt)->vertexColor.alpha * anOpacityValue;
1320 		}
1321 	}
1322 }
1323 
1324 
createVertex(double xPos,double yPos,double zPos,double aTexCoordSPos,double aTexCoordTPos,VertexColor anRGBAColor)1325 VisualVertex* VisualStageBox::createVertex(double xPos, double yPos, double zPos, double aTexCoordSPos, double aTexCoordTPos, VertexColor anRGBAColor) {
1326 
1327 	double xCoordPos = this->getLeftCoord() + (this->getCoordWidth() * xPos);
1328 	double yCoordPos = this->getBottomCoord() + (this->getCoordHeight() * yPos);
1329 
1330 	double zCoordDistance = this->getBackPosition() - this->getFrontPosition();
1331 	double zCoordPos = zCoordDistance * zPos;
1332 	//printf("back: %f, front: %f\n", this->getBackPosition(), this->getFrontPosition()); // hwtest
1333 	zCoordPos += this->getFrontPosition();
1334 
1335 	TexCoord relTexCoord;
1336 	relTexCoord.s = aTexCoordSPos;
1337 	relTexCoord.t = aTexCoordTPos;
1338 
1339 	const VisualImage* const anImage = this->assetRef->getImage();
1340 	if (anImage != NULL) {
1341 		aTexCoordSPos = anImage->getLogicalWidth() * aTexCoordSPos;
1342 		aTexCoordTPos = anImage->getLogicalHeight() * aTexCoordTPos;
1343 	}
1344 
1345 	Coord coord;
1346 	Coord relCoord;
1347 	coord.x = xCoordPos;
1348 	coord.y = yCoordPos;
1349 	coord.z = zCoordPos;
1350 	relCoord.x = xPos;
1351 	relCoord.y = yPos;
1352 	relCoord.z = zPos;
1353 
1354 	TexCoord texCoord;
1355 	texCoord.s = aTexCoordSPos;
1356 	texCoord.t = aTexCoordTPos;
1357 
1358 	VisualVertex* aVertex = new VisualVertex(coord, relCoord, texCoord, relTexCoord, anRGBAColor);
1359 	return aVertex;
1360 }
1361 
1362 
createVertex(double xPos,double yPos,double zPos,VertexColor anRGBAColor)1363 VisualVertex* VisualStageBox::createVertex(double xPos, double yPos, double zPos, VertexColor anRGBAColor) {
1364 
1365 	double xCoordPos = this->getLeftCoord() + (this->getCoordWidth() * xPos);
1366 	double yCoordPos = this->getBottomCoord() + (this->getCoordHeight() * yPos);
1367 
1368 	double zCoordDistance = this->getBackPosition() - this->getFrontPosition();
1369 	double zCoordPos = zCoordDistance * zPos;
1370 	zCoordPos += this->getFrontPosition();
1371 
1372 	Coord coord;
1373 	Coord relCoord;
1374 	coord.x = xCoordPos;
1375 	coord.y = yCoordPos;
1376 	coord.z = zCoordPos;
1377 	relCoord.x = xPos;
1378 	relCoord.y = yPos;
1379 	relCoord.z = zPos;
1380 
1381 	VisualVertex* aVertex = new VisualVertex(coord, relCoord, anRGBAColor);
1382 	return aVertex;
1383 }
1384 
1385 
setDebugMode(bool requestedDebugMode)1386 void VisualStageBox::setDebugMode(bool requestedDebugMode) {
1387 	this->debugMode = requestedDebugMode;
1388 }
1389 
1390 
getDebugMode()1391 bool VisualStageBox::getDebugMode() {
1392 	return this->debugMode;
1393 }
1394 
1395 
updateVertices()1396 void VisualStageBox::updateVertices() {
1397 
1398 	double xOffset = this->getUnscaledCoordWidth() - this->getCoordWidth();
1399 	xOffset *= 0.5;
1400 	double yOffset = this->getUnscaledCoordHeight() - this->getCoordHeight();
1401 	yOffset *= 0.5;
1402 
1403 	double zCoordDistance = this->getBackPosition() - this->getFrontPosition();
1404 	for (VertexChainMapIterator mapIt = this->vertexChainMap.begin(); mapIt != this->vertexChainMap.end(); mapIt++) {
1405 		for (VertexChainIterator chainIt = mapIt->second->begin(); chainIt != mapIt->second->end(); chainIt++) {
1406 			if ((*chainIt)->vertexPosition.relCoord.x != -1.0) {
1407 				(*chainIt)->vertexPosition.coord.x = this->getLeftCoord() + (this->getCoordWidth() * (*chainIt)->vertexPosition.relCoord.x);
1408 				if ((*chainIt)->vertexPosition.relCoord.x > 0.5) {
1409 					//(*chainIt)->vertexPosition.coord.x -= xOffset;
1410 				} else {
1411 					//printf("hwtest x1: %f\n", (*chainIt)->vertexPosition.coord.x);
1412 					//(*chainIt)->vertexPosition.coord.x += xOffset;
1413 					//printf("hwtest x2: %f\n", (*chainIt)->vertexPosition.coord.x);
1414 				}
1415 			} else {
1416 				//(*chainIt)->vertexPosition.coord.x = this->getRightCoord();
1417 				//printf("coord.x == %f\n", (*chainIt)->vertexPosition.coord.x); // hwtest
1418 			}
1419 			if ((*chainIt)->vertexPosition.relCoord.y != -1.0) {
1420 				(*chainIt)->vertexPosition.coord.y = this->getBottomCoord() + (this->getCoordHeight() * (*chainIt)->vertexPosition.relCoord.y);
1421 				if ((*chainIt)->vertexPosition.relCoord.y > 0.5) {
1422 					//(*chainIt)->vertexPosition.coord.y -= yOffset;
1423 				} else {
1424 					//(*chainIt)->vertexPosition.coord.y += yOffset;
1425 				}
1426 			} else {
1427 				//(*chainIt)->vertexPosition.coord.y = this->getTopCoord();
1428 				//printf("coord.y == %f\n", (*chainIt)->vertexPosition.coord.y); // hwtest
1429 			}
1430 			if ((*chainIt)->vertexPosition.relCoord.z != -1.0) {
1431 				(*chainIt)->vertexPosition.coord.z = zCoordDistance * (*chainIt)->vertexPosition.relCoord.z;
1432 				(*chainIt)->vertexPosition.coord.z += this->getFrontPosition();
1433 			} else {
1434 				//(*chainIt)->vertexPosition.coord.z = this->getFrontPosition();
1435 			}
1436 			if ((*chainIt)->texCoordPosition.relCoord.s != -1.0) {
1437 				const VisualImage* const anImage = this->assetRef->getImage();
1438 				if (anImage != NULL) {
1439 					//double before = (*chainIt)->texCoordPosition.coord.s;
1440 					(*chainIt)->texCoordPosition.coord.s = anImage->getLogicalWidth() * (*chainIt)->texCoordPosition.relCoord.s;
1441 					//printf("before: %f, danach: %f\n", before, (*chainIt)->texCoordPosition.coord.s);
1442 				}
1443 			}
1444 			if ((*chainIt)->texCoordPosition.relCoord.t != -1.0) {
1445 				const VisualImage* const anImage = this->assetRef->getImage();
1446 				if (anImage != NULL) {
1447 					(*chainIt)->texCoordPosition.coord.t = anImage->getLogicalHeight() * (*chainIt)->texCoordPosition.relCoord.t;
1448 				}
1449 			}
1450 		}
1451 	}
1452 }
1453 
1454 
tweenVisualStagePosition(const VisualStagePosition & startPosition,const VisualStagePosition & stopPosition,double currPosition,const VisualStageBox & currentAssetBox)1455 VisualStagePosition VisualStageBox::tweenVisualStagePosition(const VisualStagePosition& startPosition, const VisualStagePosition& stopPosition, double currPosition, const VisualStageBox& currentAssetBox) {
1456 	VisualStagePosition tweenedPosition(startPosition);
1457 	VisualStageBox startBox(currentAssetBox);
1458 	startBox.setVisualStagePosition(startPosition);
1459 	VisualStageBox stopBox(currentAssetBox);
1460 	stopBox.setVisualStagePosition(stopPosition);
1461 	double distanceX = stopBox.getRightCoord() - startBox.getRightCoord();
1462 	double distanceY = stopBox.getBottomCoord() - startBox.getBottomCoord();
1463 	tweenedPosition.horizontalCoordOffset += (distanceX * currPosition);
1464 	tweenedPosition.verticalCoordOffset += (distanceY * currPosition);
1465 	return tweenedPosition;
1466 }
1467