예제 #1
0
void CVecPolygon::DrawRotatedDragImage(CDC* pDC, double dAng, LPPOINT lpCenter, double dAngLast, LPPOINT lpCenterLast)
{
   CRect rect = m_t_Rect;
   LPPOINT lpPointsNew = NULL;
   LPPOINT lpPointsLast = NULL;

   if(lpCenter!=NULL)
   {
      lpPointsNew = new POINT[m_uiNumOfPoints];
   	memcpy(lpPointsNew, m_t_lpIntPoints, m_uiNumOfPoints*sizeof(POINT));
      RotatePoints(lpPointsNew, m_uiNumOfPoints, dAng, lpCenter);
   }

   if(lpCenterLast!=NULL)
   {
      lpPointsLast = new POINT[m_uiNumOfPoints];
   	memcpy(lpPointsLast, m_t_lpIntPoints, m_uiNumOfPoints*sizeof(POINT));
      RotatePoints(lpPointsLast, m_uiNumOfPoints, dAngLast, lpCenterLast);
   }

   CPolygonTracker::DrawDragPolygon(pDC, lpPointsNew, 1, lpPointsLast, 1, m_uiNumOfPoints);

   if(lpPointsNew != NULL)
      delete []lpPointsNew;
   if(lpPointsLast != NULL)
      delete []lpPointsLast;

}
예제 #2
0
파일: Compass.cpp 프로젝트: avppro71/KPPV
void CCompass::Draw(QPainter *p_pPainter, QPoint *p_pCenter)
{
 QBrush BkBrush, Brush[2], TextBrush;
 QPen Pen;
 QRect DrawRect;
 QColor Color;
 QPoint Points[3], TickPoints[24];
 QFont Font;
 short i, Offset = 5, FontPixelSize = 15, TextWidth;
 char tstr[128];
 double dCompassPosition;

 for(i = 0; i < 24; i += 2) {
   TickPoints[i].setX(p_pCenter->x() + 0); 
   TickPoints[i].setY(p_pCenter->y() - m_nRadius); 
   TickPoints[i + 1].setX(p_pCenter->x() + 0); 
   TickPoints[i + 1].setY(p_pCenter->y() - m_nRadius + 2 * Offset + ((!(i % 3)) ? Offset : 0)); }
 
 DrawRect.setCoords(p_pCenter->x() - m_nRadius, p_pCenter->y() - m_nRadius, p_pCenter->x() + m_nRadius, p_pCenter->y() + m_nRadius);

 BkBrush = QBrush(QColor(255, 0, 0, 128));
 TextBrush = QBrush(QColor(255, 255, 0, 255));
 Brush[0] = QBrush(QColor(255, 0, 0, 255));
 Brush[1] = QBrush(QColor(255, 255, 255, 255));
 Pen = QPen(Qt::black);
 Pen.setWidth(1);
 
 Pen.setStyle(Qt::NoPen);
 p_pPainter->setPen(Pen);
 BkBrush.setStyle(Qt::SolidPattern);
 p_pPainter->setBrush(BkBrush);
 p_pPainter->drawEllipse(DrawRect.center(), m_nRadius - Offset, m_nRadius - Offset);

 BkBrush.setStyle(Qt::NoBrush);
 p_pPainter->setBrush(BkBrush);
 Pen.setStyle(Qt::SolidLine);
 p_pPainter->setPen(Pen);
 p_pPainter->drawEllipse(DrawRect.center(), m_nRadius, m_nRadius);

 for(i = 0; i < 12; i ++)
   RotatePoints(&(TickPoints[i * 2]), 2, p_pCenter, 30 * i);
 
 p_pPainter->drawLines(TickPoints, 12);

 Pen.setStyle(Qt::NoPen);
 p_pPainter->setPen(Pen);

 p_pPainter->setBrush(Brush[0]);
 Points[0].setX(p_pCenter->x() + Offset);
 Points[0].setY(p_pCenter->y());
 Points[1].setX(p_pCenter->x() - Offset);
 Points[1].setY(p_pCenter->y());
 Points[2].setX(p_pCenter->x());
 Points[2].setY(p_pCenter->y() - m_nRadius + Offset);
 
 dCompassPosition = 360.0 - m_dHeading_deg;
 if(dCompassPosition < 0) dCompassPosition += 360;

 RotatePoints(Points, 3, p_pCenter, dCompassPosition);
 p_pPainter->drawConvexPolygon(Points, 3);

 p_pPainter->setBrush(Brush[1]);
 Points[0].setX(p_pCenter->x() + Offset);
 Points[0].setY(p_pCenter->y());
 Points[1].setX(p_pCenter->x() - Offset);
 Points[1].setY(p_pCenter->y());
 Points[2].setX(p_pCenter->x());
 Points[2].setY(p_pCenter->y() + m_nRadius - Offset);

 RotatePoints(Points, 3, p_pCenter, dCompassPosition);
 p_pPainter->drawConvexPolygon(Points, 3);

 Pen.setColor(Qt::black);
 Pen.setStyle(Qt::SolidLine);
 p_pPainter->setPen(Pen);
 p_pPainter->setBrush(TextBrush);
 Font.setPixelSize(FontPixelSize);
 p_pPainter->setFont(Font);
 sprintf_s(tstr, sizeof(tstr), "%.0lf", m_dHeading_deg);
 QFontMetrics FontMetrics(Font);
 TextWidth = FontMetrics.width(tstr) + 4;

 DrawRect.setCoords(p_pCenter->x() - TextWidth / 2, p_pCenter->y() - FontPixelSize / 2, p_pCenter->x() + TextWidth / 2, p_pCenter->y() + FontPixelSize / 2 + 2);
 p_pPainter->drawRect(DrawRect);
 p_pPainter->drawText(DrawRect, Qt::AlignCenter, QString::fromLocal8Bit(tstr));
}
예제 #3
0
BOOL CPicTracker::Track(CWnd* pWnd, CPoint point, BOOL bRotate, CSnapper* pSnapper,
	CWnd* pWndClipTo)
{

   BOOL bResizeOrMove = HitTest(point)==hitOnPoint ? TRUE : FALSE; 

	// don't handle if capture already set
	if (::GetCapture() != NULL)
		return FALSE;


	m_rectOrigianl = m_rect;

   AfxLockTempMaps();  // protect maps while looping

	ASSERT(!m_bFinalErase);

	// set capture to the window which received this message
	pWnd->SetCapture();
	ASSERT(pWnd == CWnd::GetCapture());
	pWnd->UpdateWindow();
	if (pWndClipTo != NULL)
		pWndClipTo->UpdateWindow();

   CPoint LastPoint(point);

	// get DC for drawing
	CDC* pDrawDC;
	if (pWndClipTo != NULL)
	{
		// clip to arbitrary window by using adjusted Window DC
		pDrawDC = pWndClipTo->GetDCEx(NULL, DCX_CACHE);
	}
	else
	{
		// otherwise, just use normal DC
		pDrawDC = pWnd->GetDC();
	}
	ASSERT_VALID(pDrawDC);

	CDRectangle rectOld;
	BOOL bMoved = FALSE;

	// get messages until capture lost or cancelled/accepted
	for (;;)
	{
		MSG msg;
		VERIFY(::GetMessage(&msg, NULL, 0, 0));

		if (CWnd::GetCapture() != pWnd)
			break;

      if(msg.message == WM_MOUSEMOVE)
			DispatchMessage(&msg);

		switch (msg.message)
		{
		// handle movement/accept messages
		case WM_LBUTTONUP:
		case WM_MOUSEMOVE:
OnCheange:
         {
   			rectOld = m_rect;
            m_rect = m_rectOrigianl;
			   // handle resize cases (and part of move)
            CPoint p;
            ::GetCursorPos(&p);
            pWnd->ScreenToClient(&p);

            p -= LastPoint;
            //LastPoint = point;
            
			   // handle move case
            if(bRotate)
            {
               LPDPOINT lpPoints = m_rect.GetPoints();
               CPoint pp = p+LastPoint;
               double dAngle = GetPointAng(&pp, &LastPoint);
               double dist = sqrt((double)(p.x*p.x + p.y*p.y));
               if(dist<30)
               {
                  dAngle /= 30;
                  dAngle *= dist;
               }
               if(::GetKeyState(VK_SHIFT) & 0x8000) //if the shift is pressed then snap to the close 45 degrees
               {
                  dAngle = ((int)((dAngle/(RAD90D/2))+0.499))*(RAD90D/2);
               }

               RotatePoints((LPCDPOINT)lpPoints, m_rect.GetNumOfPoints(), dAngle, NULL);
            }
			   else if (!bResizeOrMove)
			   {
               if((::GetKeyState(VK_SHIFT) & 0x8000)!=0)
               {
                  if(ABS(p.x)>ABS(p.y))
                     p.y=0;
                  else
                     p.x=0;
               }
               LPDPOINT lpPoints = m_rect.GetPoints();
               for(int i=0; i<m_rect.GetNumOfPoints();i++)
               {
                  lpPoints[i].x += p.x;
                  lpPoints[i].y += p.y;
               }
               if(pSnapper!=NULL)
                  pSnapper->FixSnapTo((LPCDPOINT)lpPoints,m_rect.GetNumOfPoints());
			   }
            else
            {
               double dAngle1 = m_rect.GetAngle1();
               double dAngle2 = m_rect.GetAngle2()-RAD90D;

               CDPoint center(0,0);
               CDPoint dp(p);
               RotatePoints(&dp, 1, -dAngle1, &center);

               if(CheckRetainProportions() && (m_dWidthDivHeight!=0)) //if the shift is pressed then remain proporions
               {
                  dp.y=dp.x/m_dWidthDivHeight;
               }

               LPDPOINT lpPoints = m_rect.GetPoints();

               center = GetPointsCenter((LPCDPOINT)lpPoints, m_rect.GetNumOfPoints());
               RotatePoints((LPCDPOINT)lpPoints, m_rect.GetNumOfPoints(), -dAngle1, &center);
			   int i;
               for(i=0; i<m_rect.GetNumOfPoints(); i++)
               {
                  CDPoint ppp = lpPoints[i];
                  ppp-=center;
                  if(ppp.x>0)
                     ppp.x += dp.x;
                  else
                     ppp.x -= dp.x;

                  ppp+=center;
                  lpPoints[i] = ppp;
               }
               RotatePoints((LPCDPOINT)lpPoints, m_rect.GetNumOfPoints(), dAngle1-dAngle2, &center);
               for(i=0; i<m_rect.GetNumOfPoints(); i++)
               {
                  CDPoint ppp = lpPoints[i];
                  ppp-=center;

                  if(ppp.y>0)
                     ppp.y += dp.y;
                  else
                     ppp.y -= dp.y;
                  ppp+=center;
                  lpPoints[i] = ppp;
               }
               RotatePoints((LPCDPOINT)lpPoints, m_rect.GetNumOfPoints(), dAngle2, &center);

               if(pSnapper!=NULL)
                  pSnapper->FixSnapTo((LPCDPOINT)lpPoints,m_rect.GetNumOfPoints());
            }


			   // only redraw and callback if the rect actually changed!
			   m_bFinalErase = (msg.message == WM_LBUTTONUP);
			   if (!rectOld.IsEqual(m_rect) || m_bFinalErase)
			   {
				   if (bMoved)
				   {
					   m_bErase = TRUE;
					   DrawTracker(&rectOld, pWndClipTo, pDrawDC, pWnd);
				   }
				   if (msg.message != WM_LBUTTONUP)
					   bMoved = TRUE;
			   }
			   if (m_bFinalErase)
				   goto ExitLoop;

			   if (!rectOld.IsEqual(m_rect))
			   {
				   m_bErase = FALSE;
				   DrawTracker(&m_rect, pWndClipTo, pDrawDC, pWnd);
			   }
         }
			break;

      case WM_KEYUP:
			if (msg.wParam == VK_SHIFT)
            goto OnCheange;
			break;

		// handle cancel messages
		case WM_KEYDOWN:
			if (msg.wParam == VK_SHIFT)
            goto OnCheange;
			if (msg.wParam != VK_ESCAPE)
				break;
		case WM_RBUTTONDOWN:
			if (bMoved)
			{
				m_bErase = m_bFinalErase = TRUE;
				DrawTracker(&m_rect, pWndClipTo, pDrawDC, pWnd);
			}
			m_rect = m_rectOrigianl;
			goto ExitLoop;

		// just dispatch rest of the messages
		default:
			DispatchMessage(&msg);
			break;
		}
	}

ExitLoop:
	if (pWndClipTo != NULL)
		pWndClipTo->ReleaseDC(pDrawDC);
	else
		pWnd->ReleaseDC(pDrawDC);
	ReleaseCapture();

	AfxUnlockTempMaps(FALSE);

	// restore rect in case bMoved is still FALSE
	if (!bMoved)
		m_rect = m_rectOrigianl;
	m_bFinalErase = FALSE;
	m_bErase = FALSE;

	// return TRUE only if rect has changed
	return !m_rectOrigianl.IsEqual(m_rect);
}