[tiled] r612 - in trunk: . src/tiled/mapeditor src/tiled/view
svn@biggeruniverse.com
svn at biggeruniverse.com
Sat Apr 22 13:36:52 PDT 2006
Author: bjorn
Date: 2006-04-22 15:36:51 -0500 (Sat, 22 Apr 2006)
New Revision: 612
Modified:
trunk/CHANGES
trunk/src/tiled/mapeditor/MapEditor.java
trunk/src/tiled/view/MapView.java
Log:
Implemented keeping the view centered while zooming by remembering the relative
midpoint. Still some flicker visible when the centering correction comes after
drawing had already started, which I hope to fix later.
Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES 2006-04-22 17:06:12 UTC (rev 611)
+++ trunk/CHANGES 2006-04-22 20:36:51 UTC (rev 612)
@@ -30,8 +30,9 @@
* Fixed tile palette bug of not accounting for gaps in tile ids (old bug)
* Fixed bug of adding a new tile even if cancelling out of new tile dialog
* Fixed NPE when saving a map with no extension - default to .tmx
+* Fixed the zooming so that it keeps the center in place
* Rewrote configuration based on the Preferences class, no more tiled.conf
-* Cleaned up TileSet- removed checksumming and rotation/orienation code
+* Cleaned up TileSet (removed checksumming and rotation/orienation code)
0.5.1 - June 15th, 2005
Modified: trunk/src/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/src/tiled/mapeditor/MapEditor.java 2006-04-22 17:06:12 UTC (rev 611)
+++ trunk/src/tiled/mapeditor/MapEditor.java 2006-04-22 20:36:51 UTC (rev 612)
@@ -71,7 +71,7 @@
private Cursor curEyed;
private Cursor curMarquee;
- /** Current release version */
+ /** Current release version. */
public static final String version = "0.6.0";
private Map currentMap;
@@ -93,6 +93,7 @@
private AbstractBrush currentBrush;
private SelectionLayer marqueeSelection;
private MapLayer clipboardLayer;
+ private float relativeMidX, relativeMidY;
// GUI components
private JPanel mainPanel;
@@ -138,9 +139,11 @@
private final Action mergeLayerDownAction, mergeAllLayersAction;
public MapEditor() {
- /*eraserBrush = new Eraser();
+ /*
+ eraserBrush = new Eraser();
brushes.add(eraserBrush());
- setBrush(eraserBrush);*/
+ setBrush(eraserBrush);
+ */
/*
try {
@@ -1165,6 +1168,13 @@
// This can currently only happen when the map changes size
String s = String.valueOf((int) (mapView.getZoom() * 100)) + "%";
zoomLabel.setText(s);
+
+ // Restore the midpoint
+ JViewport mapViewPort = mapScrollPane.getViewport();
+ Rectangle viewRect = mapViewPort.getViewRect();
+ int absMidX = Math.max(0, Math.round(relativeMidX * mapView.getWidth()) - viewRect.width / 2);
+ int absMidY = Math.max(0, Math.round(relativeMidY * mapView.getHeight()) - viewRect.height / 2);
+ mapViewPort.setViewPosition(new Point(absMidX, absMidY));
}
public void componentShown(ComponentEvent event) {
@@ -1198,16 +1208,26 @@
}
public void stateChanged(ChangeEvent e) {
- // At the moment, this can only be movement in the opacity slider
+ JViewport mapViewport = mapScrollPane.getViewport();
- if (currentMap != null && currentLayer >= 0) {
- MapLayer layer = getCurrentLayer();
- layer.setOpacity(opacitySlider.getValue() / 100.0f);
+ if (e.getSource() == opacitySlider) {
+ if (currentMap != null && currentLayer >= 0) {
+ MapLayer layer = getCurrentLayer();
+ layer.setOpacity(opacitySlider.getValue() / 100.0f);
- /*MapLayerStateEdit mlse = new MapLayerStateEdit(currentMap);
- mlse.setPresentationName("Opacity Change");
- undoSupport.postEdit(mlse);*/
+ /*
+ MapLayerStateEdit mlse = new MapLayerStateEdit(currentMap);
+ mlse.setPresentationName("Opacity Change");
+ undoSupport.postEdit(mlse);
+ */
+ }
}
+ else if (e.getSource() == mapViewport) {
+ // Store the point in the middle for zooming purposes
+ Rectangle viewRect = mapViewport.getViewRect();
+ relativeMidX = Math.min(1, (viewRect.x + viewRect.width / 2) / (float)mapView.getWidth());
+ relativeMidY = Math.min(1, (viewRect.y + viewRect.height / 2) / (float)mapView.getHeight());
+ }
}
private class UndoAction extends AbstractAction {
@@ -1650,9 +1670,9 @@
public boolean loadMap(String file) {
File exist = new File(file);
if (!exist.exists()) {
- JOptionPane.showMessageDialog(appFrame,
- Resources.getString("general.file.notexists.message"),
- Resources.getString("dialog.openmap.error.title"),
+ JOptionPane.showMessageDialog(appFrame,
+ Resources.getString("general.file.notexists.message"),
+ Resources.getString("dialog.openmap.error.title"),
JOptionPane.ERROR_MESSAGE);
return false;
}
@@ -1669,7 +1689,7 @@
} else {
JOptionPane.showMessageDialog(appFrame,
"Unsupported map format",
- Resources.getString("dialog.openmap.error.title"),
+ Resources.getString("dialog.openmap.error.title"),
JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
@@ -1938,6 +1958,7 @@
mapView.addComponentListener(this);
JViewport mapViewport = new JViewport();
mapViewport.setView(mapView);
+ mapViewport.addChangeListener(this);
mapScrollPane.setViewport(mapViewport);
setCurrentPointerState(PS_PAINT);
@@ -2037,13 +2058,15 @@
}
private void setCurrentPointerState(int state) {
- /*if(currentPointerState == PS_MARQUEE && state != PS_MARQUEE) {
+ /*
+ if (currentPointerState == PS_MARQUEE && state != PS_MARQUEE) {
// Special logic for selection
if (marqueeSelection != null) {
currentMap.removeLayerSpecial(marqueeSelection);
marqueeSelection = null;
}
- }*/
+ }
+ */
currentPointerState = state;
Modified: trunk/src/tiled/view/MapView.java
===================================================================
--- trunk/src/tiled/view/MapView.java 2006-04-22 17:06:12 UTC (rev 611)
+++ trunk/src/tiled/view/MapView.java 2006-04-22 20:36:51 UTC (rev 612)
@@ -126,7 +126,7 @@
}
}
- public void setZoomSmooth(double zoom) {
+ private void setZoomSmooth(double zoom) {
if (zoom > 0) {
if (smoothZoomer != null) {
smoothZoomer.stopZooming();
More information about the tiled-commit
mailing list