leocad/common/lc_glwidget.h

251 lines
4.4 KiB
C
Raw Normal View History

#pragma once
2013-08-09 06:57:18 +02:00
2020-12-05 21:17:09 +01:00
#include "lc_commands.h"
2020-12-06 19:52:57 +01:00
#include "lc_math.h"
2020-12-05 21:17:09 +01:00
2020-11-14 21:47:55 +01:00
enum class lcDragState
{
None,
Piece,
Color
};
2020-02-15 20:36:06 +01:00
enum class lcCursor
2013-08-09 06:57:18 +02:00
{
2020-12-06 20:15:23 +01:00
First,
Hidden = First,
2020-02-15 20:36:06 +01:00
Default,
Brick,
Light,
Spotlight,
Camera,
Select,
SelectAdd,
SelectRemove,
Move,
Rotate,
RotateX,
RotateY,
Delete,
Paint,
ColorPicker,
Zoom,
ZoomRegion,
Pan,
Roll,
RotateView,
Count
2013-08-09 06:57:18 +02:00
};
2020-12-05 01:52:57 +01:00
enum class lcTrackButton
{
None,
Left,
Middle,
Right
};
2020-12-05 21:17:09 +01:00
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 lcGLWidget : public QObject
2013-08-09 06:57:18 +02:00
{
Q_OBJECT
2013-08-09 06:57:18 +02:00
public:
lcGLWidget(lcViewType ViewType, lcModel* Model);
2020-12-04 20:40:53 +01:00
virtual ~lcGLWidget();
2013-08-09 06:57:18 +02:00
2020-12-04 20:40:53 +01:00
lcGLWidget(const lcGLWidget&) = delete;
lcGLWidget& operator=(const lcGLWidget&) = delete;
2014-04-20 21:09:46 +02:00
2020-12-16 02:19:32 +01:00
static void UpdateProjectViews(const Project* Project);
static void UpdateAllViews();
2020-12-06 19:52:57 +01:00
lcModel* GetActiveModel() const;
lcViewType GetViewType() const
{
return mViewType;
}
2020-12-04 21:49:01 +01:00
lcCamera* GetCamera() const
{
return mCamera;
}
bool IsLastFocused() const
{
return mLastFocusedView == this;
}
2020-12-05 01:52:57 +01:00
bool IsTracking() const
{
return mTrackButton != lcTrackButton::None;
}
2020-12-13 21:05:54 +01:00
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;
}
2020-12-05 17:45:29 +01:00
int GetMouseX() const
{
return mMouseX;
}
int GetMouseY() const
{
return mMouseY;
}
2020-12-12 03:01:04 +01:00
void SetFocus(bool Focus);
2020-12-05 17:45:29 +01:00
void SetMousePosition(int MouseX, int MouseY);
void SetMouseModifiers(Qt::KeyboardModifiers MouseModifiers);
2020-12-04 20:40:53 +01:00
void SetContext(lcContext* Context);
2013-08-09 06:57:18 +02:00
void MakeCurrent();
void Redraw();
2020-12-05 21:17:09 +01:00
void UpdateCursor();
2020-12-04 21:49:01 +01:00
lcVector3 ProjectPoint(const lcVector3& Point) const;
lcVector3 UnprojectPoint(const lcVector3& Point) const;
void UnprojectPoints(lcVector3* Points, int NumPoints) const;
lcMatrix44 GetProjectionMatrix() const;
void ZoomExtents();
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);
2020-12-14 01:27:21 +01:00
void SetCamera(const QString& CameraName);
void SetCameraIndex(int Index);
2020-11-26 21:07:41 +01:00
void DrawBackground() const;
2020-12-12 03:01:04 +01:00
void DrawViewport() const;
2020-12-04 21:49:01 +01:00
void DrawAxes() const;
2013-08-09 06:57:18 +02:00
virtual void OnDraw() { }
virtual void OnInitialUpdate() { }
virtual void OnLeftButtonDown() { }
virtual void OnLeftButtonUp() { }
virtual void OnLeftButtonDoubleClick() { }
virtual void OnMiddleButtonDown() { }
virtual void OnMiddleButtonUp() { }
virtual void OnRightButtonDown() { }
virtual void OnRightButtonUp() { }
virtual void OnBackButtonDown() { }
virtual void OnBackButtonUp() { }
virtual void OnForwardButtonDown() { }
virtual void OnForwardButtonUp() { }
2013-08-09 06:57:18 +02:00
virtual void OnMouseMove() { }
2020-12-16 02:19:32 +01:00
void OnMouseWheel(float Direction);
2020-12-04 20:40:53 +01:00
virtual void BeginDrag(lcDragState DragState) { Q_UNUSED(DragState); }
virtual void EndDrag(bool Accept) { Q_UNUSED(Accept); }
2013-08-09 06:57:18 +02:00
2020-12-04 20:40:53 +01:00
lcContext* mContext = nullptr;
2020-12-04 21:49:01 +01:00
signals:
2020-12-16 03:27:54 +01:00
void FocusReceived();
void CameraChanged();
2020-12-04 21:49:01 +01:00
protected:
2020-12-05 21:17:09 +01:00
lcCursor GetCursor() const;
void SetCursor(lcCursor Cursor);
lcTool GetCurrentTool() const;
2020-12-06 19:52:57 +01:00
void StartTracking(lcTrackButton TrackButton);
lcVector3 GetCameraLightInsertPosition() const;
2020-12-05 21:17:09 +01:00
2020-12-05 17:45:29 +01:00
int mMouseX = 0;
int mMouseY = 0;
2020-12-05 20:02:10 +01:00
int mMouseDownX = 0;
int mMouseDownY = 0;
2020-12-05 17:45:29 +01:00
Qt::KeyboardModifiers mMouseModifiers = Qt::NoModifier;
2020-12-12 03:01:04 +01:00
bool mTrackUpdated = false;
2020-12-05 21:17:09 +01:00
lcTrackTool mTrackTool = lcTrackTool::None;
2020-12-05 17:45:29 +01:00
lcTrackButton mTrackButton = lcTrackButton::None;
lcCursor mCursor = lcCursor::Default;
2020-12-05 20:02:10 +01:00
std::unique_ptr<lcScene> mScene;
std::unique_ptr<lcViewSphere> mViewSphere;
2020-12-05 20:02:10 +01:00
2020-12-06 19:52:57 +01:00
lcModel* mModel = nullptr;
lcPiece* mActiveSubmodelInstance = nullptr;
lcMatrix44 mActiveSubmodelTransform;
2020-12-04 21:49:01 +01:00
lcCamera* mCamera = nullptr;
2020-12-13 21:05:54 +01:00
QGLWidget* mWidget = nullptr;
int mWidth = 1;
int mHeight = 1;
2020-12-04 20:40:53 +01:00
bool mDeleteContext = true;
lcViewType mViewType;
2020-12-12 03:01:04 +01:00
static lcGLWidget* mLastFocusedView;
2020-12-16 02:19:32 +01:00
static std::vector<lcGLWidget*> mViews;
2013-08-09 06:57:18 +02:00
};