diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUIStaticText.h Irrlicht_starsonata/include/IGUIStaticText.h --- irrlicht-svn-ss/trunk/include/IGUIStaticText.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/IGUIStaticText.h 2008-06-03 07:57:46.000000000 +0200 @@ -59,8 +59,13 @@ namespace gui //! \return true if the override color is enabled, false otherwise virtual bool isOverrideColorEnabled(void) = 0; - //! Sets another color for the background. - virtual void setBackgroundColor(video::SColor color) = 0; + // StarSonata, Micha - this replaces the old setBackgroundColor + //! override the background color + virtual void setBackgroundOverrideColor(const video::SColor &color) = 0; + + // StarSonata, Micha + //! clear the background color override + virtual void clearBackgroundOverrideColor() = 0; //! Sets whether to draw the background virtual void setDrawBackground(bool draw) = 0; @@ -95,6 +100,23 @@ namespace gui \return The width of the text, or the widest broken line. */ virtual s32 getTextWidth(void) = 0; + // Starsonata, Micha + //! scroll a static with wordwrap + //! numberOfLines_ is added to the currently scrolled lines + //! resetting to the orinal state is done with scrollLines(-getScrolledLines()) + virtual void scrollLines(s32 numberOfLines_) = 0; + + // Starsonata, Micha + //! get the amount of lines which are scrolled + virtual s32 getScrolledLines() const = 0; + + // Starsonata, Micha + //! get the number of lines in the static. Will be at least 1. + virtual u32 getLineCount() const = 0; + + // Starsonata, Micha + //! Return the font which is currently used for this element + virtual IGUIFont* getCurrentFont() = 0; }; diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIStaticText.cpp Irrlicht_starsonata/source/Irrlicht/CGUIStaticText.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIStaticText.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIStaticText.cpp 2008-06-03 08:16:18.000000000 +0200 @@ -22,18 +22,16 @@ CGUIStaticText::CGUIStaticText(const wch bool background) : IGUIStaticText(environment, parent, id, rectangle), Border(border), HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_UPPERLEFT), - OverrideColorEnabled(false), WordWrap(false), Background(background), - OverrideColor(video::SColor(101,255,255,255)), BGColor(video::SColor(101,210,210,210)), + OverrideColorEnabled(false), OverrideBgColorEnabled(false), + WordWrap(false), Background(background), + ScrolledLines(0), + OverrideColor(video::SColor(101,255,255,255)), OverrideBgColor(video::SColor(101,210,210,210)), OverrideFont(0), LastBreakFont(0) { #ifdef _DEBUG setDebugName("CGUIStaticText"); #endif - Text = text; - if (environment && environment->getSkin()) - { - BGColor = environment->getSkin()->getColor(gui::EGDC_3D_FACE); - } + setText(text); } @@ -62,7 +60,7 @@ void CGUIStaticText::draw() if (Background) { - driver->draw2DRectangle(BGColor, frameRect, &AbsoluteClippingRect); + driver->draw2DRectangle(OverrideBgColorEnabled ? OverrideBgColor : skin->getColor(gui::EGDC_3D_FACE), frameRect, &AbsoluteClippingRect); } // draw the border @@ -76,9 +74,7 @@ void CGUIStaticText::draw() // draw the text if (Text.size()) { - IGUIFont* font = OverrideFont; - if (!OverrideFont) - font = skin->getFont(); + IGUIFont* font = getCurrentFont(); if (font) { @@ -95,6 +91,12 @@ void CGUIStaticText::draw() font->getDimension(Text.c_str()).Width; } + if ( ScrolledLines ) + { + s32 height = font->getDimension(L"A").Height + font->getKerningHeight(); + frameRect.UpperLeftCorner.Y += ScrolledLines * height; + } + font->draw(Text.c_str(), frameRect, OverrideColorEnabled ? OverrideColor : skin->getColor(IsEnabled ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER, &AbsoluteClippingRect); @@ -116,6 +118,8 @@ void CGUIStaticText::draw() r.UpperLeftCorner.Y = r.LowerRightCorner.Y - totalHeight; } + r.UpperLeftCorner.Y += ScrolledLines * height; + for (u32 i=0; igetFont(); - + IGUIFont* font = getCurrentFont(); if (!font) return; @@ -276,7 +281,7 @@ void CGUIStaticText::breakText() c = ' '; } - if (c == L' ' || c == 0 || i == (size-1)) + if (c == L' ' || c == 0 /*|| i == (size-1)*/) { if (word.size()) { @@ -325,8 +330,25 @@ void CGUIStaticText::breakText() } } + + s32 whitelgth = font->getDimension(whitespace.c_str()).Width; + s32 worldlgth = font->getDimension(word.c_str()).Width; + + if (length + worldlgth + whitelgth > elWidth) + { + // break to next line + length = worldlgth; + BrokenText.push_back(line); + line = word; + } + else + { + // add word to line line += whitespace; line += word; + length += whitelgth + worldlgth; + } + BrokenText.push_back(line); } @@ -334,6 +356,7 @@ void CGUIStaticText::breakText() //! Sets the new caption of this element. void CGUIStaticText::setText(const wchar_t* text) { + ScrolledLines = 0; IGUIElement::setText(text); breakText(); } @@ -353,10 +376,7 @@ s32 CGUIStaticText::getTextHeight() if (!skin) return 0; - IGUIFont* font = OverrideFont; - if (!OverrideFont) - font = skin->getFont(); - + IGUIFont* font = getCurrentFont(); if (!font) return 0; @@ -371,15 +391,7 @@ s32 CGUIStaticText::getTextHeight() s32 CGUIStaticText::getTextWidth() { - IGUIFont * font = OverrideFont; - - if(!OverrideFont) - { - IGUISkin * skin = Environment->getSkin(); - if(skin) - font = skin->getFont(); - } - + IGUIFont * font = getCurrentFont(); if(!font) return 0; @@ -403,7 +415,37 @@ s32 CGUIStaticText::getTextWidth() } } +// scroll a a multi-line static +// Setting the topline would be: lineScroll( -getFirstVisibleLine() ) +void CGUIStaticText::scrollLines(s32 numberOfLines_) +{ + ScrolledLines += numberOfLines_; +} + +// get the currently top-visible line +s32 CGUIStaticText::getScrolledLines() const +{ + return ScrolledLines; +} + +//! get the number of lines in the static. Will be at least 1. +u32 CGUIStaticText::getLineCount() const +{ + return BrokenText.size(); +} + +// Starsonata, Micha +//! Return the font which is currently used for this element +IGUIFont* CGUIStaticText::getCurrentFont() +{ + if ( OverrideFont ) + return OverrideFont; + IGUISkin* skin = Environment->getSkin(); + if (!skin) + return NULL; + return skin->getFont(); +} //! Writes attributes of the element. //! Implement this to expose the attributes of your element for @@ -413,14 +455,18 @@ void CGUIStaticText::serializeAttributes IGUIStaticText::serializeAttributes(out,options); out->addBool ("Border", Border); - out->addBool ("OverrideColorEnabled", OverrideColorEnabled); out->addBool ("WordWrap", WordWrap); out->addBool ("Background", Background); + out->addBool ("OverrideColorEnabled", OverrideColorEnabled); out->addColor ("OverrideColor", OverrideColor); + out->addBool ("OverrideBgColorEnabled", OverrideBgColorEnabled); + out->addColor ("OverrideBgColor", OverrideBgColor); out->addEnum ("HTextAlign", HAlign, GUIAlignmentNames); out->addEnum ("VTextAlign", VAlign, GUIAlignmentNames); + out->addInt ("ScrolledLines", ScrolledLines); - // out->addFont ("OverrideFont", OverrideFont); + if ( OverrideFont && OverrideFont->getName().size() ) + out->addString("OverrideFont", OverrideFont->getName().c_str() ); } //! Reads attributes of the element @@ -430,16 +476,22 @@ void CGUIStaticText::deserializeAttribut IGUIStaticText::deserializeAttributes(in,options); Border = in->getAttributeAsBool ("Border"); - OverrideColor = in->getAttributeAsBool("OverrideColor"); - + OverrideColor = in->getAttributeAsColor("OverrideColor"); enableOverrideColor(in->getAttributeAsBool("OverrideColorEnabled")); + OverrideBgColor = in->getAttributeAsColor("OverrideBgColor"); + OverrideBgColorEnabled = in->getAttributeAsBool("OverrideBgColorEnabled"); setWordWrap(in->getAttributeAsBool("WordWrap")); Background = in->getAttributeAsBool("Background"); setTextAlignment( (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("HTextAlign", GUIAlignmentNames), (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("VTextAlign", GUIAlignmentNames)); + ScrolledLines = in->getAttributeAsInt("ScrolledLines"); - // OverrideFont = in->getAttributeAsFont("OverrideFont"); + core::stringc fontName = in->getAttributeAsString("OverrideFont"); + if ( fontName.size() ) + { + setOverrideFont( Environment->getFont(fontName.c_str()) ); + } } diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIStaticText.h Irrlicht_starsonata/source/Irrlicht/CGUIStaticText.h --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIStaticText.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIStaticText.h 2008-06-03 08:02:02.000000000 +0200 @@ -36,8 +36,14 @@ namespace gui //! Sets another color for the text. virtual void setOverrideColor(video::SColor color); - //! Sets another color for the background. - virtual void setBackgroundColor(video::SColor color); + // StarSonata, Micha - this replaces the old setBackgroundColor + //! override the background color + virtual void setBackgroundOverrideColor(const video::SColor &color); + + // StarSonata, Micha + //! clear the background color override + virtual void clearBackgroundOverrideColor(); + //! Sets whether to draw the background virtual void setDrawBackground(bool draw); @@ -77,6 +83,25 @@ namespace gui //! Updates the absolute position, splits text if word wrap is enabled virtual void updateAbsolutePosition(); + // Starsonata, Micha + //! scroll a static which has wordwrap enabled + //! numberOfLines_ is added to the currently scrolled lines + //! Resetting to the original state is done with scrollLines(-getScrolledLines()) + //! Scrolled lines are also resetted when the text of the static is changed. + virtual void scrollLines(s32 numberOfLines_); + + // Starsonata, Micha + //! get the amount of lines which are scrolled + virtual s32 getScrolledLines() const; + + // Starsonata, Micha + //! get the number of lines in the static. Will be at least 1. + virtual u32 getLineCount() const; + + // Starsonata, Micha + //! Return the font which is currently used for this element + virtual IGUIFont* getCurrentFont(); + //! Writes attributes of the element. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options); @@ -91,10 +116,13 @@ namespace gui bool Border; EGUI_ALIGNMENT HAlign, VAlign; bool OverrideColorEnabled; + bool OverrideBgColorEnabled; bool WordWrap; bool Background; + s32 ScrolledLines; - video::SColor OverrideColor, BGColor; + video::SColor OverrideColor; + video::SColor OverrideBgColor; gui::IGUIFont* OverrideFont; gui::IGUIFont* LastBreakFont; // stored because: if skin changes, line break must be recalculated. diff -abBpNPwrU2 --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIEnvironment.cpp Irrlicht_starsonata/source/Irrlicht/CGUIEnvironment.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIEnvironment.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIEnvironment.cpp 2008-08-15 18:20:47.000000000 +0200 @@ -400,5 +418,5 @@ void CGUIEnvironment::OnPostRender( u32 ToolTip.Element = addStaticText(Hovered->getToolTipText().c_str(), pos, true, true, this, -1, true); ToolTip.Element->setOverrideColor(getSkin()->getColor(EGDC_TOOLTIP)); - ToolTip.Element->setBackgroundColor(getSkin()->getColor(EGDC_TOOLTIP_BACKGROUND)); + ToolTip.Element->setBackgroundOverrideColor(getSkin()->getColor(EGDC_TOOLTIP_BACKGROUND)); ToolTip.Element->setOverrideFont(getSkin()->getFont(EGDF_TOOLTIP)); ToolTip.Element->setSubElement(true);