From 5b9d0aeff33127ec7401791371d604341f7b00fd Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 28 Feb 2006 06:28:42 +0000 Subject: Drag and drop new pieces from the category tree. git-svn-id: http://svn.leocad.org/trunk@499 c7d43263-9d01-0410-8a33-9dba5d9f93d6 --- common/project.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/project.h | 3 +++ 2 files changed, 63 insertions(+) (limited to 'common') diff --git a/common/project.cpp b/common/project.cpp index d9456fb..9b3a28a 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -7765,6 +7765,18 @@ bool Project::OnKeyDown(char nKey, bool bControl, bool bShift) return ret; } +void Project::BeginPieceDrop(PieceInfo* Info) +{ + StartTracking(LC_TRACK_LEFT); + + m_PreviousAction = m_nCurAction; + m_PreviousPiece = m_pCurPiece; + + m_pCurPiece = Info; + m_pCurPiece->AddRef(); + SetAction(LC_ACTION_INSERT); +} + void Project::OnLeftButtonDown(int x, int y, bool bControl, bool bShift) { GLdouble modelMatrix[16], projMatrix[16], point[3]; @@ -8162,6 +8174,54 @@ void Project::OnLeftButtonDoubleClick(int x, int y, bool bControl, bool bShift) void Project::OnLeftButtonUp(int x, int y, bool bControl, bool bShift) { + if (m_nTracking == LC_TRACK_LEFT) + { + // Dragging a new piece from the tree. + if (m_nCurAction == LC_ACTION_INSERT) + { + int Viewport[4]; + Viewport[0] = (int)(viewports[m_nViewportMode].dim[m_nActiveViewport][0] * (float)m_nViewX); + Viewport[1] = (int)(viewports[m_nViewportMode].dim[m_nActiveViewport][1] * (float)m_nViewY); + Viewport[2] = (int)(viewports[m_nViewportMode].dim[m_nActiveViewport][2] * (float)m_nViewX); + Viewport[3] = (int)(viewports[m_nViewportMode].dim[m_nActiveViewport][3] * (float)m_nViewY); + + if ((x > Viewport[0]) && (x < Viewport[2]) && (y > Viewport[1]) && (y < Viewport[3])) + { + Vector3 Pos; + Vector4 Rot; + + GetPieceInsertPosition(x, y, Pos, Rot); + + Piece* pPiece = new Piece(m_pCurPiece); + pPiece->Initialize(Pos[0], Pos[1], Pos[2], m_nCurStep, m_nCurFrame, m_nCurColor); + + pPiece->ChangeKey(m_nCurStep, false, false, Rot, LC_PK_ROTATION); + pPiece->ChangeKey(m_nCurFrame, true, false, Rot, LC_PK_ROTATION); + pPiece->UpdatePosition(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation); + + SelectAndFocusNone(false); + pPiece->CreateName(m_pPieces); + AddPiece(pPiece); + pPiece->CalculateConnections(m_pConnections, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, false, true); + pPiece->Select (true, true, false); + UpdateSelection(); + SystemPieceComboAdd(m_pCurPiece->m_strDescription); + SystemUpdateFocus(pPiece); + + if (m_nSnap & LC_DRAW_MOVE) + SetAction(LC_ACTION_MOVE); + else + SetAction(m_PreviousAction); + } + else + SetAction(m_PreviousAction); + + m_pCurPiece->DeRef(); + m_pCurPiece = m_PreviousPiece; + m_PreviousPiece = NULL; + } + } + StopTracking(true); } diff --git a/common/project.h b/common/project.h index 614a584..96d762c 100644 --- a/common/project.h +++ b/common/project.h @@ -112,6 +112,7 @@ public: // Special notifications void DeleteContents(bool bUndo); // delete doc items etc void LoadDefaults(bool cameras); + void BeginPieceDrop(PieceInfo* Info); void CreateImages(Image* images, int width, int height, unsigned short from, unsigned short to, bool hilite); void Render(bool bToMemory); @@ -256,8 +257,10 @@ protected: int m_nViewX; int m_nViewY; PieceInfo* m_pCurPiece; + PieceInfo* m_PreviousPiece; unsigned char m_nCurColor; unsigned char m_nCurAction; + unsigned char m_PreviousAction; bool m_bAnimation; bool m_bAddKeys; unsigned char m_nFPS; -- cgit v1.2.3