litecad的一个鼠标拖动实现
2014 年 2 月 7 日 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 );
}
}
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 );
}
}
发表评论