00001 #ifndef CSIcon_h 00002 #define CSIcon_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 00013 #include "CSGrafikElement.h" 00014 #include "CSPicture.h" 00015 #include "CSLog.h" 00016 #include "CSInset.h" 00017 00018 class CSIcon; 00019 typedef std::vector<CSIcon *> CSIcons; 00020 00021 const int ICON_KIND_UNKOWN = -1; 00022 const int ICON_KIND_PICTURE = 0; 00023 const int ICON_KIND_TEXT = 1; 00024 const int ICON_KIND_PAINT = 2; 00025 00026 const int ICON_STATE_UNKOWN = -1; 00027 const int ICON_STATE_ENABLED = 0; 00028 const int ICON_STATE_DISABLED = 1; 00029 const int ICON_STATE_ACTIVATED = 2; 00030 00031 class CSIcon : public CSGrafikElement 00032 { 00033 private: 00034 int mKind; 00035 int mState; 00036 00037 protected: 00038 CSIcon(int kind) : CSGrafikElement(0,0) 00039 { 00040 mKind = kind; 00041 mState = ICON_STATE_ENABLED; 00042 } 00043 00044 int getKind() {return mKind;} 00045 00046 public: 00047 static const char *CLASS; 00048 virtual std::string getType() {return (std::string) CLASS;} 00049 virtual ~CSIcon() {} 00050 void setState(int state) 00051 { 00052 if ((state <= ICON_STATE_UNKOWN) || (state >= ICON_STATE_ACTIVATED)) 00053 return; 00054 mState = state; 00055 } 00056 00057 int getState() {return mState;} 00058 virtual bool isFocusable() {return false;} 00059 virtual void paint(SDL_Surface *destination, SDL_Rect *parentViewport) = 0; 00060 }; 00061 00062 class CSPictureIcon : public CSIcon 00063 { 00064 private: 00065 CSPicture *mEnabledPicture; 00066 CSPicture *mDisabledPicture; 00067 00068 protected: 00069 CSPictureIcon() : CSIcon(ICON_KIND_PICTURE){} 00070 void layoutSetupPictureIcon(); 00071 00072 public: 00073 static const char *CLASS; 00074 virtual std::string getType() {return (std::string) CLASS;} 00075 static CSPictureIcon* buildIcon(std::string enabledPictureFile, std::string disabledPictureFile) 00076 { 00077 CSPictureIcon* icon = 0; 00078 try 00079 { 00080 icon = new CSPictureIcon(); 00081 if (!icon->initIcon(enabledPictureFile, disabledPictureFile)) 00082 { 00083 delete(icon); 00084 icon = 0; 00085 } 00086 } 00087 catch (...) {} 00088 icon->layoutChanged(); 00089 return icon; 00090 } 00091 static CSPictureIcon* buildIcon(CSPicture *picture) 00092 { 00093 CSPictureIcon* icon = 0; 00094 try 00095 { 00096 icon = new CSPictureIcon(); 00097 if (!icon->initIcon(picture)) 00098 { 00099 delete(icon); 00100 icon = 0; 00101 } 00102 } 00103 catch (...) {} 00104 icon->layoutChanged(); 00105 return icon; 00106 } 00107 00108 static CSPictureIcon* buildIcon(std::string enabledPictureFile) 00109 { 00110 CSPictureIcon* icon = 0; 00111 try 00112 { 00113 icon = new CSPictureIcon(); 00114 if (!icon->initIcon(enabledPictureFile, enabledPictureFile)) 00115 { 00116 delete(icon); 00117 icon = 0; 00118 } 00119 } 00120 catch (...) {} 00121 icon->layoutChanged(); 00122 return icon; 00123 } 00124 virtual ~CSPictureIcon(); 00125 bool initIcon(std::string enabledPictureFile, std::string disabledPictureFile); 00126 bool initIcon(CSPicture *picture); 00127 virtual void paint(SDL_Surface *destination, SDL_Rect *parentViewport); 00128 virtual void layoutSetup() {layoutSetupPictureIcon();} 00129 }; 00130 00131 class CSTextIcon : public CSIcon 00132 { 00133 private: 00134 std::string mText; 00135 00136 protected: 00137 CSTextIcon() : CSIcon(ICON_KIND_TEXT) {} 00138 void layoutSetupTextIcon(); 00139 00140 public: 00141 static const char *CLASS; 00142 virtual std::string getType() {return (std::string) CLASS;} 00143 00144 static CSTextIcon* buildIcon(const std::string &text) 00145 { 00146 CSTextIcon* icon = 0; 00147 try 00148 { 00149 icon = new CSTextIcon(); 00150 if (!icon->initIcon(text)) 00151 { 00152 delete(icon); 00153 icon = 0; 00154 } 00155 } 00156 catch (...) {} 00157 icon->layoutChanged(); 00158 return icon; 00159 } 00160 virtual ~CSTextIcon(); 00161 bool initIcon(const std::string &text); 00162 void setText(const std::string &text) 00163 { 00164 if (text.compare(mText) != 0) 00165 { 00166 mText = text;layoutChanged(); 00167 } 00168 } 00169 virtual void paint(SDL_Surface *destination, SDL_Rect *parentViewport); 00170 virtual void layoutSetup() {layoutSetupTextIcon();} 00171 }; 00172 00173 #endif // CSIcon_h 00174