8,834
社区成员
发帖
与我相关
我的任务
分享
PointF m_panOffset = new PointF(25, -25); //为什么取这个店呢。。
PointF m_dragOffset = new PointF(0, 0);
float m_screenResolution = 96;
protected override void OnMouseWheel(MouseEventArgs e)
{
UnitPoint p = GetMousePoint();
float wheeldeltatick = 120;
float zoomdelta = (1.25f * (Math.Abs(e.Delta) / wheeldeltatick)); //为什么要这样倍数
if (e.Delta < 0)
m_model.Zoom = m_model.Zoom / zoomdelta;
else
m_model.Zoom = m_model.Zoom * zoomdelta;
SetCenterScreen(ToScreen(p), true);
DoInvalidate(true);
base.OnMouseWheel(e);
}
PointF Translate(UnitPoint point)
{
return point.Point;
}
float ScreenHeight()
{
return (float)(ToUnit(this.ClientRectangle.Height) / m_model.Zoom);//这里为什么要除缩放比例呢
}
public double ToUnit(float screenvalue)
{
return (double)screenvalue / (double)(m_screenResolution * m_model.Zoom);//上面除了比例 ,这里为什么还除呢。 还有为什么要除分辨率呢。。
}
public UnitPoint GetMousePoint()
{
Point point = this.PointToClient(Control.MousePosition);
return ToUnit(point);
}
//UnitPoint只是个类
protected void SetCenterScreen(PointF screenPoint, bool setCursor)
{
float centerX = ClientRectangle.Width / 2;
m_panOffset.X += centerX - screenPoint.X; //这里又是什么意思。。
float centerY = ClientRectangle.Height / 2;
m_panOffset.Y += centerY - screenPoint.Y;
if (setCursor)
Cursor.Position = this.PointToScreen(new Point((int)centerX, (int)centerY));
DoInvalidate(true);
}
public UnitPoint ToUnit(PointF screenpoint)
{
float panoffsetX = m_panOffset.X + m_dragOffset.X;
float panoffsetY = m_panOffset.Y + m_dragOffset.Y;
float xpos = (screenpoint.X - panoffsetX) / (m_screenResolution * m_model.Zoom);
float ypos = ScreenHeight() - ((screenpoint.Y - panoffsetY)) / (m_screenResolution * m_model.Zoom);///为什么要用height - 呢
return new UnitPoint(xpos, ypos);
}
public UnitPoint(double x, double y)
{
m_x = x;
m_y = y;
}