MyGUI: MyGUI_MaskPickInfo.cpp Source File

MyGUI 3.2.2

MyGUI_MaskPickInfo.cpp
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #include "MyGUI_Precompiled.h"
8 #include "MyGUI_MaskPickInfo.h"
9 #include "MyGUI_ResourceManager.h"
10 #include "MyGUI_RenderManager.h"
11 #include "MyGUI_DataManager.h"
12
13 namespace MyGUI
14 {
15
16 MaskPickInfo::MaskPickInfo() :
17 mWidth(0),
18 mHeight(0)
19 {
20 }
21
22 bool MaskPickInfo::load(const std::string& _file)
23 {
24 if (!DataManager::getInstance().isDataExist(_file))
25 return false;
26
27 RenderManager& render = RenderManager::getInstance();
28 ITexture* texture = render.createTexture(_file);
29 texture->loadFromFile(_file);
30
31 uint8* buffer = (uint8*)texture->lock(TextureUsage::Read);
32 if (buffer == 0)
33 {
34 render.destroyTexture(texture);
35 return false;
36 }
37
38 size_t pixel_size = texture->getNumElemBytes();
39
40 mWidth = texture->getWidth();
41 mHeight = texture->getHeight();
42 size_t size = mWidth * mHeight;
43 mData.resize(size);
44
45 size_t pos = 0;
46 for (size_t pos_pix = 0; pos_pix < size; pos_pix++)
47 {
48 bool white = true;
49 for (size_t in_pix = 0; in_pix < pixel_size; in_pix++)
50 {
51 if (0xFF != buffer[pos])
52 {
53 white = false;
54 }
55 pos++;
56 }
57
58 mData[pos_pix] = white;
59 }
60
61 texture->unlock();
62 render.destroyTexture(texture);
63
64 return true;
65 }
66
67 bool MaskPickInfo::pick(const IntPoint& _point, const IntCoord& _coord) const
68 {
69 if ((0 == _coord.width) || (0 == _coord.height)) return false;
70
71 int x = ((_point.left * mWidth) - 1) / _coord.width;
72 int y = ((_point.top * mHeight) - 1) / _coord.height;
73
74 return 0 != mData[(size_t)(y * mWidth + x)];
75 }
76
77 bool MaskPickInfo::empty() const
78 {
79 return mData.empty();
80 }
81
82 } // namespace MyGUI
MyGUI::MaskPickInfo::MaskPickInfo
MaskPickInfo()
Definition: MyGUI_MaskPickInfo.cpp:16
MyGUI::Singleton< DataManager >::getInstance
static DataManager & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI_DataManager.h
MyGUI::ITexture::loadFromFile
virtual void loadFromFile(const std::string &_filename)=0
MyGUI::MaskPickInfo::load
bool load(const std::string &_file)
Definition: MyGUI_MaskPickInfo.cpp:22
MyGUI::ITexture::getWidth
virtual int getWidth()=0
MyGUI::types::TPoint::top
T top
Definition: MyGUI_TPoint.h:21
MyGUI::RenderManager
Definition: MyGUI_RenderManager.h:20
MyGUI::ITexture::getNumElemBytes
virtual size_t getNumElemBytes()=0
MyGUI_ResourceManager.h
MyGUI::ITexture::unlock
virtual void unlock()=0
MyGUI::ITexture::lock
virtual void * lock(TextureUsage _access)=0
MyGUI::types::TPoint< int >
MyGUI::RenderManager::createTexture
virtual ITexture * createTexture(const std::string &_name)=0
MyGUI_MaskPickInfo.h
MyGUI::MaskPickInfo::pick
bool pick(const IntPoint &_point, const IntCoord &_coord) const
Definition: MyGUI_MaskPickInfo.cpp:67
MyGUI_Precompiled.h
MyGUI::TextureUsage::Read
Definition: MyGUI_RenderFormat.h:92
MyGUI::RenderManager::destroyTexture
virtual void destroyTexture(ITexture *_texture)=0
MyGUI::ITexture::getHeight
virtual int getHeight()=0
MyGUI::types::TPoint::left
T left
Definition: MyGUI_TPoint.h:20
MyGUI::MaskPickInfo::empty
bool empty() const
Definition: MyGUI_MaskPickInfo.cpp:77
MyGUI::uint8
unsigned char uint8
Definition: MyGUI_Types.h:46
MyGUI::ITexture
Definition: MyGUI_ITexture.h:26
MyGUI_RenderManager.h
MyGUI::types::TCoord::width
T width
Definition: MyGUI_TCoord.h:24
MyGUI::types::TCoord< int >
MyGUI::types::TCoord::height
T height
Definition: MyGUI_TCoord.h:25
MyGUI
Definition: MyGUI_ActionController.h:14