Skip to content

Commit

Permalink
#5746: Add toggle buttons and events to switch texture tool selection…
Browse files Browse the repository at this point in the history
… modes
  • Loading branch information
codereader committed Sep 19, 2021
1 parent ce03fcc commit 200bbdc
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 55 deletions.
3 changes: 3 additions & 0 deletions install/user.xml
Expand Up @@ -307,6 +307,9 @@
<toggletoolbutton name="textoolrotate" action="TextureToolRotateMode" tooltip="Rotate" icon="select_mouserotate.png"/>
<toggletoolbutton name="textooldrag" action="TextureToolDragMode" tooltip="Drag-Manipulate" icon="select_mouseresize.png"/>
<separator/>
<toggletoolbutton name="textoolsurfacemode" action="TextureToolSurfaceSelectionMode" tooltip="Select Surfaces" icon="modify_faces.png"/>
<toggletoolbutton name="textoolvertexmode" action="TextureToolVertexSelectionMode" tooltip="Select Vertices" icon="modify_vertices.png"/>
<separator/>
<toolbutton name="mergeitems" action="TexToolMergeItems" tooltip="Merge Selection" icon="textool_merge.png"/>
<toolbutton name="texflips" action="TexToolFlipS" tooltip="Flip Selection Horiz (S-Axis)" icon="tex_flips.png"/>
<toolbutton name="texflipt" action="TexToolFlipT" tooltip="Flip Selection Vertical (T-Axis)" icon="tex_flipt.png"/>
Expand Down
10 changes: 10 additions & 0 deletions radiant/textool/TexTool.cpp
Expand Up @@ -135,6 +135,7 @@ void TexTool::_preHide()

_selectionChanged.disconnect();
_manipulatorChanged.disconnect();
_selectionModeChanged.disconnect();

// Clear items to prevent us from running into stale references
// when the textool is shown again
Expand All @@ -150,6 +151,7 @@ void TexTool::_preShow()
_undoHandler.disconnect();
_redoHandler.disconnect();
_manipulatorChanged.disconnect();
_selectionModeChanged.disconnect();

// Register self to the SelSystem to get notified upon selection changes.
_selectionChanged = GlobalSelectionSystem().signal_selectionChanged().connect(
Expand All @@ -163,6 +165,9 @@ void TexTool::_preShow()
_manipulatorChanged = GlobalTextureToolSelectionSystem().signal_activeManipulatorChanged().connect(
sigc::mem_fun(this, &TexTool::onManipulatorModeChanged)
);
_selectionModeChanged = GlobalTextureToolSelectionSystem().signal_selectionModeChanged().connect(
sigc::mem_fun(this, &TexTool::onSelectionModeChanged)
);

// Trigger an update of the current selection
_selectionRescanNeeded = true;
Expand All @@ -179,6 +184,11 @@ void TexTool::onManipulatorModeChanged(selection::IManipulator::Type type)
queueDraw();
}

void TexTool::onSelectionModeChanged(textool::SelectionMode mode)
{
queueDraw();
}

void TexTool::gridUp() {
if (_grid*2 <= GRID_MAX && _gridActive) {
_grid *= 2;
Expand Down
3 changes: 3 additions & 0 deletions radiant/textool/TexTool.h
@@ -1,6 +1,7 @@
#pragma once

#include "icommandsystem.h"
#include "itexturetoolmodel.h"

#include "wxutil/window/TransientWindow.h"
#include "math/Vector3.h"
Expand Down Expand Up @@ -90,6 +91,7 @@ class TexTool :
sigc::connection _undoHandler;
sigc::connection _redoHandler;
sigc::connection _manipulatorChanged;
sigc::connection _selectionModeChanged;

private:
// This is where the static shared_ptr of the singleton instance is held.
Expand Down Expand Up @@ -289,6 +291,7 @@ class TexTool :
void updateProjection();
double getTextureAspectRatio();
void onManipulatorModeChanged(selection::IManipulator::Type type);
void onSelectionModeChanged(textool::SelectionMode mode);

TextureToolMouseEvent createMouseEvent(const Vector2& point, const Vector2& delta = Vector2(0, 0));

Expand Down
50 changes: 0 additions & 50 deletions radiant/textool/TexToolManipulatorToggle.h

This file was deleted.

74 changes: 74 additions & 0 deletions radiant/textool/TexToolModeToggles.h
@@ -0,0 +1,74 @@
#pragma once

#include "itexturetoolmodel.h"
#include "ieventmanager.h"

#include <sigc++/connection.h>

namespace ui
{

// Adaptor class connecting the EventSystem toggles connecting the various
// modes to the actual state of the backend TextureToolSelectionSystem
class TexToolModeToggles
{
private:
sigc::connection _activeSelectionModeChanged;
sigc::connection _activeManipulatorChanged;

public:
TexToolModeToggles()
{
_activeManipulatorChanged = GlobalTextureToolSelectionSystem().signal_activeManipulatorChanged()
.connect(sigc::mem_fun(this, &TexToolModeToggles::onActiveManipulatorChanged));

_activeSelectionModeChanged = GlobalTextureToolSelectionSystem().signal_selectionModeChanged()
.connect(sigc::mem_fun(this, &TexToolModeToggles::onSelectionModeChanged));

// Manipulator mode toggles
GlobalEventManager().addToggle("TextureToolRotateMode", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleTextureToolManipulatorMode", { "Rotate" });
});

GlobalEventManager().addToggle("TextureToolDragMode", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleTextureToolManipulatorMode", { "Drag" });
});

// Selection mode toggles
GlobalEventManager().addToggle("TextureToolSurfaceSelectionMode", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleTextureToolSelectionMode", { "Surface" });
});

GlobalEventManager().addToggle("TextureToolVertexSelectionMode", [this](bool)
{
GlobalCommandSystem().executeCommand("ToggleTextureToolSelectionMode", { "Vertex" });
});

onSelectionModeChanged(GlobalTextureToolSelectionSystem().getMode());
onActiveManipulatorChanged(GlobalTextureToolSelectionSystem().getActiveManipulatorType());
}

~TexToolModeToggles()
{
_activeManipulatorChanged.disconnect();
_activeSelectionModeChanged.disconnect();
}

private:
void onActiveManipulatorChanged(selection::IManipulator::Type type)
{
GlobalEventManager().setToggled("TextureToolRotateMode", type == selection::IManipulator::Rotate);
GlobalEventManager().setToggled("TextureToolDragMode", type == selection::IManipulator::Drag);
}

void onSelectionModeChanged(textool::SelectionMode mode)
{
GlobalEventManager().setToggled("TextureToolSurfaceSelectionMode", mode == textool::SelectionMode::Surface);
GlobalEventManager().setToggled("TextureToolVertexSelectionMode", mode == textool::SelectionMode::Vertex);
}
};

}
3 changes: 2 additions & 1 deletion radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -218,7 +218,7 @@ void UserInterfaceModule::initialiseModule(const IApplicationContext& ctx)
_editStopwatchStatus.reset(new statusbar::EditingStopwatchStatus);
_mapStatisticsStatus.reset(new statusbar::MapStatistics);
_manipulatorToggle.reset(new ManipulatorToggle);
_textureToolManipulatorModeToggle.reset(new TextureToolManipulatorToggle);
_textureToolModeToggles.reset(new TexToolModeToggles);
_selectionModeToggle.reset(new SelectionModeToggle);

