Skip to content

Commit

Permalink
#5532: New ExpressionBinding class to help with expression display.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Feb 27, 2021
1 parent c74c397 commit df45115
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 24 deletions.
File renamed without changes.
36 changes: 36 additions & 0 deletions radiant/ui/materials/ExpressionBinding.h
@@ -0,0 +1,36 @@
#pragma once

#include "Binding.h"
#include "ishaderexpression.h"

namespace ui
{

template<typename Source>
class ExpressionBinding :
public Binding<Source>
{
private:
wxTextCtrl* _textCtrl;
std::function<shaders::IShaderExpressionPtr(const Source&)> _getExpression;

public:
ExpressionBinding(wxTextCtrl* textCtrl, const std::function<shaders::IShaderExpressionPtr(const Source&)> loadFunc) :
_textCtrl(textCtrl),
_getExpression(loadFunc)
{}

virtual void updateFromSource(const Source& source) override
{
if (!source)
{
_textCtrl->SetValue("");
return;
}

auto expression = _getExpression(source);
_textCtrl->SetValue(expression ? expression->getExpressionString() : "");
}
};

}
26 changes: 6 additions & 20 deletions radiant/ui/materials/MaterialEditor.cpp
Expand Up @@ -13,6 +13,7 @@
#include "wxutil/SourceView.h"
#include "fmt/format.h"
#include "materials/ParseLib.h"
#include "ExpressionBinding.h"

namespace ui
{
Expand Down Expand Up @@ -392,6 +393,11 @@ void MaterialEditor::setupMaterialStageProperties()
{
texgenDropdown->AppendString(pair.first);
}

_stageBindings.emplace(std::make_shared<ExpressionBinding<ShaderLayerPtr>>(getControl<wxTextCtrl>("MaterialStageTransformX"),
[=](const ShaderLayerPtr& layer) { return layer->getTranslationExpression(0); }));
_stageBindings.emplace(std::make_shared<ExpressionBinding<ShaderLayerPtr>>(getControl<wxTextCtrl>("MaterialStageTransformY"),
[=](const ShaderLayerPtr& layer) { return layer->getTranslationExpression(1); }));
}

void MaterialEditor::_onTreeViewSelectionChanged(wxDataViewEvent& ev)
Expand Down Expand Up @@ -793,25 +799,6 @@ void MaterialEditor::updateStageTexgenControls()
}
}

void MaterialEditor::updateStageTransformControls()
{
auto selectedStage = getSelectedStage();

if (selectedStage)
{
auto xExpr = selectedStage->getTranslationExpression(0);
getControl<wxTextCtrl>("MaterialStageTransformX")->SetValue(xExpr ? xExpr->getExpressionString() : "");

auto yExpr = selectedStage->getTranslationExpression(1);
getControl<wxTextCtrl>("MaterialStageTransformY")->SetValue(yExpr ? yExpr->getExpressionString() : "");
}
else
{
getControl<wxTextCtrl>("MaterialStageTransformX")->SetValue("");
getControl<wxTextCtrl>("MaterialStageTransformY")->SetValue("");
}
}

void MaterialEditor::updateStageControls()
{
auto selectedStage = getSelectedStage();
Expand All @@ -826,7 +813,6 @@ void MaterialEditor::updateStageControls()

updateStageBlendControls();
updateStageTexgenControls();
updateStageTransformControls();

if (selectedStage)
{
Expand Down
3 changes: 1 addition & 2 deletions radiant/ui/materials/MaterialEditor.h
Expand Up @@ -11,7 +11,7 @@
#include "wxutil/SourceView.h"

#include "ui/common/MaterialTreeView.h"
#include "MaterialBinding.h"
#include "Binding.h"

namespace ui
{
Expand Down Expand Up @@ -71,7 +71,6 @@ class MaterialEditor :
void updateStageControls();
void updateStageBlendControls();
void updateStageTexgenControls();
void updateStageTransformControls();

void _onTreeViewSelectionChanged(wxDataViewEvent& ev);
void _onStageListSelectionChanged(wxDataViewEvent& ev);
Expand Down
3 changes: 2 additions & 1 deletion tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -456,7 +456,8 @@
<ClInclude Include="..\..\radiant\ui\MapFileProgressHandler.h" />
<ClInclude Include="..\..\radiant\ui\mapinfo\LayerInfoTab.h" />
<ClInclude Include="..\..\radiant\ui\mapselector\MapSelector.h" />
<ClInclude Include="..\..\radiant\ui\materials\MaterialBinding.h" />
<ClInclude Include="..\..\radiant\ui\materials\Binding.h" />
<ClInclude Include="..\..\radiant\ui\materials\ExpressionBinding.h" />
<ClInclude Include="..\..\radiant\ui\materials\MaterialEditor.h" />
<ClInclude Include="..\..\radiant\ui\mediabrowser\MediaBrowserTreeView.h" />
<ClInclude Include="..\..\radiant\ui\menu\MenuBar.h" />
Expand Down
5 changes: 4 additions & 1 deletion tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -1335,7 +1335,10 @@
<ClInclude Include="..\..\radiant\ui\common\MaterialPopulator.h">
<Filter>src\ui\common</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\materials\MaterialBinding.h">
<ClInclude Include="..\..\radiant\ui\materials\Binding.h">
<Filter>src\ui\materials</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\ui\materials\ExpressionBinding.h">
<Filter>src\ui\materials</Filter>
</ClInclude>
</ItemGroup>
Expand Down

0 comments on commit df45115

Please sign in to comment.