MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI 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 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #include "MyGUI_Precompiled.h" 00023 #include "MyGUI_MaskPickInfo.h" 00024 #include "MyGUI_ResourceManager.h" 00025 #include "MyGUI_RenderManager.h" 00026 #include "MyGUI_DataManager.h" 00027 00028 namespace MyGUI 00029 { 00030 00031 MaskPickInfo::MaskPickInfo() : 00032 width(0), 00033 height(0) 00034 { 00035 } 00036 00037 bool MaskPickInfo::load(const std::string& _file) 00038 { 00039 if (!DataManager::getInstance().isDataExist(_file)) 00040 return false; 00041 00042 RenderManager& render = RenderManager::getInstance(); 00043 ITexture* texture = render.createTexture(_file); 00044 texture->loadFromFile(_file); 00045 00046 uint8* buffer = (uint8*)texture->lock(TextureUsage::Read); 00047 if (buffer == 0) 00048 { 00049 render.destroyTexture(texture); 00050 return false; 00051 } 00052 00053 size_t pixel_size = texture->getNumElemBytes(); 00054 00055 width = texture->getWidth(); 00056 height = texture->getHeight(); 00057 size_t size = width * height; 00058 data.resize(size); 00059 00060 size_t pos = 0; 00061 for (size_t pos_pix = 0; pos_pix < size; pos_pix++) 00062 { 00063 bool white = true; 00064 for (size_t in_pix = 0; in_pix < pixel_size; in_pix++) 00065 { 00066 if (0xFF != buffer[pos]) 00067 { 00068 white = false; 00069 } 00070 pos++; 00071 } 00072 00073 data[pos_pix] = white; 00074 } 00075 00076 texture->unlock(); 00077 render.destroyTexture(texture); 00078 00079 return true; 00080 } 00081 00082 bool MaskPickInfo::pick(const IntPoint& _point, const IntCoord& _coord) const 00083 { 00084 if ((0 == _coord.width) || (0 == _coord.height)) return false; 00085 00086 int x = ((_point.left * width) - 1) / _coord.width; 00087 int y = ((_point.top * height) - 1) / _coord.height; 00088 00089 return 0 != data[(size_t)(y * width + x)]; 00090 } 00091 00092 bool MaskPickInfo::empty() const 00093 { 00094 return data.empty(); 00095 } 00096 00097 } // namespace MyGUI