Reformat the code, using:

find -type f |  # list all regular files
  grep -E '\.(h|cpp|mm)$' |  # filter for source files
  grep -v '/mt_' |  # filter out generated files
  grep -v '/vendor/' | # and vendored GL
  grep -v '/test/image_loader_test.cpp' |  # and this file (has giant literals arrays)
  xargs -n 1 -P $(nproc) clang-format -i  # reformat everything

Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
Desour
2024-03-20 19:35:52 +01:00
parent eb4dec46c2
commit 2bf1d12353
292 changed files with 37376 additions and 42421 deletions

View File

@ -22,18 +22,18 @@ namespace gui
// ------------------------------------------------------------------
//! constructor
CGUITab::CGUITab(IGUIEnvironment* environment,
IGUIElement* parent, const core::rect<s32>& rectangle,
s32 id)
: IGUITab(environment, parent, id, rectangle),
BackColor(0,0,0,0), OverrideTextColorEnabled(false), TextColor(255,0,0,0),
CGUITab::CGUITab(IGUIEnvironment *environment,
IGUIElement *parent, const core::rect<s32> &rectangle,
s32 id) :
IGUITab(environment, parent, id, rectangle),
BackColor(0, 0, 0, 0), OverrideTextColorEnabled(false), TextColor(255, 0, 0, 0),
DrawBackground(false)
{
#ifdef _DEBUG
#ifdef _DEBUG
setDebugName("CGUITab");
#endif
#endif
const IGUISkin* const skin = environment->getSkin();
const IGUISkin *const skin = environment->getSkin();
if (skin)
TextColor = skin->getColor(EGDC_BUTTON_TEXT);
}
@ -52,21 +52,18 @@ void CGUITab::draw()
IGUIElement::draw();
}
//! sets if the tab should draw its background
void CGUITab::setDrawBackground(bool draw)
{
DrawBackground = draw;
}
//! sets the color of the background, if it should be drawn.
void CGUITab::setBackgroundColor(video::SColor c)
{
BackColor = c;
}
//! sets the color of the text
void CGUITab::setTextColor(video::SColor c)
{
@ -74,10 +71,9 @@ void CGUITab::setTextColor(video::SColor c)
TextColor = c;
}
video::SColor CGUITab::getTextColor() const
{
if ( OverrideTextColorEnabled )
if (OverrideTextColorEnabled)
return TextColor;
else
return Environment->getSkin()->getColor(EGDC_BUTTON_TEXT);
@ -89,45 +85,42 @@ bool CGUITab::isDrawingBackground() const
return DrawBackground;
}
//! returns the color of the background
video::SColor CGUITab::getBackgroundColor() const
{
return BackColor;
}
// ------------------------------------------------------------------
// Tabcontrol
// ------------------------------------------------------------------
//! constructor
CGUITabControl::CGUITabControl(IGUIEnvironment* environment,
IGUIElement* parent, const core::rect<s32>& rectangle,
bool fillbackground, bool border, s32 id)
: IGUITabControl(environment, parent, id, rectangle), ActiveTabIndex(-1),
Border(border), FillBackground(fillbackground), ScrollControl(false), TabHeight(0), VerticalAlignment(EGUIA_UPPERLEFT),
UpButton(0), DownButton(0), TabMaxWidth(0), CurrentScrollTabIndex(0), TabExtraWidth(20)
CGUITabControl::CGUITabControl(IGUIEnvironment *environment,
IGUIElement *parent, const core::rect<s32> &rectangle,
bool fillbackground, bool border, s32 id) :
IGUITabControl(environment, parent, id, rectangle),
ActiveTabIndex(-1),
Border(border), FillBackground(fillbackground), ScrollControl(false), TabHeight(0), VerticalAlignment(EGUIA_UPPERLEFT),
UpButton(0), DownButton(0), TabMaxWidth(0), CurrentScrollTabIndex(0), TabExtraWidth(20)
{
#ifdef _DEBUG
#ifdef _DEBUG
setDebugName("CGUITabControl");
#endif
#endif
IGUISkin* skin = Environment->getSkin();
IGUISpriteBank* sprites = 0;
IGUISkin *skin = Environment->getSkin();
IGUISpriteBank *sprites = 0;
TabHeight = 32;
if (skin)
{
if (skin) {
sprites = skin->getSpriteBank();
TabHeight = skin->getSize(gui::EGDS_BUTTON_HEIGHT) + 2;
}
UpButton = Environment->addButton(core::rect<s32>(0,0,10,10), this);
UpButton = Environment->addButton(core::rect<s32>(0, 0, 10, 10), this);
if (UpButton)
{
if (UpButton) {
UpButton->setSpriteBank(sprites);
UpButton->setVisible(false);
UpButton->setSubElement(true);
@ -136,10 +129,9 @@ CGUITabControl::CGUITabControl(IGUIEnvironment* environment,
UpButton->grab();
}
DownButton = Environment->addButton(core::rect<s32>(0,0,10,10), this);
DownButton = Environment->addButton(core::rect<s32>(0, 0, 10, 10), this);
if (DownButton)
{
if (DownButton) {
DownButton->setSpriteBank(sprites);
DownButton->setVisible(false);
DownButton->setSubElement(true);
@ -155,8 +147,7 @@ CGUITabControl::CGUITabControl(IGUIEnvironment* environment,
//! destructor
CGUITabControl::~CGUITabControl()
{
for (u32 i=0; i<Tabs.size(); ++i)
{
for (u32 i = 0; i < Tabs.size(); ++i) {
if (Tabs[i])
Tabs[i]->drop();
}
@ -170,20 +161,17 @@ CGUITabControl::~CGUITabControl()
void CGUITabControl::refreshSprites()
{
video::SColor color(255,255,255,255);
IGUISkin* skin = Environment->getSkin();
if (skin)
{
video::SColor color(255, 255, 255, 255);
IGUISkin *skin = Environment->getSkin();
if (skin) {
color = skin->getColor(isEnabled() ? EGDC_WINDOW_SYMBOL : EGDC_GRAY_WINDOW_SYMBOL);
if (UpButton)
{
if (UpButton) {
UpButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_LEFT), color);
UpButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_LEFT), color);
}
if (DownButton)
{
if (DownButton) {
DownButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_RIGHT), color);
DownButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_RIGHT), color);
}
@ -191,18 +179,17 @@ void CGUITabControl::refreshSprites()
}
//! Adds a tab
IGUITab* CGUITabControl::addTab(const wchar_t* caption, s32 id)
IGUITab *CGUITabControl::addTab(const wchar_t *caption, s32 id)
{
CGUITab* tab = new CGUITab(Environment, this, calcTabPos(), id);
CGUITab *tab = new CGUITab(Environment, this, calcTabPos(), id);
tab->setText(caption);
tab->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
tab->setVisible(false);
Tabs.push_back(tab); // no grab as new already creates a reference
Tabs.push_back(tab); // no grab as new already creates a reference
if (ActiveTabIndex == -1)
{
ActiveTabIndex = Tabs.size()-1;
if (ActiveTabIndex == -1) {
ActiveTabIndex = Tabs.size() - 1;
tab->setVisible(true);
}
@ -211,33 +198,29 @@ IGUITab* CGUITabControl::addTab(const wchar_t* caption, s32 id)
return tab;
}
//! adds a tab which has been created elsewhere
s32 CGUITabControl::addTab(IGUITab* tab)
s32 CGUITabControl::addTab(IGUITab *tab)
{
return insertTab( Tabs.size(), tab, false);
return insertTab(Tabs.size(), tab, false);
}
//! Insert the tab at the given index
IGUITab* CGUITabControl::insertTab(s32 idx, const wchar_t* caption, s32 id)
IGUITab *CGUITabControl::insertTab(s32 idx, const wchar_t *caption, s32 id)
{
if ( idx < 0 || idx > (s32)Tabs.size() ) // idx == Tabs.size() is indeed OK here as core::array can handle that
if (idx < 0 || idx > (s32)Tabs.size()) // idx == Tabs.size() is indeed OK here as core::array can handle that
return NULL;
CGUITab* tab = new CGUITab(Environment, this, calcTabPos(), id);
CGUITab *tab = new CGUITab(Environment, this, calcTabPos(), id);
tab->setText(caption);
tab->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
tab->setVisible(false);
Tabs.insert(tab, (u32)idx);
if (ActiveTabIndex == -1)
{
if (ActiveTabIndex == -1) {
ActiveTabIndex = (u32)idx;
tab->setVisible(true);
}
else if ( idx <= ActiveTabIndex )
{
} else if (idx <= ActiveTabIndex) {
++ActiveTabIndex;
setVisibleTab(ActiveTabIndex);
}
@ -247,51 +230,44 @@ IGUITab* CGUITabControl::insertTab(s32 idx, const wchar_t* caption, s32 id)
return tab;
}
s32 CGUITabControl::insertTab(s32 idx, IGUITab* tab, bool serializationMode)
s32 CGUITabControl::insertTab(s32 idx, IGUITab *tab, bool serializationMode)
{
if (!tab)
return -1;
if ( idx > (s32)Tabs.size() && !serializationMode ) // idx == Tabs.size() is indeed OK here as core::array can handle that
if (idx > (s32)Tabs.size() && !serializationMode) // idx == Tabs.size() is indeed OK here as core::array can handle that
return -1;
// Not allowing to add same tab twice as it would make things complicated (serialization or setting active visible)
if ( getTabIndex(tab) >= 0 )
if (getTabIndex(tab) >= 0)
return -1;
if ( idx < 0 )
if (idx < 0)
idx = (s32)Tabs.size();
if ( tab->getParent() != this )
if (tab->getParent() != this)
this->addChildToEnd(tab);
tab->setVisible(false);
tab->grab();
if ( serializationMode)
{
while ( idx >= (s32)Tabs.size() )
{
if (serializationMode) {
while (idx >= (s32)Tabs.size()) {
Tabs.push_back(0);
}
Tabs[idx] = tab;
if ( idx == ActiveTabIndex) // in serialization that can happen for any index
if (idx == ActiveTabIndex) // in serialization that can happen for any index
{
setVisibleTab(ActiveTabIndex);
tab->setVisible(true);
}
}
else
{
} else {
Tabs.insert(tab, (u32)idx);
if (ActiveTabIndex == -1)
{
if (ActiveTabIndex == -1) {
ActiveTabIndex = idx;
setVisibleTab(ActiveTabIndex);
}
else if ( idx <= ActiveTabIndex)
{
} else if (idx <= ActiveTabIndex) {
++ActiveTabIndex;
setVisibleTab(ActiveTabIndex);
}
@ -303,10 +279,10 @@ s32 CGUITabControl::insertTab(s32 idx, IGUITab* tab, bool serializationMode)
}
//! Removes a child.
void CGUITabControl::removeChild(IGUIElement* child)
void CGUITabControl::removeChild(IGUIElement *child)
{
s32 idx = getTabIndex(child);
if ( idx >= 0 )
if (idx >= 0)
removeTabButNotChild(idx);
// remove real element
@ -315,11 +291,10 @@ void CGUITabControl::removeChild(IGUIElement* child)
recalculateScrollBar();
}
//! Removes a tab from the tabcontrol
void CGUITabControl::removeTab(s32 idx)
{
if ( idx < 0 || idx >= (s32)Tabs.size() )
if (idx < 0 || idx >= (s32)Tabs.size())
return;
removeChild(Tabs[(u32)idx]);
@ -327,20 +302,17 @@ void CGUITabControl::removeTab(s32 idx)
void CGUITabControl::removeTabButNotChild(s32 idx)
{
if ( idx < 0 || idx >= (s32)Tabs.size() )
if (idx < 0 || idx >= (s32)Tabs.size())
return;
Tabs[(u32)idx]->drop();
Tabs.erase((u32)idx);
if ( idx < ActiveTabIndex )
{
if (idx < ActiveTabIndex) {
--ActiveTabIndex;
setVisibleTab(ActiveTabIndex);
}
else if ( idx == ActiveTabIndex )
{
if ( (u32)idx == Tabs.size() )
} else if (idx == ActiveTabIndex) {
if ((u32)idx == Tabs.size())
--ActiveTabIndex;
setVisibleTab(ActiveTabIndex);
}
@ -349,10 +321,8 @@ void CGUITabControl::removeTabButNotChild(s32 idx)
//! Clears the tabcontrol removing all tabs
void CGUITabControl::clear()
{
for (u32 i=0; i<Tabs.size(); ++i)
{
if (Tabs[i])
{
for (u32 i = 0; i < Tabs.size(); ++i) {
if (Tabs[i]) {
IGUIElement::removeChild(Tabs[i]);
Tabs[i]->drop();
}
@ -368,9 +338,8 @@ s32 CGUITabControl::getTabCount() const
return Tabs.size();
}
//! Returns a tab based on zero based index
IGUITab* CGUITabControl::getTab(s32 idx) const
IGUITab *CGUITabControl::getTab(s32 idx) const
{
if (idx < 0 || (u32)idx >= Tabs.size())
return 0;
@ -378,45 +347,35 @@ IGUITab* CGUITabControl::getTab(s32 idx) const
return Tabs[idx];
}
//! called if an event happened.
bool CGUITabControl::OnEvent(const SEvent& event)
bool CGUITabControl::OnEvent(const SEvent &event)
{
if (isEnabled())
{
switch(event.EventType)
{
if (isEnabled()) {
switch (event.EventType) {
case EET_GUI_EVENT:
switch(event.GUIEvent.EventType)
{
switch (event.GUIEvent.EventType) {
case EGET_BUTTON_CLICKED:
if (event.GUIEvent.Caller == UpButton)
{
if (event.GUIEvent.Caller == UpButton) {
scrollLeft();
return true;
}
else if (event.GUIEvent.Caller == DownButton)
{
} else if (event.GUIEvent.Caller == DownButton) {
scrollRight();
return true;
}
break;
break;
default:
break;
break;
}
break;
case EET_MOUSE_INPUT_EVENT:
switch(event.MouseInput.Event)
{
//case EMIE_LMOUSE_PRESSED_DOWN:
switch (event.MouseInput.Event) {
// case EMIE_LMOUSE_PRESSED_DOWN:
// // todo: dragging tabs around
// return true;
case EMIE_LMOUSE_LEFT_UP:
{
case EMIE_LMOUSE_LEFT_UP: {
s32 idx = getTabAt(event.MouseInput.X, event.MouseInput.Y);
if ( idx >= 0 )
{
if (idx >= 0) {
setActiveTab(idx);
return true;
}
@ -434,32 +393,29 @@ bool CGUITabControl::OnEvent(const SEvent& event)
return IGUIElement::OnEvent(event);
}
void CGUITabControl::scrollLeft()
{
if ( CurrentScrollTabIndex > 0 )
if (CurrentScrollTabIndex > 0)
--CurrentScrollTabIndex;
recalculateScrollBar();
}
void CGUITabControl::scrollRight()
{
if ( CurrentScrollTabIndex < (s32)(Tabs.size()) - 1 )
{
if ( needScrollControl(CurrentScrollTabIndex, true) )
if (CurrentScrollTabIndex < (s32)(Tabs.size()) - 1) {
if (needScrollControl(CurrentScrollTabIndex, true))
++CurrentScrollTabIndex;
}
recalculateScrollBar();
}
s32 CGUITabControl::calcTabWidth(IGUIFont* font, const wchar_t* text) const
s32 CGUITabControl::calcTabWidth(IGUIFont *font, const wchar_t *text) const
{
if ( !font )
if (!font)
return 0;
s32 len = font->getDimension(text).Width + TabExtraWidth;
if ( TabMaxWidth > 0 && len > TabMaxWidth )
if (TabMaxWidth > 0 && len > TabMaxWidth)
len = TabMaxWidth;
return len;
@ -467,14 +423,14 @@ s32 CGUITabControl::calcTabWidth(IGUIFont* font, const wchar_t* text) const
bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl, s32 *pos_rightmost)
{
if ( startIndex < 0 )
if (startIndex < 0)
startIndex = 0;
IGUISkin* skin = Environment->getSkin();
IGUISkin *skin = Environment->getSkin();
if (!skin)
return false;
IGUIFont* font = skin->getFont();
IGUIFont *font = skin->getFont();
if (Tabs.empty())
return false;
@ -483,20 +439,16 @@ bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl, s
return false;
s32 pos = AbsoluteRect.UpperLeftCorner.X + 2;
const s32 pos_right = withScrollControl ?
UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 :
AbsoluteRect.LowerRightCorner.X;
const s32 pos_right = withScrollControl ? UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 : AbsoluteRect.LowerRightCorner.X;
for (s32 i = startIndex; i < (s32)Tabs.size(); ++i)
{
for (s32 i = startIndex; i < (s32)Tabs.size(); ++i) {
// get Text
const wchar_t* text = 0;
if (Tabs[i])
{
const wchar_t *text = 0;
if (Tabs[i]) {
text = Tabs[i]->getText();
// get text length
s32 len = calcTabWidth(font, text); // always without withScrollControl here or len would be shortened
s32 len = calcTabWidth(font, text); // always without withScrollControl here or len would be shortened
pos += len;
}
@ -509,7 +461,6 @@ bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl, s
return false;
}
s32 CGUITabControl::calculateScrollIndexFromActive()
{
if (!ScrollControl || Tabs.empty())
@ -566,27 +517,21 @@ core::rect<s32> CGUITabControl::calcTabPos()
core::rect<s32> r;
r.UpperLeftCorner.X = 0;
r.LowerRightCorner.X = AbsoluteRect.getWidth();
if ( Border )
{
if (Border) {
++r.UpperLeftCorner.X;
--r.LowerRightCorner.X;
}
if ( VerticalAlignment == EGUIA_UPPERLEFT )
{
r.UpperLeftCorner.Y = TabHeight+2;
r.LowerRightCorner.Y = AbsoluteRect.getHeight()-1;
if ( Border )
{
if (VerticalAlignment == EGUIA_UPPERLEFT) {
r.UpperLeftCorner.Y = TabHeight + 2;
r.LowerRightCorner.Y = AbsoluteRect.getHeight() - 1;
if (Border) {
--r.LowerRightCorner.Y;
}
}
else
{
} else {
r.UpperLeftCorner.Y = 0;
r.LowerRightCorner.Y = AbsoluteRect.getHeight()-(TabHeight+2);
if ( Border )
{
r.LowerRightCorner.Y = AbsoluteRect.getHeight() - (TabHeight + 2);
if (Border) {
++r.UpperLeftCorner.Y;
}
}
@ -594,19 +539,18 @@ core::rect<s32> CGUITabControl::calcTabPos()
return r;
}
//! draws the element and its children
void CGUITabControl::draw()
{
if (!IsVisible)
return;
IGUISkin* skin = Environment->getSkin();
IGUISkin *skin = Environment->getSkin();
if (!skin)
return;
IGUIFont* font = skin->getFont();
video::IVideoDriver* driver = Environment->getVideoDriver();
IGUIFont *font = skin->getFont();
video::IVideoDriver *driver = Environment->getVideoDriver();
core::rect<s32> frameRect(AbsoluteRect);
@ -618,13 +562,10 @@ void CGUITabControl::draw()
return;
// tab button bar can be above or below the tabs
if ( VerticalAlignment == EGUIA_UPPERLEFT )
{
if (VerticalAlignment == EGUIA_UPPERLEFT) {
frameRect.UpperLeftCorner.Y += 2;
frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight;
}
else
{
} else {
frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight - 1;
frameRect.LowerRightCorner.Y -= 2;
}
@ -639,14 +580,13 @@ void CGUITabControl::draw()
s32 left = 0;
s32 right = 0;
//const wchar_t* activetext = 0;
// const wchar_t* activetext = 0;
IGUITab *activeTab = 0;
// Draw all tab-buttons except the active one
for (u32 i = CurrentScrollTabIndex; i < Tabs.size() && !needRightScroll; ++i)
{
for (u32 i = CurrentScrollTabIndex; i < Tabs.size() && !needRightScroll; ++i) {
// get Text
const wchar_t* text = 0;
const wchar_t *text = 0;
if (Tabs[i])
text = Tabs[i]->getText();
@ -666,44 +606,39 @@ void CGUITabControl::draw()
pos += len;
if ((s32)i == ActiveTabIndex)
{
if ((s32)i == ActiveTabIndex) {
// for active button just remember values
left = frameRect.UpperLeftCorner.X;
right = frameRect.LowerRightCorner.X;
//activetext = text;
// activetext = text;
activeTab = Tabs[i];
}
else
{
} else {
skin->draw3DTabButton(this, false, frameRect, &AbsoluteClippingRect, VerticalAlignment);
// draw text
core::rect<s32> textClipRect(frameRect); // TODO: exact size depends on borders in draw3DTabButton which we don't get with current interface
core::rect<s32> textClipRect(frameRect); // TODO: exact size depends on borders in draw3DTabButton which we don't get with current interface
textClipRect.clipAgainst(AbsoluteClippingRect);
font->draw(text, frameRect, Tabs[i]->getTextColor(),
true, true, &textClipRect);
true, true, &textClipRect);
}
}
// Draw active tab button
// Drawn later than other buttons because it draw over the buttons before/after it.
if (left != 0 && right != 0 && activeTab != 0)
{
if (left != 0 && right != 0 && activeTab != 0) {
// draw upper highlight frame
if ( VerticalAlignment == EGUIA_UPPERLEFT )
{
frameRect.UpperLeftCorner.X = left-2;
frameRect.LowerRightCorner.X = right+2;
if (VerticalAlignment == EGUIA_UPPERLEFT) {
frameRect.UpperLeftCorner.X = left - 2;
frameRect.LowerRightCorner.X = right + 2;
frameRect.UpperLeftCorner.Y -= 2;
skin->draw3DTabButton(this, true, frameRect, &AbsoluteClippingRect, VerticalAlignment);
// draw text
core::rect<s32> textClipRect(frameRect); // TODO: exact size depends on borders in draw3DTabButton which we don't get with current interface
core::rect<s32> textClipRect(frameRect); // TODO: exact size depends on borders in draw3DTabButton which we don't get with current interface
textClipRect.clipAgainst(AbsoluteClippingRect);
font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(),
true, true, &textClipRect);
true, true, &textClipRect);
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
tr.LowerRightCorner.X = left - 1;
@ -714,18 +649,16 @@ void CGUITabControl::draw()
tr.UpperLeftCorner.X = right;
tr.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X;
driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), tr, &AbsoluteClippingRect);
}
else
{
frameRect.UpperLeftCorner.X = left-2;
frameRect.LowerRightCorner.X = right+2;
} else {
frameRect.UpperLeftCorner.X = left - 2;
frameRect.LowerRightCorner.X = right + 2;
frameRect.LowerRightCorner.Y += 2;
skin->draw3DTabButton(this, true, frameRect, &AbsoluteClippingRect, VerticalAlignment);
// draw text
font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(),
true, true, &frameRect);
true, true, &frameRect);
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
tr.LowerRightCorner.X = left - 1;
@ -737,9 +670,7 @@ void CGUITabControl::draw()
tr.LowerRightCorner.X = AbsoluteRect.LowerRightCorner.X;
driver->draw2DRectangle(skin->getColor(EGDC_3D_DARK_SHADOW), tr, &AbsoluteClippingRect);
}
}
else
{
} else {
// No active tab
// Draw a line separating button bar from tab area
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
@ -747,12 +678,9 @@ void CGUITabControl::draw()
tr.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - 1;
tr.LowerRightCorner.Y = frameRect.LowerRightCorner.Y;
if ( VerticalAlignment == EGUIA_UPPERLEFT )
{
if (VerticalAlignment == EGUIA_UPPERLEFT) {
driver->draw2DRectangle(skin->getColor(EGDC_3D_HIGH_LIGHT), tr, &AbsoluteClippingRect);
}
else
{
} else {
tr.UpperLeftCorner.Y = frameRect.UpperLeftCorner.Y - 1;
tr.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y;
driver->draw2DRectangle(skin->getColor(EGDC_3D_DARK_SHADOW), tr, &AbsoluteClippingRect);
@ -763,20 +691,19 @@ void CGUITabControl::draw()
skin->draw3DTabBody(this, Border, FillBackground, AbsoluteRect, &AbsoluteClippingRect, TabHeight, VerticalAlignment);
// enable scrollcontrols on need
if ( UpButton )
if (UpButton)
UpButton->setEnabled(needLeftScroll);
if ( DownButton )
if (DownButton)
DownButton->setEnabled(needRightScroll);
refreshSprites();
IGUIElement::draw();
}
//! Set the height of the tabs
void CGUITabControl::setTabHeight( s32 height )
void CGUITabControl::setTabHeight(s32 height)
{
if ( height < 0 )
if (height < 0)
height = 0;
TabHeight = height;
@ -785,7 +712,6 @@ void CGUITabControl::setTabHeight( s32 height )
recalculateScrollBar();
}
//! Get the height of the tabs
s32 CGUITabControl::getTabHeight() const
{
@ -793,7 +719,7 @@ s32 CGUITabControl::getTabHeight() const
}
//! set the maximal width of a tab. Per default width is 0 which means "no width restriction".
void CGUITabControl::setTabMaxWidth(s32 width )
void CGUITabControl::setTabMaxWidth(s32 width)
{
TabMaxWidth = width;
}
@ -804,11 +730,10 @@ s32 CGUITabControl::getTabMaxWidth() const
return TabMaxWidth;
}
//! Set the extra width added to tabs on each side of the text
void CGUITabControl::setTabExtraWidth( s32 extraWidth )
void CGUITabControl::setTabExtraWidth(s32 extraWidth)
{
if ( extraWidth < 0 )
if (extraWidth < 0)
extraWidth = 0;
TabExtraWidth = extraWidth;
@ -816,14 +741,12 @@ void CGUITabControl::setTabExtraWidth( s32 extraWidth )
recalculateScrollBar();
}
//! Get the extra width added to tabs on each side of the text
s32 CGUITabControl::getTabExtraWidth() const
{
return TabExtraWidth;
}
void CGUITabControl::recalculateScrollBar()
{
// Down: to right, Up: to left
@ -832,23 +755,20 @@ void CGUITabControl::recalculateScrollBar()
ScrollControl = needScrollControl() || CurrentScrollTabIndex > 0;
if (ScrollControl)
{
UpButton->setVisible( true );
DownButton->setVisible( true );
}
else
{
UpButton->setVisible( false );
DownButton->setVisible( false );
if (ScrollControl) {
UpButton->setVisible(true);
DownButton->setVisible(true);
} else {
UpButton->setVisible(false);
DownButton->setVisible(false);
}
bringToFront( UpButton );
bringToFront( DownButton );
bringToFront(UpButton);
bringToFront(DownButton);
}
//! Set the alignment of the tabs
void CGUITabControl::setTabVerticalAlignment( EGUI_ALIGNMENT alignment )
void CGUITabControl::setTabVerticalAlignment(EGUI_ALIGNMENT alignment)
{
VerticalAlignment = alignment;
@ -856,45 +776,40 @@ void CGUITabControl::setTabVerticalAlignment( EGUI_ALIGNMENT alignment )
recalculateScrollBar();
core::rect<s32> r(calcTabPos());
for ( u32 i=0; i<Tabs.size(); ++i )
{
for (u32 i = 0; i < Tabs.size(); ++i) {
Tabs[i]->setRelativePosition(r);
}
}
void CGUITabControl::recalculateScrollButtonPlacement()
{
IGUISkin* skin = Environment->getSkin();
IGUISkin *skin = Environment->getSkin();
s32 ButtonSize = 16;
s32 ButtonHeight = TabHeight - 2;
if ( ButtonHeight < 0 )
if (ButtonHeight < 0)
ButtonHeight = TabHeight;
if (skin)
{
if (skin) {
ButtonSize = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH);
if (ButtonSize > TabHeight)
ButtonSize = TabHeight;
}
s32 ButtonX = RelativeRect.getWidth() - (s32)(2.5f*(f32)ButtonSize) - 1;
s32 ButtonX = RelativeRect.getWidth() - (s32)(2.5f * (f32)ButtonSize) - 1;
s32 ButtonY = 0;
if (VerticalAlignment == EGUIA_UPPERLEFT)
{
if (VerticalAlignment == EGUIA_UPPERLEFT) {
ButtonY = 2 + (TabHeight / 2) - (ButtonHeight / 2);
UpButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
}
else
{
} else {
ButtonY = RelativeRect.getHeight() - (TabHeight / 2) - (ButtonHeight / 2) - 2;
UpButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
DownButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
}
UpButton->setRelativePosition(core::rect<s32>(ButtonX, ButtonY, ButtonX+ButtonSize, ButtonY+ButtonHeight));
UpButton->setRelativePosition(core::rect<s32>(ButtonX, ButtonY, ButtonX + ButtonSize, ButtonY + ButtonHeight));
ButtonX += ButtonSize + 1;
DownButton->setRelativePosition(core::rect<s32>(ButtonX, ButtonY, ButtonX+ButtonSize, ButtonY+ButtonHeight));
DownButton->setRelativePosition(core::rect<s32>(ButtonX, ButtonY, ButtonX + ButtonSize, ButtonY + ButtonHeight));
}
//! Get the alignment of the tabs
@ -903,22 +818,18 @@ EGUI_ALIGNMENT CGUITabControl::getTabVerticalAlignment() const
return VerticalAlignment;
}
s32 CGUITabControl::getTabAt(s32 xpos, s32 ypos) const
{
core::position2di p(xpos, ypos);
IGUISkin* skin = Environment->getSkin();
IGUIFont* font = skin->getFont();
IGUISkin *skin = Environment->getSkin();
IGUIFont *font = skin->getFont();
core::rect<s32> frameRect(AbsoluteRect);
if ( VerticalAlignment == EGUIA_UPPERLEFT )
{
if (VerticalAlignment == EGUIA_UPPERLEFT) {
frameRect.UpperLeftCorner.Y += 2;
frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight;
}
else
{
} else {
frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight;
}
@ -928,10 +839,9 @@ s32 CGUITabControl::getTabAt(s32 xpos, s32 ypos) const
return -1;
bool abort = false;
for (s32 i = CurrentScrollTabIndex; i < (s32)Tabs.size() && !abort; ++i)
{
for (s32 i = CurrentScrollTabIndex; i < (s32)Tabs.size() && !abort; ++i) {
// get Text
const wchar_t* text = 0;
const wchar_t *text = 0;
if (Tabs[i])
text = Tabs[i]->getText();
@ -951,11 +861,9 @@ s32 CGUITabControl::getTabAt(s32 xpos, s32 ypos) const
pos += len;
if (frameRect.isPointInside(p))
{
if (frameRect.isPointInside(p)) {
return i;
}
}
return -1;
}
@ -966,7 +874,6 @@ s32 CGUITabControl::getActiveTab() const
return ActiveTabIndex;
}
//! Brings a tab to front.
bool CGUITabControl::setActiveTab(s32 idx)
{
@ -979,8 +886,7 @@ bool CGUITabControl::setActiveTab(s32 idx)
setVisibleTab(ActiveTabIndex);
if (changed && Parent)
{
if (changed && Parent) {
SEvent event;
event.EventType = EET_GUI_EVENT;
event.GUIEvent.Caller = this;
@ -999,12 +905,11 @@ bool CGUITabControl::setActiveTab(s32 idx)
void CGUITabControl::setVisibleTab(s32 idx)
{
for (u32 i=0; i<Tabs.size(); ++i)
for (u32 i = 0; i < Tabs.size(); ++i)
if (Tabs[i])
Tabs[i]->setVisible( (s32)i == idx );
Tabs[i]->setVisible((s32)i == idx);
}
bool CGUITabControl::setActiveTab(IGUITab *tab)
{
return setActiveTab(getTabIndex(tab));
@ -1012,7 +917,7 @@ bool CGUITabControl::setActiveTab(IGUITab *tab)
s32 CGUITabControl::getTabIndex(const IGUIElement *tab) const
{
for (u32 i=0; i<Tabs.size(); ++i)
for (u32 i = 0; i < Tabs.size(); ++i)
if (Tabs[i] == tab)
return (s32)i;
@ -1026,6 +931,5 @@ void CGUITabControl::updateAbsolutePosition()
recalculateScrollBar();
}
} // end namespace irr
} // end namespace gui