所以我试图创建一个小图表,我将允许用户添加随机行等作为学习项目。最令人沮丧的部分是弄清楚如何让放大/缩小工作 - 我将我的ZoomScale变量绑定到鼠标滚轮并且它可以工作"但我希望能够根据它们的缩放程度来标记轴并计算它的距离测量值(米,厘米等),因为我每个Pixel变量都有MM,所以我们应该能够计算出来所以它需要更多的是一个精确的科学,而不仅仅是#34;它起作用"
double X1 = ((actualline[i].X1 + actualWidth - VisibleXMax - VisibleXMin) * ZoomScale); //Calculate modified coordinates based on
double X2 = ((actualline[i].X2 + actualWidth - VisibleXMax - VisibleXMin) * ZoomScale); // window width, window height, Visible X/Y, and Zoom.
double Y1 = ((actualline[i].Y1 + actualHeight - VisibleYMax - VisibleYMin) * ZoomScale);
double Y2 = ((actualline[i].Y2 + actualHeight - VisibleYMax - VisibleYMin) * ZoomScale);
尝试使用简单的1维方程式而不是尝试使用它,我可以为x和y重新编写。
因此,假设我们在x方向上有一个5单位宽的线
. . . . .
目前填满整个屏幕(实际上是窗口)。从0到5一直到。现在用户滚动以放大前3个单位。现在这3个单元应该填满整个窗口,因为用户已经放大了它。它应该在整个窗口看起来像这样
. . .
所以最初的线是x1 = 0,x2 = 5.0到5.由于我们的窗口是5个单位宽,它填满了窗口。现在用户想要只看到单位x1 = 0到x2 = 3. 0到3.但是我们希望这些单位在窗口上伸展,所以通过某种缩放计算(如上所述),我们希望将0,3变成0,5使用可用变量。变量是:
窗口宽度(本例中为5个单位)
原始X1和X2(本例中为0和5)
可见X分钟和最大值(在这种情况下为0和3)
每次向上滚动时,缩放比例为1,增量为0.05。
有什么建议吗?
答案 0 :(得分:1)
以下是我的做法。如果您有任何问题,请按照评论告诉我:
public void ZoomImage(int ScrollDelta)
{
OldUnitInPixels = UnitInPixels; // UnitInPixels is something similar to what you called mm/pixel - we need to keep the old one
if (ScrollDelta > 0) // this `if` means zoom in - the `else` means zoom out
{
if (ZoomLevel != 20) // to control my maximum zoom in (I want 20 zoom levels only)
{
ZoomLevel++; // increment zoom level
UnitInPixels += initialUnitInPixels; // I add certain value when I zoom in - for ex: initially it was 3 mm per pix, on zoom in it would be 4 mm per pixel
dotSize++; // I want some points to increase in size a little bit
lineSize += 0.1; // I want some liness to increase in size a little bit
// adjust all coord (points)
for (var i = 0; i < DisplayedCoords.Count; i++)
{
DisplayedCoords[i].X -= XCoordOffset; // remove value of what you called VisibleX from current x value - means go back to the very original coord - ex: actual value is (1,1) but I added (49, 49) for it so it looks (50,50) better on the screen. So I want to remove whatever I added which is (49,49)
DisplayedCoords[i].Y -= YCoordOffset; // remove value of what you called VisibleY from current Y value
DisplayedCoords[i].X /= OldUnitInPixels; // divide by old
DisplayedCoords[i].Y /= OldUnitInPixels;
DisplayedCoords[i].X *= UnitInPixels; // multiply by new
DisplayedCoords[i].Y *= UnitInPixels;
DisplayedCoords[i].X += XCoordOffset; // add back whatever we removed earlier. So it looks back again "better"
DisplayedCoords[i].Y += YCoordOffset;
}
DrawImage(); // draw
}
}
else
{
// else is super similar but instead of all the (++)s I do (--)s
}
}
看到它正常工作:(从鼠标位置放大/缩小未完成)