Main Page   Class Hierarchy   Compound List   File List   Compound Members  

textbox.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2002
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under 2 licenses:
00008 
00009         - The GPL, with no additional restrictions.
00010         - The LGPL, provided you display the Kyra splash screen, described below.
00011 
00012 
00013 --- GPL License --
00014         This program is free software; you can redistribute it and/or
00015         modify it under the terms of the GNU General Public License
00016         as published by the Free Software Foundation; either version 2
00017         of the License, or (at your option) any later version.
00018 
00019         This program is distributed in the hope that it will be useful,
00020         but WITHOUT ANY WARRANTY; without even the implied warranty of
00021         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022         GNU General Public License for more details.
00023 
00024         You should have received a copy of the GNU General Public License
00025         along with this program; if not, write to the Free Software
00026         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028         The full text of the license can be found in license.txt
00029 
00030 
00031 --- LGPL License --
00032   **Provided you kindly display the Kyra splash screen (details below), 
00033         you     may use the LGPL license:**
00034 
00035     This library is free software; you can redistribute it and/or
00036     modify it under the terms of the GNU Lesser General Public
00037     License as published by the Free Software Foundation; either
00038     version 2.1 of the License, or (at your option) any later version.
00039 
00040     This library is distributed in the hope that it will be useful,
00041     but WITHOUT ANY WARRANTY; without even the implied warranty of
00042     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00043     Lesser General Public License for more details.
00044 
00045     You should have received a copy of the GNU Lesser General Public
00046     License along with this library; if not, write to the Free Software
00047     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00048 
00049         The full text of the license can be found in lgpl.txt
00050 
00051 
00052 --- Kyra Splash Screen.
00053 
00054         It would be appreciate if you display the Kyra splash screen when using
00055         either license, however it is only required for the LGPL. All the
00056         resources for the splash are compiled into the library, and it can be
00057         accessed through the following API:
00058 
00059                 KrEngine::StartSplash
00060                 KrEngine::UpdateSplash
00061                 KrEngine::EndSplash
00062 
00063         Full documentation is provided with the KrEngine class. The splash screen
00064         should be displayed for 2 seconds.
00065 
00066         Thank you.
00067 */
00068 
00069 #ifndef KYRA_TEXT_INCLUDED
00070 #define KYRA_TEXT_INCLUDED
00071 
00072 #include "image.h"
00073 #include "fontresource.h"
00074 
00075 class KrSprite;
00076 
00089 class KrTextBox : public KrImNode
00090 {
00091   public:
00092         enum Alignment
00093         {
00094                 LEFT,
00095                 CENTER,
00096                 RIGHT
00097         };
00105         KrTextBox( KrFontResource* resource,
00106                            int width, int height,          // set to 0 to be un-bound
00107                            int lineSpacing,
00108                            Alignment alignment = LEFT );
00109 
00110         virtual ~KrTextBox();
00111 
00113         KrFontResource*  FontResource() { return resource; }
00114 
00116         int Width()     const   { return width; }
00118         int Height() const      { return height; }
00119 
00121         int NumLines() const                                    { return numLines; }
00123         int GetLineY( int lineNum ) const               { return line[lineNum].dy; }
00124 
00126         void            SetText16(   const U16*  text, int lineNum );
00128         const U16*  GetText16( int lineNum ) const                                      { return line[lineNum].str.Memory(); }
00130         const GlDynArray<U16>& GetText16Array( int lineNum ) const  { return line[lineNum].str; }
00131 
00133         void SetTextChar( const std::string& text, int lineNum );
00135         void GetTextChar( std::string* buffer, int lineNum );
00136 
00138         int GetLineLength( int lineNum = 0 )    {       GLASSERT( line[lineNum].str.Count() > 0 ); 
00139                                                                                                 return line[lineNum].str.Count() - 1; }
00140 
00141         virtual KrImNode* Clone();
00142 
00143         // ---- Internal ----- //
00144         virtual KrTextBox* ToTextBox()  { return this; }        
00145         virtual void    AddedtoTree();
00146         void                    CreateLetters( int index );
00147         virtual void FlushInvalid( int win, bool cache );
00148 
00149 
00150   private:
00151         enum {
00152                 CHILD_DEPTH = 65536     // Depth where the letters will start.
00153         };
00154         
00155         // The collision routines depend on letter->parent->textbox relationship.
00156         // Be careful changing the tree structure.
00157         struct TextLine
00158         {
00159                 int                                             dy;
00160                 GlDynArray<U16>                 str;
00161                 KrImNode*                               parent;         
00162                 GlDynArray<KrSprite*>   letter;         
00163                 int                                             width;          // The width of this line. Used for positioning of LEFT, RIGHT, CENTER.
00164         };
00165 
00166         int                             width, height;  // Untransformed.
00167         int                             numLines;               // Number of text lines in the box.
00168         TextLine*               line;
00169         KrFontResource* resource;
00170         Alignment               align;
00171         int                             lineSpacing;
00172 };
00173 
00174 #endif

Generated on Mon Sep 15 12:01:11 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001