VC++开发GIS系统(121)滚轮缩放之函数实现

在使用ArcGIS或者MapGIS等软件绘图的时候有一个很实用的功能——使用滚轮放大缩小。放大缩小已经在实现了,现在本文也做一个尝试。

滚轮缩放类的定义

VC++开发GIS系统(108)放大地图之新建tools模块基础上,新建一个类,用于处理滚轮缩放的相关操作。代码如下:

/*
* 鼠标滚动
*/
class malatoolsdll malaZoom :public CmalaMouseAction
{
public:
    malaZoom();
    malaZoom(CView* ptView, malaScreen *Screen);
    ~malaZoom();
    void MouseWheel(UINT nFlags, short zDelta, malaPoint pt);
public:
    malaScreen *m_Screen;
};

滚轮缩放类的实现

从上面可以看出重载了MouseWheel这个了函数,实现如下:

/*
* 鼠标滚动实现
*/
malaZoom::malaZoom()
{

}
malaZoom::malaZoom(CView* ptView, malaScreen *Screen)
{
    mBaseView = ptView;
    m_Screen = Screen;
}

malaZoom::~malaZoom()
{

}

void malaZoom::MouseWheel(UINT nFlags, short zDelta, malaPoint pt)
{
    long xmid = m_Screen->wScreen / 2;
    long ymid = m_Screen->hScreen / 2;
    malaPoint tmpPoint;
    ScreenToCoord(xmid, ymid, *m_Screen, &tmpPoint.x, &tmpPoint.y);


    
    if (zDelta < 0)
    {
        m_Screen->lbx = m_Screen->lbx + xmid * m_Screen->scale * 0.1;
        m_Screen->lby = m_Screen->lby + ymid * m_Screen->scale * 0.1;
        m_Screen->scale = m_Screen->scale*0.9;
    }
    else
    {
        m_Screen->lbx = m_Screen->lbx - xmid * m_Screen->scale * 0.1;
        m_Screen->lby = m_Screen->lby - ymid * m_Screen->scale * 0.1;
        m_Screen->scale = m_Screen->scale*1.1;
    }
    mBaseView->Invalidate(TRUE);
}

其中zDelta代表鼠标前后滚动的2个方向。

详细代码可以参考:GitHub

VC++开发GIS系统(120)更改鼠标指针之实现替换 VC++开发GIS系统(122)滚轮缩放之响应

作者:,GIS爱好者。
分享本文,请您带上本文链接
分享到:

发表评论