mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 20:56:39 +00:00 
			
		
		
		
	Added description below the cell id (name if exists, or region)
This commit is contained in:
		
							parent
							
								
									7640875f9d
								
							
						
					
					
						commit
						0cccdfd114
					
				
					 3 changed files with 25 additions and 5 deletions
				
			
		|  | @ -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); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue