From a9fac6110b5908c621cdd19f6da5bd9e5d54acf7 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 5 Dec 2020 08:45:29 -0800 Subject: [PATCH] Inlined lcInputState. --- common/lc_glwidget.cpp | 17 +++++- common/lc_glwidget.h | 29 ++++++--- common/lc_mainwindow.cpp | 18 +++--- common/lc_previewwidget.cpp | 12 ++-- common/lc_viewsphere.cpp | 38 +++++------- common/lc_viewsphere.h | 16 ++--- common/minifig.cpp | 22 +++---- common/view.cpp | 94 ++++++++++++++-------------- qt/lc_qglwidget.cpp | 118 +++++++++++++++++------------------- qt/lc_qglwidget.h | 4 +- 10 files changed, 189 insertions(+), 179 deletions(-) diff --git a/common/lc_glwidget.cpp b/common/lc_glwidget.cpp index 9e08e688..b69d4cb9 100644 --- a/common/lc_glwidget.cpp +++ b/common/lc_glwidget.cpp @@ -16,6 +16,17 @@ lcGLWidget::~lcGLWidget() delete mContext; } +void lcGLWidget::SetMousePosition(int MouseX, int MouseY) +{ + mMouseX = MouseX; + mMouseY = MouseY; +} + +void lcGLWidget::SetMouseModifiers(Qt::KeyboardModifiers MouseModifiers) +{ + mMouseModifiers = MouseModifiers; +} + void lcGLWidget::SetContext(lcContext* Context) { if (mDeleteContext) @@ -72,17 +83,17 @@ void lcGLWidget::SetCursor(lcCursor CursorType) static_assert(LC_ARRAY_COUNT(Cursors) == static_cast(lcCursor::Count), "Array size mismatch"); - QGLWidget* widget = (QGLWidget*)mWidget; + QGLWidget* mWidget = (QGLWidget*)mWidget; if (CursorType > lcCursor::Default && CursorType < lcCursor::Count) { const lcCursorInfo& Cursor = Cursors[static_cast(CursorType)]; - widget->setCursor(QCursor(QPixmap(Cursor.Name), Cursor.x, Cursor.y)); + mWidget->setCursor(QCursor(QPixmap(Cursor.Name), Cursor.x, Cursor.y)); mCursor = CursorType; } else { - widget->unsetCursor(); + mWidget->unsetCursor(); mCursor = lcCursor::Default; } } diff --git a/common/lc_glwidget.h b/common/lc_glwidget.h index a5fea838..708358f0 100644 --- a/common/lc_glwidget.h +++ b/common/lc_glwidget.h @@ -40,13 +40,6 @@ enum class lcTrackButton Right }; -struct lcInputState -{ - int x = 0; - int y = 0; - Qt::KeyboardModifiers Modifiers = Qt::NoModifier; -}; - class lcGLWidget { public: @@ -66,6 +59,18 @@ public: return mTrackButton != lcTrackButton::None; } + int GetMouseX() const + { + return mMouseX; + } + + int GetMouseY() const + { + return mMouseY; + } + + void SetMousePosition(int MouseX, int MouseY); + void SetMouseModifiers(Qt::KeyboardModifiers MouseModifiers); void SetContext(lcContext* Context); void MakeCurrent(); void Redraw(); @@ -98,15 +103,19 @@ public: virtual void BeginDrag(lcDragState DragState) { Q_UNUSED(DragState); } virtual void EndDrag(bool Accept) { Q_UNUSED(Accept); } - lcInputState mInputState; int mWidth = 1; int mHeight = 1; QGLWidget* mWidget = nullptr; lcContext* mContext = nullptr; protected: + int mMouseX = 0; + int mMouseY = 0; + Qt::KeyboardModifiers mMouseModifiers = Qt::NoModifier; + + lcTrackButton mTrackButton = lcTrackButton::None; + lcCursor mCursor = lcCursor::Default; + lcCamera* mCamera = nullptr; bool mDeleteContext = true; - lcCursor mCursor = lcCursor::Default; - lcTrackButton mTrackButton = lcTrackButton::None; }; diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 1897ffb1..2fd38aa9 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -72,7 +72,7 @@ void lcModelTabWidget::ResetLayout() TopWidget->deleteLater(); Widget->setFocus(); - SetActiveView((View*)((lcQGLWidget*)Widget)->widget); + SetActiveView((View*)((lcQGLWidget*)Widget)->mWidget); } void lcModelTabWidget::Clear() @@ -84,8 +84,8 @@ void lcModelTabWidget::Clear() mViews.RemoveAll(); mActiveView = nullptr; lcQGLWidget* Widget = (lcQGLWidget*)layout()->itemAt(0)->widget(); - delete Widget->widget; - Widget->widget = nullptr; + delete Widget->mWidget; + Widget->mWidget = nullptr; } lcMainWindow::lcMainWindow() @@ -1364,7 +1364,7 @@ QByteArray lcMainWindow::GetTabLayout() { if (Widget->metaObject() == &lcQGLWidget::staticMetaObject) { - View* CurrentView = (View*)((lcQGLWidget*)Widget)->widget; + View* CurrentView = (View*)((lcQGLWidget*)Widget)->mWidget; DataStream << (qint32)0; DataStream << (qint32)(TabWidget->GetActiveView() == CurrentView ? 1 : 0); @@ -1463,7 +1463,7 @@ void lcMainWindow::RestoreTabLayout(const QByteArray& TabLayout) View* CurrentView = nullptr; if (ParentWidget) - CurrentView = (View*)((lcQGLWidget*)ParentWidget)->widget; + CurrentView = (View*)((lcQGLWidget*)ParentWidget)->mWidget; if (CameraType == 0) { @@ -1536,7 +1536,7 @@ void lcMainWindow::RestoreTabLayout(const QByteArray& TabLayout) if (ActiveWidget && TabWidget) { - View* ActiveView = (View*)((lcQGLWidget*)ActiveWidget)->widget; + View* ActiveView = (View*)((lcQGLWidget*)ActiveWidget)->mWidget; TabWidget->SetActiveView(ActiveView); } } @@ -1613,9 +1613,9 @@ void lcMainWindow::SetCurrentModelTab(lcModel* Model) NewView = new View(Model); ViewWidget = (lcQGLWidget*)TabWidget->layout()->itemAt(0)->widget(); - ViewWidget->widget = NewView; + ViewWidget->mWidget = NewView; NewView->mWidget = ViewWidget; - float Scale = ViewWidget->deviceScale(); + float Scale = ViewWidget->GetDeviceScale(); NewView->mWidth = ViewWidget->width() * Scale; NewView->mHeight = ViewWidget->height() * Scale; AddView(NewView); @@ -1904,7 +1904,7 @@ void lcMainWindow::RemoveActiveView() } OtherWidget->setFocus(); - SetActiveView((View*)((lcQGLWidget*)OtherWidget)->widget); + SetActiveView((View*)((lcQGLWidget*)OtherWidget)->mWidget); } void lcMainWindow::ResetViews() diff --git a/common/lc_previewwidget.cpp b/common/lc_previewwidget.cpp index 79318367..84a03be3 100644 --- a/common/lc_previewwidget.cpp +++ b/common/lc_previewwidget.cpp @@ -290,8 +290,8 @@ void lcPreviewWidget::StartTracking(lcTrackButton TrackButton) { mTrackButton = TrackButton; mTrackUpdated = false; - mMouseDownX = mInputState.x; - mMouseDownY = mInputState.y; + mMouseDownX = mMouseX; + mMouseDownY = mMouseY; lcTool Tool = GetCurrentTool(); // Either lcTrackTool::None (LC_TOOL_SELECT) or lcTrackTool::OrbitXY (LC_TOOL_ROTATE_VIEW) lcModel* ActiveModel = GetActiveModel(); @@ -563,8 +563,8 @@ void lcPreviewWidget::OnMouseMove() { lcVector3 Points[4] = { - lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), - lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f), + lcVector3((float)mMouseX, (float)mMouseY, 0.0f), + lcVector3((float)mMouseX, (float)mMouseY, 1.0f), lcVector3(mMouseDownX, mMouseDownY, 0.0f), lcVector3(mMouseDownX, mMouseDownY, 1.0f) }; @@ -596,7 +596,7 @@ void lcPreviewWidget::OnMouseMove() break; case lcTrackTool::OrbitXY: - ActiveModel->UpdateOrbitTool(mCamera, 0.1f * MouseSensitivity * (mInputState.x - mMouseDownX), 0.1f * MouseSensitivity * (mInputState.y - mMouseDownY)); + ActiveModel->UpdateOrbitTool(mCamera, 0.1f * MouseSensitivity * (mMouseX - mMouseDownX), 0.1f * MouseSensitivity * (mMouseY - mMouseDownY)); Redraw(); break; @@ -607,6 +607,6 @@ void lcPreviewWidget::OnMouseMove() void lcPreviewWidget::OnMouseWheel(float Direction) { - mModel->Zoom(mCamera, (int)(((mInputState.Modifiers & Qt::ControlModifier) ? 100 : 10) * Direction)); + mModel->Zoom(mCamera, (int)(((mMouseModifiers & Qt::ControlModifier) ? 100 : 10) * Direction)); Redraw(); } diff --git a/common/lc_viewsphere.cpp b/common/lc_viewsphere.cpp index 8a37216b..c2538b2b 100644 --- a/common/lc_viewsphere.cpp +++ b/common/lc_viewsphere.cpp @@ -17,25 +17,19 @@ const float lcViewSphere::mHighlightRadius = 0.35f; const int lcViewSphere::mSubdivisions = 7; lcViewSphere::lcViewSphere(View* View) - : mPreview(nullptr), - mView(View), - mIsPreview(false) + : mWidget(View), mPreview(nullptr), mView(View), mIsPreview(false) { - mMouseDown = false; } lcViewSphere::lcViewSphere(lcPreviewWidget* Preview) - : mPreview(Preview), - mView(nullptr), - mIsPreview(true) + : mWidget(Preview), mPreview(Preview), mView(nullptr), mIsPreview(true) { - mMouseDown = false; mViewSphereSize = lcGetPreferences().mPreviewViewSphereSize; } lcMatrix44 lcViewSphere::GetViewMatrix() const { - lcMatrix44 ViewMatrix = mIsPreview ? mPreview->GetCamera()->mWorldView : mView->GetCamera()->mWorldView; + lcMatrix44 ViewMatrix = mWidget->GetCamera()->mWorldView; ViewMatrix.SetTranslation(lcVector3(0, 0, 0)); return ViewMatrix; } @@ -170,9 +164,9 @@ void lcViewSphere::Draw() if (ViewportSize == 0 || !Preferences.mViewSphereEnabled) return; - lcContext* Context = mIsPreview ? mPreview->mContext : mView->mContext; - int Width = mIsPreview ? mPreview->mWidth : mView->mWidth; - int Height = mIsPreview ? mPreview->mHeight : mView->mHeight; + lcContext* Context = mWidget->mContext; + int Width = mWidget->mWidth; + int Height = mWidget->mHeight; lcViewSphereLocation Location = mIsPreview ? Preferences.mPreviewViewSphereLocation : Preferences.mViewSphereLocation; int Left = (Location == lcViewSphereLocation::BottomLeft || Location == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize; @@ -242,8 +236,8 @@ bool lcViewSphere::OnLeftButtonDown() if (!mIntersectionFlags.any()) return false; - mMouseDownX = mIsPreview ? mPreview->mInputState.x : mView->mInputState.x; - mMouseDownY = mIsPreview ? mPreview->mInputState.y : mView->mInputState.y; + mMouseDownX = mWidget->GetMouseX(); + mMouseDownY = mWidget->GetMouseY(); mMouseDown = true; return true; @@ -291,7 +285,7 @@ bool lcViewSphere::OnMouseMove() return true; } - if (mIsPreview ? mPreview->IsTracking() : mView->IsTracking()) + if (mWidget->IsTracking()) return false; std::bitset<6> IntersectionFlags = GetIntersectionFlags(mIntersection); @@ -299,7 +293,7 @@ bool lcViewSphere::OnMouseMove() if (IntersectionFlags != mIntersectionFlags) { mIntersectionFlags = IntersectionFlags; - mIsPreview ? mPreview->Redraw() : mView->Redraw(); + mWidget->Redraw(); } return mIntersectionFlags.any(); @@ -307,8 +301,8 @@ bool lcViewSphere::OnMouseMove() bool lcViewSphere::IsDragging() const { - int InputStateX = mIsPreview ? mPreview->mInputState.x : mView->mInputState.x; - int InputStateY = mIsPreview ? mPreview->mInputState.y : mView->mInputState.y; + int InputStateX = mWidget->GetMouseX(); + int InputStateY = mWidget->GetMouseY(); return mMouseDown && (qAbs(mMouseDownX - InputStateX) > 3 || qAbs(mMouseDownY - InputStateY) > 3); } @@ -317,13 +311,13 @@ std::bitset<6> lcViewSphere::GetIntersectionFlags(lcVector3& Intersection) const const lcPreferences& Preferences = lcGetPreferences(); lcViewSphereLocation Location = mIsPreview ? Preferences.mPreviewViewSphereLocation : Preferences.mViewSphereLocation; - int Width = mIsPreview ? mPreview->mWidth : mView->mWidth; - int Height = mIsPreview ? mPreview->mHeight : mView->mHeight; + int Width = mWidget->mWidth; + int Height = mWidget->mHeight; int ViewportSize = mIsPreview ? mViewSphereSize : Preferences.mViewSphereSize; int Left = (Location == lcViewSphereLocation::BottomLeft || Location == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize; int Bottom = (Location == lcViewSphereLocation::BottomLeft || Location == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize; - int x = (mIsPreview ? mPreview->mInputState.x : mView->mInputState.x) - Left; - int y = (mIsPreview ? mPreview->mInputState.y : mView->mInputState.y) - Bottom; + int x = mWidget->GetMouseX() - Left; + int y = mWidget->GetMouseY() - Bottom; std::bitset<6> IntersectionFlags; if (x < 0 || x > Width || y < 0 || y > Height) diff --git a/common/lc_viewsphere.h b/common/lc_viewsphere.h index e6362694..2eb816f4 100644 --- a/common/lc_viewsphere.h +++ b/common/lc_viewsphere.h @@ -4,6 +4,7 @@ #include "lc_context.h" #include +class lcGLWidget; class View; class lcPreviewWidget; @@ -27,15 +28,16 @@ protected: lcMatrix44 GetProjectionMatrix() const; std::bitset<6> GetIntersectionFlags(lcVector3& Intersection) const; - lcPreviewWidget* mPreview; - View* mView; + lcGLWidget* mWidget = nullptr; + lcPreviewWidget* mPreview = nullptr; + View* mView = nullptr; lcVector3 mIntersection; std::bitset<6> mIntersectionFlags; - int mViewSphereSize; - int mMouseDownX; - int mMouseDownY; - bool mMouseDown; - bool mIsPreview; + int mViewSphereSize = 1; + int mMouseDownX = 0; + int mMouseDownY = 0; + bool mMouseDown = false; + bool mIsPreview = false; static lcTexture* mTexture; static lcVertexBuffer mVertexBuffer; diff --git a/common/minifig.cpp b/common/minifig.cpp index 563fe984..0ca23bcb 100644 --- a/common/minifig.cpp +++ b/common/minifig.cpp @@ -402,8 +402,8 @@ void MinifigWizard::OnLeftButtonDown() { if (mTracking == LC_TRACK_NONE) { - mDownX = mInputState.x; - mDownY = mInputState.y; + mDownX = mMouseX; + mDownY = mMouseY; mTracking = LC_TRACK_LEFT; } } @@ -424,8 +424,8 @@ void MinifigWizard::OnRightButtonDown() { if (mTracking == LC_TRACK_NONE) { - mDownX = mInputState.x; - mDownY = mInputState.y; + mDownX = mMouseX; + mDownY = mMouseY; mTracking = LC_TRACK_RIGHT; } } @@ -441,30 +441,30 @@ void MinifigWizard::OnMouseMove() if (mTracking == LC_TRACK_LEFT) { // Rotate. - mRotateZ += mInputState.x - mDownX; - mRotateX += mInputState.y - mDownY; + mRotateZ += mMouseX - mDownX; + mRotateX += mMouseY - mDownY; if (mRotateX > 179.5f) mRotateX = 179.5f; else if (mRotateX < 0.5f) mRotateX = 0.5f; - mDownX = mInputState.x; - mDownY = mInputState.y; + mDownX = mMouseX; + mDownY = mMouseY; Redraw(); } else if (mTracking == LC_TRACK_RIGHT) { // Zoom. - mDistance += (float)(mDownY - mInputState.y) * 0.2f; + mDistance += (float)(mDownY - mMouseY) * 0.2f; mAutoZoom = false; if (mDistance < 0.5f) mDistance = 0.5f; - mDownX = mInputState.x; - mDownY = mInputState.y; + mDownX = mMouseX; + mDownY = mMouseY; Redraw(); } diff --git a/common/view.cpp b/common/view.cpp index 80c69569..5ecec44c 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -432,10 +432,10 @@ lcCursor View::GetCursor() const { if (mTrackTool == lcTrackTool::Select) { - if (mInputState.Modifiers & Qt::ControlModifier) + if (mMouseModifiers & Qt::ControlModifier) return lcCursor::SelectAdd; - if (mInputState.Modifiers & Qt::ShiftModifier) + if (mMouseModifiers & Qt::ShiftModifier) return lcCursor::SelectRemove; } @@ -593,7 +593,7 @@ lcMatrix44 View::GetPieceInsertPosition(bool IgnoreSelected, PieceInfo* Info) co return WorldMatrix; } - std::array ClickPoints = {{ lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f) }}; + std::array ClickPoints = {{ lcVector3((float)mMouseX, (float)mMouseY, 0.0f), lcVector3((float)mMouseX, (float)mMouseY, 1.0f) }}; UnprojectPoints(ClickPoints.data(), 2); if (ActiveModel != mModel) @@ -613,14 +613,14 @@ lcMatrix44 View::GetPieceInsertPosition(bool IgnoreSelected, PieceInfo* Info) co return lcMatrix44Translation(Intersection); } - return lcMatrix44Translation(UnprojectPoint(lcVector3((float)mInputState.x, (float)mInputState.y, 0.9f))); + return lcMatrix44Translation(UnprojectPoint(lcVector3((float)mMouseX, (float)mMouseY, 0.9f))); } lcVector3 View::GetCameraLightInsertPosition() const { lcModel* ActiveModel = GetActiveModel(); - std::array ClickPoints = { { lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f) } }; + std::array ClickPoints = { { lcVector3((float)mMouseX, (float)mMouseY, 0.0f), lcVector3((float)mMouseX, (float)mMouseY, 1.0f) } }; UnprojectPoints(ClickPoints.data(), 2); if (ActiveModel != mModel) @@ -646,8 +646,8 @@ void View::GetRayUnderPointer(lcVector3& Start, lcVector3& End) const { lcVector3 StartEnd[2] = { - lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), - lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f) + lcVector3((float)mMouseX, (float)mMouseY, 0.0f), + lcVector3((float)mMouseX, (float)mMouseY, 1.0f) }; UnprojectPoints(StartEnd, 2); @@ -660,8 +660,8 @@ lcObjectSection View::FindObjectUnderPointer(bool PiecesOnly, bool IgnoreSelecte { lcVector3 StartEnd[2] = { - lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), - lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f) + lcVector3((float)mMouseX, (float)mMouseY, 0.0f), + lcVector3((float)mMouseX, (float)mMouseY, 1.0f) }; UnprojectPoints(StartEnd, 2); @@ -1435,8 +1435,8 @@ void View::DrawSelectZoomRegionOverlay() float pt1x = (float)mMouseDownX; float pt1y = (float)mMouseDownY; - float pt2x = (float)mInputState.x; - float pt2y = (float)mInputState.y; + float pt2x = (float)mMouseX; + float pt2y = (float)mMouseY; float Left, Right, Bottom, Top; @@ -1846,7 +1846,7 @@ lcTrackTool View::GetOverrideTrackTool(Qt::MouseButton Button) const if (mTrackToolFromOverlay) return lcTrackTool::None; - lcTool OverrideTool = gMouseShortcuts.GetTool(Button, mInputState.Modifiers); + lcTool OverrideTool = gMouseShortcuts.GetTool(Button, mMouseModifiers); if (OverrideTool == lcTool::Count) return lcTrackTool::None; @@ -1972,8 +1972,8 @@ void View::UpdateTrackTool() { lcTool CurrentTool = gMainWindow->GetTool(); lcTrackTool NewTrackTool = mTrackTool; - int x = mInputState.x; - int y = mInputState.y; + int x = mMouseX; + int y = mMouseY; bool Redraw = false; mTrackToolFromOverlay = false; lcModel* ActiveModel = GetActiveModel(); @@ -2161,7 +2161,7 @@ void View::UpdateTrackTool() } } - if (CurrentTool == lcTool::Select && NewTrackTool == lcTrackTool::Select && mInputState.Modifiers == Qt::NoModifier) + if (CurrentTool == lcTool::Select && NewTrackTool == lcTrackTool::Select && mMouseModifiers == Qt::NoModifier) { lcObjectSection ObjectSection = FindObjectUnderPointer(false, false); lcObject* Object = ObjectSection.Object; @@ -2506,8 +2506,8 @@ void View::StartTracking(lcTrackButton TrackButton) { mTrackButton = TrackButton; mTrackUpdated = false; - mMouseDownX = mInputState.x; - mMouseDownY = mInputState.y; + mMouseDownX = mMouseX; + mMouseDownY = mMouseY; lcTool Tool = GetCurrentTool(); lcModel* ActiveModel = GetActiveModel(); @@ -2583,13 +2583,13 @@ void View::StopTracking(bool Accept) break; case lcTool::Select: - if (Accept && mMouseDownX != mInputState.x && mMouseDownY != mInputState.y) + if (Accept && mMouseDownX != mMouseX && mMouseDownY != mMouseY) { - lcArray Objects = FindObjectsInBox(mMouseDownX, mMouseDownY, mInputState.x, mInputState.y); + lcArray Objects = FindObjectsInBox(mMouseDownX, mMouseDownY, mMouseX, mMouseY); - if (mInputState.Modifiers & Qt::ControlModifier) + if (mMouseModifiers & Qt::ControlModifier) ActiveModel->AddToSelection(Objects, true, true); - else if (mInputState.Modifiers & Qt::ShiftModifier) + else if (mMouseModifiers & Qt::ShiftModifier) ActiveModel->RemoveFromSelection(Objects); else ActiveModel->SetSelectionAndFocus(Objects, nullptr, 0, true); @@ -2615,15 +2615,15 @@ void View::StopTracking(bool Accept) case lcTool::ZoomRegion: { - if (mInputState.x == mMouseDownX || mInputState.y == mMouseDownY) + if (mMouseX == mMouseDownX || mMouseY == mMouseDownY) break; lcVector3 Points[6] = { - lcVector3((mMouseDownX + lcMin(mInputState.x, mWidth - 1)) / 2, (mMouseDownY + lcMin(mInputState.y, mHeight - 1)) / 2, 0.0f), - lcVector3((mMouseDownX + lcMin(mInputState.x, mWidth - 1)) / 2, (mMouseDownY + lcMin(mInputState.y, mHeight - 1)) / 2, 1.0f), - lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), - lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f), + lcVector3((mMouseDownX + lcMin(mMouseX, mWidth - 1)) / 2, (mMouseDownY + lcMin(mMouseY, mHeight - 1)) / 2, 0.0f), + lcVector3((mMouseDownX + lcMin(mMouseX, mWidth - 1)) / 2, (mMouseDownY + lcMin(mMouseY, mHeight - 1)) / 2, 1.0f), + lcVector3((float)mMouseX, (float)mMouseY, 0.0f), + lcVector3((float)mMouseX, (float)mMouseY, 1.0f), lcVector3(mMouseDownX, mMouseDownY, 0.0f), lcVector3(mMouseDownX, mMouseDownY, 1.0f) }; @@ -2683,7 +2683,7 @@ void View::OnButtonDown(lcTrackButton TrackButton) ActiveModel->InsertPieceToolClicked(GetPieceInsertPosition(false, gMainWindow->GetCurrentPieceInfo())); - if ((mInputState.Modifiers & Qt::ControlModifier) == 0) + if ((mMouseModifiers & Qt::ControlModifier) == 0) gMainWindow->SetTool(lcTool::Select); UpdateTrackTool(); @@ -2694,7 +2694,7 @@ void View::OnButtonDown(lcTrackButton TrackButton) { ActiveModel->PointLightToolClicked(GetCameraLightInsertPosition()); - if ((mInputState.Modifiers & Qt::ControlModifier) == 0) + if ((mMouseModifiers & Qt::ControlModifier) == 0) gMainWindow->SetTool(lcTool::Select); UpdateTrackTool(); @@ -2710,9 +2710,9 @@ void View::OnButtonDown(lcTrackButton TrackButton) { lcObjectSection ObjectSection = FindObjectUnderPointer(false, false); - if (mInputState.Modifiers & Qt::ControlModifier) + if (mMouseModifiers & Qt::ControlModifier) ActiveModel->FocusOrDeselectObject(ObjectSection); - else if (mInputState.Modifiers & Qt::ShiftModifier) + else if (mMouseModifiers & Qt::ShiftModifier) ActiveModel->RemoveFromSelection(ObjectSection); else ActiveModel->ClearSelectionAndSetFocus(ObjectSection, true); @@ -2813,9 +2813,9 @@ void View::OnLeftButtonDoubleClick() lcObjectSection ObjectSection = FindObjectUnderPointer(false, false); lcModel* ActiveModel = GetActiveModel(); - if (mInputState.Modifiers & Qt::ControlModifier) + if (mMouseModifiers & Qt::ControlModifier) ActiveModel->FocusOrDeselectObject(ObjectSection); - else if (mInputState.Modifiers & Qt::ShiftModifier) + else if (mMouseModifiers & Qt::ShiftModifier) ActiveModel->RemoveFromSelection(ObjectSection); else ActiveModel->ClearSelectionAndSetFocus(ObjectSection, true); @@ -2953,8 +2953,8 @@ void View::OnMouseMove() { lcVector3 Points[4] = { - lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), - lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f), + lcVector3((float)mMouseX, (float)mMouseY, 0.0f), + lcVector3((float)mMouseX, (float)mMouseY, 1.0f), lcVector3(mMouseDownX, mMouseDownY, 0.0f), lcVector3(mMouseDownX, mMouseDownY, 1.0f) }; @@ -3131,8 +3131,8 @@ void View::OnMouseMove() MoveY = -Dir1; } - MoveX *= 36.0f * (float)(mInputState.x - mMouseDownX) * MouseSensitivity; - MoveY *= 36.0f * (float)(mInputState.y - mMouseDownY) * MouseSensitivity; + MoveX *= 36.0f * (float)(mMouseX - mMouseDownX) * MouseSensitivity; + MoveY *= 36.0f * (float)(mMouseY - mMouseDownY) * MouseSensitivity; ActiveModel->UpdateRotateTool(MoveX + MoveY, mTrackButton != lcTrackButton::Left); } @@ -3144,8 +3144,8 @@ void View::OnMouseMove() lcVector3 ScreenX = lcCross(ScreenZ, mCamera->mUpVector); lcVector3 ScreenY = mCamera->mUpVector; - lcVector3 MoveX = 36.0f * (float)(mInputState.x - mMouseDownX) * MouseSensitivity * ScreenX; - lcVector3 MoveY = 36.0f * (float)(mInputState.y - mMouseDownY) * MouseSensitivity * ScreenY; + lcVector3 MoveX = 36.0f * (float)(mMouseX - mMouseDownX) * MouseSensitivity * ScreenX; + lcVector3 MoveY = 36.0f * (float)(mMouseY - mMouseDownY) * MouseSensitivity * ScreenY; ActiveModel->UpdateRotateTool(MoveX + MoveY, mTrackButton != lcTrackButton::Left); } break; @@ -3154,7 +3154,7 @@ void View::OnMouseMove() { lcVector3 ScreenZ = lcNormalize(mCamera->mTargetPosition - mCamera->mPosition); - ActiveModel->UpdateRotateTool(36.0f * (float)(mInputState.y - mMouseDownY) * MouseSensitivity * ScreenZ, mTrackButton != lcTrackButton::Left); + ActiveModel->UpdateRotateTool(36.0f * (float)(mMouseY - mMouseDownY) * MouseSensitivity * ScreenZ, mTrackButton != lcTrackButton::Left); } break; @@ -3164,15 +3164,15 @@ void View::OnMouseMove() break; case lcTrackTool::Zoom: - ActiveModel->UpdateZoomTool(mCamera, 2.0f * MouseSensitivity * (mInputState.y - mMouseDownY)); + ActiveModel->UpdateZoomTool(mCamera, 2.0f * MouseSensitivity * (mMouseY - mMouseDownY)); break; case lcTrackTool::Pan: { lcVector3 Points[4] = { - lcVector3((float)mInputState.x, (float)mInputState.y, 0.0f), - lcVector3((float)mInputState.x, (float)mInputState.y, 1.0f), + lcVector3((float)mMouseX, (float)mMouseY, 0.0f), + lcVector3((float)mMouseX, (float)mMouseY, 1.0f), lcVector3(mMouseDownX, mMouseDownY, 0.0f), lcVector3(mMouseDownX, mMouseDownY, 1.0f) }; @@ -3203,19 +3203,19 @@ void View::OnMouseMove() break; case lcTrackTool::OrbitX: - ActiveModel->UpdateOrbitTool(mCamera, 0.1f * MouseSensitivity * (mInputState.x - mMouseDownX), 0.0f); + ActiveModel->UpdateOrbitTool(mCamera, 0.1f * MouseSensitivity * (mMouseX - mMouseDownX), 0.0f); break; case lcTrackTool::OrbitY: - ActiveModel->UpdateOrbitTool(mCamera, 0.0f, 0.1f * MouseSensitivity * (mInputState.y - mMouseDownY)); + ActiveModel->UpdateOrbitTool(mCamera, 0.0f, 0.1f * MouseSensitivity * (mMouseY - mMouseDownY)); break; case lcTrackTool::OrbitXY: - ActiveModel->UpdateOrbitTool(mCamera, 0.1f * MouseSensitivity * (mInputState.x - mMouseDownX), 0.1f * MouseSensitivity * (mInputState.y - mMouseDownY)); + ActiveModel->UpdateOrbitTool(mCamera, 0.1f * MouseSensitivity * (mMouseX - mMouseDownX), 0.1f * MouseSensitivity * (mMouseY - mMouseDownY)); break; case lcTrackTool::Roll: - ActiveModel->UpdateRollTool(mCamera, 2.0f * MouseSensitivity * (mInputState.x - mMouseDownX) * LC_DTOR); + ActiveModel->UpdateRollTool(mCamera, 2.0f * MouseSensitivity * (mMouseX - mMouseDownX) * LC_DTOR); break; case lcTrackTool::ZoomRegion: @@ -3229,5 +3229,5 @@ void View::OnMouseMove() void View::OnMouseWheel(float Direction) { - mModel->Zoom(mCamera, (int)(((mInputState.Modifiers & Qt::ControlModifier) ? 100 : 10) * Direction)); + mModel->Zoom(mCamera, (int)(((mMouseModifiers & Qt::ControlModifier) ? 100 : 10) * Direction)); } diff --git a/qt/lc_qglwidget.cpp b/qt/lc_qglwidget.cpp index 2279f595..84dfef2c 100644 --- a/qt/lc_qglwidget.cpp +++ b/qt/lc_qglwidget.cpp @@ -23,21 +23,21 @@ lcQGLWidget::lcQGLWidget(QWidget* Parent, lcGLWidget* Owner) : QGLWidget(Parent, gWidgetList.isEmpty() ? nullptr : gWidgetList.first()) { mWheelAccumulator = 0; - widget = Owner; - widget->mWidget = this; + mWidget = Owner; + mWidget->mWidget = this; makeCurrent(); if (gWidgetList.isEmpty()) { // TODO: Find a better place for the grid texture and font - gStringCache.Initialize(widget->mContext); - gTexFont.Initialize(widget->mContext); + gStringCache.Initialize(mWidget->mContext); + gTexFont.Initialize(mWidget->mContext); lcInitializeGLExtensions(context()); lcContext::CreateResources(); - View::CreateResources(widget->mContext); - lcViewSphere::CreateResources(widget->mContext); + View::CreateResources(mWidget->mContext); + lcViewSphere::CreateResources(mWidget->mContext); if (!gSupportsShaderObjects && lcGetPreferences().mShadingMode == lcShadingMode::DefaultLights) lcGetPreferences().mShadingMode = lcShadingMode::Flat; @@ -51,7 +51,7 @@ lcQGLWidget::lcQGLWidget(QWidget* Parent, lcGLWidget* Owner) gWidgetList.append(this); - widget->OnInitialUpdate(); + mWidget->OnInitialUpdate(); setMouseTracking(true); @@ -71,16 +71,16 @@ lcQGLWidget::~lcQGLWidget() gStringCache.Reset(); gTexFont.Reset(); - lcGetPiecesLibrary()->ReleaseBuffers(widget->mContext); - View::DestroyResources(widget->mContext); + lcGetPiecesLibrary()->ReleaseBuffers(mWidget->mContext); + View::DestroyResources(mWidget->mContext); lcContext::DestroyResources(); - lcViewSphere::DestroyResources(widget->mContext); + lcViewSphere::DestroyResources(mWidget->mContext); delete gPlaceholderMesh; gPlaceholderMesh = nullptr; } - delete widget; + delete mWidget; } QSize lcQGLWidget::sizeHint() const @@ -91,7 +91,7 @@ QSize lcQGLWidget::sizeHint() const void lcQGLWidget::SetPreviewPosition(const QRect& ParentRect) { lcPreferences& Preferences = lcGetPreferences(); - lcPreviewWidget* Preview = reinterpret_cast(widget); + lcPreviewWidget* Preview = reinterpret_cast(mWidget); setWindowTitle(tr("%1 Preview").arg(Preview->IsModel() ? "Submodel" : "Part")); @@ -102,7 +102,7 @@ void lcQGLWidget::SetPreviewPosition(const QRect& ParentRect) } mPreferredSize = QSize(Size[0], Size[1]); - float Scale = deviceScale(); + float Scale = GetDeviceScale(); Preview->mWidth = width() * Scale; Preview->mHeight = height() * Scale; @@ -142,21 +142,21 @@ void lcQGLWidget::SetPreviewPosition(const QRect& ParentRect) void lcQGLWidget::resizeGL(int Width, int Height) { - widget->mWidth = Width; - widget->mHeight = Height; + mWidget->mWidth = Width; + mWidget->mHeight = Height; } void lcQGLWidget::paintGL() { - widget->OnDraw(); + mWidget->OnDraw(); } void lcQGLWidget::keyPressEvent(QKeyEvent* KeyEvent) { if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift) { - widget->mInputState.Modifiers = KeyEvent->modifiers(); - widget->OnUpdateCursor(); + mWidget->SetMouseModifiers(KeyEvent->modifiers()); + mWidget->OnUpdateCursor(); } QGLWidget::keyPressEvent(KeyEvent); @@ -166,8 +166,8 @@ void lcQGLWidget::keyReleaseEvent(QKeyEvent* KeyEvent) { if (KeyEvent->key() == Qt::Key_Control || KeyEvent->key() == Qt::Key_Shift) { - widget->mInputState.Modifiers = KeyEvent->modifiers(); - widget->OnUpdateCursor(); + mWidget->SetMouseModifiers(KeyEvent->modifiers()); + mWidget->OnUpdateCursor(); } QGLWidget::keyReleaseEvent(KeyEvent); @@ -175,33 +175,32 @@ void lcQGLWidget::keyReleaseEvent(QKeyEvent* KeyEvent) void lcQGLWidget::mousePressEvent(QMouseEvent* MouseEvent) { - float scale = deviceScale(); + float DeviceScale = GetDeviceScale(); - widget->mInputState.x = MouseEvent->x() * scale; - widget->mInputState.y = widget->mHeight - MouseEvent->y() * scale - 1; - widget->mInputState.Modifiers = MouseEvent->modifiers(); + mWidget->SetMousePosition(MouseEvent->x() * DeviceScale, mWidget->mHeight - MouseEvent->y() * DeviceScale - 1); + mWidget->SetMouseModifiers(MouseEvent->modifiers()); switch (MouseEvent->button()) { case Qt::LeftButton: - widget->OnLeftButtonDown(); + mWidget->OnLeftButtonDown(); break; case Qt::MidButton: - widget->OnMiddleButtonDown(); + mWidget->OnMiddleButtonDown(); break; case Qt::RightButton: - widget->OnRightButtonDown(); + mWidget->OnRightButtonDown(); break; #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) case Qt::BackButton: - widget->OnBackButtonDown(); + mWidget->OnBackButtonDown(); break; case Qt::ForwardButton: - widget->OnForwardButtonDown(); + mWidget->OnForwardButtonDown(); break; #endif @@ -212,33 +211,32 @@ void lcQGLWidget::mousePressEvent(QMouseEvent* MouseEvent) void lcQGLWidget::mouseReleaseEvent(QMouseEvent* MouseEvent) { - float scale = deviceScale(); + float DeviceScale = GetDeviceScale(); - widget->mInputState.x = MouseEvent->x() * scale; - widget->mInputState.y = widget->mHeight - MouseEvent->y() * scale - 1; - widget->mInputState.Modifiers = MouseEvent->modifiers(); + mWidget->SetMousePosition(MouseEvent->x() * DeviceScale, mWidget->mHeight - MouseEvent->y() * DeviceScale - 1); + mWidget->SetMouseModifiers(MouseEvent->modifiers()); switch (MouseEvent->button()) { case Qt::LeftButton: - widget->OnLeftButtonUp(); + mWidget->OnLeftButtonUp(); break; case Qt::MidButton: - widget->OnMiddleButtonUp(); + mWidget->OnMiddleButtonUp(); break; case Qt::RightButton: - widget->OnRightButtonUp(); + mWidget->OnRightButtonUp(); break; #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) case Qt::BackButton: - widget->OnBackButtonUp(); + mWidget->OnBackButtonUp(); break; case Qt::ForwardButton: - widget->OnForwardButtonUp(); + mWidget->OnForwardButtonUp(); break; #endif @@ -249,16 +247,15 @@ void lcQGLWidget::mouseReleaseEvent(QMouseEvent* MouseEvent) void lcQGLWidget::mouseDoubleClickEvent(QMouseEvent* MouseEvent) { - float scale = deviceScale(); + float DeviceScale = GetDeviceScale(); - widget->mInputState.x = MouseEvent->x() * scale; - widget->mInputState.y = widget->mHeight - MouseEvent->y() * scale - 1; - widget->mInputState.Modifiers = MouseEvent->modifiers(); + mWidget->SetMousePosition(MouseEvent->x() * DeviceScale, mWidget->mHeight - MouseEvent->y() * DeviceScale - 1); + mWidget->SetMouseModifiers(MouseEvent->modifiers()); switch (MouseEvent->button()) { case Qt::LeftButton: - widget->OnLeftButtonDoubleClick(); + mWidget->OnLeftButtonDoubleClick(); break; default: break; @@ -267,13 +264,12 @@ void lcQGLWidget::mouseDoubleClickEvent(QMouseEvent* MouseEvent) void lcQGLWidget::mouseMoveEvent(QMouseEvent* MouseEvent) { - float scale = deviceScale(); + float DeviceScale = GetDeviceScale(); - widget->mInputState.x = MouseEvent->x() * scale; - widget->mInputState.y = widget->mHeight - MouseEvent->y() * scale - 1; - widget->mInputState.Modifiers = MouseEvent->modifiers(); + mWidget->SetMousePosition(MouseEvent->x() * DeviceScale, mWidget->mHeight - MouseEvent->y() * DeviceScale - 1); + mWidget->SetMouseModifiers(MouseEvent->modifiers()); - widget->OnMouseMove(); + mWidget->OnMouseMove(); } void lcQGLWidget::wheelEvent(QWheelEvent* WheelEvent) @@ -284,11 +280,10 @@ void lcQGLWidget::wheelEvent(QWheelEvent* WheelEvent) return; } - float scale = deviceScale(); + float DeviceScale = GetDeviceScale(); - widget->mInputState.x = WheelEvent->x() * scale; - widget->mInputState.y = widget->mHeight - WheelEvent->y() * scale - 1; - widget->mInputState.Modifiers = WheelEvent->modifiers(); + mWidget->SetMousePosition(WheelEvent->x() * DeviceScale, mWidget->mHeight - WheelEvent->y() * DeviceScale - 1); + mWidget->SetMouseModifiers(WheelEvent->modifiers()); #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) mWheelAccumulator += WheelEvent->angleDelta().y() / 8; @@ -299,7 +294,7 @@ void lcQGLWidget::wheelEvent(QWheelEvent* WheelEvent) if (numSteps) { - widget->OnMouseWheel(numSteps); + mWidget->OnMouseWheel(numSteps); mWheelAccumulator -= numSteps * 15; } @@ -313,13 +308,13 @@ void lcQGLWidget::dragEnterEvent(QDragEnterEvent* DragEnterEvent) if (MimeData->hasFormat("application/vnd.leocad-part")) { DragEnterEvent->acceptProposedAction(); - widget->BeginDrag(lcDragState::Piece); + mWidget->BeginDrag(lcDragState::Piece); return; } else if (MimeData->hasFormat("application/vnd.leocad-color")) { DragEnterEvent->acceptProposedAction(); - widget->BeginDrag(lcDragState::Color); + mWidget->BeginDrag(lcDragState::Color); return; } @@ -328,7 +323,7 @@ void lcQGLWidget::dragEnterEvent(QDragEnterEvent* DragEnterEvent) void lcQGLWidget::dragLeaveEvent(QDragLeaveEvent* DragLeaveEvent) { - widget->EndDrag(false); + mWidget->EndDrag(false); DragLeaveEvent->accept(); } @@ -338,13 +333,12 @@ void lcQGLWidget::dragMoveEvent(QDragMoveEvent* DragMoveEvent) if (MimeData->hasFormat("application/vnd.leocad-part") || MimeData->hasFormat("application/vnd.leocad-color")) { - float scale = deviceScale(); + float DeviceScale = GetDeviceScale(); - widget->mInputState.x = DragMoveEvent->pos().x() * scale; - widget->mInputState.y = widget->mHeight - DragMoveEvent->pos().y() * scale - 1; - widget->mInputState.Modifiers = DragMoveEvent->keyboardModifiers(); + mWidget->SetMousePosition(DragMoveEvent->pos().x() * DeviceScale, mWidget->mHeight - DragMoveEvent->pos().y() * DeviceScale - 1); + mWidget->SetMouseModifiers(DragMoveEvent->keyboardModifiers()); - widget->OnMouseMove(); + mWidget->OnMouseMove(); DragMoveEvent->accept(); return; @@ -359,7 +353,7 @@ void lcQGLWidget::dropEvent(QDropEvent* DropEvent) if (MimeData->hasFormat("application/vnd.leocad-part") || MimeData->hasFormat("application/vnd.leocad-color")) { - widget->EndDrag(true); + mWidget->EndDrag(true); setFocus(Qt::MouseFocusReason); DropEvent->accept(); diff --git a/qt/lc_qglwidget.h b/qt/lc_qglwidget.h index 4e8d8c71..343dcfa9 100644 --- a/qt/lc_qglwidget.h +++ b/qt/lc_qglwidget.h @@ -11,9 +11,9 @@ public: QSize sizeHint() const override; - lcGLWidget* widget; + lcGLWidget* mWidget; - float deviceScale() + float GetDeviceScale() const { #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) return windowHandle()->devicePixelRatio();