mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
moddable post-processing pipeline
This commit is contained in:
parent
e7fb8b6fd8
commit
04843fed6d
130 changed files with 8645 additions and 608 deletions
164
components/fx/widgets.cpp
Normal file
164
components/fx/widgets.cpp
Normal file
|
@ -0,0 +1,164 @@
|
|||
#include "widgets.hpp"
|
||||
|
||||
#include <components/widgets/box.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
template <class T, class WidgetT>
|
||||
void createVectorWidget(const std::shared_ptr<fx::Types::UniformBase>& uniform, MyGUI::Widget* client, fx::Widgets::UniformBase* base)
|
||||
{
|
||||
int height = client->getHeight();
|
||||
base->setSize(base->getSize().width, (base->getSize().height - height) + (height * T::num_components));
|
||||
client->setSize(client->getSize().width, height * T::num_components);
|
||||
|
||||
for (int i = 0; i < T::num_components; ++i)
|
||||
{
|
||||
auto* widget = client->createWidget<WidgetT>("MW_ValueEditNumber", {0, height * i, client->getWidth(), height}, MyGUI::Align::Default);
|
||||
widget->setData(uniform, static_cast<fx::Widgets::Index>(i));
|
||||
base->addItem(widget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace fx
|
||||
{
|
||||
namespace Widgets
|
||||
{
|
||||
void EditBool::setValue(bool value)
|
||||
{
|
||||
auto uniform = mUniform.lock();
|
||||
|
||||
if (!uniform)
|
||||
return;
|
||||
|
||||
mCheckbutton->setCaptionWithReplacing(value ? "#{sOn}" : "#{sOff}");
|
||||
|
||||
uniform->setValue<bool>(value);
|
||||
}
|
||||
|
||||
void EditBool::setValueFromUniform()
|
||||
{
|
||||
auto uniform = mUniform.lock();
|
||||
|
||||
if (!uniform)
|
||||
return;
|
||||
|
||||
setValue(uniform->template getValue<bool>());
|
||||
}
|
||||
|
||||
void EditBool::toDefault()
|
||||
{
|
||||
auto uniform = mUniform.lock();
|
||||
|
||||
if (!uniform)
|
||||
return;
|
||||
|
||||
setValue(uniform->getDefault<bool>());
|
||||
}
|
||||
|
||||
void EditBool::initialiseOverride()
|
||||
{
|
||||
Base::initialiseOverride();
|
||||
|
||||
assignWidget(mCheckbutton, "Checkbutton");
|
||||
|
||||
mCheckbutton->eventMouseButtonClick += MyGUI::newDelegate(this, &EditBool::notifyMouseButtonClick);
|
||||
}
|
||||
|
||||
|
||||
void EditBool::notifyMouseButtonClick(MyGUI::Widget* sender)
|
||||
{
|
||||
auto uniform = mUniform.lock();
|
||||
|
||||
if (!uniform)
|
||||
return;
|
||||
|
||||
setValue(!uniform->getValue<bool>());
|
||||
}
|
||||
|
||||
void UniformBase::init(const std::shared_ptr<fx::Types::UniformBase>& uniform)
|
||||
{
|
||||
mLabel->setCaption(uniform->mName);
|
||||
|
||||
if (uniform->mDescription.empty())
|
||||
{
|
||||
mLabel->setUserString("ToolTipType", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
mLabel->setUserString("ToolTipType", "Layout");
|
||||
mLabel->setUserString("ToolTipLayout", "TextToolTip");
|
||||
mLabel->setUserString("Caption_Text", uniform->mDescription);
|
||||
}
|
||||
|
||||
std::visit([this, &uniform](auto&& arg) {
|
||||
using T = typename std::decay_t<decltype(arg)>::value_type;
|
||||
|
||||
if constexpr (std::is_same_v<osg::Vec4f, T>)
|
||||
{
|
||||
createVectorWidget<T, EditNumberFloat4>(uniform, mClient, this);
|
||||
}
|
||||
else if constexpr (std::is_same_v<osg::Vec3f, T>)
|
||||
{
|
||||
createVectorWidget<T, EditNumberFloat3>(uniform, mClient, this);
|
||||
}
|
||||
else if constexpr (std::is_same_v<osg::Vec2f, T>)
|
||||
{
|
||||
createVectorWidget<T, EditNumberFloat2>(uniform, mClient, this);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, float>)
|
||||
{
|
||||
auto* widget = mClient->createWidget<EditNumberFloat>("MW_ValueEditNumber", {0, 0, mClient->getWidth(), mClient->getHeight()}, MyGUI::Align::Stretch);
|
||||
widget->setData(uniform);
|
||||
mBases.emplace_back(widget);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, int>)
|
||||
{
|
||||
auto* widget = mClient->createWidget<EditNumberInt>("MW_ValueEditNumber", {0, 0, mClient->getWidth(), mClient->getHeight()}, MyGUI::Align::Stretch);
|
||||
widget->setData(uniform);
|
||||
mBases.emplace_back(widget);
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, bool>)
|
||||
{
|
||||
auto* widget = mClient->createWidget<EditBool>("MW_ValueEditBool", {0, 0, mClient->getWidth(), mClient->getHeight()}, MyGUI::Align::Stretch);
|
||||
widget->setData(uniform);
|
||||
mBases.emplace_back(widget);
|
||||
}
|
||||
|
||||
mReset->eventMouseButtonClick += MyGUI::newDelegate(this, &UniformBase::notifyResetClicked);
|
||||
|
||||
for (EditBase* base : mBases)
|
||||
base->setValueFromUniform();
|
||||
|
||||
}, uniform->mData);
|
||||
}
|
||||
|
||||
void UniformBase::addItem(EditBase* item)
|
||||
{
|
||||
mBases.emplace_back(item);
|
||||
}
|
||||
|
||||
void UniformBase::toDefault()
|
||||
{
|
||||
for (EditBase* base : mBases)
|
||||
{
|
||||
if (base)
|
||||
base->toDefault();
|
||||
}
|
||||
}
|
||||
|
||||
void UniformBase::notifyResetClicked(MyGUI::Widget* sender)
|
||||
{
|
||||
toDefault();
|
||||
}
|
||||
|
||||
void UniformBase::initialiseOverride()
|
||||
{
|
||||
Base::initialiseOverride();
|
||||
|
||||
assignWidget(mReset, "Reset");
|
||||
assignWidget(mLabel, "Label");
|
||||
assignWidget(mClient, "Client");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue