CCharacterEditorViewport: Make use of in-class initializers where applicable

This commit is contained in:
Lioncash 2020-06-28 02:45:19 -04:00
parent 2f767d6b9a
commit b42536fdea
2 changed files with 25 additions and 29 deletions

View File

@ -1,26 +1,20 @@
#include "CCharacterEditorViewport.h"
CCharacterEditorViewport::CCharacterEditorViewport(QWidget *pParent /*= 0*/)
: CBasicViewport(pParent)
, mpCharNode(nullptr)
, mGridEnabled(true)
CCharacterEditorViewport::CCharacterEditorViewport(QWidget *pParent)
: CBasicViewport(pParent), mpRenderer{std::make_unique<CRenderer>()}
{
mpRenderer = new CRenderer();
qreal pixelRatio = devicePixelRatioF();
const qreal pixelRatio = devicePixelRatioF();
mpRenderer->SetViewportSize(width() * pixelRatio, height() * pixelRatio);
mpRenderer->SetClearColor(CColor(0.3f, 0.3f, 0.3f));
mpRenderer->ToggleGrid(true);
mViewInfo.ShowFlags = EShowFlag::ObjectGeometry; // This enables the mesh and not the skeleton by default
mViewInfo.pRenderer = mpRenderer;
mViewInfo.pRenderer = mpRenderer.get();
mViewInfo.pScene = nullptr;
mViewInfo.GameMode = false;
}
CCharacterEditorViewport::~CCharacterEditorViewport()
{
delete mpRenderer;
}
CCharacterEditorViewport::~CCharacterEditorViewport() = default;
void CCharacterEditorViewport::SetNode(CCharacterNode *pNode)
{
@ -29,12 +23,12 @@ void CCharacterEditorViewport::SetNode(CCharacterNode *pNode)
void CCharacterEditorViewport::CheckUserInput()
{
uint32 HoverBoneID = -1;
uint32 HoverBoneID = UINT32_MAX;
if (underMouse() && !IsMouseInputActive())
{
CRay Ray = CastRay();
SRayIntersection Intersect = mpCharNode->RayNodeIntersectTest(Ray, 0, mViewInfo);
const CRay Ray = CastRay();
const SRayIntersection Intersect = mpCharNode->RayNodeIntersectTest(Ray, 0, mViewInfo);
if (Intersect.Hit)
HoverBoneID = Intersect.ComponentIndex;
@ -51,11 +45,12 @@ void CCharacterEditorViewport::Paint()
{
mpRenderer->BeginFrame();
mCamera.LoadMatrices();
if (mGridEnabled) mGrid.AddToRenderer(mpRenderer, mViewInfo);
if (mGridEnabled)
mGrid.AddToRenderer(mpRenderer.get(), mViewInfo);
if (mpCharNode)
if (mpCharNode != nullptr)
{
mpCharNode->AddToRenderer(mpRenderer, mViewInfo);
mpCharNode->AddToRenderer(mpRenderer.get(), mViewInfo);
}
mpRenderer->RenderBuckets(mViewInfo);
@ -64,7 +59,7 @@ void CCharacterEditorViewport::Paint()
void CCharacterEditorViewport::OnResize()
{
qreal pixelRatio = devicePixelRatioF();
const qreal pixelRatio = devicePixelRatioF();
mpRenderer->SetViewportSize(width() * pixelRatio, height() * pixelRatio);
}

View File

@ -4,28 +4,29 @@
#include "Editor/CBasicViewport.h"
#include "Editor/CGridRenderable.h"
#include <Core/Scene/CCharacterNode.h>
#include <memory>
class CCharacterEditorViewport : public CBasicViewport
{
Q_OBJECT
CCharacterNode *mpCharNode;
CCharacterNode *mpCharNode = nullptr;
CGridRenderable mGrid;
CRenderer *mpRenderer;
uint32 mHoverBone;
bool mGridEnabled;
std::unique_ptr<CRenderer> mpRenderer;
uint32 mHoverBone = 0;
bool mGridEnabled = true;
public:
CCharacterEditorViewport(QWidget *pParent = 0);
explicit CCharacterEditorViewport(QWidget* pParent = nullptr);
~CCharacterEditorViewport();
void SetNode(CCharacterNode *pNode);
void CheckUserInput();
void Paint();
void OnResize();
void OnMouseClick(QMouseEvent *pEvent);
void CheckUserInput() override;
void Paint() override;
void OnResize() override;
void OnMouseClick(QMouseEvent *pEvent) override;
inline uint32 HoverBoneID() const { return mHoverBone; }
inline void SetGridEnabled(bool Enable) { mGridEnabled = Enable; }
uint32 HoverBoneID() const { return mHoverBone; }
void SetGridEnabled(bool Enable) { mGridEnabled = Enable; }
signals:
void HoverBoneChanged(uint32 BoneID);