diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 6ac1f2b63f..e2e2e1ab11 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -257,7 +258,12 @@ namespace MWGui mSelected->id = item.getCellRef().getRefId(); mSelected->name = item.getClass().getName(item); - mSelected->button->setFrame("textures\\menu_icon_select_magic_magic.dds", MyGUI::IntCoord(2, 2, 40, 40)); + float scale = 1.f; + MyGUI::ITexture* texture = MyGUI::RenderManager::getInstance().getTexture("textures\\menu_icon_select_magic_magic.dds"); + if (texture) + scale = texture->getHeight() / 64.f; + + mSelected->button->setFrame("textures\\menu_icon_select_magic_magic.dds", MyGUI::IntCoord(0, 0, 44*scale, 44*scale)); mSelected->button->setIcon(item); mSelected->button->setUserString("ToolTipType", "ItemPtr"); @@ -292,7 +298,12 @@ namespace MWGui path.insert(slashPos+1, "b_"); path = MWBase::Environment::get().getWindowManager()->correctIconPath(path); - mSelected->button->setFrame("textures\\menu_icon_select_magic.dds", MyGUI::IntCoord(2, 2, 40, 40)); + float scale = 1.f; + MyGUI::ITexture* texture = MyGUI::RenderManager::getInstance().getTexture("textures\\menu_icon_select_magic.dds"); + if (texture) + scale = texture->getHeight() / 64.f; + + mSelected->button->setFrame("textures\\menu_icon_select_magic.dds", MyGUI::IntCoord(0, 0, 44*scale, 44*scale)); mSelected->button->setIcon(path); if (mMagicSelectionDialog) diff --git a/components/widgets/imagebutton.cpp b/components/widgets/imagebutton.cpp index 2ea494ebd0..0d1f798da5 100644 --- a/components/widgets/imagebutton.cpp +++ b/components/widgets/imagebutton.cpp @@ -14,6 +14,8 @@ namespace Gui , mMouseFocus(false) , mMousePress(false) , mKeyFocus(false) + , mUseWholeTexture(true) + , mTextureRect(MyGUI::IntCoord(0, 0, 0, 0)) { setNeedKeyFocus(sDefaultNeedKeyFocus); } @@ -23,6 +25,13 @@ namespace Gui sDefaultNeedKeyFocus = enabled; } + void ImageButton::setTextureRect(MyGUI::IntCoord coord) + { + mTextureRect = coord; + mUseWholeTexture = (coord == MyGUI::IntCoord(0, 0, 0, 0)); + updateImage(); + } + void ImageButton::setPropertyOverride(const std::string &_key, const std::string &_value) { if (_key == "ImageHighlighted") @@ -37,6 +46,11 @@ namespace Gui } mImageNormal = _value; } + else if (_key == "TextureRect") + { + mTextureRect = MyGUI::IntCoord::parse(_value); + mUseWholeTexture = (mTextureRect == MyGUI::IntCoord(0, 0, 0, 0)); + } else ImageBox::setPropertyOverride(_key, _value); } @@ -66,12 +80,25 @@ namespace Gui void ImageButton::updateImage() { + std::string textureName = mImageNormal; if (mMousePress) - setImageTexture(mImagePushed); + textureName = mImagePushed; else if (mMouseFocus || mKeyFocus) - setImageTexture(mImageHighlighted); - else - setImageTexture(mImageNormal); + textureName = mImageHighlighted; + + if (!mUseWholeTexture) + { + int scale = 1.f; + MyGUI::ITexture* texture = MyGUI::RenderManager::getInstance().getTexture(textureName); + if (texture && getHeight() != 0) + scale = texture->getHeight() / getHeight(); + + setImageTile(MyGUI::IntSize(mTextureRect.width * scale, mTextureRect.height * scale)); + MyGUI::IntCoord scaledSize(mTextureRect.left * scale, mTextureRect.top * scale, mTextureRect.width * scale, mTextureRect.height * scale); + setImageCoord(scaledSize); + } + + setImageTexture(textureName); } MyGUI::IntSize ImageButton::getRequestedSize() @@ -82,7 +109,11 @@ namespace Gui Log(Debug::Error) << "ImageButton: can't find image " << mImageNormal; return MyGUI::IntSize(0,0); } - return MyGUI::IntSize (texture->getWidth(), texture->getHeight()); + + if (mUseWholeTexture) + return MyGUI::IntSize(texture->getWidth(), texture->getHeight()); + + return MyGUI::IntSize(mTextureRect.width, mTextureRect.height); } void ImageButton::setImage(const std::string &image) @@ -96,7 +127,7 @@ namespace Gui mImageHighlighted = imageNoExt + "_over" + ext; mImagePushed = imageNoExt + "_pressed" + ext; - setImageTexture(mImageNormal); + updateImage(); } void ImageButton::onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id) diff --git a/components/widgets/imagebutton.hpp b/components/widgets/imagebutton.hpp index bfcff79979..bb2baa91ff 100644 --- a/components/widgets/imagebutton.hpp +++ b/components/widgets/imagebutton.hpp @@ -23,6 +23,8 @@ namespace Gui /// Set mImageNormal, mImageHighlighted and mImagePushed based on file convention (image_idle.ext, image_over.ext and image_pressed.ext) void setImage(const std::string& image); + void setTextureRect(MyGUI::IntCoord coord); + private: void updateImage(); @@ -44,6 +46,9 @@ namespace Gui bool mMouseFocus; bool mMousePress; bool mKeyFocus; + bool mUseWholeTexture; + + MyGUI::IntCoord mTextureRect; }; } diff --git a/files/mygui/openmw_journal.layout b/files/mygui/openmw_journal.layout index cf81e22e47..3752897f97 100644 --- a/files/mygui/openmw_journal.layout +++ b/files/mygui/openmw_journal.layout @@ -65,12 +65,14 @@ - + + - + + diff --git a/files/mygui/openmw_quickkeys_menu.layout b/files/mygui/openmw_quickkeys_menu.layout index 3371b4f49b..27bbbc190a 100644 --- a/files/mygui/openmw_quickkeys_menu.layout +++ b/files/mygui/openmw_quickkeys_menu.layout @@ -17,16 +17,16 @@ - - - - - - - - - - + + + + + + + + + +