#include "widgets.hpp" #include namespace { template void createVectorWidget( const std::shared_ptr& 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( "MW_ValueEditNumber", { 0, height * i, client->getWidth(), height }, MyGUI::Align::Default); widget->setData(uniform, static_cast(i)); base->addItem(widget); } } } namespace fx { namespace Widgets { void EditBool::setValue(bool value) { mCheckbutton->setCaptionWithReplacing(value ? "#{Interface:On}" : "#{Interface:Off}"); mFill->setVisible(value); mUniform->setValue(value); } void EditBool::setValueFromUniform() { setValue(mUniform->template getValue()); } void EditBool::toDefault() { setValue(mUniform->getDefault()); } void EditBool::initialiseOverride() { Base::initialiseOverride(); assignWidget(mCheckbutton, "Checkbutton"); assignWidget(mFill, "Fill"); mCheckbutton->eventMouseButtonClick += MyGUI::newDelegate(this, &EditBool::notifyMouseButtonClick); } void EditBool::notifyMouseButtonClick(MyGUI::Widget* sender) { setValue(!mUniform->getValue()); } template void EditChoice::setValue(const T& value) { // Update the combo view for (size_t i = 0; i < this->mChoices->getItemCount(); i++) { if (*this->mChoices->getItemDataAt(i) == value) { this->mChoices->setIndexSelected(i); break; } } mUniform->template setValue(value); } void EditChoice::notifyComboBoxChanged(MyGUI::ComboBox* sender, size_t pos) { std::visit( [this, sender, pos](auto&& data) { using T = typename std::decay_t::value_type; setValue(*sender->getItemDataAt(pos)); }, mUniform->mData); } void EditChoice::setValueFromUniform() { std::visit( [this](auto&& data) { using T = typename std::decay_t::value_type; size_t index = 0; for (const auto& choice : data.mChoices) { this->mChoices->addItem(choice.mLabel, choice.mValue); if (choice.mValue == mUniform->template getValue()) { this->mChoices->setIndexSelected(index); } index++; } setValue(mUniform->template getValue()); }, mUniform->mData); } void EditChoice::toDefault() { std::visit( [this](auto&& data) { using T = typename std::decay_t::value_type; setValue(mUniform->template getDefault()); }, mUniform->mData); } void EditChoice::initialiseOverride() { Base::initialiseOverride(); assignWidget(mChoices, "Choices"); mChoices->eventComboChangePosition += MyGUI::newDelegate(this, &EditChoice::notifyComboBoxChanged); } void UniformBase::init(const std::shared_ptr& uniform) { if (uniform->mDisplayName.empty()) mLabel->setCaption(uniform->mName); else mLabel->setCaptionWithReplacing(uniform->mDisplayName); 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::value_type; if (arg.mChoices.size() > 0) { auto* widget = mClient->createWidget("MW_ValueEditChoice", { 0, 0, mClient->getWidth(), mClient->getHeight() }, MyGUI::Align::Stretch); widget->setData(uniform); mBases.emplace_back(widget); } else { if constexpr (std::is_same_v) { createVectorWidget(uniform, mClient, this); } else if constexpr (std::is_same_v) { createVectorWidget(uniform, mClient, this); } else if constexpr (std::is_same_v) { createVectorWidget(uniform, mClient, this); } else if constexpr (std::is_same_v) { auto* widget = mClient->createWidget("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) { auto* widget = mClient->createWidget("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) { auto* widget = mClient->createWidget("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"); } } }