Repository navigation
Expand file tree
/
Copy pathlayout_manager.cpp
More file actions
754 lines (669 loc) · 27.6 KB
/
Copy pathlayout_manager.cpp
File metadata and controls
754 lines (669 loc) · 27.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010-2015 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "guiengine/layout_manager.hpp"
#include <iostream>
#include <IGUIFont.h>
#include <ITexture.h>
#include "graphics/irr_driver.hpp"
#include "guiengine/abstract_top_level_container.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/scalable_font.hpp"
#include "guiengine/widget.hpp"
#include "io/file_manager.hpp"
#include "utils/ptr_vector.hpp"
#include "utils/string_utils.hpp"
#include "utils/vs.hpp"
using namespace irr;
using namespace gui;
using namespace video;
using namespace GUIEngine;
/** Like atoi, but on error prints an error message to stderr */
int atoi_p(const char* val)
{
int i;
if (StringUtils::parseString<int>(val, &i))
{
return i;
}
else
{
Log::warn("LayoutManager", "Invalid value '%s' found in XML file where integer was expected.", val);
return 0;
}
}
// ----------------------------------------------------------------------------
bool LayoutManager::convertToCoord(std::string& x, int* absolute /* out */, int* percentage /* out */)
{
int i = 0;
if (!StringUtils::fromString<int>(x, i /* out */)) return false;
if( x[x.size()-1] == '%' ) // percentage
{
*percentage = i;
return true;
}
else if( x[x.size()-1] == 'f' ) // font height
{
*absolute = i * GUIEngine::getFontHeight();
return true;
}
else // absolute number
{
*absolute = i;
return true;
}
}
// ----------------------------------------------------------------------------
void LayoutManager::readCoords(Widget* self)
{
// determine widget position and size if not already done by sizers
std::string x = self->m_properties[PROP_X];
std::string y = self->m_properties[PROP_Y];
std::string width = self->m_properties[PROP_WIDTH];
std::string height = self->m_properties[PROP_HEIGHT];
/*
// retrieve parent size (or screen size if none). Will be useful for layout
// and especially for percentages.
unsigned int parent_w, parent_h, parent_x, parent_y;
if(parent == NULL)
{
//core::dimension2d<u32> frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize();
//parent_w = frame_size.Width;
//parent_h = frame_size.Height;
parent_w = topLevelContainer->getWidth();
parent_h = topLevelContainer->getHeight();
parent_x = 0;
parent_y = 0;
}
else
{
parent_w = parent->m_w;
parent_h = parent->m_h;
parent_x = parent->m_x;
parent_y = parent->m_y;
}
*/
// ---- try converting to number
// x coord
{
int abs_x = 0x7FFFFFFF, percent_x = 0x7FFFFFFF;
if (convertToCoord(x, &abs_x, &percent_x ))
{
if (abs_x >= 0 && abs_x != 0x7FFFFFFF)
{
self->m_absolute_x = abs_x;
}
else if (abs_x < 0)
{
self->m_absolute_reverse_x = abs(abs_x);
}
else if (percent_x >= 0 && percent_x != 0x7FFFFFFF)
{
self->m_relative_x = (float)percent_x;
}
}
}
// y coord
{
int abs_y = 0x7FFFFFFF, percent_y = 0x7FFFFFFF;
if (convertToCoord(y, &abs_y, &percent_y ))
{
if (abs_y >= 0 && abs_y != 0x7FFFFFFF)
{
self->m_absolute_y = abs_y;
}
else if (abs_y < 0)
{
self->m_absolute_reverse_y = abs(abs_y);
}
else if (percent_y >= 0 && percent_y != 0x7FFFFFFF)
{
self->m_relative_y = (float)percent_y;
}
}
}
// ---- if this widget has an icon, get icon size. this can helpful determine its optimal size
int texture_w = -1, texture_h = -1;
if (self->m_properties[PROP_ICON].size() > 0)
{
// PROP_ICON includes paths (e.g. gui/icons/logo.png)
ITexture* texture = irr_driver->getTexture(file_manager->getAsset(
self->m_properties[PROP_ICON]));
if (texture != NULL)
{
texture_w = texture->getSize().Width;
texture_h = texture->getSize().Height;
}
}
// ---- if this widget has a label, get text size. this can helpful determine its optimal size
int label_w = -1, label_h = -1;
if (self->m_text.size() > 0)
{
IGUIFont* font = (self->m_title_font ? GUIEngine::getTitleFont() : GUIEngine::getFont());
core::dimension2d< u32 > dim = font->getDimension( self->m_text.c_str() );
label_w = dim.Width + self->getWidthNeededAroundLabel();
// FIXME - won't work with multiline labels. thus, for now, when multiple
// lines are required, we need to specify a height explicitely
label_h = dim.Height + self->getHeightNeededAroundLabel();
}
else if (self->getType() == WTYPE_CHECKBOX)
{
// User text height to guess checkbox size
IGUIFont* font = (self->m_title_font ? GUIEngine::getTitleFont() : GUIEngine::getFont());
core::dimension2d< u32 > dim = font->getDimension( L"X" );
label_h = dim.Height + self->getHeightNeededAroundLabel();
label_w = label_h; // a checkbox is square
}
if (label_h == -1)
{
if (self->getType() == WTYPE_TEXTBOX ||
self->getType() == WTYPE_BUTTON ||
self->getType() == WTYPE_LABEL ||
self->getType() == WTYPE_SPINNER)
{
IGUIFont* font = (self->m_title_font ? GUIEngine::getTitleFont() : GUIEngine::getFont());
// get text height, a text box, button or label is always as high as the text it could contain
core::dimension2d< u32 > dim = font->getDimension( L"X" );
label_h = dim.Height + self->getHeightNeededAroundLabel();
}
}
// ---- if this widget has children, get their size size. this can helpful determine its optimal size
if (self->m_properties[PROP_WIDTH] == "fit" || self->m_properties[PROP_HEIGHT] == "fit")
{
bool is_vertical_row = (self->m_properties[PROP_LAYOUT] == "vertical-row");
bool is_horizontal_row = (self->m_properties[PROP_LAYOUT] == "horizontal-row");
int child_max_width = -1, child_max_height = -1;
int total_width = 0, total_height = 0;
for (unsigned int child=0; child<self->m_children.size(); child++)
{
if (self->m_children[child].m_absolute_w > -1)
{
if (is_horizontal_row)
{
total_width += self->m_children[child].m_absolute_w ;
}
else
{
if (child_max_width == -1 || self->m_children[child].m_absolute_w > child_max_width)
{
child_max_width = self->m_children[child].m_absolute_w;
}
}
}
if (self->m_children[child].m_absolute_h > -1)
{
if (is_vertical_row)
{
total_height += self->m_children[child].m_absolute_h;
}
else
{
if (child_max_height == -1 || self->m_children[child].m_absolute_h > child_max_height)
{
child_max_height = self->m_children[child].m_absolute_h;
}
}
}
}
//Add padding to <box> elements
if (self->getType() == WTYPE_DIV && self->m_show_bounding_box)
{
int padding = GUIEngine::getFontHeight() / 2;
if (self->m_properties[PROP_DIV_PADDING].length() > 0)
padding = atoi(self->m_properties[PROP_DIV_PADDING].c_str());
child_max_height += padding * 2;
total_height += padding * 2;
total_width += padding * 2;
child_max_width += padding * 2;
}
if (self->m_properties[PROP_WIDTH] == "fit")
{
self->m_absolute_w = (is_horizontal_row ? total_width : child_max_width);
}
if (self->m_properties[PROP_HEIGHT] == "fit")
{
self->m_absolute_h = (is_vertical_row ? total_height : child_max_height);
}
}
// ---- read dimension
// width
{
int abs_w = -1, percent_w = -1;
if (width == "font") self->m_absolute_w = GUIEngine::getFontHeight();
else if (convertToCoord(width, &abs_w, &percent_w ))
{
if (abs_w > -1) self->m_absolute_w = abs_w;
else if (percent_w > -1) self->m_relative_w = (float)percent_w;
}
else if(texture_w > -1) self->m_absolute_w = texture_w;
else if(label_w > -1) self->m_absolute_w = label_w;
}
// height
{
int abs_h = -1, percent_h = -1;
if (height == "font") self->m_absolute_h = GUIEngine::getFontHeight();
else if (convertToCoord(height, &abs_h, &percent_h ))
{
if (abs_h > -1) self->m_absolute_h = abs_h;
else if (percent_h > -1) self->m_relative_h = (float)percent_h;
}
else if (texture_h > -1 && label_h > -1) self->m_absolute_h = texture_h + label_h; // label + icon
else if (texture_h > -1) self->m_absolute_h = texture_h;
else if (label_h > -1) self->m_absolute_h = label_h;
}
}
// ----------------------------------------------------------------------------
void LayoutManager::applyCoords(Widget* self, AbstractTopLevelContainer* topLevelContainer, Widget* parent)
{
// retrieve parent size (or screen size if none). Will be useful for layout
// and especially for percentages.
unsigned int parent_w, parent_h, parent_x, parent_y;
if(parent == NULL)
{
//core::dimension2d<u32> frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize();
//parent_w = frame_size.Width;
//parent_h = frame_size.Height;
parent_w = topLevelContainer->getWidth();
parent_h = topLevelContainer->getHeight();
parent_x = 0;
parent_y = 0;
}
else
{
parent_w = parent->m_w;
parent_h = parent->m_h;
parent_x = parent->m_x;
parent_y = parent->m_y;
}
if (parent != NULL && parent->getType() == WTYPE_DIV && parent->m_show_bounding_box)
{
int padding = GUIEngine::getFontHeight() / 2;
if (parent->m_properties[PROP_DIV_PADDING].length() > 0)
padding = atoi(parent->m_properties[PROP_DIV_PADDING].c_str());
parent_x += padding;
parent_y += padding;
parent_w -= padding*2;
parent_h -= padding*2;
}
if (self->m_absolute_x > -1) self->m_x = parent_x + self->m_absolute_x;
else if (self->m_absolute_reverse_x > -1) self->m_x = parent_x + (parent_w - self->m_absolute_reverse_x);
else if (self->m_relative_x > -1) self->m_x = (int)(parent_x + parent_w*self->m_relative_x/100);
if (self->m_absolute_y > -1) self->m_y = parent_y + self->m_absolute_y;
else if (self->m_absolute_reverse_y > -1) self->m_y = parent_y + (parent_h - self->m_absolute_reverse_y);
else if (self->m_relative_y > -1) self->m_y = (int)(parent_y + parent_h*self->m_relative_y/100);
if (self->m_absolute_w > -1) self->m_w = self->m_absolute_w;
else if (self->m_relative_w > -1) self->m_w = (int)roundf(parent_w*self->m_relative_w/100.0f);
if (self->m_absolute_h > -1) self->m_h = self->m_absolute_h;
else if (self->m_relative_h > -1) self->m_h = (int)roundf(parent_h*self->m_relative_h/100.0f);
// ---- can't make widget bigger than parent
if (self->m_h > (int)parent_h)
{
float ratio = (float)parent_h / self->m_h;
self->m_w = (int)(self->m_w*ratio);
self->m_h = (int)(self->m_h*ratio);
}
if (self->m_w > (int)parent_w)
{
// scale down while keeping aspect ratio (don't do this for text widgets though...)
float ratio = (float)parent_w / self->m_w;
self->m_w = (int)(self->m_w * ratio);
// FIXME: ugly to hardcode widgets types here
if (self->m_type != WTYPE_LABEL && self->m_type != WTYPE_BUBBLE)
{
self->m_h = (int)(self->m_h * ratio);
}
}
// ------ check for given max size
if (self->m_properties[PROP_MAX_WIDTH].size() > 0)
{
const int max_width = atoi_p( self->m_properties[PROP_MAX_WIDTH].c_str() );
if (self->m_w > max_width) self->m_w = max_width;
}
if (self->m_properties[PROP_MAX_HEIGHT].size() > 0)
{
const int max_height = atoi_p( self->m_properties[PROP_MAX_HEIGHT].c_str() );
if (self->m_h > max_height) self->m_h = max_height;
}
}
// ----------------------------------------------------------------------------
void LayoutManager::recursivelyReadCoords(PtrVector<Widget>& widgets)
{
const unsigned short widgets_amount = widgets.size();
// ----- deal with containers' children
for (int n=0; n<widgets_amount; n++)
{
if (widgets[n].m_type == WTYPE_DIV) recursivelyReadCoords(widgets[n].m_children);
}
// ----- read x/y/size parameters
for (unsigned short n=0; n<widgets_amount; n++)
{
readCoords(widgets.get(n));
}//next widget
}
// ----------------------------------------------------------------------------
void LayoutManager::calculateLayout(PtrVector<Widget>& widgets, AbstractTopLevelContainer* topLevelContainer)
{
recursivelyReadCoords(widgets);
doCalculateLayout(widgets, topLevelContainer, NULL);
}
// ----------------------------------------------------------------------------
void LayoutManager::doCalculateLayout(PtrVector<Widget>& widgets, AbstractTopLevelContainer* topLevelContainer,
Widget* parent)
{
const unsigned short widgets_amount = widgets.size();
for (int n=0; n<widgets_amount; n++)
{
applyCoords(widgets.get(n), topLevelContainer, parent);
}
// ----- manage 'layout's if relevant
do // i'm using 'while false' here just to be able to 'break' ...
{
if(parent == NULL) break;
std::string layout_name = parent->m_properties[PROP_LAYOUT];
if(layout_name.size() < 1) break;
bool horizontal = false;
if (!strcmp("horizontal-row", layout_name.c_str()))
horizontal = true;
else if(!strcmp("vertical-row", layout_name.c_str()))
horizontal = false;
else
{
Log::error("LayoutManager::doCalculateLayout", "Unknown layout name: %s", layout_name.c_str());
break;
}
int x = parent->m_x;
int y = parent->m_y;
int w = parent->m_w;
int h = parent->m_h;
if (parent != NULL && parent->getType() == WTYPE_DIV && parent->m_show_bounding_box)
{
int padding = GUIEngine::getFontHeight() / 2;
if (parent->m_properties[PROP_DIV_PADDING].length() > 0)
padding = atoi(parent->m_properties[PROP_DIV_PADDING].c_str());
x += padding;
y += padding;
w -= padding*2;
h -= padding*2;
}
// find space left after placing all absolutely-sized widgets in a row
// (the space left will be divided between remaining widgets later)
int left_space = (horizontal ? w : h);
unsigned short total_proportion = 0;
for(int n=0; n<widgets_amount; n++)
{
// relatively-sized widget
std::string prop = widgets[n].m_properties[ PROP_PROPORTION ];
if(prop.size() != 0)
{
total_proportion += atoi_p( prop.c_str() );
continue;
}
// absolutely-sized widgets
left_space -= (horizontal ? widgets[n].m_w : widgets[n].m_h);
} // next widget
if (left_space < 0)
{
Log::warn("LayoutManager", "Statically sized widgets took all the place!!");
left_space = 0;
}
// ---- lay widgets in row
for (int n=0; n<widgets_amount; n++)
{
std::string prop = widgets[n].m_properties[ PROP_PROPORTION ];
if(prop.size() != 0)
{
// proportional size
int proportion = 1;
std::istringstream myStream(prop);
if (!(myStream >> proportion))
Log::warn("LayoutManager::doCalculateLayout",
"Proportion '%s' is not a number for widget %s", prop.c_str(),
widgets[n].m_properties[PROP_ID].c_str());
const float fraction = (float)proportion/(float)total_proportion;
if (horizontal)
{
widgets[n].m_x = x;
std::string align = widgets[n].m_properties[ PROP_ALIGN ];
if (align.size() < 1)
{
std::string prop_y = widgets[n].m_properties[ PROP_Y ];
if (prop_y.size() > 0)
{
if (prop_y[ prop_y.size()-1 ] == '%')
{
prop_y = prop_y.substr(0, prop_y.size() - 1);
widgets[n].m_y = (int)(y + atoi_p(prop_y.c_str())/100.0f * h);
}
else if(prop_y[ prop_y.size()-1 ] == 'f')
{
widgets[n].m_y = y + atoi_p(prop_y.c_str()) * GUIEngine::getFontHeight();
}
else
{
widgets[n].m_y = y + atoi_p(prop_y.c_str());
}
}
else
{
widgets[n].m_y = y;
}
}
else if (align == "top")
{
widgets[n].m_y = y;
}
else if (align == "center")
{
widgets[n].m_y = y + h/2 - widgets[n].m_h/2;
}
else if (align == "bottom")
{
widgets[n].m_y = y + h - widgets[n].m_h;
}
else
{
Log::warn("LayoutManager::doCalculateLayout",
"Alignment '%s' is unknown (widget '%s', in a horiozntal-row layout)",
align.c_str(), widgets[n].m_properties[PROP_ID].c_str());
}
widgets[n].m_w = (int)(left_space*fraction);
if (widgets[n].m_properties[PROP_MAX_WIDTH].size() > 0)
{
const int max_width = atoi_p( widgets[n].m_properties[PROP_MAX_WIDTH].c_str() );
if (widgets[n].m_w > max_width) widgets[n].m_w = max_width;
}
if (widgets[n].m_w <= 0)
{
Log::warn("LayoutManager", "Widget '%s' has a width of %i (left_space = %i, "
"fraction = %f, max_width = %s)", widgets[n].m_properties[PROP_ID].c_str(),
widgets[n].m_w, left_space, fraction, widgets[n].m_properties[PROP_MAX_WIDTH].c_str());
widgets[n].m_w = 1;
}
x += widgets[n].m_w;
}
else
{
widgets[n].m_h = (int)(left_space*fraction);
if (widgets[n].m_properties[PROP_MAX_HEIGHT].size() > 0)
{
const int max_height = atoi_p( widgets[n].m_properties[PROP_MAX_HEIGHT].c_str() );
if (widgets[n].m_h > max_height) widgets[n].m_h = max_height;
}
if (widgets[n].m_h <= 0)
{
Log::warn("LayoutManager", "Widget '%s' has a height of %i (left_space = %i, "
"fraction = %f, max_width = %s)\n", widgets[n].m_properties[PROP_ID].c_str(),
widgets[n].m_h, left_space, fraction, widgets[n].m_properties[PROP_MAX_WIDTH].c_str());
widgets[n].m_h = 1;
}
std::string align = widgets[n].m_properties[ PROP_ALIGN ];
if (align.size() < 1)
{
std::string prop_x = widgets[n].m_properties[ PROP_X ];
if (prop_x.size() > 0)
{
if (prop_x[ prop_x.size()-1 ] == '%')
{
prop_x = prop_x.substr(0, prop_x.size() - 1);
widgets[n].m_x = (int)(x + atoi_p(prop_x.c_str())/100.0f * w);
}
else if(prop_x[ prop_x.size()-1 ] == 'f')
{
widgets[n].m_x = x + atoi_p(prop_x.c_str()) * GUIEngine::getFontHeight();
}
else
{
widgets[n].m_x = x + atoi_p(prop_x.c_str());
}
}
else
{
widgets[n].m_x = x;
}
}
else if (align == "left")
{
widgets[n].m_x = x;
}
else if (align == "center")
{
widgets[n].m_x = x + w/2 - widgets[n].m_w/2;
}
else if (align == "right")
{
widgets[n].m_x = x + w - widgets[n].m_w;
}
else
{
Log::warn("LayoutManager::doCalculateLayout",
"Alignment '%s' is unknown (widget '%s', in a vertical-row layout)",
align.c_str(), widgets[n].m_properties[PROP_ID].c_str());
}
widgets[n].m_y = y;
y += widgets[n].m_h;
}
}
else
{
// absolute size
if (horizontal)
{
widgets[n].m_x = x;
std::string align = widgets[n].m_properties[ PROP_ALIGN ];
if (align.size() < 1)
{
std::string prop_y = widgets[n].m_properties[ PROP_Y ];
if (prop_y.size() > 0)
{
if (prop_y[ prop_y.size()-1 ] == '%')
{
prop_y = prop_y.substr(0, prop_y.size() - 1);
widgets[n].m_y = (int)(y + atoi_p(prop_y.c_str())/100.0f * h);
}
else if(prop_y[ prop_y.size()-1 ] == 'f')
{
widgets[n].m_y = y + atoi_p(prop_y.c_str()) * GUIEngine::getFontHeight();
}
else
{
widgets[n].m_y = y + atoi_p(prop_y.c_str());
}
}
else
{
widgets[n].m_y = y;
}
}
else if (align == "top")
{
widgets[n].m_y = y;
}
else if (align == "center")
{
widgets[n].m_y = y + h/2 - widgets[n].m_h/2;
}
else if (align == "bottom")
{
widgets[n].m_y = y + h - widgets[n].m_h;
}
else
{
Log::warn("LayoutManager::doCalculateLayout",
"Alignment '%s' is unknown in widget '%s'",
align.c_str(), widgets[n].m_properties[PROP_ID].c_str());
}
x += widgets[n].m_w;
}
else
{
std::string align = widgets[n].m_properties[ PROP_ALIGN ];
if (align.size() < 1)
{
std::string prop_x = widgets[n].m_properties[ PROP_X ];
if (prop_x.size() > 0)
{
if (prop_x[ prop_x.size()-1 ] == '%')
{
prop_x = prop_x.substr(0, prop_x.size() - 1);
widgets[n].m_x = (int)(x + atoi_p(prop_x.c_str())/100.0f * w);
}
else if(prop_x[ prop_x.size()-1 ] == 'f')
{
widgets[n].m_x = x + atoi_p(prop_x.c_str()) * GUIEngine::getFontHeight();
}
else
{
widgets[n].m_x = x + atoi_p(prop_x.c_str());
}
}
else
{
widgets[n].m_x = x;
}
}
else if (align == "left")
{
widgets[n].m_x = x;
}
else if (align == "center")
{
widgets[n].m_x = x + w/2 - widgets[n].m_w/2;
}
else if (align == "right")
{
widgets[n].m_x = x + w - widgets[n].m_w;
}
else
{
Log::warn("LayoutManager::doCalculateLayout",
"Alignment '%s' is unknown in widget '%s'",
align.c_str(), widgets[n].m_properties[PROP_ID].c_str());
}
widgets[n].m_y = y;
y += widgets[n].m_h;
}
} // end if property or absolute size
} // next widget
} while(false);
// ----- also deal with containers' children
for (int n=0; n<widgets_amount; n++)
{
if (widgets[n].m_type == WTYPE_DIV)
{
doCalculateLayout(widgets[n].m_children, topLevelContainer, &widgets[n]);
}
}
} // calculateLayout