1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*!
@file
@author Albert Semenov
@date 1/2009
*/
#include "Precompiled.h"
#include "PointerManager.h"
#include <MyGUI.h>
#include "ResourceW32Pointer.cpp"
namespace input
{
PointerManager::PointerManager() :
mHwnd(0),
mManagerPointer(true)
{
}
PointerManager::~PointerManager()
{
}
void PointerManager::createPointerManager(size_t _handle)
{
mHwnd = _handle;
MyGUI::PointerManager& manager = MyGUI::PointerManager::getInstance();
manager.setVisible(false);
manager.eventChangeMousePointer += MyGUI::newDelegate(this, &PointerManager::notifyChangeMousePointer);
std::string resourceCategory = MyGUI::ResourceManager::getInstance().getCategoryName();
MyGUI::FactoryManager::getInstance().registerFactory<ResourceW32Pointer>(resourceCategory);
}
void PointerManager::destroyPointerManager()
{
std::string resourceCategory = MyGUI::ResourceManager::getInstance().getCategoryName();
MyGUI::FactoryManager::getInstance().unregisterFactory<ResourceW32Pointer>(resourceCategory);
MyGUI::PointerManager& manager = MyGUI::PointerManager::getInstance();
manager.eventChangeMousePointer -= MyGUI::newDelegate(this, &PointerManager::notifyChangeMousePointer);
}
void PointerManager::setPointerVisible(bool _value)
{
ShowCursor(_value);
}
void PointerManager::notifyChangeMousePointer(const std::string& _name)
{
if (mManagerPointer)
{
setPointer(_name);
}
}
void PointerManager::setPointerHandle(size_t _id)
{
SetClassLongPtr((HWND)mHwnd, GCLP_HCURSOR, (LONG_PTR)_id);
if ((GetCapture() == (HWND)mHwnd)
|| isMouseInClient())
{
::SetCursor((HCURSOR)_id);
}
}
bool PointerManager::isMouseInClient()
{
POINT point = { 0, 0 };
ClientToScreen((HWND)mHwnd, &point);
// x и y всегда 0
RECT client_rect = { 0, 0, 0, 0 };
GetClientRect((HWND)mHwnd, &client_rect);
POINT cursor_point = { 0, 0 };
GetCursorPos(&cursor_point);
bool hor = cursor_point.x >= point.x && cursor_point.x < (point.x + client_rect.right);
bool ver = cursor_point.y >= point.y && cursor_point.y < (point.y + client_rect.bottom);
return hor && ver;
}
void PointerManager::setPointerName(const std::string& _name)
{
mManagerPointer = false;
setPointer(_name);
}
void PointerManager::setPointer(const std::string& _name)
{
MapPointer::iterator iter = mMapGuiPointer.find(_name);
if (iter != mMapGuiPointer.end())
{
setPointerHandle(iter->second);
}
else
{
MyGUI::IResource* resource_generic = MyGUI::ResourceManager::getInstance().getByName(_name, false);
if (resource_generic != nullptr)
{
ResourceW32Pointer* resource = resource_generic->castType<ResourceW32Pointer>(false);
if (resource != nullptr)
{
mMapGuiPointer[_name] = resource->getPointerHandle();
setPointerHandle(resource->getPointerHandle());
}
}
}
}
void PointerManager::loadPointerResources()
{
MyGUI::ResourceManager::getInstance().load("PointersW32.xml");
}
} // namespace input
|