Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreTTYGuiElement.cpp

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002 This source file is a part of OGRE
00003 (Object-oriented Graphics Rendering Engine)
00004 
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This library is free software; you can redistribute it and/or modify it
00011 under the terms of the GNU Lesser General Public License (LGPL) as 
00012 published by the Free Software Foundation; either version 2.1 of the 
00013 License, or (at your option) any later version.
00014 
00015 This library is distributed in the hope that it will be useful, but 
00016 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
00017 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
00018 License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public License 
00021 along with this library; if not, write to the Free Software Foundation, 
00022 Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA or go to
00023 http://www.gnu.org/copyleft/lesser.txt
00024 -------------------------------------------------------------------------*/
00025 
00026 #include "OgreString.h"
00027 #include "OgreGuiManager.h"
00028 #include "OgreTTYGuiElement.h"
00029 #include "OgreRoot.h"
00030 #include "OgreLogManager.h"
00031 #include "OgreOverlayManager.h"
00032 #include "OgreHardwareBufferManager.h"
00033 #include "OgreHardwareVertexBuffer.h"
00034 
00035 namespace Ogre {
00036 
00037 #define DEFAULT_INITIAL_CHARS 12
00038     //---------------------------------------------------------------------
00039     String TTYGuiElement::msTypeName = "TTY";
00040     TTYGuiElement::CmdCharHeight TTYGuiElement::msCmdCharHeight;
00041     TTYGuiElement::CmdSpaceWidth TTYGuiElement::msCmdSpaceWidth;
00042     TTYGuiElement::CmdFontName TTYGuiElement::msCmdFontName;
00043     TTYGuiElement::CmdColour TTYGuiElement::msCmdColour;
00044     TTYGuiElement::CmdColourBottom TTYGuiElement::msCmdColourBottom;
00045     TTYGuiElement::CmdColourTop TTYGuiElement::msCmdColourTop;
00046     TTYGuiElement::CmdScrollBar TTYGuiElement::msCmdScrollBar;
00047     TTYGuiElement::CmdTextLimit TTYGuiElement::msCmdTextLimit;
00048     //---------------------------------------------------------------------
00049     #define POS_TEX_BINDING 0
00050     #define COLOUR_BINDING 1
00051     //---------------------------------------------------------------------
00052     TTYGuiElement::TTYGuiElement(const String& name)
00053         : GuiElement(name)
00054     {
00055         mpFont = 0;
00056 
00057         mColourTop = ColourValue::White;
00058         mColourBottom = ColourValue::White;
00059         Root::getSingleton().convertColourValue(mColourTop, &mTopColour);
00060         Root::getSingleton().convertColourValue(mColourBottom, &mBottomColour);
00061 
00062         mUpdateGeometry = false;
00063         mUpdateGeometryNotVisible = false;
00064         mTtlFaces = 0;
00065         mTtlChars = 0;
00066         mMaxChars = 2048;
00067         mTtlLines = 0;
00068         mTopLine = 0;
00069         mAutoScroll = true;
00070 
00071         mScrollBar = NULL;
00072 
00073         mAllocSize = 0;
00074 
00075         mCharHeight = 0.02;
00076         mPixelCharHeight = 12;
00077         mSpaceWidth = 0;
00078         mPixelSpaceWidth = 0;
00079 
00080         mScrLines = mHeight / mCharHeight;
00081 
00082         if (createParamDictionary("TTYGuiElement"))
00083         {
00084             addBaseParameters();
00085         }
00086     }
00087 
00088     void TTYGuiElement::initialise(void)
00089     {
00090         memset( &mRenderOp, 0, sizeof( mRenderOp ) );
00091 
00092        // Set up the render op
00093         // Combine positions and texture coords since they tend to change together
00094         // since character sizes are different
00095         mRenderOp.vertexData = new VertexData();
00096         VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
00097         size_t offset = 0;
00098         // Positions
00099         decl->addElement(POS_TEX_BINDING, offset, VET_FLOAT3, VES_POSITION);
00100         offset += VertexElement::getTypeSize(VET_FLOAT3);
00101         // Texcoords
00102         decl->addElement(POS_TEX_BINDING, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
00103         offset += VertexElement::getTypeSize(VET_FLOAT2);
00104         // Colours - store these in a separate buffer because they change less often
00105         decl->addElement(COLOUR_BINDING, 0, VET_COLOUR, VES_DIFFUSE);
00106 
00107         mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
00108         mRenderOp.useIndexes = false;
00109         mRenderOp.vertexData->vertexStart = 0;
00110         // Vertex buffer will be created in checkMemoryAllocation
00111 
00112         checkMemoryAllocation( DEFAULT_INITIAL_CHARS );
00113 
00114     }
00115 
00116     void TTYGuiElement::appendText( const ColourValue &colour, const String& text )
00117     {
00118         RGBA sColour;
00119 
00120         Root::getSingleton().convertColourValue(colour, &sColour);
00121 
00122         appendText(sColour, sColour, text);
00123     }
00124     
00125     void TTYGuiElement::appendText( const ColourValue &tColour, const ColourValue& bColour, const String& text )
00126     {
00127         RGBA stColour, sbColour;
00128 
00129         Root::getSingleton().convertColourValue(tColour, &stColour);
00130         Root::getSingleton().convertColourValue(bColour, &sbColour);
00131 
00132         appendText(stColour, sbColour, text);
00133     }
00134 
00135     void TTYGuiElement::appendText( const RGBA &tColour, const RGBA& bColour, const String& text )
00136     {
00137         mTextBlockQueue.push_back(TextBlock(text, tColour, bColour));
00138 
00139         if( mUpdateGeometry )
00140         {
00141             TextBlockQueue::reverse_iterator i, j;
00142 
00143             i = mTextBlockQueue.rbegin();
00144             if( (j = (i + 1)) != mTextBlockQueue.rend() )
00145               updateTextGeometry(*i, j->end);
00146             else
00147               updateTextGeometry(*i);
00148 
00149             mTtlChars += (uint)i->text.size();
00150             mTtlLines += i->cntLines;
00151             mTtlFaces += i->cntFaces;
00152 
00153             pruneText();
00154 
00155             if( mAutoScroll && mTtlLines > mScrLines )
00156                 mTopLine = mTtlLines - mScrLines;
00157 
00158             updateScrollBar();
00159             updateWindowGeometry();
00160         }
00161     }
00162 
00163     void TTYGuiElement::clearText()
00164     {
00165         mTextBlockQueue.clear();
00166         mTtlChars = 0;
00167         mTtlFaces  = 0;
00168         mTtlLines = 0;
00169         mTopLine  = 0;
00170         mAutoScroll = true;
00171 
00172         if( mUpdateGeometry )
00173         {
00174             updateScrollBar();
00175             updateWindowGeometry();
00176         }
00177     }
00178 
00179     void TTYGuiElement::setTextLimit( uint maxChars )
00180     {
00181         mMaxChars = maxChars;
00182 
00183         pruneText();
00184         if ( mUpdateGeometry )
00185         {
00186             updateScrollBar();
00187             updateWindowGeometry();
00188         }
00189     }
00190 
00191     void TTYGuiElement::setScrollBar(ScrollBarGuiElement *scrollBar)
00192     {
00193       if( mScrollBar == scrollBar )
00194         return;
00195 
00196       if( mScrollBar != NULL )
00197       {
00198         mScrollBar->removeScrollListener(this);
00199       }
00200 
00201       mScrollBar = scrollBar;
00202 
00203       if( mScrollBar != NULL )
00204       {
00205           mScrollBar->addScrollListener(this);
00206           updateScrollBar();
00207       }
00208     }
00209 
00210     void TTYGuiElement::scrollPerformed(ScrollEvent* e)
00211     {
00212         if( mUpdateGeometry )
00213         {
00214           mTopLine = e->getTopVisible();
00215           updateWindowGeometry();
00216         }
00217     }
00218 
00219     void TTYGuiElement::checkMemoryAllocation( uint numChars )
00220     {
00221         if( mAllocSize < numChars )
00222         {
00223             // Create and bind new buffers
00224             // Note that old buffers will be deleted automatically through reference counting
00225             
00226             // 6 verts per char since we're doing tri lists without indexes
00227             // Allocate space for positions & texture coords
00228             VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
00229             VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;
00230 
00231             mRenderOp.vertexData->vertexCount = numChars * 6;
00232 
00233             // Create dynamic since text tends to change alot
00234             // positions & texcoords
00235             HardwareVertexBufferSharedPtr vbuf = 
00236                 HardwareBufferManager::getSingleton().
00237                     createVertexBuffer(
00238                         decl->getVertexSize(POS_TEX_BINDING), 
00239                         mRenderOp.vertexData->vertexCount,
00240                         HardwareBuffer::HBU_DYNAMIC);
00241             bind->setBinding(POS_TEX_BINDING, vbuf);
00242 
00243             // colours
00244             vbuf = HardwareBufferManager::getSingleton().
00245                     createVertexBuffer(
00246                         decl->getVertexSize(COLOUR_BINDING), 
00247                         mRenderOp.vertexData->vertexCount,
00248                         HardwareBuffer::HBU_DYNAMIC);
00249             bind->setBinding(COLOUR_BINDING, vbuf);
00250 
00251             mAllocSize = numChars;
00252         }
00253 
00254     }
00255 
00256     void TTYGuiElement::checkAndSetUpdateGeometry()
00257     {
00258       if( mpFont != NULL && mHeight >= mCharHeight && mWidth >= mCharHeight )
00259       {
00260          //if (mVisible || mUpdateGeometryNotVisible)
00261             mUpdateGeometry = true;
00262       }
00263       else
00264       {
00265           mUpdateGeometry = false;
00266           mRenderOp.vertexData->vertexStart = 0; // FIX ME: don't like this here
00267           mRenderOp.vertexData->vertexCount = 0;
00268 
00269       }
00270     }
00271 
00272     void TTYGuiElement::pruneText()
00273     {
00274         TextBlockQueue::iterator i;
00275 
00276         if( (i = mTextBlockQueue.begin()) != mTextBlockQueue.end() )
00277             while( (mTtlChars - i->text.size()) >= mMaxChars )
00278             {
00279                 mTtlChars -= (uint)i->text.size();
00280                 mTtlLines -= i->cntLines;
00281                 mTtlFaces -= i->cntFaces;
00282                 i = mTextBlockQueue.erase(i);
00283             }
00284     }
00285 
00286     void TTYGuiElement::updateScrollBar()
00287     {
00288         if( !mUpdateGeometry || mScrollBar == NULL )
00289             return;
00290         mScrollBar->setLimits(mTopLine, (mScrLines <= mTtlLines ? mScrLines : mTtlLines), mTtlLines);          
00291     }
00292 
00293     void TTYGuiElement::updateTextGeometry(TextBlock &textBlock, Real lineWidth)
00294     {
00295         Real lenLine;    // running length of current line
00296         Real charWidth;  // character width
00297         String::iterator i, iend;
00298         uint cntLines;
00299         uint cntFaces;
00300 
00301         if( !mUpdateGeometry )
00302           return;
00303 
00304         cntLines = 0;
00305         cntFaces = 0;
00306         lenLine  = lineWidth;
00307 
00308         iend = textBlock.text.end();
00309         for( i = textBlock.text.begin(); i != iend; ++i )
00310         {
00311             switch (*i) {
00312             case '\n' :
00313               lenLine   = 0;
00314               charWidth = 0;
00315               ++cntLines;
00316               break;
00317 
00318             case ' ' :
00319               charWidth = mSpaceWidth;
00320               break;
00321 
00322             default :
00323               charWidth = mpFont->getGlyphAspectRatio( *i ) * (mCharHeight * 2.0);
00324               cntFaces += 2;
00325               break;
00326             }
00327 
00328             if( (lenLine + charWidth) > (mWidth * 2.0) ) // because of wrapping
00329             {
00330                 lenLine = 0;
00331                 ++cntLines;
00332             }
00333 
00334             lenLine += charWidth;
00335         }
00336 
00337         textBlock.cntLines = cntLines;
00338         textBlock.cntFaces = cntFaces;
00339         textBlock.begin    = lineWidth;
00340         textBlock.end      = lenLine;
00341     }
00342 
00343     void TTYGuiElement::updateTextGeometry()
00344     {
00345         TextBlockQueue::iterator i;
00346         TextBlockQueue::iterator iend;
00347         Real lineWidth;
00348 
00349             if (!mUpdateGeometry)
00350                 return;
00351 
00352         lineWidth = 0;
00353         mTtlChars = 0;
00354         mTtlLines = 0;
00355         mTtlFaces = 0;
00356 
00357         iend = mTextBlockQueue.end();
00358         for ( i = mTextBlockQueue.begin(); i != iend; ++i )
00359         {
00360             updateTextGeometry(*i, lineWidth);
00361             lineWidth = i->end;
00362 
00363             mTtlChars += (uint)i->text.size();
00364             mTtlLines += i->cntLines;
00365             mTtlFaces += i->cntFaces;
00366         }
00367 
00368         pruneText();
00369 
00370         if (mAutoScroll && mTtlLines > mScrLines)
00371           mTopLine = mTtlLines - mScrLines;
00372     }
00373 
00374 
00379     void TTYGuiElement::updateWindowGeometry()
00380     {
00381         Real *pVert;
00382         Real *pTex;
00383         RGBA *pDest;
00384         Real len;    // running length of current line
00385         uint curLine;
00386         Real height; // character height
00387         Real farLeft;
00388         String::iterator i, iend;
00389         TextBlockQueue::iterator t;
00390         TextBlockQueue::iterator tend;
00391 
00392 
00393         if (!mUpdateGeometry)
00394           return;
00395 
00396         checkMemoryAllocation(mTtlChars);
00397 
00398         height = mCharHeight * 2.0;
00399 
00400         HardwareVertexBufferSharedPtr vbuf = 
00401             mRenderOp.vertexData->vertexBufferBinding->getBuffer(POS_TEX_BINDING);
00402         pVert = static_cast<Real*>( vbuf->lock(HardwareBuffer::HBL_DISCARD) );
00403        
00404         HardwareVertexBufferSharedPtr cbuf = 
00405             mRenderOp.vertexData->vertexBufferBinding->getBuffer(COLOUR_BINDING);
00406         pDest = static_cast<RGBA*>( cbuf->lock(HardwareBuffer::HBL_DISCARD) );
00407 
00408         farLeft = _getDerivedLeft() * 2.0 - 1.0;
00409 
00410         Real left = farLeft;
00411         Real top  = -( (_getDerivedTop() * 2.0 ) - 1.0 );
00412         len       = 0;
00413         curLine   = 0;
00414 
00415         tend = mTextBlockQueue.end();
00416         for ( t = mTextBlockQueue.begin(); t != tend; ++t )
00417         {
00418             if( (curLine + t->cntLines) < mTopLine ) // skip whole text block if not visible
00419             {
00420                 curLine += t->cntLines;
00421                 continue;
00422             }
00423 
00424             left = farLeft + t->begin;
00425             iend = t->text.end();
00426             for( i = t->text.begin(); i != iend; )
00427             {
00428                 if( curLine >= (mTopLine + mScrLines) )
00429                     break;
00430 
00431                 if( *i == '\n' )
00432                 {
00433                     left = farLeft;
00434                     len  = 0;
00435                     if (curLine >= mTopLine)
00436                         top -= height;
00437                     ++curLine;
00438                     ++i;
00439                     continue;
00440                 }
00441 
00442                 if ( *i == ' ') // just leave a gap, no triangle
00443                 {
00444                     left += mSpaceWidth;
00445                     len  += mSpaceWidth;
00446                     ++i;
00447                     continue;
00448                 }
00449 
00450                 Real width = mpFont->getGlyphAspectRatio( *i ) * mCharHeight * 2.0;
00451                 if( (len + width) > (mWidth * 2.0) )
00452                 {
00453                     left = farLeft;
00454                     len  = 0;
00455                     if (curLine >= mTopLine)
00456                       top -= height;
00457                     ++curLine;
00458                     continue;
00459                 }
00460 
00461                 if( curLine < mTopLine )
00462                 {
00463                   left += width;
00464                   len  += width;
00465                   ++i;
00466                   continue;
00467                 }
00468 
00469                 Real u1, u2, v1, v2; 
00470                 mpFont->getGlyphTexCoords( *i, u1, v1, u2, v2 );
00471 
00472                 //-------------------------------------------------------------------------------------
00473                 // First tri
00474                 //
00475                 // Upper left
00476                 *pVert++ = left;
00477                 *pVert++ = top;
00478                 *pVert++ = -1.0;
00479                 *pVert++ = u1;
00480                 *pVert++ = v1;
00481 
00482                 // Bottom left
00483                 *pVert++ = left;
00484                 *pVert++ = top - height;
00485                 *pVert++ = -1.0;
00486                 *pVert++ = u1;
00487                 *pVert++ = v2;
00488 
00489                 // Top right
00490                 *pVert++ = left + width;
00491                 *pVert++ = top;
00492                 *pVert++ = -1.0;
00493                 *pVert++ = u2;
00494                 *pVert++ = v1;
00495 
00496                 //-------------------------------------------------------------------------------------
00497 
00498                 //-------------------------------------------------------------------------------------
00499                 // Second tri
00500                 //
00501                 // Top right (again)
00502                 *pVert++ = left + width;
00503                 *pVert++ = top;
00504                 *pVert++ = -1.0;
00505                 *pVert++ = u2;
00506                 *pVert++ = v1;
00507 
00508                 // Bottom left (again)
00509                 *pVert++ = left;
00510                 *pVert++ = top - height;
00511                 *pVert++ = -1.0;
00512                 *pVert++ = u1;
00513                 *pVert++ = v2;
00514 
00515                 // Bottom right
00516                 *pVert++ = left + width;
00517                 *pVert++ = top - height;
00518                 *pVert++ = -1.0;
00519                 *pVert++ = u2;
00520                 *pVert++ = v2;
00521                 //-------------------------------------------------------------------------------------
00522 
00523                 // First tri (top, bottom, top)
00524                 *pDest++ = t->topColour;
00525                 *pDest++ = t->bottomColour;
00526                 *pDest++ = t->topColour;
00527                 // Second tri (top, bottom, bottom)
00528                 *pDest++ = t->topColour;
00529                 *pDest++ = t->bottomColour;
00530                 *pDest++ = t->bottomColour;
00531 
00532                 left += width;
00533                 len  += width;
00534                 ++i;
00535             }
00536         }
00537 
00538         vbuf->unlock();
00539         cbuf->unlock();
00540     }
00541 
00542 
00547     void TTYGuiElement::updatePositionGeometry()
00548     {
00549         checkAndSetUpdateGeometry();
00550 
00551         if (mUpdateGeometry)
00552         {
00553             mScrLines = mHeight / mCharHeight;
00554             updateTextGeometry();
00555             updateScrollBar();
00556             updateWindowGeometry();
00557         }
00558     }
00559     
00560     void TTYGuiElement::setCaption( const String& caption )
00561     {
00562         mTextBlockQueue.clear();
00563         mTtlChars = 0;
00564         mTtlFaces = 0;
00565         mTtlLines = 0;
00566         mTopLine = 0;
00567         mAutoScroll = true;
00568 
00569         appendText(caption);
00570     }
00571 
00572     const String& TTYGuiElement::getCaption() const
00573     {
00574         return mCaption; // FIX ME: not sure what to do here
00575     }
00576 
00577     void TTYGuiElement::setFontName( const String& font )
00578     {
00579         mpFont = (Font*)FontManager::getSingleton().getByName( font );
00580         mpFont->load();
00581         mpMaterial = mpFont->getMaterial();
00582         mpMaterial->setDepthCheckEnabled(false);
00583         mpMaterial->setLightingEnabled(false);
00584 
00585         mSpaceWidth = mpFont->getGlyphAspectRatio( 'A' ) * (mCharHeight * 2.0);
00586 
00587         checkAndSetUpdateGeometry();
00588         updateTextGeometry();
00589         updateScrollBar();
00590         updateWindowGeometry();
00591     }
00592 
00593     const String& TTYGuiElement::getFontName() const
00594     {
00595         return mpFont->getName();
00596     }
00597 
00598     void TTYGuiElement::setCharHeight( Real height )
00599     {
00600         if (mMetricsMode != GMM_RELATIVE)
00601         {
00602             mPixelCharHeight = height;
00603         }
00604         else
00605         {
00606             mCharHeight = height;
00607         }
00608         mGeomPositionsOutOfDate = true;
00609     }
00610 
00611     Real TTYGuiElement::getCharHeight() const
00612     {
00613         if (mMetricsMode == GMM_PIXELS)
00614         {
00615             return mPixelCharHeight;
00616         }
00617         else
00618         {
00619             return mCharHeight;
00620         };
00621     }
00622 
00623     void TTYGuiElement::setSpaceWidth( Real width )
00624     {
00625         if (mMetricsMode != GMM_RELATIVE)
00626         {
00627             mPixelSpaceWidth = width;
00628         }
00629         else
00630         {
00631             mSpaceWidth = width;
00632         }
00633 
00634         mGeomPositionsOutOfDate = true;
00635     }
00636 
00637     Real TTYGuiElement::getSpaceWidth() const
00638     {
00639         if (mMetricsMode == GMM_PIXELS)
00640         {
00641             return mPixelSpaceWidth;
00642         }
00643         else
00644         {
00645             return mSpaceWidth;
00646         };
00647     }
00648 
00649     //---------------------------------------------------------------------
00650     TTYGuiElement::~TTYGuiElement()
00651     {
00652        delete mRenderOp.vertexData;
00653     }
00654     //---------------------------------------------------------------------
00655     const String& TTYGuiElement::getTypeName(void) const
00656     {
00657         return msTypeName;
00658     }
00659     //---------------------------------------------------------------------
00660     void TTYGuiElement::getRenderOperation(RenderOperation& op)
00661     {
00662         op = mRenderOp;
00663     }
00664     //---------------------------------------------------------------------
00665     void TTYGuiElement::setMaterialName(const String& matName)
00666     {
00667         GuiElement::setMaterialName(matName);
00668         updateWindowGeometry();
00669     }
00670     //---------------------------------------------------------------------
00671     void TTYGuiElement::addBaseParameters(void)
00672     {
00673         GuiElement::addBaseParameters();
00674         ParamDictionary* dict = getParamDictionary();
00675 
00676         dict->addParameter(ParameterDef("char_height", 
00677             "Sets the height of the characters in relation to the screen."
00678             , PT_REAL),
00679             &msCmdCharHeight);
00680 
00681         dict->addParameter(ParameterDef("space_width", 
00682             "Sets the width of a space in relation to the screen."
00683             , PT_REAL),
00684             &msCmdSpaceWidth);
00685 
00686         dict->addParameter(ParameterDef("font_name", 
00687             "Sets the name of the font to use."
00688             , PT_STRING),
00689             &msCmdFontName);
00690 
00691         dict->addParameter(ParameterDef("colour", 
00692             "Sets the colour of the font (a solid colour)."
00693             , PT_STRING),
00694             &msCmdColour);
00695 
00696         dict->addParameter(ParameterDef("colour_bottom", 
00697             "Sets the colour of the font at the bottom (a gradient colour)."
00698             , PT_STRING),
00699             &msCmdColourBottom);
00700 
00701         dict->addParameter(ParameterDef("colour_top", 
00702             "Sets the colour of the font at the top (a gradient colour)."
00703             , PT_STRING),
00704             &msCmdColourTop);
00705 
00706         dict->addParameter(ParameterDef("text_limit", 
00707             "sets a soft limit on the number stored characters."
00708             , PT_STRING),
00709             &msCmdTextLimit);
00710 
00711         dict->addParameter(ParameterDef("scroll_bar", 
00712             "set the controlling scroll bar."
00713             , PT_STRING),
00714             &msCmdScrollBar);
00715     }
00716     //---------------------------------------------------------------------
00717     void TTYGuiElement::setColour(const ColourValue& col)
00718     {
00719         mColourBottom = mColourTop = col;
00720 
00721         Root::getSingleton().convertColourValue(mColourTop, &mTopColour);
00722         mBottomColour = mTopColour;
00723     }
00724     //---------------------------------------------------------------------
00725     const ColourValue& TTYGuiElement::getColour(void) const
00726     {
00727         // Either one
00728         return mColourTop;
00729     }
00730     //---------------------------------------------------------------------
00731     void TTYGuiElement::setColourBottom(const ColourValue& col)
00732     {
00733         mColourBottom = col;
00734         Root::getSingleton().convertColourValue(mColourBottom, &mBottomColour);
00735     }
00736     //---------------------------------------------------------------------
00737     const ColourValue& TTYGuiElement::getColourBottom(void) const
00738     {
00739         return mColourBottom;
00740     }
00741     //---------------------------------------------------------------------
00742     void TTYGuiElement::setColourTop(const ColourValue& col)
00743     {
00744         mColourTop = col;
00745         Root::getSingleton().convertColourValue(mColourTop, &mTopColour);
00746     }
00747     //---------------------------------------------------------------------
00748     const ColourValue& TTYGuiElement::getColourTop(void) const
00749     {
00750         return mColourTop;
00751     }
00752     //-----------------------------------------------------------------------
00753     void TTYGuiElement::setMetricsMode(GuiMetricsMode gmm)
00754     {
00755         GuiElement::setMetricsMode(gmm);
00756         if (gmm != GMM_RELATIVE)
00757         {
00758             mPixelCharHeight = mCharHeight;
00759             mPixelSpaceWidth = mSpaceWidth;
00760         }
00761     }
00762     //-----------------------------------------------------------------------
00763     void TTYGuiElement::_update(void)
00764     {
00765         if (mMetricsMode != GMM_RELATIVE && 
00766             (OverlayManager::getSingleton().hasViewportChanged() || mGeomPositionsOutOfDate))
00767         {
00768             // Recalc character size
00769             Real vpHeight;
00770             vpHeight = (Real) (OverlayManager::getSingleton().getViewportHeight());
00771 
00772             mCharHeight = (Real) mPixelCharHeight / vpHeight;
00773             mSpaceWidth = (Real) mPixelSpaceWidth / vpHeight;
00774             mGeomPositionsOutOfDate = true;
00775             updateScrollBar();
00776             updateWindowGeometry();
00777         }
00778         GuiElement::_update();
00779     }
00780 
00781     //---------------------------------------------------------------------------------------------
00782     // Char height command object
00783     //
00784     String TTYGuiElement::CmdCharHeight::doGet( const void* target ) const
00785     {
00786         return StringConverter::toString( 
00787             static_cast< const TTYGuiElement* >( target )->getCharHeight() );
00788     }
00789     void TTYGuiElement::CmdCharHeight::doSet( void* target, const String& val )
00790     {
00791         static_cast< TTYGuiElement* >( target )->setCharHeight( 
00792             StringConverter::parseReal( val ) );
00793     }
00794     //---------------------------------------------------------------------------------------------
00795     // Space width command object
00796     //
00797     String TTYGuiElement::CmdSpaceWidth::doGet( const void* target ) const
00798     {
00799         return StringConverter::toString( 
00800             static_cast< const TTYGuiElement* >( target )->getSpaceWidth() );
00801     }
00802     void TTYGuiElement::CmdSpaceWidth::doSet( void* target, const String& val )
00803     {
00804         static_cast< TTYGuiElement* >( target )->setSpaceWidth( 
00805             StringConverter::parseReal( val ) );
00806     }
00807     //---------------------------------------------------------------------------------------------
00808 
00809     //---------------------------------------------------------------------------------------------
00810     // Font name command object
00811     //
00812     String TTYGuiElement::CmdFontName::doGet( const void* target ) const
00813     {
00814         return static_cast< const TTYGuiElement* >( target )->getFontName();
00815     }
00816     void TTYGuiElement::CmdFontName::doSet( void* target, const String& val )
00817     {
00818         static_cast< TTYGuiElement* >( target )->setFontName( val );
00819     }
00820     //---------------------------------------------------------------------------------------------
00821     //---------------------------------------------------------------------------------------------
00822     // Colour command object
00823     //
00824     String TTYGuiElement::CmdColour::doGet( const void* target ) const
00825     {
00826         return StringConverter::toString (
00827             static_cast< const TTYGuiElement* >( target )->getColour());
00828     }
00829     void TTYGuiElement::CmdColour::doSet( void* target, const String& val )
00830     {
00831         static_cast< TTYGuiElement* >( target )->setColour( 
00832             StringConverter::parseColourValue(val) );
00833     }
00834     //---------------------------------------------------------------------------------------------
00835     //---------------------------------------------------------------------------------------------
00836     //---------------------------------------------------------------------------------------------
00837     // Top colour command object
00838     //
00839     String TTYGuiElement::CmdColourTop::doGet( const void* target ) const
00840     {
00841         return StringConverter::toString (
00842             static_cast< const TTYGuiElement* >( target )->getColourTop());
00843     }
00844     void TTYGuiElement::CmdColourTop::doSet( void* target, const String& val )
00845     {
00846         static_cast< TTYGuiElement* >( target )->setColourTop( 
00847             StringConverter::parseColourValue(val) );
00848     }
00849     //---------------------------------------------------------------------------------------------
00850     //---------------------------------------------------------------------------------------------
00851     //---------------------------------------------------------------------------------------------
00852     // Bottom colour command object
00853     //
00854     String TTYGuiElement::CmdColourBottom::doGet( const void* target ) const
00855     {
00856         return StringConverter::toString (
00857             static_cast< const TTYGuiElement* >( target )->getColourBottom());
00858     }
00859     void TTYGuiElement::CmdColourBottom::doSet( void* target, const String& val )
00860     {
00861         static_cast< TTYGuiElement* >( target )->setColourBottom( 
00862             StringConverter::parseColourValue(val) );
00863     }
00864     //---------------------------------------------------------------------------------------------
00865     //---------------------------------------------------------------------------------------------
00866     // Text limit command object
00867     //
00868     String TTYGuiElement::CmdTextLimit::doGet( const void* target ) const
00869     {
00870          return StringConverter::toString( 
00871             static_cast< const TTYGuiElement* >( target )->getTextLimit() );
00872 
00873     }
00874     void TTYGuiElement::CmdTextLimit::doSet( void* target, const String& val )
00875     {
00876         static_cast< TTYGuiElement* >( target )->setTextLimit( 
00877             StringConverter::parseInt( val ) );
00878     }
00879     //---------------------------------------------------------------------------------------------
00880     //---------------------------------------------------------------------------------------------
00881     // ScrollBar command object
00882     //
00883     String TTYGuiElement::CmdScrollBar::doGet( const void* target ) const
00884     {
00885         const ScrollBarGuiElement *scrollBar = 
00886             static_cast< const TTYGuiElement* >( target )->getScrollBar();
00887         return (scrollBar != NULL) ? scrollBar->getName() : "";
00888     }
00889     void TTYGuiElement::CmdScrollBar::doSet( void* target, const String& val )
00890     {
00891         ScrollBarGuiElement* scrollBar;
00892         scrollBar = static_cast<ScrollBarGuiElement* >(GuiManager::getSingleton().getGuiElement(val));
00893         static_cast< TTYGuiElement* >( target )->setScrollBar(scrollBar);
00894     }
00895     //---------------------------------------------------------------------------------------------
00896 }

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:53 2004