Skip to content

Commit

Permalink
Fit Texture spinboxes apply changes immediately
Browse files Browse the repository at this point in the history
Save a few clicks when experimenting with different fit values by updating the
surface every time the value changes, rather than requiring a separate click on
the Fit button.
  • Loading branch information
Matthew Mott committed Jul 20, 2021
1 parent deaa9ae commit 743ea1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
45 changes: 23 additions & 22 deletions radiant/ui/surfaceinspector/SurfaceInspector.cpp
Expand Up @@ -151,7 +151,7 @@ void SurfaceInspector::connectEvents()
{
// Be sure to connect these signals BEFORE the buttons are connected
// to the events, so that the doUpdate() call gets invoked after the actual event has been fired.
_fitTexture.button->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onFit), NULL, this);
_fitTexture.button->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { onFit(); });

_flipTexture.flipX->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);
_flipTexture.flipY->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);
Expand Down Expand Up @@ -207,34 +207,35 @@ void SurfaceInspector::keyChanged()
_callbackActive = false;
}

wxBoxSizer* SurfaceInspector::createFitTextureRow()
wxSpinCtrlDouble* SurfaceInspector::makeFitSpinBox()
{
wxBoxSizer* fitTextureHBox = new wxBoxSizer(wxHORIZONTAL);
wxSpinCtrlDouble* box = new wxSpinCtrlDouble(this, wxID_ANY);

// Create the "Fit Texture" label
_fitTexture.label = new wxStaticText(this, wxID_ANY, _(LABEL_FIT_TEXTURE));
// Set visual parameters
box->SetMinSize(wxSize(box->GetCharWidth() * 16, -1));
box->SetRange(1.0, 1000.0);
box->SetIncrement(1.0);
box->SetValue(1.0);
box->SetDigits(2);

// Create the width entry field
_fitTexture.width = new wxSpinCtrlDouble(this, wxID_ANY);
_fitTexture.width->SetMinSize(wxSize(_fitTexture.width->GetCharWidth() * 16, -1));
_fitTexture.width->SetRange(0.0, 1000.0);
_fitTexture.width->SetIncrement(1.0);
_fitTexture.width->SetValue(1.0);
_fitTexture.width->SetDigits(2);
// Perform a fit operation when the value changes
box->Bind(wxEVT_SPINCTRLDOUBLE, [=](wxSpinDoubleEvent&) { onFit(); });

// Create the "x" label
_fitTexture.x = new wxStaticText(this, wxID_ANY, "x");
return box;
}

// Create the height entry field
_fitTexture.height = new wxSpinCtrlDouble(this, wxID_ANY);
_fitTexture.height->SetMinSize(wxSize(_fitTexture.height->GetCharWidth() * 16, -1));
_fitTexture.height->SetRange(0.0, 1000.0);
_fitTexture.height->SetIncrement(1.0);
_fitTexture.height->SetValue(1.0);
_fitTexture.height->SetDigits(2);
wxBoxSizer* SurfaceInspector::createFitTextureRow()
{
wxBoxSizer* fitTextureHBox = new wxBoxSizer(wxHORIZONTAL);

// Create widgets from left to right
_fitTexture.label = new wxStaticText(this, wxID_ANY, _(LABEL_FIT_TEXTURE));
_fitTexture.width = makeFitSpinBox();
_fitTexture.x = new wxStaticText(this, wxID_ANY, "x");
_fitTexture.height = makeFitSpinBox();
_fitTexture.button = new wxButton(this, wxID_ANY, _(LABEL_FIT));

// Add widgets to the sizer
fitTextureHBox->Add(_fitTexture.width, 0, wxALIGN_CENTER_VERTICAL);
fitTextureHBox->Add(_fitTexture.x, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 3);
fitTextureHBox->Add(_fitTexture.height, 0, wxALIGN_CENTER_VERTICAL);
Expand Down Expand Up @@ -605,7 +606,7 @@ void SurfaceInspector::fitTexture()
}
}

void SurfaceInspector::onFit(wxCommandEvent& ev)
void SurfaceInspector::onFit()
{
// Call the according member method
fitTexture();
Expand Down
3 changes: 2 additions & 1 deletion radiant/ui/surfaceinspector/SurfaceInspector.h
Expand Up @@ -142,6 +142,7 @@ class SurfaceInspector :

// Widget construction
void populateWindow();
wxSpinCtrlDouble* makeFitSpinBox();
wxBoxSizer* createFitTextureRow();

// Connect IEvents to the widgets
Expand All @@ -163,7 +164,7 @@ class SurfaceInspector :
void onShaderSelect(wxCommandEvent& ev);

// The callback for the Fit Texture button
void onFit(wxCommandEvent& ev);
void onFit();

// If any of the control button get clicked, an update is performed
void onUpdateAfterButtonClick(wxCommandEvent& ev);
Expand Down

0 comments on commit 743ea1a

Please sign in to comment.