MouseToolRegistrationHelper::RegisterTools();
Expand Down Expand Up @@ -257,6 +257,7 @@ void UserInterfaceModule::shutdownModule()
_editStopwatchStatus.reset();
_manipulatorToggle.reset();
_selectionModeToggle.reset();
_textureToolModeToggles.reset();

_mruMenu.reset();
}
Expand Down
4 changes: 2 additions & 2 deletions radiant/ui/UserInterfaceModule.h
Expand Up @@ -23,7 +23,7 @@
#include "ui/mru/MRUMenu.h"
#include "DispatchEvent.h"
#include "map/AutoSaveTimer.h"
#include "textool/TexToolManipulatorToggle.h"
#include "textool/TexToolModeToggles.h"

namespace ui
{
Expand All @@ -50,7 +50,7 @@ class UserInterfaceModule :
std::unique_ptr<statusbar::MapStatistics> _mapStatisticsStatus;
std::unique_ptr<ManipulatorToggle> _manipulatorToggle;
std::unique_ptr<SelectionModeToggle> _selectionModeToggle;
std::unique_ptr<TextureToolManipulatorToggle> _textureToolManipulatorModeToggle;
std::unique_ptr<TexToolModeToggles> _textureToolModeToggles;

sigc::connection _entitySettingsConn;
sigc::connection _coloursUpdatedConn;
Expand Down
4 changes: 4 additions & 0 deletions radiantcore/selection/textool/FaceNode.h
Expand Up @@ -105,6 +105,10 @@ class FaceNode :
{
glColor3f(1, 0.5f, 0);
}
else if (mode == SelectionMode::Vertex)
{
glColor3f(0.6f, 0.6f, 0.6f);
}
else
{
glColor3f(0.8f, 0.8f, 0.8f);
Expand Down
2 changes: 1 addition & 1 deletion tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -420,7 +420,7 @@
<ClInclude Include="..\..\radiant\settings\LocalisationModule.h" />
<ClInclude Include="..\..\radiant\settings\LocalisationProvider.h" />
<ClInclude Include="..\..\radiant\settings\Win32Registry.h" />
<ClInclude Include="..\..\radiant\textool\TexToolManipulatorToggle.h" />
<ClInclude Include="..\..\radiant\textool\TexToolModeToggles.h" />
<ClInclude Include="..\..\radiant\textool\tools\TextureToolManipulateMouseTool.h" />
<ClInclude Include="..\..\radiant\textool\tools\TextureToolMouseEvent.h" />
<ClInclude Include="..\..\radiant\textool\tools\TextureToolSelectionTool.h" />
Expand Down
2 changes: 1 addition & 1 deletion tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -1431,7 +1431,7 @@
<ClInclude Include="..\..\radiant\selection\SceneManipulateMouseTool.h">
<Filter>src\selection</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\textool\TexToolManipulatorToggle.h">
<ClInclude Include="..\..\radiant\textool\TexToolModeToggles.h">
<Filter>src\textool</Filter>
</ClInclude>
</ItemGroup>
Expand Down

0 comments on commit 200bbdc

Please sign in to comment.