CBasicViewport: Make member functions const where applicable

These don't modify member state. While we're at it, we can mark
functions as override where applicable.
This commit is contained in:
Lioncash 2020-06-10 01:44:06 -04:00
parent 0096b28294
commit 01372f7049
2 changed files with 31 additions and 24 deletions

View File

@ -216,18 +216,18 @@ void CBasicViewport::SetCursorVisible(bool Visible)
setCursor(Qt::BlankCursor); setCursor(Qt::BlankCursor);
} }
bool CBasicViewport::IsCursorVisible() bool CBasicViewport::IsCursorVisible() const
{ {
return mCursorVisible; return mCursorVisible;
} }
bool CBasicViewport::IsMouseInputActive() bool CBasicViewport::IsMouseInputActive() const
{ {
static const FMouseInputs skMoveButtons = EMouseInput::MiddleButton | EMouseInput::RightButton; static const FMouseInputs skMoveButtons = EMouseInput::MiddleButton | EMouseInput::RightButton;
return ((mButtonsPressed & skMoveButtons) != 0); return ((mButtonsPressed & skMoveButtons) != 0);
} }
bool CBasicViewport::IsKeyboardInputActive() bool CBasicViewport::IsKeyboardInputActive() const
{ {
static const FKeyInputs skMoveKeys = EKeyInput::Q | EKeyInput::W | EKeyInput::E | static const FKeyInputs skMoveKeys = EKeyInput::Q | EKeyInput::W | EKeyInput::E |
EKeyInput::A | EKeyInput::S | EKeyInput::D; EKeyInput::A | EKeyInput::S | EKeyInput::D;
@ -239,13 +239,18 @@ CCamera& CBasicViewport::Camera()
return mCamera; return mCamera;
} }
CRay CBasicViewport::CastRay() const CCamera& CBasicViewport::Camera() const
{
return mCamera;
}
CRay CBasicViewport::CastRay() const
{ {
CVector2f MouseCoords = MouseDeviceCoordinates(); CVector2f MouseCoords = MouseDeviceCoordinates();
return mCamera.CastRay(MouseCoords); return mCamera.CastRay(MouseCoords);
} }
CVector2f CBasicViewport::MouseDeviceCoordinates() CVector2f CBasicViewport::MouseDeviceCoordinates() const
{ {
QPoint MousePos = mapFromGlobal(QCursor::pos()); QPoint MousePos = mapFromGlobal(QCursor::pos());

View File

@ -36,33 +36,35 @@ protected:
FKeyInputs mKeysPressed; FKeyInputs mKeysPressed;
public: public:
explicit CBasicViewport(QWidget *pParent = 0); explicit CBasicViewport(QWidget *pParent = nullptr);
~CBasicViewport(); ~CBasicViewport() override;
void initializeGL(); void initializeGL() override;
void paintGL(); void paintGL() override;
void resizeGL(int Width, int Height); void resizeGL(int Width, int Height) override;
void mousePressEvent(QMouseEvent *pEvent); void mousePressEvent(QMouseEvent *pEvent) override;
void mouseReleaseEvent(QMouseEvent *pEvent); void mouseReleaseEvent(QMouseEvent *pEvent) override;
void mouseMoveEvent(QMouseEvent *pEvent); void mouseMoveEvent(QMouseEvent *pEvent) override;
void wheelEvent(QWheelEvent *pEvent); void wheelEvent(QWheelEvent *pEvent) override;
virtual void keyPressEvent(QKeyEvent *pEvent); void keyPressEvent(QKeyEvent *pEvent) override;
virtual void keyReleaseEvent(QKeyEvent *pEvent); void keyReleaseEvent(QKeyEvent *pEvent) override;
void focusOutEvent(QFocusEvent *pEvent); void focusOutEvent(QFocusEvent *pEvent) override;
void contextMenuEvent(QContextMenuEvent *pEvent); void contextMenuEvent(QContextMenuEvent *pEvent) override;
void SetShowFlag(EShowFlag Flag, bool Visible); void SetShowFlag(EShowFlag Flag, bool Visible);
void SetGameMode(bool Enabled); void SetGameMode(bool Enabled);
void SetCursorState(const QCursor& rkCursor); void SetCursorState(const QCursor& rkCursor);
void SetCursorVisible(bool Visible); void SetCursorVisible(bool Visible);
bool IsCursorVisible(); bool IsCursorVisible() const;
bool IsMouseInputActive(); bool IsMouseInputActive() const;
bool IsKeyboardInputActive(); bool IsKeyboardInputActive() const;
CCamera& Camera(); CCamera& Camera();
CRay CastRay(); const CCamera& Camera() const;
CVector2f MouseDeviceCoordinates(); CRay CastRay() const;
CVector2f MouseDeviceCoordinates() const;
double LastRenderDuration(); double LastRenderDuration();
inline SCollisionRenderSettings& CollisionRenderSettings() { return mViewInfo.CollisionSettings; } SCollisionRenderSettings& CollisionRenderSettings() { return mViewInfo.CollisionSettings; }
const SCollisionRenderSettings& CollisionRenderSettings() const { return mViewInfo.CollisionSettings; }
public slots: public slots:
void ProcessInput(); void ProcessInput();
void Render(); void Render();