Merge pull request #2590 from akortunov/guifixes

UI textures scaling corrections
pull/2593/head
Alexei Dobrohotov 5 years ago committed by GitHub
commit a1ed0144e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,7 @@
#include <MyGUI_Button.h>
#include <MyGUI_Gui.h>
#include <MyGUI_ImageBox.h>
#include <MyGUI_RenderManager.h>
#include <components/esm/esmwriter.hpp>
#include <components/esm/quickkeys.hpp>
@ -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)

@ -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)

@ -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;
};
}

@ -65,12 +65,14 @@
<Widget type="BookPage" skin="MW_BookPage" position="75 10 92 260" name="CenterTopicIndex"/>
<Widget type="BookPage" skin="MW_BookPage" position="130 10 92 260" name="RightTopicIndex"/>
<Widget type="ImageButton" skin="ImageBox" position="71 15 100 20" Align="Top|Left" name="ShowActiveBTN">
<Widget type="ImageButton" skin="ImageBox" position="76 15 96 32" Align="Top|Left" name="ShowActiveBTN">
<!-- Image set at runtime since it may not be available in all versions of the game -->
<Property key="TextureRect" value="0 0 96 32"/>
</Widget>
<Widget type="ImageButton" skin="ImageBox" position="85 15 72 20" Align="Top|Left" name="ShowAllBTN">
<Widget type="ImageButton" skin="ImageBox" position="83 15 72 32" Align="Top|Left" name="ShowAllBTN">
<!-- Image set at runtime since it may not be available in all versions of the game -->
<Property key="TextureRect" value="0 0 72 32"/>
</Widget>
<Widget type="MWList" skin="MW_QuestList" position="8 40 226 212" name="TopicsList" align="Right VStretch">

@ -17,16 +17,16 @@
<Widget type="Widget" skin="" position="15 55 332 128" align="Left Bottom HCenter">
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="0 0 60 59" name="QuickKey1"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="68 0 60 59" name="QuickKey2"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="136 0 60 59" name="QuickKey3"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="204 0 60 59" name="QuickKey4"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="272 0 60 59" name="QuickKey5"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="0 67 60 59" name="QuickKey6"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="68 67 60 59" name="QuickKey7"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="136 67 60 59" name="QuickKey8"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="204 67 60 59" name="QuickKey9"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="272 67 60 59" name="QuickKey10"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="0 0 60 60" name="QuickKey1"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="68 0 60 60" name="QuickKey2"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="136 0 60 60" name="QuickKey3"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="204 0 60 60" name="QuickKey4"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="272 0 60 60" name="QuickKey5"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="0 67 60 60" name="QuickKey6"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="68 67 60 60" name="QuickKey7"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="136 67 60 60" name="QuickKey8"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="204 67 60 60" name="QuickKey9"/>
<Widget type="ItemWidget" skin="MW_ItemIconBox" position="272 67 60 60" name="QuickKey10"/>
</Widget>

Loading…
Cancel
Save