Added scoped enums.

This commit is contained in:
Leonardo Zide 2020-02-15 11:36:06 -08:00
parent e5d06a29a2
commit e9c38e4f39
4 changed files with 154 additions and 149 deletions

View file

@ -2,29 +2,29 @@
#include "lc_context.h" #include "lc_context.h"
enum LC_CURSOR_TYPE enum class lcCursor
{ {
LC_CURSOR_DEFAULT, Default,
LC_CURSOR_BRICK, Brick,
LC_CURSOR_LIGHT, Light,
LC_CURSOR_SPOTLIGHT, Spotlight,
LC_CURSOR_CAMERA, Camera,
LC_CURSOR_SELECT, Select,
LC_CURSOR_SELECT_ADD, SelectAdd,
LC_CURSOR_SELECT_REMOVE, SelectRemove,
LC_CURSOR_MOVE, Move,
LC_CURSOR_ROTATE, Rotate,
LC_CURSOR_ROTATEX, RotateX,
LC_CURSOR_ROTATEY, RotateY,
LC_CURSOR_DELETE, Delete,
LC_CURSOR_PAINT, Paint,
LC_CURSOR_COLOR_PICKER, ColorPicker,
LC_CURSOR_ZOOM, Zoom,
LC_CURSOR_ZOOM_REGION, ZoomRegion,
LC_CURSOR_PAN, Pan,
LC_CURSOR_ROLL, Roll,
LC_CURSOR_ROTATE_VIEW, RotateView,
LC_CURSOR_COUNT Count
}; };
struct lcInputState struct lcInputState
@ -39,7 +39,7 @@ class lcGLWidget
public: public:
lcGLWidget() lcGLWidget()
{ {
mCursorType = LC_CURSOR_DEFAULT; mCursor = lcCursor::Default;
mWidget = nullptr; mWidget = nullptr;
mInputState.x = 0; mInputState.x = 0;
mInputState.y = 0; mInputState.y = 0;
@ -67,7 +67,7 @@ public:
void MakeCurrent(); void MakeCurrent();
void Redraw(); void Redraw();
void SetCursor(LC_CURSOR_TYPE Cursor); void SetCursor(lcCursor Cursor);
virtual void OnDraw() { } virtual void OnDraw() { }
virtual void OnInitialUpdate() { } virtual void OnInitialUpdate() { }
@ -89,9 +89,8 @@ public:
lcInputState mInputState; lcInputState mInputState;
int mWidth; int mWidth;
int mHeight; int mHeight;
int mCursorType; lcCursor mCursor;
void* mWidget; void* mWidget;
lcContext* mContext; lcContext* mContext;
bool mDeleteContext; bool mDeleteContext;
}; };

View file

@ -21,8 +21,8 @@ View::View(lcModel* Model)
mHighlight = false; mHighlight = false;
memset(mGridSettings, 0, sizeof(mGridSettings)); memset(mGridSettings, 0, sizeof(mGridSettings));
mDragState = lcDragState::NONE; mDragState = lcDragState::None;
mTrackButton = LC_TRACKBUTTON_NONE; mTrackButton = lcTrackButton::None;
mTrackTool = LC_TRACKTOOL_NONE; mTrackTool = LC_TRACKTOOL_NONE;
mTrackToolFromOverlay = false; mTrackToolFromOverlay = false;
@ -444,52 +444,57 @@ lcMatrix44 View::GetTileProjectionMatrix(int CurrentRow, int CurrentColumn, int
return lcMatrix44Frustum(Left, Right, Bottom, Top, Near, Far); return lcMatrix44Frustum(Left, Right, Bottom, Top, Near, Far);
} }
LC_CURSOR_TYPE View::GetCursor() const lcCursor View::GetCursor() const
{ {
if (mTrackTool == LC_TRACKTOOL_SELECT) if (mTrackTool == LC_TRACKTOOL_SELECT)
{ {
if (mInputState.Modifiers & Qt::ControlModifier) if (mInputState.Modifiers & Qt::ControlModifier)
return LC_CURSOR_SELECT_ADD; return lcCursor::SelectAdd;
if (mInputState.Modifiers & Qt::ShiftModifier) if (mInputState.Modifiers & Qt::ShiftModifier)
return LC_CURSOR_SELECT_REMOVE; return lcCursor::SelectRemove;
} }
const LC_CURSOR_TYPE CursorFromTrackTool[] = const lcCursor CursorFromTrackTool[] =
{ {
LC_CURSOR_SELECT, // LC_TRACKTOOL_NONE lcCursor::Select, // LC_TRACKTOOL_NONE
LC_CURSOR_BRICK, // LC_TRACKTOOL_INSERT lcCursor::Brick, // LC_TRACKTOOL_INSERT
LC_CURSOR_LIGHT, // LC_TRACKTOOL_POINTLIGHT lcCursor::Light, // LC_TRACKTOOL_POINTLIGHT
LC_CURSOR_SPOTLIGHT, // LC_TRACKTOOL_SPOTLIGHT lcCursor::Spotlight, // LC_TRACKTOOL_SPOTLIGHT
LC_CURSOR_CAMERA, // LC_TRACKTOOL_CAMERA lcCursor::Camera, // LC_TRACKTOOL_CAMERA
LC_CURSOR_SELECT, // LC_TRACKTOOL_SELECT lcCursor::Select, // LC_TRACKTOOL_SELECT
LC_CURSOR_MOVE, // LC_TRACKTOOL_MOVE_X lcCursor::Move, // LC_TRACKTOOL_MOVE_X
LC_CURSOR_MOVE, // LC_TRACKTOOL_MOVE_Y lcCursor::Move, // LC_TRACKTOOL_MOVE_Y
LC_CURSOR_MOVE, // LC_TRACKTOOL_MOVE_Z lcCursor::Move, // LC_TRACKTOOL_MOVE_Z
LC_CURSOR_MOVE, // LC_TRACKTOOL_MOVE_XY lcCursor::Move, // LC_TRACKTOOL_MOVE_XY
LC_CURSOR_MOVE, // LC_TRACKTOOL_MOVE_XZ lcCursor::Move, // LC_TRACKTOOL_MOVE_XZ
LC_CURSOR_MOVE, // LC_TRACKTOOL_MOVE_YZ lcCursor::Move, // LC_TRACKTOOL_MOVE_YZ
LC_CURSOR_MOVE, // LC_TRACKTOOL_MOVE_XYZ lcCursor::Move, // LC_TRACKTOOL_MOVE_XYZ
LC_CURSOR_ROTATE, // LC_TRACKTOOL_ROTATE_X lcCursor::Rotate, // LC_TRACKTOOL_ROTATE_X
LC_CURSOR_ROTATE, // LC_TRACKTOOL_ROTATE_Y lcCursor::Rotate, // LC_TRACKTOOL_ROTATE_Y
LC_CURSOR_ROTATE, // LC_TRACKTOOL_ROTATE_Z lcCursor::Rotate, // LC_TRACKTOOL_ROTATE_Z
LC_CURSOR_ROTATE, // LC_TRACKTOOL_ROTATE_XY lcCursor::Rotate, // LC_TRACKTOOL_ROTATE_XY
LC_CURSOR_ROTATE, // LC_TRACKTOOL_ROTATE_XYZ lcCursor::Rotate, // LC_TRACKTOOL_ROTATE_XYZ
LC_CURSOR_MOVE, // LC_TRACKTOOL_SCALE_PLUS lcCursor::Move, // LC_TRACKTOOL_SCALE_PLUS
LC_CURSOR_MOVE, // LC_TRACKTOOL_SCALE_MINUS lcCursor::Move, // LC_TRACKTOOL_SCALE_MINUS
LC_CURSOR_DELETE, // LC_TRACKTOOL_ERASER lcCursor::Delete, // LC_TRACKTOOL_ERASER
LC_CURSOR_PAINT, // LC_TRACKTOOL_PAINT lcCursor::Paint, // LC_TRACKTOOL_PAINT
LC_CURSOR_COLOR_PICKER, // LC_TRACKTOOL_COLOR_PICKER lcCursor::ColorPicker, // LC_TRACKTOOL_COLOR_PICKER
LC_CURSOR_ZOOM, // LC_TRACKTOOL_ZOOM lcCursor::Zoom, // LC_TRACKTOOL_ZOOM
LC_CURSOR_PAN, // LC_TRACKTOOL_PAN lcCursor::Pan, // LC_TRACKTOOL_PAN
LC_CURSOR_ROTATEX, // LC_TRACKTOOL_ORBIT_X lcCursor::RotateX, // LC_TRACKTOOL_ORBIT_X
LC_CURSOR_ROTATEY, // LC_TRACKTOOL_ORBIT_Y lcCursor::RotateY, // LC_TRACKTOOL_ORBIT_Y
LC_CURSOR_ROTATE_VIEW, // LC_TRACKTOOL_ORBIT_XY lcCursor::RotateView, // LC_TRACKTOOL_ORBIT_XY
LC_CURSOR_ROLL, // LC_TRACKTOOL_ROLL lcCursor::Roll, // LC_TRACKTOOL_ROLL
LC_CURSOR_ZOOM_REGION // LC_TRACKTOOL_ZOOM_REGION lcCursor::ZoomRegion // LC_TRACKTOOL_ZOOM_REGION
}; };
return CursorFromTrackTool[mTrackTool]; static_assert(LC_ARRAY_COUNT(CursorFromTrackTool) == LC_TRACKTOOL_COUNT, "Array size mismatch.");
if (mTrackTool >= 0 && mTrackTool < LC_ARRAY_COUNT(CursorFromTrackTool))
return CursorFromTrackTool[mTrackTool];
return lcCursor::Select;
} }
void View::ShowContextMenu() const void View::ShowContextMenu() const
@ -930,15 +935,15 @@ void View::OnDraw()
lcTool Tool = gMainWindow->GetTool(); lcTool Tool = gMainWindow->GetTool();
lcModel* ActiveModel = GetActiveModel(); lcModel* ActiveModel = GetActiveModel();
if ((Tool == LC_TOOL_SELECT || Tool == LC_TOOL_MOVE) && mTrackButton == LC_TRACKBUTTON_NONE && ActiveModel->AnyObjectsSelected()) if ((Tool == LC_TOOL_SELECT || Tool == LC_TOOL_MOVE) && mTrackButton == lcTrackButton::None && ActiveModel->AnyObjectsSelected())
DrawSelectMoveOverlay(); DrawSelectMoveOverlay();
else if (GetCurrentTool() == LC_TOOL_MOVE && mTrackButton != LC_TRACKBUTTON_NONE) else if (GetCurrentTool() == LC_TOOL_MOVE && mTrackButton != lcTrackButton::None)
DrawSelectMoveOverlay(); DrawSelectMoveOverlay();
else if ((Tool == LC_TOOL_ROTATE || (Tool == LC_TOOL_SELECT && mTrackButton != LC_TRACKBUTTON_NONE && mTrackTool >= LC_TRACKTOOL_ROTATE_X && mTrackTool <= LC_TRACKTOOL_ROTATE_XYZ)) && ActiveModel->AnyPiecesSelected()) else if ((Tool == LC_TOOL_ROTATE || (Tool == LC_TOOL_SELECT && mTrackButton != lcTrackButton::None && mTrackTool >= LC_TRACKTOOL_ROTATE_X && mTrackTool <= LC_TRACKTOOL_ROTATE_XYZ)) && ActiveModel->AnyPiecesSelected())
DrawRotateOverlay(); DrawRotateOverlay();
else if ((mTrackTool == LC_TRACKTOOL_SELECT || mTrackTool == LC_TRACKTOOL_ZOOM_REGION) && mTrackButton == LC_TRACKBUTTON_LEFT) else if ((mTrackTool == LC_TRACKTOOL_SELECT || mTrackTool == LC_TRACKTOOL_ZOOM_REGION) && mTrackButton == lcTrackButton::Left)
DrawSelectZoomRegionOverlay(); DrawSelectZoomRegionOverlay();
else if (Tool == LC_TOOL_ROTATE_VIEW && mTrackButton == LC_TRACKBUTTON_NONE) else if (Tool == LC_TOOL_ROTATE_VIEW && mTrackButton == lcTrackButton::None)
DrawRotateViewOverlay(); DrawRotateViewOverlay();
mViewSphere.Draw(); mViewSphere.Draw();
@ -979,7 +984,7 @@ void View::DrawSelectMoveOverlay()
lcObject* Focus = ActiveModel->GetFocusObject(); lcObject* Focus = ActiveModel->GetFocusObject();
quint32 AllowedTransforms = Focus ? Focus->GetAllowedTransforms() : LC_OBJECT_TRANSFORM_MOVE_X | LC_OBJECT_TRANSFORM_MOVE_Y | LC_OBJECT_TRANSFORM_MOVE_Z | LC_OBJECT_TRANSFORM_ROTATE_X | LC_OBJECT_TRANSFORM_ROTATE_Y | LC_OBJECT_TRANSFORM_ROTATE_Z; quint32 AllowedTransforms = Focus ? Focus->GetAllowedTransforms() : LC_OBJECT_TRANSFORM_MOVE_X | LC_OBJECT_TRANSFORM_MOVE_Y | LC_OBJECT_TRANSFORM_MOVE_Z | LC_OBJECT_TRANSFORM_ROTATE_X | LC_OBJECT_TRANSFORM_ROTATE_Y | LC_OBJECT_TRANSFORM_ROTATE_Z;
if (mTrackButton == LC_TRACKBUTTON_NONE || (mTrackTool >= LC_TRACKTOOL_MOVE_X && mTrackTool <= LC_TRACKTOOL_MOVE_XYZ)) if (mTrackButton == lcTrackButton::None || (mTrackTool >= LC_TRACKTOOL_MOVE_X && mTrackTool <= LC_TRACKTOOL_MOVE_XYZ))
{ {
if (AllowedTransforms & LC_OBJECT_TRANSFORM_MOVE_X) if (AllowedTransforms & LC_OBJECT_TRANSFORM_MOVE_X)
{ {
@ -988,7 +993,7 @@ void View::DrawSelectMoveOverlay()
mContext->SetColor(0.8f, 0.8f, 0.0f, 1.0f); mContext->SetColor(0.8f, 0.8f, 0.0f, 1.0f);
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0); mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
} }
else if (mTrackButton == LC_TRACKBUTTON_NONE) else if (mTrackButton == lcTrackButton::None)
{ {
mContext->SetColor(0.8f, 0.0f, 0.0f, 1.0f); mContext->SetColor(0.8f, 0.0f, 0.0f, 1.0f);
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0); mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
@ -1002,7 +1007,7 @@ void View::DrawSelectMoveOverlay()
mContext->SetColor(0.8f, 0.8f, 0.0f, 1.0f); mContext->SetColor(0.8f, 0.8f, 0.0f, 1.0f);
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 36 * 2); mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 36 * 2);
} }
else if (mTrackButton == LC_TRACKBUTTON_NONE) else if (mTrackButton == lcTrackButton::None)
{ {
mContext->SetColor(0.0f, 0.8f, 0.0f, 1.0f); mContext->SetColor(0.0f, 0.8f, 0.0f, 1.0f);
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 36 * 2); mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 36 * 2);
@ -1016,7 +1021,7 @@ void View::DrawSelectMoveOverlay()
mContext->SetColor(0.8f, 0.8f, 0.0f, 1.0f); mContext->SetColor(0.8f, 0.8f, 0.0f, 1.0f);
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 72 * 2); mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 72 * 2);
} }
else if (mTrackButton == LC_TRACKBUTTON_NONE) else if (mTrackButton == lcTrackButton::None)
{ {
mContext->SetColor(0.0f, 0.0f, 0.8f, 1.0f); mContext->SetColor(0.0f, 0.0f, 0.8f, 1.0f);
mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 72 * 2); mContext->DrawIndexedPrimitives(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 72 * 2);
@ -1024,7 +1029,7 @@ void View::DrawSelectMoveOverlay()
} }
} }
if (gMainWindow->GetTool() == LC_TOOL_SELECT && mTrackButton == LC_TRACKBUTTON_NONE && AnyPiecesSelected) if (gMainWindow->GetTool() == LC_TOOL_SELECT && mTrackButton == lcTrackButton::None && AnyPiecesSelected)
{ {
if (AllowedTransforms & LC_OBJECT_TRANSFORM_ROTATE_X) if (AllowedTransforms & LC_OBJECT_TRANSFORM_ROTATE_X)
{ {
@ -1158,7 +1163,7 @@ void View::DrawRotateOverlay()
bool HasAngle = false; bool HasAngle = false;
// Draw a disc showing the rotation amount. // Draw a disc showing the rotation amount.
if (MouseToolDistance.LengthSquared() != 0.0f && (mTrackButton != LC_TRACKBUTTON_NONE)) if (MouseToolDistance.LengthSquared() != 0.0f && (mTrackButton != lcTrackButton::None))
{ {
lcVector4 Rotation; lcVector4 Rotation;
float Angle, Step; float Angle, Step;
@ -1252,7 +1257,7 @@ void View::DrawRotateOverlay()
} }
// Draw the circles. // Draw the circles.
if (gMainWindow->GetTool() == LC_TOOL_ROTATE && !HasAngle && mTrackButton == LC_TRACKBUTTON_NONE) if (gMainWindow->GetTool() == LC_TOOL_ROTATE && !HasAngle && mTrackButton == lcTrackButton::None)
{ {
lcMatrix44 Mat = lcMatrix44AffineInverse(mCamera->mWorldView); lcMatrix44 Mat = lcMatrix44AffineInverse(mCamera->mWorldView);
Mat.SetTranslation(OverlayCenter); Mat.SetTranslation(OverlayCenter);
@ -1296,7 +1301,7 @@ void View::DrawRotateOverlay()
} }
else else
{ {
if (gMainWindow->GetTool() != LC_TOOL_ROTATE || HasAngle || mTrackButton != LC_TRACKBUTTON_NONE) if (gMainWindow->GetTool() != LC_TOOL_ROTATE || HasAngle || mTrackButton != lcTrackButton::None)
continue; continue;
switch (i) switch (i)
@ -1338,7 +1343,7 @@ void View::DrawRotateOverlay()
break; break;
} }
if (gMainWindow->GetTool() != LC_TOOL_ROTATE || HasAngle || mTrackButton != LC_TRACKBUTTON_NONE || lcDot(ViewDir, v1 + v2) <= 0.0f) if (gMainWindow->GetTool() != LC_TOOL_ROTATE || HasAngle || mTrackButton != lcTrackButton::None || lcDot(ViewDir, v1 + v2) <= 0.0f)
{ {
Verts[NumVerts++] = v1 * (OverlayRotateRadius * OverlayScale); Verts[NumVerts++] = v1 * (OverlayRotateRadius * OverlayScale);
Verts[NumVerts++] = v2 * (OverlayRotateRadius * OverlayScale); Verts[NumVerts++] = v2 * (OverlayRotateRadius * OverlayScale);
@ -1352,7 +1357,7 @@ void View::DrawRotateOverlay()
} }
// Draw tangent vector. // Draw tangent vector.
if (mTrackButton != LC_TRACKBUTTON_NONE && ((mTrackTool == LC_TRACKTOOL_ROTATE_X) || (mTrackTool == LC_TRACKTOOL_ROTATE_Y) || (mTrackTool == LC_TRACKTOOL_ROTATE_Z))) if (mTrackButton != lcTrackButton::None && ((mTrackTool == LC_TRACKTOOL_ROTATE_X) || (mTrackTool == LC_TRACKTOOL_ROTATE_Y) || (mTrackTool == LC_TRACKTOOL_ROTATE_Z)))
{ {
const float OverlayRotateArrowSize = 1.5f; const float OverlayRotateArrowSize = 1.5f;
const float OverlayRotateArrowCapSize = 0.25f; const float OverlayRotateArrowCapSize = 0.25f;
@ -1975,23 +1980,23 @@ void View::EndDrag(bool Accept)
switch (mDragState) switch (mDragState)
{ {
case lcDragState::NONE: case lcDragState::None:
break; break;
case lcDragState::PIECE: case lcDragState::Piece:
{ {
PieceInfo* Info = gMainWindow->GetCurrentPieceInfo(); PieceInfo* Info = gMainWindow->GetCurrentPieceInfo();
if (Info) if (Info)
ActiveModel->InsertPieceToolClicked(GetPieceInsertPosition(false, Info)); ActiveModel->InsertPieceToolClicked(GetPieceInsertPosition(false, Info));
} break; } break;
case lcDragState::COLOR: case lcDragState::Color:
ActiveModel->PaintToolClicked(FindObjectUnderPointer(true, false).Object); ActiveModel->PaintToolClicked(FindObjectUnderPointer(true, false).Object);
break; break;
} }
} }
mDragState = lcDragState::NONE; mDragState = lcDragState::None;
UpdateTrackTool(); UpdateTrackTool();
gMainWindow->UpdateAllViews(); gMainWindow->UpdateAllViews();
} }
@ -2474,15 +2479,15 @@ void View::UpdateTrackTool()
switch (mDragState) switch (mDragState)
{ {
case lcDragState::NONE: case lcDragState::None:
break; break;
case lcDragState::PIECE: case lcDragState::Piece:
NewTrackTool = LC_TRACKTOOL_INSERT; NewTrackTool = LC_TRACKTOOL_INSERT;
Redraw = true; Redraw = true;
break; break;
case lcDragState::COLOR: case lcDragState::Color:
NewTrackTool = LC_TRACKTOOL_PAINT; NewTrackTool = LC_TRACKTOOL_PAINT;
break; break;
} }
@ -2568,7 +2573,7 @@ void View::StartOrbitTracking()
{ {
mTrackTool = LC_TRACKTOOL_ORBIT_XY; mTrackTool = LC_TRACKTOOL_ORBIT_XY;
OnUpdateCursor(); OnUpdateCursor();
OnButtonDown(LC_TRACKBUTTON_LEFT); OnButtonDown(lcTrackButton::Left);
} }
void View::StartTracking(lcTrackButton TrackButton) void View::StartTracking(lcTrackButton TrackButton)
@ -2634,7 +2639,7 @@ void View::StartTracking(lcTrackButton TrackButton)
void View::StopTracking(bool Accept) void View::StopTracking(bool Accept)
{ {
if (mTrackButton == LC_TRACKBUTTON_NONE) if (mTrackButton == lcTrackButton::None)
return; return;
lcTool Tool = GetCurrentTool(); lcTool Tool = GetCurrentTool();
@ -2717,14 +2722,14 @@ void View::StopTracking(bool Accept)
break; break;
} }
mTrackButton = LC_TRACKBUTTON_NONE; mTrackButton = lcTrackButton::None;
UpdateTrackTool(); UpdateTrackTool();
gMainWindow->UpdateAllViews(); gMainWindow->UpdateAllViews();
} }
void View::CancelTrackingOrClearSelection() void View::CancelTrackingOrClearSelection()
{ {
if (mTrackButton != LC_TRACKBUTTON_NONE) if (mTrackButton != lcTrackButton::None)
StopTracking(false); StopTracking(false);
else else
{ {
@ -2842,7 +2847,7 @@ void View::OnButtonDown(lcTrackButton TrackButton)
void View::OnLeftButtonDown() void View::OnLeftButtonDown()
{ {
if (mTrackButton != LC_TRACKBUTTON_NONE) if (mTrackButton != lcTrackButton::None)
{ {
StopTracking(false); StopTracking(false);
return; return;
@ -2861,12 +2866,12 @@ void View::OnLeftButtonDown()
OnUpdateCursor(); OnUpdateCursor();
} }
OnButtonDown(LC_TRACKBUTTON_LEFT); OnButtonDown(lcTrackButton::Left);
} }
void View::OnLeftButtonUp() void View::OnLeftButtonUp()
{ {
StopTracking(mTrackButton == LC_TRACKBUTTON_LEFT); StopTracking(mTrackButton == lcTrackButton::Left);
if (mViewSphere.OnLeftButtonUp()) if (mViewSphere.OnLeftButtonUp())
return; return;
@ -2889,7 +2894,7 @@ void View::OnLeftButtonDoubleClick()
void View::OnMiddleButtonDown() void View::OnMiddleButtonDown()
{ {
if (mTrackButton != LC_TRACKBUTTON_NONE) if (mTrackButton != lcTrackButton::None)
{ {
StopTracking(false); StopTracking(false);
return; return;
@ -2905,17 +2910,17 @@ void View::OnMiddleButtonDown()
OnUpdateCursor(); OnUpdateCursor();
} }
#endif #endif
OnButtonDown(LC_TRACKBUTTON_MIDDLE); OnButtonDown(lcTrackButton::Middle);
} }
void View::OnMiddleButtonUp() void View::OnMiddleButtonUp()
{ {
StopTracking(mTrackButton == LC_TRACKBUTTON_MIDDLE); StopTracking(mTrackButton == lcTrackButton::Middle);
} }
void View::OnRightButtonDown() void View::OnRightButtonDown()
{ {
if (mTrackButton != LC_TRACKBUTTON_NONE) if (mTrackButton != lcTrackButton::None)
{ {
StopTracking(false); StopTracking(false);
return; return;
@ -2931,15 +2936,15 @@ void View::OnRightButtonDown()
OnUpdateCursor(); OnUpdateCursor();
} }
OnButtonDown(LC_TRACKBUTTON_RIGHT); OnButtonDown(lcTrackButton::Right);
} }
void View::OnRightButtonUp() void View::OnRightButtonUp()
{ {
bool ShowMenu = mTrackButton == LC_TRACKBUTTON_NONE || !mTrackUpdated; bool ShowMenu = mTrackButton == lcTrackButton::None || !mTrackUpdated;
if (mTrackButton != LC_TRACKBUTTON_NONE) if (mTrackButton != lcTrackButton::None)
StopTracking(mTrackButton == LC_TRACKBUTTON_RIGHT); StopTracking(mTrackButton == lcTrackButton::Right);
if (ShowMenu) if (ShowMenu)
ShowContextMenu(); ShowContextMenu();
@ -2962,7 +2967,7 @@ void View::OnMouseMove()
if (!ActiveModel) if (!ActiveModel)
return; return;
if (mTrackButton == LC_TRACKBUTTON_NONE) if (mTrackButton == lcTrackButton::None)
{ {
if (mViewSphere.OnMouseMove()) if (mViewSphere.OnMouseMove())
{ {
@ -3056,7 +3061,7 @@ void View::OnMouseMove()
lcVector3 Distance = Intersection - MoveStart; lcVector3 Distance = Intersection - MoveStart;
Distance = lcMul(Distance, lcMatrix33AffineInverse(RelativeRotation)); Distance = lcMul(Distance, lcMatrix33AffineInverse(RelativeRotation));
ActiveModel->UpdateMoveTool(Distance, mTrackButton != LC_TRACKBUTTON_LEFT); ActiveModel->UpdateMoveTool(Distance, mTrackButton != lcTrackButton::Left);
} }
else if (mTrackTool == LC_TRACKTOOL_MOVE_XY || mTrackTool == LC_TRACKTOOL_MOVE_XZ || mTrackTool == LC_TRACKTOOL_MOVE_YZ) else if (mTrackTool == LC_TRACKTOOL_MOVE_XY || mTrackTool == LC_TRACKTOOL_MOVE_XZ || mTrackTool == LC_TRACKTOOL_MOVE_YZ)
{ {
@ -3081,7 +3086,7 @@ void View::OnMouseMove()
{ {
lcVector3 Distance = Intersection - MoveStart; lcVector3 Distance = Intersection - MoveStart;
Distance = lcMul(Distance, lcMatrix33AffineInverse(RelativeRotation)); Distance = lcMul(Distance, lcMatrix33AffineInverse(RelativeRotation));
ActiveModel->UpdateMoveTool(Distance, mTrackButton != LC_TRACKBUTTON_LEFT); ActiveModel->UpdateMoveTool(Distance, mTrackButton != lcTrackButton::Left);
} }
} }
} }
@ -3089,7 +3094,7 @@ void View::OnMouseMove()
{ {
lcMatrix44 NewPosition = GetPieceInsertPosition(true, mMouseDownPiece); lcMatrix44 NewPosition = GetPieceInsertPosition(true, mMouseDownPiece);
lcVector3 Distance = NewPosition.GetTranslation() - mMouseDownPosition; lcVector3 Distance = NewPosition.GetTranslation() - mMouseDownPosition;
ActiveModel->UpdateMoveTool(Distance, mTrackButton != LC_TRACKBUTTON_LEFT); ActiveModel->UpdateMoveTool(Distance, mTrackButton != lcTrackButton::Left);
} }
else if (mTrackTool == LC_TRACKTOOL_SCALE_PLUS || mTrackTool == LC_TRACKTOOL_SCALE_MINUS) else if (mTrackTool == LC_TRACKTOOL_SCALE_PLUS || mTrackTool == LC_TRACKTOOL_SCALE_MINUS)
{ {
@ -3142,7 +3147,7 @@ void View::OnMouseMove()
if (lcLineSegmentPlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane)) if (lcLineSegmentPlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
{ {
lcVector3 Distance = Intersection - MoveStart; lcVector3 Distance = Intersection - MoveStart;
ActiveModel->UpdateMoveTool(Distance, mTrackButton != LC_TRACKBUTTON_LEFT); ActiveModel->UpdateMoveTool(Distance, mTrackButton != lcTrackButton::Left);
} }
} }
} }
@ -3200,7 +3205,7 @@ void View::OnMouseMove()
MoveX *= 36.0f * (float)(mInputState.x - mMouseDownX) * MouseSensitivity; MoveX *= 36.0f * (float)(mInputState.x - mMouseDownX) * MouseSensitivity;
MoveY *= 36.0f * (float)(mInputState.y - mMouseDownY) * MouseSensitivity; MoveY *= 36.0f * (float)(mInputState.y - mMouseDownY) * MouseSensitivity;
ActiveModel->UpdateRotateTool(MoveX + MoveY, mTrackButton != LC_TRACKBUTTON_LEFT); ActiveModel->UpdateRotateTool(MoveX + MoveY, mTrackButton != lcTrackButton::Left);
} }
break; break;
@ -3212,7 +3217,7 @@ void View::OnMouseMove()
lcVector3 MoveX = 36.0f * (float)(mInputState.x - mMouseDownX) * MouseSensitivity * ScreenX; lcVector3 MoveX = 36.0f * (float)(mInputState.x - mMouseDownX) * MouseSensitivity * ScreenX;
lcVector3 MoveY = 36.0f * (float)(mInputState.y - mMouseDownY) * MouseSensitivity * ScreenY; lcVector3 MoveY = 36.0f * (float)(mInputState.y - mMouseDownY) * MouseSensitivity * ScreenY;
ActiveModel->UpdateRotateTool(MoveX + MoveY, mTrackButton != LC_TRACKBUTTON_LEFT); ActiveModel->UpdateRotateTool(MoveX + MoveY, mTrackButton != lcTrackButton::Left);
} }
break; break;
@ -3220,7 +3225,7 @@ void View::OnMouseMove()
{ {
lcVector3 ScreenZ = lcNormalize(mCamera->mTargetPosition - mCamera->mPosition); lcVector3 ScreenZ = lcNormalize(mCamera->mTargetPosition - mCamera->mPosition);
ActiveModel->UpdateRotateTool(36.0f * (float)(mInputState.y - mMouseDownY) * MouseSensitivity * ScreenZ, mTrackButton != LC_TRACKBUTTON_LEFT); ActiveModel->UpdateRotateTool(36.0f * (float)(mInputState.y - mMouseDownY) * MouseSensitivity * ScreenZ, mTrackButton != lcTrackButton::Left);
} }
break; break;

View file

@ -6,12 +6,12 @@
#include "lc_viewsphere.h" #include "lc_viewsphere.h"
#include "lc_commands.h" #include "lc_commands.h"
enum lcTrackButton enum class lcTrackButton
{ {
LC_TRACKBUTTON_NONE, None,
LC_TRACKBUTTON_LEFT, Left,
LC_TRACKBUTTON_MIDDLE, Middle,
LC_TRACKBUTTON_RIGHT Right
}; };
enum lcTrackTool enum lcTrackTool
@ -45,14 +45,15 @@ enum lcTrackTool
LC_TRACKTOOL_ORBIT_Y, LC_TRACKTOOL_ORBIT_Y,
LC_TRACKTOOL_ORBIT_XY, LC_TRACKTOOL_ORBIT_XY,
LC_TRACKTOOL_ROLL, LC_TRACKTOOL_ROLL,
LC_TRACKTOOL_ZOOM_REGION LC_TRACKTOOL_ZOOM_REGION,
LC_TRACKTOOL_COUNT
}; };
enum class lcDragState enum class lcDragState
{ {
NONE, None,
PIECE, Piece,
COLOR Color
}; };
class View : public lcGLWidget class View : public lcGLWidget
@ -101,7 +102,7 @@ public:
bool IsTracking() const bool IsTracking() const
{ {
return mTrackButton != LC_TRACKBUTTON_NONE; return mTrackButton != lcTrackButton::None;
} }
void StartOrbitTracking(); void StartOrbitTracking();
@ -124,7 +125,7 @@ public:
void SetCameraAngles(float Latitude, float Longitude); void SetCameraAngles(float Latitude, float Longitude);
void SetDefaultCamera(); void SetDefaultCamera();
lcMatrix44 GetProjectionMatrix() const; lcMatrix44 GetProjectionMatrix() const;
LC_CURSOR_TYPE GetCursor() const; lcCursor GetCursor() const;
void ShowContextMenu() const; void ShowContextMenu() const;
lcVector3 GetMoveDirection(const lcVector3& Direction) const; lcVector3 GetMoveDirection(const lcVector3& Direction) const;

View file

@ -32,9 +32,9 @@ void lcGLWidget::Redraw()
Widget->mUpdateTimer.start(0); Widget->mUpdateTimer.start(0);
} }
void lcGLWidget::SetCursor(LC_CURSOR_TYPE CursorType) void lcGLWidget::SetCursor(lcCursor CursorType)
{ {
if (mCursorType == CursorType) if (mCursor == CursorType)
return; return;
struct lcCursorInfo struct lcCursorInfo
@ -43,44 +43,44 @@ void lcGLWidget::SetCursor(LC_CURSOR_TYPE CursorType)
const char* Name; const char* Name;
}; };
const lcCursorInfo Cursors[LC_CURSOR_COUNT] = const lcCursorInfo Cursors[] =
{ {
{ 0, 0, "" }, // LC_CURSOR_DEFAULT { 0, 0, "" }, // lcCursor::Default
{ 8, 3, ":/resources/cursor_insert" }, // LC_CURSOR_BRICK { 8, 3, ":/resources/cursor_insert" }, // lcCursor::Brick
{ 15, 15, ":/resources/cursor_light" }, // LC_CURSOR_LIGHT { 15, 15, ":/resources/cursor_light" }, // lcCursor::Light
{ 7, 10, ":/resources/cursor_spotlight" }, // LC_CURSOR_SPOTLIGHT { 7, 10, ":/resources/cursor_spotlight" }, // lcCursor::Spotlight
{ 15, 9, ":/resources/cursor_camera" }, // LC_CURSOR_CAMERA { 15, 9, ":/resources/cursor_camera" }, // lcCursor::Camera
{ 0, 2, ":/resources/cursor_select" }, // LC_CURSOR_SELECT { 0, 2, ":/resources/cursor_select" }, // lcCursor::Select
{ 0, 2, ":/resources/cursor_select_add" }, // LC_CURSOR_SELECT_ADD { 0, 2, ":/resources/cursor_select_add" }, // lcCursor::SelectAdd
{ 0, 2, ":/resources/cursor_select_remove" }, // LC_CURSOR_SELECT_REMOVE { 0, 2, ":/resources/cursor_select_remove" }, // lcCursor::SelectRemove
{ 15, 15, ":/resources/cursor_move" }, // LC_CURSOR_MOVE { 15, 15, ":/resources/cursor_move" }, // lcCursor::Move
{ 15, 15, ":/resources/cursor_rotate" }, // LC_CURSOR_ROTATE { 15, 15, ":/resources/cursor_rotate" }, // lcCursor::Rotate
{ 15, 15, ":/resources/cursor_rotatex" }, // LC_CURSOR_ROTATEX { 15, 15, ":/resources/cursor_rotatex" }, // lcCursor::RotateX
{ 15, 15, ":/resources/cursor_rotatey" }, // LC_CURSOR_ROTATEY { 15, 15, ":/resources/cursor_rotatey" }, // lcCursor::RotateY
{ 0, 10, ":/resources/cursor_delete" }, // LC_CURSOR_DELETE { 0, 10, ":/resources/cursor_delete" }, // lcCursor::Delete
{ 14, 14, ":/resources/cursor_paint" }, // LC_CURSOR_PAINT { 14, 14, ":/resources/cursor_paint" }, // lcCursor::Paint
{ 1, 13, ":/resources/cursor_color_picker" }, // LC_CURSOR_COLOR_PICKER { 1, 13, ":/resources/cursor_color_picker" }, // lcCursor::ColorPicker
{ 15, 15, ":/resources/cursor_zoom" }, // LC_CURSOR_ZOOM { 15, 15, ":/resources/cursor_zoom" }, // lcCursor::Zoom
{ 9, 9, ":/resources/cursor_zoom_region" }, // LC_CURSOR_ZOOM_REGION { 9, 9, ":/resources/cursor_zoom_region" }, // lcCursor::ZoomRegion
{ 15, 15, ":/resources/cursor_pan" }, // LC_CURSOR_PAN { 15, 15, ":/resources/cursor_pan" }, // lcCursor::Pan
{ 15, 15, ":/resources/cursor_roll" }, // LC_CURSOR_ROLL { 15, 15, ":/resources/cursor_roll" }, // lcCursor::Roll
{ 15, 15, ":/resources/cursor_rotate_view" }, // LC_CURSOR_ROTATE_VIEW { 15, 15, ":/resources/cursor_rotate_view" }, // lcCursor::RotateView
}; };
static_assert(LC_ARRAY_COUNT(Cursors) == LC_CURSOR_COUNT, "Array size mismatch"); static_assert(LC_ARRAY_COUNT(Cursors) == static_cast<int>(lcCursor::Count), "Array size mismatch");
QGLWidget* widget = (QGLWidget*)mWidget; QGLWidget* widget = (QGLWidget*)mWidget;
if (CursorType != LC_CURSOR_DEFAULT && CursorType < LC_CURSOR_COUNT) if (CursorType != lcCursor::Default && CursorType < lcCursor::Count)
{ {
const lcCursorInfo& Cursor = Cursors[CursorType]; const lcCursorInfo& Cursor = Cursors[static_cast<int>(CursorType)];
widget->setCursor(QCursor(QPixmap(Cursor.Name), Cursor.x, Cursor.y)); widget->setCursor(QCursor(QPixmap(Cursor.Name), Cursor.x, Cursor.y));
mCursorType = CursorType; mCursor = CursorType;
} }
else else
{ {
widget->unsetCursor(); widget->unsetCursor();
mCursorType = LC_CURSOR_DEFAULT; mCursor = lcCursor::Default;
} }
} }
@ -339,12 +339,12 @@ void lcQGLWidget::dragEnterEvent(QDragEnterEvent* DragEnterEvent)
if (MimeData->hasFormat("application/vnd.leocad-part")) if (MimeData->hasFormat("application/vnd.leocad-part"))
{ {
DragEnterEvent->acceptProposedAction(); DragEnterEvent->acceptProposedAction();
((View*)widget)->BeginDrag(lcDragState::PIECE); ((View*)widget)->BeginDrag(lcDragState::Piece);
} }
else if (MimeData->hasFormat("application/vnd.leocad-color")) else if (MimeData->hasFormat("application/vnd.leocad-color"))
{ {
DragEnterEvent->acceptProposedAction(); DragEnterEvent->acceptProposedAction();
((View*)widget)->BeginDrag(lcDragState::COLOR); ((View*)widget)->BeginDrag(lcDragState::Color);
} }
} }
else else