Skip to content

Commit

Permalink
#5776: Working on scale controls
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 10, 2021
1 parent feeabb8 commit 27cdeb1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
4 changes: 2 additions & 2 deletions install/ui/texturetoolmanipulationpanel.fbp
Expand Up @@ -745,7 +745,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_textCtrl1</property>
<property name="name">HorizScaleFactor</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand Down Expand Up @@ -1025,7 +1025,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_textCtrl11</property>
<property name="name">VertScaleFactor</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
Expand Down
4 changes: 2 additions & 2 deletions install/ui/texturetoolmanipulationpanel.xrc
Expand Up @@ -119,7 +119,7 @@
<option>0</option>
<flag>wxEXPAND|wxLEFT</flag>
<border>6</border>
<object class="wxTextCtrl" name="m_textCtrl1">
<object class="wxTextCtrl" name="HorizScaleFactor">
<size>40,-1</size>
<value></value>
</object>
Expand Down Expand Up @@ -163,7 +163,7 @@
<option>0</option>
<flag>wxEXPAND|wxLEFT</flag>
<border>6</border>
<object class="wxTextCtrl" name="m_textCtrl11">
<object class="wxTextCtrl" name="VertScaleFactor">
<size>40,-1</size>
<value></value>
</object>
Expand Down
33 changes: 28 additions & 5 deletions radiant/textool/TexTool.cpp
Expand Up @@ -131,10 +131,10 @@ wxWindow* TexTool::createManipulationPanel()
makeLabelBold(panel, "ShiftLabel");
makeLabelBold(panel, "ScaleLabel");

findNamedObject<wxButton>(panel, "ScaleHorizSmallerButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScaleSelected("up"); });
findNamedObject<wxButton>(panel, "ScaleHorizLargerButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScaleSelected("down"); });
findNamedObject<wxButton>(panel, "ScaleVertSmallerButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScaleSelected("up"); });
findNamedObject<wxButton>(panel, "ScaleVertLargerButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScaleSelected("down"); });
findNamedObject<wxButton>(panel, "ScaleHorizSmallerButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScaleSelected("down"); });
findNamedObject<wxButton>(panel, "ScaleHorizLargerButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScaleSelected("up"); });
findNamedObject<wxButton>(panel, "ScaleVertSmallerButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScaleSelected("left"); });
findNamedObject<wxButton>(panel, "ScaleVertLargerButton")->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { onScaleSelected("right"); });

return panel;
}
Expand Down Expand Up @@ -962,7 +962,30 @@ void TexTool::onShiftSelected(const std::string& direction)

void TexTool::onScaleSelected(const std::string& direction)
{
// TODO GlobalCommandSystem().executeCommand("TexToolShiftSelected", direction);
Vector2 scale(1, 1);

if (direction == "up")
{
auto factor = string::convert<double>(findNamedObject<wxTextCtrl>(this, "VertScaleFactor")->GetValue().ToStdString());
scale = Vector2(1, 1 + factor/100);
}
else if (direction == "down")
{
auto factor = string::convert<double>(findNamedObject<wxTextCtrl>(this, "VertScaleFactor")->GetValue().ToStdString());
scale = Vector2(1, 1 / (1 + factor / 100));
}
else if (direction == "left")
{
auto factor = string::convert<double>(findNamedObject<wxTextCtrl>(this, "HorizScaleFactor")->GetValue().ToStdString());
scale = Vector2(1 / (1 + factor / 100), 1);
}
else if (direction == "right")
{
auto factor = string::convert<double>(findNamedObject<wxTextCtrl>(this, "HorizScaleFactor")->GetValue().ToStdString());
scale = Vector2(1 + factor / 100, 1);
}

GlobalCommandSystem().executeCommand("TexToolScaleSelected", scale);
}

void TexTool::updateManipulationPanel()
Expand Down
40 changes: 40 additions & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -10,6 +10,7 @@
#include "string/case_conv.h"
#include "math/Matrix3.h"
#include "selection/algorithm/Texturing.h"
#include "command/ExecutionFailure.h"

namespace textool
{
Expand Down Expand Up @@ -59,6 +60,9 @@ void TextureToolSelectionSystem::initialiseModule(const IApplicationContext& ctx
GlobalCommandSystem().addCommand("TexToolShiftSelected",
std::bind(&TextureToolSelectionSystem::shiftSelectionCmd, this, std::placeholders::_1),
{ cmd::ARGTYPE_STRING });
GlobalCommandSystem().addCommand("TexToolScaleSelected",
std::bind(&TextureToolSelectionSystem::scaleSelectionCmd, this, std::placeholders::_1),
{ cmd::ARGTYPE_VECTOR2 });

GlobalCommandSystem().addCommand("TexToolFlipS",
std::bind(&TextureToolSelectionSystem::flipHorizontallyCmd, this, std::placeholders::_1));
Expand Down Expand Up @@ -796,6 +800,42 @@ void TextureToolSelectionSystem::shiftSelectionCmd(const cmd::ArgumentList& args
});
}

void TextureToolSelectionSystem::scaleSelectionCmd(const cmd::ArgumentList& args)
{
if (getSelectionMode() != SelectionMode::Surface)
{
rWarning() << "This command can only be executed in Surface manipulation mode" << std::endl;
return;
}

UndoableCommand cmd("scaleTexcoords");

if (args.size() < 1)
{
return;
}

auto scale = args[0].getVector2();

if (scale.x() == 0 || scale.y() == 0)
{
throw cmd::ExecutionFailure("Scale factor cannot be zero");
}

// Calculate the center based on the selection
selection::algorithm::TextureBoundsAccumulator accumulator;
foreachSelectedNode(accumulator);

if (!accumulator.getBounds().isValid())
{
return;
}

Vector2 pivot{ accumulator.getBounds().origin.x(), accumulator.getBounds().origin.y() };
selection::algorithm::TextureScaler scaler(pivot, scale);
foreachSelectedNode(scaler);
}

module::StaticModule<TextureToolSelectionSystem> _textureToolSelectionSystemModule;

}
1 change: 1 addition & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.h
Expand Up @@ -94,6 +94,7 @@ class TextureToolSelectionSystem :
void flipVerticallyCmd(const cmd::ArgumentList& args);
void normaliseSelectionCmd(const cmd::ArgumentList& args);
void shiftSelectionCmd(const cmd::ArgumentList& args);
void scaleSelectionCmd(const cmd::ArgumentList& args);

void flipSelected(int axis);
void performSelectionTest(Selector& selector, SelectionTest& test);
Expand Down

0 comments on commit 27cdeb1

Please sign in to comment.