Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSTextarea.h

Go to the documentation of this file.
00001 #ifndef CSTextarea_h
00002 #define CSTextarea_h
00003 
00004 // USES SDL_Surface
00005 
00006 #ifdef WIN32
00007 #pragma warning(disable : 4786 )
00008 #endif
00009 
00010 #include <vector>
00011 #include <string>
00012 #include <map>
00013 #include "CSTypes.h"
00014 
00015 #include "CSGrafikElement.h"
00016 #include "CSLog.h"
00017 #include "CSTypes.h"
00018 #include "CSStringlist.h"
00019 
00020 class CSTextarea;
00021 typedef std::vector<CSTextarea *> CSTextareas;
00022 
00023 class CSTextarea : public CSGrafikElement
00024 {
00025     private:
00026         std::string mString;
00027         CSStringlist mLines;
00028         std::string mWorkingString;
00029         init(const std::string &text);
00030         float mTickTimeNext;
00031         float mCursorRate;
00032         bool mCursorShown;
00033         int mCursorX;   // in characters whole text
00034         int mCursorY;
00035         signed int mExactCursorX;   // in pixel - in relation to textarea only screen!
00036         signed int mExactCursorY;
00037 
00038         int mVerticalDisplayStart;          // offset where the displayed text starts (which) line!
00039         int mVerticalDisplayEnd;
00040         int mVerticalDisplayLengthChar;
00041         int mHorizontalDisplayStart;
00042         int mHorizontalDisplayEnd;
00043         int mHorizontalDisplayLengthChar;
00044         bool mIsEditable;
00045 
00046         void buildLines();
00047         void buildString();
00048         void setGrafikCursor(int x, int y); // in pixel relative to textarea! (position in viewport relation)
00049         void setTextCursor(int x, int y);   // in characters relative to complete text
00050         void deleteCharAtPos(int p);
00051         void insertCharAtPos(int p, char ch);
00052 
00053     protected:
00054         void layoutSetupTextarea();
00055     public:
00056         CSTextarea(int height, int width);
00057         virtual ~CSTextarea() {}
00058         static const char *CLASS;
00059         virtual std::string getType() {return (std::string) CLASS;}
00060 
00061         virtual void setText(const std::string text);
00062         virtual void setText(const CSStringlist &lines) {mLines = lines;}
00063         
00064         // lines are seperated by a "/n"
00065         virtual void setMultiLineText(const std::string text) 
00066         {
00067             mLines.clear();
00068             char *copy = strdup(text.c_str());
00069             char *tmp = copy;
00070             
00071             char *pointerToWord = strtok( copy, "\n");
00072             while (pointerToWord != 0)
00073             {
00074                 mLines.add(std::string(pointerToWord));
00075                 pointerToWord = strtok( 0, " \n\t");
00076             }
00077             free(tmp);
00078         }
00079         
00080         void reactOnMessageTextarea(CSMessage *message);
00081         virtual void reactOnMessage(CSMessage *message);
00082 
00083         void setEditable(bool b) {mIsEditable = b;}
00084 
00085         virtual void paint(SDL_Surface *destination, SDL_Rect *parentViewport);
00086         virtual void putString(SDL_Surface *destination, SDL_Rect *viewport, int x, int y, const std::string &string);
00087         virtual void layoutSetup() {layoutSetupTextarea();}
00088 };
00089 
00090 #endif // CSTextarea_h

Generated on Wed Jul 14 00:43:42 2004 for CSLib by doxygen 1.3.6