2019-12-12 17:32:41 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
2021-08-27 17:55:04 +02:00
|
|
|
#ifndef IRR_C_GUI_TAB_CONTROL_H_INCLUDED
|
|
|
|
#define IRR_C_GUI_TAB_CONTROL_H_INCLUDED
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
#include "IrrCompileConfig.h"
|
|
|
|
#ifdef _IRR_COMPILE_WITH_GUI_
|
|
|
|
|
|
|
|
#include "IGUITabControl.h"
|
|
|
|
#include "irrArray.h"
|
|
|
|
#include "IGUISkin.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace gui
|
|
|
|
{
|
|
|
|
class CGUITabControl;
|
|
|
|
class IGUIButton;
|
|
|
|
|
|
|
|
// A tab, onto which other gui elements could be added.
|
|
|
|
class CGUITab : public IGUITab
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CGUITab(IGUIEnvironment* environment,
|
|
|
|
IGUIElement* parent, const core::rect<s32>& rectangle,
|
|
|
|
s32 id);
|
|
|
|
|
|
|
|
//! draws the element and its children
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void draw() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! sets if the tab should draw its background
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setDrawBackground(bool draw=true) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! sets the color of the background, if it should be drawn.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setBackgroundColor(video::SColor c) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! sets the color of the text
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setTextColor(video::SColor c) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! returns true if the tab is drawing its background, false if not
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool isDrawingBackground() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! returns the color of the background
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual video::SColor getBackgroundColor() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual video::SColor getTextColor() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Writes attributes of the element.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Reads attributes of the element
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
video::SColor BackColor;
|
|
|
|
bool OverrideTextColorEnabled;
|
|
|
|
video::SColor TextColor;
|
|
|
|
bool DrawBackground;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//! A standard tab control
|
|
|
|
class CGUITabControl : public IGUITabControl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
CGUITabControl(IGUIEnvironment* environment,
|
|
|
|
IGUIElement* parent, const core::rect<s32>& rectangle,
|
|
|
|
bool fillbackground=true, bool border=true, s32 id=-1);
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~CGUITabControl();
|
|
|
|
|
|
|
|
//! Adds a tab
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual IGUITab* addTab(const wchar_t* caption, s32 id=-1) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Adds an existing tab
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 addTab(IGUITab* tab) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Insert the tab at the given index
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual IGUITab* insertTab(s32 idx, const wchar_t* caption, s32 id=-1) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Insert an existing tab
|
|
|
|
/** Note that it will also add the tab as a child of this TabControl.
|
|
|
|
\return Index of added tab (should be same as the one passed) or -1 for failure*/
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 insertTab(s32 idx, IGUITab* tab, bool serializationMode) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Removes a tab from the tabcontrol
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void removeTab(s32 idx) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Clears the tabcontrol removing all tabs
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void clear() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns amount of tabs in the tabcontrol
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getTabCount() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns a tab based on zero based index
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual IGUITab* getTab(s32 idx) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Brings a tab to front.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool setActiveTab(s32 idx) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Brings a tab to front.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool setActiveTab(IGUITab *tab) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! For given given tab find it's zero-based index (or -1 for not found)
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getTabIndex(const IGUIElement *tab) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Returns which tab is currently active
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getActiveTab() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! get the the id of the tab at the given absolute coordinates
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getTabAt(s32 xpos, s32 ypos) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! called if an event happened.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual bool OnEvent(const SEvent& event) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! draws the element and its children
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void draw() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Removes a child.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void removeChild(IGUIElement* child) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Writes attributes of the element.
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
//! Set the height of the tabs
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setTabHeight( s32 height ) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Reads attributes of the element
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get the height of the tabs
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getTabHeight() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! set the maximal width of a tab. Per default width is 0 which means "no width restriction".
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setTabMaxWidth(s32 width ) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! get the maximal width of a tab
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getTabMaxWidth() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Set the alignment of the tabs
|
|
|
|
//! note: EGUIA_CENTER is not an option
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setTabVerticalAlignment( gui::EGUI_ALIGNMENT alignment ) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get the alignment of the tabs
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual gui::EGUI_ALIGNMENT getTabVerticalAlignment() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Set the extra width added to tabs on each side of the text
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void setTabExtraWidth( s32 extraWidth ) IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Get the extra width added to tabs on each side of the text
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual s32 getTabExtraWidth() const IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
//! Update the position of the element, decides scroll button status
|
2021-08-27 14:55:10 +02:00
|
|
|
virtual void updateAbsolutePosition() IRR_OVERRIDE;
|
2019-12-12 17:32:41 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void scrollLeft();
|
|
|
|
void scrollRight();
|
|
|
|
bool needScrollControl( s32 startIndex=0, bool withScrollControl=false );
|
|
|
|
s32 calcTabWidth(s32 pos, IGUIFont* font, const wchar_t* text, bool withScrollControl ) const;
|
|
|
|
core::rect<s32> calcTabPos();
|
|
|
|
void setVisibleTab(s32 idx);
|
|
|
|
void removeTabButNotChild(s32 idx);
|
|
|
|
|
|
|
|
void recalculateScrollButtonPlacement();
|
|
|
|
void recalculateScrollBar();
|
|
|
|
void refreshSprites();
|
|
|
|
|
|
|
|
core::array<IGUITab*> Tabs;
|
|
|
|
s32 ActiveTabIndex;
|
|
|
|
bool Border;
|
|
|
|
bool FillBackground;
|
|
|
|
bool ScrollControl;
|
|
|
|
s32 TabHeight;
|
|
|
|
gui::EGUI_ALIGNMENT VerticalAlignment;
|
|
|
|
IGUIButton* UpButton;
|
|
|
|
IGUIButton* DownButton;
|
|
|
|
s32 TabMaxWidth;
|
|
|
|
s32 CurrentScrollTabIndex;
|
|
|
|
s32 TabExtraWidth;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace gui
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif // _IRR_COMPILE_WITH_GUI_
|
|
|
|
|
|
|
|
#endif
|