Fix scrolling controls in CGUITabControl (backport from 1.6 branch)
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2637 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
be8a1ff7b6
commit
6361391247
|
@ -1,5 +1,7 @@
|
||||||
Changes in 1.6 (??.??.2009)
|
Changes in 1.6 (??.??.2009)
|
||||||
|
|
||||||
|
- Fix scrolling controls in CGUITabControl
|
||||||
|
|
||||||
- Fix a bug when getting optimal texture size in D3D drivers, by Jetro Lauha (tonic)
|
- Fix a bug when getting optimal texture size in D3D drivers, by Jetro Lauha (tonic)
|
||||||
|
|
||||||
- Added EGDS_TITLEBARTEXT_DISTANCE_X and EGDS_TITLEBARTEXT_DISTANCE_Y to GUI, submitted by FuzzYspo0N
|
- Added EGDS_TITLEBARTEXT_DISTANCE_X and EGDS_TITLEBARTEXT_DISTANCE_Y to GUI, submitted by FuzzYspo0N
|
||||||
|
|
|
@ -171,6 +171,7 @@ CGUITabControl::CGUITabControl(IGUIEnvironment* environment,
|
||||||
sprites = skin->getSpriteBank();
|
sprites = skin->getSpriteBank();
|
||||||
color = skin->getColor(EGDC_WINDOW_SYMBOL);
|
color = skin->getColor(EGDC_WINDOW_SYMBOL);
|
||||||
TabHeight = skin->getSize(gui::EGDS_BUTTON_HEIGHT) + 2;
|
TabHeight = skin->getSize(gui::EGDS_BUTTON_HEIGHT) + 2;
|
||||||
|
TabMaxWidth = 3 * TabHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpButton = Environment->addButton(core::rect<s32>(0,0,10,10), this);
|
UpButton = Environment->addButton(core::rect<s32>(0,0,10,10), this);
|
||||||
|
@ -391,6 +392,29 @@ void CGUITabControl::scrollRight()
|
||||||
recalculateScrollBar();
|
recalculateScrollBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s32 CGUITabControl::calcTabWidth(s32 pos, IGUIFont* font, const wchar_t* text, bool withScrollControl)
|
||||||
|
{
|
||||||
|
if ( !font )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
s32 len = font->getDimension(text).Width + TabExtraWidth;
|
||||||
|
if ( TabMaxWidth > 0 && len > TabMaxWidth )
|
||||||
|
len = TabMaxWidth;
|
||||||
|
|
||||||
|
// check if we miss the place to draw the tab-button
|
||||||
|
if ( withScrollControl && ScrollControl && pos+len > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
|
||||||
|
{
|
||||||
|
s32 tabMinWidth = font->getDimension(L"A").Width;
|
||||||
|
if ( TabExtraWidth > 0 && TabExtraWidth > tabMinWidth )
|
||||||
|
tabMinWidth = TabExtraWidth;
|
||||||
|
|
||||||
|
if ( ScrollControl && pos+tabMinWidth <= UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
|
||||||
|
{
|
||||||
|
len = UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 - pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl)
|
bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl)
|
||||||
{
|
{
|
||||||
|
@ -424,7 +448,7 @@ bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl)
|
||||||
text = Tabs[i]->getText();
|
text = Tabs[i]->getText();
|
||||||
|
|
||||||
// get text length
|
// get text length
|
||||||
s32 len = font->getDimension(text).Width + TabExtraWidth;
|
s32 len = calcTabWidth(pos, font, text, false); // always without withScrollControl here or len would be shortened
|
||||||
|
|
||||||
frameRect.LowerRightCorner.X += len;
|
frameRect.LowerRightCorner.X += len;
|
||||||
|
|
||||||
|
@ -432,7 +456,7 @@ bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl)
|
||||||
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
|
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
|
||||||
pos += len;
|
pos += len;
|
||||||
|
|
||||||
if ( withScrollControl && pos > AbsoluteRect.LowerRightCorner.X - TabMaxWidth)
|
if ( withScrollControl && pos > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( !withScrollControl && pos > AbsoluteRect.LowerRightCorner.X )
|
if ( !withScrollControl && pos > AbsoluteRect.LowerRightCorner.X )
|
||||||
|
@ -473,13 +497,13 @@ bool CGUITabControl::selectTab(core::position2d<s32> p)
|
||||||
text = Tabs[i]->getText();
|
text = Tabs[i]->getText();
|
||||||
|
|
||||||
// get text length
|
// get text length
|
||||||
s32 len = font->getDimension(text).Width + TabExtraWidth;
|
s32 len = calcTabWidth(pos, font, text, true);
|
||||||
|
if ( ScrollControl && pos+len > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
|
||||||
|
return false;
|
||||||
|
|
||||||
frameRect.UpperLeftCorner.X = pos;
|
frameRect.UpperLeftCorner.X = pos;
|
||||||
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
|
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
|
||||||
|
|
||||||
if ( ScrollControl && pos > AbsoluteRect.LowerRightCorner.X)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
pos += len;
|
pos += len;
|
||||||
|
|
||||||
if (frameRect.isPointInside(p))
|
if (frameRect.isPointInside(p))
|
||||||
|
@ -527,6 +551,9 @@ void CGUITabControl::draw()
|
||||||
core::rect<s32> tr;
|
core::rect<s32> tr;
|
||||||
s32 pos = frameRect.UpperLeftCorner.X + 2;
|
s32 pos = frameRect.UpperLeftCorner.X + 2;
|
||||||
|
|
||||||
|
bool needLeftScroll = CurrentScrollTabIndex > 0;
|
||||||
|
bool needRightScroll = false;
|
||||||
|
|
||||||
// left and right pos of the active tab
|
// left and right pos of the active tab
|
||||||
s32 left = 0;
|
s32 left = 0;
|
||||||
s32 right = 0;
|
s32 right = 0;
|
||||||
|
@ -534,7 +561,7 @@ void CGUITabControl::draw()
|
||||||
//const wchar_t* activetext = 0;
|
//const wchar_t* activetext = 0;
|
||||||
CGUITab *activeTab = 0;
|
CGUITab *activeTab = 0;
|
||||||
|
|
||||||
for (u32 i=0; i<Tabs.size(); ++i)
|
for (u32 i=CurrentScrollTabIndex; i<Tabs.size(); ++i)
|
||||||
{
|
{
|
||||||
// get Text
|
// get Text
|
||||||
const wchar_t* text = 0;
|
const wchar_t* text = 0;
|
||||||
|
@ -542,16 +569,17 @@ void CGUITabControl::draw()
|
||||||
text = Tabs[i]->getText();
|
text = Tabs[i]->getText();
|
||||||
|
|
||||||
// get text length
|
// get text length
|
||||||
s32 len = font->getDimension(text).Width + TabExtraWidth;
|
s32 len = calcTabWidth(pos, font, text, true);
|
||||||
|
if ( ScrollControl && pos+len > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
|
||||||
|
{
|
||||||
|
needRightScroll = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
frameRect.LowerRightCorner.X += len;
|
frameRect.LowerRightCorner.X += len;
|
||||||
|
|
||||||
frameRect.UpperLeftCorner.X = pos;
|
frameRect.UpperLeftCorner.X = pos;
|
||||||
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
|
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
|
||||||
|
|
||||||
if ( ScrollControl && pos > frameRect.LowerRightCorner.X )
|
|
||||||
break;
|
|
||||||
|
|
||||||
pos += len;
|
pos += len;
|
||||||
|
|
||||||
if ((s32)i == ActiveTab)
|
if ((s32)i == ActiveTab)
|
||||||
|
@ -567,7 +595,7 @@ void CGUITabControl::draw()
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
font->draw(text, frameRect, Tabs[i]->getTextColor(),
|
font->draw(text, frameRect, Tabs[i]->getTextColor(),
|
||||||
true, true, &AbsoluteClippingRect);
|
true, true, &frameRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,7 +613,7 @@ void CGUITabControl::draw()
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(),
|
font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(),
|
||||||
true, true, &AbsoluteClippingRect);
|
true, true, &frameRect);
|
||||||
|
|
||||||
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
|
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
|
||||||
tr.LowerRightCorner.X = left - 1;
|
tr.LowerRightCorner.X = left - 1;
|
||||||
|
@ -608,7 +636,7 @@ void CGUITabControl::draw()
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(),
|
font->draw(activeTab->getText(), frameRect, activeTab->getTextColor(),
|
||||||
true, true, &AbsoluteClippingRect);
|
true, true, &frameRect);
|
||||||
|
|
||||||
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
|
tr.UpperLeftCorner.X = AbsoluteRect.UpperLeftCorner.X;
|
||||||
tr.LowerRightCorner.X = left - 1;
|
tr.LowerRightCorner.X = left - 1;
|
||||||
|
@ -642,6 +670,12 @@ void CGUITabControl::draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
skin->draw3DTabBody(this, Border, FillBackground, AbsoluteRect, &AbsoluteClippingRect, TabHeight, VerticalAlignment);
|
skin->draw3DTabBody(this, Border, FillBackground, AbsoluteRect, &AbsoluteClippingRect, TabHeight, VerticalAlignment);
|
||||||
|
|
||||||
|
// enable scrollcontrols on need
|
||||||
|
if ( UpButton )
|
||||||
|
UpButton->setEnabled(needLeftScroll);
|
||||||
|
if ( DownButton )
|
||||||
|
DownButton->setEnabled(needRightScroll);
|
||||||
|
|
||||||
IGUIElement::draw();
|
IGUIElement::draw();
|
||||||
}
|
}
|
||||||
|
@ -655,8 +689,6 @@ void CGUITabControl::setTabHeight( s32 height )
|
||||||
|
|
||||||
TabHeight = height;
|
TabHeight = height;
|
||||||
|
|
||||||
TabMaxWidth = 2 * TabHeight;
|
|
||||||
|
|
||||||
recalculateScrollBar();
|
recalculateScrollBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -724,8 +756,7 @@ void CGUITabControl::setTabVerticalAlignment( EGUI_ALIGNMENT alignment )
|
||||||
ButtonSize = TabHeight;
|
ButtonSize = TabHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
TabMaxWidth = s32(f32(ButtonSize) * 2.5f);
|
s32 ButtonX = RelativeRect.getWidth() - (s32)(2.5f*(f32)ButtonSize) - 1;
|
||||||
s32 ButtonX = RelativeRect.getWidth() - TabMaxWidth - 1;
|
|
||||||
s32 ButtonY = 0;
|
s32 ButtonY = 0;
|
||||||
|
|
||||||
if (VerticalAlignment == EGUIA_UPPERLEFT)
|
if (VerticalAlignment == EGUIA_UPPERLEFT)
|
||||||
|
@ -851,6 +882,7 @@ void CGUITabControl::serializeAttributes(io::IAttributes* out, io::SAttributeRea
|
||||||
out->addBool("Border", Border);
|
out->addBool("Border", Border);
|
||||||
out->addBool("FillBackground", FillBackground);
|
out->addBool("FillBackground", FillBackground);
|
||||||
out->addInt ("TabHeight", TabHeight);
|
out->addInt ("TabHeight", TabHeight);
|
||||||
|
out->addInt ("TabMaxWidth", TabMaxWidth);
|
||||||
out->addEnum("TabVerticalAlignment", s32(VerticalAlignment), GUIAlignmentNames);
|
out->addEnum("TabVerticalAlignment", s32(VerticalAlignment), GUIAlignmentNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -864,6 +896,7 @@ void CGUITabControl::deserializeAttributes(io::IAttributes* in, io::SAttributeRe
|
||||||
ActiveTab = -1;
|
ActiveTab = -1;
|
||||||
|
|
||||||
setTabHeight(in->getAttributeAsInt("TabHeight"));
|
setTabHeight(in->getAttributeAsInt("TabHeight"));
|
||||||
|
TabMaxWidth = in->getAttributeAsInt("TabMaxWidth");
|
||||||
|
|
||||||
IGUITabControl::deserializeAttributes(in,options);
|
IGUITabControl::deserializeAttributes(in,options);
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,7 @@ namespace gui
|
||||||
void scrollLeft();
|
void scrollLeft();
|
||||||
void scrollRight();
|
void scrollRight();
|
||||||
bool needScrollControl( s32 startIndex=0, bool withScrollControl=false );
|
bool needScrollControl( s32 startIndex=0, bool withScrollControl=false );
|
||||||
|
s32 calcTabWidth(s32 pos, IGUIFont* font, const wchar_t* text, bool withScrollControl );
|
||||||
|
|
||||||
void recalculateScrollBar();
|
void recalculateScrollBar();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue