Skip to content

Commit

Permalink
#5532: Bind vertex colour controls
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Mar 19, 2021
1 parent 0bce7e6 commit 5919c9b
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/ishaderlayer.h
Expand Up @@ -424,4 +424,7 @@ class IEditableShaderLayer :

// Set the stage condition expression
virtual void setConditionExpressionFromString(const std::string& expression) = 0;

// Set the vertex colour mode of this stage
virtual void setVertexColourMode(VertexColourMode mode) = 0;
};
23 changes: 23 additions & 0 deletions radiant/ui/materials/MaterialEditor.cpp
Expand Up @@ -20,6 +20,7 @@
#include "string/join.h"
#include "materials/ParseLib.h"
#include "ExpressionBinding.h"
#include "RadioButtonBinding.h"

namespace ui
{
Expand Down Expand Up @@ -376,6 +377,18 @@ void MaterialEditor::createExpressionBinding(const std::string& textCtrlName,
std::bind(&MaterialEditor::onMaterialChanged, this)));
}

void MaterialEditor::createRadioButtonBinding(const std::string& ctrlName,
const std::function<bool(const IShaderLayer::Ptr&)>& loadFunc,
const std::function<void(const IEditableShaderLayer::Ptr&, bool)>& saveFunc)
{
_stageBindings.emplace(std::make_shared<RadioButtonBinding>(
getControl<wxRadioButton>(ctrlName),
loadFunc,
std::bind(&MaterialEditor::getEditableStageForSelection, this),
saveFunc,
std::bind(&MaterialEditor::onMaterialChanged, this)));
}

void MaterialEditor::setupMaterialStageProperties()
{
setupStageFlag("MaterialStageFlagMaskRed", IShaderLayer::FLAG_MASK_RED);
Expand Down Expand Up @@ -490,6 +503,16 @@ void MaterialEditor::setupMaterialStageProperties()
_stageBindings.emplace(std::make_shared<CheckBoxBinding<IShaderLayer::Ptr>>(getControl<wxCheckBox>("MaterialStageColored"),
[](const IShaderLayer::Ptr& layer) { return (layer->getParseFlags() & IShaderLayer::PF_HasColoredKeyword) != 0; }));

createRadioButtonBinding("MaterialStageNoVertexColourFlag",
[](const IShaderLayer::Ptr& layer) { return layer->getVertexColourMode() == IShaderLayer::VERTEX_COLOUR_NONE; },
[](const IEditableShaderLayer::Ptr& layer, bool value) { if (value) layer->setVertexColourMode(IShaderLayer::VERTEX_COLOUR_NONE); });
createRadioButtonBinding("MaterialStageVertexColourFlag",
[](const IShaderLayer::Ptr& layer) { return layer->getVertexColourMode() == IShaderLayer::VERTEX_COLOUR_MULTIPLY; },
[](const IEditableShaderLayer::Ptr& layer, bool value) { if (value) layer->setVertexColourMode(IShaderLayer::VERTEX_COLOUR_MULTIPLY); });
createRadioButtonBinding("MaterialStageInverseVertexColourFlag",
[](const IShaderLayer::Ptr& layer) { return layer->getVertexColourMode() == IShaderLayer::VERTEX_COLOUR_INVERSE_MULTIPLY; },
[](const IEditableShaderLayer::Ptr& layer, bool value) { if (value) layer->setVertexColourMode(IShaderLayer::VERTEX_COLOUR_INVERSE_MULTIPLY); });

createExpressionBinding("MaterialStageRed",
[](const IShaderLayer::Ptr& layer) { return layer->getColourExpression(IShaderLayer::COMP_RED); },
[](const IEditableShaderLayer::Ptr& layer, const std::string& value) { layer->setColourExpressionFromString(IShaderLayer::COMP_RED, value); });
Expand Down
5 changes: 4 additions & 1 deletion radiant/ui/materials/MaterialEditor.h
Expand Up @@ -102,7 +102,10 @@ class MaterialEditor :

void createExpressionBinding(const std::string& textCtrlName,
const std::function<shaders::IShaderExpression::Ptr(const IShaderLayer::Ptr&)>& loadFunc,
const std::function<void(const IEditableShaderLayer::Ptr&, const std::string&)>& saveFunc = std::function<void(const IEditableShaderLayer::Ptr&, const std::string&)>());
const std::function<void(const IEditableShaderLayer::Ptr&, const std::string&)>& saveFunc);
void createRadioButtonBinding(const std::string& ctrlName,
const std::function<bool(const IShaderLayer::Ptr&)>& loadFunc,
const std::function<void(const IEditableShaderLayer::Ptr&, bool)>& saveFunc);

