forked from mirror/openmw-tes3mp
Fix menu/journal/book/scroll buttons when using localised MW-installations
This patch implements a custom widget that can switch its texture on-the-fly, making it obsolete having to use an atlas to get a hover animation. This also removes the predefined size restriction and should now work with all button texture sizes.actorid
parent
ff74f687fb
commit
1718d735b5
@ -0,0 +1,63 @@
|
||||
#include "imagebutton.hpp"
|
||||
|
||||
#include <OgreTextureManager.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
void ImageButton::setPropertyOverride(const std::string &_key, const std::string &_value)
|
||||
{
|
||||
if (_key == "ImageHighlighted")
|
||||
mImageHighlighted = _value;
|
||||
else if (_key == "ImagePushed")
|
||||
mImagePushed = _value;
|
||||
else if (_key == "ImageNormal")
|
||||
{
|
||||
if (mImageNormal == "")
|
||||
{
|
||||
setImageTexture(_value);
|
||||
}
|
||||
mImageNormal = _value;
|
||||
}
|
||||
else
|
||||
ImageBox::setPropertyOverride(_key, _value);
|
||||
}
|
||||
void ImageButton::onMouseSetFocus(Widget* _old)
|
||||
{
|
||||
setImageTexture(mImageHighlighted);
|
||||
ImageBox::onMouseSetFocus(_old);
|
||||
}
|
||||
|
||||
void ImageButton::onMouseLostFocus(Widget* _new)
|
||||
{
|
||||
setImageTexture(mImageNormal);
|
||||
ImageBox::onMouseLostFocus(_new);
|
||||
}
|
||||
|
||||
void ImageButton::onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id)
|
||||
{
|
||||
if (_id == MyGUI::MouseButton::Left)
|
||||
setImageTexture(mImagePushed);
|
||||
|
||||
ImageBox::onMouseButtonPressed(_left, _top, _id);
|
||||
}
|
||||
|
||||
MyGUI::IntSize ImageButton::getRequestedSize()
|
||||
{
|
||||
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName(mImageNormal);
|
||||
if (texture.isNull())
|
||||
{
|
||||
std::cerr << "ImageButton: can't find " << mImageNormal << std::endl;
|
||||
return MyGUI::IntSize(0,0);
|
||||
}
|
||||
return MyGUI::IntSize (texture->getWidth(), texture->getHeight());
|
||||
}
|
||||
|
||||
void ImageButton::onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id)
|
||||
{
|
||||
if (_id == MyGUI::MouseButton::Left)
|
||||
setImageTexture(mImageHighlighted);
|
||||
|
||||
ImageBox::onMouseButtonReleased(_left, _top, _id);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#ifndef MWGUI_IMAGEBUTTON_H
|
||||
#define MWGUI_IMAGEBUTTON_H
|
||||
|
||||
#include "MyGUI_ImageBox.h"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief allows using different image textures depending on the button state
|
||||
*/
|
||||
class ImageButton : public MyGUI::ImageBox
|
||||
{
|
||||
MYGUI_RTTI_DERIVED(ImageButton)
|
||||
|
||||
public:
|
||||
MyGUI::IntSize getRequestedSize();
|
||||
|
||||
protected:
|
||||
virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
|
||||
virtual void onMouseLostFocus(MyGUI::Widget* _new);
|
||||
virtual void onMouseSetFocus(MyGUI::Widget* _old);
|
||||
virtual void onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id);
|
||||
virtual void onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id);
|
||||
|
||||
std::string mImageHighlighted;
|
||||
std::string mImageNormal;
|
||||
std::string mImagePushed;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,51 +0,0 @@
|
||||
[settings]
|
||||
size_x = 512
|
||||
size_y = 512
|
||||
|
||||
[tx_menubook_close_idle.dds]
|
||||
x = 0
|
||||
y = 0
|
||||
|
||||
[tx_menubook_close_over.dds]
|
||||
x = 128
|
||||
y = 0
|
||||
|
||||
[tx_menubook_close_pressed.dds]
|
||||
x = 256
|
||||
y = 0
|
||||
|
||||
[tx_menubook_take_idle.dds]
|
||||
x = 384
|
||||
y = 0
|
||||
|
||||
[tx_menubook_take_over.dds]
|
||||
x = 0
|
||||
y = 32
|
||||
|
||||
[tx_menubook_take_pressed.dds]
|
||||
x = 128
|
||||
y = 32
|
||||
|
||||
[tx_menubook_next_idle.dds]
|
||||
x = 256
|
||||
y = 32
|
||||
|
||||
[tx_menubook_next_over.dds]
|
||||
x = 384
|
||||
y = 32
|
||||
|
||||
[tx_menubook_next_pressed.dds]
|
||||
x = 0
|
||||
y = 64
|
||||
|
||||
[tx_menubook_prev_idle.dds]
|
||||
x = 128
|
||||
y = 64
|
||||
|
||||
[tx_menubook_prev_over.dds]
|
||||
x = 256
|
||||
y = 64
|
||||
|
||||
[tx_menubook_prev_pressed.dds]
|
||||
x = 384
|
||||
y = 64
|
@ -1,95 +0,0 @@
|
||||
[settings]
|
||||
size_x = 512
|
||||
size_y = 512
|
||||
|
||||
|
||||
[menu_newgame.dds]
|
||||
x = 0
|
||||
y = 0
|
||||
|
||||
[menu_newgame_pressed.dds]
|
||||
x = 128
|
||||
y = 0
|
||||
|
||||
[menu_newgame_over.dds]
|
||||
x = 256
|
||||
y = 0
|
||||
|
||||
|
||||
[menu_loadgame.dds]
|
||||
x = 384
|
||||
y = 0
|
||||
|
||||
[menu_loadgame_pressed.dds]
|
||||
x = 0
|
||||
y = 64
|
||||
|
||||
[menu_loadgame_over.dds]
|
||||
x = 128
|
||||
y = 64
|
||||
|
||||
|
||||
[menu_options.dds]
|
||||
x = 256
|
||||
y = 64
|
||||
|
||||
[menu_options_pressed.dds]
|
||||
x = 384
|
||||
y = 64
|
||||
|
||||
[menu_options_over.dds]
|
||||
x = 0
|
||||
y = 128
|
||||
|
||||
|
||||
[menu_credits.dds]
|
||||
x = 128
|
||||
y = 128
|
||||
|
||||
[menu_credits_pressed.dds]
|
||||
x = 256
|
||||
y = 128
|
||||
|
||||
[menu_credits_over.dds]
|
||||
x = 384
|
||||
y = 128
|
||||
|
||||
|
||||
[menu_exitgame.dds]
|
||||
x = 0
|
||||
y = 192
|
||||
|
||||
[menu_exitgame_pressed.dds]
|
||||
x = 128
|
||||
y = 192
|
||||
|
||||
[menu_exitgame_over.dds]
|
||||
x = 256
|
||||
y = 192
|
||||
|
||||
|
||||
[menu_savegame.dds]
|
||||
x = 384
|
||||
y = 192
|
||||
|
||||
[menu_savegame_pressed.dds]
|
||||
x = 0
|
||||
y = 256
|
||||
|
||||
[menu_savegame_over.dds]
|
||||
x = 128
|
||||
y = 256
|
||||
|
||||
|
||||
[menu_return.dds]
|
||||
x = 256
|
||||
y = 256
|
||||
|
||||
[menu_return_pressed.dds]
|
||||
x = 384
|
||||
y = 256
|
||||
|
||||
[menu_return_over.dds]
|
||||
x = 0
|
||||
y = 320
|
||||
|
@ -1,34 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Skin">
|
||||
<Skin name="ReturnButton" size="128 64" texture="textures\menu_return.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="NewButton" size="128 64" texture="textures\menu_newgame.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="SaveButton" size="128 64" texture="textures\menu_savegame.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="LoadButton" size="128 64" texture="textures\menu_loadgame.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="OptionsButton" size="128 64" texture="textures\menu_options.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
<Skin name="ExitButton" size="128 64" texture="textures\menu_exitgame.dds">
|
||||
<BasisSkin type="MainSkin" offset = "0 0 128 64">
|
||||
<State name="normal" offset = "0 0 128 64"/>
|
||||
</BasisSkin>
|
||||
</Skin>
|
||||
</MyGUI>
|
||||
|
@ -1,113 +0,0 @@
|
||||
#include "atlas.hpp"
|
||||
|
||||
#include <OgreRoot.h>
|
||||
#include <OgreSceneManager.h>
|
||||
#include <OgreImage.h>
|
||||
#include <OgreTexture.h>
|
||||
#include <OgreRenderTarget.h>
|
||||
#include <OgreCamera.h>
|
||||
#include <OgreTextureUnitState.h>
|
||||
#include <OgreHardwarePixelBuffer.h>
|
||||
#include <OgreConfigFile.h>
|
||||
#include <OgreStringConverter.h>
|
||||
|
||||
using namespace Ogre;
|
||||
using namespace OEngine::Render;
|
||||
|
||||
void Atlas::createFromFile (const std::string& filename, const std::string& textureName, const std::string& texturePrefix)
|
||||
{
|
||||
ConfigFile file;
|
||||
file.load(filename, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, "\t:=", true);
|
||||
|
||||
Root* root = Ogre::Root::getSingletonPtr();
|
||||
|
||||
SceneManager* sceneMgr = root->createSceneManager(ST_GENERIC);
|
||||
Camera* camera = sceneMgr->createCamera("AtlasCamera");
|
||||
|
||||
int width = StringConverter::parseInt(file.getSetting("size_x", "settings"));
|
||||
int height = StringConverter::parseInt(file.getSetting("size_y", "settings"));
|
||||
|
||||
std::vector<Rectangle2D*> rectangles;
|
||||
int i = 0;
|
||||
|
||||
ConfigFile::SectionIterator seci = file.getSectionIterator();
|
||||
while (seci.hasMoreElements())
|
||||
{
|
||||
Ogre::String sectionName = seci.peekNextKey();
|
||||
seci.getNext();
|
||||
|
||||
if (sectionName == "settings" || sectionName == "")
|
||||
continue;
|
||||
|
||||
MaterialPtr material = MaterialManager::getSingleton().create("AtlasMaterial" + StringConverter::toString(i), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
|
||||
material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
|
||||
material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
|
||||
TextureUnitState* tus = material->getTechnique(0)->getPass(0)->createTextureUnitState(texturePrefix + sectionName);
|
||||
tus->setTextureBorderColour(ColourValue(0, 0, 0, 0));
|
||||
|
||||
Rectangle2D* rect = new Rectangle2D(true);
|
||||
rect->setMaterial("AtlasMaterial" + StringConverter::toString(i));
|
||||
rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);
|
||||
|
||||
int x = StringConverter::parseInt(file.getSetting("x", sectionName));
|
||||
int y = StringConverter::parseInt(file.getSetting("y", sectionName));
|
||||
|
||||
TexturePtr texture = TextureManager::getSingleton().getByName(texturePrefix + sectionName);
|
||||
if (texture.isNull())
|
||||
{
|
||||
std::cerr << "OEngine::Render::Atlas: Can't find texture " << texturePrefix + sectionName << ", skipping..." << std::endl;
|
||||
continue;
|
||||
}
|
||||
int textureWidth = texture->getWidth();
|
||||
int textureHeight = texture->getHeight();
|
||||
|
||||
float left = x/float(width) * 2 - 1;
|
||||
float top = (1-(y/float(height))) * 2 - 1;
|
||||
float right = ((x+textureWidth))/float(width) * 2 - 1;
|
||||
float bottom = (1-((y+textureHeight)/float(height))) * 2 - 1;
|
||||
rect->setCorners(left, top, right, bottom);
|
||||
|
||||
// Use infinite AAB to always stay visible
|
||||
AxisAlignedBox aabInf;
|
||||
aabInf.setInfinite();
|
||||
rect->setBoundingBox(aabInf);
|
||||
|
||||
// Attach background to the scene
|
||||
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode();
|
||||
node->attachObject(rect);
|
||||
|
||||
rectangles.push_back(rect);
|
||||
++i;
|
||||
}
|
||||
|
||||
TexturePtr destTexture = TextureManager::getSingleton().createManual(
|
||||
textureName,
|
||||
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
TEX_TYPE_2D,
|
||||
width, height,
|
||||
0,
|
||||
PF_FLOAT16_RGBA,
|
||||
TU_RENDERTARGET);
|
||||
|
||||
RenderTarget* rtt = destTexture->getBuffer()->getRenderTarget();
|
||||
rtt->setAutoUpdated(false);
|
||||
Viewport* vp = rtt->addViewport(camera);
|
||||
vp->setOverlaysEnabled(false);
|
||||
vp->setShadowsEnabled(false);
|
||||
vp->setBackgroundColour(ColourValue(0,0,0,0));
|
||||
|
||||
rtt->update();
|
||||
|
||||
// remove all the junk we've created
|
||||
for (std::vector<Rectangle2D*>::iterator it=rectangles.begin();
|
||||
it!=rectangles.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
}
|
||||
while (i > 0)
|
||||
{
|
||||
MaterialManager::getSingleton().remove("AtlasMaterial" + StringConverter::toString(i-1));
|
||||
--i;
|
||||
}
|
||||
root->destroySceneManager(sceneMgr);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#ifndef OENGINE_OGRE_ATLAS_HPP
|
||||
#define OENGINE_OGRE_ATLAS_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OEngine
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
|
||||
/// \brief Creates a texture atlas at runtime
|
||||
class Atlas
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param absolute path to file that specifies layout of the texture (positions of the textures it contains)
|
||||
* @param name of the destination texture to save to (in memory)
|
||||
* @param texture directory prefix
|
||||
*/
|
||||
static void createFromFile (const std::string& filename, const std::string& textureName, const std::string& texturePrefix="textures\\");
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue