mirror of
https://github.com/leozide/leocad
synced 2024-12-27 21:58:37 +01:00
Widget merge.
This commit is contained in:
parent
28ccd8f681
commit
b981de80c5
7 changed files with 111 additions and 141 deletions
|
@ -2,12 +2,15 @@
|
|||
#include "lc_glwidget.h"
|
||||
#include "lc_application.h"
|
||||
#include "lc_context.h"
|
||||
#include "piece.h"
|
||||
#include "camera.h"
|
||||
#include "pieceinf.h"
|
||||
#include "texfont.h"
|
||||
#include "lc_model.h"
|
||||
#include "lc_scene.h"
|
||||
|
||||
lcGLWidget::lcGLWidget()
|
||||
: mScene(new lcScene())
|
||||
lcGLWidget::lcGLWidget(lcModel* Model)
|
||||
: mModel(Model), mScene(new lcScene())
|
||||
{
|
||||
mContext = new lcContext();
|
||||
}
|
||||
|
@ -18,6 +21,11 @@ lcGLWidget::~lcGLWidget()
|
|||
delete mContext;
|
||||
}
|
||||
|
||||
lcModel* lcGLWidget::GetActiveModel() const
|
||||
{
|
||||
return !mActiveSubmodelInstance ? mModel : mActiveSubmodelInstance->mPieceInfo->GetModel();
|
||||
}
|
||||
|
||||
void lcGLWidget::SetMousePosition(int MouseX, int MouseY)
|
||||
{
|
||||
mMouseX = MouseX;
|
||||
|
@ -233,6 +241,93 @@ void lcGLWidget::UnprojectPoints(lcVector3* Points, int NumPoints) const
|
|||
lcUnprojectPoints(Points, NumPoints, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
||||
}
|
||||
|
||||
void lcGLWidget::StartTracking(lcTrackButton TrackButton)
|
||||
{
|
||||
mTrackButton = TrackButton;
|
||||
mTrackUpdated = false;
|
||||
mMouseDownX = mMouseX;
|
||||
mMouseDownY = mMouseY;
|
||||
lcTool Tool = GetCurrentTool();
|
||||
lcModel* ActiveModel = GetActiveModel();
|
||||
|
||||
switch (Tool)
|
||||
{
|
||||
case lcTool::Insert:
|
||||
case lcTool::Light:
|
||||
break;
|
||||
|
||||
case lcTool::SpotLight:
|
||||
{
|
||||
lcVector3 Position = GetCameraLightInsertPosition();
|
||||
lcVector3 Target = Position + lcVector3(0.1f, 0.1f, 0.1f);
|
||||
ActiveModel->BeginSpotLightTool(Position, Target);
|
||||
}
|
||||
break;
|
||||
|
||||
case lcTool::Camera:
|
||||
{
|
||||
lcVector3 Position = GetCameraLightInsertPosition();
|
||||
lcVector3 Target = Position + lcVector3(0.1f, 0.1f, 0.1f);
|
||||
ActiveModel->BeginCameraTool(Position, Target);
|
||||
}
|
||||
break;
|
||||
|
||||
case lcTool::Select:
|
||||
break;
|
||||
|
||||
case lcTool::Move:
|
||||
case lcTool::Rotate:
|
||||
ActiveModel->BeginMouseTool();
|
||||
break;
|
||||
|
||||
case lcTool::Eraser:
|
||||
case lcTool::Paint:
|
||||
case lcTool::ColorPicker:
|
||||
break;
|
||||
|
||||
case lcTool::Zoom:
|
||||
case lcTool::Pan:
|
||||
case lcTool::RotateView:
|
||||
case lcTool::Roll:
|
||||
ActiveModel->BeginMouseTool();
|
||||
break;
|
||||
|
||||
case lcTool::ZoomRegion:
|
||||
break;
|
||||
|
||||
case lcTool::Count:
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateCursor();
|
||||
}
|
||||
|
||||
lcVector3 lcGLWidget::GetCameraLightInsertPosition() const
|
||||
{
|
||||
lcModel* ActiveModel = GetActiveModel();
|
||||
|
||||
std::array<lcVector3, 2> ClickPoints = { { lcVector3((float)mMouseX, (float)mMouseY, 0.0f), lcVector3((float)mMouseX, (float)mMouseY, 1.0f) } };
|
||||
UnprojectPoints(ClickPoints.data(), 2);
|
||||
|
||||
if (ActiveModel != mModel)
|
||||
{
|
||||
lcMatrix44 InverseMatrix = lcMatrix44AffineInverse(mActiveSubmodelTransform);
|
||||
|
||||
for (lcVector3& Point : ClickPoints)
|
||||
Point = lcMul31(Point, InverseMatrix);
|
||||
}
|
||||
|
||||
lcVector3 Min, Max;
|
||||
lcVector3 Center;
|
||||
|
||||
if (ActiveModel->GetPiecesBoundingBox(Min, Max))
|
||||
Center = (Min + Max) / 2.0f;
|
||||
else
|
||||
Center = lcVector3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
return lcRayPointClosestPoint(Center, ClickPoints[0], ClickPoints[1]);
|
||||
}
|
||||
|
||||
void lcGLWidget::DrawBackground() const
|
||||
{
|
||||
const lcPreferences& Preferences = lcGetPreferences();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "lc_commands.h"
|
||||
#include "lc_math.h"
|
||||
|
||||
enum class lcDragState
|
||||
{
|
||||
|
@ -80,12 +81,14 @@ enum class lcTrackTool
|
|||
class lcGLWidget
|
||||
{
|
||||
public:
|
||||
lcGLWidget();
|
||||
lcGLWidget(lcModel* Model);
|
||||
virtual ~lcGLWidget();
|
||||
|
||||
lcGLWidget(const lcGLWidget&) = delete;
|
||||
lcGLWidget& operator=(const lcGLWidget&) = delete;
|
||||
|
||||
lcModel* GetActiveModel() const;
|
||||
|
||||
lcCamera* GetCamera() const
|
||||
{
|
||||
return mCamera;
|
||||
|
@ -148,6 +151,8 @@ protected:
|
|||
lcCursor GetCursor() const;
|
||||
void SetCursor(lcCursor Cursor);
|
||||
lcTool GetCurrentTool() const;
|
||||
void StartTracking(lcTrackButton TrackButton);
|
||||
lcVector3 GetCameraLightInsertPosition() const;
|
||||
|
||||
int mMouseX = 0;
|
||||
int mMouseY = 0;
|
||||
|
@ -155,12 +160,17 @@ protected:
|
|||
int mMouseDownY = 0;
|
||||
Qt::KeyboardModifiers mMouseModifiers = Qt::NoModifier;
|
||||
|
||||
bool mTrackUpdated;
|
||||
lcTrackTool mTrackTool = lcTrackTool::None;
|
||||
lcTrackButton mTrackButton = lcTrackButton::None;
|
||||
lcCursor mCursor = lcCursor::Default;
|
||||
|
||||
std::unique_ptr<lcScene> mScene;
|
||||
|
||||
lcModel* mModel = nullptr;
|
||||
lcPiece* mActiveSubmodelInstance = nullptr;
|
||||
lcMatrix44 mActiveSubmodelTransform;
|
||||
|
||||
lcCamera* mCamera = nullptr;
|
||||
bool mDeleteContext = true;
|
||||
};
|
||||
|
|
|
@ -80,7 +80,7 @@ void lcPreviewDockWidget::SetPreviewLock()
|
|||
}
|
||||
|
||||
lcPreviewWidget::lcPreviewWidget()
|
||||
: mLoader(new Project(true)), mViewSphere(this)
|
||||
: lcGLWidget(nullptr), mLoader(new Project(true)), mViewSphere(this)
|
||||
{
|
||||
mLoader->SetActiveModel(0);
|
||||
mModel = mLoader->GetActiveModel();
|
||||
|
@ -203,11 +203,6 @@ void lcPreviewWidget::SetCamera(lcCamera* Camera) // called by lcModel::DeleteMo
|
|||
mCamera->CopyPosition(Camera);
|
||||
}
|
||||
|
||||
lcModel* lcPreviewWidget::GetActiveModel() const
|
||||
{
|
||||
return mModel;
|
||||
}
|
||||
|
||||
void lcPreviewWidget::ZoomExtents()
|
||||
{
|
||||
lcModel* ActiveModel = GetActiveModel();
|
||||
|
@ -268,32 +263,6 @@ void lcPreviewWidget::DrawViewport()
|
|||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void lcPreviewWidget::StartTracking(lcTrackButton TrackButton)
|
||||
{
|
||||
mTrackButton = TrackButton;
|
||||
mMouseDownX = mMouseX;
|
||||
mMouseDownY = mMouseY;
|
||||
lcTool Tool = GetCurrentTool();
|
||||
lcModel* ActiveModel = GetActiveModel();
|
||||
|
||||
switch (Tool)
|
||||
{
|
||||
case lcTool::Select:
|
||||
break;
|
||||
|
||||
case lcTool::Pan:
|
||||
case lcTool::RotateView:
|
||||
ActiveModel->BeginMouseTool();
|
||||
break;
|
||||
|
||||
case lcTool::Count:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateCursor();
|
||||
}
|
||||
|
||||
void lcPreviewWidget::StopTracking(bool Accept)
|
||||
{
|
||||
if (mTrackButton == lcTrackButton::None)
|
||||
|
|
|
@ -43,7 +43,6 @@ public:
|
|||
void ClearPreview();
|
||||
void UpdatePreview();
|
||||
bool SetCurrentPiece(const QString& PartType, int ColorCode);
|
||||
lcModel* GetActiveModel() const;
|
||||
void SetCamera(lcCamera* Camera);
|
||||
void SetDefaultCamera();
|
||||
void ZoomExtents();
|
||||
|
@ -71,12 +70,10 @@ public:
|
|||
protected:
|
||||
void DrawViewport();
|
||||
|
||||
void StartTracking(lcTrackButton TrackButton);
|
||||
void StopTracking(bool Accept);
|
||||
void OnButtonDown(lcTrackButton TrackButton);
|
||||
|
||||
Project* mLoader;
|
||||
lcModel* mModel;
|
||||
lcViewSphere mViewSphere;
|
||||
|
||||
QString mDescription;
|
||||
|
|
|
@ -36,6 +36,7 @@ const char* MinifigWizard::mSectionNames[LC_MFW_NUMITEMS] =
|
|||
};
|
||||
|
||||
MinifigWizard::MinifigWizard()
|
||||
: lcGLWidget(nullptr)
|
||||
{
|
||||
LoadSettings();
|
||||
LoadTemplates();
|
||||
|
|
|
@ -14,10 +14,8 @@ lcVertexBuffer View::mRotateMoveVertexBuffer;
|
|||
lcIndexBuffer View::mRotateMoveIndexBuffer;
|
||||
|
||||
View::View(lcModel* Model)
|
||||
: mViewSphere(this)
|
||||
: lcGLWidget(Model), mViewSphere(this)
|
||||
{
|
||||
mModel = Model;
|
||||
mActiveSubmodelInstance = nullptr;
|
||||
memset(mGridSettings, 0, sizeof(mGridSettings));
|
||||
|
||||
mDragState = lcDragState::None;
|
||||
|
@ -41,11 +39,6 @@ View::~View()
|
|||
delete mCamera;
|
||||
}
|
||||
|
||||
lcModel* View::GetActiveModel() const
|
||||
{
|
||||
return !mActiveSubmodelInstance ? mModel : mActiveSubmodelInstance->mPieceInfo->GetModel();
|
||||
}
|
||||
|
||||
void View::SetTopSubmodelActive()
|
||||
{
|
||||
lcModel* ActiveModel = GetActiveModel();
|
||||
|
@ -561,32 +554,6 @@ lcMatrix44 View::GetPieceInsertPosition(bool IgnoreSelected, PieceInfo* Info) co
|
|||
return lcMatrix44Translation(UnprojectPoint(lcVector3((float)mMouseX, (float)mMouseY, 0.9f)));
|
||||
}
|
||||
|
||||
lcVector3 View::GetCameraLightInsertPosition() const
|
||||
{
|
||||
lcModel* ActiveModel = GetActiveModel();
|
||||
|
||||
std::array<lcVector3, 2> ClickPoints = { { lcVector3((float)mMouseX, (float)mMouseY, 0.0f), lcVector3((float)mMouseX, (float)mMouseY, 1.0f) } };
|
||||
UnprojectPoints(ClickPoints.data(), 2);
|
||||
|
||||
if (ActiveModel != mModel)
|
||||
{
|
||||
lcMatrix44 InverseMatrix = lcMatrix44AffineInverse(mActiveSubmodelTransform);
|
||||
|
||||
for (lcVector3& Point : ClickPoints)
|
||||
Point = lcMul31(Point, InverseMatrix);
|
||||
}
|
||||
|
||||
lcVector3 Min, Max;
|
||||
lcVector3 Center;
|
||||
|
||||
if (ActiveModel->GetPiecesBoundingBox(Min, Max))
|
||||
Center = (Min + Max) / 2.0f;
|
||||
else
|
||||
Center = lcVector3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
return lcRayPointClosestPoint(Center, ClickPoints[0], ClickPoints[1]);
|
||||
}
|
||||
|
||||
void View::GetRayUnderPointer(lcVector3& Start, lcVector3& End) const
|
||||
{
|
||||
lcVector3 StartEnd[2] =
|
||||
|
@ -2398,67 +2365,6 @@ void View::StartOrbitTracking()
|
|||
OnButtonDown(lcTrackButton::Left);
|
||||
}
|
||||
|
||||
void View::StartTracking(lcTrackButton TrackButton)
|
||||
{
|
||||
mTrackButton = TrackButton;
|
||||
mTrackUpdated = false;
|
||||
mMouseDownX = mMouseX;
|
||||
mMouseDownY = mMouseY;
|
||||
lcTool Tool = GetCurrentTool();
|
||||
lcModel* ActiveModel = GetActiveModel();
|
||||
|
||||
switch (Tool)
|
||||
{
|
||||
case lcTool::Insert:
|
||||
case lcTool::Light:
|
||||
break;
|
||||
|
||||
case lcTool::SpotLight:
|
||||
{
|
||||
lcVector3 Position = GetCameraLightInsertPosition();
|
||||
lcVector3 Target = Position + lcVector3(0.1f, 0.1f, 0.1f);
|
||||
ActiveModel->BeginSpotLightTool(Position, Target);
|
||||
}
|
||||
break;
|
||||
|
||||
case lcTool::Camera:
|
||||
{
|
||||
lcVector3 Position = GetCameraLightInsertPosition();
|
||||
lcVector3 Target = Position + lcVector3(0.1f, 0.1f, 0.1f);
|
||||
ActiveModel->BeginCameraTool(Position, Target);
|
||||
}
|
||||
break;
|
||||
|
||||
case lcTool::Select:
|
||||
break;
|
||||
|
||||
case lcTool::Move:
|
||||
case lcTool::Rotate:
|
||||
ActiveModel->BeginMouseTool();
|
||||
break;
|
||||
|
||||
case lcTool::Eraser:
|
||||
case lcTool::Paint:
|
||||
case lcTool::ColorPicker:
|
||||
break;
|
||||
|
||||
case lcTool::Zoom:
|
||||
case lcTool::Pan:
|
||||
case lcTool::RotateView:
|
||||
case lcTool::Roll:
|
||||
ActiveModel->BeginMouseTool();
|
||||
break;
|
||||
|
||||
case lcTool::ZoomRegion:
|
||||
break;
|
||||
|
||||
case lcTool::Count:
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateCursor();
|
||||
}
|
||||
|
||||
void View::StopTracking(bool Accept)
|
||||
{
|
||||
if (mTrackButton == lcTrackButton::None)
|
||||
|
|
|
@ -26,7 +26,6 @@ public:
|
|||
return mModel;
|
||||
}
|
||||
|
||||
lcModel* GetActiveModel() const;
|
||||
void SetTopSubmodelActive();
|
||||
void SetSelectedSubmodelActive();
|
||||
|
||||
|
@ -70,7 +69,6 @@ public:
|
|||
|
||||
lcVector3 GetMoveDirection(const lcVector3& Direction) const;
|
||||
lcMatrix44 GetPieceInsertPosition(bool IgnoreSelected, PieceInfo* Info) const;
|
||||
lcVector3 GetCameraLightInsertPosition() const;
|
||||
void GetRayUnderPointer(lcVector3& Start, lcVector3& End) const;
|
||||
lcObjectSection FindObjectUnderPointer(bool PiecesOnly, bool IgnoreSelected) const;
|
||||
lcArray<lcObject*> FindObjectsInBox(float x1, float y1, float x2, float y2) const;
|
||||
|
@ -97,18 +95,12 @@ protected:
|
|||
bool IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms) const;
|
||||
lcTrackTool GetOverrideTrackTool(Qt::MouseButton Button) const;
|
||||
float GetOverlayScale() const;
|
||||
void StartTracking(lcTrackButton TrackButton);
|
||||
void StopTracking(bool Accept);
|
||||
void OnButtonDown(lcTrackButton TrackButton);
|
||||
lcMatrix44 GetTileProjectionMatrix(int CurrentRow, int CurrentColumn, int CurrentTileWidth, int CurrentTileHeight) const;
|
||||
|
||||
lcModel* mModel;
|
||||
lcPiece* mActiveSubmodelInstance;
|
||||
lcMatrix44 mActiveSubmodelTransform;
|
||||
|
||||
lcDragState mDragState;
|
||||
bool mTrackToolFromOverlay;
|
||||
bool mTrackUpdated;
|
||||
lcVector3 mMouseDownPosition;
|
||||
PieceInfo* mMouseDownPiece;
|
||||
QImage mRenderImage;
|
||||
|
|
Loading…
Reference in a new issue