leocad/common/lc_view.h

321 lines
6.1 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,
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,
Count
};
class View : public QObject
2011-09-07 23:06:51 +02:00
{
Q_OBJECT
2011-09-07 23:06:51 +02:00
public:
View(lcViewType ViewType, lcModel* Model);
~View();
2012-02-05 03:50:57 +01:00
2020-05-04 00:39:39 +02:00
View(const View&) = delete;
View& operator=(const View&) = delete;
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;
}
QGLWidget* GetWidget() const
{
return mWidget;
}
void SetWidget(QGLWidget* Widget)
{
mWidget = Widget;
}
int GetMouseX() const
{
return mMouseX;
}
int GetMouseY() const
{
return mMouseY;
}
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 SetContext(lcContext* Context);
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 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);
void SetCameraIndex(int Index);
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;
2011-09-07 23:06:51 +02: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;
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
bool BeginRenderToImage(int Width, int Height);
void EndRenderToImage();
QImage GetRenderImage() const
{
return mRenderImage;
}
2020-12-25 19:37:59 +01:00
lcContext* mContext = nullptr;
signals:
void FocusReceived();
void CameraChanged();
protected:
static void CreateSelectMoveOverlayMesh(lcContext* Context);
2020-12-25 19:37:59 +01:00
void DrawBackground() const;
void DrawViewport() const;
void DrawAxes() const;
void DrawSelectMoveOverlay();
void DrawRotateOverlay();
void DrawSelectZoomRegionOverlay();
void DrawRotateViewOverlay();
void DrawGrid();
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;
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;
float GetOverlayScale() const;
2020-12-25 19:37:59 +01:00
void StartTracking(lcTrackButton TrackButton);
void StopTracking(bool Accept);
void OnButtonDown(lcTrackButton TrackButton);
2020-12-25 19:37:59 +01:00
QGLWidget* mWidget = nullptr;
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;
lcTrackTool mTrackTool = lcTrackTool::None;
lcTrackButton mTrackButton = lcTrackButton::None;
lcCursor mCursor = lcCursor::Default;
2014-05-27 00:58:08 +02:00
lcDragState mDragState;
bool mTrackToolFromOverlay;
2017-11-13 04:38:07 +01:00
lcVector3 mMouseDownPosition;
PieceInfo* mMouseDownPiece;
QImage mRenderImage;
std::pair<lcFramebuffer, lcFramebuffer> mRenderFramebuffer;
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;
lcVertexBuffer mGridBuffer;
2015-04-14 06:14:10 +02:00
int mGridSettings[7];
2020-12-25 19:37:59 +01:00
static View* mLastFocusedView;
static std::vector<View*> mViews;
static lcVertexBuffer mRotateMoveVertexBuffer;
static lcIndexBuffer mRotateMoveIndexBuffer;
2011-09-07 23:06:51 +02:00
};