Skip to content

Commit

Permalink
CamWnd no longer implements ICameraView
Browse files Browse the repository at this point in the history
CamWnd was only ever a "forwarding wrapper" for ICameraView, with public
methods which did nothing other than pass the call directly to the equivalent
method on the contained ICameraView::Ptr member.

This is now simplified by removing the ICameraView interface from CamWnd
entirely, and instead passing the contained ICameraView object to the
constructor of CameraMouseToolEvent (which also now needs a separate
IInteractiveView reference for the MouseToolEvent parent class to expose).

The ICameraView forwarding methods are mostly removed from CamWnd now, except
for a few which are still used explicitly (by CamWnd and other classes).

Also renamed the IMainFrame's toolbar enum values from "HORIZONTAL" and
"VERTICAL" to "TOP" and "LEFT" to make clear that they refer to specific
application toolbars, not possible toolbar orientations.
  • Loading branch information
Matthew Mott committed Jan 5, 2021
1 parent 60d396a commit 0aefd97
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 83 deletions.
24 changes: 11 additions & 13 deletions include/imainframe.h
Expand Up @@ -37,9 +37,6 @@ class IMainFrame :
public RegisterableModule
{
public:
// Constructs the toplevel mainframe window and issues the "radiant startup" signal
virtual void construct() = 0;

// Returns TRUE if screen updates are enabled
virtual bool screenUpdatesEnabled() = 0;

Expand Down Expand Up @@ -68,17 +65,18 @@ class IMainFrame :
*/
virtual wxBoxSizer* getWxMainContainer() = 0;

enum Toolbar
{
TOOLBAR_HORIZONTAL, // the "view" toolbar (on the top)
TOOLBAR_VERTICAL, // the "edit" toolbar (on the left)
};
/// Identifiers for application toolbars
enum class Toolbar
{
/// Top horizontal toolbar, containing mostly view-related options
TOP,

/**
* greebo: Returns a toolbar widget, as specified by the
* passed enum value.
*/
virtual wxToolBar* getToolbar(Toolbar type) = 0;
/// Left vertical toolbar, containing various edit options
LEFT
};

/// Obtain a pointer to an application toolbar
virtual wxToolBar* getToolbar(Toolbar toolbarID) = 0;

/**
* Updates all viewports which are child of the toplevel window.
Expand Down
32 changes: 1 addition & 31 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -931,21 +931,6 @@ void CamWnd::setCameraOrigin(const Vector3& origin)
_camera->setCameraOrigin(origin);
}

const Vector3& CamWnd::getRightVector() const
{
return _camera->getRightVector();
}

const Vector3& CamWnd::getUpVector() const
{
return _camera->getUpVector();
}

const Vector3& CamWnd::getForwardVector() const
{
return _camera->getForwardVector();
}

const Vector3& CamWnd::getCameraAngles() const
{
return _camera->getCameraAngles();
Expand All @@ -956,21 +941,6 @@ void CamWnd::setCameraAngles(const Vector3& angles)
_camera->setCameraAngles(angles);
}

void CamWnd::setOriginAndAngles(const Vector3& newOrigin, const Vector3& newAngles)
{
_camera->setOriginAndAngles(newOrigin, newAngles);
}

const Matrix4& CamWnd::getModelView() const
{
return _camera->getModelView();
}

const Matrix4& CamWnd::getProjection() const
{
return _camera->getProjection();
}

const Frustum& CamWnd::getViewFrustum() const
{
return _view.getFrustum();
Expand Down Expand Up @@ -1046,7 +1016,7 @@ CameraMouseToolEvent CamWnd::createMouseEvent(const Vector2& point, const Vector
Vector2 normalisedDeviceCoords = device_constrained(
window_to_normalised_device(actualPoint, _camera->getDeviceWidth(), _camera->getDeviceHeight()));

return CameraMouseToolEvent(*this, normalisedDeviceCoords, delta);
return CameraMouseToolEvent(*_camera, *this, normalisedDeviceCoords, delta);
}

MouseTool::Result CamWnd::processMouseDownEvent(const MouseToolPtr& tool, const Vector2& point)
Expand Down
32 changes: 14 additions & 18 deletions radiant/camera/CamWnd.h
Expand Up @@ -41,7 +41,6 @@ namespace ui
/// Main 3D view widget
class CamWnd :
public wxEvtHandler,
public camera::ICameraView,
public camera::IFreeMoveView,
public scene::Graph::Observer,
public util::Noncopyable,
Expand All @@ -60,7 +59,7 @@ class CamWnd :
render::View _view;

// The contained camera
ICameraView::Ptr _camera;
camera::ICameraView::Ptr _camera;

static ShaderPtr _faceHighlightShader;
static ShaderPtr _primitiveHighlightShader;
Expand Down Expand Up @@ -135,20 +134,14 @@ class CamWnd :

camera::ICameraView& getCamera();

const Vector3& getCameraOrigin() const override;
void setCameraOrigin(const Vector3& origin) override;
/// \see ICameraView::getCameraAngles
const Vector3& getCameraAngles() const;

const Vector3& getRightVector() const override;
const Vector3& getUpVector() const override;
const Vector3& getForwardVector() const override;
/// \see ICameraView::setCameraAngles
void setCameraAngles(const Vector3& angles);

const Vector3& getCameraAngles() const override;
void setCameraAngles(const Vector3& angles) override;

void setOriginAndAngles(const Vector3& newOrigin, const Vector3& newAngles) override;

virtual const Matrix4& getModelView() const override;
virtual const Matrix4& getProjection() const override;
/// \see ICameraView::getCameraOrigin
const Vector3& getCameraOrigin() const;

const Frustum& getViewFrustum() const;

Expand All @@ -170,10 +163,10 @@ class CamWnd :
void removeHandlersMove();

// Increases/decreases the far clip plane distance
float getFarClipPlaneDistance() const override;
void setFarClipPlaneDistance(float distance) override;
bool getFarClipPlaneEnabled() const override;
void setFarClipPlaneEnabled(bool enabled) override;
float getFarClipPlaneDistance() const;
void setFarClipPlaneDistance(float distance);
bool getFarClipPlaneEnabled() const;
void setFarClipPlaneEnabled(bool enabled);

void startRenderTime();
void stopRenderTime();
Expand Down Expand Up @@ -226,6 +219,9 @@ class CamWnd :
void drawTime();
void requestRedraw(bool force);

// Motion and ICameraView related
void setCameraOrigin(const Vector3& origin);

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

void onGLResize(wxSizeEvent& ev);
Expand Down
20 changes: 11 additions & 9 deletions radiant/camera/tools/CameraMouseToolEvent.h
Expand Up @@ -10,23 +10,25 @@ namespace ui
class CameraMouseToolEvent :
public MouseToolEvent
{
private:
camera::ICameraView& _view;
camera::ICameraView& _camView;

public:
CameraMouseToolEvent(camera::ICameraView& view, const Vector2& devicePos) :
MouseToolEvent(view, devicePos),
_view(view)
CameraMouseToolEvent(camera::ICameraView& camView, IInteractiveView& iView,
const Vector2& devicePos) :
MouseToolEvent(iView, devicePos),
_camView(camView)
{}

CameraMouseToolEvent(camera::ICameraView& view, const Vector2& devicePos, const Vector2& delta) :
MouseToolEvent(view, devicePos, delta),
_view(view)
CameraMouseToolEvent(camera::ICameraView& camView, IInteractiveView& iView,
const Vector2& devicePos, const Vector2& delta) :
MouseToolEvent(iView, devicePos, delta),
_camView(camView)
{}

/// Return the ICameraView which generated this event
camera::ICameraView& getView()
{
return _view;
return _camView;
}
};

Expand Down
3 changes: 1 addition & 2 deletions radiant/ui/mainframe/MainFrame.h
Expand Up @@ -33,6 +33,7 @@ class MainFrame :
sigc::signal<void> _sigMainFrameShuttingDown;

private:
void construct();
void keyChanged();
void preDestructionCleanup();
void updateTitle();
Expand All @@ -41,8 +42,6 @@ class MainFrame :
public:
MainFrame();

void construct() override;

// IMainFrame implementation
bool screenUpdatesEnabled() override;
void enableScreenUpdates() override;
Expand Down
15 changes: 6 additions & 9 deletions radiant/ui/mainframe/TopLevelFrame.cpp
Expand Up @@ -28,15 +28,13 @@ TopLevelFrame::TopLevelFrame() :

// Instantiate the ToolbarManager and retrieve the view toolbar widget
IToolbarManager& tbCreator = GlobalUIManager().getToolbarManager();

wxToolBar* viewToolbar = tbCreator.createToolbar("view", this);

if (viewToolbar != NULL)
if (viewToolbar)
{
_toolbars[IMainFrame::TOOLBAR_HORIZONTAL] = viewToolbar;
_toolbars[IMainFrame::Toolbar::TOP] = viewToolbar;

// Pack it into the main window
_topLevelContainer->Add(_toolbars[IMainFrame::TOOLBAR_HORIZONTAL].get(), 0, wxEXPAND);
_topLevelContainer->Add(_toolbars[IMainFrame::Toolbar::TOP].get(), 0, wxEXPAND);
}
else
{
Expand All @@ -48,13 +46,12 @@ TopLevelFrame::TopLevelFrame() :

// Get the edit toolbar widget
wxToolBar* editToolbar = tbCreator.createToolbar("edit", this);

if (editToolbar != NULL)
if (editToolbar)
{
_toolbars[IMainFrame::TOOLBAR_VERTICAL] = editToolbar;
_toolbars[IMainFrame::Toolbar::LEFT] = editToolbar;

// Pack it into the main window
_mainContainer->Add(_toolbars[IMainFrame::TOOLBAR_VERTICAL].get(), 0, wxEXPAND);
_mainContainer->Add(_toolbars[IMainFrame::Toolbar::LEFT].get(), 0, wxEXPAND);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion radiant/ui/selectionset/SelectionSetToolmenu.cpp
Expand Up @@ -35,7 +35,7 @@ SelectionSetToolmenu::SelectionSetToolmenu() :
_dropdownToolId(wxID_NONE)
{
// Get the horizontal toolbar and add a custom widget
wxToolBar* toolbar = GlobalMainFrame().getToolbar(IMainFrame::TOOLBAR_HORIZONTAL);
wxToolBar* toolbar = GlobalMainFrame().getToolbar(IMainFrame::Toolbar::TOP);

// Insert a separator at the end of the toolbar
toolbar->AddSeparator();
Expand Down

0 comments on commit 0aefd97

Please sign in to comment.