forked from gecube/opencaesar3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oc3_widget.cpp
1060 lines (895 loc) · 27 KB
/
oc3_widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is part of openCaesar3.
//
// openCaesar3 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.
//
// openCaesar3 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 openCaesar3. If not, see <http://www.gnu.org/licenses/>.
#include "oc3_widget.hpp"
#include "oc3_widgetprivate.hpp"
#include "oc3_guienv.hpp"
#include "oc3_event.hpp"
void Widget::beforeDraw( GfxEngine& painter )
{
_OC3_DEBUG_BREAK_IF( !_d->parent && "Parent must be exists" );
ChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
(*it)->beforeDraw( painter );
}
// void Widget::setFont( Font font, u32 nA/*=0 */ )
// {
// _d->overrideFonts[ nA ] = font;
// }
//
// Font Widget::getFont( u32 index/*=0 */ ) const
// {
// FontsMap::Node* ret = _d->overrideFonts.find( index );
// return ret ? ret->getValue() : Font();
// }
// void Widget::setColor( const Color& color, u32 nA/*=0 */ )
// {
// _d->overrideColors.set( nA, _OverrideColor( color, true ) );
// }
//
// Color Widget::getColor( u32 index/*=0 */ ) const
// {
// ColorMap::Node* ret = _d->overrideColors.find( index );
// return ret ? ret->getValue().color : Color( 0xff000000 );
// }
// FontsMap& Widget::getFonts_()
// {
// return _d->overrideFonts;
// }
// unsigned int Widget::getResultOpacity()
// {
// f32 resultAlpha = getOpacity() / 255.f;
//
// Widget* parent = getParent();
// while( parent )
// {
// resultAlpha *= ( parent->getOpacity() / 255.f );
// parent = parent->getParent();
// }
//
// return u32( resultAlpha * 0xff );
// }
//
// Color Widget::getResultColor( Color defColor /*= video::SColor( 0xffffffff ) */ )
// {
// defColor.setAlpha( math::middle_<u32>( defColor.getAlpha(), getResultOpacity(), 255 ) );
// return defColor;
// }
GuiEnv* Widget::getEnvironment()
{
return _environment;
}
void Widget::setTextAlignment( TypeAlign horizontal, TypeAlign vertical )
{
_OC3_DEBUG_BREAK_IF( (!(horizontal >= alignUpperLeft && horizontal <= alignAuto)
|| !(vertical >= alignUpperLeft && vertical <= alignAuto))
&& "Unknown align in SetTextAlignment" );
_d->textHorzAlign = horizontal;
_d->textVertAlign = vertical;
}
void Widget::styleChanged()
{
ConstChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
(*it)->styleChanged();
}
void Widget::setMaxWidth( unsigned int width )
{
_d->maxSize.setWidth( width );
}
unsigned int Widget::getHeight() const
{
return getRelativeRect().getHeight();
}
Widget::Widget( Widget* parent, int id, const Rect& rectangle )
: _d( new Impl ),
_isVisible(true), _isEnabled(true),
_isSubElement(false), _noClip(false), _id(id), _isTabStop(false), _tabOrder(-1), _isTabGroup(false),
_alignLeft(alignUpperLeft), _alignRight(alignUpperLeft), _alignTop(alignUpperLeft), _alignBottom(alignUpperLeft),
_environment( parent ? parent->getEnvironment() : NULL ), _eventHandler( NULL )
{
_d->maxSize = Size(0,0);
_d->minSize = Size(1,1);
_d->parent = parent;
_d->relativeRect = rectangle;
_d->absoluteRect = rectangle;
_d->absoluteClippingRect = rectangle;
_d->desiredRect = rectangle;
#ifdef _DEBUG
setDebugName( "AbstractWidget" );
#endif
// if we were given a parent to attach to
if (parent)
{
parent->addChild_(this);
recalculateAbsolutePosition(true);
drop();
}
setTextAlignment( alignUpperLeft, alignCenter );
}
Widget::~Widget()
{
// delete all children
ChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
{
(*it)->_d->parent = 0;
(*it)->drop();
}
}
void Widget::setGeometry( const Rect& r, GeometryType mode )
{
if( getParent() )
{
/*const Rect& r2 = */getParent()->getAbsoluteRect();
// NSizeF d = r2.getSize().As<f32>();//( (f32)(r2.getSize().Width), (f32)(r2.getSize().Height) );
//
// RectF& scaleRect = _d->scaleRect;
// if (_alignLeft == alignScale)
// scaleRect.UpperLeftCorner.X = (f32)r.UpperLeftCorner.X / d.Width;
// if (_alignRight == alignScale)
// scaleRect.LowerRightCorner.X = (f32)r.LowerRightCorner.X / d.Width;
// if (_alignTop == alignScale)
// scaleRect.UpperLeftCorner.Y = (f32)r.UpperLeftCorner.Y / d.Height;
// if (_alignBottom == alignScale)
// scaleRect.LowerRightCorner.Y = (f32)r.LowerRightCorner.Y / d.Height;
}
_d->desiredRect = r;
updateAbsolutePosition();
}
void Widget::resizeEvent_()
{
}
void Widget::setPosition( const Point& position )
{
const Rect rectangle( position, getSize() );
setGeometry( rectangle );
}
// void Widget::setRelativeRectProportional( const RectF& r, GeometryType mode )
// {
// if( !getParent() )
// return;
//
// const NSizeI& d = getParent()->getSize();
//
// switch( mode )
// {
// case ProportionalGeometry:
// _d->desiredRect = RectI(
// math::floor32( d.Width * r.UpperLeftCorner.X),
// math::floor32( d.Height * r.UpperLeftCorner.Y),
// math::floor32( d.Width * r.LowerRightCorner.X),
// math::floor32( d.Height * r.LowerRightCorner.Y));
//
// _d->scaleRect = r;
// break;
//
// default:
// break;
// }
//
// updateAbsolutePosition();
// }
Rect Widget::getAbsoluteRect() const
{
return _d->absoluteRect;
}
Rect Widget::getAbsoluteClippingRect() const
{
return _d->absoluteClippingRect;
}
void Widget::setNotClipped( bool noClip )
{
_noClip = noClip;
updateAbsolutePosition();
}
void Widget::setMaxSize( const Size& size )
{
_d->maxSize = size;
updateAbsolutePosition();
}
void Widget::setMinSize( const Size& size )
{
_d->minSize = size;
if( _d->minSize.getWidth() < 1)
_d->minSize.setWidth( 1 );
if( _d->minSize.getHeight() < 1)
_d->minSize.setHeight( 1 );
updateAbsolutePosition();
}
void Widget::setAlignment( TypeAlign left, TypeAlign right, TypeAlign top, TypeAlign bottom )
{
_alignLeft = left;
_alignRight = right;
_alignTop = top;
_alignBottom = bottom;
if( getParent() )
{
Rect r( getParent()->getAbsoluteRect() );
// SizeF d = r.getSize().As<f32>();
//
// RectF& scaleRect = _d->scaleRect;
// RectF dRect = _d->desiredRect.As<f32>();
// if (_alignLeft == alignScale)
// scaleRect.UpperLeftCorner.X = dRect.UpperLeftCorner.X / d.Width;
// if (_alignRight == alignScale)
// scaleRect.LowerRightCorner.X = dRect.LowerRightCorner.X / d.Width;
// if (_alignTop == alignScale)
// scaleRect.UpperLeftCorner.Y = dRect.UpperLeftCorner.Y / d.Height;
// if (_alignBottom == alignScale)
// scaleRect.LowerRightCorner.Y = dRect.LowerRightCorner.Y / d.Height;
}
}
void Widget::updateAbsolutePosition()
{
const Rect oldRect = _d->absoluteRect;
recalculateAbsolutePosition(false);
if( oldRect != _d->absoluteRect )
resizeEvent_();
// update all children
ChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
{
(*it)->updateAbsolutePosition();
}
}
Widget* Widget::getElementFromPoint( const Point& point )
{
Widget* target = 0;
// we have to search from back to front, because later children
// might be drawn over the top of earlier ones.
ChildIterator it = _d->children.getLast();
if (isVisible())
{
while(it != _d->children.end())
{
target = (*it)->getElementFromPoint(point);
if (target)
return target;
--it;
}
}
if (isVisible() && isPointInside(point))
target = this;
return target;
}
bool Widget::isPointInside( const Point& point ) const
{
return getAbsoluteClippingRect().isPointInside(point);
}
void Widget::addChild( Widget* child )
{
addChild_(child);
if (child)
{
child->updateAbsolutePosition();
}
}
void Widget::removeChild( Widget* child )
{
ChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
if ((*it) == child)
{
(*it)->_d->parent = 0;
(*it)->drop();
_d->children.erase(it);
return;
}
}
void Widget::draw( GfxEngine& painter )
{
if ( isVisible() )
{
ChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
(*it)->draw( painter );
}
}
bool Widget::isVisible() const
{
return _isVisible;
}
bool Widget::isSubElement() const
{
return _isSubElement;
}
void Widget::setSubElement( bool subElement )
{
_isSubElement = subElement;
}
void Widget::setTabStop( bool enable )
{
_isTabStop = enable;
}
void Widget::setTabOrder( int index )
{
// negative = autonumber
if (index < 0)
{
_tabOrder = 0;
Widget *el = getTabGroup();
while( _isTabGroup && el && el->getParent() )
el = el->getParent();
Widget *first=0, *closest=0;
if (el)
{
// find the highest element number
el->getNextWidget(-1, true, _isTabGroup, first, closest, true);
if (first)
{
_tabOrder = first->getTabOrder() + 1;
}
}
}
else
_tabOrder = index;
}
int Widget::getTabOrder() const
{
return _tabOrder;
}
Widget* Widget::getTabGroup()
{
Widget *ret=this;
while (ret && !ret->hasTabGroup())
ret = ret->getParent();
return ret;
}
bool Widget::isEnabled() const
{
if ( isSubElement() && _isEnabled && getParent() )
return getParent()->isEnabled();
return _isEnabled;
}
bool Widget::bringToFront()
{
if( getParent() )
return getParent()->bringChildToFront( this );
return false;
}
bool Widget::bringChildToFront( Widget* element )
{
ChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
{
if (element == (*it))
{
_d->children.erase(it);
_d->children.push_back(element);
return true;
}
}
return false;
}
bool Widget::sendChildToBack( Widget* child )
{
ChildIterator it = _d->children.begin();
if (child == (*it)) // already there
return true;
for (; it != _d->children.end(); ++it)
{
if (child == (*it))
{
_d->children.erase(it);
_d->children.push_front(child);
return true;
}
}
return false;
}
bool Widget::sendToBack()
{
if( getParent() )
return getParent()->sendChildToBack( this );
return false;
}
Widget* Widget::findChild( int id, bool searchchildren/*=false*/ ) const
{
Widget* e = 0;
ConstChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
{
if ((*it)->getID() == id)
return (*it);
if (searchchildren)
e = (*it)->findChild(id, true);
if (e)
return e;
}
return e;
}
bool Widget::getNextWidget( int startOrder, bool reverse, bool group, Widget*& first, Widget*& closest, bool includeInvisible/*=false*/ ) const
{
// we'll stop searching if we find this number
int wanted = startOrder + ( reverse ? -1 : 1 );
if (wanted==-2)
wanted = 1073741824; // maximum int
ConstChildIterator it = _d->children.begin();
int closestOrder, currentOrder;
while(it != _d->children.end())
{
// ignore invisible elements and their children
if ( ( (*it)->isVisible() || includeInvisible ) &&
(group == true || (*it)->hasTabGroup() == false) )
{
// only check tab stops and those with the same group status
if ((*it)->isTabStop() && ((*it)->hasTabGroup() == group))
{
currentOrder = (*it)->getTabOrder();
// is this what we're looking for?
if (currentOrder == wanted)
{
closest = *it;
return true;
}
// is it closer than the current closest?
if (closest)
{
closestOrder = closest->getTabOrder();
if ( ( reverse && currentOrder > closestOrder && currentOrder < startOrder)
||(!reverse && currentOrder < closestOrder && currentOrder > startOrder))
{
closest = *it;
}
}
else
if ( (reverse && currentOrder < startOrder) || (!reverse && currentOrder > startOrder) )
{
closest = *it;
}
// is it before the current first?
if (first)
{
closestOrder = first->getTabOrder();
if ( (reverse && closestOrder < currentOrder) || (!reverse && closestOrder > currentOrder) )
{
first = *it;
}
}
else
{
first = *it;
}
}
// search within children
if ((*it)->getNextWidget(startOrder, reverse, group, first, closest))
{
return true;
}
}
++it;
}
return false;
}
// void Widget::save( core::VariantArray* out ) const
// {
// out->AddString( SerializeHelper::styleProp, getStyle().getName() );
// out->AddFloat( SerializeHelper::opacityProp, getOpacity() );
// out->AddString( SerializeHelper::internalNameProp, _d->internalName );
// out->AddEnum( SerializeHelper::hTextAlignProp, _d->textHorzAlign, NrpAlignmentNames );
// out->AddEnum( SerializeHelper::vTextAlignProp, _d->textVertAlign, NrpAlignmentNames );
// out->AddInt( SerializeHelper::idProp, _id );
// out->AddString( SerializeHelper::captionProp, getText() );
// out->AddString( SerializeHelper::tooltipProp, getTooltipText() );
// out->AddRect( SerializeHelper::rectangleProp, _d->desiredRect );
// out->AddSize( SerializeHelper::minSizeProp, _minSize );
// out->AddSize( SerializeHelper::maxSizeProp, _maxSize );
// out->AddEnum( SerializeHelper::leftAlignProp, _alignLeft, NrpAlignmentNames);
// out->AddEnum( SerializeHelper::rightAlignProp, _alignRight, NrpAlignmentNames);
// out->AddEnum( SerializeHelper::topAlignProp, _alignTop, NrpAlignmentNames);
// out->AddEnum( SerializeHelper::bottomAlignProp, _alignBottom, NrpAlignmentNames);
// out->AddBool( SerializeHelper::visibleProp, _isVisible);
// out->AddBool( SerializeHelper::enabledProp, _isEnabled);
// out->AddBool( SerializeHelper::tabStopProp, _isTabStop);
// out->AddBool( SerializeHelper::tabGroupProp, _isTabGroup);
// out->AddInt( SerializeHelper::tabOrderProp, _tabOrder);
// out->AddBool( SerializeHelper::noClipProp, _noClip);
// }
//
// void Widget::load( core::VariantArray* in )
// {
// setStyle( in->getAttributeAsString( SerializeHelper::styleProp ) );
// setOpacity( in->getAttributeAsFloat( SerializeHelper::opacityProp ) );
// _d->internalName = in->getAttributeAsString( SerializeHelper::internalNameProp );
// setTextAlignment( (TypeAlign)in->getAttributeAsEnumeration( SerializeHelper::hTextAlignProp, NrpAlignmentNames ),
// (TypeAlign)in->getAttributeAsEnumeration( SerializeHelper::vTextAlignProp, NrpAlignmentNames ) );
// setID( in->getAttributeAsInt( SerializeHelper::idProp ) );
// setText(in->getAttributeAsString( SerializeHelper::captionProp ) );
// setTooltipText( in->getAttributeAsString( SerializeHelper::tooltipProp ) );
// setVisible( in->getAttributeAsBool( SerializeHelper::visibleProp ) );
// setEnabled(in->getAttributeAsBool( SerializeHelper::enabledProp ));
// _isTabStop = in->getAttributeAsBool( SerializeHelper::tabStopProp );
// _isTabGroup = in->getAttributeAsBool( SerializeHelper::tabGroupProp );
// _tabOrder = in->getAttributeAsInt( SerializeHelper::tabOrderProp );
//
// setMaxSize( in->getAttributeAsSize( SerializeHelper::maxSizeProp ) );
// setMinSize( in->getAttributeAsSize( SerializeHelper::minSizeProp ) );
//
// setAlignment( (TypeAlign) in->getAttributeAsEnumeration( SerializeHelper::leftAlignProp, NrpAlignmentNames),
// (TypeAlign)in->getAttributeAsEnumeration( SerializeHelper::rightAlignProp, NrpAlignmentNames),
// (TypeAlign)in->getAttributeAsEnumeration( SerializeHelper::topAlignProp, NrpAlignmentNames),
// (TypeAlign)in->getAttributeAsEnumeration( SerializeHelper::bottomAlignProp, NrpAlignmentNames));
//
// setGeometry( in->getAttributeAsRect( SerializeHelper::rectangleProp ));
//
// setNotClipped( in->getAttributeAsBool( SerializeHelper::noClipProp ) );
// }
void Widget::addChild_( Widget* child )
{
if (child)
{
child->grab(); // prevent destruction when removed
child->remove(); // remove from old parent
child->_d->lastParentRect = getAbsoluteRect();
child->_d->parent = this;
_d->children.push_back(child);
}
}
void Widget::recalculateAbsolutePosition( bool recursive )
{
Rect parentAbsolute(0,0,0,0);
Rect parentAbsoluteClip;
//float fw=0.f, fh=0.f;
if ( getParent() )
{
parentAbsolute = getParent()->getAbsoluteRect();
if (_noClip)
{
Widget* p=this;
while( p && p->getParent() )
p = p->getParent();
parentAbsoluteClip = p->getAbsoluteClippingRect();
}
else
parentAbsoluteClip = getParent()->getAbsoluteClippingRect();
}
const int diffx = parentAbsolute.getWidth() - _d->lastParentRect.getWidth();
const int diffy = parentAbsolute.getHeight() - _d->lastParentRect.getHeight();
/* QUESTION: garbage code?????
if (_alignLeft == alignScale || _alignRight == alignScale)
fw = (float)parentAbsolute.getWidth();
if (_alignTop == alignScale || _alignBottom == alignScale)
fh = (float)parentAbsolute.getHeight();
*/
switch (_alignLeft)
{
case alignAuto:
case alignUpperLeft:
break;
case alignLowerRight:
_d->desiredRect.UpperLeftCorner += Point( diffx, 0 );
break;
case alignCenter:
_d->desiredRect.UpperLeftCorner += Point( diffx/2, 0 );
break;
case alignScale:
//_d->desiredRect.UpperLeftCorner.setX( _d->scaleRect.UpperLeftCorner.X * fw );
break;
}
switch (_alignRight)
{
case alignAuto:
case alignUpperLeft:
break;
case alignLowerRight:
_d->desiredRect.LowerRightCorner += Point( diffx, 0 );
break;
case alignCenter:
_d->desiredRect.LowerRightCorner += Point( diffx/2, 0 );
break;
case alignScale:
//_d->desiredRect.LowerRightCorner.X = math::round_(_d->scaleRect.LowerRightCorner.X * fw);
break;
}
switch (_alignTop)
{
case alignAuto:
case alignUpperLeft:
break;
case alignLowerRight:
_d->desiredRect.UpperLeftCorner += Point( 0, diffy );
break;
case alignCenter:
_d->desiredRect.UpperLeftCorner += Point( 0, diffy/2 );
break;
case alignScale:
//_d->desiredRect.UpperLeftCorner.Y = math::round_(_d->scaleRect.UpperLeftCorner.Y * fh);
break;
}
switch (_alignBottom)
{
case alignAuto:
case alignUpperLeft:
break;
case alignLowerRight:
_d->desiredRect.LowerRightCorner += Point( 0, diffy );
break;
case alignCenter:
_d->desiredRect.LowerRightCorner += Point( 0, diffy/2 );
break;
case alignScale:
//_d->desiredRect.LowerRightCorner.Y = math::round_(_d->scaleRect.LowerRightCorner.Y * fh);
break;
}
_d->relativeRect = _d->desiredRect;
const int w = _d->relativeRect.getWidth();
const int h = _d->relativeRect.getHeight();
// make sure the desired rectangle is allowed
if (w < (int)_d->minSize.getWidth() )
_d->relativeRect.LowerRightCorner.setX( _d->relativeRect.UpperLeftCorner.getX() + _d->minSize.getWidth() );
if (h < (int)_d->minSize.getHeight() )
_d->relativeRect.LowerRightCorner.setY( _d->relativeRect.UpperLeftCorner.getY() + _d->minSize.getHeight() );
if (_d->maxSize.getWidth() > 0 && w > (int)_d->maxSize.getWidth() )
_d->relativeRect.LowerRightCorner.setX( _d->relativeRect.UpperLeftCorner.getX() + _d->maxSize.getWidth() );
if (_d->maxSize.getHeight() > 0 && h > (int)_d->maxSize.getHeight() )
_d->relativeRect.LowerRightCorner.setY( _d->relativeRect.UpperLeftCorner.getY() + _d->maxSize.getHeight() );
_d->relativeRect.repair();
_d->absoluteRect = _d->relativeRect + parentAbsolute.UpperLeftCorner;
if (!getParent())
parentAbsoluteClip = getAbsoluteRect();
_d->absoluteClippingRect = getAbsoluteRect();
_d->absoluteClippingRect.clipAgainst(parentAbsoluteClip);
_d->lastParentRect = parentAbsolute;
if ( recursive )
{
// update all children
ChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
{
(*it)->recalculateAbsolutePosition(recursive);
}
}
}
void Widget::animate( unsigned int timeMs )
{
if ( isVisible() )
{
ChildIterator it = _d->children.begin();
for (; it != _d->children.end(); ++it)
(*it)->animate( timeMs );
}
}
void Widget::remove()
{
_OC3_DEBUG_BREAK_IF( !getParent() && "parent must be exist for element" );
if( getParent() )
getParent()->removeChild( this );
}
void Widget::setEnabled(bool enabled)
{
_isEnabled = enabled;
}
// f32 Widget::getOpacity( u32 index/*=0 */ ) const
// {
// return ( index < _d->opacity.size() ) ? (f32)_d->opacity[ index ] : 0xff;
// }
//
// void Widget::setOpacity( f32 nA, int index/*=0 */ )
// {
// _d->opacity[ index ] = math::clamp<f32>( nA, 0, 255 );
// }
std::string Widget::getInternalName() const
{
return _d->internalName;
}
void Widget::setInternalName( const std::string& name )
{
_d->internalName = name;
}
Widget* Widget::getParent() const
{
return _d->parent;
}
Rect Widget::getRelativeRect() const
{
return _d->relativeRect;
}
bool Widget::isNotClipped() const
{
return _noClip;
}
void Widget::setVisible( bool visible )
{
_isVisible = visible;
}
bool Widget::isTabStop() const
{
return _isTabStop;
}
bool Widget::hasTabGroup() const
{
return _isTabGroup;
}
void Widget::setText( const std::string& text )
{
_text = text;
}
void Widget::setTooltipText( const std::string& text )
{
_toolTipText = text;
}
std::string Widget::getText() const
{
return _text;
}
std::string Widget::getTooltipText() const
{
return _toolTipText;
}
int Widget::getID() const
{
return _id;
}
void Widget::setID( int id )
{
_id = id;
}
bool Widget::onEvent( const NEvent& event )
{
if( _eventHandler )
_eventHandler->onEvent( event );
if (event.EventType == OC3_MOUSE_EVENT)
if (getParent() && (getParent()->getParent() == NULL))
return true;
return getParent() ? getParent()->onEvent(event) : false;
}
const Widget::Widgets& Widget::getChildren() const
{
return _d->children;
}
bool Widget::isMyChild( Widget* child ) const
{
if (!child)
return false;
do
{
if( child->getParent() )
child = child->getParent();
} while (child->getParent() && child != this);
return child == this;
}
Size Widget::getMaxSize() const
{
return _d->maxSize;
}
Size Widget::getMinSize() const
{
return _d->minSize;
}
// bool Widget::isColorEnabled( u32 index ) const
// {
// ColorMap::Node* ret = _d->overrideColors.find( index );
// return ret ? ret->getValue().enabled : false;
// }
//
// void Widget::setEnabledColor( bool enable, u32 index/*=0*/ )
// {
// ColorMap::Node* ret = _d->overrideColors.find( index );
// if( ret )
// {
// _d->overrideColors.set( index, _OverrideColor( ret->getValue().color, enable ));
// }
// }
void Widget::installEventHandler( Widget* elementHandler )
{
_eventHandler = elementHandler;
}
bool Widget::isHovered() const
{
return _environment->isHovered( this );
}
bool Widget::isFocused() const
{
return _environment->hasFocus( this );
}
Rect Widget::getClientRect() const
{
return Rect( 0, 0, getWidth(), getHeight() );
}
void Widget::setFocus()
{
getEnvironment()->setFocus( this );
}
void Widget::removeFocus()
{
getEnvironment()->removeFocus( this );
}
Rect& Widget::getAbsoluteClippingRectRef() const
{
return _d->absoluteClippingRect;
}
unsigned int Widget::getWidth() const
{
return getRelativeRect().getWidth();
}
Size Widget::getSize() const
{
return Size( _d->relativeRect.getWidth(), _d->relativeRect.getHeight() );
}
int Widget::getScreenTop() const { return getAbsoluteRect().getTop(); }
int Widget::getScreenLeft() const { return getAbsoluteRect().getLeft(); }
int Widget::getScreenBottom() const { return getAbsoluteRect().getBottom(); }
int Widget::getScreenRight() const { return getAbsoluteRect().getRight(); }
unsigned int Widget::getArea() const { return getAbsoluteRect().getArea(); }
Point Widget::convertLocalToScreen( const Point& localPoint ) const
{
return localPoint + _d->absoluteRect.UpperLeftCorner;
}
Rect Widget::convertLocalToScreen( const Rect& localRect ) const
{
return localRect + _d->absoluteRect.UpperLeftCorner;
}
void Widget::move( const Point& relativeMovement )
{
setGeometry( _d->desiredRect + relativeMovement );
}
int Widget::getBottom() const
{
return _d->relativeRect.LowerRightCorner.getY();
}
void Widget::setTabGroup( bool isGroup )
{
_isTabGroup = isGroup;
}
void Widget::setWidth( unsigned int width )