EditWidget.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2005  The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef EDITWIDGET_H
00020 #define EDITWIDGET_H
00021 
00022 //
00023 // EditWidget. Widget for text input (single or multi-line)
00024 //
00025 
00026 #include "Gump.h"
00027 
00028 #include "Font.h"
00029 
00030 using Pentagram::Font;
00031 
00032 class RenderedText;
00033 
00034 class EditWidget : public Gump
00035 {
00036 public:
00037         ENABLE_RUNTIME_CLASSTYPE();
00038 
00039         EditWidget(int X, int Y, std::string txt, bool gamefont, int fontnum,
00040                            int width, int height, unsigned int maxlength=0,
00041                            bool multiline=false);
00042         virtual ~EditWidget(void);
00043 
00044         virtual void InitGump(Gump* newparent, bool take_focus=true);
00045 
00046         virtual void PaintThis(RenderSurface*, sint32 lerp_factor, bool scaled);
00047         virtual void PaintComposited(RenderSurface* surf, sint32 lerp_factor, sint32 sx, sint32 sy);
00048 
00049         virtual Gump* OnMouseMotion(int mx, int my);
00050         virtual bool OnKeyDown(int key, int mod);
00051         virtual bool OnKeyUp(int key);
00052         virtual bool OnTextInput(int unicode);
00053 
00055         std::string getText() const { return text; }
00056         void setText(const std::string& t);
00057 
00058         enum Message
00059         {
00060                 EDIT_ENTER = 16,
00061                 EDIT_ESCAPE = 17
00062         };
00063 
00064 
00065 protected:
00066         std::string text;
00067         std::string::size_type cursor;
00068         bool gamefont;
00069         int fontnum;
00070         unsigned int maxlength;
00071         bool multiline;
00072 
00073         uint32 cursor_changed;
00074         bool cursor_visible;
00075 
00076         void ensureCursorVisible();
00077         bool textFits(std::string& t);
00078         void renderText();
00079         Pentagram::Font* getFont() const;
00080 
00081         RenderedText* cached_text;
00082 
00083 };
00084 
00085 #endif

Generated on Fri Jul 27 22:27:14 2007 for pentagram by  doxygen 1.4.7