- Main Page
- Classes
- Files
- Directories
- Related Pages

# textbox.h

    00001 /*--License:
    00002         Kyra Sprite Engine
    00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
    00004         www.grinninglizard.com/kyra
    00005         www.sourceforge.net/projects/kyra
    00006
    00007         Kyra is provided under the LGPL.
    00008
    00009         I kindly request you display a splash screen (provided in the HTML documentation)
    00010         to promote Kyra and acknowledge the software and everyone who has contributed to it,
    00011         but it is not required by the license.
    00012
    00013 --- LGPL License --
    00014
    00015     This library is free software; you can redistribute it and/or
    00016     modify it under the terms of the GNU Lesser General Public
    00017     License as published by the Free Software Foundation; either
    00018     version 2.1 of the License, or (at your option) any later version.
    00019
    00020     This library is distributed in the hope that it will be useful,
    00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00023     Lesser General Public License for more details.
    00024
    00025     You should have received a copy of the GNU Lesser General Public
    00026     License along with this library; if not, write to the Free Software
    00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00028
    00029         The full text of the license can be found in lgpl.txt
    00030 */
    00031
    00032 #ifndef KYRA_TEXT_INCLUDED
    00033 #define KYRA_TEXT_INCLUDED
    00034
    00035 #include "image.h"
    00036 #include "fontresource.h"
    00037
    00038 class KrSprite;
    00039
    00052 class KrTextBox : public KrImNode
    00053 {
    00054   public:
    00055         enum Alignment
    00056         {
    00057                 LEFT,
    00058                 CENTER,
    00059                 RIGHT
    00060         };
    00068         KrTextBox( KrFontResource* resource,
    00069                            int width, int height,          // set to 0 to be un-bound
    00070                            int lineSpacing,
    00071                            Alignment alignment = LEFT );
    00072
    00073         virtual ~KrTextBox();
    00074
    00076         KrFontResource*  FontResource() { return resource; }
    00077
    00079         int Width()     const   { return width; }
    00081         int Height() const      { return height; }
    00082
    00084         int NumLines() const                                    { return numLines; }
    00086         int GetLineY( int lineNum ) const               { return line[lineNum].dy; }
    00087
    00089         void            SetText16(   const U16*  text, int lineNum );
    00091         const U16*  GetText16( int lineNum ) const                              { return &line[lineNum].str[0]; }
    00093         const std::vector<U16>& GetText16Array( int lineNum ) const  { return line[lineNum].str; }
    00094
    00096         void SetTextChar( const std::string& text, int lineNum );
    00098         void GetTextChar( std::string* buffer, int lineNum );
    00099
    00101         int GetLineLength( int lineNum = 0 )    {       GLASSERT( line[lineNum].str.size() > 0 );
    00102                                                                                                 return line[lineNum].str.size() - 1; }
    00103
    00104         virtual KrImNode* Clone();
    00105
    00106         // ---- Internal ----- //
    00107         virtual KrTextBox* ToTextBox()  { return this; }
    00108         virtual void    AddedtoTree();
    00109         void                    CreateLetters( int index );
    00110         virtual void FlushInvalid( int win, bool cache );
    00111
    00112
    00113   private:
    00114         enum {
    00115                 CHILD_DEPTH = 65536     // Depth where the letters will start.
    00116         };
    00117
    00118         // The collision routines depend on letter->parent->textbox relationship.
    00119         // Be careful changing the tree structure.
    00120         struct TextLine
    00121         {
    00122                 int                                             dy;
    00123                 std::vector<U16>                        str;
    00124                 KrImNode*                               parent;
    00125                 std::vector<KrSprite*>  letter;
    00126                 int                                             width;          // The width of this line. Used for positioning of LEFT, RIGHT, CENTER.
    00127         };
    00128
    00129         int                             width, height;  // Untransformed.
    00130         int                             numLines;               // Number of text lines in the box.
    00131         TextLine*               line;
    00132         KrFontResource* resource;
    00133         Alignment               align;
    00134         int                             lineSpacing;
    00135 };
    00136
    00137 #endif