Derive preview from view.

This commit is contained in:
Leonardo Zide 2020-12-24 11:32:56 -08:00
parent 72bb41e8aa
commit e27b235936
9 changed files with 54 additions and 362 deletions

View file

@ -792,7 +792,7 @@ void lcMainWindow::PreviewPiece(const QString& PartId, int ColorCode)
} }
else else
{ {
lcPreviewWidget* Preview = new lcPreviewWidget(); lcPreview* Preview = new lcPreview();
lcViewWidget* ViewWidget = new lcViewWidget(nullptr, Preview); lcViewWidget* ViewWidget = new lcViewWidget(nullptr, Preview);
if (Preview && ViewWidget) if (Preview && ViewWidget)

View file

@ -8,6 +8,7 @@
#include "lc_mainwindow.h" #include "lc_mainwindow.h"
#include "lc_profile.h" #include "lc_profile.h"
#include "lc_library.h" #include "lc_library.h"
#include "lc_scene.h"
#include "lc_texture.h" #include "lc_texture.h"
#include "lc_synth.h" #include "lc_synth.h"
#include "lc_file.h" #include "lc_file.h"

View file

@ -8,6 +8,7 @@
#include "lc_model.h" #include "lc_model.h"
#include "project.h" #include "project.h"
#include "pieceinf.h" #include "pieceinf.h"
#include "lc_scene.h"
#include "view.h" #include "view.h"
#include "lc_glextensions.h" #include "lc_glextensions.h"
#include "lc_viewwidget.h" #include "lc_viewwidget.h"

View file

@ -4,15 +4,14 @@
#include "piece.h" #include "piece.h"
#include "project.h" #include "project.h"
#include "lc_model.h" #include "lc_model.h"
#include "camera.h"
#include "lc_library.h" #include "lc_library.h"
#include "lc_viewsphere.h"
#include "lc_viewwidget.h" #include "lc_viewwidget.h"
#include "view.h"
lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow* Parent) lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow* Parent)
: QMainWindow(Parent) : QMainWindow(Parent)
{ {
mPreview = new lcPreviewWidget(); mPreview = new lcPreview();
mViewWidget = new lcViewWidget(nullptr, mPreview); mViewWidget = new lcViewWidget(nullptr, mPreview);
setCentralWidget(mViewWidget); setCentralWidget(mViewWidget);
setMinimumSize(200, 200); setMinimumSize(200, 200);
@ -24,7 +23,7 @@ lcPreviewDockWidget::lcPreviewDockWidget(QMainWindow* Parent)
connect(mLockAction, SIGNAL(triggered()), this, SLOT(SetPreviewLock())); connect(mLockAction, SIGNAL(triggered()), this, SLOT(SetPreviewLock()));
SetPreviewLock(); SetPreviewLock();
mLabel = new QLabel(QString()); mLabel = new QLabel();
mToolBar = addToolBar(tr("Toolbar")); mToolBar = addToolBar(tr("Toolbar"));
mToolBar->setObjectName("Toolbar"); mToolBar->setObjectName("Toolbar");
@ -58,54 +57,46 @@ void lcPreviewDockWidget::UpdatePreview()
void lcPreviewDockWidget::ClearPreview() void lcPreviewDockWidget::ClearPreview()
{ {
if (mPreview->GetActiveModel()->GetPieces().GetSize()) if (mPreview->GetModel()->GetPieces().GetSize())
mPreview->ClearPreview(); mPreview->ClearPreview();
mLabel->setText(QString()); mLabel->setText(QString());
} }
void lcPreviewDockWidget::SetPreviewLock() void lcPreviewDockWidget::SetPreviewLock()
{ {
bool Locked = mLockAction->isChecked(); bool Locked = mLockAction->isChecked();
if (Locked && mPreview->GetActiveModel()->GetPieces().IsEmpty())
if (Locked && mPreview->GetModel()->GetPieces().IsEmpty())
{ {
mLockAction->setChecked(false); mLockAction->setChecked(false);
return; return;
} }
QIcon LockIcon(Locked ? ":/resources/action_preview_locked.png" : ":/resources/action_preview_unlocked.png"); QIcon LockIcon(Locked ? ":/resources/action_preview_locked.png" : ":/resources/action_preview_unlocked.png");
QString State(Locked ? tr("Unlock") : tr("Lock")); QString State(Locked ? tr("Unlock") : tr("Lock"));
QString StatusTip(tr("%1 the preview display to %2 updates").arg(State).arg(Locked ? "enable" : "disable")); QString StatusTip(tr("%1 the preview display to %2 updates").arg(State).arg(Locked ? "enable" : "disable"));
mLockAction->setToolTip(tr("%1 Preview").arg(State)); mLockAction->setToolTip(tr("%1 Preview").arg(State));
mLockAction->setIcon(LockIcon); mLockAction->setIcon(LockIcon);
mLockAction->setStatusTip(StatusTip); mLockAction->setStatusTip(StatusTip);
} }
lcPreviewWidget::lcPreviewWidget() lcPreview::lcPreview()
: lcGLWidget(lcViewType::Preview, nullptr), mLoader(new Project(true)) : View(lcViewType::Preview, nullptr), mLoader(new Project(true))
{ {
mViewSphere = std::unique_ptr<lcViewSphere>(new lcViewSphere(this));
mLoader->SetActiveModel(0); mLoader->SetActiveModel(0);
mModel = mLoader->GetActiveModel(); mModel = mLoader->GetActiveModel();
SetDefaultCamera();
} }
lcPreviewWidget::~lcPreviewWidget() bool lcPreview::SetCurrentPiece(const QString& PartType, int ColorCode)
{
if (mCamera && mCamera->IsSimple())
delete mCamera;
delete mLoader;
}
bool lcPreviewWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
{ {
lcPiecesLibrary* Library = lcGetPiecesLibrary(); lcPiecesLibrary* Library = lcGetPiecesLibrary();
PieceInfo* Info = Library->FindPiece(PartType.toLatin1().constData(), nullptr, false, false); PieceInfo* Info = Library->FindPiece(PartType.toLatin1().constData(), nullptr, false, false);
if (Info) if (Info)
{ {
lcModel* ActiveModel = GetActiveModel(); for (lcPiece* ModelPiece : mModel->GetPieces())
for (lcPiece* ModelPiece : ActiveModel->GetPieces())
{ {
if (Info == ModelPiece->mPieceInfo) if (Info == ModelPiece->mPieceInfo)
{ {
@ -118,8 +109,8 @@ bool lcPreviewWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
mIsModel = Info->IsModel(); mIsModel = Info->IsModel();
mDescription = Info->m_strDescription; mDescription = Info->m_strDescription;
ActiveModel->SelectAllPieces(); mModel->SelectAllPieces();
ActiveModel->DeleteSelectedObjects(); mModel->DeleteSelectedObjects();
Library->LoadPieceInfo(Info, false, true); Library->LoadPieceInfo(Info, false, true);
Library->WaitForLoadQueue(); Library->WaitForLoadQueue();
@ -131,7 +122,7 @@ bool lcPreviewWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
Piece->Initialize(lcMatrix44Identity(), CurrentStep); Piece->Initialize(lcMatrix44Identity(), CurrentStep);
Piece->SetColorCode(ColorCode); Piece->SetColorCode(ColorCode);
ActiveModel->SetPreviewPiece(Piece); mModel->SetPreviewPiece(Piece);
} }
else else
{ {
@ -158,22 +149,21 @@ bool lcPreviewWidget::SetCurrentPiece(const QString& PartType, int ColorCode)
return true; return true;
} }
void lcPreviewWidget::ClearPreview() void lcPreview::ClearPreview()
{ {
delete mLoader; mLoader = std::unique_ptr<Project>(new Project(true/*IsPreview*/));
mLoader = new Project(true/*IsPreview*/);
mLoader->SetActiveModel(0); mLoader->SetActiveModel(0);
mModel = mLoader->GetActiveModel(); mModel = mLoader->GetActiveModel();
lcGetPiecesLibrary()->UnloadUnusedParts(); lcGetPiecesLibrary()->UnloadUnusedParts();
Redraw(); Redraw();
} }
void lcPreviewWidget::UpdatePreview() void lcPreview::UpdatePreview()
{ {
QString PartType; QString PartType;
int ColorCode = -1; int ColorCode = -1;
lcModel* ActiveModel = GetActiveModel();
for (lcPiece* ModelPiece : ActiveModel->GetPieces()) for (lcPiece* ModelPiece : mModel->GetPieces())
{ {
if (ModelPiece->mPieceInfo) if (ModelPiece->mPieceInfo)
{ {
@ -188,275 +178,3 @@ void lcPreviewWidget::UpdatePreview()
if (!PartType.isEmpty() && ColorCode > -1) if (!PartType.isEmpty() && ColorCode > -1)
SetCurrentPiece(PartType, ColorCode); SetCurrentPiece(PartType, ColorCode);
} }
void lcPreviewWidget::StartOrbitTracking() // called by viewSphere
{
mTrackTool = lcTrackTool::OrbitXY;
UpdateCursor();
OnButtonDown(lcTrackButton::Left);
}
void lcPreviewWidget::StopTracking(bool Accept)
{
if (mTrackButton == lcTrackButton::None)
return;
lcTool Tool = GetCurrentTool();
lcModel* ActiveModel = GetActiveModel();
switch (Tool)
{
case lcTool::Select:
break;
case lcTool::Pan:
case lcTool::RotateView:
ActiveModel->EndMouseTool(Tool, Accept);
break;
case lcTool::Count:
default:
break;
}
mTrackButton = lcTrackButton::None;
mTrackTool = lcTrackTool::None;
UpdateCursor();
}
void lcPreviewWidget::OnButtonDown(lcTrackButton TrackButton)
{
switch (mTrackTool)
{
case lcTrackTool::None:
break;
case lcTrackTool::Pan:
StartTracking(TrackButton);
break;
case lcTrackTool::OrbitXY:
StartTracking(TrackButton);
break;
default:
break;
}
}
void lcPreviewWidget::OnDraw()
{
if (!mModel)
return;
lcPreferences& Preferences = lcGetPreferences();
const bool DrawInterface = mWidget != nullptr;
mScene->SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr);
mScene->SetLODDistance(Preferences.mMeshLODDistance);
mScene->Begin(mCamera->mWorldView);
mScene->SetDrawInterface(DrawInterface);
mModel->GetScene(mScene.get(), mCamera, false /*HighlightNewParts*/, false/*mFadeSteps*/);
mScene->End();
mContext->SetDefaultState();
mContext->SetViewport(0, 0, mWidth, mHeight);
DrawBackground();
mContext->SetProjectionMatrix(GetProjectionMatrix());
mContext->SetLineWidth(Preferences.mLineWidth);
mScene->Draw(mContext);
if (DrawInterface)
{
mContext->SetLineWidth(1.0f);
if (Preferences.mDrawPreviewAxis)
DrawAxes();
if (Preferences.mDrawPreviewViewSphere)
mViewSphere->Draw();
DrawViewport();
}
mContext->ClearResources();
}
void lcPreviewWidget::OnLeftButtonDown()
{
if (mTrackButton != lcTrackButton::None)
{
StopTracking(false);
return;
}
if (mViewSphere->OnLeftButtonDown())
return;
lcTrackTool OverrideTool = lcTrackTool::OrbitXY;
if (OverrideTool != lcTrackTool::None)
{
mTrackTool = OverrideTool;
UpdateCursor();
}
OnButtonDown(lcTrackButton::Left);
}
void lcPreviewWidget::OnLeftButtonUp()
{
StopTracking(mTrackButton == lcTrackButton::Left);
if (mViewSphere->OnLeftButtonUp())
{
ZoomExtents();
return;
}
}
void lcPreviewWidget::OnMiddleButtonDown()
{
if (mTrackButton != lcTrackButton::None)
{
StopTracking(false);
return;
}
#if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
lcTrackTool OverrideTool = lcTrackTool::None;
if (OverrideTool != lcTrackTool::None)
{
mTrackTool = OverrideTool;
UpdateCursor();
}
#endif
OnButtonDown(lcTrackButton::Middle);
}
void lcPreviewWidget::OnMiddleButtonUp()
{
StopTracking(mTrackButton == lcTrackButton::Middle);
}
void lcPreviewWidget::OnLeftButtonDoubleClick()
{
ZoomExtents();
Redraw();
}
void lcPreviewWidget::OnRightButtonDown()
{
if (mTrackButton != lcTrackButton::None)
{
StopTracking(false);
return;
}
lcTrackTool OverrideTool = lcTrackTool::Pan;
if (OverrideTool != lcTrackTool::None)
{
mTrackTool = OverrideTool;
UpdateCursor();
}
OnButtonDown(lcTrackButton::Middle);
}
void lcPreviewWidget::OnRightButtonUp()
{
if (mTrackButton != lcTrackButton::None)
StopTracking(mTrackButton == lcTrackButton::Right);
}
void lcPreviewWidget::OnMouseMove()
{
lcModel* ActiveModel = GetActiveModel();
if (!ActiveModel)
return;
if (mTrackButton == lcTrackButton::None)
{
if (mViewSphere->OnMouseMove())
{
lcTrackTool NewTrackTool = mViewSphere->IsDragging() ? lcTrackTool::OrbitXY : lcTrackTool::None;
if (NewTrackTool != mTrackTool)
{
mTrackTool = NewTrackTool;
UpdateCursor();
}
return;
}
return;
}
const float MouseSensitivity = 0.5f / (21.0f - lcGetPreferences().mMouseSensitivity);
switch (mTrackTool)
{
case lcTrackTool::None:
break;
case lcTrackTool::Pan:
{
lcVector3 Points[4] =
{
lcVector3((float)mMouseX, (float)mMouseY, 0.0f),
lcVector3((float)mMouseX, (float)mMouseY, 1.0f),
lcVector3(mMouseDownX, mMouseDownY, 0.0f),
lcVector3(mMouseDownX, mMouseDownY, 1.0f)
};
UnprojectPoints(Points, 4);
const lcVector3& CurrentStart = Points[0];
const lcVector3& CurrentEnd = Points[1];
const lcVector3& MouseDownStart = Points[2];
const lcVector3& MouseDownEnd = Points[3];
lcVector3 Center = ActiveModel->GetSelectionOrModelCenter();
lcVector3 PlaneNormal(mCamera->mPosition - mCamera->mTargetPosition);
lcVector4 Plane(PlaneNormal, -lcDot(PlaneNormal, Center));
lcVector3 Intersection, MoveStart;
if (!lcLineSegmentPlaneIntersection(&Intersection, CurrentStart, CurrentEnd, Plane) || !lcLineSegmentPlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
{
Center = MouseDownStart + lcNormalize(MouseDownEnd - MouseDownStart) * 10.0f;
Plane = lcVector4(PlaneNormal, -lcDot(PlaneNormal, Center));
if (!lcLineSegmentPlaneIntersection(&Intersection, CurrentStart, CurrentEnd, Plane) || !lcLineSegmentPlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
break;
}
ActiveModel->UpdatePanTool(mCamera, MoveStart - Intersection);
Redraw();
}
break;
case lcTrackTool::OrbitXY:
ActiveModel->UpdateOrbitTool(mCamera, 0.1f * MouseSensitivity * (mMouseX - mMouseDownX), 0.1f * MouseSensitivity * (mMouseY - mMouseDownY));
Redraw();
break;
default:
break;
}
}

View file

@ -1,10 +1,8 @@
#pragma once #pragma once
#include "lc_glwidget.h" #include "view.h"
#include "lc_scene.h"
#include "lc_commands.h"
class lcPreviewWidget; class lcPreview;
class lcPreviewDockWidget : public QMainWindow class lcPreviewDockWidget : public QMainWindow
{ {
@ -12,6 +10,7 @@ class lcPreviewDockWidget : public QMainWindow
public: public:
explicit lcPreviewDockWidget(QMainWindow* Parent = nullptr); explicit lcPreviewDockWidget(QMainWindow* Parent = nullptr);
bool SetCurrentPiece(const QString& PartType, int ColorCode); bool SetCurrentPiece(const QString& PartType, int ColorCode);
void ClearPreview(); void ClearPreview();
void UpdatePreview(); void UpdatePreview();
@ -23,15 +22,14 @@ protected:
QAction* mLockAction; QAction* mLockAction;
QToolBar* mToolBar; QToolBar* mToolBar;
QLabel* mLabel; QLabel* mLabel;
lcPreviewWidget* mPreview; lcPreview* mPreview;
lcViewWidget* mViewWidget; lcViewWidget* mViewWidget;
}; };
class lcPreviewWidget : public lcGLWidget class lcPreview : public View
{ {
public: public:
lcPreviewWidget(); lcPreview();
~lcPreviewWidget();
QString GetDescription() const QString GetDescription() const
{ {
@ -47,24 +45,9 @@ public:
void UpdatePreview(); void UpdatePreview();
bool SetCurrentPiece(const QString& PartType, int ColorCode); bool SetCurrentPiece(const QString& PartType, int ColorCode);
void StartOrbitTracking();
void OnDraw() override;
void OnLeftButtonDown() override;
void OnLeftButtonUp() override;
void OnLeftButtonDoubleClick() override;
void OnMiddleButtonDown() override;
void OnMiddleButtonUp() override;
void OnRightButtonDown() override;
void OnRightButtonUp() override;
void OnMouseMove() override;
protected: protected:
void StopTracking(bool Accept); std::unique_ptr<Project> mLoader;
void OnButtonDown(lcTrackButton TrackButton);
Project* mLoader;
QString mDescription; QString mDescription;
bool mIsModel; bool mIsModel = false;
}; };

View file

@ -1,7 +1,6 @@
#include "lc_global.h" #include "lc_global.h"
#include "lc_viewsphere.h" #include "lc_viewsphere.h"
#include "view.h" #include "view.h"
#include "lc_previewwidget.h"
#include "camera.h" #include "camera.h"
#include "lc_context.h" #include "lc_context.h"
#include "lc_stringcache.h" #include "lc_stringcache.h"
@ -17,13 +16,7 @@ const float lcViewSphere::mHighlightRadius = 0.35f;
const int lcViewSphere::mSubdivisions = 7; const int lcViewSphere::mSubdivisions = 7;
lcViewSphere::lcViewSphere(View* View) lcViewSphere::lcViewSphere(View* View)
: mWidget(View), mPreview(nullptr), mView(View), mIsPreview(false) : mView(View)
{
UpdateSettings();
}
lcViewSphere::lcViewSphere(lcPreviewWidget* Preview)
: mWidget(Preview), mPreview(Preview), mView(nullptr), mIsPreview(true)
{ {
UpdateSettings(); UpdateSettings();
} }
@ -32,7 +25,7 @@ void lcViewSphere::UpdateSettings()
{ {
const lcPreferences& Preferences = lcGetPreferences(); const lcPreferences& Preferences = lcGetPreferences();
switch (mWidget->GetViewType()) switch (mView->GetViewType())
{ {
case lcViewType::View: case lcViewType::View:
mSize = Preferences.mViewSphereSize; mSize = Preferences.mViewSphereSize;
@ -54,7 +47,7 @@ void lcViewSphere::UpdateSettings()
lcMatrix44 lcViewSphere::GetViewMatrix() const lcMatrix44 lcViewSphere::GetViewMatrix() const
{ {
lcMatrix44 ViewMatrix = mWidget->GetCamera()->mWorldView; lcMatrix44 ViewMatrix = mView->GetCamera()->mWorldView;
ViewMatrix.SetTranslation(lcVector3(0, 0, 0)); ViewMatrix.SetTranslation(lcVector3(0, 0, 0));
return ViewMatrix; return ViewMatrix;
} }
@ -188,9 +181,9 @@ void lcViewSphere::Draw()
if (!mSize || !mEnabled) if (!mSize || !mEnabled)
return; return;
lcContext* Context = mWidget->mContext; lcContext* Context = mView->mContext;
const int Width = mWidget->GetWidth(); const int Width = mView->GetWidth();
const int Height = mWidget->GetHeight(); const int Height = mView->GetHeight();
const int ViewportSize = mSize; const int ViewportSize = mSize;
const int Left = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize; const int Left = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize;
const int Bottom = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize; const int Bottom = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize;
@ -259,8 +252,8 @@ bool lcViewSphere::OnLeftButtonDown()
if (!mIntersectionFlags.any()) if (!mIntersectionFlags.any())
return false; return false;
mMouseDownX = mWidget->GetMouseX(); mMouseDownX = mView->GetMouseX();
mMouseDownY = mWidget->GetMouseY(); mMouseDownY = mView->GetMouseY();
mMouseDown = true; mMouseDown = true;
return true; return true;
@ -289,7 +282,7 @@ bool lcViewSphere::OnLeftButtonUp()
Position[AxisIdx] = -1250.0f; Position[AxisIdx] = -1250.0f;
} }
mWidget->SetViewpoint(Position); mView->SetViewpoint(Position);
return true; return true;
} }
@ -302,11 +295,11 @@ bool lcViewSphere::OnMouseMove()
if (IsDragging()) if (IsDragging())
{ {
mIntersectionFlags.reset(); mIntersectionFlags.reset();
mIsPreview ? mPreview->StartOrbitTracking() : mView->StartOrbitTracking(); mView->StartOrbitTracking();
return true; return true;
} }
if (mWidget->IsTracking()) if (mView->IsTracking())
return false; return false;
std::bitset<6> IntersectionFlags = GetIntersectionFlags(mIntersection); std::bitset<6> IntersectionFlags = GetIntersectionFlags(mIntersection);
@ -314,7 +307,7 @@ bool lcViewSphere::OnMouseMove()
if (IntersectionFlags != mIntersectionFlags) if (IntersectionFlags != mIntersectionFlags)
{ {
mIntersectionFlags = IntersectionFlags; mIntersectionFlags = IntersectionFlags;
mWidget->Redraw(); mView->Redraw();
} }
return mIntersectionFlags.any(); return mIntersectionFlags.any();
@ -322,20 +315,20 @@ bool lcViewSphere::OnMouseMove()
bool lcViewSphere::IsDragging() const bool lcViewSphere::IsDragging() const
{ {
int InputStateX = mWidget->GetMouseX(); int InputStateX = mView->GetMouseX();
int InputStateY = mWidget->GetMouseY(); int InputStateY = mView->GetMouseY();
return mMouseDown && (qAbs(mMouseDownX - InputStateX) > 3 || qAbs(mMouseDownY - InputStateY) > 3); return mMouseDown && (qAbs(mMouseDownX - InputStateX) > 3 || qAbs(mMouseDownY - InputStateY) > 3);
} }
std::bitset<6> lcViewSphere::GetIntersectionFlags(lcVector3& Intersection) const std::bitset<6> lcViewSphere::GetIntersectionFlags(lcVector3& Intersection) const
{ {
const int Width = mWidget->GetWidth(); const int Width = mView->GetWidth();
const int Height = mWidget->GetHeight(); const int Height = mView->GetHeight();
const int ViewportSize = mSize; const int ViewportSize = mSize;
const int Left = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize; const int Left = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::TopLeft) ? 0 : Width - ViewportSize;
const int Bottom = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize; const int Bottom = (mLocation == lcViewSphereLocation::BottomLeft || mLocation == lcViewSphereLocation::BottomRight) ? 0 : Height - ViewportSize;
const int x = mWidget->GetMouseX() - Left; const int x = mView->GetMouseX() - Left;
const int y = mWidget->GetMouseY() - Bottom; const int y = mView->GetMouseY() - Bottom;
std::bitset<6> IntersectionFlags; std::bitset<6> IntersectionFlags;
if (x < 0 || x > Width || y < 0 || y > Height) if (x < 0 || x > Width || y < 0 || y > Height)

View file

@ -5,7 +5,6 @@
#include <bitset> #include <bitset>
class View; class View;
class lcPreviewWidget;
enum class lcViewSphereLocation enum class lcViewSphereLocation
{ {
@ -19,7 +18,6 @@ class lcViewSphere
{ {
public: public:
lcViewSphere(View* View); lcViewSphere(View* View);
lcViewSphere(lcPreviewWidget* Preview);
void Draw(); void Draw();
bool OnMouseMove(); bool OnMouseMove();
@ -36,10 +34,7 @@ protected:
lcMatrix44 GetProjectionMatrix() const; lcMatrix44 GetProjectionMatrix() const;
std::bitset<6> GetIntersectionFlags(lcVector3& Intersection) const; std::bitset<6> GetIntersectionFlags(lcVector3& Intersection) const;
lcGLWidget* const mWidget = nullptr;
lcPreviewWidget* const mPreview = nullptr;
View* const mView = nullptr; View* const mView = nullptr;
bool mIsPreview = false;
int mSize = 1; int mSize = 1;
bool mEnabled = false; bool mEnabled = false;

View file

@ -106,7 +106,7 @@ void lcViewWidget::SetView(lcGLWidget* View)
void lcViewWidget::SetPreviewPosition(const QRect& ParentRect) void lcViewWidget::SetPreviewPosition(const QRect& ParentRect)
{ {
lcPreferences& Preferences = lcGetPreferences(); lcPreferences& Preferences = lcGetPreferences();
lcPreviewWidget* Preview = reinterpret_cast<lcPreviewWidget*>(mView); lcPreview* Preview = reinterpret_cast<lcPreview*>(mView);
setWindowTitle(tr("%1 Preview").arg(Preview->IsModel() ? "Submodel" : "Part")); setWindowTitle(tr("%1 Preview").arg(Preview->IsModel() ? "Submodel" : "Part"));

View file

@ -35,7 +35,7 @@ View::~View()
{ {
mContext->DestroyVertexBuffer(mGridBuffer); mContext->DestroyVertexBuffer(mGridBuffer);
if (gMainWindow) if (gMainWindow && mViewType == lcViewType::View)
gMainWindow->RemoveView(this); gMainWindow->RemoveView(this);
if (mCamera && mCamera->IsSimple()) if (mCamera && mCamera->IsSimple())
@ -1572,7 +1572,8 @@ void View::DrawGrid()
void View::OnInitialUpdate() void View::OnInitialUpdate()
{ {
gMainWindow->AddView(this); if (mViewType == lcViewType::View)
gMainWindow->AddView(this);
} }
lcTrackTool View::GetOverrideTrackTool(Qt::MouseButton Button) const lcTrackTool View::GetOverrideTrackTool(Qt::MouseButton Button) const