diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 03e5e1427..0cccde5cf 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -105,6 +105,9 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells() CSVRender::TextOverlay *textDisp = new CSVRender::TextOverlay(entity, getCamera(), iter->getId(mWorldspace)); textDisp->enable(true); textDisp->setCaption(iter->getId(mWorldspace)); + std::string desc = cells.getRecord(index).get().mName; + if(desc == "") desc = cells.getRecord(index).get().mRegion; + textDisp->setDesc(desc); textDisp->update(); mTextOverlays.push_back(textDisp); diff --git a/apps/opencs/view/render/textoverlay.cpp b/apps/opencs/view/render/textoverlay.cpp index 200f77476..143d08fc4 100644 --- a/apps/opencs/view/render/textoverlay.cpp +++ b/apps/opencs/view/render/textoverlay.cpp @@ -233,6 +233,15 @@ void TextOverlay::setCaption(const Ogre::String& text) mElement->setCaption(text); } +void TextOverlay::setDesc(const Ogre::String& text) +{ + if(mDesc == text) + return; + + mDesc = text; + mElement->setCaption(mCaption + ((text == "") ? "" : ("\n" + text))); +} + Ogre::FontPtr TextOverlay::getFont() { return mFont; @@ -240,15 +249,19 @@ Ogre::FontPtr TextOverlay::getFont() int TextOverlay::textWidth() { - float textWidth = 0; + float captionWidth = 0; + float descWidth = 0; // NOTE: assumed fixed width font, i.e. no compensation for narrow glyphs for(Ogre::String::const_iterator i = mCaption.begin(); i < mCaption.end(); ++i) - textWidth += getFont()->getGlyphAspectRatio(*i); + captionWidth += getFont()->getGlyphAspectRatio(*i); + for(Ogre::String::const_iterator i = mDesc.begin(); i < mDesc.end(); ++i) + descWidth += getFont()->getGlyphAspectRatio(*i); - textWidth *= fontHeight(); + captionWidth *= fontHeight(); + descWidth *= fontHeight(); - return (int) textWidth; + return (int) std::max(captionWidth, descWidth); } int TextOverlay::fontHeight() @@ -278,8 +291,10 @@ void TextOverlay::update() float viewportWidth = std::max(overlayMgr.getViewportWidth(), 1); // zero at the start float viewportHeight = std::max(overlayMgr.getViewportHeight(), 1); // zero at the start - int width = 2*fontHeight()/3 + textWidth() + fontHeight()/3; // 2 = fudge factor + int width = fontHeight()/3 + textWidth() + fontHeight()/3; int height = fontHeight()/3 + fontHeight() + fontHeight()/3; + if(mDesc != "") + height = fontHeight()/3 + 2*fontHeight() + fontHeight()/3; float relTextWidth = width / viewportWidth; float relTextHeight = height / viewportHeight; diff --git a/apps/opencs/view/render/textoverlay.hpp b/apps/opencs/view/render/textoverlay.hpp index 3db36c378..7402e33a0 100644 --- a/apps/opencs/view/render/textoverlay.hpp +++ b/apps/opencs/view/render/textoverlay.hpp @@ -25,6 +25,7 @@ namespace CSVRender Ogre::OverlayContainer* mContainer; Ogre::TextAreaOverlayElement* mElement; Ogre::String mCaption; + Ogre::String mDesc; const Ogre::MovableObject* mObj; const Ogre::Camera* mCamera; @@ -50,6 +51,7 @@ namespace CSVRender void enable(bool enable); bool isEnabled(); void setCaption(const Ogre::String& text); + void setDesc(const Ogre::String& text); void update(); QRect container(); Ogre::String getCaption() { return mCaption; } // FIXME: debug