trackeditor: show cursor position in track coordinates
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9008 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 6e030c37764671a7af78932d546288c7213dbcf4 Former-commit-id: 88ce12ac844c550189d414725708abda1d8a1b7f
This commit is contained in:
parent
b0e080fa44
commit
a948df16e9
4 changed files with 96 additions and 21 deletions
|
@ -230,6 +230,8 @@ public class EditorFrame extends JFrame
|
|||
private final static String RECENT_FILES_MAX = "RecentFilesMax";
|
||||
private boolean interactiveFixes = false;
|
||||
private final static String INTERACTIVE_FIXES = "InteractiveFixes";
|
||||
private boolean cursorCoordinates = false;
|
||||
private final static String CURSOR_COORDINATES = "CursorCoordinates";
|
||||
|
||||
private TrackData trackData = null;
|
||||
private Vector<Surface> defaultSurfaces = new Vector<Surface>();
|
||||
|
@ -340,6 +342,7 @@ public class EditorFrame extends JFrame
|
|||
libDirectory = preferences.get(SD_LIB_DIRECTORY, null);
|
||||
recentFilesMax = Integer.parseInt(preferences.get(RECENT_FILES_MAX, "10"));
|
||||
interactiveFixes = preferences.getBoolean(INTERACTIVE_FIXES, false);
|
||||
cursorCoordinates = preferences.getBoolean(CURSOR_COORDINATES, false);
|
||||
|
||||
readDefaultSurfaces();
|
||||
readDefaultObjects();
|
||||
|
@ -460,6 +463,18 @@ public class EditorFrame extends JFrame
|
|||
preferences.putBoolean(INTERACTIVE_FIXES, interactiveFixes);
|
||||
}
|
||||
|
||||
public boolean getCursorCoordinates()
|
||||
{
|
||||
return cursorCoordinates;
|
||||
}
|
||||
|
||||
public void setCursorCoordinates(boolean value)
|
||||
{
|
||||
cursorCoordinates = value;
|
||||
|
||||
preferences.putBoolean(CURSOR_COORDINATES, cursorCoordinates);
|
||||
}
|
||||
|
||||
private void updateRecentFiles(String filename)
|
||||
{
|
||||
recentFiles.remove(filename);
|
||||
|
@ -1289,8 +1304,10 @@ public class EditorFrame extends JFrame
|
|||
setLibDirectory(preferencesDialog.getLibDirectory());
|
||||
setRecentFilesMax(preferencesDialog.getRecentFilesMax());
|
||||
setInteractiveFixes(preferencesDialog.getInteractiveFixes());
|
||||
setCursorCoordinates(preferencesDialog.getCursorCoordinates());
|
||||
readDefaultSurfaces();
|
||||
readDefaultObjects();
|
||||
view.redrawCircuit();
|
||||
if (view.segmentParamDialog != null)
|
||||
view.segmentParamDialog.refresh();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public class PreferencesDialog extends JDialog
|
|||
private JLabel recentFilesMaxLabel = null;
|
||||
private JTextField recentFilesMaxTextField = null;
|
||||
private JCheckBox interactiveFixesCheckBox = null;
|
||||
private JCheckBox cursorCoordinatesCheckBox = null;
|
||||
private JButton okButton = null;
|
||||
private JButton cancelButton = null;
|
||||
|
||||
|
@ -87,6 +88,7 @@ public class PreferencesDialog extends JDialog
|
|||
jPanel.add(getLibDirectoryButton(), null);
|
||||
jPanel.add(getRecentFilesMaxTextField(), null);
|
||||
jPanel.add(getInteractiveFixesCheckBox(), null);
|
||||
jPanel.add(getCursorCoordinatesCheckBox(), null);
|
||||
jPanel.add(getOkButton(), null);
|
||||
jPanel.add(getCancelButton(), null);
|
||||
}
|
||||
|
@ -266,6 +268,18 @@ public class PreferencesDialog extends JDialog
|
|||
return interactiveFixesCheckBox;
|
||||
}
|
||||
|
||||
private JCheckBox getCursorCoordinatesCheckBox()
|
||||
{
|
||||
if (cursorCoordinatesCheckBox == null)
|
||||
{
|
||||
cursorCoordinatesCheckBox = new JCheckBox();
|
||||
cursorCoordinatesCheckBox.setBounds(200, 161, 290, 23);
|
||||
cursorCoordinatesCheckBox.setText("Cursor Track Coordinates");
|
||||
cursorCoordinatesCheckBox.setSelected(editorFrame.getCursorCoordinates());
|
||||
}
|
||||
return cursorCoordinatesCheckBox;
|
||||
}
|
||||
|
||||
private JButton getOkButton()
|
||||
{
|
||||
if (okButton == null)
|
||||
|
@ -349,6 +363,11 @@ public class PreferencesDialog extends JDialog
|
|||
return getInteractiveFixesCheckBox().isSelected();
|
||||
}
|
||||
|
||||
public boolean getCursorCoordinates()
|
||||
{
|
||||
return getCursorCoordinatesCheckBox().isSelected();
|
||||
}
|
||||
|
||||
protected void processWindowEvent(WindowEvent e)
|
||||
{
|
||||
super.processWindowEvent(e);
|
||||
|
|
|
@ -17,6 +17,8 @@ import java.awt.event.KeyListener;
|
|||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
@ -87,7 +89,7 @@ import utils.undo.UndoSplitSegment;
|
|||
* @version 0.1a
|
||||
*/
|
||||
|
||||
public class CircuitView extends JComponent implements KeyListener, MouseListener, MouseMotionListener,WindowListener //,Scrollable
|
||||
public class CircuitView extends JComponent implements KeyListener, MouseListener, MouseMotionListener, WindowListener, MouseWheelListener
|
||||
{
|
||||
/** zooming factor */
|
||||
double zoomFactor = 1.0;
|
||||
|
@ -200,7 +202,9 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
|||
|
||||
/** upward link to parent frame */
|
||||
EditorFrame editorFrame;
|
||||
|
||||
|
||||
Graphics graphics = null;
|
||||
|
||||
private final String sep = System.getProperty("file.separator");
|
||||
|
||||
/**
|
||||
|
@ -216,7 +220,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
|||
addKeyListener(this);
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
//addMouseWheelListener( this );
|
||||
addMouseWheelListener(this);
|
||||
this.editorFrame = editorFrame;
|
||||
terrain = new ObjShapeTerrain();
|
||||
Editor.getProperties().addPropertiesListener(new ActionListener()
|
||||
|
@ -926,7 +930,13 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
|||
public void mouseMoved(MouseEvent e)
|
||||
{
|
||||
screenToReal(e, mousePoint);
|
||||
|
||||
|
||||
if (editorFrame.getCursorCoordinates())
|
||||
{
|
||||
invalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
switch (currentState)
|
||||
|
@ -1010,6 +1020,19 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
|||
}
|
||||
}
|
||||
|
||||
public void mouseWheelMoved(MouseWheelEvent e)
|
||||
{
|
||||
screenToReal(e, mousePoint);
|
||||
|
||||
getParent().dispatchEvent(e);
|
||||
|
||||
if (editorFrame.getCursorCoordinates())
|
||||
{
|
||||
invalidate();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
// /** input events management */
|
||||
// /*
|
||||
// * public void mouseWheelMoved( MouseWheelEvent e ) { int n =
|
||||
|
@ -1434,6 +1457,21 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
|||
*/
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
graphics = g;
|
||||
|
||||
// visible part of screen in pixels
|
||||
Rectangle r = getVisibleRect();
|
||||
|
||||
if (editorFrame.getCursorCoordinates())
|
||||
{
|
||||
if (editorFrame.getTrackData() != null)
|
||||
{
|
||||
String coordinates = String.format("x: %.3f y: %.3f", + mousePoint.x, + mousePoint.y);
|
||||
|
||||
graphics.drawString(coordinates, r.x + 10, r.y + 20);
|
||||
}
|
||||
}
|
||||
|
||||
if (editorFrame.getTrackData() != null && editorFrame.getTrackData().getSegments() != null)
|
||||
{
|
||||
if (boundingRectangle == null)
|
||||
|
@ -1441,9 +1479,6 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
|||
return;
|
||||
}
|
||||
|
||||
// visible part of screen in pixels
|
||||
Rectangle r = getVisibleRect();
|
||||
|
||||
// out zone size in meters
|
||||
outZoneWidth = (r.getWidth() / 2) / zoomFactor;
|
||||
outZoneHeight = (r.getHeight() / 2) / zoomFactor;
|
||||
|
@ -1774,18 +1809,8 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
|||
{
|
||||
ObjShapeObject object = objects.get(j);
|
||||
|
||||
Rectangle2D.Double rect = new Rectangle2D.Double(boundingRectangle.getMinX() - border,
|
||||
boundingRectangle.getMinY() - border,
|
||||
boundingRectangle.getWidth() + (border * 2),
|
||||
boundingRectangle.getHeight() + (border * 2));
|
||||
|
||||
double widthScale = rect.getWidth() / objectMap.getImageWidth();
|
||||
double heightScale = rect.getHeight() / objectMap.getImageHeight();
|
||||
|
||||
double worldX = rect.getMinX() + (object.getImageX() * widthScale);
|
||||
double worldY = rect.getMinY() + ((objectMap.getImageHeight() - object.getImageY()) * heightScale);
|
||||
|
||||
Point2D.Double location = new Point2D.Double(worldX, worldY);
|
||||
Point2D.Double location = new Point2D.Double();
|
||||
imageToReal(object.getImageX(), object.getImageY(), objectMap.getImageWidth(), objectMap.getImageHeight(), location);
|
||||
|
||||
object.calcShape(location);
|
||||
}
|
||||
|
@ -2689,7 +2714,21 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
|||
imageXY[0] = (int)Math.round(imageWidth * ((real.x + -rect.x) / rect.width));
|
||||
imageXY[1] = (int)Math.round(imageHeight * (1 - (((real.y + -rect.y) / rect.height))));
|
||||
}
|
||||
|
||||
|
||||
private void imageToReal(int imageX, int imageY, int imageWidth, int imageHeight, Point2D.Double real)
|
||||
{
|
||||
double border = editorFrame.getTrackData().getGraphic().getTerrainGeneration().getBorderMargin();
|
||||
Rectangle2D.Double rect = new Rectangle2D.Double(boundingRectangle.getMinX() - border,
|
||||
boundingRectangle.getMinY() - border,
|
||||
boundingRectangle.getWidth() + (border * 2),
|
||||
boundingRectangle.getHeight() + (border * 2));
|
||||
double widthScale = rect.getWidth() / imageWidth;
|
||||
double heightScale = rect.getHeight() / imageHeight;
|
||||
|
||||
real.x = rect.getMinX() + (imageX * widthScale);
|
||||
real.y = rect.getMinY() + ((imageHeight - imageY) * heightScale);
|
||||
}
|
||||
|
||||
private void noObjectSelected(MouseEvent me)
|
||||
{
|
||||
class AddNewAction extends AbstractAction
|
||||
|
|
|
@ -34,7 +34,7 @@ public class Properties
|
|||
private static Properties instance = new Properties();
|
||||
private Vector<ActionListener> propertiesListeners = new Vector<ActionListener>();
|
||||
public final String title = "sd2-trackeditor";
|
||||
public final String version = "1.2.47";
|
||||
public final String version = "1.2.48";
|
||||
private String path;
|
||||
|
||||
private double imageScale = 1;
|
||||
|
|
Loading…
Reference in a new issue