forked from mirror/openmw-tes3mp
Got rid of the texture rotation hack by rendering the cursor manually.
parent
6238c8d758
commit
d8f2d0195a
@ -0,0 +1,130 @@
|
||||
#include "cursor.hpp"
|
||||
|
||||
#include <MyGUI_PointerManager.h>
|
||||
#include <MyGUI_InputManager.h>
|
||||
#include <MyGUI_RenderManager.h>
|
||||
#include <MyGUI_RotatingSkin.h>
|
||||
#include <MyGUI_Gui.h>
|
||||
|
||||
#include <OgreMath.h>
|
||||
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
|
||||
ResourceImageSetPointerFix::ResourceImageSetPointerFix() :
|
||||
mImageSet(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ResourceImageSetPointerFix::~ResourceImageSetPointerFix()
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceImageSetPointerFix::deserialization(MyGUI::xml::ElementPtr _node, MyGUI::Version _version)
|
||||
{
|
||||
Base::deserialization(_node, _version);
|
||||
|
||||
MyGUI::xml::ElementEnumerator info = _node->getElementEnumerator();
|
||||
while (info.next("Property"))
|
||||
{
|
||||
const std::string& key = info->findAttribute("key");
|
||||
const std::string& value = info->findAttribute("value");
|
||||
|
||||
if (key == "Point")
|
||||
mPoint = MyGUI::IntPoint::parse(value);
|
||||
else if (key == "Size")
|
||||
mSize = MyGUI::IntSize::parse(value);
|
||||
else if (key == "Rotation")
|
||||
mRotation = MyGUI::utility::parseInt(value);
|
||||
else if (key == "Resource")
|
||||
mImageSet = MyGUI::ResourceManager::getInstance().getByName(value)->castType<MyGUI::ResourceImageSet>();
|
||||
}
|
||||
}
|
||||
|
||||
int ResourceImageSetPointerFix::getRotation()
|
||||
{
|
||||
return mRotation;
|
||||
}
|
||||
|
||||
void ResourceImageSetPointerFix::setImage(MyGUI::ImageBox* _image)
|
||||
{
|
||||
if (mImageSet != nullptr)
|
||||
_image->setItemResourceInfo(mImageSet->getIndexInfo(0, 0));
|
||||
}
|
||||
|
||||
void ResourceImageSetPointerFix::setPosition(MyGUI::ImageBox* _image, const MyGUI::IntPoint& _point)
|
||||
{
|
||||
_image->setCoord(_point.left - mPoint.left, _point.top - mPoint.top, mSize.width, mSize.height);
|
||||
}
|
||||
|
||||
MyGUI::ResourceImageSetPtr ResourceImageSetPointerFix:: getImageSet()
|
||||
{
|
||||
return mImageSet;
|
||||
}
|
||||
|
||||
MyGUI::IntPoint ResourceImageSetPointerFix::getHotSpot()
|
||||
{
|
||||
return mPoint;
|
||||
}
|
||||
|
||||
MyGUI::IntSize ResourceImageSetPointerFix::getSize()
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
Cursor::Cursor()
|
||||
{
|
||||
// hide mygui's pointer since we're rendering it ourselves (because mygui's pointer doesn't support rotation)
|
||||
MyGUI::PointerManager::getInstance().setVisible(false);
|
||||
|
||||
MyGUI::PointerManager::getInstance().eventChangeMousePointer += MyGUI::newDelegate(this, &Cursor::onCursorChange);
|
||||
|
||||
mWidget = MyGUI::Gui::getInstance().createWidget<MyGUI::ImageBox>("RotatingSkin",0,0,0,0,MyGUI::Align::Default,"Pointer","");
|
||||
|
||||
onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer());
|
||||
}
|
||||
|
||||
Cursor::~Cursor()
|
||||
{
|
||||
}
|
||||
|
||||
void Cursor::onCursorChange(const std::string &name)
|
||||
{
|
||||
ResourceImageSetPointerFix* imgSetPtr = dynamic_cast<ResourceImageSetPointerFix*>(
|
||||
MyGUI::PointerManager::getInstance().getByName(name));
|
||||
assert(imgSetPtr != NULL);
|
||||
|
||||
MyGUI::ResourceImageSet* imgSet = imgSetPtr->getImageSet();
|
||||
|
||||
std::string texture = imgSet->getIndexInfo(0,0).texture;
|
||||
|
||||
mSize = imgSetPtr->getSize();
|
||||
mHotSpot = imgSetPtr->getHotSpot();
|
||||
|
||||
int rotation = imgSetPtr->getRotation();
|
||||
|
||||
mWidget->setImageTexture(texture);
|
||||
MyGUI::ISubWidget* main = mWidget->getSubWidgetMain();
|
||||
MyGUI::RotatingSkin* rotatingSubskin = main->castType<MyGUI::RotatingSkin>();
|
||||
rotatingSubskin->setCenter(MyGUI::IntPoint(16,16));
|
||||
rotatingSubskin->setAngle(Ogre::Degree(rotation).valueRadians());
|
||||
}
|
||||
|
||||
void Cursor::update()
|
||||
{
|
||||
MyGUI::IntPoint position = MyGUI::InputManager::getInstance().getMousePosition();
|
||||
|
||||
mWidget->setPosition(position - mHotSpot);
|
||||
mWidget->setSize(mSize);
|
||||
}
|
||||
|
||||
void Cursor::setVisible(bool visible)
|
||||
{
|
||||
mWidget->setVisible(visible);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
#ifndef MWGUI_CURSOR_H
|
||||
#define MWGUI_CURSOR_H
|
||||
|
||||
#include <MyGUI_IPointer.h>
|
||||
#include <MyGUI_ResourceImageSet.h>
|
||||
#include <MyGUI_RTTI.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
/// \brief Allows us to get the members of
|
||||
/// ResourceImageSetPointer that we need.
|
||||
/// \example MyGUI::FactoryManager::getInstance().registerFactory<ResourceImageSetPointerFix>("Resource", "ResourceImageSetPointer");
|
||||
/// MyGUI::ResourceManager::getInstance().load("core.xml");
|
||||
class ResourceImageSetPointerFix :
|
||||
public MyGUI::IPointer
|
||||
{
|
||||
MYGUI_RTTI_DERIVED( ResourceImageSetPointerFix )
|
||||
|
||||
public:
|
||||
ResourceImageSetPointerFix();
|
||||
virtual ~ResourceImageSetPointerFix();
|
||||
|
||||
virtual void deserialization(MyGUI::xml::ElementPtr _node, MyGUI::Version _version);
|
||||
|
||||
virtual void setImage(MyGUI::ImageBox* _image);
|
||||
virtual void setPosition(MyGUI::ImageBox* _image, const MyGUI::IntPoint& _point);
|
||||
|
||||
//and now for the whole point of this class, allow us to get
|
||||
//the hot spot, the image and the size of the cursor.
|
||||
virtual MyGUI::ResourceImageSetPtr getImageSet();
|
||||
virtual MyGUI::IntPoint getHotSpot();
|
||||
virtual MyGUI::IntSize getSize();
|
||||
virtual int getRotation();
|
||||
|
||||
private:
|
||||
MyGUI::IntPoint mPoint;
|
||||
MyGUI::IntSize mSize;
|
||||
MyGUI::ResourceImageSetPtr mImageSet;
|
||||
int mRotation; // rotation in degrees
|
||||
};
|
||||
|
||||
class Cursor
|
||||
{
|
||||
public:
|
||||
Cursor();
|
||||
~Cursor();
|
||||
void update ();
|
||||
|
||||
void setVisible (bool visible);
|
||||
|
||||
void onCursorChange (const std::string& name);
|
||||
|
||||
private:
|
||||
MyGUI::ImageBox* mWidget;
|
||||
|
||||
MyGUI::IntSize mSize;
|
||||
MyGUI::IntPoint mHotSpot;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,16 +0,0 @@
|
||||
#include "cursorreplace.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <openengine/ogre/imagerotate.hpp>
|
||||
|
||||
#include <OgreResourceGroupManager.h>
|
||||
#include <OgreRoot.h>
|
||||
|
||||
using namespace MWGui;
|
||||
|
||||
CursorReplace::CursorReplace()
|
||||
{
|
||||
OEngine::Render::ImageRotate::rotate("textures\\tx_cursormove.dds", "mwpointer_vresize.png", 90);
|
||||
OEngine::Render::ImageRotate::rotate("textures\\tx_cursormove.dds", "mwpointer_dresize1.png", -45);
|
||||
OEngine::Render::ImageRotate::rotate("textures\\tx_cursormove.dds", "mwpointer_dresize2.png", 45);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#ifndef GAME_CURSORREPLACE_H
|
||||
#define GAME_CURSORREPLACE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
/// \brief MyGUI does not support rotating cursors, so we have to do it manually
|
||||
class CursorReplace
|
||||
{
|
||||
public:
|
||||
CursorReplace();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue