Skip to content

Commit

Permalink
#5231: Create IRegionManager interface, for use in the XYWnd class. M…
Browse files Browse the repository at this point in the history
…ore refactoring.
  • Loading branch information
codereader committed Jun 15, 2020
1 parent 2db1573 commit fb09689
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 41 deletions.
2 changes: 2 additions & 0 deletions include/iorthoview.h
Expand Up @@ -7,6 +7,8 @@ template<typename Element>
class BasicVector3;
typedef BasicVector3<double> Vector3;

const char* const RKEY_HIGHER_ENTITY_PRIORITY = "user/ui/xyview/higherEntitySelectionPriority";

// Possible types of the orthogonal view window
enum EViewType
{
Expand Down
36 changes: 36 additions & 0 deletions 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 <regionMin>, <regionMax> 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<map::IRegionManager>(
module::GlobalModuleRegistry().getModule(MODULE_REGION_MANAGER)
)
);
return _module;
}
3 changes: 3 additions & 0 deletions include/iselection.h
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions radiant/xyview/GlobalXYWnd.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
Expand Down
13 changes: 5 additions & 8 deletions radiant/xyview/XYWnd.cpp
Expand Up @@ -7,24 +7,20 @@
#include "imainframe.h"
#include "ientity.h"
#include "igrid.h"
#include "iregion.h"
#include "iuimanager.h"

#include "wxutil/MouseButton.h"
#include "wxutil/GLWidget.h"
#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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions radiant/xyview/tools/ClipperTool.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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<EViewType>(event.getViewType()));
int nDim = (GlobalClipper().getViewType() == YZ) ? 0 : ((GlobalClipper().getViewType() == XZ) ? 1 : 2);
Expand Down
30 changes: 17 additions & 13 deletions radiantcore/map/RegionManager.cpp
Expand Up @@ -38,12 +38,11 @@
namespace map
{

namespace
{
typedef std::shared_ptr<RegionManager> RegionManagerPtr;
const std::string GKEY_PLAYER_START_ECLASS = "/mapFormat/playerStartPoint";
const char* const MODULE_REGION_MANAGER = "RegionManager";
}
namespace
{
typedef std::shared_ptr<RegionManager> RegionManagerPtr;
const std::string GKEY_PLAYER_START_ECLASS = "/mapFormat/playerStartPoint";
}

RegionManager::RegionManager() :
_active(false)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -470,10 +480,4 @@ AABB RegionManager::getVisibleBounds()

module::StaticModule<RegionManager> staticRegionManagerModule;

} // namespace map

map::RegionManager& GlobalRegion()
{
return *std::static_pointer_cast<map::RegionManager>(
module::GlobalModuleRegistry().getModule(map::MODULE_REGION_MANAGER));
}
} // namespace
19 changes: 9 additions & 10 deletions radiantcore/map/RegionManager.h
@@ -1,7 +1,7 @@
#pragma once

#include <list>
#include "imodule.h"
#include "iregion.h"
#include "icommandsystem.h"
#include "math/AABB.h"
#include "math/Vector2.h"
Expand All @@ -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;
Expand Down Expand Up @@ -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 <aabb>
Expand All @@ -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.
Expand Down Expand Up @@ -153,7 +155,4 @@ class RegionManager :
AABB getVisibleBounds();
};

} // namespace map

// Use this to call the non-static member methods.
map::RegionManager& GlobalRegion();
} // namespace
10 changes: 5 additions & 5 deletions radiantcore/selection/RadiantSelectionSystem.cpp
Expand Up @@ -29,11 +29,6 @@
namespace selection
{

namespace
{
const std::string RKEY_HIGHER_ENTITY_PRIORITY = "user/ui/xyview/higherEntitySelectionPriority";
}

// --------- RadiantSelectionSystem Implementation ------------------------------------------

RadiantSelectionSystem::RadiantSelectionSystem() :
Expand Down Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions radiantcore/selection/RadiantSelectionSystem.h
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/include.vcxproj
Expand Up @@ -164,6 +164,7 @@
<ClInclude Include="..\..\include\ipath.h" />
<ClInclude Include="..\..\include\ipreferencesystem.h" />
<ClInclude Include="..\..\include\iradiant.h" />
<ClInclude Include="..\..\include\iregion.h" />
<ClInclude Include="..\..\include\iregistry.h" />
<ClInclude Include="..\..\include\irender.h" />
<ClInclude Include="..\..\include\irenderable.h" />
Expand Down

0 comments on commit fb09689

Please sign in to comment.