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

OgreTTYGuiElement.h

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 #ifndef _TTYGuiElement_H__
00027 #define _TTYGuiElement_H__
00028 
00029 #include <deque>
00030 #include "OgreEventListeners.h"
00031 #include "OgreGuiElementPrerequisites.h"
00032 #include "OgreGuiContainer.h"
00033 #include "OgreMaterial.h"
00034 #include "OgreStringConverter.h"
00035 #include "OgreGuiElementFactory.h"
00036 #include "OgreFont.h"
00037 #include "OgreFontManager.h"
00038 #include "OgreScrollBarGuiElement.h"
00039 
00040 namespace Ogre
00041 {
00050     class _OgreGuiElementExport TTYGuiElement : public GuiElement, private ScrollListener
00051     {
00052     public:
00054         TTYGuiElement(const String& name);
00055         ~TTYGuiElement();
00056 
00058         void initialise(void);
00059 
00065         void setCaption( const String& caption );
00066         const String& getCaption() const;
00067 
00073         virtual void appendText(const String &text) { appendText(mTopColour, mBottomColour, text); }
00079         virtual void appendText(const ColourValue& colour, const String &text);
00085         virtual void appendText(const ColourValue& tColour, const ColourValue& bColour, const String &text);
00091         virtual void appendText(const RGBA& tColour, const RGBA& bColour, const String &text);
00092 
00093         virtual void clearText();
00094 
00095         virtual void setScrollBar(ScrollBarGuiElement *scrollBar);
00096         virtual ScrollBarGuiElement* getScrollBar() const { return mScrollBar; }
00097 
00098         virtual void setTextLimit( uint maxChars );
00099         virtual uint getTextLimit() const { return mMaxChars; }
00100 
00101         virtual void setCharHeight( Real height );
00102         virtual Real getCharHeight() const;
00103 
00104         virtual void setSpaceWidth( Real width );
00105         virtual Real getSpaceWidth() const;
00106 
00107         virtual void setFontName( const String& font );
00108         virtual const String& getFontName() const;
00109 
00111         virtual const String& getTypeName(void) const;
00113         void getRenderOperation(RenderOperation& op);
00115         void setMaterialName(const String& matName);
00116 
00123         virtual void setColour(const ColourValue& col);
00124 
00126         virtual const ColourValue& getColour(void) const;
00133         virtual void setColourBottom(const ColourValue& col);
00135         virtual const ColourValue& getColourBottom(void) const;
00142         virtual void setColourTop(const ColourValue& col);
00144         virtual const ColourValue& getColourTop(void) const;
00145 
00147         void setMetricsMode(GuiMetricsMode gmm);
00148 
00150         void _update(void);
00151 
00152         //-----------------------------------------------------------------------------------------
00156         class CmdCaption : public ParamCommand
00157         {
00158         public:
00159             String doGet( const void* target ) const;
00160             void doSet( void* target, const String& val );
00161         };
00162         //-----------------------------------------------------------------------------------------
00166         class CmdCharHeight : public ParamCommand
00167         {
00168         public:
00169             String doGet( const void* target ) const;
00170             void doSet( void* target, const String& val );
00171         };
00172         //-----------------------------------------------------------------------------------------
00176         class CmdSpaceWidth : public ParamCommand
00177         {
00178         public:
00179             String doGet( const void* target ) const;
00180             void doSet( void* target, const String& val );
00181         };
00182         //-----------------------------------------------------------------------------------------
00186         class CmdFontName : public ParamCommand
00187         {
00188         public:
00189             String doGet( const void* target ) const;
00190             void doSet( void* target, const String& val );
00191         };
00192         //-----------------------------------------------------------------------------------------
00196         class CmdColourTop : public ParamCommand
00197         {
00198         public:
00199             String doGet( const void* target ) const;
00200             void doSet( void* target, const String& val );
00201         };
00202         //-----------------------------------------------------------------------------------------
00206         class CmdColourBottom : public ParamCommand
00207         {
00208         public:
00209             String doGet( const void* target ) const;
00210             void doSet( void* target, const String& val );
00211         };
00212         //-----------------------------------------------------------------------------------------
00216         class CmdColour : public ParamCommand
00217         {
00218         public:
00219             String doGet( const void* target ) const;
00220             void doSet( void* target, const String& val );
00221         };
00222         //-----------------------------------------------------------------------------------------
00226         class CmdTextLimit : public ParamCommand
00227         {
00228         public:
00229             String doGet( const void* target ) const;
00230             void doSet( void* target, const String& val );
00231         };
00232         //-----------------------------------------------------------------------------------------
00236         class CmdScrollBar : public ParamCommand
00237         {
00238         public:
00239             String doGet( const void* target ) const;
00240             void doSet( void* target, const String& val );
00241         };
00242 
00243 
00244     protected:
00245 
00246         struct TextBlock {
00247           String text;
00248           RGBA   topColour;
00249           RGBA   bottomColour;
00250           uint   cntLines; // how many screen "lines" this text covers (cached, update if mWidth changes)
00251           uint   cntFaces; // how many faces (triangles) this text requires (cached, update if text changes)
00252           Real   begin;    // window location (side to side) where this text begins
00253           Real   end;      // window location (side to side) where this text ends
00254 
00255           TextBlock(const String &_text, const RGBA &_topColour, const RGBA &_bottomColour)
00256             :text(_text), topColour(_topColour), bottomColour(_bottomColour),
00257              cntLines(0), cntFaces(0), begin(0), end(0) {}
00258         };
00259 
00260         typedef std::deque<TextBlock> TextBlockQueue;
00261 
00263         RenderOperation mRenderOp;
00264 
00266         void addBaseParameters(void);
00267 
00268         static String msTypeName;
00269 
00270         // Command objects
00271         static CmdCharHeight msCmdCharHeight;
00272         static CmdSpaceWidth msCmdSpaceWidth;
00273         static CmdFontName msCmdFontName;
00274         static CmdColour msCmdColour;
00275         static CmdColourTop msCmdColourTop;
00276         static CmdColourBottom msCmdColourBottom;
00277         static CmdTextLimit msCmdTextLimit;
00278         static CmdScrollBar msCmdScrollBar;
00279 
00280 
00281         Font *mpFont;
00282         Real mCharHeight;
00283         ushort mPixelCharHeight;
00284         Real mSpaceWidth;
00285         ushort mPixelSpaceWidth;
00286         uint mAllocSize;
00287 
00289         ColourValue mColourBottom;
00290         ColourValue mColourTop;
00291         RGBA mTopColour;    // cached
00292         RGBA mBottomColour; // cached
00293 
00294         uint mScrLines;                 // number of screen lines (update if mHeight changes)
00295 
00296           // text info
00297         bool mUpdateGeometry;           // whether or not geometry updates are enabled
00298         bool mUpdateGeometryNotVisible; // whether or not to update geometry if not visible
00299         TextBlockQueue mTextBlockQueue; // all text blocks (in order received)
00300         uint mTtlChars;                 // total number of chars stored
00301         uint mMaxChars;                 // a soft limit on the number of chars to store
00302         uint mTtlFaces;                 // total number of faces (triangles) for all text
00303         uint mTtlLines;                 // total number of screen lines covered by all of the text
00304         uint mTopLine;                  // top line
00305         bool mAutoScroll;
00306 
00307         ScrollBarGuiElement *mScrollBar;
00308 
00309 
00311         void checkAndSetUpdateGeometry();
00312         void pruneText();
00313         void updateScrollBar();
00314         void updateTextGeometry(TextBlock &text, Real lineWidth = 0.0);
00315         void updateTextGeometry();
00316         void updateWindowGeometry();
00317 
00319         void checkMemoryAllocation( uint numChar );
00320 
00322             virtual void scrollPerformed(ScrollEvent* e);
00323         virtual void updatePositionGeometry();
00324     };
00325 }
00326 
00327 #endif
00328 

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