00001 // wg_resource_handle.h 00002 // 00003 // Resource handles interface 00004 // 00005 // 00006 // Copyright (c) 2002-2004 Rob Wiskow 00007 // rob-dev@boxedchaos.com 00008 // 00009 // This library is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU Lesser General Public 00011 // License as published by the Free Software Foundation; either 00012 // version 2.1 of the License, or (at your option) any later version. 00013 // 00014 // This library is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 // Lesser General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU Lesser General Public 00020 // License along with this library; if not, write to the Free Software 00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 // 00023 00024 00025 #ifndef _WG_RESOURCE_HANDLE_H_ 00026 #define _WG_RESOURCE_HANDLE_H_ 00027 00028 #include "SDL.h" 00029 #include <map> 00030 #include <string> 00031 00032 namespace wGui 00033 { 00035 typedef long int TResourceId; 00036 00037 const TResourceId AUTO_CREATE_RESOURCE_ID = -2; 00038 const TResourceId INVALID_RESOURCE_ID = -1; 00039 const TResourceId NULL_RESOURCE_ID = 0; 00040 00041 00045 class CResourceHandle 00046 { 00047 public: 00050 CResourceHandle(TResourceId resId); 00051 00054 CResourceHandle(const CResourceHandle& resHandle); 00055 00057 virtual ~CResourceHandle(void); 00058 00061 TResourceId GetResourceId(void) { return m_ResourceId; } 00062 00065 unsigned int GetRefCount(void) { return m_RefCountMap[m_ResourceId]; } 00066 00067 protected: 00069 TResourceId m_ResourceId; 00070 00071 private: 00073 CResourceHandle(void) : m_ResourceId(NULL_RESOURCE_ID) { } 00074 00076 void operator=(CResourceHandle) { } 00077 00079 static std::map<TResourceId, unsigned int> m_RefCountMap; 00080 00082 static TResourceId m_NextUnusedResourceId; 00083 }; 00084 00085 00088 class CBitmapResourceHandle : public CResourceHandle 00089 { 00090 public: 00093 CBitmapResourceHandle(TResourceId resId) : CResourceHandle(resId) { } 00094 00097 CBitmapResourceHandle(const CBitmapResourceHandle& resHandle) : 00098 CResourceHandle(resHandle) { } 00099 00101 virtual ~CBitmapResourceHandle(void); 00102 00105 SDL_Surface* Bitmap(void) const; 00106 00107 protected: 00109 static std::map<TResourceId, SDL_Surface*> m_BitmapMap; 00110 00111 private: 00113 void operator=(CBitmapResourceHandle) { } 00114 }; 00115 00116 00119 class CBitmapFileResourceHandle : public CBitmapResourceHandle 00120 { 00121 public: 00124 CBitmapFileResourceHandle(std::wstring sFilename); 00125 00126 protected: 00127 std::wstring m_sFilename; 00128 00129 private: 00131 void operator=(CBitmapFileResourceHandle) { } 00132 }; 00133 00134 00136 class CStringResourceHandle : public CResourceHandle 00137 { 00138 public: 00141 CStringResourceHandle(TResourceId resId) : CResourceHandle(resId) { } 00142 00145 CStringResourceHandle(const CStringResourceHandle& resHandle) : 00146 CResourceHandle(resHandle) { } 00147 00149 virtual ~CStringResourceHandle(void); 00150 00153 const std::wstring String(void) const; 00154 00155 protected: 00157 static std::map<TResourceId, std::wstring> m_StringMap; 00158 00159 private: 00161 void operator=(CStringResourceHandle) { } 00162 }; 00163 00164 00166 class CCursorResourceHandle : public CResourceHandle 00167 { 00168 public: 00171 CCursorResourceHandle(TResourceId resId) : CResourceHandle(resId) { } 00172 00175 CCursorResourceHandle(const CCursorResourceHandle& resHandle) : 00176 CResourceHandle(resHandle) { } 00177 00179 virtual ~CCursorResourceHandle(void); 00180 00183 SDL_Cursor* Cursor(void) const; 00184 00185 protected: 00187 static std::map<TResourceId, SDL_Cursor*> m_SDLCursorMap; 00188 00189 private: 00191 void operator=(CCursorResourceHandle) { } 00192 }; 00193 00194 } 00195 00196 #endif // _WG_RESOURCE_HANDLE_H 00197