📄 wg_resource_handle.cpp
字号:
// wg_resource_handle.cpp//// Resource Handle implementation////// Copyright (c) 2002 Rob Wiskow// rob-dev@boxedchaos.com//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//#include "wgui_include_config.h"#include "wg_resource_handle.h"#include "wg_error.h"namespace wGui{std::map<TResourceId, unsigned int> CResourceHandle::m_RefCountMap;std::map<TResourceId, SDL_Surface*> CBitmapResourceHandle::m_BitmapMap;std::map<TResourceId, std::string> CStringResourceHandle::m_StringMap;std::map<TResourceId, SDL_Cursor*> CCursorResourceHandle::m_SDLCursorMap;TResourceId CResourceHandle::m_NextUnusedResourceId = 10000;CResourceHandle::CResourceHandle(TResourceId resId) : m_ResourceId(resId){ if (m_ResourceId == AUTO_CREATE_RESOURCE_ID) { while (m_RefCountMap.find(m_NextUnusedResourceId) != m_RefCountMap.end()) { ++m_NextUnusedResourceId; } m_ResourceId = m_NextUnusedResourceId; ++m_NextUnusedResourceId; } if (m_RefCountMap.find(m_ResourceId) == m_RefCountMap.end() || m_RefCountMap[m_ResourceId] == 0) { m_RefCountMap[m_ResourceId] = 0; } ++m_RefCountMap[m_ResourceId];}CResourceHandle::CResourceHandle(const CResourceHandle& resHandle){ m_ResourceId = resHandle.m_ResourceId; ++m_RefCountMap[m_ResourceId];}CResourceHandle::~CResourceHandle(void){ if (GetRefCount() > 0) { --m_RefCountMap[m_ResourceId]; } else { throw(Wg_Ex_App("CResourceHandle::~CResourceHandle : Trying to decrement refcount of zero!")); }}CBitmapResourceHandle::~CBitmapResourceHandle(void){ if (GetRefCount() == 1 && m_BitmapMap.find(m_ResourceId) != m_BitmapMap.end()) { SDL_FreeSurface(m_BitmapMap[m_ResourceId]); m_BitmapMap.erase(m_ResourceId); }}SDL_Surface* CBitmapResourceHandle::Bitmap(void) const{ return (m_BitmapMap.find(m_ResourceId) != m_BitmapMap.end()) ? m_BitmapMap[m_ResourceId] : 0;}CBitmapFileResourceHandle::CBitmapFileResourceHandle(std::string sFilename) : CBitmapResourceHandle(AUTO_CREATE_RESOURCE_ID), m_sFilename(sFilename){ if (m_BitmapMap.find(m_ResourceId) == m_BitmapMap.end()) { m_BitmapMap[m_ResourceId] = SDL_LoadBMP(m_sFilename.c_str()); }}CStringResourceHandle::~CStringResourceHandle(void){ if (GetRefCount() == 1 && m_StringMap.find(m_ResourceId) != m_StringMap.end()) { m_StringMap.erase(m_ResourceId); }}const std::string CStringResourceHandle::String(void) const{ return (m_StringMap.find(m_ResourceId) != m_StringMap.end()) ? m_StringMap[m_ResourceId] : "";}CCursorResourceHandle::~CCursorResourceHandle(void){ if (GetRefCount() == 1 && m_SDLCursorMap.find(m_ResourceId) != m_SDLCursorMap.end()) { SDL_FreeCursor(m_SDLCursorMap[m_ResourceId]); m_SDLCursorMap.erase(m_ResourceId); }}SDL_Cursor* CCursorResourceHandle::Cursor(void) const{ return (m_SDLCursorMap.find(m_ResourceId) != m_SDLCursorMap.end()) ? m_SDLCursorMap[m_ResourceId] : 0;}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -