主页 > 原创 > litecad的一个鼠标拖动实现

litecad的一个鼠标拖动实现

在绑定鼠标拖动事件后ProcMouseMove后,通过计算新的中心点来实现拖动视图,代码如下(注意需要同时在单击事件中做isClicked判断):

//鼠标移动
void CALLBACK CCoalCADView::ProcMouseMove( HANDLE hLcWnd, int Button, int Flags, int Xwin, int Ywin, double X, double Y )
{
 if (Button == LC_LBUTTON )
  {
   if (!isClicked) {
     HANDLE hView = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEW );
     baseLeft = lcPropGetFloat( hView, LC_PROP_VIEW_LEF );
     baseTop = lcPropGetFloat( hView, LC_PROP_VIEW_TOP );
      baseRight = lcPropGetFloat( hView, LC_PROP_VIEW_RIG );
      baseBottom = lcPropGetFloat( hView, LC_PROP_VIEW_BOT );

     winBaseX = Xwin;
      winBaseY = Ywin;
      baseX = X;
      baseY = Y;

      a = (baseX-baseLeft)/winBaseX;
      b = (baseY-baseTop)/winBaseY;

     isClicked = true;
   }

   HANDLE hView = lcPropGetHandle( hLcWnd, LC_PROP_WND_VIEW );
   float left = lcPropGetFloat( hView, LC_PROP_VIEW_PIXELSIZE );

   double xt;
    double yt;
    xt = a*(-Xwin+winBaseX+(baseRight+baseLeft)/(2*a));
   yt = b*(-Ywin+winBaseY+(baseBottom+baseTop)/(2*b));

   lcViewSetRect(hView, xt, yt, 0, 0);
   lcWndRedraw( hLcWnd );
  }
}

发表评论

邮箱地址不会被公开。 必填项已用*标注