2017-07-19 23:20:32 +02:00
|
|
|
#pragma once
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2020-12-16 03:47:58 +01:00
|
|
|
#include "lc_context.h"
|
2020-12-25 19:37:59 +01:00
|
|
|
#include "lc_math.h"
|
|
|
|
#include "lc_commands.h"
|
2014-05-18 01:03:05 +02:00
|
|
|
|
2020-12-25 19:37:59 +01:00
|
|
|
enum class lcDragState
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Piece,
|
|
|
|
Color
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class lcCursor
|
|
|
|
{
|
|
|
|
First,
|
|
|
|
Hidden = First,
|
|
|
|
Default,
|
|
|
|
Brick,
|
2023-08-13 15:15:52 +02:00
|
|
|
PointLight,
|
2023-09-10 03:25:34 +02:00
|
|
|
SpotLight,
|
2023-08-13 15:15:52 +02:00
|
|
|
DirectionalLight,
|
|
|
|
AreaLight,
|
2020-12-25 19:37:59 +01:00
|
|
|
Camera,
|
|
|
|
Select,
|
|
|
|
SelectAdd,
|
|
|
|
SelectRemove,
|
|
|
|
Move,
|
|
|
|
Rotate,
|
|
|
|
RotateX,
|
|
|
|
RotateY,
|
|
|
|
Delete,
|
|
|
|
Paint,
|
|
|
|
ColorPicker,
|
|
|
|
Zoom,
|
|
|
|
ZoomRegion,
|
|
|
|
Pan,
|
|
|
|
Roll,
|
|
|
|
RotateView,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class lcTrackButton
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Left,
|
|
|
|
Middle,
|
|
|
|
Right
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class lcTrackTool
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Insert,
|
|
|
|
PointLight,
|
2023-09-10 03:25:34 +02:00
|
|
|
SpotLight,
|
2023-08-13 15:15:52 +02:00
|
|
|
DirectionalLight,
|
2023-08-04 22:26:29 +02:00
|
|
|
AreaLight,
|
2020-12-25 19:37:59 +01:00
|
|
|
Camera,
|
|
|
|
Select,
|
|
|
|
MoveX,
|
|
|
|
MoveY,
|
|
|
|
MoveZ,
|
|
|
|
MoveXY,
|
|
|
|
MoveXZ,
|
|
|
|
MoveYZ,
|
|
|
|
MoveXYZ,
|
|
|
|
RotateX,
|
|
|
|
RotateY,
|
|
|
|
RotateZ,
|
|
|
|
RotateXY,
|
|
|
|
RotateXYZ,
|
|
|
|
ScalePlus,
|
|
|
|
ScaleMinus,
|
|
|
|
Eraser,
|
|
|
|
Paint,
|
|
|
|
ColorPicker,
|
|
|
|
Zoom,
|
|
|
|
Pan,
|
|
|
|
OrbitX,
|
|
|
|
OrbitY,
|
|
|
|
OrbitXY,
|
|
|
|
Roll,
|
|
|
|
ZoomRegion,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class lcViewType
|
|
|
|
{
|
|
|
|
View,
|
|
|
|
Preview,
|
|
|
|
Minifig,
|
2020-12-29 21:23:36 +01:00
|
|
|
PartsList,
|
2020-12-25 19:37:59 +01:00
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
2021-02-01 23:12:03 +01:00
|
|
|
struct lcFindReplaceParams
|
|
|
|
{
|
|
|
|
PieceInfo* FindInfo = nullptr;
|
|
|
|
QString FindString;
|
|
|
|
int FindColorIndex = 0;
|
|
|
|
PieceInfo* ReplacePieceInfo = nullptr;
|
|
|
|
int ReplaceColorIndex = 0;
|
|
|
|
};
|
|
|
|
|
2020-12-25 19:54:33 +01:00
|
|
|
class lcView : public QObject
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2020-12-13 19:33:42 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2011-09-07 23:06:51 +02:00
|
|
|
public:
|
2020-12-25 19:54:33 +01:00
|
|
|
lcView(lcViewType ViewType, lcModel* Model);
|
|
|
|
~lcView();
|
2012-02-05 03:50:57 +01:00
|
|
|
|
2020-12-25 19:54:33 +01:00
|
|
|
lcView(const lcView&) = delete;
|
2021-11-15 03:34:24 +01:00
|
|
|
lcView(lcView&&) = delete;
|
2020-12-25 19:54:33 +01:00
|
|
|
lcView& operator=(const lcView&) = delete;
|
2021-11-15 03:34:24 +01:00
|
|
|
lcView& operator=(lcView&&) = delete;
|
2020-05-04 00:39:39 +02:00
|
|
|
|
2021-02-01 23:12:03 +01:00
|
|
|
static lcFindReplaceParams& GetFindReplaceParams()
|
|
|
|
{
|
|
|
|
return mFindReplaceParams;
|
|
|
|
}
|
2021-01-31 21:05:15 +01:00
|
|
|
|
2018-03-29 19:20:36 +02:00
|
|
|
lcModel* GetModel() const
|
|
|
|
{
|
|
|
|
return mModel;
|
|
|
|
}
|
|
|
|
|
2020-12-25 19:37:59 +01:00
|
|
|
lcViewType GetViewType() const
|
|
|
|
{
|
|
|
|
return mViewType;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcCamera* GetCamera() const
|
|
|
|
{
|
|
|
|
return mCamera;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsLastFocused() const
|
|
|
|
{
|
|
|
|
return mLastFocusedView == this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsTracking() const
|
|
|
|
{
|
|
|
|
return mTrackButton != lcTrackButton::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetWidth() const
|
|
|
|
{
|
|
|
|
return mWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetHeight() const
|
|
|
|
{
|
|
|
|
return mHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSize(int Width, int Height)
|
|
|
|
{
|
|
|
|
mWidth = Width;
|
|
|
|
mHeight = Height;
|
|
|
|
}
|
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
lcViewWidget* GetWidget() const
|
2020-12-25 19:37:59 +01:00
|
|
|
{
|
|
|
|
return mWidget;
|
|
|
|
}
|
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
void SetWidget(lcViewWidget* Widget)
|
2020-12-25 19:37:59 +01:00
|
|
|
{
|
|
|
|
mWidget = Widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetMouseX() const
|
|
|
|
{
|
|
|
|
return mMouseX;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetMouseY() const
|
|
|
|
{
|
|
|
|
return mMouseY;
|
|
|
|
}
|
|
|
|
|
2021-01-08 02:04:19 +01:00
|
|
|
void SetBackgroundColorOverride(quint32 BackgroundColor)
|
|
|
|
{
|
|
|
|
mOverrideBackgroundColor = true;
|
|
|
|
mBackgroundColor = BackgroundColor;
|
|
|
|
}
|
|
|
|
|
2021-06-20 20:40:16 +02:00
|
|
|
lcMatrix44 GetActiveSubmodelTransform() const
|
|
|
|
{
|
|
|
|
return mActiveSubmodelTransform;
|
|
|
|
}
|
|
|
|
|
2021-02-27 20:15:04 +01:00
|
|
|
static std::vector<lcView*> GetModelViews(const lcModel* Model);
|
2020-12-25 19:37:59 +01:00
|
|
|
static void UpdateProjectViews(const Project* Project);
|
|
|
|
static void UpdateAllViews();
|
2018-03-29 19:20:36 +02:00
|
|
|
|
2015-04-27 02:47:31 +02:00
|
|
|
static void CreateResources(lcContext* Context);
|
|
|
|
static void DestroyResources(lcContext* Context);
|
|
|
|
|
2020-12-25 19:37:59 +01:00
|
|
|
void MakeCurrent();
|
|
|
|
void Redraw();
|
2021-01-02 03:41:28 +01:00
|
|
|
|
|
|
|
void SetOffscreenContext();
|
2020-12-25 19:37:59 +01:00
|
|
|
|
|
|
|
void SetFocus(bool Focus);
|
|
|
|
void SetMousePosition(int MouseX, int MouseY);
|
|
|
|
void SetMouseModifiers(Qt::KeyboardModifiers MouseModifiers);
|
|
|
|
|
|
|
|
lcModel* GetActiveModel() const;
|
|
|
|
void SetTopSubmodelActive();
|
|
|
|
void SetSelectedSubmodelActive();
|
|
|
|
|
|
|
|
void OnDraw();
|
|
|
|
void OnLeftButtonDown();
|
|
|
|
void OnLeftButtonUp();
|
|
|
|
void OnLeftButtonDoubleClick();
|
|
|
|
void OnMiddleButtonDown();
|
|
|
|
void OnMiddleButtonUp();
|
|
|
|
void OnRightButtonDown();
|
|
|
|
void OnRightButtonUp();
|
|
|
|
void OnBackButtonDown();
|
|
|
|
void OnBackButtonUp();
|
|
|
|
void OnForwardButtonDown();
|
|
|
|
void OnForwardButtonUp();
|
|
|
|
void OnMouseMove();
|
|
|
|
void OnMouseWheel(float Direction);
|
|
|
|
void BeginDrag(lcDragState DragState);
|
|
|
|
void EndDrag(bool Accept);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2020-12-25 19:37:59 +01:00
|
|
|
void UpdateCursor();
|
2022-05-08 03:46:26 +02:00
|
|
|
void StartPanGesture();
|
|
|
|
void UpdatePanGesture(int dx, int dy);
|
|
|
|
void EndPanGesture(bool Accept);
|
2018-09-12 01:36:10 +02:00
|
|
|
void StartOrbitTracking();
|
2014-11-29 03:55:58 +01:00
|
|
|
void CancelTrackingOrClearSelection();
|
2014-11-30 18:53:09 +01:00
|
|
|
|
2020-12-25 19:37:59 +01:00
|
|
|
void SetViewpoint(lcViewpoint Viewpoint);
|
|
|
|
void SetViewpoint(const lcVector3& Position);
|
|
|
|
void SetViewpoint(const lcVector3& Position, const lcVector3& Target, const lcVector3& Up);
|
|
|
|
void SetCameraAngles(float Latitude, float Longitude);
|
|
|
|
void SetDefaultCamera();
|
|
|
|
void SetCamera(lcCamera* Camera, bool ForceCopy);
|
|
|
|
void SetCamera(const QString& CameraName);
|
2024-06-04 18:34:38 +02:00
|
|
|
void SetCameraIndex(size_t CameraIndex);
|
2020-12-25 19:37:59 +01:00
|
|
|
|
2014-11-30 18:53:09 +01:00
|
|
|
void SetProjection(bool Ortho);
|
|
|
|
void LookAt();
|
2018-01-15 20:35:15 +01:00
|
|
|
void MoveCamera(const lcVector3& Direction);
|
2019-02-10 01:30:11 +01:00
|
|
|
void Zoom(float Amount);
|
2020-12-25 19:37:59 +01:00
|
|
|
void ZoomExtents();
|
2014-05-27 00:58:08 +02:00
|
|
|
|
2014-11-25 01:51:34 +01:00
|
|
|
void RemoveCamera();
|
2015-12-04 21:32:10 +01:00
|
|
|
void ShowContextMenu() const;
|
2021-01-31 00:37:17 +01:00
|
|
|
bool CloseFindReplaceDialog();
|
|
|
|
void ShowFindReplaceWidget(bool Replace);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2021-06-20 20:40:16 +02:00
|
|
|
float GetOverlayScale() const;
|
2014-11-30 18:53:09 +01:00
|
|
|
lcVector3 GetMoveDirection(const lcVector3& Direction) const;
|
2024-11-03 03:34:22 +01:00
|
|
|
void UpdatePiecePreview();
|
2017-11-13 04:38:07 +01:00
|
|
|
lcMatrix44 GetPieceInsertPosition(bool IgnoreSelected, PieceInfo* Info) const;
|
2020-12-25 19:37:59 +01:00
|
|
|
lcVector3 GetCameraLightInsertPosition() const;
|
2016-03-03 01:04:49 +01:00
|
|
|
void GetRayUnderPointer(lcVector3& Start, lcVector3& End) const;
|
2017-11-13 04:38:07 +01:00
|
|
|
lcObjectSection FindObjectUnderPointer(bool PiecesOnly, bool IgnoreSelected) const;
|
2021-12-25 00:42:37 +01:00
|
|
|
lcPieceInfoRayTest FindPieceInfoUnderPointer(bool IgnoreSelected) const;
|
2024-05-26 22:01:34 +02:00
|
|
|
std::vector<lcObject*> FindObjectsInBox(float x1, float y1, float x2, float y2) const;
|
2014-05-03 18:59:57 +02:00
|
|
|
|
2021-06-20 20:40:16 +02:00
|
|
|
lcVector3 ProjectPoint(const lcVector3& Point) const;
|
|
|
|
lcVector3 UnprojectPoint(const lcVector3& Point) const;
|
|
|
|
void UnprojectPoints(lcVector3* Points, int NumPoints) const;
|
|
|
|
lcMatrix44 GetProjectionMatrix() const;
|
|
|
|
|
2017-07-30 23:18:57 +02:00
|
|
|
bool BeginRenderToImage(int Width, int Height);
|
|
|
|
void EndRenderToImage();
|
2020-12-29 02:30:41 +01:00
|
|
|
QImage GetRenderImage() const;
|
2021-01-02 03:41:28 +01:00
|
|
|
void BindRenderFramebuffer();
|
|
|
|
void UnbindRenderFramebuffer();
|
2020-12-29 02:30:41 +01:00
|
|
|
QImage GetRenderFramebufferImage() const;
|
2021-01-06 18:55:03 +01:00
|
|
|
std::vector<QImage> GetStepImages(lcStep Start, lcStep End);
|
2021-01-11 03:07:27 +01:00
|
|
|
void SaveStepImages(const QString& BaseName, bool AddStepSuffix, lcStep Start, lcStep End, std::function<void(const QString&)> ProgressCallback);
|
2017-07-30 23:18:57 +02:00
|
|
|
|
2020-12-25 19:37:59 +01:00
|
|
|
lcContext* mContext = nullptr;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void FocusReceived();
|
|
|
|
|
2014-05-18 01:03:05 +02:00
|
|
|
protected:
|
2022-04-19 23:06:11 +02:00
|
|
|
void DrawBackground(int CurrentTileRow, int TotalTileRows, int CurrentTileHeight) const;
|
2020-12-25 19:37:59 +01:00
|
|
|
void DrawViewport() const;
|
|
|
|
void DrawAxes() const;
|
|
|
|
|
2014-05-18 01:03:05 +02:00
|
|
|
void DrawSelectZoomRegionOverlay();
|
|
|
|
void DrawRotateViewOverlay();
|
2014-08-24 00:56:59 +02:00
|
|
|
void DrawGrid();
|
2014-05-18 01:03:05 +02:00
|
|
|
|
2020-12-25 19:37:59 +01:00
|
|
|
lcMatrix44 GetTileProjectionMatrix(int CurrentRow, int CurrentColumn, int CurrentTileWidth, int CurrentTileHeight) const;
|
|
|
|
|
|
|
|
lcCursor GetCursor() const;
|
|
|
|
void SetCursor(lcCursor Cursor);
|
|
|
|
lcTool GetCurrentTool() const;
|
2014-05-18 01:03:05 +02:00
|
|
|
void UpdateTrackTool();
|
2016-04-23 02:17:33 +02:00
|
|
|
lcTrackTool GetOverrideTrackTool(Qt::MouseButton Button) const;
|
2020-12-25 19:37:59 +01:00
|
|
|
void StartTracking(lcTrackButton TrackButton);
|
2014-05-18 01:03:05 +02:00
|
|
|
void StopTracking(bool Accept);
|
2016-05-09 03:59:10 +02:00
|
|
|
void OnButtonDown(lcTrackButton TrackButton);
|
2022-05-08 03:46:26 +02:00
|
|
|
void StartPan(int x, int y);
|
|
|
|
void UpdatePan(int x, int y);
|
2020-12-25 19:37:59 +01:00
|
|
|
|
2020-12-27 22:05:55 +01:00
|
|
|
lcViewWidget* mWidget = nullptr;
|
2020-12-25 19:37:59 +01:00
|
|
|
int mWidth = 1;
|
|
|
|
int mHeight = 1;
|
|
|
|
bool mDeleteContext = true;
|
|
|
|
lcViewType mViewType;
|
|
|
|
|
|
|
|
int mMouseX = 0;
|
|
|
|
int mMouseY = 0;
|
|
|
|
int mMouseDownX = 0;
|
|
|
|
int mMouseDownY = 0;
|
|
|
|
Qt::KeyboardModifiers mMouseModifiers = Qt::NoModifier;
|
|
|
|
|
|
|
|
bool mTrackUpdated = false;
|
2020-12-28 19:42:51 +01:00
|
|
|
bool mToolClicked = false;
|
2020-12-25 19:37:59 +01:00
|
|
|
lcTrackTool mTrackTool = lcTrackTool::None;
|
|
|
|
lcTrackButton mTrackButton = lcTrackButton::None;
|
|
|
|
lcCursor mCursor = lcCursor::Default;
|
2014-05-18 01:03:05 +02:00
|
|
|
|
2014-05-27 00:58:08 +02:00
|
|
|
lcDragState mDragState;
|
2018-02-06 23:47:11 +01:00
|
|
|
bool mTrackToolFromOverlay;
|
2024-11-03 03:34:22 +01:00
|
|
|
quint32 mTrackToolSection = ~0U;
|
2017-11-13 04:38:07 +01:00
|
|
|
lcVector3 mMouseDownPosition;
|
|
|
|
PieceInfo* mMouseDownPiece;
|
2022-05-08 03:46:26 +02:00
|
|
|
int mPanX = 0;
|
|
|
|
int mPanY = 0;
|
2020-12-29 02:30:41 +01:00
|
|
|
|
2017-07-30 23:18:57 +02:00
|
|
|
QImage mRenderImage;
|
2020-12-29 02:30:41 +01:00
|
|
|
std::unique_ptr<QOpenGLFramebufferObject> mRenderFramebuffer;
|
2021-01-08 02:04:19 +01:00
|
|
|
bool mOverrideBackgroundColor = false;
|
|
|
|
quint32 mBackgroundColor = 0;
|
2015-04-14 06:14:10 +02:00
|
|
|
|
2020-12-25 19:37:59 +01:00
|
|
|
std::unique_ptr<lcScene> mScene;
|
2021-06-20 20:40:16 +02:00
|
|
|
std::unique_ptr<lcViewManipulator> mViewManipulator;
|
2020-12-25 19:37:59 +01:00
|
|
|
std::unique_ptr<lcViewSphere> mViewSphere;
|
|
|
|
|
|
|
|
lcModel* mModel = nullptr;
|
|
|
|
lcPiece* mActiveSubmodelInstance = nullptr;
|
|
|
|
lcMatrix44 mActiveSubmodelTransform;
|
|
|
|
|
|
|
|
lcCamera* mCamera = nullptr;
|
|
|
|
|
2024-11-03 03:34:22 +01:00
|
|
|
PieceInfo* mPiecePreviewInfo = nullptr;
|
|
|
|
lcMatrix44 mPiecePreviewTransform;
|
|
|
|
|
2015-04-26 20:14:33 +02:00
|
|
|
lcVertexBuffer mGridBuffer;
|
2015-04-14 06:14:10 +02:00
|
|
|
int mGridSettings[7];
|
2015-04-27 02:47:31 +02:00
|
|
|
|
2024-01-15 19:18:50 +01:00
|
|
|
static QPointer<lcFindReplaceWidget> mFindWidget;
|
2021-02-01 23:12:03 +01:00
|
|
|
static lcFindReplaceParams mFindReplaceParams;
|
|
|
|
|
2020-12-25 19:54:33 +01:00
|
|
|
static lcView* mLastFocusedView;
|
|
|
|
static std::vector<lcView*> mViews;
|
2011-09-07 23:06:51 +02:00
|
|
|
};
|