MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #include "MyGUI_Precompiled.h" 00008 #include "MyGUI_MaskPickInfo.h" 00009 #include "MyGUI_ResourceManager.h" 00010 #include "MyGUI_RenderManager.h" 00011 #include "MyGUI_DataManager.h" 00012 00013 namespace MyGUI 00014 { 00015 00016 MaskPickInfo::MaskPickInfo() : 00017 mWidth(0), 00018 mHeight(0) 00019 { 00020 } 00021 00022 bool MaskPickInfo::load(const std::string& _file) 00023 { 00024 if (!DataManager::getInstance().isDataExist(_file)) 00025 return false; 00026 00027 RenderManager& render = RenderManager::getInstance(); 00028 ITexture* texture = render.createTexture(_file); 00029 texture->loadFromFile(_file); 00030 00031 uint8* buffer = (uint8*)texture->lock(TextureUsage::Read); 00032 if (buffer == 0) 00033 { 00034 render.destroyTexture(texture); 00035 return false; 00036 } 00037 00038 size_t pixel_size = texture->getNumElemBytes(); 00039 00040 mWidth = texture->getWidth(); 00041 mHeight = texture->getHeight(); 00042 size_t size = mWidth * mHeight; 00043 mData.resize(size); 00044 00045 size_t pos = 0; 00046 for (size_t pos_pix = 0; pos_pix < size; pos_pix++) 00047 { 00048 bool white = true; 00049 for (size_t in_pix = 0; in_pix < pixel_size; in_pix++) 00050 { 00051 if (0xFF != buffer[pos]) 00052 { 00053 white = false; 00054 } 00055 pos++; 00056 } 00057 00058 mData[pos_pix] = white; 00059 } 00060 00061 texture->unlock(); 00062 render.destroyTexture(texture); 00063 00064 return true; 00065 } 00066 00067 bool MaskPickInfo::pick(const IntPoint& _point, const IntCoord& _coord) const 00068 { 00069 if ((0 == _coord.width) || (0 == _coord.height)) return false; 00070 00071 int x = ((_point.left * mWidth) - 1) / _coord.width; 00072 int y = ((_point.top * mHeight) - 1) / _coord.height; 00073 00074 return 0 != mData[(size_t)(y * mWidth + x)]; 00075 } 00076 00077 bool MaskPickInfo::empty() const 00078 { 00079 return mData.empty(); 00080 } 00081 00082 } // namespace MyGUI