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,
|
|
|
|
Light,
|
|
|
|
Spotlight,
|
|
|
|
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,
|
|
|
|
SpotLight,
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
lcView& operator=(const lcView&) = delete;
|
2020-05-04 00:39:39 +02:00
|
|
|
|
2018-03-29 19:20:36 +02:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mModel = nullptr;
|
|
|
|
mActiveSubmodelInstance = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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();
|
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);
|
|
|
|
void SetCameraIndex(int Index);
|
|
|
|
|
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;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2014-11-30 18:53:09 +01:00
|
|
|
lcVector3 GetMoveDirection(const lcVector3& Direction) const;
|
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;
|
2014-11-29 03:55:58 +01:00
|
|
|
lcArray<lcObject*> FindObjectsInBox(float x1, float y1, float x2, float y2) const;
|
2014-05-03 18:59:57 +02:00
|
|
|
|
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();
|
|
|
|
void CameraChanged();
|
|
|
|
|
2014-05-18 01:03:05 +02:00
|
|
|
protected:
|
2015-04-27 02:47:31 +02:00
|
|
|
static void CreateSelectMoveOverlayMesh(lcContext* Context);
|
|
|
|
|
2020-12-25 19:37:59 +01:00
|
|
|
void DrawBackground() const;
|
|
|
|
void DrawViewport() const;
|
|
|
|
void DrawAxes() const;
|
|
|
|
|
2014-05-18 01:03:05 +02:00
|
|
|
void DrawSelectMoveOverlay();
|
|
|
|
void DrawRotateOverlay();
|
|
|
|
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
|
|
|
lcVector3 ProjectPoint(const lcVector3& Point) const;
|
|
|
|
lcVector3 UnprojectPoint(const lcVector3& Point) const;
|
|
|
|
void UnprojectPoints(lcVector3* Points, int NumPoints) const;
|
|
|
|
lcMatrix44 GetProjectionMatrix() const;
|
|
|
|
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();
|
2017-12-02 21:22:04 +01:00
|
|
|
bool IsTrackToolAllowed(lcTrackTool TrackTool, quint32 AllowedTransforms) const;
|
2016-04-23 02:17:33 +02:00
|
|
|
lcTrackTool GetOverrideTrackTool(Qt::MouseButton Button) const;
|
2014-05-18 01:03:05 +02:00
|
|
|
float GetOverlayScale() 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);
|
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;
|
2017-11-13 04:38:07 +01:00
|
|
|
lcVector3 mMouseDownPosition;
|
|
|
|
PieceInfo* mMouseDownPiece;
|
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;
|
|
|
|
std::unique_ptr<lcViewSphere> mViewSphere;
|
|
|
|
|
|
|
|
lcModel* mModel = nullptr;
|
|
|
|
lcPiece* mActiveSubmodelInstance = nullptr;
|
|
|
|
lcMatrix44 mActiveSubmodelTransform;
|
|
|
|
|
|
|
|
lcCamera* mCamera = nullptr;
|
|
|
|
|
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
|
|
|
|
2020-12-25 19:54:33 +01:00
|
|
|
static lcView* mLastFocusedView;
|
|
|
|
static std::vector<lcView*> mViews;
|
2020-12-25 19:37:59 +01:00
|
|
|
|
2015-04-27 02:47:31 +02:00
|
|
|
static lcVertexBuffer mRotateMoveVertexBuffer;
|
|
|
|
static lcIndexBuffer mRotateMoveIndexBuffer;
|
2011-09-07 23:06:51 +02:00
|
|
|
};
|
|
|
|
|