MyGUI_MaskPickInfo.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_MaskPickInfo.h"
#include "MyGUI_ResourceManager.h"
#include "MyGUI_RenderManager.h"
#include "MyGUI_DataManager.h"
namespace MyGUI
{
bool MaskPickInfo::load(const std::string& _file)
{
if (!DataManager::getInstance().isDataExist(_file))
return false;
RenderManager& render = RenderManager::getInstance();
ITexture* texture = render.createTexture(_file);
texture->loadFromFile(_file);
uint8* buffer = (uint8*)texture->lock(TextureUsage::Read);
if (buffer == nullptr)
{
render.destroyTexture(texture);
return false;
}
size_t pixel_size = texture->getNumElemBytes();
mWidth = texture->getWidth();
mHeight = texture->getHeight();
size_t size = mWidth * mHeight;
mData.resize(size);
size_t pos = 0;
for (size_t pos_pix = 0; pos_pix < size; pos_pix++)
{
bool white = true;
for (size_t in_pix = 0; in_pix < pixel_size; in_pix++)
{
if (0xFF != buffer[pos])
{
white = false;
}
pos++;
}
mData[pos_pix] = white;
}
texture->unlock();
render.destroyTexture(texture);
return true;
}
bool MaskPickInfo::pick(const IntPoint& _point, const IntCoord& _coord) const
{
if ((0 == _coord.width) || (0 == _coord.height))
return false;
int x = ((_point.left * mWidth) - 1) / _coord.width;
int y = ((_point.top * mHeight) - 1) / _coord.height;
return 0 != mData[(size_t)(y * mWidth + x)];
}
bool MaskPickInfo::empty() const
{
return mData.empty();
}
} // namespace MyGUI
MyGUI_DataManager.h
MyGUI_MaskPickInfo.h
MyGUI_Precompiled.h
MyGUI_RenderManager.h
MyGUI_ResourceManager.h
MyGUI::DataManager::getInstance
static DataManager & getInstance()
MyGUI::ITexture
Definition MyGUI_ITexture.h:28
MyGUI::ITexture::getWidth
virtual int getWidth() const =0
MyGUI::ITexture::loadFromFile
virtual void loadFromFile(const std::string &_filename)=0
MyGUI::ITexture::getNumElemBytes
virtual size_t getNumElemBytes() const =0
MyGUI::ITexture::unlock
virtual void unlock()=0
MyGUI::ITexture::getHeight
virtual int getHeight() const =0
MyGUI::ITexture::lock
virtual void * lock(TextureUsage _access)=0
MyGUI::MaskPickInfo::empty
bool empty() const
Definition MyGUI_MaskPickInfo.cpp:72
MyGUI::MaskPickInfo::load
bool load(const std::string &_file)
Definition MyGUI_MaskPickInfo.cpp:16
MyGUI::MaskPickInfo::pick
bool pick(const IntPoint &_point, const IntCoord &_coord) const
Definition MyGUI_MaskPickInfo.cpp:61
MyGUI::RenderManager
Definition MyGUI_RenderManager.h:21
MyGUI::RenderManager::createTexture
virtual ITexture * createTexture(const std::string &_name)=0
MyGUI::RenderManager::destroyTexture
virtual void destroyTexture(ITexture *_texture)=0
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::uint8
uint8_t uint8
Definition MyGUI_Types.h:46
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::TextureUsage::Read
@ Read
Definition MyGUI_RenderFormat.h:105
MyGUI::types::TCoord::height
T height
Definition MyGUI_TCoord.h:23
MyGUI::types::TCoord::width
T width
Definition MyGUI_TCoord.h:22
MyGUI::types::TPoint::left
T left
Definition MyGUI_TPoint.h:19
MyGUI::types::TPoint::top
T top
Definition MyGUI_TPoint.h:20