diff --git a/include/iorthoview.h b/include/iorthoview.h index f1d22c605b..c67470be84 100644 --- a/include/iorthoview.h +++ b/include/iorthoview.h @@ -7,6 +7,8 @@ template class BasicVector3; typedef BasicVector3 Vector3; +const char* const RKEY_HIGHER_ENTITY_PRIORITY = "user/ui/xyview/higherEntitySelectionPriority"; + // Possible types of the orthogonal view window enum EViewType { diff --git a/include/iregion.h b/include/iregion.h new file mode 100644 index 0000000000..3a03b466c4 --- /dev/null +++ b/include/iregion.h @@ -0,0 +1,36 @@ +#pragma once + +#include "imodule.h" +#include "math/AABB.h" + +namespace map +{ + +class IRegionManager : + public RegisterableModule +{ +public: + virtual ~IRegionManager() {} + + /** + ' greebo: Stores the corners coordinates of the currently active + * region into the given , vectors. + * If regioning is inactive, the maximum possible bounds are returned. + */ + virtual AABB getRegionBounds() = 0; +}; + +} // namespace + +const char* const MODULE_REGION_MANAGER = "RegionManager"; + +inline map::IRegionManager& GlobalRegionManager() +{ + // Cache the reference locally + static map::IRegionManager& _module( + *std::static_pointer_cast( + module::GlobalModuleRegistry().getModule(MODULE_REGION_MANAGER) + ) + ); + return _module; +} diff --git a/include/iselection.h b/include/iselection.h index 654423aa8e..78225f9641 100644 --- a/include/iselection.h +++ b/include/iselection.h @@ -310,6 +310,9 @@ class SelectionSystem : * Note: the struct is defined in selectionlib.h. */ virtual const selection::WorkZone& getWorkZone() = 0; + + // Returns the center point of the current selection + virtual Vector3 getCurrentSelectionCenter() = 0; }; const char* const MODULE_SELECTIONSYSTEM("SelectionSystem"); diff --git a/radiant/xyview/GlobalXYWnd.cpp b/radiant/xyview/GlobalXYWnd.cpp index 3316bd8b10..f3df683e32 100644 --- a/radiant/xyview/GlobalXYWnd.cpp +++ b/radiant/xyview/GlobalXYWnd.cpp @@ -10,7 +10,6 @@ #include "registry/registry.h" #include "module/StaticModule.h" -#include "selection/algorithm/General.h" #include "camera/GlobalCamera.h" #include "wxutil/MouseButton.h" @@ -603,8 +602,9 @@ Vector3 XYWndManager::getFocusPosition() { Vector3 position(0,0,0); - if (GlobalSelectionSystem().countSelected() != 0) { - position = selection::algorithm::getCurrentSelectionCenter(); + if (GlobalSelectionSystem().countSelected() != 0) + { + position = GlobalSelectionSystem().getCurrentSelectionCenter(); } else { CamWndPtr cam = GlobalCamera().getActiveCamWnd(); diff --git a/radiant/xyview/XYWnd.cpp b/radiant/xyview/XYWnd.cpp index b0df6cb725..3ec7d1b121 100644 --- a/radiant/xyview/XYWnd.cpp +++ b/radiant/xyview/XYWnd.cpp @@ -7,6 +7,7 @@ #include "imainframe.h" #include "ientity.h" #include "igrid.h" +#include "iregion.h" #include "iuimanager.h" #include "wxutil/MouseButton.h" @@ -14,17 +15,12 @@ #include "string/string.h" #include "selectionlib.h" -#include "brush/TexDef.h" #include "ibrush.h" #include "camera/GlobalCamera.h" #include "camera/CameraSettings.h" #include "ui/ortho/OrthoContextMenu.h" #include "ui/overlay/Overlay.h" #include "ui/texturebrowser/TextureBrowser.h" -#include "map/RegionManager.h" -#include "map/Map.h" -#include "selection/algorithm/General.h" -#include "selection/algorithm/Primitives.h" #include "registry/registry.h" #include "selection/Device.h" #include "selection/SelectionTest.h" @@ -604,9 +600,10 @@ Vector4 XYWnd::getWindowCoordinates() { double h = (_height / 2 / _scale); // Query the region minimum/maximum vectors - Vector3 regionMin; - Vector3 regionMax; - GlobalRegion().getMinMax(regionMin, regionMax); + auto regionBounds = GlobalRegionManager().getRegionBounds(); + + Vector3 regionMin = regionBounds.origin - regionBounds.extents; + Vector3 regionMax = regionBounds.origin + regionBounds.extents; double xb = _origin[nDim1] - w; // Constrain this value to the region minimum diff --git a/radiant/xyview/tools/ClipperTool.cpp b/radiant/xyview/tools/ClipperTool.cpp index 486f902486..6d811b8ccc 100644 --- a/radiant/xyview/tools/ClipperTool.cpp +++ b/radiant/xyview/tools/ClipperTool.cpp @@ -3,8 +3,8 @@ #include "i18n.h" #include "igrid.h" #include "iclipper.h" +#include "iselection.h" #include "imainframe.h" -#include "selection/algorithm/General.h" #include "XYMouseToolEvent.h" namespace ui @@ -123,7 +123,7 @@ bool ClipperTool::alwaysReceivesMoveEvents() void ClipperTool::dropClipPoint(XYMouseToolEvent& event) { Vector3 point = event.getWorldPos(); - Vector3 mid = selection::algorithm::getCurrentSelectionCenter(); + Vector3 mid = GlobalSelectionSystem().getCurrentSelectionCenter(); GlobalClipper().setViewType(static_cast(event.getViewType())); int nDim = (GlobalClipper().getViewType() == YZ) ? 0 : ((GlobalClipper().getViewType() == XZ) ? 1 : 2); diff --git a/radiantcore/map/RegionManager.cpp b/radiantcore/map/RegionManager.cpp index 5843fec611..309372f970 100644 --- a/radiantcore/map/RegionManager.cpp +++ b/radiantcore/map/RegionManager.cpp @@ -38,12 +38,11 @@ namespace map { - namespace - { - typedef std::shared_ptr RegionManagerPtr; - const std::string GKEY_PLAYER_START_ECLASS = "/mapFormat/playerStartPoint"; - const char* const MODULE_REGION_MANAGER = "RegionManager"; - } +namespace +{ + typedef std::shared_ptr RegionManagerPtr; + const std::string GKEY_PLAYER_START_ECLASS = "/mapFormat/playerStartPoint"; +} RegionManager::RegionManager() : _active(false) @@ -104,6 +103,17 @@ void RegionManager::getMinMax(Vector3& regionMin, Vector3& regionMax) const { } } +AABB RegionManager::getRegionBounds() +{ + if (isEnabled()) + { + return _bounds; + } + + // Set the region bounds to the maximum available size + return AABB(Vector3(0, 0, 0), Vector3(_worldMax, _worldMax, _worldMax)); +} + void RegionManager::setRegion(const AABB& aabb, bool autoEnable) { _bounds = aabb; @@ -470,10 +480,4 @@ AABB RegionManager::getVisibleBounds() module::StaticModule staticRegionManagerModule; -} // namespace map - -map::RegionManager& GlobalRegion() -{ - return *std::static_pointer_cast( - module::GlobalModuleRegistry().getModule(map::MODULE_REGION_MANAGER)); -} +} // namespace diff --git a/radiantcore/map/RegionManager.h b/radiantcore/map/RegionManager.h index 0743865ca6..bc935abcb6 100644 --- a/radiantcore/map/RegionManager.h +++ b/radiantcore/map/RegionManager.h @@ -1,7 +1,7 @@ #pragma once #include -#include "imodule.h" +#include "iregion.h" #include "icommandsystem.h" #include "math/AABB.h" #include "math/Vector2.h" @@ -23,10 +23,11 @@ * the file together with an info_player_start entity. * The info_player_start is placed at the current camera position. */ -namespace map { +namespace map +{ class RegionManager : - public RegisterableModule + public IRegionManager { // TRUE, if regioning is active bool _active; @@ -72,6 +73,7 @@ class RegionManager : * * Note: If region is inactive, the maximum possible bounds are returned. */ + AABB getRegionBounds() override; void getMinMax(Vector3& regionMin, Vector3& regionMax) const; /** greebo: Sets the region bounds according to the given @@ -91,9 +93,9 @@ class RegionManager : void setRegionFromXY(Vector2 topLeft, Vector2 lowerRight); // RegisterableModule - virtual const std::string& getName() const override; - virtual const StringSet& getDependencies() const override; - virtual void initialiseModule(const ApplicationContext& ctx) override; + const std::string& getName() const override; + const StringSet& getDependencies() const override; + void initialiseModule(const ApplicationContext& ctx) override; private: /** greebo: Adds the bounding brushes that enclose the current region. @@ -153,7 +155,4 @@ class RegionManager : AABB getVisibleBounds(); }; -} // namespace map - -// Use this to call the non-static member methods. -map::RegionManager& GlobalRegion(); +} // namespace diff --git a/radiantcore/selection/RadiantSelectionSystem.cpp b/radiantcore/selection/RadiantSelectionSystem.cpp index f36d02a549..872cb51d9e 100644 --- a/radiantcore/selection/RadiantSelectionSystem.cpp +++ b/radiantcore/selection/RadiantSelectionSystem.cpp @@ -29,11 +29,6 @@ namespace selection { -namespace -{ - const std::string RKEY_HIGHER_ENTITY_PRIORITY = "user/ui/xyview/higherEntitySelectionPriority"; -} - // --------- RadiantSelectionSystem Implementation ------------------------------------------ RadiantSelectionSystem::RadiantSelectionSystem() : @@ -939,6 +934,11 @@ const WorkZone& RadiantSelectionSystem::getWorkZone() return _workZone; } +Vector3 RadiantSelectionSystem::getCurrentSelectionCenter() +{ + return algorithm::getCurrentSelectionCenter(); +} + /* greebo: Renders the currently active manipulator by setting the render state and * calling the manipulator's render method */ diff --git a/radiantcore/selection/RadiantSelectionSystem.h b/radiantcore/selection/RadiantSelectionSystem.h index 8ff4b71398..c67a244dbf 100644 --- a/radiantcore/selection/RadiantSelectionSystem.h +++ b/radiantcore/selection/RadiantSelectionSystem.h @@ -147,6 +147,7 @@ class RadiantSelectionSystem : void onManipulationCancelled() override; const WorkZone& getWorkZone() override; + Vector3 getCurrentSelectionCenter() override; void renderSolid(RenderableCollector& collector, const VolumeTest& volume) const override; void renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const override; diff --git a/tools/msvc/include.vcxproj b/tools/msvc/include.vcxproj index b65f711789..95efbb14d3 100644 --- a/tools/msvc/include.vcxproj +++ b/tools/msvc/include.vcxproj @@ -164,6 +164,7 @@ +