Skip to content

Commit

Permalink
#5532 Some refactoring and rearrangement, surface flags can be modifi…
Browse files Browse the repository at this point in the history
…ed now
  • Loading branch information
codereader committed Mar 21, 2021
1 parent 1fb9fed commit 7b4c12e
Show file tree
Hide file tree
Showing 11 changed files with 499 additions and 383 deletions.
367 changes: 150 additions & 217 deletions install/ui/materialeditor.fbp

Large diffs are not rendered by default.

73 changes: 34 additions & 39 deletions install/ui/materialeditor.xrc
Expand Up @@ -766,41 +766,6 @@
<checked>0</checked>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag></flag>
<border>0</border>
<object class="wxCheckBox" name="MaterialFlagClamp">
<label>clamp</label>
<checked>0</checked>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag></flag>
<border>0</border>
<object class="wxCheckBox" name="MaterialFlagZeroClamp">
<label>zeroClamp</label>
<checked>0</checked>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag></flag>
<border>0</border>
<object class="wxCheckBox" name="MaterialFlagAlphaZeroClamp">
<label>alphaZeroClamp</label>
<checked>0</checked>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag></flag>
Expand All @@ -827,6 +792,32 @@
</object>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<border>0</border>
<object class="wxStaticText" name="m_staticText901">
<label>Clamping:</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxLEFT</flag>
<border>6</border>
<object class="wxChoice" name="MaterialClampType">
<selection>0</selection>
<content />
</object>
</object>
</object>
</object>
</object>
</object>
</object>
Expand Down Expand Up @@ -870,6 +861,7 @@
<flag>wxALIGN_CENTER_VERTICAL</flag>
<border>0</border>
<object class="wxCheckBox" name="MaterialHasDecalMacro">
<enabled>0</enabled>
<label>DECAL__MACRO</label>
<checked>0</checked>
</object>
Expand All @@ -888,6 +880,7 @@
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>0</border>
<object class="wxCheckBox" name="MaterialHasTwoSidedDecalMacro">
<enabled>0</enabled>
<label>TWOSIDED__DECAL__MACRO</label>
<checked>0</checked>
</object>
Expand Down Expand Up @@ -1066,7 +1059,7 @@
</object>
<object class="notebookpage">
<label>Deform</label>
<selected>1</selected>
<selected>0</selected>
<object class="wxPanel" name="DeformPage">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down Expand Up @@ -1350,7 +1343,7 @@
</object>
<object class="notebookpage">
<label>Misc</label>
<selected>0</selected>
<selected>1</selected>
<object class="wxPanel" name="MiscPage">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down Expand Up @@ -1427,6 +1420,7 @@
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>0</border>
<object class="wxCheckBox" name="MaterialHasGlassMacro">
<enabled>0</enabled>
<label>GLASS__MACRO</label>
<checked>0</checked>
</object>
Expand All @@ -1436,6 +1430,7 @@
<flag>wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxTOP</flag>
<border>3</border>
<object class="wxCheckBox" name="MaterialHasParticleMacro">
<enabled>0</enabled>
<label>PARTICLE__MACRO</label>
<checked>0</checked>
</object>
Expand Down Expand Up @@ -2202,7 +2197,7 @@
</object>
<object class="notebookpage">
<label>Texture</label>
<selected>0</selected>
<selected>1</selected>
<object class="wxPanel" name="TexturePanel">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down Expand Up @@ -2684,7 +2679,7 @@
</object>
<object class="notebookpage">
<label>Program</label>
<selected>1</selected>
<selected>0</selected>
<object class="wxPanel" name="m_panel61111">
<style>wxTAB_TRAVERSAL</style>
<object class="wxBoxSizer">
Expand Down
63 changes: 1 addition & 62 deletions radiant/ui/materials/Binding.h
Expand Up @@ -85,6 +85,7 @@ class TwoWayBinding :
_loadValue(loadValue),
_acquireTarget(acquireTarget),
_updateValue(updateValue),
_postUpdate(postChangeNotify),
_blockUpdates(false)
{}

Expand Down Expand Up @@ -131,66 +132,4 @@ class TwoWayBinding :
}
};

