Skip to content

Commit

Permalink
#5532: Until wxGTK supports instantiating wxSpinCtrlDouble types from…
Browse files Browse the repository at this point in the history
… XRC, we need to go for this workaround.
  • Loading branch information
codereader committed Mar 22, 2021
1 parent bd51ca2 commit c996c54
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 124 deletions.
130 changes: 61 additions & 69 deletions install/ui/materialeditor.fbp

Large diffs are not rendered by default.

52 changes: 21 additions & 31 deletions install/ui/materialeditor.xrc
Expand Up @@ -392,16 +392,13 @@
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>0</border>
<object class="wxSpinCtrlDouble" name="MaterialPolygonOffsetValue">
<object class="wxSpinCtrl" name="MaterialPolygonOffsetValue">
<style>wxSP_ARROW_KEYS</style>
<size>70,-1</size>
<value>0.300000</value>
<min>-100</min>
<max>100</max>
<inc>0.1</inc>
<digits>1</digits>
<value>0</value>
<min>0</min>
<max>10</max>
</object>
</object>
<object class="sizeritem">
Expand Down Expand Up @@ -1030,16 +1027,14 @@
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL</flag>
<border>6</border>
<object class="wxSpinCtrlDouble" name="MaterialEditorDecalInfoStaySeconds">
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>0</border>
<object class="wxSpinCtrl" name="MaterialEditorDecalInfoStaySeconds">
<style>wxSP_ARROW_KEYS</style>
<enabled>0</enabled>
<value>0.100000</value>
<value>0</value>
<min>0</min>
<max>999999</max>
<inc>0.1</inc>
<digits>2</digits>
<max>10</max>
</object>
</object>
<object class="sizeritem">
Expand Down Expand Up @@ -1070,16 +1065,14 @@
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxLEFT</flag>
<border>6</border>
<object class="wxSpinCtrlDouble" name="MaterialEditorDecalInfoFadeSeconds">
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>0</border>
<object class="wxSpinCtrl" name="MaterialEditorDecalInfoFadeSeconds">
<style>wxSP_ARROW_KEYS</style>
<enabled>0</enabled>
<value>0.200000</value>
<value>0</value>
<min>0</min>
<max>999999</max>
<inc>0.1</inc>
<digits>2</digits>
<max>10</max>
</object>
</object>
<object class="sizeritem">
Expand Down Expand Up @@ -2011,16 +2004,13 @@
</object>
<object class="sizeritem">
<option>0</option>
<flag></flag>
<border>6</border>
<object class="wxSpinCtrlDouble" name="MaterialStagePrivatePolygonOffset">
<flag>wxALL</flag>
<border>0</border>
<object class="wxSpinCtrl" name="MaterialStagePrivatePolygonOffset">
<style>wxSP_ARROW_KEYS</style>
<enabled>0</enabled>
<value>0.100000</value>
<min>-9999</min>
<max>9999</max>
<inc>0.1</inc>
<digits>1</digits>
<value>0</value>
<min>0</min>
<max>10</max>
</object>
</object>
<object class="sizeritem">
Expand Down
26 changes: 26 additions & 0 deletions libs/wxutil/XmlResourceBasedWidget.h
Expand Up @@ -4,6 +4,8 @@
#include <wx/toolbar.h>
#include <wx/panel.h>
#include <wx/stattext.h>
#include <wx/spinctrl.h>
#include <wx/sizer.h>

namespace wxutil
{
Expand Down Expand Up @@ -87,6 +89,30 @@ class XmlResourceBasedWidget
wxStaticText* text = findNamedObject<wxStaticText>(parent, widgetName);
text->SetFont(text->GetFont().Bold());
}

// Swaps out the wxSpinCtrl with wxSpinCtrlDouble
// This is a workaround for http://trac.wxwidgets.org/ticket/15425 - wxGTK < 3.1.1 don't ship an XRC handler for wxSpinCtrlDouble
wxSpinCtrlDouble* convertToSpinCtrlDouble(wxWindow* parent, const std::string& nameOfControlToReplace, double min, double max, double increment, int digits)
{
auto oldCtrl = findNamedObject<wxSpinCtrl>(parent, nameOfControlToReplace);

auto spinCtrlDouble = new wxSpinCtrlDouble(oldCtrl->GetParent(), wxID_ANY);

spinCtrlDouble->SetRange(min, max);
spinCtrlDouble->SetDigits(digits);
spinCtrlDouble->SetIncrement(increment);

bool wasEnabled = oldCtrl->IsEnabled();
auto name = oldCtrl->GetName();
oldCtrl->GetContainingSizer()->Replace(oldCtrl, spinCtrlDouble);
oldCtrl->Destroy();

spinCtrlDouble->SetName(name);
spinCtrlDouble->Enable(wasEnabled);
spinCtrlDouble->GetContainingSizer()->Layout();

return spinCtrlDouble;
}
};

} // namespace
6 changes: 6 additions & 0 deletions radiant/ui/materials/MaterialEditor.cpp
Expand Up @@ -241,6 +241,12 @@ void MaterialEditor::ShowDialog(const cmd::ArgumentList& args)

void MaterialEditor::setupMaterialProperties()
{
// Convert int-valued spinctrls to double-valued ones
convertToSpinCtrlDouble(this, "MaterialPolygonOffsetValue", -100, 100, 0.1, 1);
convertToSpinCtrlDouble(this, "MaterialEditorDecalInfoStaySeconds", 0, 999999, 0.1, 2);
convertToSpinCtrlDouble(this, "MaterialEditorDecalInfoFadeSeconds", 0, 999999, 0.1, 2);
convertToSpinCtrlDouble(this, "MaterialStagePrivatePolygonOffset", -100, 100, 0.1, 1);

auto* typeDropdown = getControl<wxChoice>("MaterialType");

typeDropdown->AppendString(""); // empty string for undefined
Expand Down
27 changes: 4 additions & 23 deletions radiant/ui/particles/ParticleEditor.cpp
Expand Up @@ -225,36 +225,17 @@ void ParticleEditor::setupParticleStageList()
wxEVT_BUTTON, wxCommandEventHandler(ParticleEditor::_onDuplicateStage), NULL, this);
}

wxSpinCtrlDouble* ParticleEditor::convertToSpinCtrlDouble(wxSpinCtrl* spinCtrlToReplace, double min, double max, double increment, int digits)
{
wxSpinCtrlDouble* spinCtrlDouble = new wxSpinCtrlDouble(spinCtrlToReplace->GetParent(), wxID_ANY);

spinCtrlDouble->SetRange(min, max);
spinCtrlDouble->SetDigits(digits);
spinCtrlDouble->SetIncrement(increment);
spinCtrlDouble->SetMaxSize(wxSize(70, -1));

wxString name = spinCtrlToReplace->GetName();
spinCtrlToReplace->GetContainingSizer()->Replace(spinCtrlToReplace, spinCtrlDouble);
spinCtrlToReplace->Destroy();

spinCtrlDouble->SetName(name);
spinCtrlDouble->GetContainingSizer()->Layout();

return spinCtrlDouble;
}

wxSpinCtrlDouble* ParticleEditor::convertToSpinCtrlDouble(const std::string& name, double min, double max, double increment, int digits)
{
return convertToSpinCtrlDouble(findNamedObject<wxSpinCtrl>(this, name), min, max, increment, digits);
auto spinCtrlDouble = XmlResourceBasedWidget::convertToSpinCtrlDouble(this, name, min, max, increment, digits);
spinCtrlDouble->SetMaxSize(wxSize(70, -1));
return spinCtrlDouble;
}

void ParticleEditor::setupSettingsPages()
{
// Depth Hack
wxSpinCtrlDouble* depthHack = convertToSpinCtrlDouble(
findNamedObject<wxSpinCtrl>(this, "ParticleEditorDepthHack"),
0, 999, 0.1, 2);
wxSpinCtrlDouble* depthHack = convertToSpinCtrlDouble("ParticleEditorDepthHack", 0, 999, 0.1, 2);

depthHack->Connect(wxEVT_SPINCTRLDOUBLE,
wxSpinDoubleEventHandler(ParticleEditor::_onDepthHackChanged), NULL, this);
Expand Down
1 change: 0 additions & 1 deletion radiant/ui/particles/ParticleEditor.h
Expand Up @@ -97,7 +97,6 @@ class ParticleEditor :
typedef void (ParticleEditor::*MemberMethod)(wxCommandEvent& ev);

// Replace the given wxSpinCtrl with a wxSpinCtrlDouble
wxSpinCtrlDouble* convertToSpinCtrlDouble(wxSpinCtrl* spinCtrlToReplace, double min, double max, double increment, int digits = 2);
wxSpinCtrlDouble* convertToSpinCtrlDouble(const std::string& name, double min, double max, double increment, int digits = 2);

// Connect a spin button to call the given member method
Expand Down

0 comments on commit c996c54

Please sign in to comment.