【发布时间】:2022-01-21 06:41:13
【问题描述】:
如何实现鼠标位置的放大/缩小中心?
例如(在一维示例中)
C the position of the center (C = 3)
M the point where the zoom is applied (M = 5)
[___] represent the screen
[__C_M___]
after a zoom in, I increment the zoomFactor and it render like that :
[__C__M__]
but I'll like to render like that (The point M dont move):
[_C__M___]
我需要对中心应用哪个偏移量才能得到这个显示?
在这个简单的例子中,它是-1
提前致谢
[编辑:添加我的代码]
public void zoomCallback(boolean zoomUp, Point origine) {
// origine is the mouse position relatively to the screen
if ((zoomLevel == 0.75 && !zoomUp) || (zoomLevel == 3 && zoomUp))
return;
zoomLevel *= zoomUp ? 1.25 : 0.75;
zoomLevel = Math.max(0.75, zoomLevel);
zoomLevel = Math.min(3, zoomLevel);
// zoomLevel is used the scale the map when displaying it
Point mapCenter = this.getMapCenter();
// the map center is juste the position of map center relatively to the screen
this.mapOffset.translate(/* ??? , ??? */);
// the mapOffset is used to print the map on the screen
}
【问题讨论】:
-
发布您当前的代码 - 它可以更轻松地解释需要更改的内容。
-
@500-InternalServerError 完成 :)