template<typename Source>
class CheckBoxBinding :
public Binding<Source>
{
private:
wxCheckBox* _checkbox;
std::function<bool(const Source&)> _loadFunc;
std::function<void(const Source&, bool)> _saveFunc;
std::function<void()> _postUpdateFunc;

public:
CheckBoxBinding(wxCheckBox* checkbox,
const std::function<bool(const Source&)>& loadFunc) :
CheckBoxBinding(checkbox, loadFunc, std::function<void(const Source&, bool)>(), std::function<void()>())
{}

CheckBoxBinding(wxCheckBox* checkbox,
const std::function<bool(const Source&)>& loadFunc,
const std::function<void(const Source&, bool)>& saveFunc,
const std::function<void()>& postUpdateFunc) :
_checkbox(checkbox),
_loadFunc(loadFunc),
_saveFunc(saveFunc),
_postUpdateFunc(postUpdateFunc)
{
if (_saveFunc)
{
_checkbox->Bind(wxEVT_CHECKBOX, &CheckBoxBinding::onCheckedChanged, this);
}
}

virtual ~CheckBoxBinding()
{
if (_saveFunc)
{
_checkbox->Unbind(wxEVT_CHECKBOX, &CheckBoxBinding::onCheckedChanged, this);
}
}

virtual void updateFromSource() override
{
if (!Binding<Source>::getSource())
{
_checkbox->SetValue(false);
return;
}

_checkbox->SetValue(_loadFunc(Binding<Source>::getSource()));
}

private:
void onCheckedChanged(wxCommandEvent& ev)
{
_saveFunc(Binding<Source>::getSource(), _checkbox->IsChecked());

if (_postUpdateFunc)
{
_postUpdateFunc();
}
}
};

}
64 changes: 64 additions & 0 deletions radiant/ui/materials/CheckBoxBinding.h
@@ -0,0 +1,64 @@
#pragma once

namespace ui
{

template<typename Source>
class CheckBoxBinding :
public TwoWayBinding<Source, bool>
{
public:
using BaseBinding = TwoWayBinding<Source, bool>;

private:
wxCheckBox* _checkbox;

public:
CheckBoxBinding(wxCheckBox* checkbox,
const typename BaseBinding::LoadFunc& loadFunc,
const typename BaseBinding::UpdateFunc& saveFunc) :
CheckBoxBinding(checkbox, loadFunc, saveFunc, BaseBinding::PostUpdateFunc())
{}

CheckBoxBinding(wxCheckBox* checkbox,
const typename BaseBinding::LoadFunc& loadFunc,
const typename BaseBinding::UpdateFunc& saveFunc,
const typename BaseBinding::PostUpdateFunc& postChangeNotify) :
CheckBoxBinding(checkbox, loadFunc, saveFunc, postChangeNotify, std::bind(&BaseBinding::UseSourceAsTarget, this))
{}

CheckBoxBinding(wxCheckBox* checkbox,
const typename BaseBinding::LoadFunc& loadFunc,
const typename BaseBinding::UpdateFunc& saveFunc,
const typename BaseBinding::PostUpdateFunc& postChangeNotify,
const typename BaseBinding::AcquireTargetFunc& acquireSaveTarget) :
BaseBinding(loadFunc, saveFunc, postChangeNotify, acquireSaveTarget),
_checkbox(checkbox)
{
if (BaseBinding::_updateValue)
{
_checkbox->Bind(wxEVT_CHECKBOX, &CheckBoxBinding::onValueChanged, this);
}
}

virtual ~CheckBoxBinding()
{
if (BaseBinding::_updateValue)
{
_checkbox->Unbind(wxEVT_CHECKBOX, &CheckBoxBinding::onValueChanged, this);
}
}

protected:
void setValueOnControl(const bool& value) override
{
_checkbox->SetValue(value);
}

void onValueChanged(wxCommandEvent& ev)
{
BaseBinding::updateValueOnTarget(_checkbox->GetValue());
}
};

}
10 changes: 9 additions & 1 deletion radiant/ui/materials/ExpressionBinding.h
Expand Up @@ -39,12 +39,20 @@ class ExpressionBinding :
BaseBinding(loadFunc, saveFunc, postChangeNotify, acquireSaveTarget),
_textCtrl(textCtrl)
{
if (saveFunc)
if (BaseBinding::_updateValue)
{
_textCtrl->Bind(wxEVT_TEXT, &ExpressionBinding::onTextChanged, this);
}
}

virtual ~ExpressionBinding()
{
if (BaseBinding::_updateValue)
{
_textCtrl->Unbind(wxEVT_TEXT, &ExpressionBinding::onTextChanged, this);
}
}

protected:
void setValueOnControl(const std::string& value) override
{
Expand Down

0 comments on commit 7b4c12e

Please sign in to comment.