mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-12 02:02:16 +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).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
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 Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
*
|
||||
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
*
|
||||
* This file is part of DIYLC.
|
||||
*
|
||||
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by 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
|
||||
* Public License for more details.
|
||||
*
|
||||
* 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;
|
||||
|
||||
import java.awt.Dimension;
|
||||
@@ -36,6 +32,7 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
@@ -275,23 +272,40 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
plugInPort.setZoomLevel(newZoom = availableZoomLevels[i]);
|
||||
}
|
||||
|
||||
// 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;
|
||||
Rectangle2D selectionBounds = plugInPort.getSelectionBounds(true);
|
||||
Rectangle visibleRect = scrollPane.getVisibleRect();
|
||||
|
||||
JScrollBar horizontal = scrollPane.getHorizontalScrollBar();
|
||||
horizontal.setValue(horizontal.getValue() + dx);
|
||||
JScrollBar vertical = scrollPane.getVerticalScrollBar();
|
||||
vertical.setValue(vertical.getValue() + dy);
|
||||
} if (e.isShiftDown()) {
|
||||
|
||||
if (selectionBounds == null) {
|
||||
// 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;
|
||||
horizontal.setValue(horizontal.getValue() + dx);
|
||||
vertical.setValue(vertical.getValue() + dy);
|
||||
} 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 iNewValue = horizontalScrollBar.getValue() + horizontalScrollBar.getBlockIncrement() * iScrollAmount * e.getWheelRotation();
|
||||
int iNewValue =
|
||||
horizontalScrollBar.getValue() + horizontalScrollBar.getBlockIncrement() * iScrollAmount
|
||||
* e.getWheelRotation();
|
||||
if (iNewValue <= horizontalScrollBar.getMaximum())
|
||||
horizontalScrollBar.setValue(iNewValue);
|
||||
horizontalScrollBar.setValue(iNewValue);
|
||||
} else {
|
||||
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())
|
||||
verticalScrollBar.setValue(iNewValue);
|
||||
}
|
||||
|
||||
@@ -1970,6 +1970,10 @@
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<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>
|
||||
<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>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Change mouse cursor when in "Highlight Connected Areas" mode to avoid confusion</description>
|
||||
|
||||
Reference in New Issue
Block a user