From 718b31a2bde79d7d14cc8560ead01f34914cbce4 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 7 Apr 2018 11:45:00 -0700 Subject: [PATCH] Fixed selection tinting when editing submodels. --- common/lc_mesh.h | 12 ++++---- common/lc_model.cpp | 8 +++-- common/lc_model.h | 3 +- common/lc_partselectionwidget.cpp | 2 +- common/lc_scene.cpp | 23 ++++++++------ common/lc_scene.h | 23 ++++++++++++++ common/minifig.cpp | 2 +- common/piece.cpp | 51 ++++++++++++++++++------------- common/piece.h | 5 +-- common/pieceinf.cpp | 10 +++--- common/pieceinf.h | 2 +- common/project.cpp | 4 +-- common/view.cpp | 5 +-- 13 files changed, 93 insertions(+), 57 deletions(-) diff --git a/common/lc_mesh.h b/common/lc_mesh.h index 3b313677..ba0d5985 100644 --- a/common/lc_mesh.h +++ b/common/lc_mesh.h @@ -96,13 +96,13 @@ public: int mIndexType; }; -enum lcRenderMeshState +enum class lcRenderMeshState : int { - LC_RENDERMESH_NONE, - LC_RENDERMESH_SELECTED, - LC_RENDERMESH_FOCUSED, - LC_RENDERMESH_DISABLED, - LC_RENDERMESH_HIGHLIGHT + NORMAL, + SELECTED, + FOCUSED, + DISABLED, + HIGHLIGHT }; struct lcRenderMesh diff --git a/common/lc_model.cpp b/common/lc_model.cpp index bb9bcd0b..81f328b1 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -1254,12 +1254,14 @@ void lcModel::DuplicateSelectedPieces() void lcModel::GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const { Scene.Begin(ViewCamera->mWorldView); + Scene.SetActiveSubmodelInstance(ActiveSubmodelInstance); + Scene.SetDrawInterface(DrawInterface); mPieceInfo->AddRenderMesh(Scene); for (lcPiece* Piece : mPieces) if (Piece->IsVisible(mCurrentStep)) - Piece->AddRenderMeshes(Scene, DrawInterface, Highlight && Piece->GetStepShow() == mCurrentStep, ActiveSubmodelInstance); + Piece->AddMainModelRenderMeshes(Scene, Highlight && Piece->GetStepShow() == mCurrentStep); if (DrawInterface && !ActiveSubmodelInstance) { @@ -1283,11 +1285,11 @@ void lcModel::GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface, Scene.End(); } -void lcModel::SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected, bool Disabled, lcPiece* ActiveSubmodelInstance) const +void lcModel::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const { for (lcPiece* Piece : mPieces) if (Piece->GetStepHide() == LC_STEP_MAX) - Piece->SubModelAddRenderMeshes(Scene, WorldMatrix, DefaultColorIndex, Focused, Selected, Disabled, ActiveSubmodelInstance); + Piece->AddSubModelRenderMeshes(Scene, WorldMatrix, DefaultColorIndex, RenderMeshState, ParentActive); } void lcModel::DrawBackground(lcGLWidget* Widget) diff --git a/common/lc_model.h b/common/lc_model.h index 405cd970..cefa7f0f 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -19,6 +19,7 @@ #define LC_SEL_CAN_REMOVE_CONTROL_POINT 0x1000 // Can remove control points from focused piece class lcGLWidget; +enum class lcRenderMeshState : int; enum class lcSelectionMode { @@ -233,7 +234,7 @@ public: void DuplicateSelectedPieces(); void GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const; - void SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected, bool Disabled, lcPiece* ActiveSubmodelInstance) const; + void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const; void DrawBackground(lcGLWidget* Widget); void SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Zoom, bool Highlight, int Width, int Height, lcStep Start, lcStep End); diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index 7ea7ab8b..e8619a22 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -370,7 +370,7 @@ void lcPartSelectionListModel::DrawPreview(int InfoIndex) lcScene Scene; Scene.Begin(ViewMatrix); - Info->AddRenderMeshes(Scene, lcMatrix44Identity(), mColorIndex, false, false, false, false, nullptr); + Info->AddRenderMeshes(Scene, lcMatrix44Identity(), mColorIndex, lcRenderMeshState::NORMAL, true); Scene.End(); diff --git a/common/lc_scene.cpp b/common/lc_scene.cpp index 98fb6e01..691f2bb6 100644 --- a/common/lc_scene.cpp +++ b/common/lc_scene.cpp @@ -10,11 +10,14 @@ lcScene::lcScene() : mRenderMeshes(0, 1024), mOpaqueMeshes(0, 1024), mTranslucentMeshes(0, 1024), mInterfaceObjects(0, 1024) { + mActiveSubmodelInstance = nullptr; } void lcScene::Begin(const lcMatrix44& ViewMatrix) { mViewMatrix = ViewMatrix; + mActiveSubmodelInstance = nullptr; + mDrawInterface = false; mRenderMeshes.RemoveAll(); mOpaqueMeshes.RemoveAll(); mTranslucentMeshes.RemoveAll(); @@ -94,20 +97,20 @@ void lcScene::DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool Enab switch (RenderMesh.State) { - case LC_RENDERMESH_NONE: - case LC_RENDERMESH_HIGHLIGHT: + case lcRenderMeshState::NORMAL: + case lcRenderMeshState::HIGHLIGHT: Context->SetColorIndex(ColorIndex); break; - case LC_RENDERMESH_SELECTED: + case lcRenderMeshState::SELECTED: Context->SetColorIndexTinted(ColorIndex, LC_COLOR_SELECTED, 0.5f); break; - case LC_RENDERMESH_FOCUSED: + case lcRenderMeshState::FOCUSED: Context->SetColorIndexTinted(ColorIndex, LC_COLOR_FOCUSED, 0.5f); break; - case LC_RENDERMESH_DISABLED: + case lcRenderMeshState::DISABLED: Context->SetColorIndexTinted(ColorIndex, LC_COLOR_DISABLED, 0.25f); break; } @@ -116,26 +119,26 @@ void lcScene::DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool Enab { switch (RenderMesh.State) { - case LC_RENDERMESH_NONE: + case lcRenderMeshState::NORMAL: if (ColorIndex == gEdgeColor) Context->SetEdgeColorIndex(RenderMesh.ColorIndex); else Context->SetColorIndex(ColorIndex); break; - case LC_RENDERMESH_SELECTED: + case lcRenderMeshState::SELECTED: Context->SetInterfaceColor(LC_COLOR_SELECTED); break; - case LC_RENDERMESH_FOCUSED: + case lcRenderMeshState::FOCUSED: Context->SetInterfaceColor(LC_COLOR_FOCUSED); break; - case LC_RENDERMESH_HIGHLIGHT: + case lcRenderMeshState::HIGHLIGHT: Context->SetInterfaceColor(LC_COLOR_HIGHLIGHT); break; - case LC_RENDERMESH_DISABLED: + case lcRenderMeshState::DISABLED: Context->SetInterfaceColor(LC_COLOR_DISABLED); break; } diff --git a/common/lc_scene.h b/common/lc_scene.h index 7d264155..268cbff3 100644 --- a/common/lc_scene.h +++ b/common/lc_scene.h @@ -8,6 +8,26 @@ class lcScene public: lcScene(); + void SetActiveSubmodelInstance(lcPiece* ActiveSubmodelInstance) + { + mActiveSubmodelInstance = ActiveSubmodelInstance; + } + + lcPiece* GetActiveSubmodelInstance() const + { + return mActiveSubmodelInstance; + } + + void SetDrawInterface(bool DrawInterface) + { + mDrawInterface = DrawInterface; + } + + bool GetDrawInterface() const + { + return mDrawInterface; + } + void Begin(const lcMatrix44& ViewMatrix); void End(); void AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State, int Flags); @@ -24,6 +44,9 @@ protected: void DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool EnableNormals, bool DrawTranslucent, bool DrawTextured) const; lcMatrix44 mViewMatrix; + lcPiece* mActiveSubmodelInstance; + bool mDrawInterface; + lcArray mRenderMeshes; lcArray mOpaqueMeshes; lcArray mTranslucentMeshes; diff --git a/common/minifig.cpp b/common/minifig.cpp index fc2c8ef5..b617fda7 100644 --- a/common/minifig.cpp +++ b/common/minifig.cpp @@ -350,7 +350,7 @@ void MinifigWizard::OnDraw() for (int PieceIdx = 0; PieceIdx < LC_MFW_NUMITEMS; PieceIdx++) if (mMinifig.Parts[PieceIdx]) - mMinifig.Parts[PieceIdx]->AddRenderMeshes(Scene, mMinifig.Matrices[PieceIdx], mMinifig.Colors[PieceIdx], false, false, false, false, nullptr); + mMinifig.Parts[PieceIdx]->AddRenderMeshes(Scene, mMinifig.Matrices[PieceIdx], mMinifig.Colors[PieceIdx], lcRenderMeshState::NORMAL, true); Scene.End(); diff --git a/common/piece.cpp b/common/piece.cpp index fd82c2b9..755119eb 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -646,46 +646,55 @@ void lcPiece::RemoveKeyFrames() ChangeKey(mRotationKeys, lcMatrix33(mModelWorld), 1, true); } -void lcPiece::AddRenderMeshes(lcScene& Scene, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const +void lcPiece::AddMainModelRenderMeshes(lcScene& Scene, bool Highlight) const { - bool Focused, Selected, Disabled; + lcRenderMeshState RenderMeshState = lcRenderMeshState::NORMAL; + bool ParentActive = false; - if (DrawInterface) + if (Scene.GetDrawInterface()) { - Focused = IsFocused(); - Selected = IsSelected(); - Disabled = ActiveSubmodelInstance && (ActiveSubmodelInstance != this); - } - else - { - Focused = false; - Selected = false; - Disabled = false; - } + lcPiece* ActiveSubmodelInstance = Scene.GetActiveSubmodelInstance(); - if (ActiveSubmodelInstance == this) - ActiveSubmodelInstance = nullptr; + if (!ActiveSubmodelInstance) + RenderMeshState = IsFocused() ? lcRenderMeshState::FOCUSED : (IsSelected() ? lcRenderMeshState::SELECTED : lcRenderMeshState::NORMAL); + else if (ActiveSubmodelInstance == this) + ParentActive = true; + else + RenderMeshState = lcRenderMeshState::DISABLED; + } + else if (Highlight) + RenderMeshState = lcRenderMeshState::HIGHLIGHT; if (!mMesh) - mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, Focused, Selected, Disabled, Highlight, ActiveSubmodelInstance); + mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, RenderMeshState, ParentActive); else - Scene.AddMesh(mMesh, mModelWorld, mColorIndex, Disabled ? LC_RENDERMESH_DISABLED : (Focused ? LC_RENDERMESH_FOCUSED : (Selected ? LC_RENDERMESH_SELECTED : LC_RENDERMESH_NONE)), mPieceInfo->mFlags); + Scene.AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState, mPieceInfo->mFlags); - if (Selected) + if (RenderMeshState == lcRenderMeshState::FOCUSED || RenderMeshState == lcRenderMeshState::SELECTED) Scene.AddInterfaceObject(this); } -void lcPiece::SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected, bool Disabled, lcPiece* ActiveSubmodelInstance) const +void lcPiece::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const { int ColorIndex = mColorIndex; if (ColorIndex == gDefaultColor) ColorIndex = DefaultColorIndex; + lcPiece* ActiveSubmodelInstance = Scene.GetActiveSubmodelInstance(); + + if (ActiveSubmodelInstance == this) + RenderMeshState = lcRenderMeshState::NORMAL; + else if (ParentActive) + RenderMeshState = IsFocused() ? lcRenderMeshState::FOCUSED : (IsSelected() ? lcRenderMeshState::SELECTED : lcRenderMeshState::NORMAL); + if (!mMesh) - mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, Focused, Selected, Disabled, false, ActiveSubmodelInstance); + mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, ActiveSubmodelInstance == this); else - Scene.AddMesh(mMesh, lcMul(mModelWorld, WorldMatrix), ColorIndex, Disabled ? LC_RENDERMESH_DISABLED : (Focused ? LC_RENDERMESH_FOCUSED : (Selected ? LC_RENDERMESH_SELECTED : LC_RENDERMESH_NONE)), mPieceInfo->mFlags); + Scene.AddMesh(mMesh, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, mPieceInfo->mFlags); + + if (ParentActive && (RenderMeshState == lcRenderMeshState::FOCUSED || RenderMeshState == lcRenderMeshState::SELECTED)) + Scene.AddInterfaceObject(this); } void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance) diff --git a/common/piece.h b/common/piece.h index 5eddadfd..8aa2b465 100644 --- a/common/piece.h +++ b/common/piece.h @@ -1,6 +1,7 @@ #pragma once class PieceInfo; +enum class lcRenderMeshState : int; #include "object.h" #include "lc_colors.h" @@ -346,8 +347,8 @@ public: virtual void DrawInterface(lcContext* Context) const override; virtual void RemoveKeyFrames() override; - void AddRenderMeshes(lcScene& Scene, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const; - void SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected, bool Disabled, lcPiece* ActiveSubmodelInstance) const; + void AddMainModelRenderMeshes(lcScene& Scene, bool Highlight) const; + void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const; void InsertTime(lcStep Start, lcStep Time); void RemoveTime(lcStep Start, lcStep Time); diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp index d28e1f3d..72a1b489 100644 --- a/common/pieceinf.cpp +++ b/common/pieceinf.cpp @@ -303,21 +303,21 @@ void PieceInfo::ZoomExtents(float FoV, float AspectRatio, lcMatrix44& Projection void PieceInfo::AddRenderMesh(lcScene& Scene) { if (mMesh) - Scene.AddMesh(mMesh, lcMatrix44Identity(), gDefaultColor, LC_RENDERMESH_NONE, mFlags); + Scene.AddMesh(mMesh, lcMatrix44Identity(), gDefaultColor, lcRenderMeshState::NORMAL, mFlags); } -void PieceInfo::AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, bool Focused, bool Selected, bool Disabled, bool Highlight, lcPiece* ActiveSubmodelInstance) const +void PieceInfo::AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const { if ((mMesh) || (mFlags & LC_PIECE_PLACEHOLDER)) - Scene.AddMesh((mFlags & LC_PIECE_PLACEHOLDER) ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, Disabled ? LC_RENDERMESH_DISABLED : (Focused ? LC_RENDERMESH_FOCUSED : (Selected ? LC_RENDERMESH_SELECTED : (Highlight ? LC_RENDERMESH_HIGHLIGHT : LC_RENDERMESH_NONE))), mFlags); + Scene.AddMesh((mFlags & LC_PIECE_PLACEHOLDER) ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, RenderMeshState, mFlags); if (mFlags & LC_PIECE_MODEL) - mModel->SubModelAddRenderMeshes(Scene, WorldMatrix, ColorIndex, Focused, Selected, Disabled, ActiveSubmodelInstance); + mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive); else if (mFlags & LC_PIECE_PROJECT) { lcModel* Model = mProject->GetMainModel(); if (Model) - Model->SubModelAddRenderMeshes(Scene, WorldMatrix, ColorIndex, Focused, Selected, Disabled, ActiveSubmodelInstance); + Model->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive); } } diff --git a/common/pieceinf.h b/common/pieceinf.h index 14c38b45..41158931 100644 --- a/common/pieceinf.h +++ b/common/pieceinf.h @@ -136,7 +136,7 @@ public: void ZoomExtents(float FoV, float AspectRatio, lcMatrix44& ProjectionMatrix, lcMatrix44& ViewMatrix) const; void AddRenderMesh(lcScene& Scene); - void AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, bool Focused, bool Selected, bool Disabled, bool Highlight, lcPiece* ActiveSubmodelInstance) const; + void AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const; void CreatePlaceholder(const char* Name); diff --git a/common/project.cpp b/common/project.cpp index 88c9229c..384e6f08 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -1554,7 +1554,7 @@ QImage Project::CreatePartsListImage(lcModel* Model, lcStep Step) lcScene Scene; Scene.Begin(ViewMatrix); - Image.Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Image.ColorIndex, false, false, false, false, nullptr); + Image.Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Image.ColorIndex, lcRenderMeshState::NORMAL, true); Scene.End(); @@ -1942,7 +1942,7 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options) lcScene Scene; Scene.Begin(ViewMatrix); - Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Options.PartImagesColor, false, false, false, false, nullptr); + Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Options.PartImagesColor, lcRenderMeshState::NORMAL, true); Scene.End(); diff --git a/common/view.cpp b/common/view.cpp index 489b763f..018daa71 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -54,7 +54,6 @@ void View::SetSelectedSubmodelActive() { lcModel* Model = mActiveSubmodelInstance->mPieceInfo->GetModel(); Model->SetActive(false); - Model->ClearSelection(true); mActiveSubmodelInstance = nullptr; } @@ -67,13 +66,11 @@ void View::SetSelectedSubmodelActive() if (Piece->mPieceInfo->IsModel()) { - ActiveModel->ClearSelection(false); mActiveSubmodelMatrix = lcMatrix44Identity(); mModel->GetPieceWorldMatrix(Piece, mActiveSubmodelMatrix); mActiveSubmodelInstance = Piece; lcModel* Model = mActiveSubmodelInstance->mPieceInfo->GetModel(); Model->SetActive(true); - Model->ClearSelection(true); } } } @@ -722,7 +719,7 @@ void View::OnDraw() PieceInfo* Info = gMainWindow->GetCurrentPieceInfo(); if (Info) - Info->AddRenderMeshes(mScene, GetPieceInsertPosition(false, gMainWindow->GetCurrentPieceInfo()), gMainWindow->mColorIndex, true, true, false, false, nullptr); + Info->AddRenderMeshes(mScene, GetPieceInsertPosition(false, gMainWindow->GetCurrentPieceInfo()), gMainWindow->mColorIndex, lcRenderMeshState::FOCUSED, true); } int TotalTileRows = 1;