Split window caption bars so that the caption can be transparent (Fixes #531)

Fix transparent window background not applying to the header bar (Fixes #2294)
openmw-35
scrawl 9 years ago
parent 60f722b0a9
commit 4921c6ef9e

@ -154,8 +154,6 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton);
// Careful here. setTitle may cause size updates, causing itemview redraw, so make sure to do it last
// or we end up using a possibly invalid model.
setTitle(container.getClass().getName(container));
}

@ -108,7 +108,6 @@ namespace MWGui
void StatsWindow::setPlayerName(const std::string& playerName)
{
mMainWidget->castType<MyGUI::Window>()->setCaption(playerName);
adjustWindowCaption();
}
void StatsWindow::setValue (const std::string& id, const MWMechanics::AttributeValue& value)

@ -133,8 +133,6 @@ namespace MWGui
updateLabels();
// Careful here. setTitle may cause size updates, causing itemview redraw, so make sure to do it last
// or we end up using a possibly invalid model.
setTitle(actor.getClass().getName(actor));
onFilterChanged(mFilterAll);

@ -113,7 +113,7 @@ add_component_dir (ogreinit
)
add_component_dir (widgets
box imagebutton tags list numericeditbox sharedstatebutton widgets
box imagebutton tags list numericeditbox sharedstatebutton windowcaption widgets
)
add_component_dir (fontloader

@ -7,6 +7,7 @@
#include "box.hpp"
#include "imagebutton.hpp"
#include "sharedstatebutton.hpp"
#include "windowcaption.hpp"
namespace Gui
{
@ -22,6 +23,7 @@ namespace Gui
MyGUI::FactoryManager::getInstance().registerFactory<Gui::ImageButton>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::NumericEditBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::SharedStateButton>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::WindowCaption>("Widget");
}
}

@ -0,0 +1,58 @@
#include "windowcaption.hpp"
#include <stdexcept>
namespace Gui
{
WindowCaption::WindowCaption()
: mLeft(NULL)
, mRight(NULL)
{
}
void WindowCaption::initialiseOverride()
{
Base::initialiseOverride();
assignWidget(mLeft, "Left");
assignWidget(mRight, "Right");
assignWidget(mClient, "Client");
if (!mClient)
throw std::runtime_error("WindowCaption needs an EditBox Client widget in its skin");
}
void WindowCaption::setCaption(const MyGUI::UString &_value)
{
EditBox::setCaption(_value);
align();
}
void WindowCaption::setSize(const MyGUI::IntSize& _value)
{
Base::setSize(_value);
align();
}
void WindowCaption::setCoord(const MyGUI::IntCoord& _value)
{
Base::setCoord(_value);
align();
}
void WindowCaption::align()
{
MyGUI::IntSize textSize = getTextSize();
MyGUI::Widget* caption = mClient;
caption->setSize(textSize.width + 24, caption->getHeight());
int barwidth = (getWidth()-caption->getWidth())/2;
caption->setPosition(barwidth, caption->getTop());
if (mLeft)
mLeft->setCoord(0, mLeft->getTop(), barwidth, mLeft->getHeight());
if (mRight)
mRight->setCoord(barwidth + caption->getWidth(), mRight->getTop(), barwidth, mRight->getHeight());
}
}

@ -0,0 +1,32 @@
#ifndef OPENMW_WIDGETS_WINDOWCAPTION_H
#define OPENMW_WIDGETS_WINDOWCAPTION_H
#include <MyGUI_EditBox.h>
namespace Gui
{
/// Window caption that automatically adjusts "Left" and "Right" widgets in its skin
/// based on the text size of the caption in the middle
class WindowCaption : public MyGUI::EditBox
{
MYGUI_RTTI_DERIVED(WindowCaption)
public:
WindowCaption();
virtual void setCaption(const MyGUI::UString &_value);
virtual void initialiseOverride();
virtual void setSize(const MyGUI::IntSize& _value);
virtual void setCoord(const MyGUI::IntCoord& _value);
private:
MyGUI::Widget* mLeft;
MyGUI::Widget* mRight;
void align();
};
}
#endif

@ -6,13 +6,13 @@
<Resource type="ResourceSkin" name="HUD_Box" size="40 40">
<!-- Borders -->
<!-- The interior of the box -->
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch" name="Client"/>
<Child type="Widget" skin="BlackBG" offset="0 0 40 40" align="Stretch" name="Client"/>
<!-- The interior of the box -->
<!-- Borders -->
<Child type="Widget" skin="BlackBG" offset="2 2 36 36" align="Stretch" name="Client"/>
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch" name="Client"/>
</Resource>
@ -22,13 +22,13 @@
<Resource type="ResourceSkin" name="HUD_Box_NoTransp" size="40 40">
<!-- Borders -->
<!-- The interior of the box -->
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch" name="Client"/>
<Child type="Widget" skin="DialogBG" offset="0 0 40 40" align="Stretch" name="Client"/>
<!-- The interior of the box -->
<!-- Borders -->
<Child type="Widget" skin="DialogBG" offset="2 2 36 36" align="Stretch" name="Client"/>
<Child type="Widget" skin="MW_Box" offset="0 0 40 40" align="Left Stretch" name="Client"/>
</Resource>

