MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_MaskPickInfo.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_MaskPickInfo.h"
24 #include "MyGUI_ResourceManager.h"
25 #include "MyGUI_RenderManager.h"
26 #include "MyGUI_DataManager.h"
27
28 namespace MyGUI
29 {
30
31 MaskPickInfo::MaskPickInfo() :
32 width(0),
33 height(0)
34 {
35 }
36
37 bool MaskPickInfo::load(const std::string& _file)
38 {
39 if (!DataManager::getInstance().isDataExist(_file))
40 return false;
41
42 RenderManager& render = RenderManager::getInstance();
43 ITexture* texture = render.createTexture(_file);
44 texture->loadFromFile(_file);
45
46 uint8* buffer = (uint8*)texture->lock(TextureUsage::Read);
47 if (buffer == 0)
48 {
49 render.destroyTexture(texture);
50 return false;
51 }
52
53 size_t pixel_size = texture->getNumElemBytes();
54
55 width = texture->getWidth();
56 height = texture->getHeight();
57 size_t size = width * height;
58 data.resize(size);
59
60 size_t pos = 0;
61 for (size_t pos_pix = 0; pos_pix < size; pos_pix++)
62 {
63 bool white = true;
64 for (size_t in_pix = 0; in_pix < pixel_size; in_pix++)
65 {
66 if (0xFF != buffer[pos])
67 {
68 white = false;
69 }
70 pos++;
71 }
72
73 data[pos_pix] = white;
74 }
75
76 texture->unlock();
77 render.destroyTexture(texture);
78
79 return true;
80 }
81
82 bool MaskPickInfo::pick(const IntPoint& _point, const IntCoord& _coord) const
83 {
84 if ((0 == _coord.width) || (0 == _coord.height)) return false;
85
86 int x = ((_point.left * width) - 1) / _coord.width;
87 int y = ((_point.top * height) - 1) / _coord.height;
88
89 return 0 != data[(size_t)(y * width + x)];
90 }
91
92 bool MaskPickInfo::empty() const
93 {
94 return data.empty();
95 }
96
97 } // namespace MyGUI
MyGUI::types::TCoord< int >
MyGUI::ITexture::getNumElemBytes
virtual size_t getNumElemBytes()=0
MyGUI::types::TPoint< int >
MyGUI_Precompiled.h
MyGUI_DataManager.h
MyGUI::Singleton< DataManager >::getInstance
static DataManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::MaskPickInfo::load
bool load(const std::string &_file)
Definition: MyGUI_MaskPickInfo.cpp:37
MyGUI::TextureUsage::Read
Definition: MyGUI_RenderFormat.h:97
MyGUI::ITexture::lock
virtual void * lock(TextureUsage _access)=0
MyGUI::types::TPoint::top
T top
Definition: MyGUI_TPoint.h:36
MyGUI::ITexture::unlock
virtual void unlock()=0
MyGUI::MaskPickInfo::empty
bool empty() const
Definition: MyGUI_MaskPickInfo.cpp:92
MyGUI::types::TCoord::width
T width
Definition: MyGUI_TCoord.h:39
MyGUI_RenderManager.h
MyGUI::types::TPoint::left
T left
Definition: MyGUI_TPoint.h:35
MyGUI_MaskPickInfo.h
MyGUI::ITexture::getHeight
virtual int getHeight()=0
MyGUI::ITexture
Definition: MyGUI_ITexture.h:41
MyGUI_ResourceManager.h
MyGUI::ITexture::loadFromFile
virtual void loadFromFile(const std::string &_filename)=0
MyGUI::uint8
unsigned char uint8
Definition: MyGUI_Types.h:61
MyGUI::RenderManager::createTexture
virtual ITexture * createTexture(const std::string &_name)=0
MyGUI::RenderManager
Definition: MyGUI_RenderManager.h:35
MyGUI::types::TCoord::height
T height
Definition: MyGUI_TCoord.h:40
MyGUI::ITexture::getWidth
virtual int getWidth()=0
MyGUI::MaskPickInfo::MaskPickInfo
MaskPickInfo()
Definition: MyGUI_MaskPickInfo.cpp:31
MyGUI::RenderManager::destroyTexture
virtual void destroyTexture(ITexture *_texture)=0
MyGUI::MaskPickInfo::pick
bool pick(const IntPoint &_point, const IntCoord &_coord) const
Definition: MyGUI_MaskPickInfo.cpp:82