Merge revision 4789:4790 from trunk to ogl-es:

- Add override font to IGUITable


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@4843 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2014-05-08 16:10:30 +00:00
parent cc6f7b2ec3
commit 5508ba4d23
4 changed files with 79 additions and 38 deletions

View File

@ -7,6 +7,7 @@ Changes in ogl-es (not yet released - will be merged with trunk at some point)
--------------------------
Changes in 1.9 (not yet released)
- Add override font to IGUITable
- IGUITable can now disable the active column.
- IGUIElement::getElementFromPoint now virtual
- Fixed issue with wrongly enabled Z-writing for transparent shader materials. Thanks Hendu for this fix.

View File

@ -12,6 +12,7 @@ namespace irr
{
namespace gui
{
class IGUIFont;
//! modes for ordering used when a column header is clicked
enum EGUI_COLUMN_ORDERING
@ -193,6 +194,20 @@ namespace gui
//! Get the flags, as defined in ::EGUI_TABLE_DRAW_FLAGS, which influence the layout
virtual s32 getDrawFlags() const = 0;
//! Sets another skin independent font.
/** If this is set to zero, the button uses the font of the skin.
\param font: New font to set. */
virtual void setOverrideFont(IGUIFont* font=0) = 0;
//! Gets the override font (if any)
/** \return The override font (may be 0) */
virtual IGUIFont* getOverrideFont(void) const = 0;
//! Get the font which is used right now for drawing
/** Currently this is the override font when one is set and the
font of the active skin otherwise */
virtual IGUIFont* getActiveFont() const = 0;
};

View File

@ -26,13 +26,14 @@ namespace gui
CGUITable::CGUITable(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, const core::rect<s32>& rectangle, bool clip,
bool drawBack, bool moveOverSelect)
: IGUITable(environment, parent, id, rectangle), Font(0),
: IGUITable(environment, parent, id, rectangle),
VerticalScrollBar(0), HorizontalScrollBar(0),
Clip(clip), DrawBack(drawBack), MoveOverSelect(moveOverSelect),
Selecting(false), CurrentResizedColumn(-1), ResizeStart(0), ResizableColumns(true),
ItemHeight(0), TotalItemHeight(0), TotalItemWidth(0), Selected(-1),
CellHeightPadding(2), CellWidthPadding(5), ActiveTab(-1),
CurrentOrdering(EGOM_NONE), DrawFlags(EGTDF_ROWS | EGTDF_COLUMNS | EGTDF_ACTIVE_ROW )
CurrentOrdering(EGOM_NONE), DrawFlags(EGTDF_ROWS | EGTDF_COLUMNS | EGTDF_ACTIVE_ROW ),
OverrideFont(0)
{
#ifdef _DEBUG
setDebugName("CGUITable");
@ -66,8 +67,8 @@ CGUITable::~CGUITable()
if ( HorizontalScrollBar )
HorizontalScrollBar->drop();
if (Font)
Font->drop();
if (OverrideFont)
OverrideFont->drop();
}
@ -75,7 +76,7 @@ void CGUITable::addColumn(const wchar_t* caption, s32 columnIndex)
{
Column tabHeader;
tabHeader.Name = caption;
tabHeader.Width = Font->getDimension(caption).Width + (CellWidthPadding * 2) + ARROW_PAD;
tabHeader.Width = getActiveFont()->getDimension(caption).Width + (CellWidthPadding * 2) + ARROW_PAD;
tabHeader.OrderingMode = EGCO_NONE;
if ( columnIndex < 0 || columnIndex >= (s32)Columns.size() )
@ -214,7 +215,7 @@ void CGUITable::setColumnWidth(u32 columnIndex, u32 width)
{
if ( columnIndex < Columns.size() )
{
const u32 MIN_WIDTH = Font->getDimension(Columns[columnIndex].Name.c_str() ).Width + (CellWidthPadding * 2);
const u32 MIN_WIDTH = getActiveFont()->getDimension(Columns[columnIndex].Name.c_str() ).Width + (CellWidthPadding * 2);
if ( width < MIN_WIDTH )
width = MIN_WIDTH;
@ -413,24 +414,17 @@ void CGUITable::recalculateWidths()
void CGUITable::recalculateHeights()
{
TotalItemHeight = 0;
IGUISkin* skin = Environment->getSkin();
if (Font != skin->getFont())
IGUIFont* activeFont = getActiveFont();
if(activeFont)
{
if (Font)
Font->drop();
Font = skin->getFont();
ItemHeight = 0;
if(Font)
{
ItemHeight = Font->getDimension(L"A").Height + (CellHeightPadding * 2);
Font->grab();
}
ItemHeight = activeFont->getDimension(L"A").Height + (CellHeightPadding * 2);
TotalItemHeight = ItemHeight * Rows.size(); // header is not counted, because we only want items
}
else
{
ItemHeight = 0;
TotalItemHeight = 0;
}
TotalItemHeight = ItemHeight * Rows.size(); // header is not counted, because we only want items
checkScrollbars();
}
@ -866,7 +860,7 @@ void CGUITable::draw()
if (!skin)
return;
IGUIFont* font = skin->getFont();
IGUIFont* font = getActiveFont();
if (!font)
return;
@ -967,8 +961,6 @@ void CGUITable::draw()
const wchar_t* text = Columns[i].Name.c_str();
u32 colWidth = Columns[i].Width;
//core::dimension2d<s32 > dim = font->getDimension(text);
core::rect<s32> columnrect(pos, tableRect.UpperLeftCorner.Y, pos + colWidth, headerBottom);
// draw column background
@ -1021,10 +1013,7 @@ void CGUITable::breakText(const core::stringw& text, core::stringw& brokenText,
if (!skin)
return;
if (!Font)
return;
IGUIFont* font = skin->getFont();
IGUIFont* font = getActiveFont();
if (!font)
return;
@ -1076,6 +1065,39 @@ s32 CGUITable::getDrawFlags() const
return DrawFlags;
}
//! Sets another skin independent font.
void CGUITable::setOverrideFont(IGUIFont* font)
{
if (OverrideFont == font)
return;
if (OverrideFont)
OverrideFont->drop();
OverrideFont = font;
if (OverrideFont)
OverrideFont->grab();
refreshControls();
}
//! Gets the override font (if any)
IGUIFont * CGUITable::getOverrideFont() const
{
return OverrideFont;
}
//! Get the font which is used right now for drawing
IGUIFont* CGUITable::getActiveFont() const
{
if ( OverrideFont )
return OverrideFont;
IGUISkin* skin = Environment->getSkin();
if (skin)
return skin->getFont();
return 0;
}
//! Writes attributes of the element.
void CGUITable::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
@ -1124,7 +1146,7 @@ void CGUITable::serializeAttributes(io::IAttributes* out, io::SAttributeReadWrit
// s32 ItemHeight; // can be calculated
// TotalItemHeight // calculated
// TotalItemWidth // calculated
// gui::IGUIFont* Font; // font is just the current font from environment
// gui::IGUIFont* ActiveFont; // TODO: we don't have a sane font-serialization so far
// gui::IGUIScrollBar* VerticalScrollBar; // not serialized
// gui::IGUIScrollBar* HorizontalScrollBar; // not serialized
@ -1211,13 +1233,6 @@ void CGUITable::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWri
TotalItemHeight = 0; // calculated
TotalItemWidth = 0; // calculated
// force font recalculation
if ( Font )
{
Font->drop();
Font = 0;
}
Clip = in->getAttributeAsBool("Clip");
DrawBack = in->getAttributeAsBool("DrawBack");
MoveOverSelect = in->getAttributeAsBool("MoveOverSelect");

View File

@ -143,6 +143,15 @@ namespace gui
//! Get the flags, as defined in EGUI_TABLE_DRAW_FLAGS, which influence the layout
virtual s32 getDrawFlags() const _IRR_OVERRIDE_;
//! Sets another skin independent font.
virtual void setOverrideFont(IGUIFont* font=0) _IRR_OVERRIDE_;
//! Gets the override font (if any)
virtual IGUIFont* getOverrideFont() const _IRR_OVERRIDE_;
//! Get the font which is used right now for drawing
virtual IGUIFont* getActiveFont() const _IRR_OVERRIDE_;
//! Writes attributes of the object.
//! Implement this to expose the attributes of your scene node animator for
//! scripting languages, editors, debuggers or xml serialization purposes.
@ -196,7 +205,6 @@ namespace gui
core::array< Column > Columns;
core::array< Row > Rows;
gui::IGUIFont* Font;
gui::IGUIScrollBar* VerticalScrollBar;
gui::IGUIScrollBar* HorizontalScrollBar;
bool Clip;
@ -216,6 +224,8 @@ namespace gui
s32 ActiveTab;
EGUI_ORDERING_MODE CurrentOrdering;
s32 DrawFlags;
gui::IGUIFont* OverrideFont;
};
} // end namespace gui