Added mouse coordinate info

This commit is contained in:
Brendan Robert 2016-04-09 10:43:35 -05:00
parent c2b3283601
commit 294fe817e9
9 changed files with 59 additions and 18 deletions

View File

@ -11,6 +11,8 @@
package org.badvision.outlaweditor;
import java.util.EnumMap;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.Menu;
import org.badvision.outlaweditor.data.xml.Image;
import org.badvision.outlaweditor.data.xml.PlatformData;
@ -52,4 +54,9 @@ public abstract class ImageEditor extends Editor<Image, ImageEditor.DrawMode> {
}
return null;
}
StringProperty cursorInfo = new SimpleStringProperty();
public StringProperty cursorInfoProperty() {
return cursorInfo;
}
}

View File

@ -18,6 +18,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.scene.Group;
@ -508,6 +510,12 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
}
}
}
StringProperty cursorInfo = new SimpleStringProperty();
public StringProperty cursorInfoProperty() {
return cursorInfo;
}
public static Rectangle selectRect = null;
public double selectStartX = 0;
public double selectStartY = 0;
@ -564,14 +572,15 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
@Override
public void handle(MouseEvent t) {
int x = (int) (t.getX() / tileWidth) + posX;
int y = (int) (t.getY() / tileHeight) + posY;
updateCursorAssistant(t);
cursorInfo.set("X="+x+" Y="+y);
if (!t.isPrimaryButtonDown() && drawMode != DrawMode.FilledRect && t.getEventType() != MouseEvent.MOUSE_RELEASED) return;
if (getCurrentTile() == null && drawMode != DrawMode.Eraser) {
return;
}
t.consume();
int x = (int) (t.getX() / tileWidth) + posX;
int y = (int) (t.getY() / tileHeight) + posY;
boolean canSkip = false;
if (getCurrentTile() == lastTile && x == lastX && y == lastY && drawMode == lastDrawMode) {
canSkip = true;

View File

@ -75,6 +75,7 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
redraw();
screen = new ImageView(currentImage);
anchorPane.getChildren().add(0, screen);
screen.setOnMouseMoved(this);
screen.setOnMousePressed(this);
screen.setOnMouseClicked(this);
screen.setOnMouseReleased(this);
@ -223,7 +224,13 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
@Override
public void handle(MouseEvent t) {
if (performAction(t.isShiftDown() || t.isSecondaryButtonDown(), t.getEventType().equals(MouseEvent.MOUSE_RELEASED), (int) t.getX() / xScale, (int) t.getY() / yScale)) {
int x = (int) t.getX() / xScale;
int y = (int) t.getY() / yScale;
cursorInfoProperty().set("X="+x+"("+(x/7)+","+(x%7)+") Y="+y);
if (t.getEventType().equals(MouseEvent.MOUSE_MOVED)) {
return;
}
if (performAction(t.isShiftDown() || t.isSecondaryButtonDown(), t.getEventType().equals(MouseEvent.MOUSE_RELEASED), x, y)) {
t.consume();
}
@ -424,6 +431,7 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
}
byte[] copyData = null;
@Override
public void copy() {
java.util.Map<DataFormat, Object> clip = new HashMap<>();
@ -482,7 +490,7 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
}
sourceData = platformData.getValue();
}
if ("all".equals(bufferDetails[1])) {
setData(Arrays.copyOf(sourceData, sourceData.length));
redraw();
@ -496,14 +504,14 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
int pasteX = lastActionX;
int pasteY = lastActionY;
// fix odd/even: Try to nudge left or right where it might work best.
if ((xStart%2) != pasteX %2) {
if (pasteX == 0 || pasteX % 7 > 3 || (pasteX + (xEnd-xStart)/7) < getWidth()) {
if ((xStart % 2) != pasteX % 2) {
if (pasteX == 0 || pasteX % 7 > 3 || (pasteX + (xEnd - xStart) / 7) < getWidth()) {
pasteX++;
} else {
pasteX--;
}
}
System.out.println("Paste to "+pasteX+","+pasteY);
System.out.println("Paste to " + pasteX + "," + pasteY);
for (int sourceY = yStart, targetY = pasteY; sourceY <= yEnd; sourceY++, targetY++) {
if (targetY < 0 || targetY >= getHeight()) {
continue;
@ -511,11 +519,11 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
int sourceRow = sourceY * getWidth();
int targetRow = targetY * getWidth();
for (int sourceX = xStart, targetX = pasteX; sourceX <= xEnd; sourceX++, targetX++) {
if (targetX < 0 || targetX/7 >= getWidth()) {
if (targetX < 0 || targetX / 7 >= getWidth()) {
continue;
}
int targetLoc = targetRow + targetX/7;
byte sourceByte = sourceData[sourceRow + sourceX/7];
int targetLoc = targetRow + targetX / 7;
byte sourceByte = sourceData[sourceRow + sourceX / 7];
byte targetByte = targetData[targetLoc];
int targetBit = targetX % 7;
int sourceBit = sourceX % 7;

View File

@ -10,6 +10,8 @@
package org.badvision.outlaweditor.ui;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Group;
@ -50,6 +52,8 @@ public abstract class ImageEditorTabController {
protected TextField imageWidthField; // Value injected by FXMLLoader
@FXML
protected Label zoomLabel;
@FXML
protected Label cursorInfo;
@FXML
public void initalize() {
@ -64,6 +68,7 @@ public abstract class ImageEditorTabController {
assert imageEditorZoomGroup != null : "fx:id\"imageEditorZoomGroup\" was not injected: check your FXML file 'imageEditorTab.fxml'";
assert imageEditorScrollAnchorPane != null : "fx:id\"imageEditorScrollAnchorPane\" was not injected: check your FXML file 'imageEditorTab.fxml'";
assert zoomLabel != null : "fx:id=\"zoomLabel\" was not injected: check your FXML file 'imageEditorTab.fxml'.";
assert cursorInfo != null : "fx:id=\"cursorInfo\" was not injected: check your FXML file 'imageEditorTab.fxml'.";
}
abstract public void rebuildImageSelector();

View File

@ -15,6 +15,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.Menu;
import javafx.scene.control.TextField;
@ -65,6 +66,8 @@ public abstract class MapEditorTabController {
protected CheckBox mapWrapAround; // Value injected by FXMLLoader
@FXML
protected Button scriptEraseTool;
@FXML
protected Label cursorInfo;
@FXML
abstract public void mapEraser(ActionEvent event);
@ -152,6 +155,7 @@ public abstract class MapEditorTabController {
assert mapSelectTile != null : "fx:id=\"mapSelectTile\" was not injected: check your FXML file 'mapEditorTab.fxml'.";
assert mapWidthField != null : "fx:id=\"mapWidthField\" was not injected: check your FXML file 'mapEditorTab.fxml'.";
assert mapWrapAround != null : "fx:id=\"mapWrapAround\" was not injected: check your FXML file 'mapEditorTab.fxml'.";
assert cursorInfo != null : "fx:id=\"cursorInfo\" was not injected: check your FXML file 'imageEditorTab.fxml'.";
}
abstract public void rebuildTileSelectors();

View File

@ -11,10 +11,8 @@ package org.badvision.outlaweditor.ui.impl;
import java.util.EnumMap;
import java.util.List;
import org.badvision.outlaweditor.ui.EntitySelectorCell;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
@ -22,16 +20,16 @@ import javafx.scene.control.ListView;
import javafx.util.StringConverter;
import javax.xml.bind.JAXBException;
import org.badvision.outlaweditor.Application;
import static org.badvision.outlaweditor.Application.currentPlatform;
import org.badvision.outlaweditor.Editor;
import org.badvision.outlaweditor.ImageEditor;
import static org.badvision.outlaweditor.Application.currentPlatform;
import org.badvision.outlaweditor.TransferHelper;
import static org.badvision.outlaweditor.ui.UIAction.confirm;
import static org.badvision.outlaweditor.data.PropertyHelper.bind;
import static org.badvision.outlaweditor.data.PropertyHelper.stringProp;
import org.badvision.outlaweditor.data.xml.GameData;
import org.badvision.outlaweditor.data.xml.Image;
import org.badvision.outlaweditor.ui.EntitySelectorCell;
import org.badvision.outlaweditor.ui.ImageEditorTabController;
import static org.badvision.outlaweditor.ui.UIAction.confirm;
/**
* FXML Controller class
@ -205,6 +203,8 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
if (currentImageEditor != null) {
oldEditorState = currentImageEditor.getState();
currentImageEditor.unregister();
cursorInfo.textProperty().unbind();
cursorInfo.setText("");
}
if (i == null) {
bind(imageCategoryField.textProperty(), null);
@ -216,6 +216,8 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
imageNameField.setDisable(true);
imageWidthField.setDisable(true);
currentImageEditor = null;
cursorInfo.textProperty().unbind();
cursorInfo.setText("");
} else {
if (i.getName() == null) {
i.setName("Untitled");
@ -246,6 +248,7 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
currentImageEditor.setState(oldEditorState);
}
}
cursorInfo.textProperty().bind(currentImageEditor.cursorInfoProperty());
}
private Image getCurrentImage() {

View File

@ -286,6 +286,8 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
mapWidthField.setDisable(true);
mapWrapAround.setDisable(true);
setCurrentEditor(null);
cursorInfo.textProperty().unbind();
cursorInfo.setText("");
} else {
if (m.getScripts() != null) {
DataUtilities.sortNamedEntities(m.getScripts().getScript());
@ -321,6 +323,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
if (currentTile != null) {
e.setCurrentTile(currentTile);
}
cursorInfo.textProperty().bind(e.cursorInfoProperty());
}
redrawMapScripts();
}

View File

@ -7,14 +7,14 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="tilesTab" minHeight="0.0" minWidth="0.0" prefHeight="420.0" prefWidth="677.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.ImageEditorTabControllerImpl">
<AnchorPane id="tilesTab" minHeight="0.0" minWidth="0.0" prefHeight="420.0" prefWidth="677.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.ImageEditorTabControllerImpl">
<children>
<VBox prefHeight="420.0000999999975" prefWidth="677.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<ToolBar prefWidth="686.0">
<items>
<Label text="Image:" />
<ComboBox id="tileSelect" fx:id="imageSelector" onAction="#onImageSelected" prefHeight="26.0" prefWidth="271.0" />
<ComboBox id="tileSelect" fx:id="imageSelector" onAction="#onImageSelected" prefHeight="27.0" prefWidth="242.0" />
<Button mnemonicParsing="false" onAction="#onImageCreatePressed" text="Create new" />
<Button mnemonicParsing="false" onAction="#onImageClonePressed" text="Clone" />
<Button mnemonicParsing="false" onAction="#onImageExportPressed" text="Export" />
@ -35,6 +35,7 @@
<MenuItem mnemonicParsing="false" onAction="#imageShift" text="Shift..." />
</items>
</MenuButton>
<Label fx:id="cursorInfo" text="cursorInfo" />
</items>
</ToolBar>
<HBox prefHeight="387.0" prefWidth="677.0" VBox.vgrow="ALWAYS">

View File

@ -4,7 +4,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="mapsTab" minHeight="0.0" minWidth="0.0" prefHeight="480.0" prefWidth="677.0" stylesheets="@styles/applicationui.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.MapEditorTabControllerImpl">
<AnchorPane id="mapsTab" minHeight="0.0" minWidth="0.0" prefHeight="480.0" prefWidth="677.0" stylesheets="@styles/applicationui.css" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.MapEditorTabControllerImpl">
<children>
<VBox prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
@ -32,6 +32,7 @@
<MenuItem mnemonicParsing="false" onAction="#mapTogglePanZoom" text="Toggle pan/zoom controls" />
</items>
</MenuButton>
<Label fx:id="cursorInfo" text="CursorInfo" />
</items>
</ToolBar>
<HBox prefHeight="438.0" prefWidth="677.0" VBox.vgrow="ALWAYS">