Commit 1869d1ec authored by cutealien's avatar cutealien

Added IGUITabControl::insertTab, IGUITabControl::removeTab,...

Added IGUITabControl::insertTab, IGUITabControl::removeTab, IGUITabControl::clear and IGUITabControl::getTabAt


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3773 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 30cf180d
Changes in 1.8 (??.??.2011) Changes in 1.8 (??.??.2011)
- Added IGUITabControl::insertTab, IGUITabControl::removeTab, IGUITabControl::clear and IGUITabControl::getTabAt
- Added IGUIListBox::getItemAt - Added IGUIListBox::getItemAt
- Added IGUITable::getColumnWidth - Added IGUITable::getColumnWidth
......
...@@ -23,8 +23,10 @@ namespace gui ...@@ -23,8 +23,10 @@ namespace gui
IGUITab(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) IGUITab(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: IGUIElement(EGUIET_TAB, environment, parent, id, rectangle) {} : IGUIElement(EGUIET_TAB, environment, parent, id, rectangle) {}
//! Returns number of tab if in tabcontrol. //! Returns zero based index of tab if in tabcontrol.
/** Can be accessed later IGUITabControl::getTab() by this number. */ /** Can be accessed later IGUITabControl::getTab() by this number.
Note that this number can change when other tabs are inserted or removed .
*/
virtual s32 getNumber() const = 0; virtual s32 getNumber() const = 0;
//! sets if the tab should draw its background //! sets if the tab should draw its background
...@@ -58,6 +60,16 @@ namespace gui ...@@ -58,6 +60,16 @@ namespace gui
//! Adds a tab //! Adds a tab
virtual IGUITab* addTab(const wchar_t* caption, s32 id=-1) = 0; virtual IGUITab* addTab(const wchar_t* caption, s32 id=-1) = 0;
//! Insert the tab at the given index
/** \return The tab on success or NULL on failure. */
virtual IGUITab* insertTab(s32 idx, const wchar_t* caption, s32 id=-1) = 0;
//! Removes a tab from the tabcontrol
virtual void removeTab(s32 idx) = 0;
//! Clears the tabcontrol removing all tabs
virtual void clear() = 0;
//! Returns amount of tabs in the tabcontrol //! Returns amount of tabs in the tabcontrol
virtual s32 getTabCount() const = 0; virtual s32 getTabCount() const = 0;
...@@ -80,6 +92,10 @@ namespace gui ...@@ -80,6 +92,10 @@ namespace gui
//! Returns which tab is currently active //! Returns which tab is currently active
virtual s32 getActiveTab() const = 0; virtual s32 getActiveTab() const = 0;
//! get the the id of the tab at the given absolute coordinates
/** \return The id of the tab or -1 when no tab is at those coordinates*/
virtual s32 getTabAt(s32 xpos, s32 ypos) const = 0;
//! Set the height of the tabs //! Set the height of the tabs
virtual void setTabHeight( s32 height ) = 0; virtual void setTabHeight( s32 height ) = 0;
......
...@@ -254,10 +254,6 @@ void CGUITabControl::refreshSprites() ...@@ -254,10 +254,6 @@ void CGUITabControl::refreshSprites()
//! Adds a tab //! Adds a tab
IGUITab* CGUITabControl::addTab(const wchar_t* caption, s32 id) IGUITab* CGUITabControl::addTab(const wchar_t* caption, s32 id)
{ {
IGUISkin* skin = Environment->getSkin();
if (!skin)
return 0;
CGUITab* tab = new CGUITab(Tabs.size(), Environment, this, calcTabPos(), id); CGUITab* tab = new CGUITab(Tabs.size(), Environment, this, calcTabPos(), id);
tab->setText(caption); tab->setText(caption);
...@@ -315,6 +311,59 @@ void CGUITabControl::addTab(CGUITab* tab) ...@@ -315,6 +311,59 @@ void CGUITabControl::addTab(CGUITab* tab)
} }
} }
//! Insert the tab at the given index
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
return NULL;
CGUITab* tab = new CGUITab(idx, 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 (ActiveTab == -1)
{
ActiveTab = 0;
tab->setVisible(true);
}
for ( u32 i=(u32)idx+1; i < Tabs.size(); ++i )
{
Tabs[i]->setNumber(i);
}
recalculateScrollBar();
return tab;
}
//! Removes a tab from the tabcontrol
void CGUITabControl::removeTab(s32 idx)
{
if ( idx < 0 || idx >= (s32)Tabs.size() )
return;
Tabs[(u32)idx]->drop();
Tabs.erase((u32)idx);
for ( u32 i=(u32)idx; i < Tabs.size(); ++i )
{
Tabs[i]->setNumber(i);
}
}
//! Clears the tabcontrol removing all tabs
void CGUITabControl::clear()
{
for (u32 i=0; i<Tabs.size(); ++i)
{
if (Tabs[i])
Tabs[i]->drop();
}
Tabs.clear();
}
//! Returns amount of tabs in the tabcontrol //! Returns amount of tabs in the tabcontrol
s32 CGUITabControl::getTabCount() const s32 CGUITabControl::getTabCount() const
...@@ -368,9 +417,15 @@ bool CGUITabControl::OnEvent(const SEvent& event) ...@@ -368,9 +417,15 @@ bool CGUITabControl::OnEvent(const SEvent& event)
// todo: dragging tabs around // todo: dragging tabs around
return true; return true;
case EMIE_LMOUSE_LEFT_UP: case EMIE_LMOUSE_LEFT_UP:
if (selectTab(core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y))) {
s32 idx = getTabAt(event.MouseInput.X, event.MouseInput.Y);
if ( idx >= 0 )
{
setActiveTab(idx);
return true; return true;
}
break; break;
}
default: default:
break; break;
} }
...@@ -402,7 +457,7 @@ void CGUITabControl::scrollRight() ...@@ -402,7 +457,7 @@ void CGUITabControl::scrollRight()
recalculateScrollBar(); recalculateScrollBar();
} }
s32 CGUITabControl::calcTabWidth(s32 pos, IGUIFont* font, const wchar_t* text, bool withScrollControl) s32 CGUITabControl::calcTabWidth(s32 pos, IGUIFont* font, const wchar_t* text, bool withScrollControl) const
{ {
if ( !font ) if ( !font )
return 0; return 0;
...@@ -477,55 +532,6 @@ bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl) ...@@ -477,55 +532,6 @@ bool CGUITabControl::needScrollControl(s32 startIndex, bool withScrollControl)
} }
bool CGUITabControl::selectTab(core::position2d<s32> p)
{
IGUISkin* skin = Environment->getSkin();
IGUIFont* font = skin->getFont();
core::rect<s32> frameRect(AbsoluteRect);
if ( VerticalAlignment == EGUIA_UPPERLEFT )
{
frameRect.UpperLeftCorner.Y += 2;
frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight;
}
else
{
frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight;
}
s32 pos = frameRect.UpperLeftCorner.X + 2;
if (!frameRect.isPointInside(p))
return false;
for (s32 i=CurrentScrollTabIndex; i<(s32)Tabs.size(); ++i)
{
// get Text
const wchar_t* text = 0;
if (Tabs[i])
text = Tabs[i]->getText();
// get text length
s32 len = calcTabWidth(pos, font, text, true);
if ( ScrollControl && pos+len > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
return false;
frameRect.UpperLeftCorner.X = pos;
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
pos += len;
if (frameRect.isPointInside(p))
{
setActiveTab(i);
return true;
}
}
return false;
}
core::rect<s32> CGUITabControl::calcTabPos() core::rect<s32> CGUITabControl::calcTabPos()
{ {
core::rect<s32> r; core::rect<s32> r;
...@@ -863,6 +869,54 @@ EGUI_ALIGNMENT CGUITabControl::getTabVerticalAlignment() const ...@@ -863,6 +869,54 @@ EGUI_ALIGNMENT CGUITabControl::getTabVerticalAlignment() const
} }
s32 CGUITabControl::getTabAt(s32 xpos, s32 ypos) const
{
core::position2di p(xpos, ypos);
IGUISkin* skin = Environment->getSkin();
IGUIFont* font = skin->getFont();
core::rect<s32> frameRect(AbsoluteRect);
if ( VerticalAlignment == EGUIA_UPPERLEFT )
{
frameRect.UpperLeftCorner.Y += 2;
frameRect.LowerRightCorner.Y = frameRect.UpperLeftCorner.Y + TabHeight;
}
else
{
frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - TabHeight;
}
s32 pos = frameRect.UpperLeftCorner.X + 2;
if (!frameRect.isPointInside(p))
return -1;
for (s32 i=CurrentScrollTabIndex; i<(s32)Tabs.size(); ++i)
{
// get Text
const wchar_t* text = 0;
if (Tabs[i])
text = Tabs[i]->getText();
// get text length
s32 len = calcTabWidth(pos, font, text, true);
if ( ScrollControl && pos+len > UpButton->getAbsolutePosition().UpperLeftCorner.X - 2 )
return -1;
frameRect.UpperLeftCorner.X = pos;
frameRect.LowerRightCorner.X = frameRect.UpperLeftCorner.X + len;
pos += len;
if (frameRect.isPointInside(p))
{
return i;
}
}
return -1;
}
//! Returns which tab is currently active //! Returns which tab is currently active
s32 CGUITabControl::getActiveTab() const s32 CGUITabControl::getActiveTab() const
{ {
......
...@@ -97,6 +97,15 @@ namespace gui ...@@ -97,6 +97,15 @@ namespace gui
//! Adds a tab that has already been created //! Adds a tab that has already been created
virtual void addTab(CGUITab* tab); virtual void addTab(CGUITab* tab);
//! Insert the tab at the given index
virtual IGUITab* insertTab(s32 idx, const wchar_t* caption, s32 id=-1);
//! Removes a tab from the tabcontrol
virtual void removeTab(s32 idx);
//! Clears the tabcontrol removing all tabs
virtual void clear();
//! Returns amount of tabs in the tabcontrol //! Returns amount of tabs in the tabcontrol
virtual s32 getTabCount() const; virtual s32 getTabCount() const;
...@@ -112,6 +121,9 @@ namespace gui ...@@ -112,6 +121,9 @@ namespace gui
//! Returns which tab is currently active //! Returns which tab is currently active
virtual s32 getActiveTab() const; virtual s32 getActiveTab() const;
//! get the the id of the tab at the given absolute coordinates
virtual s32 getTabAt(s32 xpos, s32 ypos) const;
//! called if an event happened. //! called if an event happened.
virtual bool OnEvent(const SEvent& event); virtual bool OnEvent(const SEvent& event);
...@@ -156,18 +168,17 @@ namespace gui ...@@ -156,18 +168,17 @@ namespace gui
private: private:
bool selectTab(core::position2d<s32> p);
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 ); s32 calcTabWidth(s32 pos, IGUIFont* font, const wchar_t* text, bool withScrollControl ) const;
core::rect<s32> calcTabPos(); core::rect<s32> calcTabPos();
void recalculateScrollButtonPlacement(); void recalculateScrollButtonPlacement();
void recalculateScrollBar(); void recalculateScrollBar();
void refreshSprites(); void refreshSprites();
core::array<CGUITab*> Tabs; core::array<CGUITab*> Tabs; // CGUITab* because we need setNumber (which is certainly not nice)
s32 ActiveTab; s32 ActiveTab;
bool Border; bool Border;
bool FillBackground; bool FillBackground;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment