Apply clang-format to code base

This commit is contained in:
clang-format-bot 2022-09-22 21:26:05 +03:00 committed by ζeh Matt
parent f37d0be806
commit ddb0522bbf
No known key found for this signature in database
GPG key ID: 18CE582C71A225B0
2199 changed files with 118692 additions and 114392 deletions

View file

@ -9,36 +9,36 @@ namespace Gui
// If the 3.4.2 become a required minimum version, the ComboBox class may be removed.
void ComboBox::setPropertyOverride(const std::string& _key, const std::string& _value)
{
#if MYGUI_VERSION >= MYGUI_DEFINE_VERSION(3,4,2)
MyGUI::ComboBox::setPropertyOverride (_key, _value);
#if MYGUI_VERSION >= MYGUI_DEFINE_VERSION(3, 4, 2)
MyGUI::ComboBox::setPropertyOverride(_key, _value);
#else
if (_key == "AddItem")
{
const std::string value = MyGUI::LanguageManager::getInstance().replaceTags(_value);
MyGUI::ComboBox::setPropertyOverride (_key, value);
MyGUI::ComboBox::setPropertyOverride(_key, value);
}
else
{
MyGUI::ComboBox::setPropertyOverride (_key, _value);
MyGUI::ComboBox::setPropertyOverride(_key, _value);
}
#endif
}
void AutoSizedWidget::notifySizeChange (MyGUI::Widget* w)
void AutoSizedWidget::notifySizeChange(MyGUI::Widget* w)
{
MyGUI::Widget * parent = w->getParent();
MyGUI::Widget* parent = w->getParent();
if (parent != nullptr)
{
if (mExpandDirection.isLeft())
{
int hdiff = getRequestedSize ().width - w->getSize().width;
int hdiff = getRequestedSize().width - w->getSize().width;
w->setPosition(w->getPosition() - MyGUI::IntPoint(hdiff, 0));
}
w->setSize(getRequestedSize ());
w->setSize(getRequestedSize());
while (parent != nullptr)
{
Box * b = dynamic_cast<Box*>(parent);
Box* b = dynamic_cast<Box*>(parent);
if (b)
b->notifyChildrenSizeChanged();
else
@ -48,28 +48,27 @@ namespace Gui
}
}
MyGUI::IntSize AutoSizedTextBox::getRequestedSize()
{
return getCaption().empty() ? MyGUI::IntSize{0, 0} : getTextSize();
return getCaption().empty() ? MyGUI::IntSize{ 0, 0 } : getTextSize();
}
void AutoSizedTextBox::setCaption(const MyGUI::UString& _value)
{
TextBox::setCaption(_value);
notifySizeChange (this);
notifySizeChange(this);
}
void AutoSizedTextBox::setPropertyOverride(const std::string& _key, const std::string& _value)
{
if (_key == "ExpandDirection")
{
mExpandDirection = MyGUI::Align::parse (_value);
mExpandDirection = MyGUI::Align::parse(_value);
}
else
{
Gui::TextBox::setPropertyOverride (_key, _value);
Gui::TextBox::setPropertyOverride(_key, _value);
}
}
@ -80,12 +79,13 @@ namespace Gui
if (mShrink)
{
// MyGUI needs to know the widget size for wordwrapping, but we will know the widget size only after wordwrapping.
// To solve this issue, use the maximum tooltip width first for wordwrapping, then resize widget to its actual used space.
// MyGUI needs to know the widget size for wordwrapping, but we will know the widget size only after
// wordwrapping. To solve this issue, use the maximum tooltip width first for wordwrapping, then resize
// widget to its actual used space.
if (mWasResized)
{
int maxLineWidth = 0;
const MyGUI::VectorLineInfo & lines = getSubWidgetText()->castType<MyGUI::EditText>()->getLineInfo();
const MyGUI::VectorLineInfo& lines = getSubWidgetText()->castType<MyGUI::EditText>()->getLineInfo();
for (unsigned int i = 0; i < lines.size(); ++i)
maxLineWidth = std::max(maxLineWidth, lines[i].width);
@ -112,7 +112,7 @@ namespace Gui
EditBox::setCaption(_value);
mWasResized = false;
notifySizeChange (this);
notifySizeChange(this);
}
void AutoSizedEditBox::initialiseOverride()
@ -127,7 +127,7 @@ namespace Gui
{
if (_key == "ExpandDirection")
{
mExpandDirection = MyGUI::Align::parse (_value);
mExpandDirection = MyGUI::Align::parse(_value);
}
else if (_key == "Shrink")
{
@ -135,7 +135,7 @@ namespace Gui
}
else
{
Gui::EditBox::setPropertyOverride (_key, _value);
Gui::EditBox::setPropertyOverride(_key, _value);
}
}
@ -145,7 +145,7 @@ namespace Gui
if (isUserString("TextPadding"))
padding = MyGUI::IntSize::parse(getUserString("TextPadding"));
MyGUI::IntSize size = getTextSize() + MyGUI::IntSize(padding.width,padding.height);
MyGUI::IntSize size = getTextSize() + MyGUI::IntSize(padding.width, padding.height);
return size;
}
@ -153,18 +153,18 @@ namespace Gui
{
Button::setCaption(_value);
notifySizeChange (this);
notifySizeChange(this);
}
void AutoSizedButton::setPropertyOverride(const std::string& _key, const std::string& _value)
{
if (_key == "ExpandDirection")
{
mExpandDirection = MyGUI::Align::parse (_value);
mExpandDirection = MyGUI::Align::parse(_value);
}
else
{
Gui::Button::setPropertyOverride (_key, _value);
Gui::Button::setPropertyOverride(_key, _value);
}
}
Box::Box()
@ -174,7 +174,7 @@ namespace Gui
{
}
void Box::notifyChildrenSizeChanged ()
void Box::notifyChildrenSizeChanged()
{
align();
}
@ -193,19 +193,19 @@ namespace Gui
return true;
}
void HBox::align ()
void HBox::align()
{
unsigned int count = getChildCount ();
unsigned int count = getChildCount();
size_t h_stretched_count = 0;
int total_width = 0;
int total_height = 0;
std::vector< std::pair<MyGUI::IntSize, bool> > sizes;
std::vector<std::pair<MyGUI::IntSize, bool>> sizes;
sizes.resize(count);
for (unsigned int i = 0; i < count; ++i)
{
MyGUI::Widget* w = getChildAt(i);
bool hstretch = w->getUserString ("HStretch") == "true";
bool hstretch = w->getUserString("HStretch") == "true";
bool hidden = w->getUserString("Hidden") == "true";
if (hidden)
continue;
@ -213,9 +213,9 @@ namespace Gui
AutoSizedWidget* aw = dynamic_cast<AutoSizedWidget*>(w);
if (aw)
{
sizes[i] = std::make_pair(aw->getRequestedSize (), hstretch);
total_width += aw->getRequestedSize ().width;
total_height = std::max(total_height, aw->getRequestedSize ().height);
sizes[i] = std::make_pair(aw->getRequestedSize(), hstretch);
total_width += aw->getRequestedSize().width;
total_height = std::max(total_height, aw->getRequestedSize().height);
}
else
{
@ -225,19 +225,20 @@ namespace Gui
total_height = std::max(total_height, w->getSize().height);
}
if (i != count-1)
if (i != count - 1)
total_width += mSpacing;
}
if (mAutoResize && (total_width+mPadding*2 != getClientCoord().width || total_height+mPadding*2 != getClientCoord().height))
if (mAutoResize
&& (total_width + mPadding * 2 != getClientCoord().width
|| total_height + mPadding * 2 != getClientCoord().height))
{
int xmargin = getSize().width - getClientCoord().width;
int ymargin = getSize().height - getClientCoord().height;
setSize(MyGUI::IntSize(total_width+mPadding*2 + xmargin, total_height+mPadding*2 + ymargin));
setSize(MyGUI::IntSize(total_width + mPadding * 2 + xmargin, total_height + mPadding * 2 + ymargin));
return;
}
int curX = 0;
for (unsigned int i = 0; i < count; ++i)
{
@ -250,20 +251,21 @@ namespace Gui
if (hidden)
continue;
bool vstretch = w->getUserString ("VStretch") == "true";
int max_height = getClientCoord().height - mPadding*2;
bool vstretch = w->getUserString("VStretch") == "true";
int max_height = getClientCoord().height - mPadding * 2;
int height = vstretch ? max_height : sizes[i].first.height;
MyGUI::IntCoord widgetCoord;
widgetCoord.left = curX;
widgetCoord.top = mPadding + (getClientCoord().height-mPadding*2 - height) / 2;
widgetCoord.top = mPadding + (getClientCoord().height - mPadding * 2 - height) / 2;
int width = 0;
if (sizes[i].second)
{
if (h_stretched_count == 0)
throw std::logic_error("unexpected");
width = sizes[i].first.width + (getClientCoord().width-mPadding*2 - total_width)/h_stretched_count;
width
= sizes[i].first.width + (getClientCoord().width - mPadding * 2 - total_width) / h_stretched_count;
}
else
width = sizes[i].first.width;
@ -273,26 +275,26 @@ namespace Gui
w->setCoord(widgetCoord);
curX += width;
if (i != count-1)
if (i != count - 1)
curX += mSpacing;
}
}
void HBox::setPropertyOverride(const std::string& _key, const std::string& _value)
{
if (!Box::_setPropertyImpl (_key, _value))
if (!Box::_setPropertyImpl(_key, _value))
MyGUI::Widget::setPropertyOverride(_key, _value);
}
void HBox::setSize (const MyGUI::IntSize& _value)
void HBox::setSize(const MyGUI::IntSize& _value)
{
MyGUI::Widget::setSize (_value);
MyGUI::Widget::setSize(_value);
align();
}
void HBox::setCoord (const MyGUI::IntCoord& _value)
void HBox::setCoord(const MyGUI::IntCoord& _value)
{
MyGUI::Widget::setCoord (_value);
MyGUI::Widget::setCoord(_value);
align();
}
@ -309,10 +311,10 @@ namespace Gui
align();
}
MyGUI::IntSize HBox::getRequestedSize ()
MyGUI::IntSize HBox::getRequestedSize()
{
MyGUI::IntSize size(0,0);
for (unsigned int i = 0; i < getChildCount (); ++i)
MyGUI::IntSize size(0, 0);
for (unsigned int i = 0; i < getChildCount(); ++i)
{
bool hidden = getChildAt(i)->getUserString("Hidden") == "true";
if (hidden)
@ -321,39 +323,36 @@ namespace Gui
AutoSizedWidget* w = dynamic_cast<AutoSizedWidget*>(getChildAt(i));
if (w)
{
MyGUI::IntSize requested = w->getRequestedSize ();
MyGUI::IntSize requested = w->getRequestedSize();
size.height = std::max(size.height, requested.height);
size.width = size.width + requested.width;
if (i != getChildCount()-1)
if (i != getChildCount() - 1)
size.width += mSpacing;
}
else
{
MyGUI::IntSize requested = getChildAt(i)->getSize ();
MyGUI::IntSize requested = getChildAt(i)->getSize();
size.height = std::max(size.height, requested.height);
if (getChildAt(i)->getUserString("HStretch") != "true")
size.width = size.width + requested.width;
if (i != getChildCount()-1)
if (i != getChildCount() - 1)
size.width += mSpacing;
}
size.height += mPadding*2;
size.width += mPadding*2;
size.height += mPadding * 2;
size.width += mPadding * 2;
}
return size;
}
void VBox::align ()
void VBox::align()
{
unsigned int count = getChildCount ();
unsigned int count = getChildCount();
size_t v_stretched_count = 0;
int total_height = 0;
int total_width = 0;
std::vector< std::pair<MyGUI::IntSize, bool> > sizes;
std::vector<std::pair<MyGUI::IntSize, bool>> sizes;
sizes.resize(count);
for (unsigned int i = 0; i < count; ++i)
{
@ -363,14 +362,14 @@ namespace Gui
if (hidden)
continue;
bool vstretch = w->getUserString ("VStretch") == "true";
bool vstretch = w->getUserString("VStretch") == "true";
v_stretched_count += vstretch;
AutoSizedWidget* aw = dynamic_cast<AutoSizedWidget*>(w);
if (aw)
{
sizes[i] = std::make_pair(aw->getRequestedSize (), vstretch);
total_height += aw->getRequestedSize ().height;
total_width = std::max(total_width, aw->getRequestedSize ().width);
sizes[i] = std::make_pair(aw->getRequestedSize(), vstretch);
total_height += aw->getRequestedSize().height;
total_width = std::max(total_width, aw->getRequestedSize().width);
}
else
{
@ -381,22 +380,24 @@ namespace Gui
total_width = std::max(total_width, w->getSize().width);
}
if (i != count-1)
if (i != count - 1)
total_height += mSpacing;
}
if (mAutoResize && (total_width+mPadding*2 != getClientCoord().width || total_height+mPadding*2 != getClientCoord().height))
if (mAutoResize
&& (total_width + mPadding * 2 != getClientCoord().width
|| total_height + mPadding * 2 != getClientCoord().height))
{
int xmargin = getSize().width - getClientCoord().width;
int ymargin = getSize().height - getClientCoord().height;
setSize(MyGUI::IntSize(total_width+mPadding*2 + xmargin, total_height+mPadding*2 + ymargin));
setSize(MyGUI::IntSize(total_width + mPadding * 2 + xmargin, total_height + mPadding * 2 + ymargin));
return;
}
int curY = 0;
for (unsigned int i = 0; i < count; ++i)
{
if (i==0)
if (i == 0)
curY += mPadding;
MyGUI::Widget* w = getChildAt(i);
@ -405,20 +406,21 @@ namespace Gui
if (hidden)
continue;
bool hstretch = w->getUserString ("HStretch") == "true";
int maxWidth = getClientCoord().width - mPadding*2;
bool hstretch = w->getUserString("HStretch") == "true";
int maxWidth = getClientCoord().width - mPadding * 2;
int width = hstretch ? maxWidth : sizes[i].first.width;
MyGUI::IntCoord widgetCoord;
widgetCoord.top = curY;
widgetCoord.left = mPadding + (getClientCoord().width-mPadding*2 - width) / 2;
widgetCoord.left = mPadding + (getClientCoord().width - mPadding * 2 - width) / 2;
int height = 0;
if (sizes[i].second)
{
if (v_stretched_count == 0)
throw std::logic_error("unexpected");
height = sizes[i].first.height + (getClientCoord().height-mPadding*2 - total_height)/v_stretched_count;
height = sizes[i].first.height
+ (getClientCoord().height - mPadding * 2 - total_height) / v_stretched_count;
}
else
height = sizes[i].first.height;
@ -428,26 +430,26 @@ namespace Gui
w->setCoord(widgetCoord);
curY += height;
if (i != count-1)
if (i != count - 1)
curY += mSpacing;
}
}
void VBox::setPropertyOverride(const std::string& _key, const std::string& _value)
{
if (!Box::_setPropertyImpl (_key, _value))
if (!Box::_setPropertyImpl(_key, _value))
MyGUI::Widget::setPropertyOverride(_key, _value);
}
void VBox::setSize (const MyGUI::IntSize& _value)
void VBox::setSize(const MyGUI::IntSize& _value)
{
MyGUI::Widget::setSize (_value);
MyGUI::Widget::setSize(_value);
align();
}
void VBox::setCoord (const MyGUI::IntCoord& _value)
void VBox::setCoord(const MyGUI::IntCoord& _value)
{
MyGUI::Widget::setCoord (_value);
MyGUI::Widget::setCoord(_value);
align();
}
@ -459,10 +461,10 @@ namespace Gui
setWidgetClient(client);
}
MyGUI::IntSize VBox::getRequestedSize ()
MyGUI::IntSize VBox::getRequestedSize()
{
MyGUI::IntSize size(0,0);
for (unsigned int i = 0; i < getChildCount (); ++i)
MyGUI::IntSize size(0, 0);
for (unsigned int i = 0; i < getChildCount(); ++i)
{
bool hidden = getChildAt(i)->getUserString("Hidden") == "true";
if (hidden)
@ -471,25 +473,25 @@ namespace Gui
AutoSizedWidget* w = dynamic_cast<AutoSizedWidget*>(getChildAt(i));
if (w)
{
MyGUI::IntSize requested = w->getRequestedSize ();
MyGUI::IntSize requested = w->getRequestedSize();
size.width = std::max(size.width, requested.width);
size.height = size.height + requested.height;
if (i != getChildCount()-1)
if (i != getChildCount() - 1)
size.height += mSpacing;
}
else
{
MyGUI::IntSize requested = getChildAt(i)->getSize ();
MyGUI::IntSize requested = getChildAt(i)->getSize();
size.width = std::max(size.width, requested.width);
if (getChildAt(i)->getUserString("VStretch") != "true")
size.height = size.height + requested.height;
if (i != getChildCount()-1)
if (i != getChildCount() - 1)
size.height += mSpacing;
}
size.height += mPadding*2;
size.width += mPadding*2;
size.height += mPadding * 2;
size.width += mPadding * 2;
}
return size;
}

View file

@ -1,11 +1,11 @@
#ifndef OPENMW_WIDGETS_BOX_H
#define OPENMW_WIDGETS_BOX_H
#include <MyGUI_Widget.h>
#include <MyGUI_TextBox.h>
#include <MyGUI_EditBox.h>
#include <MyGUI_Button.h>
#include <MyGUI_ComboBox.h>
#include <MyGUI_EditBox.h>
#include <MyGUI_TextBox.h>
#include <MyGUI_Widget.h>
#include "fontwrapper.hpp"
@ -13,7 +13,7 @@ namespace Gui
{
class ComboBox : public FontWrapper<MyGUI::ComboBox>
{
MYGUI_RTTI_DERIVED( ComboBox )
MYGUI_RTTI_DERIVED(ComboBox)
protected:
void setPropertyOverride(const std::string& _key, const std::string& _value) override;
@ -21,23 +21,26 @@ namespace Gui
class Button : public FontWrapper<MyGUI::Button>
{
MYGUI_RTTI_DERIVED( Button )
MYGUI_RTTI_DERIVED(Button)
};
class TextBox : public FontWrapper<MyGUI::TextBox>
{
MYGUI_RTTI_DERIVED( TextBox )
MYGUI_RTTI_DERIVED(TextBox)
};
class EditBox : public FontWrapper<MyGUI::EditBox>
{
MYGUI_RTTI_DERIVED( EditBox )
MYGUI_RTTI_DERIVED(EditBox)
};
class AutoSizedWidget
{
public:
AutoSizedWidget() : mExpandDirection(MyGUI::Align::Right) {}
AutoSizedWidget()
: mExpandDirection(MyGUI::Align::Right)
{
}
virtual MyGUI::IntSize getRequestedSize() = 0;
@ -51,7 +54,7 @@ namespace Gui
class AutoSizedTextBox : public AutoSizedWidget, public TextBox
{
MYGUI_RTTI_DERIVED( AutoSizedTextBox )
MYGUI_RTTI_DERIVED(AutoSizedTextBox)
public:
MyGUI::IntSize getRequestedSize() override;
@ -64,10 +67,9 @@ namespace Gui
class AutoSizedEditBox : public AutoSizedWidget, public EditBox
{
MYGUI_RTTI_DERIVED( AutoSizedEditBox )
MYGUI_RTTI_DERIVED(AutoSizedEditBox)
public:
MyGUI::IntSize getRequestedSize() override;
void setCaption(const MyGUI::UString& _value) override;
@ -84,7 +86,7 @@ namespace Gui
class AutoSizedButton : public AutoSizedWidget, public Button
{
MYGUI_RTTI_DERIVED( AutoSizedButton )
MYGUI_RTTI_DERIVED(AutoSizedButton)
public:
MyGUI::IntSize getRequestedSize() override;
@ -122,20 +124,20 @@ namespace Gui
class Spacer : public AutoSizedWidget, public MyGUI::Widget
{
MYGUI_RTTI_DERIVED( Spacer )
MYGUI_RTTI_DERIVED(Spacer)
public:
Spacer();
MyGUI::IntSize getRequestedSize() override { return MyGUI::IntSize(0,0); }
MyGUI::IntSize getRequestedSize() override { return MyGUI::IntSize(0, 0); }
};
class HBox : public Box, public MyGUI::Widget
{
MYGUI_RTTI_DERIVED( HBox )
MYGUI_RTTI_DERIVED(HBox)
public:
void setSize (const MyGUI::IntSize &_value) override;
void setCoord (const MyGUI::IntCoord &_value) override;
void setSize(const MyGUI::IntSize& _value) override;
void setCoord(const MyGUI::IntCoord& _value) override;
protected:
void initialiseOverride() override;
@ -150,11 +152,11 @@ namespace Gui
class VBox : public Box, public MyGUI::Widget
{
MYGUI_RTTI_DERIVED( VBox)
MYGUI_RTTI_DERIVED(VBox)
public:
void setSize (const MyGUI::IntSize &_value) override;
void setCoord (const MyGUI::IntCoord &_value) override;
void setSize(const MyGUI::IntSize& _value) override;
void setCoord(const MyGUI::IntCoord& _value) override;
protected:
void initialiseOverride() override;

View file

@ -7,35 +7,35 @@
namespace Gui
{
template<class T>
template <class T>
class FontWrapper : public T
{
public:
void setFontName(const std::string& name) override
{
T::setFontName(name);
T::setPropertyOverride ("FontHeight", getFontSize());
T::setPropertyOverride("FontHeight", getFontSize());
}
protected:
void setPropertyOverride(const std::string& _key, const std::string& _value) override
{
T::setPropertyOverride (_key, _value);
T::setPropertyOverride(_key, _value);
// There is a bug in MyGUI: when it initializes the FontName property, it reset the font height.
// We should restore it.
if (_key == "FontName")
{
T::setPropertyOverride ("FontHeight", getFontSize());
T::setPropertyOverride("FontHeight", getFontSize());
}
}
private:
std::string getFontSize()
{
// Note: we can not use the FontLoader here, so there is a code duplication a bit.
static const std::string fontSize = std::to_string(std::clamp(Settings::Manager::getInt("font size", "GUI"), 12, 18));
static const std::string fontSize
= std::to_string(std::clamp(Settings::Manager::getInt("font size", "GUI"), 12, 18));
return fontSize;
}
};

View file

@ -34,7 +34,7 @@ namespace Gui
updateImage();
}
void ImageButton::setPropertyOverride(const std::string &_key, const std::string &_value)
void ImageButton::setPropertyOverride(const std::string& _key, const std::string& _value)
{
if (_key == "ImageHighlighted")
mImageHighlighted = _value;
@ -99,8 +99,7 @@ namespace Gui
const int height = static_cast<int>(std::round(mTextureRect.height * scale));
setImageTile(MyGUI::IntSize(width, height));
MyGUI::IntCoord scaledSize(static_cast<int>(std::round(mTextureRect.left * scale)),
static_cast<int>(std::round(mTextureRect.top * scale)),
width, height);
static_cast<int>(std::round(mTextureRect.top * scale)), width, height);
setImageCoord(scaledSize);
}
@ -113,7 +112,7 @@ namespace Gui
if (!texture)
{
Log(Debug::Error) << "ImageButton: can't find image " << mImageNormal;
return MyGUI::IntSize(0,0);
return MyGUI::IntSize(0, 0);
}
if (mUseWholeTexture)
@ -122,7 +121,7 @@ namespace Gui
return MyGUI::IntSize(mTextureRect.width, mTextureRect.height);
}
void ImageButton::setImage(const std::string &image)
void ImageButton::setImage(const std::string& image)
{
size_t extpos = image.find_last_of('.');
std::string imageNoExt = image.substr(0, extpos);
@ -147,13 +146,13 @@ namespace Gui
Base::onMouseButtonReleased(_left, _top, _id);
}
void ImageButton::onKeySetFocus(MyGUI::Widget *_old)
void ImageButton::onKeySetFocus(MyGUI::Widget* _old)
{
mKeyFocus = true;
updateImage();
}
void ImageButton::onKeyLostFocus(MyGUI::Widget *_new)
void ImageButton::onKeyLostFocus(MyGUI::Widget* _new)
{
mKeyFocus = false;
updateImage();

View file

@ -20,7 +20,8 @@ namespace Gui
static void setDefaultNeedKeyFocus(bool enabled);
/// Set mImageNormal, mImageHighlighted and mImagePushed based on file convention (image_idle.ext, image_over.ext and image_pressed.ext)
/// 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);

View file

@ -1,7 +1,7 @@
#include "list.hpp"
#include <MyGUI_Gui.h>
#include <MyGUI_Button.h>
#include <MyGUI_Gui.h>
#include <MyGUI_ImageBox.h>
namespace Gui
@ -22,9 +22,9 @@ namespace Gui
if (mClient == nullptr)
mClient = this;
mScrollView = mClient->createWidgetReal<MyGUI::ScrollView>(
"MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0),
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView");
mScrollView
= mClient->createWidgetReal<MyGUI::ScrollView>("MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0),
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView");
}
void MWList::addItem(std::string_view name)
@ -55,16 +55,15 @@ namespace Gui
}
mItemHeight = 0;
int i=0;
for (std::vector<std::string>::const_iterator it=mItems.begin();
it!=mItems.end(); ++it)
int i = 0;
for (std::vector<std::string>::const_iterator it = mItems.begin(); it != mItems.end(); ++it)
{
if (*it != "")
{
if (mListItemSkin.empty())
return;
MyGUI::Button* button = mScrollView->createWidget<MyGUI::Button>(
mListItemSkin, MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24),
MyGUI::Button* button = mScrollView->createWidget<MyGUI::Button>(mListItemSkin,
MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24),
MyGUI::Align::Left | MyGUI::Align::Top, getName() + "_item_" + (*it));
button->setCaption((*it));
button->getSubWidgetText()->setWordWrap(true);
@ -91,7 +90,8 @@ namespace Gui
++i;
}
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the
// scrollbar is hidden
mScrollView->setVisibleVScroll(false);
mScrollView->setCanvasSize(mClient->getSize().width, std::max(mItemHeight, mClient->getSize().height));
mScrollView->setVisibleVScroll(true);
@ -100,12 +100,12 @@ namespace Gui
redraw(true);
int viewRange = mScrollView->getCanvasSize().height;
if(viewPosition > viewRange)
if (viewPosition > viewRange)
viewPosition = viewRange;
mScrollView->setViewOffset(MyGUI::IntPoint(0, -viewPosition));
}
void MWList::setPropertyOverride(const std::string &_key, const std::string &_value)
void MWList::setPropertyOverride(const std::string& _key, const std::string& _value)
{
if (_key == "ListItemSkin")
mListItemSkin = _value;
@ -126,8 +126,8 @@ namespace Gui
void MWList::removeItem(const std::string& name)
{
assert( std::find(mItems.begin(), mItems.end(), name) != mItems.end() );
mItems.erase( std::find(mItems.begin(), mItems.end(), name) );
assert(std::find(mItems.begin(), mItems.end(), name) != mItems.end());
mItems.erase(std::find(mItems.begin(), mItems.end(), name));
}
void MWList::clear()
@ -137,11 +137,12 @@ namespace Gui
void MWList::onMouseWheelMoved(MyGUI::Widget* _sender, int _rel)
{
//NB view offset is negative
if (mScrollView->getViewOffset().top + _rel*0.3f > 0)
// NB view offset is negative
if (mScrollView->getViewOffset().top + _rel * 0.3f > 0)
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
else
mScrollView->setViewOffset(MyGUI::IntPoint(0, static_cast<int>(mScrollView->getViewOffset().top + _rel*0.3)));
mScrollView->setViewOffset(
MyGUI::IntPoint(0, static_cast<int>(mScrollView->getViewOffset().top + _rel * 0.3)));
}
void MWList::onItemSelected(MyGUI::Widget* _sender)

View file

@ -30,7 +30,6 @@ namespace Gui
*/
EventHandle_Widget eventWidgetSelected;
/**
* Call after the size of the list changed, or items were inserted/removed
*/
@ -40,7 +39,8 @@ namespace Gui
void addSeparator(); ///< add a seperator between the current and the next item.
void removeItem(const std::string& name);
unsigned int getItemCount();
std::string getItemNameAt(unsigned int at); ///< \attention if there are separators, this method will return "" at the place where the separator is
std::string getItemNameAt(unsigned int at); ///< \attention if there are separators, this method will return ""
///< at the place where the separator is
void clear();
MyGUI::Button* getItemWidget(std::string_view name);

View file

@ -20,7 +20,7 @@ namespace Gui
eventEditTextChange -= MyGUI::newDelegate(this, &NumericEditBox::onEditTextChange);
}
void NumericEditBox::onEditTextChange(MyGUI::EditBox *sender)
void NumericEditBox::onEditTextChange(MyGUI::EditBox* sender)
{
std::string newCaption = sender->getCaption();
if (newCaption.empty())
@ -84,12 +84,12 @@ namespace Gui
{
if (key == MyGUI::KeyCode::ArrowUp)
{
setValue(std::min(mValue+1, mMaxValue));
setValue(std::min(mValue + 1, mMaxValue));
eventValueChanged(mValue);
}
else if (key == MyGUI::KeyCode::ArrowDown)
{
setValue(std::max(mValue-1, mMinValue));
setValue(std::max(mValue - 1, mMinValue));
eventValueChanged(mValue);
}
else if (character == 0 || (character >= '0' && character <= '9'))

View file

@ -17,8 +17,9 @@ namespace Gui
public:
NumericEditBox()
: mValue(0), mMinValue(std::numeric_limits<int>::min()),
mMaxValue(std::numeric_limits<int>::max())
: mValue(0)
, mMinValue(std::numeric_limits<int>::min())
, mMaxValue(std::numeric_limits<int>::max())
{
}
@ -29,11 +30,12 @@ namespace Gui
EventHandle_ValueChanged eventValueChanged;
/// @note Does not trigger eventValueChanged
void setValue (int value);
void setValue(int value);
int getValue();
void setMinValue(int minValue);
void setMaxValue(int maxValue);
private:
void onEditTextChange(MyGUI::EditBox* sender);
void onKeyLostFocus(MyGUI::Widget* _new) override;

View file

@ -18,7 +18,7 @@ namespace Gui
}
}
void SharedStateButton::shareStateWith(const ButtonGroup &shared)
void SharedStateButton::shareStateWith(const ButtonGroup& shared)
{
mSharedWith = shared;
}
@ -37,14 +37,14 @@ namespace Gui
updateButtonState();
}
void SharedStateButton::onMouseSetFocus(MyGUI::Widget *_old)
void SharedStateButton::onMouseSetFocus(MyGUI::Widget* _old)
{
mIsMouseFocus = true;
Base::onMouseSetFocus(_old);
updateButtonState();
}
void SharedStateButton::onMouseLostFocus(MyGUI::Widget *_new)
void SharedStateButton::onMouseLostFocus(MyGUI::Widget* _new)
{
mIsMouseFocus = false;
Base::onMouseLostFocus(_new);
@ -68,7 +68,7 @@ namespace Gui
}
}
bool SharedStateButton::_setState(const std::string &_value)
bool SharedStateButton::_setState(const std::string& _value)
{
bool ret = _setWidgetState(_value);
if (ret)

View file

@ -12,10 +12,11 @@ namespace Gui
typedef std::vector<SharedStateButton*> ButtonGroup;
/// @brief A button that applies its own state changes to other widgets, to do this you define it as part of a ButtonGroup.
/// @brief A button that applies its own state changes to other widgets, to do this you define it as part of a
/// ButtonGroup.
class SharedStateButton final : public FontWrapper<MyGUI::Button>
{
MYGUI_RTTI_DERIVED(SharedStateButton)
MYGUI_RTTI_DERIVED(SharedStateButton)
public:
SharedStateButton();
@ -31,10 +32,10 @@ namespace Gui
void shutdownOverride() override;
bool _setState(const std::string &_value);
bool _setState(const std::string& _value);
public:
void shareStateWith(const ButtonGroup &shared);
void shareStateWith(const ButtonGroup& shared);
/// @note The ButtonGroup connection will be destroyed when any widget in the group gets destroyed.
static void createButtonGroup(ButtonGroup group);

View file

@ -7,53 +7,58 @@
namespace Gui
{
bool replaceTag(const MyGUI::UString& tag, MyGUI::UString& out)
{
std::string fontcolour = "fontcolour=";
size_t fontcolourLength = fontcolour.length();
std::string fontcolourhtml = "fontcolourhtml=";
size_t fontcolourhtmlLength = fontcolourhtml.length();
if (tag.compare(0, fontcolourLength, fontcolour) == 0)
bool replaceTag(const MyGUI::UString& tag, MyGUI::UString& out)
{
std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourLength);
std::string_view str = Fallback::Map::getString(fallbackName);
if (str.empty())
throw std::runtime_error("Unknown fallback name: " + fallbackName);
std::string fontcolour = "fontcolour=";
size_t fontcolourLength = fontcolour.length();
std::string ret[3];
unsigned int j=0;
for(unsigned int i=0;i<str.length();++i)
{
if(str[i]==',') j++;
else if (str[i] != ' ') ret[j]+=str[i];
}
MyGUI::Colour col (MyGUI::utility::parseInt(ret[0])/255.f,MyGUI::utility::parseInt(ret[1])/255.f,MyGUI::utility::parseInt(ret[2])/255.f);
out = col.print();
return true;
}
else if (tag.compare(0, fontcolourhtmlLength, fontcolourhtml) == 0)
{
std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourhtmlLength);
std::string_view str = Fallback::Map::getString(fallbackName);
if (str.empty())
throw std::runtime_error("Unknown fallback name: " + fallbackName);
std::string fontcolourhtml = "fontcolourhtml=";
size_t fontcolourhtmlLength = fontcolourhtml.length();
std::string ret[3];
unsigned int j=0;
for(unsigned int i=0;i<str.length();++i)
if (tag.compare(0, fontcolourLength, fontcolour) == 0)
{
if(str[i]==',') j++;
else if (str[i] != ' ') ret[j]+=str[i];
std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourLength);
std::string_view str = Fallback::Map::getString(fallbackName);
if (str.empty())
throw std::runtime_error("Unknown fallback name: " + fallbackName);
std::string ret[3];
unsigned int j = 0;
for (unsigned int i = 0; i < str.length(); ++i)
{
if (str[i] == ',')
j++;
else if (str[i] != ' ')
ret[j] += str[i];
}
MyGUI::Colour col(MyGUI::utility::parseInt(ret[0]) / 255.f, MyGUI::utility::parseInt(ret[1]) / 255.f,
MyGUI::utility::parseInt(ret[2]) / 255.f);
out = col.print();
return true;
}
std::stringstream html;
html << "#" << std::hex << MyGUI::utility::parseInt(ret[0]) << MyGUI::utility::parseInt(ret[1]) << MyGUI::utility::parseInt(ret[2]);
out = html.str();
return true;
else if (tag.compare(0, fontcolourhtmlLength, fontcolourhtml) == 0)
{
std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourhtmlLength);
std::string_view str = Fallback::Map::getString(fallbackName);
if (str.empty())
throw std::runtime_error("Unknown fallback name: " + fallbackName);
std::string ret[3];
unsigned int j = 0;
for (unsigned int i = 0; i < str.length(); ++i)
{
if (str[i] == ',')
j++;
else if (str[i] != ' ')
ret[j] += str[i];
}
std::stringstream html;
html << "#" << std::hex << MyGUI::utility::parseInt(ret[0]) << MyGUI::utility::parseInt(ret[1])
<< MyGUI::utility::parseInt(ret[2]);
out = html.str();
return true;
}
return false;
}
return false;
}
}

View file

@ -2,14 +2,14 @@
#define OPENMW_WIDGETS_TAGS_H
#include <MyGUI_UString.h>
#include <string>
#include <map>
#include <string>
namespace Gui
{
/// Try to replace a tag. Returns true on success and writes the result to \a out.
bool replaceTag (const MyGUI::UString& tag, MyGUI::UString& out);
/// Try to replace a tag. Returns true on success and writes the result to \a out.
bool replaceTag(const MyGUI::UString& tag, MyGUI::UString& out);
}

View file

@ -2,10 +2,10 @@
#include <MyGUI_FactoryManager.h>
#include "list.hpp"
#include "numericeditbox.hpp"
#include "box.hpp"
#include "imagebutton.hpp"
#include "list.hpp"
#include "numericeditbox.hpp"
#include "sharedstatebutton.hpp"
#include "windowcaption.hpp"

View file

@ -24,7 +24,7 @@ namespace Gui
throw std::runtime_error("WindowCaption needs an EditBox Client widget in its skin");
}
void WindowCaption::setCaption(const MyGUI::UString &_value)
void WindowCaption::setCaption(const MyGUI::UString& _value)
{
EditBox::setCaption(_value);
align();
@ -48,7 +48,7 @@ namespace Gui
MyGUI::Widget* caption = mClient;
caption->setSize(textSize.width + 24, caption->getHeight());
int barwidth = (getWidth()-caption->getWidth())/2;
int barwidth = (getWidth() - caption->getWidth()) / 2;
caption->setPosition(barwidth, caption->getTop());
if (mLeft)
mLeft->setCoord(0, mLeft->getTop(), barwidth, mLeft->getHeight());

View file

@ -14,7 +14,7 @@ namespace Gui
public:
WindowCaption();
void setCaption(const MyGUI::UString &_value) override;
void setCaption(const MyGUI::UString& _value) override;
void initialiseOverride() override;
void setSize(const MyGUI::IntSize& _value) override;