Exemplo n.º 1
0
bool CTrack::Done(bool bSuccess)
{
	Draw(false/*bOn*/);

	if (m_pDrawProc && m_pAGDC)
	{
		int iToolCode = (bSuccess ? TOOLCODE_DONE : TOOLCODE_ABORT);
		HDC hDC = m_pAGDC->GetHDC();
		m_pDrawProc(hDC, false/*bOn*/, iToolCode, m_pData);
	}

	// return whether the symbol was only moved
	return m_bMoveOnly;
}
Exemplo n.º 2
0
void CTrack::Delta(int dx, int dy)
{
	POINT ptOffset = {dx, dy};
	CAGMatrix CombinedMatrix = m_Matrix * m_ViewToDeviceMatrix;
	CombinedMatrix.Inverse().Transform(&ptOffset, 1, false);

	m_bMoved = true;
	Draw(false/*bOn*/);
	m_Matrix.Translate(ptOffset.x, ptOffset.y);

	if (m_pDrawProc && m_pAGDC)
	{
		HDC hDC = m_pAGDC->GetHDC();
		m_pDrawProc(hDC, false/*bOn*/, TOOLCODE_UPDATE, m_pData);
	}

	Draw(true/*bOn*/);
}
Exemplo n.º 3
0
void CTrack::Flip(bool fFlipX, bool fFlipY)
{
	Draw(false/*bOn*/);

	m_bMoveOnly = false;
	RECT rect = m_Distort.Rect;
	m_Matrix.Transform(rect);
	double fcx = (double)(rect.left + rect.right) / 2;
	double fcy = (double)(rect.top + rect.bottom) / 2;
	double fsx = (fFlipX ? -1.0 : 1.0);
	double fsy = (fFlipY ? -1.0 : 1.0);
	m_Matrix.Scale(fsx, fsy, fcx, fcy);

	if (m_pDrawProc && m_pAGDC)
	{
		HDC hDC = m_pAGDC->GetHDC();
		m_pDrawProc(hDC, false/*bOn*/, TOOLCODE_UPDATE, m_pData);
	}

	Draw(true/*bOn*/);
}
Exemplo n.º 4
0
bool CTrack::Move(int x, int y)
{
	if (m_bDisabled)
		return false;

	if (!m_iHandleGrabbed)
		return false;

	// Prevent any accidental moves on the first click
	if (m_iHandleGrabbed == H_MOVE && !m_bMoved)
	{
		#define CLOSENESS 10 // pixels
		int dx = m_iLastDownX - x;
		int dy = m_iLastDownY - y;
		if (dx >= -CLOSENESS && dx <= CLOSENESS && dy >= -CLOSENESS && dy <= CLOSENESS)
			return false;
	}

	if (m_bShear)
		ConstrainXY(&x, &y, true/*bButtonDown*/, false/*bInit*/, m_bShear/*bActive*/);

	x = bound(x, m_BoundRectScreen.left, m_BoundRectScreen.right);
	y = bound(y, m_BoundRectScreen.top, m_BoundRectScreen.bottom);

	CPoint pt(x, y);
	m_ViewToDeviceMatrix.Inverse().Transform(pt);
	x = pt.x;
	y = pt.y;

	if (x == m_iLastX && y == m_iLastY)
		return false;

	m_bMoved = true;
	Draw(false/*bOn*/);

	switch (m_iHandleGrabbed)
	{
		case H_UL:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.top, m_bConstrainX, m_bConstrainY);
			else
				Scale(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.top, m_Distort.Rect.right, m_Distort.Rect.bottom, m_bConstrainAspect ^ CONTROL);
			break;
		}

		case H_UR:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.top, m_bConstrainX, m_bConstrainY);
			else
				Scale(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.top, m_Distort.Rect.left, m_Distort.Rect.bottom, m_bConstrainAspect ^ CONTROL);
			break;
		}

		case H_LR:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.bottom, m_bConstrainX, m_bConstrainY);
			else
				Scale(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.bottom, m_Distort.Rect.left, m_Distort.Rect.top, m_bConstrainAspect ^ CONTROL);
			break;
		}

		case H_LL:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.bottom, m_bConstrainX, m_bConstrainY);
			else
				Scale(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.bottom, m_Distort.Rect.right, m_Distort.Rect.top, m_bConstrainAspect ^ CONTROL);
			break;
		}

		case H_TOP:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			int midx = (m_Distort.Rect.left + m_Distort.Rect.right)/2;

			if (m_bShear)
				Shear(pt.x, pt.y, midx, m_Distort.Rect.top, m_bConstrainX, m_bConstrainY);
			else
			{
				CPoint ptMid(midx, m_Distort.Rect.top);
				long dummy;
				m_Matrix.Transform(ptMid, pt.x, dummy);
				Scale(pt.x, pt.y, midx, m_Distort.Rect.top, midx, m_Distort.Rect.bottom, false/*bConstrainAspect*/);
			}
			break;
		}

		case H_RIGHT:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			int midy = (m_Distort.Rect.top + m_Distort.Rect.bottom)/2;

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.right, midy, m_bConstrainX, m_bConstrainY);
			else
			{
				CPoint ptMid(m_Distort.Rect.right, midy);
				long dummy;
				m_Matrix.Transform(ptMid, dummy, pt.y);
				Scale(pt.x, pt.y, m_Distort.Rect.right, midy, m_Distort.Rect.left, midy, false/*bConstrainAspect*/);
			}
			break;
		}

		case H_BOTTOM:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			int midx = (m_Distort.Rect.left + m_Distort.Rect.right)/2;

			if (m_bShear)
				Shear(pt.x, pt.y, midx, m_Distort.Rect.bottom, m_bConstrainX, m_bConstrainY);
			else
			{
				CPoint ptMid(midx, m_Distort.Rect.bottom);
				long dummy;
				m_Matrix.Transform(ptMid, pt.x, dummy);
				Scale(pt.x, pt.y, midx, m_Distort.Rect.bottom, midx, m_Distort.Rect.top, false/*bConstrainAspect*/);
			}
			break;
		}

		case H_LEFT:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			int midy = (m_Distort.Rect.top + m_Distort.Rect.bottom)/2;

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.left, midy, m_bConstrainX, m_bConstrainY);
			else
			{
				CPoint ptMid(m_Distort.Rect.left, midy);
				long dummy;
				m_Matrix.Transform(ptMid, dummy, pt.y);
				Scale(pt.x, pt.y, m_Distort.Rect.left, midy, m_Distort.Rect.right, midy, false/*bConstrainAspect*/);
			}
			break;
		}

		case H_CENTER:
		{
			// transform points to transformed position
			m_Matrix.Transform(m_ptCenter);
			m_Matrix.Transform(m_ptRotate);
			int dx = pt.x - m_ptCenter.x;
			int dy = pt.y - m_ptCenter.y;
			m_ptRotate.x += dx;
			m_ptRotate.y += dy;
			m_ptCenter = pt;
			// transform points back to untransformed position
			m_Matrix.Inverse().Transform(m_ptCenter);
			m_Matrix.Inverse().Transform(m_ptRotate);
			break;
		}

		case H_CORNER_UL:
		case H_CORNER_UR:
		case H_CORNER_LR:
		case H_CORNER_LL:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			// transform the new point back to its untransformed position
			CPoint ptTemp = pt;
			m_Matrix.Inverse().Transform(ptTemp);
			int i = m_iHandleGrabbed - H_CORNER_UL;
			m_Distort.p[i] = ptTemp;

			// Update the m_Distort.Rect rectangle
			m_Distort.Rect.left   = min(min(min(m_Distort.p[0].x, m_Distort.p[1].x), m_Distort.p[2].x), m_Distort.p[3].x);
			m_Distort.Rect.right  = max(max(max(m_Distort.p[0].x, m_Distort.p[1].x), m_Distort.p[2].x), m_Distort.p[3].x);
			m_Distort.Rect.top    = min(min(min(m_Distort.p[0].y, m_Distort.p[1].y), m_Distort.p[2].y), m_Distort.p[3].y);
			m_Distort.Rect.bottom = max(max(max(m_Distort.p[0].y, m_Distort.p[1].y), m_Distort.p[2].y), m_Distort.p[3].y);
			break;
		}

		case H_ROTATE:
		{
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_SIZE))
				Mode(m_iWhatCanDo & ~TR_SIZE, false/*fDisplay*/);

			// transform points to transformed position
			Rotate(pt.x, pt.y, m_iStartRotateX, m_iStartRotateY);
			m_ptRotate = pt;
			// transform points back to untransformed position
			m_Matrix.Inverse().Transform(m_ptRotate);
			break;
		}

		case H_MOVE:
		{
			// Calculate how far we SHOULD move
			CPoint delta1(pt.x - m_iLastX, pt.y - m_iLastY);

			// Calculate where we are right now
			CRect rect = m_Distort.Rect;
			m_Matrix.Transform(rect);

			// Calculate the new top-left point
			CPoint ptNewTL(rect.left + delta1.x, rect.top + delta1.y);

			// Snap it to the grid
			m_Grid.Snap(ptNewTL);

			if (m_iWhatCanDo & TR_BOUNDTOSYMBOL)
			{
				int delta;
				delta = ptNewTL.x - m_BoundRect.left;
				if (delta < 0)
					ptNewTL.x -= delta;
				delta = ptNewTL.y - m_BoundRect.top;
				if (delta < 0)
					ptNewTL.y -= delta;
				delta = (ptNewTL.x + rect.Width()) - m_BoundRect.right;
				if (delta > 0)
					ptNewTL.x -= delta;
				delta = (ptNewTL.y + rect.Height()) - m_BoundRect.bottom;
				if (delta > 0)
					ptNewTL.y -= delta;
			}

			// Calculate how far we WILL move
			CPoint delta2(ptNewTL.x - rect.left, ptNewTL.y - rect.top);

			// Adjust the point for the next time around
			x -= (delta1.x - delta2.x);
			y -= (delta1.y - delta2.y);

			m_Matrix.Translate(delta2.x, delta2.y);
			break;
		}

		default:
			return false;
		}

	if (m_pDrawProc && m_pAGDC)
	{
		HDC hDC = m_pAGDC->GetHDC();
		m_pDrawProc(hDC, false/*bOn*/, TOOLCODE_UPDATE, m_pData);
	}

	Draw(true/*bOn*/);
	m_iLastX = x;
	m_iLastY = y;

	return true;
}