@ -395,17 +395,9 @@
<Property key="FontName" value="Default"/>
<Property key="TextAlign" value="Center"/>
<Child type="Widget" skin="DialogBG" offset="0 0 88 20" align="Stretch"/>
<Child type="TextBox" skin="SandText" offset="2 0 84 20" align="Stretch" name="Client"/>
<!-- Add the borders of the surrounding blocks -->
<Child type="Widget" skin="HB_LEFT" offset="86 2 2 16" align="Top Right"/>
<Child type="Widget" skin="HB_RIGHT" offset="0 2 2 16" align="Top Left"/>
<Child type="Widget" skin="HB_TR" offset="0 0 2 2" align="Top Left"/>
<Child type="Widget" skin="HB_TL" offset="86 0 2 2" align="Top Right"/>
<Child type="Widget" skin="HB_BR" offset="0 18 2 2" align="Bottom Left"/>
<Child type="Widget" skin="HB_BL" offset="86 18 2 2" align="Bottom Right"/>
<Child type="Widget" skin="HB_ALL" offset="0 0 30 20" align="Default" name="Left"/>
<Child type="TextBox" skin="SandText" offset="30 0 28 20" align="Left VStretch" name="Client"/>
<Child type="Widget" skin="HB_ALL" offset="0 0 30 20" align="Right" name="Right"/>
</Resource>
<!-- ----------------------------------------------------
@ -420,7 +412,8 @@
<Property key="Snap" value="true"/>
<Property key="MinSize" value="64 64"/>
<Child type="Widget" skin="BlackBG" offset="8 28 240 220" align="Stretch" name="Client"/>
<Child type="Widget" skin="BlackBG" offset="0 0 256 256" align="Stretch"/>
<Child type="Widget" skin="" offset="8 28 240 220" align="Stretch" name="Client"/>
<!-- Outer Borders -->
<Child type="Widget" skin="TB_T" offset="14 0 228 4" align="Top HStretch" name="Action">
@ -538,12 +531,7 @@
<Property key="Scale" value="0 0 1 1"/>
</Child>
<!-- Caption -->
<Child type="Widget" skin="HB_ALL" offset="4 4 248 20" align="Top HStretch">
<Property key="Scale" value="1 1 0 0"/>
</Child>
<Child type="EditBox" skin="MW_Caption" offset="80 4 88 20" align="HCenter Top" name="Caption">
<Child type="WindowCaption" skin="MW_Caption" offset="4 4 248 20" align="HStretch Top" name="Caption">
</Child>
<!-- This invisible button makes it possible to move the
@ -559,7 +547,8 @@
<Property key="Snap" value="true"/>
<Property key="MinSize" value="64 64"/>
<Child type="Widget" skin="BlackBG" offset="8 28 240 220" align="Stretch" name="Client"/>
<Child type="Widget" skin="BlackBG" offset=" 0 0 256 256" align="Stretch"/>
<Child type="Widget" skin="" offset="8 28 240 220" align="Stretch" name="Client"/>
<!-- Outer Borders -->
<Child type="Widget" skin="TB_T" offset="14 0 228 4" align="Top HStretch" name="Action">
@ -695,7 +684,8 @@
<Property key="Snap" value="true"/>
<Property key="MinSize" value="64 64"/>
<Child type="Widget" skin="BlackBG" offset="8 28 240 220" align="Stretch" name="Client"/>
<Child type="Widget" skin="BlackBG" offset=" 0 0 256 256" align="Stretch"/>
<Child type="Widget" skin="" offset="8 28 240 220" align="Stretch" name="Client"/>
<!-- Outer Borders -->
<Child type="Widget" skin="TB_T" offset="14 0 228 4" align="Top HStretch" name="Action">
@ -814,12 +804,7 @@
</Child>
<!-- Caption -->
<Child type="Widget" skin="HB_ALL" offset="4 4 248 20" align="Top HStretch">
<Property key="Scale" value="1 1 0 0"/>
</Child>
<Child type="EditBox" skin="MW_Caption" offset="80 4 88 20" align="HCenter Top" name="Caption">
<Child type="WindowCaption" skin="MW_Caption" offset="4 4 248 20" align="HStretch Top" name="Caption">
</Child>
<!-- This invisible button makes it possible to move the

@ -46,27 +46,6 @@ namespace GUI
mMainWidget->setCoord(x,y,w,h);
}
void Layout::adjustWindowCaption()
{
MyGUI::TextBox* box = mMainWidget->castType<MyGUI::Window>(mMainWidget)->getCaptionWidget();
box->setSize(box->getTextSize().width + 24, box->getSize().height);
// in order to trigger alignment updates, we need to update the parent
// mygui doesn't provide a proper way of doing this, so we are just changing size
box->getParent()->setCoord(MyGUI::IntCoord(
box->getParent()->getCoord().left,
box->getParent()->getCoord().top,
box->getParent()->getCoord().width,
box->getParent()->getCoord().height+1
));
box->getParent()->setCoord(MyGUI::IntCoord(
box->getParent()->getCoord().left,
box->getParent()->getCoord().top,
box->getParent()->getCoord().width,
box->getParent()->getCoord().height-1
));
}
void Layout::setVisible(bool b)
{
mMainWidget->setVisible(b);
@ -82,7 +61,6 @@ namespace GUI
void Layout::setTitle(const std::string& title)
{
static_cast<MyGUI::Window*>(mMainWidget)->setCaptionWithReplacing(title);
adjustWindowCaption();
}
MyGUI::Widget* Layout::getWidget(const std::string &_name)

@ -45,10 +45,6 @@ namespace GUI
public:
void setCoord(int x, int y, int w, int h);
// adjust the size of the window caption so that all text is visible
// NOTE: this assumes that mMainWidget is of type Window.
void adjustWindowCaption();
virtual void setVisible(bool b);
void setText(const std::string& name, const std::string& caption);

Loading…
Cancel
Save