leocad/common/lc_view.h

364 lines
7.4 KiB
C
Raw Normal View History

#pragma once
2011-09-07 23:06:51 +02:00
#include "lc_context.h"
2020-12-25 19:37:59 +01:00
#include "lc_math.h"
#include "lc_commands.h"
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,
PartsList,
2020-12-25 19:37:59 +01:00
Count
};
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
{
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
static lcFindReplaceParams& GetFindReplaceParams()
{
return mFindReplaceParams;
}
2021-01-31 21:05:15 +01: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;
}
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();
static void CreateResources(lcContext* Context);
static void DestroyResources(lcContext* Context);
2020-12-25 19:37:59 +01:00
void MakeCurrent();
void Redraw();
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();
void StartPanGesture();
void UpdatePanGesture(int dx, int dy);
void EndPanGesture(bool Accept);
void StartOrbitTracking();
2014-11-29 03:55:58 +01:00
void CancelTrackingOrClearSelection();
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
void SetProjection(bool Ortho);
void LookAt();
void MoveCamera(const lcVector3& Direction);
void Zoom(float Amount);
2020-12-25 19:37:59 +01:00
void ZoomExtents();
2014-05-27 00:58:08 +02: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
float GetOverlayScale() const;
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;
void GetRayUnderPointer(lcVector3& Start, lcVector3& End) const;
2017-11-13 04:38:07 +01:00
lcObjectSection FindObjectUnderPointer(bool PiecesOnly, bool IgnoreSelected) const;
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
lcVector3 ProjectPoint(const lcVector3& Point) const;
lcVector3 UnprojectPoint(const lcVector3& Point) const;
void UnprojectPoints(lcVector3* Points, int NumPoints) const;
lcMatrix44 GetProjectionMatrix() const;
bool BeginRenderToImage(int Width, int Height);
void EndRenderToImage();
QImage GetRenderImage() const;
void BindRenderFramebuffer();
void UnbindRenderFramebuffer();
QImage GetRenderFramebufferImage() const;
std::vector<QImage> GetStepImages(lcStep Start, lcStep End);
void SaveStepImages(const QString& BaseName, bool AddStepSuffix, lcStep Start, lcStep End, std::function<void(const QString&)> ProgressCallback);
2020-12-25 19:37:59 +01:00
lcContext* mContext = nullptr;
signals:
void FocusReceived();
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;
void DrawSelectZoomRegionOverlay();
void DrawRotateViewOverlay();
void DrawGrid();
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;
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);
void StopTracking(bool Accept);
void OnButtonDown(lcTrackButton TrackButton);
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;
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-27 00:58:08 +02:00
lcDragState mDragState;
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;
int mPanX = 0;
int mPanY = 0;
QImage mRenderImage;
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<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;
lcVertexBuffer mGridBuffer;
2015-04-14 06:14:10 +02:00
int mGridSettings[7];
2024-01-15 19:18:50 +01:00
static QPointer<lcFindReplaceWidget> mFindWidget;
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
};