Skip to content

Commit

Permalink
#5775: Rough implementation of the scale link toggle button.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 9, 2021
1 parent 601794b commit a85b6cc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
Binary file added install/bitmaps/link_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added install/bitmaps/link_inactive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 38 additions & 5 deletions radiant/ui/surfaceinspector/SurfaceInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,38 @@ void SurfaceInspector::connectEvents()
wxutil::button::connectToCommand(_manipulators[HSHIFT].larger, "TexShiftRight");
wxutil::button::connectToCommand(_manipulators[VSHIFT].larger, "TexShiftUp");
wxutil::button::connectToCommand(_manipulators[VSHIFT].smaller, "TexShiftDown");
wxutil::button::connectToCommand(_manipulators[HSCALE].smaller, "TexScaleRight");
wxutil::button::connectToCommand(_manipulators[HSCALE].larger, "TexScaleLeft");
wxutil::button::connectToCommand(_manipulators[VSCALE].larger, "TexScaleDown");
wxutil::button::connectToCommand(_manipulators[VSCALE].smaller, "TexScaleUp");

_manipulators[HSCALE].smaller->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScale(HSCALE, false); });
_manipulators[HSCALE].larger->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScale(HSCALE, true); });
_manipulators[VSCALE].smaller->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScale(VSCALE, false); });
_manipulators[VSCALE].larger->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScale(VSCALE, true); });

wxutil::button::connectToCommand(_manipulators[ROTATION].larger, "TexRotateCounter");
wxutil::button::connectToCommand(_manipulators[ROTATION].smaller, "TexRotateClock");
}

void SurfaceInspector::onScale(const std::string& scaleId, bool larger)
{
if (_scaleLinkToggle->GetValue())
{
auto scaleValue = string::convert<float>(_manipulators[HSCALE].stepEntry->GetValue().ToStdString());
scaleValue *= larger ? -1 : 1;

GlobalCommandSystem().executeCommand("TexScale", Vector2(scaleValue, scaleValue));
}
else
{
if (scaleId == HSCALE)
{
GlobalCommandSystem().executeCommand(larger ? "TexScaleLeft" : "TexScaleRight");
}
else
{
GlobalCommandSystem().executeCommand(larger ? "TexScaleUp" : "TexScaleDown");
}
}
}

void SurfaceInspector::keyChanged()
{
// Avoid callback loops
Expand Down Expand Up @@ -348,6 +372,13 @@ void SurfaceInspector::populateWindow()
_useHorizScale->Bind(wxEVT_BUTTON, [&](wxCommandEvent& ev) { onHarmoniseScale(true); });
_useVertScale->Bind(wxEVT_BUTTON, [&](wxCommandEvent& ev) { onHarmoniseScale(false); });

auto linkToggle = new wxBitmapToggleButton(this, wxID_ANY, wxutil::GetLocalBitmap("link_inactive.png"));
linkToggle->SetBitmapSelected(wxutil::GetLocalBitmap("link_active.png"));
linkToggle->SetToolTip(_("Linked Scaling: when active, scale changes will affect horizontal and vertical values proportionally"));
linkToggle->SetMaxClientSize(wxSize(35, -1));
_scaleLinkToggle = linkToggle;
scaleLinkSizer->Add(_scaleLinkToggle, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 24);

table->Add(scaleLinkSizer, 1, wxEXPAND);

_manipulators[VSCALE] = createManipulatorRow(this, _(LABEL_VSCALE), table);
Expand Down Expand Up @@ -631,9 +662,11 @@ void SurfaceInspector::doUpdate()
_useHorizScale->Enable(valueSensitivity);
_useVertScale->Enable(valueSensitivity);

// The fit widget sensitivity
// The fit widget sensitivity
_fitTexture.enable(haveSelection);

_scaleLinkToggle->Enable(haveSelection);

// The align texture widget sensitivity
_alignTexture.bottom->Enable(haveSelection);
_alignTexture.left->Enable(haveSelection);
Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/surfaceinspector/SurfaceInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class SurfaceInspector :
wxSpinCtrlDouble* _defaultTexScale;
wxToggleButton* _texLockButton;
wxButton* _useHorizScale;
wxToggleButton* _scaleLinkToggle;
wxButton* _useVertScale;

// To avoid key changed loopbacks when the registry is updated
Expand Down Expand Up @@ -185,6 +186,7 @@ class SurfaceInspector :

void handleTextureChangedMessage(radiant::TextureChangedMessage& msg);

void onScale(const std::string& scaleId, bool larger);
void onHarmoniseScale(bool useHorizontal);

}; // class SurfaceInspector
Expand Down

0 comments on commit a85b6cc

Please sign in to comment.