mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
zoom scroll improvement
This commit is contained in:
@@ -222,36 +222,36 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
// disable scrolling
|
// disable scrolling
|
||||||
scrollPane.setWheelScrollingEnabled(false);
|
scrollPane.setWheelScrollingEnabled(false);
|
||||||
|
|
||||||
Dimension oldDim = plugInPort.getCanvasDimensions(true);
|
|
||||||
|
Point mousePos = getCanvasPanel().getMousePosition(true);
|
||||||
|
|
||||||
// change zoom level
|
// change zoom level
|
||||||
double d = plugInPort.getZoomLevel();
|
double oldZoom = plugInPort.getZoomLevel();
|
||||||
|
double newZoom;
|
||||||
Double[] availableZoomLevels = plugInPort.getAvailableZoomLevels();
|
Double[] availableZoomLevels = plugInPort.getAvailableZoomLevels();
|
||||||
if (e.getWheelRotation() > 0) {
|
if (e.getWheelRotation() > 0) {
|
||||||
int i = availableZoomLevels.length - 1;
|
int i = availableZoomLevels.length - 1;
|
||||||
while (i > 0 && availableZoomLevels[i] >= d) {
|
while (i > 0 && availableZoomLevels[i] >= oldZoom) {
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
plugInPort.setZoomLevel(availableZoomLevels[i]);
|
plugInPort.setZoomLevel(newZoom = availableZoomLevels[i]);
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < availableZoomLevels.length - 1 && availableZoomLevels[i] <= d) {
|
while (i < availableZoomLevels.length - 1 && availableZoomLevels[i] <= oldZoom) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
plugInPort.setZoomLevel(availableZoomLevels[i]);
|
plugInPort.setZoomLevel(newZoom = availableZoomLevels[i]);
|
||||||
// center to cursor
|
|
||||||
Point mousePos = getCanvasPanel().getMousePosition(true);
|
|
||||||
Dimension newDim = plugInPort.getCanvasDimensions(true);
|
|
||||||
Point desiredPos =
|
|
||||||
new Point((int) (1d * mousePos.x / oldDim.width * newDim.width), (int) (1d * mousePos.y
|
|
||||||
/ oldDim.height * newDim.height));
|
|
||||||
int dx = desiredPos.x - mousePos.x;
|
|
||||||
int dy = desiredPos.y - mousePos.y;
|
|
||||||
JScrollBar horizontal = scrollPane.getHorizontalScrollBar();
|
|
||||||
horizontal.setValue(horizontal.getValue() + dx);
|
|
||||||
JScrollBar vertical = scrollPane.getVerticalScrollBar();
|
|
||||||
vertical.setValue(vertical.getValue() + dy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// center to cursor
|
||||||
|
Point desiredPos =
|
||||||
|
new Point((int) (1d * mousePos.x / oldZoom * newZoom), (int) (1d * mousePos.y / oldZoom * newZoom));
|
||||||
|
int dx = desiredPos.x - mousePos.x;
|
||||||
|
int dy = desiredPos.y - mousePos.y;
|
||||||
|
JScrollBar horizontal = scrollPane.getHorizontalScrollBar();
|
||||||
|
horizontal.setValue(horizontal.getValue() + dx);
|
||||||
|
JScrollBar vertical = scrollPane.getVerticalScrollBar();
|
||||||
|
vertical.setValue(vertical.getValue() + dy);
|
||||||
} else {
|
} else {
|
||||||
// enable scrolling
|
// enable scrolling
|
||||||
scrollPane.setWheelScrollingEnabled(true);
|
scrollPane.setWheelScrollingEnabled(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user