1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-01 04:36:41 +00:00

Create hardware cursors in advance (Fixes #2660)

This commit is contained in:
scrawl 2015-07-13 23:36:25 +02:00
parent 5a0af772dd
commit de6dc21552
4 changed files with 36 additions and 40 deletions

View file

@ -235,8 +235,9 @@ namespace MWGui
MyGUI::InputManager::getInstance().eventChangeKeyFocus += MyGUI::newDelegate(this, &WindowManager::onKeyFocusChanged); MyGUI::InputManager::getInstance().eventChangeKeyFocus += MyGUI::newDelegate(this, &WindowManager::onKeyFocusChanged);
// Create all cursors in advance
createCursors();
onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer()); onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer());
mCursorManager->setEnabled(true); mCursorManager->setEnabled(true);
// hide mygui's pointer // hide mygui's pointer
@ -1181,31 +1182,7 @@ namespace MWGui
void WindowManager::onCursorChange(const std::string &name) void WindowManager::onCursorChange(const std::string &name)
{ {
if(!mCursorManager->cursorChanged(name)) mCursorManager->cursorChanged(name);
return; //the cursor manager doesn't want any more info about this cursor
//See if we can get the information we need out of the cursor resource
ResourceImageSetPointerFix* imgSetPtr = dynamic_cast<ResourceImageSetPointerFix*>(MyGUI::PointerManager::getInstance().getByName(name));
if(imgSetPtr != NULL)
{
MyGUI::ResourceImageSet* imgSet = imgSetPtr->getImageSet();
std::string tex_name = imgSet->getIndexInfo(0,0).texture;
osg::ref_ptr<osg::Texture2D> tex = mResourceSystem->getTextureManager()->getTexture2D(tex_name, osg::Texture::CLAMP, osg::Texture::CLAMP);
tex->setUnRefImageDataAfterApply(false); // FIXME?
//everything looks good, send it to the cursor manager
if(tex.valid())
{
Uint8 size_x = imgSetPtr->getSize().width;
Uint8 size_y = imgSetPtr->getSize().height;
Uint8 hotspot_x = imgSetPtr->getHotSpot().left;
Uint8 hotspot_y = imgSetPtr->getHotSpot().top;
int rotation = imgSetPtr->getRotation();
mCursorManager->receiveCursorInfo(name, rotation, tex->getImage(), size_x, size_y, hotspot_x, hotspot_y);
}
}
} }
void WindowManager::popGuiMode() void WindowManager::popGuiMode()
@ -1963,6 +1940,33 @@ namespace MWGui
return Misc::ResourceHelpers::correctTexturePath(path, mResourceSystem->getVFS()); return Misc::ResourceHelpers::correctTexturePath(path, mResourceSystem->getVFS());
} }
void WindowManager::createCursors()
{
MyGUI::ResourceManager::EnumeratorPtr enumerator = MyGUI::ResourceManager::getInstance().getEnumerator();
while (enumerator.next())
{
MyGUI::IResource* resource = enumerator.current().second;
ResourceImageSetPointerFix* imgSetPointer = dynamic_cast<ResourceImageSetPointerFix*>(resource);
if (!imgSetPointer)
continue;
std::string tex_name = imgSetPointer->getImageSet()->getIndexInfo(0,0).texture;
osg::ref_ptr<osg::Texture2D> tex = mResourceSystem->getTextureManager()->getTexture2D(tex_name, osg::Texture::CLAMP, osg::Texture::CLAMP);
if(tex.valid())
{
//everything looks good, send it to the cursor manager
Uint8 size_x = imgSetPointer->getSize().width;
Uint8 size_y = imgSetPointer->getSize().height;
Uint8 hotspot_x = imgSetPointer->getHotSpot().left;
Uint8 hotspot_y = imgSetPointer->getHotSpot().top;
int rotation = imgSetPointer->getRotation();
mCursorManager->createCursor(imgSetPointer->getResourceName(), rotation, tex->getImage(), size_x, size_y, hotspot_x, hotspot_y);
}
}
}
void WindowManager::createTextures() void WindowManager::createTextures()
{ {
{ {

View file

@ -511,6 +511,7 @@ namespace MWGui
void onClipboardRequested(const std::string& _type, std::string& _data); void onClipboardRequested(const std::string& _type, std::string& _data);
void createTextures(); void createTextures();
void createCursors();
void setMenuTransparency(float value); void setMenuTransparency(float value);
}; };
} }

View file

@ -175,23 +175,16 @@ namespace SDLUtil
} }
} }
bool SDLCursorManager::cursorChanged(const std::string& name) void SDLCursorManager::cursorChanged(const std::string& name)
{ {
mCurrentCursor = name; mCurrentCursor = name;
CursorMap::const_iterator curs_iter = mCursorMap.find(name); CursorMap::const_iterator curs_iter = mCursorMap.find(name);
//we have this cursor
if(curs_iter != mCursorMap.end()) if(curs_iter != mCursorMap.end())
{ {
//we have this cursor
_setGUICursor(name); _setGUICursor(name);
return false;
}
else
{
//they should get back to us with more info
return true;
} }
} }
@ -200,7 +193,7 @@ namespace SDLUtil
SDL_SetCursor(mCursorMap.find(name)->second); SDL_SetCursor(mCursorMap.find(name)->second);
} }
void SDLCursorManager::receiveCursorInfo(const std::string& name, int rotDegrees, osg::Image* image, Uint8 size_x, Uint8 size_y, Uint8 hotspot_x, Uint8 hotspot_y) void SDLCursorManager::createCursor(const std::string& name, int rotDegrees, osg::Image* image, Uint8 size_x, Uint8 size_y, Uint8 hotspot_x, Uint8 hotspot_y)
{ {
_createCursorFromResource(name, rotDegrees, image, size_x, size_y, hotspot_x, hotspot_y); _createCursorFromResource(name, rotDegrees, image, size_x, size_y, hotspot_x, hotspot_y);
} }

View file

@ -27,11 +27,9 @@ namespace SDLUtil
/// \brief Tell the manager that the cursor has changed, giving the /// \brief Tell the manager that the cursor has changed, giving the
/// name of the cursor we changed to ("arrow", "ibeam", etc) /// name of the cursor we changed to ("arrow", "ibeam", etc)
/// \return Whether the manager is interested in more information about the cursor virtual void cursorChanged(const std::string &name);
virtual bool cursorChanged(const std::string &name);
/// \brief Follow up a cursorChanged() call with enough info to create an cursor. virtual void createCursor(const std::string &name, int rotDegrees, osg::Image* image, Uint8 size_x, Uint8 size_y, Uint8 hotspot_x, Uint8 hotspot_y);
virtual void receiveCursorInfo(const std::string &name, int rotDegrees, osg::Image* image, Uint8 size_x, Uint8 size_y, Uint8 hotspot_x, Uint8 hotspot_y);
private: private:
void _createCursorFromResource(const std::string &name, int rotDegrees, osg::Image* image, Uint8 size_x, Uint8 size_y, Uint8 hotspot_x, Uint8 hotspot_y); void _createCursorFromResource(const std::string &name, int rotDegrees, osg::Image* image, Uint8 size_x, Uint8 size_y, Uint8 hotspot_x, Uint8 hotspot_y);