leocad/common/view.h

160 lines
3.8 KiB
C
Raw Normal View History

2011-09-07 23:06:51 +02:00
#ifndef _VIEW_H_
#define _VIEW_H_
2013-08-09 06:57:18 +02:00
#include "lc_glwidget.h"
2014-05-03 23:16:48 +02:00
#include "camera.h"
2017-04-02 01:53:54 +02:00
#include "lc_scene.h"
2011-09-07 23:06:51 +02:00
enum lcTrackButton
{
LC_TRACKBUTTON_NONE,
LC_TRACKBUTTON_LEFT,
LC_TRACKBUTTON_MIDDLE,
LC_TRACKBUTTON_RIGHT
};
enum lcTrackTool
{
LC_TRACKTOOL_NONE,
LC_TRACKTOOL_INSERT,
LC_TRACKTOOL_POINTLIGHT,
LC_TRACKTOOL_SPOTLIGHT,
LC_TRACKTOOL_CAMERA,
LC_TRACKTOOL_SELECT,
LC_TRACKTOOL_MOVE_X,
LC_TRACKTOOL_MOVE_Y,
LC_TRACKTOOL_MOVE_Z,
LC_TRACKTOOL_MOVE_XY,
LC_TRACKTOOL_MOVE_XZ,
LC_TRACKTOOL_MOVE_YZ,
LC_TRACKTOOL_MOVE_XYZ,
LC_TRACKTOOL_ROTATE_X,
LC_TRACKTOOL_ROTATE_Y,
LC_TRACKTOOL_ROTATE_Z,
LC_TRACKTOOL_ROTATE_XY,
LC_TRACKTOOL_ROTATE_XYZ,
LC_TRACKTOOL_SCALE_PLUS,
LC_TRACKTOOL_SCALE_MINUS,
LC_TRACKTOOL_ERASER,
LC_TRACKTOOL_PAINT,
LC_TRACKTOOL_ZOOM,
LC_TRACKTOOL_PAN,
LC_TRACKTOOL_ORBIT_X,
LC_TRACKTOOL_ORBIT_Y,
LC_TRACKTOOL_ORBIT_XY,
LC_TRACKTOOL_ROLL,
LC_TRACKTOOL_ZOOM_REGION
};
2014-05-27 00:58:08 +02:00
enum lcDragState
{
LC_DRAGSTATE_NONE,
LC_DRAGSTATE_PIECE
// LC_DRAGSTATE_COLOR
};
2013-08-09 06:57:18 +02:00
class View : public lcGLWidget
2011-09-07 23:06:51 +02:00
{
public:
View(lcModel* Model);
2012-02-05 03:50:57 +01:00
virtual ~View();
static void CreateResources(lcContext* Context);
static void DestroyResources(lcContext* Context);
2012-02-05 03:50:57 +01:00
void OnDraw();
void OnInitialUpdate();
2013-08-09 06:57:18 +02:00
void OnUpdateCursor();
void OnLeftButtonDown();
void OnLeftButtonUp();
void OnLeftButtonDoubleClick();
void OnMiddleButtonDown();
void OnMiddleButtonUp();
void OnRightButtonDown();
void OnRightButtonUp();
void OnBackButtonUp();
void OnForwardButtonUp();
2013-08-09 06:57:18 +02:00
void OnMouseMove();
void OnMouseWheel(float Direction);
2011-09-07 23:06:51 +02:00
2014-11-29 03:55:58 +01:00
void CancelTrackingOrClearSelection();
2014-05-27 00:58:08 +02:00
void BeginPieceDrag();
void EndPieceDrag(bool Accept);
void SetProjection(bool Ortho);
void LookAt();
2014-11-08 02:05:17 +01:00
void ZoomExtents();
2014-05-27 00:58:08 +02:00
void RemoveCamera();
2014-11-08 02:05:17 +01:00
void SetCamera(lcCamera* Camera, bool ForceCopy);
void SetCameraIndex(int Index);
2014-11-08 02:05:17 +01:00
void SetViewpoint(lcViewpoint Viewpoint);
2012-08-20 06:05:56 +02:00
void SetDefaultCamera();
2014-05-03 03:22:24 +02:00
lcMatrix44 GetProjectionMatrix() const;
LC_CURSOR_TYPE GetCursor() const;
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;
lcMatrix44 GetPieceInsertPosition() const;
void GetRayUnderPointer(lcVector3& Start, lcVector3& End) const;
2014-05-03 18:59:57 +02:00
lcObjectSection FindObjectUnderPointer(bool PiecesOnly) 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
lcModel* mModel;
lcCamera* mCamera;
2013-12-17 03:43:16 +01:00
2014-05-03 08:08:52 +02:00
lcVector3 ProjectPoint(const lcVector3& Point) const
{
int Viewport[4] = { 0, 0, mWidth, mHeight };
return lcProjectPoint(Point, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
}
lcVector3 UnprojectPoint(const lcVector3& Point) const
{
int Viewport[4] = { 0, 0, mWidth, mHeight };
return lcUnprojectPoint(Point, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
}
void UnprojectPoints(lcVector3* Points, int NumPoints) const
{
int Viewport[4] = { 0, 0, mWidth, mHeight };
lcUnprojectPoints(Points, NumPoints, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
}
protected:
static void CreateSelectMoveOverlayMesh(lcContext* Context);
void DrawSelectMoveOverlay();
void DrawRotateOverlay();
void DrawSelectZoomRegionOverlay();
void DrawRotateViewOverlay();
void DrawGrid();
void DrawAxes();
void DrawViewport();
void UpdateTrackTool();
bool IsTrackToolAllowed(lcTrackTool TrackTool, lcuint32 AllowedTransforms) const;
lcTool GetCurrentTool() const;
2016-04-23 02:17:33 +02:00
lcTrackTool GetOverrideTrackTool(Qt::MouseButton Button) const;
float GetOverlayScale() const;
void StartTracking(lcTrackButton TrackButton);
void StopTracking(bool Accept);
void OnButtonDown(lcTrackButton TrackButton);
2015-02-08 19:54:51 +01:00
lcScene mScene;
2014-05-27 00:58:08 +02:00
lcDragState mDragState;
lcTrackButton mTrackButton;
lcTrackTool mTrackTool;
bool mTrackUpdated;
int mMouseDownX;
int mMouseDownY;
2015-04-14 06:14:10 +02:00
lcVertexBuffer mGridBuffer;
2015-04-14 06:14:10 +02:00
int mGridSettings[7];
static lcVertexBuffer mRotateMoveVertexBuffer;
static lcIndexBuffer mRotateMoveIndexBuffer;
2011-09-07 23:06:51 +02:00
};
#endif // _VIEW_H_