mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Center visible area to the selection when using mouse wheel to zoom in
and out
This commit is contained in:
@@ -1,24 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
|
*
|
||||||
DIY Layout Creator (DIYLC).
|
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
*
|
||||||
|
* This file is part of DIYLC.
|
||||||
This file is part of DIYLC.
|
*
|
||||||
|
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||||
DIYLC is free software: you can redistribute it and/or modify
|
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||||
it under the terms of the GNU General Public License as published by
|
* License, or (at your option) any later version.
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
*
|
||||||
(at your option) any later version.
|
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
DIYLC is distributed in the hope that it will be useful,
|
* Public License for more details.
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
*
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||||
GNU General Public License for more details.
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
*/
|
|
||||||
package org.diylc.swing.plugins.canvas;
|
package org.diylc.swing.plugins.canvas;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
@@ -36,6 +32,7 @@ import java.awt.event.MouseAdapter;
|
|||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
import java.awt.event.MouseWheelListener;
|
import java.awt.event.MouseWheelListener;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -275,23 +272,40 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
plugInPort.setZoomLevel(newZoom = availableZoomLevels[i]);
|
plugInPort.setZoomLevel(newZoom = availableZoomLevels[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle2D selectionBounds = plugInPort.getSelectionBounds(true);
|
||||||
|
Rectangle visibleRect = scrollPane.getVisibleRect();
|
||||||
|
|
||||||
|
JScrollBar horizontal = scrollPane.getHorizontalScrollBar();
|
||||||
|
JScrollBar vertical = scrollPane.getVerticalScrollBar();
|
||||||
|
|
||||||
|
if (selectionBounds == null) {
|
||||||
// center to cursor
|
// center to cursor
|
||||||
Point desiredPos =
|
Point desiredPos =
|
||||||
new Point((int) (1d * mousePos.x / oldZoom * newZoom), (int) (1d * mousePos.y / oldZoom * newZoom));
|
new Point((int) (1d * mousePos.x / oldZoom * newZoom), (int) (1d * mousePos.y / oldZoom * newZoom));
|
||||||
int dx = desiredPos.x - mousePos.x;
|
int dx = desiredPos.x - mousePos.x;
|
||||||
int dy = desiredPos.y - mousePos.y;
|
int dy = desiredPos.y - mousePos.y;
|
||||||
JScrollBar horizontal = scrollPane.getHorizontalScrollBar();
|
|
||||||
horizontal.setValue(horizontal.getValue() + dx);
|
horizontal.setValue(horizontal.getValue() + dx);
|
||||||
JScrollBar vertical = scrollPane.getVerticalScrollBar();
|
|
||||||
vertical.setValue(vertical.getValue() + dy);
|
vertical.setValue(vertical.getValue() + dy);
|
||||||
} if (e.isShiftDown()) {
|
} else {
|
||||||
|
// center to selection
|
||||||
|
horizontal.setValue((int) (selectionBounds.getX() + selectionBounds.getWidth() / 2 - visibleRect
|
||||||
|
.getWidth() / 2));
|
||||||
|
vertical.setValue((int) (selectionBounds.getY() + selectionBounds.getHeight() / 2 - visibleRect
|
||||||
|
.getHeight() / 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.isShiftDown()) {
|
||||||
int iScrollAmount = e.getScrollAmount();
|
int iScrollAmount = e.getScrollAmount();
|
||||||
int iNewValue = horizontalScrollBar.getValue() + horizontalScrollBar.getBlockIncrement() * iScrollAmount * e.getWheelRotation();
|
int iNewValue =
|
||||||
|
horizontalScrollBar.getValue() + horizontalScrollBar.getBlockIncrement() * iScrollAmount
|
||||||
|
* e.getWheelRotation();
|
||||||
if (iNewValue <= horizontalScrollBar.getMaximum())
|
if (iNewValue <= horizontalScrollBar.getMaximum())
|
||||||
horizontalScrollBar.setValue(iNewValue);
|
horizontalScrollBar.setValue(iNewValue);
|
||||||
} else {
|
} else {
|
||||||
int iScrollAmount = e.getScrollAmount();
|
int iScrollAmount = e.getScrollAmount();
|
||||||
int iNewValue = verticalScrollBar.getValue() + verticalScrollBar.getBlockIncrement() * iScrollAmount * e.getWheelRotation();
|
int iNewValue =
|
||||||
|
verticalScrollBar.getValue() + verticalScrollBar.getBlockIncrement() * iScrollAmount
|
||||||
|
* e.getWheelRotation();
|
||||||
if (iNewValue <= verticalScrollBar.getMaximum())
|
if (iNewValue <= verticalScrollBar.getMaximum())
|
||||||
verticalScrollBar.setValue(iNewValue);
|
verticalScrollBar.setValue(iNewValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1970,6 +1970,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>All file export actions (PNG, PDF, BOM...) take the current file name as a default</description>
|
<description>All file export actions (PNG, PDF, BOM...) take the current file name as a default</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Center visible area to the selection when using mouse wheel to zoom in and out</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Change mouse cursor when in "Highlight Connected Areas" mode to avoid confusion</description>
|
<description>Change mouse cursor when in "Highlight Connected Areas" mode to avoid confusion</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user