1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#include "CGUITabControl.h"
6
#ifdef _IRR_COMPILE_WITH_GUI_
8
#include "CGUIButton.h"
10
#include "IGUIEnvironment.h"
12
#include "IVideoDriver.h"
21
// ------------------------------------------------------------------
23
// ------------------------------------------------------------------
26
CGUITab::CGUITab(s32 number, IGUIEnvironment* environment,
27
IGUIElement* parent, const core::rect<s32>& rectangle,
29
: IGUITab(environment, parent, id, rectangle), Number(number),
30
BackColor(0,0,0,0), OverrideTextColorEnabled(false), TextColor(255,0,0,0),
34
setDebugName("CGUITab");
37
const IGUISkin* const skin = environment->getSkin();
39
TextColor = skin->getColor(EGDC_BUTTON_TEXT);
43
//! Returns number of tab in tabcontrol. Can be accessed
44
//! later IGUITabControl::getTab() by this number.
45
s32 CGUITab::getNumber() const
52
void CGUITab::setNumber(s32 n)
57
void CGUITab::refreshSkinColors()
59
if ( !OverrideTextColorEnabled )
61
TextColor = Environment->getSkin()->getColor(EGDC_BUTTON_TEXT);
65
//! draws the element and its children
71
IGUISkin *skin = Environment->getSkin();
73
if (skin && DrawBackground)
74
skin->draw2DRectangle(this, BackColor, AbsoluteRect, &AbsoluteClippingRect);
80
//! sets if the tab should draw its background
81
void CGUITab::setDrawBackground(bool draw)
83
DrawBackground = draw;
87
//! sets the color of the background, if it should be drawn.
88
void CGUITab::setBackgroundColor(video::SColor c)
94
//! sets the color of the text
95
void CGUITab::setTextColor(video::SColor c)
97
OverrideTextColorEnabled = true;
102
video::SColor CGUITab::getTextColor() const
108
//! returns true if the tab is drawing its background, false if not
109
bool CGUITab::isDrawingBackground() const
111
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
112
return DrawBackground;
116
//! returns the color of the background
117
video::SColor CGUITab::getBackgroundColor() const
123
//! Writes attributes of the element.
124
void CGUITab::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
126
IGUITab::serializeAttributes(out,options);
128
out->addInt ("TabNumber", Number);
129
out->addBool ("DrawBackground", DrawBackground);
130
out->addColor ("BackColor", BackColor);
131
out->addBool ("OverrideTextColorEnabled", OverrideTextColorEnabled);
132
out->addColor ("TextColor", TextColor);
137
//! Reads attributes of the element
138
void CGUITab::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
140
IGUITab::deserializeAttributes(in,options);
142
setNumber(in->getAttributeAsInt("TabNumber"));
143
setDrawBackground(in->getAttributeAsBool("DrawBackground"));
144
setBackgroundColor(in->getAttributeAsColor("BackColor"));
145
bool override = in->getAttributeAsBool("OverrideTextColorEnabled");
146
setTextColor(in->getAttributeAsColor("TextColor"));
149
OverrideTextColorEnabled = false;
152
if (Parent && Parent->getType() == EGUIET_TAB_CONTROL)
154
((CGUITabControl*)Parent)->addTab(this);
156
((CGUITabControl*)Parent)->setActiveTab(this);
161
// ------------------------------------------------------------------
163
// ------------------------------------------------------------------
166
CGUITabControl::CGUITabControl(IGUIEnvironment* environment,
167
IGUIElement* parent, const core::rect<s32>& rectangle,
168
bool fillbackground, bool border, s32 id)
169
: IGUITabControl(environment, parent, id, rectangle), ActiveTab(-1),
170
Border(border), FillBackground(fillbackground), ScrollControl(false), TabHeight(0), VerticalAlignment(EGUIA_UPPERLEFT),
171
UpButton(0), DownButton(0), TabMaxWidth(0), CurrentScrollTabIndex(0), TabExtraWidth(20)
174
setDebugName("CGUITabControl");
177
IGUISkin* skin = Environment->getSkin();
178
IGUISpriteBank* sprites = 0;
184
sprites = skin->getSpriteBank();
185
TabHeight = skin->getSize(gui::EGDS_BUTTON_HEIGHT) + 2;
188
UpButton = Environment->addButton(core::rect<s32>(0,0,10,10), this);
192
UpButton->setSpriteBank(sprites);
193
UpButton->setVisible(false);
194
UpButton->setSubElement(true);
195
UpButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
196
UpButton->setOverrideFont(Environment->getBuiltInFont());
200
DownButton = Environment->addButton(core::rect<s32>(0,0,10,10), this);
204
DownButton->setSpriteBank(sprites);
205
DownButton->setVisible(false);
206
DownButton->setSubElement(true);
207
DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
208
DownButton->setOverrideFont(Environment->getBuiltInFont());
212
setTabVerticalAlignment(EGUIA_UPPERLEFT);
217
CGUITabControl::~CGUITabControl()
219
for (u32 i=0; i<Tabs.size(); ++i)
232
void CGUITabControl::refreshSprites()
234
video::SColor color(255,255,255,255);
235
IGUISkin* skin = Environment->getSkin();
238
color = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL);
243
UpButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_LEFT), color);
244
UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_LEFT), color);
249
DownButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_RIGHT), color);
250
DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_RIGHT), color);
255
IGUITab* CGUITabControl::addTab(const wchar_t* caption, s32 id)
257
CGUITab* tab = new CGUITab(Tabs.size(), Environment, this, calcTabPos(), id);
259
tab->setText(caption);
260
tab->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
261
tab->setVisible(false);
267
tab->setVisible(true);
270
recalculateScrollBar();
276
//! adds a tab which has been created elsewhere
277
void CGUITabControl::addTab(CGUITab* tab)
282
// check if its already added
283
for (u32 i=0; i < Tabs.size(); ++i)
291
if (tab->getNumber() == -1)
292
tab->setNumber((s32)Tabs.size());
294
while (tab->getNumber() >= (s32)Tabs.size())
297
if (Tabs[tab->getNumber()])
299
Tabs.push_back(Tabs[tab->getNumber()]);
300
Tabs[Tabs.size()-1]->setNumber(Tabs.size());
302
Tabs[tab->getNumber()] = tab;
305
ActiveTab = tab->getNumber();
308
if (tab->getNumber() == ActiveTab)
310
setActiveTab(ActiveTab);
314
//! Insert the tab at the given index
315
IGUITab* CGUITabControl::insertTab(s32 idx, const wchar_t* caption, s32 id)
317
if ( idx < 0 || idx > (s32)Tabs.size() ) // idx == Tabs.size() is indeed ok here as core::array can handle that
320
CGUITab* tab = new CGUITab(idx, Environment, this, calcTabPos(), id);
322
tab->setText(caption);
323
tab->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
324
tab->setVisible(false);
325
Tabs.insert(tab, (u32)idx);
330
tab->setVisible(true);
333
for ( u32 i=(u32)idx+1; i < Tabs.size(); ++i )
335
Tabs[i]->setNumber(i);
338
recalculateScrollBar();
343
//! Removes a tab from the tabcontrol
344
void CGUITabControl::removeTab(s32 idx)
346
if ( idx < 0 || idx >= (s32)Tabs.size() )
349
Tabs[(u32)idx]->drop();
350
Tabs.erase((u32)idx);
351
for ( u32 i=(u32)idx; i < Tabs.size(); ++i )
353
Tabs[i]->setNumber(i);
357
//! Clears the tabcontrol removing all tabs
358
void CGUITabControl::clear()
360
for (u32 i=0; i<Tabs.size(); ++i)
368
//! Returns amount of tabs in the tabcontrol
369
s32 CGUITabControl::getTabCount() const
375
//! Returns a tab based on zero based index
376
IGUITab* CGUITabControl::getTab(s32 idx) const
378
if ((u32)idx >= Tabs.size())
385
//! called if an event happened.
386
bool CGUITabControl::OnEvent(const SEvent& event)
391
switch(event.EventType)
394
switch(event.GUIEvent.EventType)
396
case EGET_BUTTON_CLICKED:
397
if (event.GUIEvent.Caller == UpButton)
402
else if (event.GUIEvent.Caller == DownButton)
413
case EET_MOUSE_INPUT_EVENT:
414
switch(event.MouseInput.Event)
416
case EMIE_LMOUSE_PRESSED_DOWN:
417
// todo: dragging tabs around
419
case EMIE_LMOUSE_LEFT_UP:
421
s32 idx = getTabAt(event.MouseInput.X, event.MouseInput.Y);
438
return IGUIElement::OnEvent(event);
442
void CGUITabControl::scrollLeft()
444
if ( CurrentScrollTabIndex > 0 )
445
--CurrentScrollTabIndex;
446
recalculateScrollBar();
450
void CGUITabControl::scrollRight()
452
if ( CurrentScrollTabIndex < (s32)(Tabs.size()) - 1 )
454
if ( needScrollControl(CurrentScrollTabIndex, true) )
455
++CurrentScrollTabIndex;
457
recalculateScrollBar();
460
s32 CGUITabControl::calcTabWidth(s32 pos, IGUIFont* font, const wchar_t* text, bool withScrollControl) const
465
s32 len = font->getDimension(text).Width + TabExtraWidth;
466
if ( TabMaxWidth > 0 && len > TabMaxWidth )
469
// check if we miss the place to draw the tab-button
470
if ( withScrollControl && ScrollControl && pos+len > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
472
s32 tabMinWidth = font->getDimension(L"A").Width;
473
if ( TabExtraWidth > 0 && TabExtraWidth > tabMinWidth )
474
tabMinWidth = TabExtraWidth;
476
if ( ScrollControl && pos+tabMinWidth <= UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
478
len = UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 - pos;
484
bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl)
486
if ( startIndex >= (s32)Tabs.size() )
489
if ( startIndex < 0 )
492
IGUISkin* skin = Environment->getSkin();
496
IGUIFont* font = skin->getFont();
498
core::rect<s32> frameRect(AbsoluteRect);
506
s32 pos = frameRect.UpperLeftCorner.X + 2;
508
for (s32 i=startIndex; i<(s32)Tabs.size(); ++i)
511
const wchar_t* text = 0;
513
text = Tabs[i]->getText();
516
s32 len = calcTabWidth(pos, font, text, false); // always without withScrollControl here or len would be shortened
518
frameRect.LowerRightCorner.X += len;
520
frameRect.UpperLeftCorner.X = pos;
521
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
524
if ( withScrollControl && pos > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2)
527
if ( !withScrollControl && pos > AbsoluteRect.LowerRightCorner.X )
535
core::rect<s32> CGUITabControl::calcTabPos()
538
r.UpperLeftCorner.X = 0;
539
r.LowerRightCorner.X = AbsoluteRect.getWidth();
542
++r.UpperLeftCorner.X;
543
--r.LowerRightCorner.X;
546
if ( VerticalAlignment == EGUIA_UPPERLEFT )
548
r.UpperLeftCorner.Y = TabHeight+2;
549
r.LowerRightCorner.Y = AbsoluteRect.getHeight()-1;
552
--r.LowerRightCorner.Y;
557
r.UpperLeftCorner.Y = 0;
558
r.LowerRightCorner.Y = AbsoluteRect.getHeight()-(TabHeight+2);
561
++r.UpperLeftCorner.Y;
569
//! draws the element and its children
570
void CGUITabControl::draw()
575
IGUISkin* skin = Environment->getSkin();
579
IGUIFont* font = skin->getFont();
580
video::IVideoDriver* driver = Environment->getVideoDriver();
582
core::rect<s32> frameRect(AbsoluteRect);
585
driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), frameRect, &AbsoluteClippingRect);
590
if ( VerticalAlignment == EGUIA_UPPERLEFT )
592
frameRect.UpperLeftCorner.Y += 2;
593
frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight;
597
frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight - 1;
598
frameRect.LowerRightCorner.Y -= 2;
602
s32 pos = frameRect.UpperLeftCorner.X + 2;
604
bool needLeftScroll = CurrentScrollTabIndex > 0;
605
bool needRightScroll = false;
607
// left and right pos of the active tab
611
//const wchar_t* activetext = 0;
612
CGUITab *activeTab = 0;
614
for (u32 i=CurrentScrollTabIndex; i<Tabs.size(); ++i)
617
const wchar_t* text = 0;
619
text = Tabs[i]->getText();
622
s32 len = calcTabWidth(pos, font, text, true);
623
if ( ScrollControl && pos+len > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
625
needRightScroll = true;
629
frameRect.LowerRightCorner.X += len;
630
frameRect.UpperLeftCorner.X = pos;
631
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
636
Tabs[i]->refreshSkinColors();
638
if ((s32)i == ActiveTab)
640
left = frameRect.UpperLeftCorner.X;
641
right = frameRect.LowerRightCorner.X;
647
skin->draw3DTabButton(this, false, frameRect, &AbsoluteClippingRect, VerticalAlignment);
650
core::rect<s32> textClipRect(frameRect); // TODO: exact size depends on borders in draw3DTabButton which we don't get with current interface
651
textClipRect.clipAgainst(AbsoluteClippingRect);
652
font->draw(text, frameRect, Tabs[i]->getTextColor(),
653
true, true, &textClipRect);
658
if (left != 0 && right != 0 && activeTab != 0)
660
// draw upper highlight frame
661
if ( VerticalAlignment == EGUIA_UPPERLEFT )
663
frameRect.UpperLeftCorner.X = left-2;
664
frameRect.LowerRightCorner.X = right+2;
665
frameRect.UpperLeftCorner.Y -= 2;
667
skin->draw3DTabButton(this, true, frameRect, &AbsoluteClippingRect, VerticalAlignment);
670
core::rect<s32> textClipRect(frameRect); // TODO: exact size depends on borders in draw3DTabButton which we don't get with current interface
671
textClipRect.clipAgainst(AbsoluteClippingRect);
672
font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(),
673
true, true, &textClipRect);
675
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
676
tr.LowerRightCorner.X = left - 1;
677
tr.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - 1;
678
tr.LowerRightCorner.Y = frameRect.LowerRightCorner.Y;
679
driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), tr, &AbsoluteClippingRect);
681
tr.UpperLeftCorner.X = right;
682
tr.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X;
683
driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), tr, &AbsoluteClippingRect);
688
frameRect.UpperLeftCorner.X = left-2;
689
frameRect.LowerRightCorner.X = right+2;
690
frameRect.LowerRightCorner.Y += 2;
692
skin->draw3DTabButton(this, true, frameRect, &AbsoluteClippingRect, VerticalAlignment);
695
font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(),
696
true, true, &frameRect);
698
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
699
tr.LowerRightCorner.X = left - 1;
700
tr.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - 1;
701
tr.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y;
702
driver->draw2DRectangle(skin->getColor(EGDC_3D_DARK_SHADOW), tr, &AbsoluteClippingRect);
704
tr.UpperLeftCorner.X = right;
705
tr.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X;
706
driver->draw2DRectangle(skin->getColor(EGDC_3D_DARK_SHADOW), tr, &AbsoluteClippingRect);
711
if ( VerticalAlignment == EGUIA_UPPERLEFT )
713
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
714
tr.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X;
715
tr.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - 1;
716
tr.LowerRightCorner.Y = frameRect.LowerRightCorner.Y;
717
driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), tr, &AbsoluteClippingRect);
721
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
722
tr.LowerRightCorner.X = 1000;
723
tr.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - 1;
724
tr.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y;
725
driver->draw2DRectangle(skin->getColor(EGDC_3D_DARK_SHADOW), tr, &AbsoluteClippingRect);
729
skin->draw3DTabBody(this, Border, FillBackground, AbsoluteRect, &AbsoluteClippingRect, TabHeight, VerticalAlignment);
731
// enable scrollcontrols on need
733
UpButton->setEnabled(needLeftScroll);
735
DownButton->setEnabled(needRightScroll);
742
//! Set the height of the tabs
743
void CGUITabControl::setTabHeight( s32 height )
750
recalculateScrollButtonPlacement();
751
recalculateScrollBar();
755
//! Get the height of the tabs
756
s32 CGUITabControl::getTabHeight() const
761
//! set the maximal width of a tab. Per default width is 0 which means "no width restriction".
762
void CGUITabControl::setTabMaxWidth(s32 width )
767
//! get the maximal width of a tab
768
s32 CGUITabControl::getTabMaxWidth() const
774
//! Set the extra width added to tabs on each side of the text
775
void CGUITabControl::setTabExtraWidth( s32 extraWidth )
777
if ( extraWidth < 0 )
780
TabExtraWidth = extraWidth;
782
recalculateScrollBar();
786
//! Get the extra width added to tabs on each side of the text
787
s32 CGUITabControl::getTabExtraWidth() const
789
return TabExtraWidth;
793
void CGUITabControl::recalculateScrollBar()
795
if (!UpButton || !DownButton)
798
ScrollControl = needScrollControl() || CurrentScrollTabIndex > 0;
802
UpButton->setVisible( true );
803
DownButton->setVisible( true );
807
UpButton->setVisible( false );
808
DownButton->setVisible( false );
811
bringToFront( UpButton );
812
bringToFront( DownButton );
815
//! Set the alignment of the tabs
816
void CGUITabControl::setTabVerticalAlignment( EGUI_ALIGNMENT alignment )
818
VerticalAlignment = alignment;
820
recalculateScrollButtonPlacement();
821
recalculateScrollBar();
823
core::rect<s32> r(calcTabPos());
824
for ( u32 i=0; i<Tabs.size(); ++i )
826
Tabs[i]->setRelativePosition(r);
830
void CGUITabControl::recalculateScrollButtonPlacement()
832
IGUISkin* skin = Environment->getSkin();
834
s32 ButtonHeight = TabHeight - 2;
835
if ( ButtonHeight < 0 )
836
ButtonHeight = TabHeight;
839
ButtonSize = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH);
840
if (ButtonSize > TabHeight)
841
ButtonSize = TabHeight;
844
s32 ButtonX = RelativeRect.getWidth() - (s32)(2.5f*(f32)ButtonSize) - 1;
847
if (VerticalAlignment == EGUIA_UPPERLEFT)
849
ButtonY = 2 + (TabHeight / 2) - (ButtonHeight / 2);
850
UpButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
851
DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
855
ButtonY = RelativeRect.getHeight() - (TabHeight / 2) - (ButtonHeight / 2) - 2;
856
UpButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
857
DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
860
UpButton->setRelativePosition(core::rect<s32>(ButtonX, ButtonY, ButtonX+ButtonSize, ButtonY+ButtonHeight));
861
ButtonX += ButtonSize + 1;
862
DownButton->setRelativePosition(core::rect<s32>(ButtonX, ButtonY, ButtonX+ButtonSize, ButtonY+ButtonHeight));
865
//! Get the alignment of the tabs
866
EGUI_ALIGNMENT CGUITabControl::getTabVerticalAlignment() const
868
return VerticalAlignment;
872
s32 CGUITabControl::getTabAt(s32 xpos, s32 ypos) const
874
core::position2di p(xpos, ypos);
875
IGUISkin* skin = Environment->getSkin();
876
IGUIFont* font = skin->getFont();
878
core::rect<s32> frameRect(AbsoluteRect);
880
if ( VerticalAlignment == EGUIA_UPPERLEFT )
882
frameRect.UpperLeftCorner.Y += 2;
883
frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight;
887
frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight;
890
s32 pos = frameRect.UpperLeftCorner.X + 2;
892
if (!frameRect.isPointInside(p))
895
for (s32 i=CurrentScrollTabIndex; i<(s32)Tabs.size(); ++i)
898
const wchar_t* text = 0;
900
text = Tabs[i]->getText();
903
s32 len = calcTabWidth(pos, font, text, true);
904
if ( ScrollControl && pos+len > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
907
frameRect.UpperLeftCorner.X = pos;
908
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
912
if (frameRect.isPointInside(p))
920
//! Returns which tab is currently active
921
s32 CGUITabControl::getActiveTab() const
927
//! Brings a tab to front.
928
bool CGUITabControl::setActiveTab(s32 idx)
930
if ((u32)idx >= Tabs.size())
933
bool changed = (ActiveTab != idx);
937
for (s32 i=0; i<(s32)Tabs.size(); ++i)
939
Tabs[i]->setVisible( i == ActiveTab );
944
event.EventType = EET_GUI_EVENT;
945
event.GUIEvent.Caller = this;
946
event.GUIEvent.Element = 0;
947
event.GUIEvent.EventType = EGET_TAB_CHANGED;
948
Parent->OnEvent(event);
955
bool CGUITabControl::setActiveTab(IGUITab *tab)
957
for (s32 i=0; i<(s32)Tabs.size(); ++i)
959
return setActiveTab(i);
965
void CGUITabControl::removeChild(IGUIElement* child)
970
// check if it is a tab
971
while (i<Tabs.size())
973
if (Tabs[i] == child)
986
for (i=0; i<Tabs.size(); ++i)
988
Tabs[i]->setNumber(i);
991
// remove real element
992
IGUIElement::removeChild(child);
994
recalculateScrollBar();
998
//! Update the position of the element, decides scroll button status
999
void CGUITabControl::updateAbsolutePosition()
1001
IGUIElement::updateAbsolutePosition();
1002
recalculateScrollBar();
1006
//! Writes attributes of the element.
1007
void CGUITabControl::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
1009
IGUITabControl::serializeAttributes(out,options);
1011
out->addInt ("ActiveTab", ActiveTab);
1012
out->addBool("Border", Border);
1013
out->addBool("FillBackground", FillBackground);
1014
out->addInt ("TabHeight", TabHeight);
1015
out->addInt ("TabMaxWidth", TabMaxWidth);
1016
out->addEnum("TabVerticalAlignment", s32(VerticalAlignment), GUIAlignmentNames);
1020
//! Reads attributes of the element
1021
void CGUITabControl::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
1023
Border = in->getAttributeAsBool("Border");
1024
FillBackground = in->getAttributeAsBool("FillBackground");
1028
setTabHeight(in->getAttributeAsInt("TabHeight"));
1029
TabMaxWidth = in->getAttributeAsInt("TabMaxWidth");
1031
IGUITabControl::deserializeAttributes(in,options);
1033
setActiveTab(in->getAttributeAsInt("ActiveTab"));
1034
setTabVerticalAlignment( static_cast<EGUI_ALIGNMENT>(in->getAttributeAsEnumeration("TabVerticalAlignment" , GUIAlignmentNames)) );
1038
} // end namespace irr
1039
} // end namespace gui
1041
#endif // _IRR_COMPILE_WITH_GUI_