void updateControlsFromMaterial();
void updateDeformControlsFromMaterial();
Expand Down
68 changes: 68 additions & 0 deletions radiant/ui/materials/RadioButtonBinding.h
@@ -0,0 +1,68 @@
#pragma once

#include "Binding.h"
#include "ishaderlayer.h"
#include <wx/radiobut.h>

namespace ui
{

class RadioButtonBinding :
public TwoWayBinding<IShaderLayer::Ptr, IEditableShaderLayer::Ptr>
{
private:
wxRadioButton* _radioButton;
std::function<bool(const IShaderLayer::Ptr&)> _getValue;
std::function<void(const IEditableShaderLayer::Ptr&, bool)> _updateValue;
std::function<void()> _postChangeNotify;

public:
RadioButtonBinding(wxRadioButton* radioButton,
const std::function<bool(const IShaderLayer::Ptr&)>& loadFunc,
const std::function<IEditableShaderLayer::Ptr()>& acquireSaveTarget,
const std::function<void(const IEditableShaderLayer::Ptr&, bool)>& saveFunc,
const std::function<void()>& postChangeNotify = std::function<void()>()) :
TwoWayBinding(acquireSaveTarget),
_radioButton(radioButton),
_getValue(loadFunc),
_updateValue(saveFunc),
_postChangeNotify(postChangeNotify)
{
if (_updateValue)
{
_radioButton->Bind(wxEVT_RADIOBUTTON, &RadioButtonBinding::onValueChanged, this);
}
}

virtual void updateFromSource() override
{
util::ScopedBoolLock lock(_blockUpdates);

if (!getSource())
{
_radioButton->SetValue(false);
return;
}

auto value = _getValue(getSource());
_radioButton->SetValue(value);
}

private:
void onValueChanged(wxCommandEvent& ev)
{
auto target = getTarget();

if (target)
{
_updateValue(target, _radioButton->GetValue());
}

if (_postChangeNotify)
{
_postChangeNotify();
}
}
};

}
2 changes: 1 addition & 1 deletion radiantcore/shaders/Doom3ShaderLayer.h
Expand Up @@ -301,7 +301,7 @@ class Doom3ShaderLayer :
* \brief
* Set vertex colour mode.
*/
void setVertexColourMode(VertexColourMode mode)
void setVertexColourMode(VertexColourMode mode) override
{
_vertexColourMode = mode;
}
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -463,6 +463,7 @@
<ClInclude Include="..\..\radiant\ui\materials\ExpressionBinding.h" />
<ClInclude Include="..\..\radiant\ui\materials\MaterialEditor.h" />
<ClInclude Include="..\..\radiant\ui\materials\MaterialPreview.h" />
<ClInclude Include="..\..\radiant\ui\materials\RadioButtonBinding.h" />
<ClInclude Include="..\..\radiant\ui\materials\TestModelSkin.h" />
<ClInclude Include="..\..\radiant\ui\mediabrowser\MediaBrowserTreeView.h" />
<ClInclude Include="..\..\radiant\ui\menu\MenuBar.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -1356,6 +1356,9 @@
<ClInclude Include="..\..\radiant\ui\materials\TestModelSkin.h">
<Filter>src\ui\materials</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\materials\RadioButtonBinding.h">
<Filter>src\ui\materials</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit 5919c9b

Please sign in to comment.