MyGUI 3.4.3
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"
10#include "MyGUI_RenderManager.h"
11#include "MyGUI_DataManager.h"
12
13namespace MyGUI
14{
15
16 bool MaskPickInfo::load(const std::string& _file)
17 {
18 if (!DataManager::getInstance().isDataExist(_file))
19 return false;
20
22 ITexture* texture = render.createTexture(_file);
23 texture->loadFromFile(_file);
24
25 uint8* buffer = (uint8*)texture->lock(TextureUsage::Read);
26 if (buffer == nullptr)
27 {
28 render.destroyTexture(texture);
29 return false;
30 }
31
32 size_t pixel_size = texture->getNumElemBytes();
33
34 mWidth = texture->getWidth();
35 mHeight = texture->getHeight();
36 size_t size = mWidth * mHeight;
37 mData.resize(size);
38
39 size_t pos = 0;
40 for (size_t pos_pix = 0; pos_pix < size; pos_pix++)
41 {
42 bool white = true;
43 for (size_t in_pix = 0; in_pix < pixel_size; in_pix++)
44 {
45 if (0xFF != buffer[pos])
46 {
47 white = false;
48 }
49 pos++;
50 }
51
52 mData[pos_pix] = white;
53 }
54
55 texture->unlock();
56 render.destroyTexture(texture);
57
58 return true;
59 }
60
61 bool MaskPickInfo::pick(const IntPoint& _point, const IntCoord& _coord) const
62 {
63 if ((0 == _coord.width) || (0 == _coord.height))
64 return false;
65
66 int x = ((_point.left * mWidth) - 1) / _coord.width;
67 int y = ((_point.top * mHeight) - 1) / _coord.height;
68
69 return 0 != mData[(size_t)(y * mWidth + x)];
70 }
71
73 {
74 return mData.empty();
75 }
76
77} // namespace MyGUI
static DataManager & getInstance()
virtual int getWidth() const =0
virtual void loadFromFile(const std::string &_filename)=0
virtual size_t getNumElemBytes() const =0
virtual void unlock()=0
virtual int getHeight() const =0
virtual void * lock(TextureUsage _access)=0
bool load(const std::string &_file)
bool pick(const IntPoint &_point, const IntCoord &_coord) const
virtual ITexture * createTexture(const std::string &_name)=0
virtual void destroyTexture(ITexture *_texture)=0
static RenderManager & getInstance()
uint8_t uint8
Definition MyGUI_Types.h:46