Commit 4ee11782 authored by bitplane's avatar bitplane

added more default fonts to skins, made elements use them by default. updated...

added more default fonts to skins, made elements use them by default. updated gui example to show use.
modalscreens now resize to fit parent.
updated meshviewer example to lock the image to the bottom left corner.
tooltips:
added EGDC_TOOLTIP_BACKGROUND to skins. 
changed the position of tooltips and their time between creation to 500ms. 
made sure that they do not leave the area of the gui environment.
new method: rect::constrainTo to forcing one rectangle to stay inside another.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@697 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a5fc06d9
Changes in version 1.3.1 (?? Mar 2007) Changes in version 1.3.1 (?? Mar 2007)
- Added rect::constrainTo for locking a rectangle inside another without resizing it
- Moved the OpenGL API functions from COpenGL driver into new extension - Moved the OpenGL API functions from COpenGL driver into new extension
handler. Thereby, some renaming took place - the ARB and EXT suffix was handler. Thereby, some renaming took place - the ARB and EXT suffix was
removed. Simply rename the functions in case you use them. removed. Simply rename the functions in case you use them.
...@@ -117,11 +119,22 @@ Changes in version 1.3.1 (?? Mar 2007) ...@@ -117,11 +119,22 @@ Changes in version 1.3.1 (?? Mar 2007)
GUI: GUI:
- Fixed a messagebox focus bug when no 'okay' button was present - Added EGUI_DEFAULT_FONT for skins, default fonts can now be set for windows, menus, buttons and tooltips.
use IGUISkin::setFont and getFont to use them. Fonts are not serialized with saveGUI yet
- Added EGDC_TOOLTIP_BACKGROUND for setting background color of tooltips.
- Tooltips now appear relative to mouse position, also they do not appear for 500ms.
- Fixed a memory leak when dropping the GUIEnvironment when a tooltip was present.
- Added IGUIStaticText::setDrawBackground and IGUIStaticText::setBackgroundColor.
- Fixed a messagebox focus bug when no 'okay' button was present.
- Added setColor and setScaleImage to GUIImage. - Added setColor and setScaleImage to GUIImage.
- Made GUIListBox clip properly. - GUIListBox highlighted area now clips properly.
- added getOSOperator to GUIEnvironment (for clipboard access in elements) and updated CGUIEditBox. - added getOSOperator to GUIEnvironment (for clipboard access in elements) and updated CGUIEditBox.
...@@ -132,7 +145,12 @@ GUI: ...@@ -132,7 +145,12 @@ GUI:
- Fixed a bug with resizing the gui environment when the device is resized - Fixed a bug with resizing the gui environment when the device is resized
- XML bitmap fonts now load textures from the XML file directory rather than the current one - Modal screens now resize to fit their parent.
- XML bitmap fonts now load textures from the XML file directory rather than the current one.
- Fixed a small bug with click areas in combo boxes.
GUI Editor: GUI Editor:
......
...@@ -182,8 +182,9 @@ int main() ...@@ -182,8 +182,9 @@ int main()
/* /*
To make the font a little bit nicer, we load an external font To make the font a little bit nicer, we load an external font
and set it as new font in the skin. An at last, we create a and set it as the new default font in the skin.
nice Irrlicht Engine logo in the top left corner. To keep the standard font for tool tip text, we set it to
the built-in font.
*/ */
IGUISkin* skin = env->getSkin(); IGUISkin* skin = env->getSkin();
...@@ -191,6 +192,8 @@ int main() ...@@ -191,6 +192,8 @@ int main()
if (font) if (font)
skin->setFont(font); skin->setFont(font);
skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP);
/* /*
We add three buttons. The first one closes the engine. The second We add three buttons. The first one closes the engine. The second
creates a window and the third opens a file open dialog. The third creates a window and the third opens a file open dialog. The third
...@@ -198,7 +201,7 @@ int main() ...@@ -198,7 +201,7 @@ int main()
the button in the event receiver. the button in the event receiver.
*/ */
env->addButton(rect<s32>(10,210,110,210 + 32), 0, 101, L"Quit", L"Exits Programm"); env->addButton(rect<s32>(10,210,110,210 + 32), 0, 101, L"Quit", L"Exits Program");
env->addButton(rect<s32>(10,250,110,250 + 32), 0, 102, L"New Window", L"Launches a new Window"); env->addButton(rect<s32>(10,250,110,250 + 32), 0, 102, L"New Window", L"Launches a new Window");
env->addButton(rect<s32>(10,290,110,290 + 32), 0, 103, L"File Open", L"Opens a file"); env->addButton(rect<s32>(10,290,110,290 + 32), 0, 103, L"File Open", L"Opens a file");
......
...@@ -622,9 +622,13 @@ int main() ...@@ -622,9 +622,13 @@ int main()
setActiveCamera ( Camera[0] ); setActiveCamera ( Camera[0] );
// load the irrlicht engine logo // load the irrlicht engine logo
IGUIImage *img =
env->addImage(driver->getTexture("irrlichtlogo2.png"), env->addImage(driver->getTexture("irrlichtlogo2.png"),
core::position2d<s32>(10, driver->getScreenSize().Height - 64)); core::position2d<s32>(10, driver->getScreenSize().Height - 64));
// lock the logo's edges to the bottom left corner of the screen
img->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
// draw everything // draw everything
while(Device->run() && driver) while(Device->run() && driver)
......
...@@ -81,8 +81,10 @@ namespace gui ...@@ -81,8 +81,10 @@ namespace gui
EGDC_INACTIVE_BORDER, EGDC_INACTIVE_BORDER,
//! Inactive window caption. //! Inactive window caption.
EGDC_INACTIVE_CAPTION, EGDC_INACTIVE_CAPTION,
//! Tool tip color //! Tool tip text color
EGDC_TOOLTIP, EGDC_TOOLTIP,
//! Tool tip background color
EGDC_TOOLTIP_BACKGROUND,
//! Scrollbar gray area //! Scrollbar gray area
EGDC_SCROLLBAR, EGDC_SCROLLBAR,
//! Window background //! Window background
...@@ -116,6 +118,7 @@ namespace gui ...@@ -116,6 +118,7 @@ namespace gui
"InactiveBorder", "InactiveBorder",
"InactiveCaption", "InactiveCaption",
"ToolTip", "ToolTip",
"ToolTipBackground",
"ScrollBar", "ScrollBar",
"Window", "Window",
"WindowSymbol", "WindowSymbol",
...@@ -268,6 +271,34 @@ namespace gui ...@@ -268,6 +271,34 @@ namespace gui
0 0
}; };
// Customizable fonts
enum EGUI_DEFAULT_FONT
{
//! For static text, edit boxes, lists and most other places
EGDF_DEFAULT=0,
//! Font for buttons
EGDF_BUTTON,
//! Font for window title bars
EGDF_WINDOW,
//! Font for menu items
EGDF_MENU,
//! Font for tooltips
EGDF_TOOLTIP,
//! this value is not used, it only specifies the amount of default fonts
//! available.
EGDF_COUNT
};
const c8* const GUISkinFontNames[] =
{
"defaultFont",
"buttonFont",
"windowFont",
"menuFont",
"tooltipFont",
0
};
//! A skin modifies the look of the GUI elements. //! A skin modifies the look of the GUI elements.
class IGUISkin : public virtual io::IAttributeExchangingObject class IGUISkin : public virtual io::IAttributeExchangingObject
{ {
...@@ -299,10 +330,10 @@ namespace gui ...@@ -299,10 +330,10 @@ namespace gui
virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size) = 0; virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size) = 0;
//! returns the default font //! returns the default font
virtual IGUIFont* getFont() = 0; virtual IGUIFont* getFont(EGUI_DEFAULT_FONT which=EGDF_DEFAULT) = 0;
//! sets a default font //! sets a default font
virtual void setFont(IGUIFont* font) = 0; virtual void setFont(IGUIFont* font, EGUI_DEFAULT_FONT which=EGDF_DEFAULT) = 0;
//! returns the sprite bank //! returns the sprite bank
virtual IGUISpriteBank* getSpriteBank() = 0; virtual IGUISpriteBank* getSpriteBank() = 0;
......
...@@ -59,6 +59,12 @@ namespace gui ...@@ -59,6 +59,12 @@ namespace gui
//! \return true if the override color is enabled, false otherwise //! \return true if the override color is enabled, false otherwise
virtual bool isOverrideColorEnabled(void) = 0; virtual bool isOverrideColorEnabled(void) = 0;
//! Sets another color for the background.
virtual void setBackgroundColor(video::SColor color) = 0;
//! Sets whether to draw the background
virtual void setDrawBackground(bool draw) = 0;
//! Enables or disables word wrap for using the static text as multiline text control. //! Enables or disables word wrap for using the static text as multiline text control.
/** \param enable: If set to true, words going over one line are /** \param enable: If set to true, words going over one line are
breaked to the next line. */ breaked to the next line. */
......
...@@ -144,6 +144,44 @@ namespace core ...@@ -144,6 +144,44 @@ namespace core
UpperLeftCorner.X = LowerRightCorner.X; UpperLeftCorner.X = LowerRightCorner.X;
} }
//! Moves this rectangle to fit inside another one.
//! \return: returns true on success, false if not possible
bool constrainTo(const rect<T>& other)
{
if (other.getWidth() < getWidth() || other.getHeight() < getHeight())
return false;
T diff = other.LowerRightCorner.X - LowerRightCorner.X;
if (diff < 0)
{
LowerRightCorner.X += diff;
UpperLeftCorner.X += diff;
}
diff = other.LowerRightCorner.Y - LowerRightCorner.Y;
if (diff < 0)
{
LowerRightCorner.Y += diff;
UpperLeftCorner.Y += diff;
}
diff = UpperLeftCorner.X - other.UpperLeftCorner.X;
if (diff < 0)
{
UpperLeftCorner.X -= diff;
LowerRightCorner.X -= diff;
}
diff = UpperLeftCorner.Y - other.UpperLeftCorner.Y;
if (diff < 0)
{
UpperLeftCorner.Y -= diff;
LowerRightCorner.Y -= diff;
}
return true;
}
//! Returns width of rectangle. //! Returns width of rectangle.
T getWidth() const T getWidth() const
{ {
......
...@@ -196,7 +196,7 @@ void CGUIButton::draw() ...@@ -196,7 +196,7 @@ void CGUIButton::draw()
IGUIFont* font = OverrideFont; IGUIFont* font = OverrideFont;
if (!OverrideFont) if (!OverrideFont)
font = skin->getFont(); font = skin->getFont(EGDF_BUTTON);
core::rect<s32> rect = AbsoluteRect; core::rect<s32> rect = AbsoluteRect;
......
...@@ -445,7 +445,7 @@ void CGUIColorSelectDialog::draw() ...@@ -445,7 +445,7 @@ void CGUIColorSelectDialog::draw()
rect.UpperLeftCorner.X += 2; rect.UpperLeftCorner.X += 2;
rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;
IGUIFont* font = skin->getFont(); IGUIFont* font = skin->getFont(EGDF_WINDOW);
if (font) if (font)
font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true,
&AbsoluteClippingRect); &AbsoluteClippingRect);
......
...@@ -382,7 +382,7 @@ void CGUIContextMenu::draw() ...@@ -382,7 +382,7 @@ void CGUIContextMenu::draw()
if (!skin) if (!skin)
return; return;
IGUIFont* font = skin->getFont(); IGUIFont* font = skin->getFont(EGDF_MENU);
IGUISpriteBank* sprites = skin->getSpriteBank(); IGUISpriteBank* sprites = skin->getSpriteBank();
video::IVideoDriver* driver = Environment->getVideoDriver(); video::IVideoDriver* driver = Environment->getVideoDriver();
...@@ -481,7 +481,7 @@ void CGUIContextMenu::draw() ...@@ -481,7 +481,7 @@ void CGUIContextMenu::draw()
void CGUIContextMenu::recalculateSize() void CGUIContextMenu::recalculateSize()
{ {
IGUISkin* skin = Environment->getSkin(); IGUISkin* skin = Environment->getSkin();
IGUIFont* font = skin->getFont(); IGUIFont* font = skin->getFont(EGDF_MENU);
if (!font) if (!font)
return; return;
......
...@@ -48,7 +48,7 @@ const wchar_t* IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE = L"type"; ...@@ -48,7 +48,7 @@ const wchar_t* IRR_XML_FORMAT_GUI_ELEMENT_ATTR_TYPE = L"type";
//! constructor //! constructor
CGUIEnvironment::CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op) CGUIEnvironment::CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op)
: IGUIElement(EGUIET_ELEMENT, 0, 0, 0, core::rect<s32>(core::position2d<s32>(0,0), driver ? driver->getScreenSize() : core::dimension2d<s32>(0,0))), : IGUIElement(EGUIET_ELEMENT, 0, 0, 0, core::rect<s32>(core::position2d<s32>(0,0), driver ? driver->getScreenSize() : core::dimension2d<s32>(0,0))),
Driver(driver), Hovered(0), Focus(0), CurrentSkin(0), Driver(driver), Hovered(0), Focus(0), LastHoveredMousePos(0,0), CurrentSkin(0),
FileSystem(fs), UserReceiver(0), Operator(op) FileSystem(fs), UserReceiver(0), Operator(op)
{ {
if (Driver) if (Driver)
...@@ -103,6 +103,12 @@ CGUIEnvironment::~CGUIEnvironment() ...@@ -103,6 +103,12 @@ CGUIEnvironment::~CGUIEnvironment()
Focus = 0; Focus = 0;
} }
if (ToolTip.Element)
{
ToolTip.Element->drop();
ToolTip.Element = 0;
}
if (FileSystem) if (FileSystem)
{ {
FileSystem->drop(); FileSystem->drop();
...@@ -294,21 +300,28 @@ void CGUIEnvironment::OnPostRender( u32 time ) ...@@ -294,21 +300,28 @@ void CGUIEnvironment::OnPostRender( u32 time )
Hovered && Hovered != this && Hovered && Hovered != this &&
ToolTip.Element == 0 && ToolTip.Element == 0 &&
Hovered != ToolTip.Element && Hovered != ToolTip.Element &&
Hovered->getToolTipText().size() Hovered->getToolTipText().size() &&
getSkin() &&
getSkin()->getFont(EGDF_TOOLTIP)
) )
{ {
core::rect<s32> pos; core::rect<s32> pos;
pos.UpperLeftCorner = Hovered->getAbsolutePosition().LowerRightCorner;
pos.LowerRightCorner = pos.UpperLeftCorner + core::position2d<s32> ( 100, 50 ); pos.UpperLeftCorner = LastHoveredMousePos;
if (getSkin() && getSkin()->getFont()) core::dimension2di dim = getSkin()->getFont(EGDF_TOOLTIP)->getDimension(Hovered->getToolTipText().c_str());
{ dim.Width += getSkin()->getSize(EGDS_TEXT_DISTANCE_X)*2;
pos.LowerRightCorner = pos.UpperLeftCorner + dim.Height += getSkin()->getSize(EGDS_TEXT_DISTANCE_Y)*2;
getSkin()->getFont()->getDimension(Hovered->getToolTipText().c_str()) +
core::position2di(getSkin()->getSize(EGDS_TEXT_DISTANCE_X)*2, getSkin()->getSize(EGDS_TEXT_DISTANCE_Y)*2); pos.UpperLeftCorner.Y -= dim.Height-1;
} pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + dim.Height-1;
pos.LowerRightCorner.X = pos.UpperLeftCorner.X + dim.Width;
pos.constrainTo(getAbsolutePosition());
ToolTip.Element = addStaticText(Hovered->getToolTipText().c_str(), pos, true, true, this, -1, true); ToolTip.Element = addStaticText(Hovered->getToolTipText().c_str(), pos, true, true, this, -1, true);
ToolTip.Element->setOverrideColor(getSkin()->getColor(EGDC_TOOLTIP)); ToolTip.Element->setOverrideColor(getSkin()->getColor(EGDC_TOOLTIP));
ToolTip.Element->setBackgroundColor(getSkin()->getColor(EGDC_TOOLTIP_BACKGROUND));
ToolTip.Element->setOverrideFont(getSkin()->getFont(EGDF_TOOLTIP));
ToolTip.Element->setSubElement(true); ToolTip.Element->setSubElement(true);
ToolTip.Element->grab(); ToolTip.Element->grab();
...@@ -327,6 +340,7 @@ void CGUIEnvironment::OnPostRender( u32 time ) ...@@ -327,6 +340,7 @@ void CGUIEnvironment::OnPostRender( u32 time )
void CGUIEnvironment::updateHoveredElement(core::position2d<s32> mousePos) void CGUIEnvironment::updateHoveredElement(core::position2d<s32> mousePos)
{ {
IGUIElement* lastHovered = Hovered; IGUIElement* lastHovered = Hovered;
LastHoveredMousePos = mousePos;
Hovered = getElementFromPoint(mousePos); Hovered = getElementFromPoint(mousePos);
...@@ -354,13 +368,14 @@ void CGUIEnvironment::updateHoveredElement(core::position2d<s32> mousePos) ...@@ -354,13 +368,14 @@ void CGUIEnvironment::updateHoveredElement(core::position2d<s32> mousePos)
ToolTip.Element->remove(); ToolTip.Element->remove();
ToolTip.Element->drop(); ToolTip.Element->drop();
ToolTip.Element = 0; ToolTip.Element = 0;
ToolTip.LastTime += 500;
} }
else else
{ {
// boost tooltip generation for relaunch // boost tooltip generation for relaunch
if ( now - ToolTip.LastTime < ToolTip.LastTime ) if ( now - ToolTip.LastTime < ToolTip.LastTime )
{ {
ToolTip.LastTime += 100; ToolTip.LastTime += 500;
} }
else else
{ {
......
...@@ -265,6 +265,7 @@ private: ...@@ -265,6 +265,7 @@ private:
video::IVideoDriver* Driver; video::IVideoDriver* Driver;
IGUIElement* Hovered; IGUIElement* Hovered;
IGUIElement* Focus; IGUIElement* Focus;
core::position2d<s32> LastHoveredMousePos;
IGUISkin* CurrentSkin; IGUISkin* CurrentSkin;
io::IFileSystem* FileSystem; io::IFileSystem* FileSystem;
IEventReceiver* UserReceiver; IEventReceiver* UserReceiver;
......
...@@ -247,7 +247,7 @@ void CGUIFileOpenDialog::draw() ...@@ -247,7 +247,7 @@ void CGUIFileOpenDialog::draw()
rect.UpperLeftCorner.X += 2; rect.UpperLeftCorner.X += 2;
rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;
IGUIFont* font = skin->getFont(); IGUIFont* font = skin->getFont(EGDF_WINDOW);
if (font) if (font)
font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true,
&AbsoluteClippingRect); &AbsoluteClippingRect);
......
...@@ -43,7 +43,7 @@ void CGUIMenu::draw() ...@@ -43,7 +43,7 @@ void CGUIMenu::draw()
return; return;
IGUISkin* skin = Environment->getSkin(); IGUISkin* skin = Environment->getSkin();
IGUIFont* font = skin->getFont(); IGUIFont* font = skin->getFont(EGDF_MENU);
core::rect<s32> rect = AbsoluteRect; core::rect<s32> rect = AbsoluteRect;
...@@ -148,7 +148,7 @@ bool CGUIMenu::OnEvent(SEvent event) ...@@ -148,7 +148,7 @@ bool CGUIMenu::OnEvent(SEvent event)
void CGUIMenu::recalculateSize() void CGUIMenu::recalculateSize()
{ {
IGUISkin* skin = Environment->getSkin(); IGUISkin* skin = Environment->getSkin();
IGUIFont* font = skin->getFont(); IGUIFont* font = skin->getFont(EGDF_MENU);
if (!font) if (!font)
{ {
......
...@@ -21,6 +21,7 @@ CGUIModalScreen::CGUIModalScreen(IGUIEnvironment* environment, IGUIElement* pare ...@@ -21,6 +21,7 @@ CGUIModalScreen::CGUIModalScreen(IGUIEnvironment* environment, IGUIElement* pare
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CGUIModalScreen"); setDebugName("CGUIModalScreen");
#endif #endif
setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
} }
......
...@@ -15,7 +15,7 @@ namespace gui ...@@ -15,7 +15,7 @@ namespace gui
{ {
CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver)
: Font(0), SpriteBank(0), Driver(driver), Type(type) : SpriteBank(0), Driver(driver), Type(type)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CGUISkin"); setDebugName("CGUISkin");
...@@ -31,7 +31,7 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) ...@@ -31,7 +31,7 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver)
Colors[EGDC_3D_HIGH_LIGHT] = video::SColor(101,255,255,255); Colors[EGDC_3D_HIGH_LIGHT] = video::SColor(101,255,255,255);
Colors[EGDC_3D_LIGHT] = video::SColor(101,210,210,210); Colors[EGDC_3D_LIGHT] = video::SColor(101,210,210,210);
Colors[EGDC_ACTIVE_BORDER] = video::SColor(101,16,14,115); Colors[EGDC_ACTIVE_BORDER] = video::SColor(101,16,14,115);
Colors[EGDC_ACTIVE_CAPTION] = video::SColor(240,255,255,255); Colors[EGDC_ACTIVE_CAPTION] = video::SColor(200,255,255,255);
Colors[EGDC_APP_WORKSPACE] = video::SColor(101,100,100,100); Colors[EGDC_APP_WORKSPACE] = video::SColor(101,100,100,100);
Colors[EGDC_BUTTON_TEXT] = video::SColor(240,10,10,10); Colors[EGDC_BUTTON_TEXT] = video::SColor(240,10,10,10);
Colors[EGDC_GRAY_TEXT] = video::SColor(240,130,130,130); Colors[EGDC_GRAY_TEXT] = video::SColor(240,130,130,130);
...@@ -39,12 +39,13 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) ...@@ -39,12 +39,13 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver)
Colors[EGDC_HIGH_LIGHT_TEXT] = video::SColor(240,255,255,255); Colors[EGDC_HIGH_LIGHT_TEXT] = video::SColor(240,255,255,255);
Colors[EGDC_INACTIVE_BORDER] = video::SColor(101,165,165,165); Colors[EGDC_INACTIVE_BORDER] = video::SColor(101,165,165,165);
Colors[EGDC_INACTIVE_CAPTION] = video::SColor(101,210,210,210); Colors[EGDC_INACTIVE_CAPTION] = video::SColor(101,210,210,210);
Colors[EGDC_TOOLTIP] = video::SColor(101,255,255,230); Colors[EGDC_TOOLTIP] = video::SColor(200,0,0,0);
Colors[EGDC_TOOLTIP_BACKGROUND]= video::SColor(200,255,255,225);
Colors[EGDC_SCROLLBAR] = video::SColor(101,230,230,230); Colors[EGDC_SCROLLBAR] = video::SColor(101,230,230,230);
Colors[EGDC_WINDOW] = video::SColor(101,255,255,255); Colors[EGDC_WINDOW] = video::SColor(101,255,255,255);
Colors[EGDC_WINDOW_SYMBOL] = video::SColor(240,10,10,10); Colors[EGDC_WINDOW_SYMBOL] = video::SColor(200,10,10,10);
Colors[EGDC_ICON] = video::SColor(240,255,255,255); Colors[EGDC_ICON] = video::SColor(200,255,255,255);
Colors[EGDC_ICON_HIGH_LIGHT] = video::SColor(240,10,10,10); Colors[EGDC_ICON_HIGH_LIGHT] = video::SColor(200,10,10,10);
Sizes[EGDS_SCROLLBAR_SIZE] = 14; Sizes[EGDS_SCROLLBAR_SIZE] = 14;
Sizes[EGDS_MENU_HEIGHT] = 30; Sizes[EGDS_MENU_HEIGHT] = 30;
...@@ -78,6 +79,7 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) ...@@ -78,6 +79,7 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver)
Colors[EGDC_INACTIVE_BORDER]= 0xf0a5a5a5; Colors[EGDC_INACTIVE_BORDER]= 0xf0a5a5a5;
Colors[EGDC_INACTIVE_CAPTION]= 0xf0d2d2d2; Colors[EGDC_INACTIVE_CAPTION]= 0xf0d2d2d2;
Colors[EGDC_TOOLTIP] = 0xf00f2033; Colors[EGDC_TOOLTIP] = 0xf00f2033;
Colors[EGDC_TOOLTIP_BACKGROUND]=0xc0cbd2d9;
Colors[EGDC_SCROLLBAR] = 0xf0e0e0e0; Colors[EGDC_SCROLLBAR] = 0xf0e0e0e0;
Colors[EGDC_WINDOW] = 0xf0f0f0f0; Colors[EGDC_WINDOW] = 0xf0f0f0f0;
Colors[EGDC_WINDOW_SYMBOL] = 0xd0161616; Colors[EGDC_WINDOW_SYMBOL] = 0xd0161616;
...@@ -123,6 +125,9 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) ...@@ -123,6 +125,9 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver)
Icons[EGDI_FILE] = 238; Icons[EGDI_FILE] = 238;
Icons[EGDI_DIRECTORY] = 239; Icons[EGDI_DIRECTORY] = 239;
for (u32 i=0; i<EGDF_COUNT; ++i)
Fonts[i] = 0;
UseGradient = (Type == EGST_WINDOWS_METALLIC) || UseGradient = (Type == EGST_WINDOWS_METALLIC) ||
(Type == EGST_BURNING_SKIN) ; (Type == EGST_BURNING_SKIN) ;
} }
...@@ -131,8 +136,12 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver) ...@@ -131,8 +136,12 @@ CGUISkin::CGUISkin(EGUI_SKIN_TYPE type, video::IVideoDriver* driver)
//! destructor //! destructor
CGUISkin::~CGUISkin() CGUISkin::~CGUISkin()
{ {
if (Font) for (u32 i=0; i<EGDF_COUNT; ++i)
Font->drop(); {
if (Fonts[i])
Fonts[i]->drop();
}
if (SpriteBank) if (SpriteBank)
SpriteBank->drop(); SpriteBank->drop();
} }
...@@ -172,21 +181,24 @@ void CGUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size) ...@@ -172,21 +181,24 @@ void CGUISkin::setSize(EGUI_DEFAULT_SIZE which, s32 size)
//! returns the default font //! returns the default font
IGUIFont* CGUISkin::getFont() IGUIFont* CGUISkin::getFont(EGUI_DEFAULT_FONT which)
{ {
return Font; if (Fonts[which])
return Fonts[which];
else
return Fonts[EGDF_DEFAULT];
} }
//! sets a default font //! sets a default font
void CGUISkin::setFont(IGUIFont* font) void CGUISkin::setFont(IGUIFont* font, EGUI_DEFAULT_FONT which)
{ {
if (Font) if (Fonts[which])
Font->drop(); Fonts[which]->drop();
Font = font; Fonts[which] = font;
if (Font) if (Fonts[which])
Font->grab(); Fonts[which]->grab();
} }
IGUISpriteBank* CGUISkin::getSpriteBank() IGUISpriteBank* CGUISkin::getSpriteBank()
......
...@@ -39,10 +39,10 @@ namespace gui ...@@ -39,10 +39,10 @@ namespace gui
virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size); virtual void setSize(EGUI_DEFAULT_SIZE which, s32 size);
//! returns the default font //! returns the default font
virtual IGUIFont* getFont(); virtual IGUIFont* getFont(EGUI_DEFAULT_FONT which=EGDF_DEFAULT);
//! sets a default font //! sets a default font
virtual void setFont(IGUIFont* font); virtual void setFont(IGUIFont* font, EGUI_DEFAULT_FONT which=EGDF_DEFAULT);
//! sets the sprite bank used for drawing icons //! sets the sprite bank used for drawing icons
virtual void setSpriteBank(IGUISpriteBank* bank); virtual void setSpriteBank(IGUISpriteBank* bank);
...@@ -207,7 +207,7 @@ namespace gui ...@@ -207,7 +207,7 @@ namespace gui
video::SColor Colors[EGDC_COUNT]; video::SColor Colors[EGDC_COUNT];
s32 Sizes[EGDS_COUNT]; s32 Sizes[EGDS_COUNT];
u32 Icons[EGDI_COUNT]; u32 Icons[EGDI_COUNT];
IGUIFont* Font; IGUIFont* Fonts[EGDF_COUNT];
IGUISpriteBank* SpriteBank; IGUISpriteBank* SpriteBank;
core::stringw Texts[EGDT_COUNT]; core::stringw Texts[EGDT_COUNT];
video::IVideoDriver* Driver; video::IVideoDriver* Driver;
......
...@@ -22,12 +22,17 @@ CGUIStaticText::CGUIStaticText(const wchar_t* text, bool border, ...@@ -22,12 +22,17 @@ CGUIStaticText::CGUIStaticText(const wchar_t* text, bool border,
bool background) bool background)
: IGUIStaticText(environment, parent, id, rectangle), Border(border), : IGUIStaticText(environment, parent, id, rectangle), Border(border),
OverrideColorEnabled(false), WordWrap(false), Background(background), OverrideColorEnabled(false), WordWrap(false), Background(background),
OverrideColor(video::SColor(101,255,255,255)), OverrideFont(0), LastBreakFont(0) OverrideColor(video::SColor(101,255,255,255)), OverrideFont(0), LastBreakFont(0),
BGColor(video::SColor(101,210,210,210))
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CGUIStaticText"); setDebugName("CGUIStaticText");
#endif #endif
Text = text; Text = text;
if (environment && environment->getSkin())
{
BGColor = environment->getSkin()->getColor(gui::EGDC_3D_FACE);
}
} }
...@@ -56,8 +61,7 @@ void CGUIStaticText::draw() ...@@ -56,8 +61,7 @@ void CGUIStaticText::draw()
if (Background) if (Background)
{ {
driver->draw2DRectangle( skin->getColor(gui::EGDC_3D_FACE), driver->draw2DRectangle(BGColor, frameRect, &AbsoluteClippingRect);
frameRect, &AbsoluteClippingRect);
} }
// draw the border // draw the border
...@@ -134,6 +138,19 @@ void CGUIStaticText::setOverrideColor(video::SColor color) ...@@ -134,6 +138,19 @@ void CGUIStaticText::setOverrideColor(video::SColor color)
OverrideColorEnabled = true; OverrideColorEnabled = true;
} }
//! Sets another color for the text.
void CGUIStaticText::setBackgroundColor(video::SColor color)
{
BGColor = color;
Background = true;
}
//! Sets whether to draw the background
void CGUIStaticText::setDrawBackground(bool draw)
{
Background = draw;
}
video::SColor const & CGUIStaticText::getOverrideColor(void) video::SColor const & CGUIStaticText::getOverrideColor(void)
{ {
return OverrideColor; return OverrideColor;
......
...@@ -36,6 +36,12 @@ namespace gui ...@@ -36,6 +36,12 @@ namespace gui
//! Sets another color for the text. //! Sets another color for the text.
virtual void setOverrideColor(video::SColor color); virtual void setOverrideColor(video::SColor color);
//! Sets another color for the background.
virtual void setBackgroundColor(video::SColor color);
//! Sets whether to draw the background
virtual void setDrawBackground(bool draw);
//! Gets the override color //! Gets the override color
virtual video::SColor const & getOverrideColor(void); virtual video::SColor const & getOverrideColor(void);
...@@ -78,7 +84,7 @@ namespace gui ...@@ -78,7 +84,7 @@ namespace gui
bool WordWrap; bool WordWrap;
bool Background; bool Background;
video::SColor OverrideColor; video::SColor OverrideColor, BGColor;
gui::IGUIFont* OverrideFont; gui::IGUIFont* OverrideFont;
gui::IGUIFont* LastBreakFont; // stored because: if skin changes, line break must be recalculated. gui::IGUIFont* LastBreakFont; // stored because: if skin changes, line break must be recalculated.
......
...@@ -192,7 +192,7 @@ void CGUIWindow::draw() ...@@ -192,7 +192,7 @@ void CGUIWindow::draw()
rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y); rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y);
rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;
IGUIFont* font = skin->getFont(); IGUIFont* font = skin->getFont(EGDF_WINDOW);
if (font) if (font)
font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, cl); font->draw(Text.c_str(), rect, skin->getColor(EGDC_ACTIVE_CAPTION), false, true, cl);
} }
......
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