From 194e02c74c8f508afe92bfd170f67bf79609c153 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Fri, 4 Dec 2020 11:40:53 -0800 Subject: [PATCH] Widget cleanup. --- common/lc_glwidget.cpp | 21 ++++++++++++++++ common/lc_glwidget.h | 56 ++++++++++++------------------------------ 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/common/lc_glwidget.cpp b/common/lc_glwidget.cpp index a6827c81..b52dfa34 100644 --- a/common/lc_glwidget.cpp +++ b/common/lc_glwidget.cpp @@ -1,6 +1,27 @@ #include "lc_global.h" #include "lc_glwidget.h" #include "lc_application.h" +#include "lc_context.h" + +lcGLWidget::lcGLWidget() +{ + mContext = new lcContext(); +} + +lcGLWidget::~lcGLWidget() +{ + if (mDeleteContext) + delete mContext; +} + +void lcGLWidget::SetContext(lcContext* Context) +{ + if (mDeleteContext) + delete mContext; + + mContext = Context; + mDeleteContext = false; +} void lcGLWidget::MakeCurrent() { diff --git a/common/lc_glwidget.h b/common/lc_glwidget.h index bd334e1e..301d5a1b 100644 --- a/common/lc_glwidget.h +++ b/common/lc_glwidget.h @@ -1,7 +1,5 @@ #pragma once -#include "lc_context.h" - enum class lcDragState { None, @@ -36,42 +34,21 @@ enum class lcCursor struct lcInputState { - int x; - int y; - Qt::KeyboardModifiers Modifiers; + int x = 0; + int y = 0; + Qt::KeyboardModifiers Modifiers = Qt::NoModifier; }; class lcGLWidget { public: - lcGLWidget() - { - mCursor = lcCursor::Default; - mWidget = nullptr; - mInputState.x = 0; - mInputState.y = 0; - mInputState.Modifiers = Qt::NoModifier; - mWidth = 1; - mHeight = 1; - mContext = new lcContext(); - mDeleteContext = true; - } + lcGLWidget(); + virtual ~lcGLWidget(); - virtual ~lcGLWidget() - { - if (mDeleteContext) - delete mContext; - } - - void SetContext(lcContext* Context) - { - if (mDeleteContext) - delete mContext; - - mContext = Context; - mDeleteContext = false; - } + lcGLWidget(const lcGLWidget&) = delete; + lcGLWidget& operator=(const lcGLWidget&) = delete; + void SetContext(lcContext* Context); void MakeCurrent(); void Redraw(); void SetCursor(lcCursor Cursor); @@ -93,15 +70,14 @@ public: virtual void OnForwardButtonUp() { } virtual void OnMouseMove() { } virtual void OnMouseWheel(float Direction) { Q_UNUSED(Direction); } - virtual void BeginDrag(lcDragState DragState) { Q_UNUSED(DragState); }; - virtual void EndDrag(bool Accept) { Q_UNUSED(Accept); }; - + virtual void BeginDrag(lcDragState DragState) { Q_UNUSED(DragState); } + virtual void EndDrag(bool Accept) { Q_UNUSED(Accept); } lcInputState mInputState; - int mWidth; - int mHeight; - lcCursor mCursor; - QGLWidget* mWidget; - lcContext* mContext; - bool mDeleteContext; + int mWidth = 1; + int mHeight = 1; + lcCursor mCursor = lcCursor::Default; + QGLWidget* mWidget = nullptr; + lcContext* mContext = nullptr; + bool mDeleteContext = true; };