No functional change, just cleaning up code format and removing unused imports

This commit is contained in:
Brendan Robert 2014-05-25 00:29:58 -05:00
parent fecfb0a477
commit 4b8b18f865
35 changed files with 273 additions and 223 deletions

View File

@ -26,12 +26,14 @@ public class Application extends javafx.application.Application {
}
private ApplicationUIController controller;
public ApplicationUIController getController() {
return controller;
}
public Stage primaryStage;
public static Stage getPrimaryStage() {
public Stage primaryStage;
public static Stage getPrimaryStage() {
return instance.primaryStage;
}
@ -51,7 +53,7 @@ public static Stage getPrimaryStage() {
} catch (IOException exception) {
throw new RuntimeException(exception);
}
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(final WindowEvent t) {
@ -73,4 +75,4 @@ public static Stage getPrimaryStage() {
public static void main(String[] args) {
launch(args);
}
}
}

View File

@ -6,31 +6,44 @@ import org.badvision.outlaweditor.data.DataProducer;
import org.badvision.outlaweditor.data.xml.Script;
/**
* Extremely generic editor abstraction -- useful for uniform edit features across application
* Extremely generic editor abstraction -- useful for uniform edit features
* across application
*
* @author brobert
*/
public abstract class Editor<T,D> implements DataObserver<T> {
public abstract class Editor<T, D> implements DataObserver<T> {
T editEntity;
public void setEntity(T t) {
editEntity = t;
DataProducer.addObserver(t, this);
}
public T getEntity() {
return editEntity;
}
abstract public void setDrawMode(D drawMode);
abstract public void showShiftUI();
abstract public void buildEditorUI(AnchorPane tileEditorAnchorPane);
abstract public void unregister();
abstract public void copy();
abstract public void paste();
abstract public void select();
abstract public void selectNone();
int startX = 0;
int startY = 0;
int endX = 0;
int endY = 0;
public void setSelectionArea(int x1, int y1, int x2, int y2) {
startX = Math.min(x1, x2);
startY = Math.min(y1, y2);
@ -39,20 +52,22 @@ public abstract class Editor<T,D> implements DataObserver<T> {
if (startX + startY + endX + endY == 0) {
selectInfo = null;
} else {
selectInfo="x1/"+startX+"/y1/"+startY+"/x2/"+endX+"/y2/"+endY;
selectInfo = "x1/" + startX + "/y1/" + startY + "/x2/" + endX + "/y2/" + endY;
}
}
public String getSelectedAllInfo() {
return "all";
}
String selectInfo;
public String getSelectionInfo() {
if (selectInfo == null) {
return getSelectedAllInfo();
}
return selectInfo;
};
}
public void addScript(Script script) {
throw new UnsupportedOperationException("Not supported yet.");

View File

@ -24,7 +24,7 @@ public class FileUtils {
XML("XML files", "xml"),
TILESET("Tileset", "ots"),
ALL("All files", "*"),
ALL("All files", "*"),
BINARY("Binary", "bin");
String description;
String extension;
@ -55,7 +55,7 @@ public class FileUtils {
if (create) {
File file = f.showSaveDialog(Application.getPrimaryStage());
if (!file.getName().contains(".")) {
return new File(file.getParentFile(), file.getName()+"."+supportedExtensions[0].extension);
return new File(file.getParentFile(), file.getName() + "." + supportedExtensions[0].extension);
} else {
return file;
}

View File

@ -5,32 +5,35 @@ import org.badvision.outlaweditor.data.xml.Image;
/**
* Details about part of an image
*
* @author blurry
* @param <T> Represents the image renderer that can produce this image
*/
public class ImageClip<T extends ImageRenderer> {
private final int clipId;
private Rectangle bounds;
private Image source;
private ImageRenderer renderer;
private Platform platform;
private boolean allSelected;
public ImageClip(Image src, boolean all, ImageRenderer r, Platform p) {
source = src;
renderer = r;
platform = p;
clipId = (int) (Math.random() * (double) Integer.MAX_VALUE);
clipId = (int) (Math.random() * (double) Integer.MAX_VALUE);
}
public ImageClip(Image src, int x1, int y1, int x2, int y2, ImageRenderer r, Platform p) {
this(src, false, r, p);
bounds = new Rectangle(
Math.min(x1,x2),
Math.min(y1,y2),
Math.abs(x2-x1),
Math.abs(y2-y1));
Math.min(x1, x2),
Math.min(y1, y2),
Math.abs(x2 - x1),
Math.abs(y2 - y1));
}
/**
* @return the clipId
*/

View File

@ -13,14 +13,14 @@ import org.badvision.outlaweditor.data.xml.PlatformData;
* @author brobert
*/
public abstract class ImageEditor extends Editor<Image, ImageEditor.DrawMode> {
public static enum DrawMode {
Toggle, Pencil1px, Pencil3px, Pencil5px, Rectangle, Circle, Stamp
}
abstract public void buildPatternSelector(Menu tilePatternMenu);
abstract public void redraw();
public abstract void scrollBy(int deltaX, int deltaY);
public abstract void togglePanZoom();
@ -28,12 +28,12 @@ public abstract class ImageEditor extends Editor<Image, ImageEditor.DrawMode> {
public abstract void zoomIn();
public abstract void zoomOut();
public abstract void exportImage();
public abstract void resize(int newWidth, int newHeight);
public PlatformData getPlatformData(Platform p) {
public PlatformData getPlatformData(Platform p) {
for (PlatformData data : getEntity().getDisplayData()) {
if (data.getPlatform().equalsIgnoreCase(p.name())) {
return data;

View File

@ -2,15 +2,10 @@ package org.badvision.outlaweditor;
import javafx.scene.image.WritableImage;
import org.badvision.outlaweditor.data.TileMap;
import org.badvision.outlaweditor.data.xml.Map;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author brobert
*/
public abstract class ImageRenderer {
@ -22,5 +17,5 @@ public abstract class ImageRenderer {
public abstract byte[] renderPreview(TileMap map, int startX, int startY, int width, int height);
public abstract WritableImage renderScanline(WritableImage currentImage, int y, int width, byte[] imageData);
}

View File

@ -20,11 +20,8 @@ import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.input.Clipboard;
import javafx.scene.input.DataFormat;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
@ -60,10 +57,11 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
super.setEntity(t);
currentMap = new TileMap(t);
}
public TileMap getCurrentMap() {
return currentMap;
}
EventHandler<ScrollEvent> scrollHandler = new EventHandler<ScrollEvent>() {
@Override
public void handle(ScrollEvent t) {
@ -136,7 +134,7 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
}
getCurrentMap().getBackingMap().getScripts().getScript().add(script);
}
public void assignScript(Script script, double x, double y) {
System.out.println("Dropped " + script.getName() + " at " + x + "," + y);
}

View File

@ -48,7 +48,7 @@ public class MythosEditor {
primaryStage = new Stage();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/MythosScriptEditor.fxml"));
Map<String,String> properties = new HashMap<>();
Map<String, String> properties = new HashMap<>();
properties.put(MythosScriptEditorController.ONLOAD_SCRIPT, generateLoadScript());
fxmlLoader.setResources(MythosScriptEditorController.createResourceBundle(properties));
try {
@ -103,13 +103,13 @@ public class MythosEditor {
try {
JAXBContext context = JAXBContext.newInstance(Block.class);
StringWriter buffer = new StringWriter();
QName qName = new QName("outlaw","block");
JAXBElement<Block> root = new JAXBElement<>(qName, Block.class, script.getBlock());
QName qName = new QName("outlaw", "block");
JAXBElement<Block> root = new JAXBElement<>(qName, Block.class, script.getBlock());
context.createMarshaller().marshal(root, buffer);
String xml = buffer.toString();
xml=xml.replace("?>", "?><xml>");
xml = xml.replace("?>", "?><xml>");
xml += "</xml>";
System.out.println("xml: "+xml);
System.out.println("xml: " + xml);
return generateLoadScript(xml);
} catch (JAXBException ex) {
Logger.getLogger(MythosEditor.class.getName()).log(Level.SEVERE, null, ex);
@ -121,22 +121,22 @@ public class MythosEditor {
public String generateLoadScript(String xml) {
xml = xml.replaceAll("'", "\\'");
xml = xml.replaceAll("\n", "");
String loadScript = "Mythos.setScriptXml('"+xml+"');";
String loadScript = "Mythos.setScriptXml('" + xml + "');";
return loadScript;
}
private String getDefaultBlockMarkup() {
return XML_HEADER+"<xml><block type=\"procedures_defreturn\" id=\"1\" inline=\"false\" x=\"5\" y=\"5\"><mutation></mutation><field name=\"NAME\">NewScript</field></block></xml>";
return XML_HEADER + "<xml><block type=\"procedures_defreturn\" id=\"1\" inline=\"false\" x=\"5\" y=\"5\"><mutation></mutation><field name=\"NAME\">NewScript</field></block></xml>";
}
// Called when the name of the root block is changed in the JS editor
public void setFunctionName(String name) {
if (script == null) {
System.out.println("How can the script be null?? wanted to set script name to "+name);
System.out.println("How can the script be null?? wanted to set script name to " + name);
return;
}
script.setName(name);
System.out.println("Function title changed! >> "+name);
System.out.println("Function title changed! >> " + name);
ApplicationUIController.getController().redrawScripts();
}
}

View File

@ -11,13 +11,15 @@ import org.badvision.outlaweditor.apple.dhgr.AppleDHGRTileRenderer;
/**
* Enumeration of platforms
*
* @author brobert
*/
public enum Platform {
AppleII(AppleTileEditor.class, AppleImageEditor.class, new AppleTileRenderer(), new AppleImageRenderer(),2, 16, 40, 192),
AppleII_DHGR(AppleDHGRTileEditor.class, AppleDHGRImageEditor.class, new AppleDHGRTileRenderer(), new AppleDHGRImageRenderer(),4, 16, 80, 192),
AppleII(AppleTileEditor.class, AppleImageEditor.class, new AppleTileRenderer(), new AppleImageRenderer(), 2, 16, 40, 192),
AppleII_DHGR(AppleDHGRTileEditor.class, AppleDHGRImageEditor.class, new AppleDHGRTileRenderer(), new AppleDHGRImageRenderer(), 4, 16, 80, 192),
C64(null, null, null, null, 16, 16, 40, 200);
public Class<? extends TileEditor> tileEditor;
public Class<? extends ImageEditor> imageEditor;
public TileRenderer tileRenderer;
@ -26,7 +28,7 @@ public enum Platform {
public int dataHeight;
public int maxImageWidth;
public int maxImageHeight;
Platform(Class ed, Class imged, TileRenderer ren, ImageRenderer img, int w, int h, int maxW, int maxH) {
tileEditor = ed;
imageEditor = imged;

View File

@ -8,9 +8,11 @@ import javafx.scene.control.Menu;
import org.badvision.outlaweditor.data.xml.Tile;
public abstract class TileEditor extends Editor<Tile, TileEditor.DrawMode> {
abstract public void buildPatternSelector(Menu tilePatternMenu);
public static enum DrawMode {
Pencil1px, Pencil3px, Toggle
}
}

View File

@ -9,6 +9,8 @@ import javafx.scene.image.WritableImage;
public abstract class TileRenderer {
public abstract WritableImage redrawSprite(byte[] spriteData, WritableImage image);
public abstract int getWidth();
public abstract int getHeight();
}

View File

@ -27,6 +27,7 @@ public class TransferHelper<T> {
static Map<String, DataFormat> dataFormats = new HashMap<>();
public interface DropEventHandler<T> {
public void handle(T object, double x, double y);
}
@ -65,6 +66,7 @@ public class TransferHelper<T> {
}
});
}
public void registerDropSupport(final Node target, final DropEventHandler<T> handler) {
target.setOnDragOver(new EventHandler<DragEvent>() {
@Override

View File

@ -228,8 +228,8 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
switch (currentDrawMode) {
case Toggle:
if (canSkip) {
return false;
}
return false;
}
if (alt) {
toggleHiBit(x, y);
} else {
@ -239,31 +239,31 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
break;
case Pencil1px:
if (canSkip) {
return false;
}
return false;
}
plot(x, y, currentFillPattern, hiBitMatters); // [ref BigBlue1_30]
redrawScanline(y);
break;
case Pencil3px:
if (canSkip) {
return false;
}
return false;
}
drawBrush(x, y, 3, currentFillPattern, hiBitMatters);
break;
case Pencil5px:
if (canSkip) {
return false;
}
return false;
}
drawBrush(x, y, 5, currentFillPattern, hiBitMatters);
break;
case Rectangle:
if (released) {
fillSelection(x, y);
redraw();
debounce = System.currentTimeMillis();
} else {
updateSelection(x, y);
}
fillSelection(x, y);
redraw();
debounce = System.currentTimeMillis();
} else {
updateSelection(x, y);
}
break;
}
return true;
@ -409,8 +409,8 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
byte[] buf = getPlatform().imageRenderer.renderPreview(
map,
details.get("x1"),
details.get("y1"),
getWidth(),
details.get("y1"),
getWidth(),
getHeight());
setData(buf);
redraw();

View File

@ -18,16 +18,17 @@ import org.badvision.outlaweditor.data.xml.Tile;
* @author brobert
*/
public class AppleImageRenderer extends ImageRenderer {
//
public static int BLACK = 0xff000000;
public static int WHITE = 0xffffffff;
// scanline is 20 16-bit words
// If mixed-mode is used then useColor needs to be an 80-boolean array indicating which bytes are supposed to be BW
@Override
public byte[] createImageBuffer(int width, int height) {
return new byte[width * height];
}
}
@Override
public byte[] renderPreview(TileMap map, int startX, int startY, int width, int height) {
byte[] buffer = createImageBuffer(width, height);
@ -62,15 +63,15 @@ public class AppleImageRenderer extends ImageRenderer {
if (img == null) {
img = new WritableImage(width * 14, height * 2);
}
for (int y = 0; y < height; y++) {
for (int y = 0; y < height; y++) {
renderScanline(img, y, width, rawImage);
}
return img;
}
@Override
public WritableImage renderScanline(WritableImage img, int y, int width, byte[] rawImage) {
int[] scanline = new int[width/2 + 1];
public WritableImage renderScanline(WritableImage img, int y, int width, byte[] rawImage) {
int[] scanline = new int[width / 2 + 1];
boolean extraHalfBit = false;
for (int x = 0; x < width; x += 2) {
int b1 = rawImage[y * width + x] & 255;
@ -83,9 +84,9 @@ public class AppleImageRenderer extends ImageRenderer {
renderScanline(img.getPixelWriter(), y * 2 + 1, scanline, true, false, width);
return img;
}
public static void renderScanline(PixelWriter img, int y, int[] scanline, boolean hiresMode, boolean mixedMode, int width, boolean... useColor) {
int scanlineLength = Math.min(width/2, scanline.length);
public static void renderScanline(PixelWriter img, int y, int[] scanline, boolean hiresMode, boolean mixedMode, int width, boolean... useColor) {
int scanlineLength = Math.min(width / 2, scanline.length);
int[][] activePalette = AppleTileRenderer.useSolidPalette ? solidPalette : textPalette;
int byteCounter = 0;
int x = 0;

View File

@ -5,8 +5,10 @@ package org.badvision.outlaweditor.apple;
* @author brobert
*/
public class AppleNTSCGraphics {
// i Range [-0.5957, 0.5957]
public static final double MAX_I = 0.5957;
// q Range [-0.5226, 0.5226]
public static final double MAX_Q = 0.5226;
public static final double MAX_Y = 1;

View File

@ -10,16 +10,20 @@ import static org.badvision.outlaweditor.apple.AppleNTSCGraphics.*;
* @author brobert
*/
public class AppleTileRenderer extends TileRenderer {
public static boolean useSolidPalette = true;
public static boolean useSolidPalette = true;
@Override
public WritableImage redrawSprite(byte[] spriteData, WritableImage img) {
if (img == null) {
img = new WritableImage(28, 32);
}
if (spriteData == null) return img;
if (spriteData == null) {
return img;
}
int[][] palette = useSolidPalette ? solidPalette : textPalette;
for (int y = 0; y < 16; y++) {
int bleedOver = (spriteData[y * 2 + 1] & 192)==192 ? 256 : 0;
int bleedOver = (spriteData[y * 2 + 1] & 192) == 192 ? 256 : 0;
int scan = hgrToDhgr[bleedOver | (spriteData[y * 2] & 255)][spriteData[y * 2 + 1] & 255];
int last = (scan >> 26) & 3;
int keep = scan & 0xff;
@ -27,7 +31,7 @@ public class AppleTileRenderer extends TileRenderer {
scan |= last;
for (int x = 0; x < 14; x++) {
boolean isHiBit = ((spriteData[y * 2 + x / 7] & 128) != 0);
int col1 = palette[ (x & 1) << 1][scan & 0x07f];
Color color1 = Color.rgb(getRed(col1), getGreen(col1), getBlue(col1));
scan >>= 1;
@ -55,4 +59,4 @@ public class AppleTileRenderer extends TileRenderer {
public int getHeight() {
return 32;
}
}
}

View File

@ -24,7 +24,8 @@ import org.badvision.outlaweditor.data.xml.Tile;
* @author brobert
*/
public enum FillPattern {
Violet(true, 2, false,
Violet(true, 2, false,
"+-+-+-+-+-+-+-"),
DarkViolet1(true, 4, false,
"+---+---+---+---+---+---+---",
@ -37,12 +38,12 @@ public enum FillPattern {
LightViolet1(true, 4, false,
"+++-+++-+++-+++-+++-+++-+++-",
"+-+++-+++-+++-+++-+++-+++-++"
),
),
LightViolet2(true, 4, false,
"+-+++-+++-+++-+++-+++-+++-++",
"+++-+++-+++-+++-+++-+++-+++-"
),
Green(true, 2, false,
),
Green(true, 2, false,
"-+-+-+-+-+-+-+"),
DarkGreen1(true, 4, false,
"-+---+---+---+---+---+---+--",
@ -55,11 +56,11 @@ public enum FillPattern {
LightGreen1(true, 4, false,
"++-+++-+++-+++-+++-+++-+++-+",
"-+++-+++-+++-+++-+++-+++-+++"
),
),
LightGreen2(true, 4, false,
"-+++-+++-+++-+++-+++-+++-+++",
"++-+++-+++-+++-+++-+++-+++-+"),
Blue(true, 2, true,
Blue(true, 2, true,
"+-+-+-+-+-+-+-"),
DarkBlue(true, 4, true,
"+---+---+---+---+---+---+---",
@ -72,12 +73,12 @@ public enum FillPattern {
LightBlue1(true, 4, true,
"+++-+++-+++-+++-+++-+++-+++-",
"+-+++-+++-+++-+++-+++-+++-++"
),
),
LightBlue2(true, 4, true,
"+-+++-+++-+++-+++-+++-+++-++",
"+++-+++-+++-+++-+++-+++-+++-"
),
Orange(true, 2, true,
),
Orange(true, 2, true,
"-+-+-+-+-+-+-+"),
DarkOrange1(true, 4, true,
"-+---+---+---+---+---+---+--",
@ -90,17 +91,17 @@ public enum FillPattern {
LightOrange1(true, 4, true,
"++-+++-+++-+++-+++-+++-+++-+",
"-+++-+++-+++-+++-+++-+++-+++"
),
),
LightOrange2(true, 4, true,
"-+++-+++-+++-+++-+++-+++-+++",
"++-+++-+++-+++-+++-+++-+++-+"),
Black(false, 1, false, "-------"),
White(false, 1, false, "+++++++"),
BW1(false, 4, false,
BW1(false, 4, false,
"++--++--++--++--++--++--++--",
"--++--++--++--++--++--++--++"
),
BW2(false, 4, false,
BW2(false, 4, false,
"--++--++--++--++--++--++--++",
"++--++--++--++--++--++--++--"
);
@ -115,11 +116,11 @@ public enum FillPattern {
// );
public static int[] bitmask(boolean hiBit, String pattern) {
int[] out = new int[pattern.length()/7];
int[] out = new int[pattern.length() / 7];
int place = 1;
int pos = 0;
int value = hiBit ? 128 : 0;
for (int i=0; i < pattern.length(); i++) {
for (int i = 0; i < pattern.length(); i++) {
char c = pattern.charAt(i);
if (c == '1' || c == '+') {
value |= place;
@ -134,7 +135,7 @@ public enum FillPattern {
}
return out;
}
public static Integer[] buildPattern(boolean hiBit, String... pattern) {
List<Integer> out = new ArrayList<>();
for (String s : pattern) {
@ -144,11 +145,11 @@ public enum FillPattern {
}
return out.toArray(new Integer[0]);
}
public static void buildMenu(Menu target, final DataObserver<FillPattern> dataObserver) {
target.getItems().clear();
for (final FillPattern fill : FillPattern.values()) {
MenuItem i = new MenuItem(fill.name(), new ImageView(fill.getPreview()));
MenuItem i = new MenuItem(fill.name(), new ImageView(fill.getPreview()));
i.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
@ -165,7 +166,7 @@ public enum FillPattern {
WritableImage preview;
private FillPattern(boolean hiBitMatters, int width, boolean hiBit, String... pattern) {
this.pattern = buildPattern(hiBit, pattern);
this.pattern = buildPattern(hiBit, pattern);
this.width = width;
this.hiBitMatters = hiBitMatters;
this.bytePattern = getBytePattern();
@ -177,7 +178,7 @@ public enum FillPattern {
}
return preview;
}
public int[] getBytePattern() {
int[] out = new int[16 * 4];
int pos = 0;

View File

@ -5,8 +5,6 @@ import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
@ -155,15 +153,15 @@ public class FloydSteinbergDither {
}
void hiresDither(final byte[] screen, int y, int x, int[] scanline, List<Integer> pixels, WritableImage tmpScaled, int pass, final WritableImage keepScaled) {
int bb1 = screen[(y+startY) * bufferWidth + startX + x] & 255;
int bb2 = screen[(y+startY) * bufferWidth + startX + x + 1] & 255;
int bb1 = screen[(y + startY) * bufferWidth + startX + x] & 255;
int bb2 = screen[(y + startY) * bufferWidth + startX + x + 1] & 255;
int next = bb2 & 127; // Preserve hi-bit so last pixel stays solid, it is a very minor detail
int prev = 0;
if ((x+startX) > 0) {
prev = screen[(y+startY) * bufferWidth + startX + x - 1] & 255;
if ((x + startX) > 0) {
prev = screen[(y + startY) * bufferWidth + startX + x - 1] & 255;
}
if ((x+startX) < 38) {
next = screen[(y+startY) * bufferWidth + startX + x + 2] & 255;
if ((x + startX) < 38) {
next = screen[(y + startY) * bufferWidth + startX + x + 2] & 255;
}
// First byte, compared with a sliding window encompassing the previous byte, if any.
int leastError = Integer.MAX_VALUE;
@ -267,8 +265,8 @@ public class FloydSteinbergDither {
tmpScaled.getPixelWriter().setPixels(0, y, 560, (y < 191) ? 2 : 1, keepScaled.getPixelReader(), 0, y);
}
}
screen[(y+startY) * bufferWidth + startX + x] = (byte) bb1;
screen[(y+startY) * bufferWidth + startX + x + 1] = (byte) bb2;
screen[(y + startY) * bufferWidth + startX + x] = (byte) bb1;
screen[(y + startY) * bufferWidth + startX + x + 1] = (byte) bb2;
}
void doubleHiresDither(final byte[] screen, int y, int x, int[] scanline, List<Integer> pixels, WritableImage tmpScaled, int pass, final WritableImage keepScaled) {
@ -293,58 +291,58 @@ public class FloydSteinbergDither {
for (int xx = 0; xx < 4; xx++) {
// First byte, compared with a sliding window encompassing the previous byte, if any.
int leastError = Integer.MAX_VALUE;
int b1 = (bytes[xx] & 0x07f);
for (int c = 0; c < 7; c++) {
int on = b1 | (1 << c);
int off = on ^ (1 << c);
// get values for "off"
int i = (xx == 3) ? off : bytes[3] & 255;
i <<= 7;
i |= (xx == 2) ? off : bytes[2] & 255;
i <<= 7;
i |= (xx == 1) ? off : bytes[1] & 255;
i <<= 7;
i |= (xx == 0) ? off : bytes[0] & 255;
scanline[1] = i;
int errorOff = getError((x + xx) * 7 - overlap + c, y, 28 + (xx * 7) + c - overlap + pixelShift, errorWindow, pixels, tmpScaled.getPixelReader(), scanline);
int off1 = pixels.get(xx * 7 + c + 28 + pixelShift);
// get values for "on"
i = (xx == 3) ? on : bytes[3] & 255;
i <<= 7;
i |= (xx == 2) ? on : bytes[2] & 255;
i <<= 7;
i |= (xx == 1) ? on : bytes[1] & 255;
i <<= 7;
i |= (xx == 0) ? on : bytes[0] & 255;
scanline[1] = i;
int errorOn = getError((x + xx) * 7 - overlap + c, y, 28 + (xx * 7) + c - overlap + pixelShift, errorWindow, pixels, tmpScaled.getPixelReader(), scanline);
int on1 = pixels.get(xx * 7 + c + 28 + pixelShift);
int b1 = (bytes[xx] & 0x07f);
for (int c = 0; c < 7; c++) {
int on = b1 | (1 << c);
int off = on ^ (1 << c);
// get values for "off"
int i = (xx == 3) ? off : bytes[3] & 255;
i <<= 7;
i |= (xx == 2) ? off : bytes[2] & 255;
i <<= 7;
i |= (xx == 1) ? off : bytes[1] & 255;
i <<= 7;
i |= (xx == 0) ? off : bytes[0] & 255;
scanline[1] = i;
int errorOff = getError((x + xx) * 7 - overlap + c, y, 28 + (xx * 7) + c - overlap + pixelShift, errorWindow, pixels, tmpScaled.getPixelReader(), scanline);
int off1 = pixels.get(xx * 7 + c + 28 + pixelShift);
// get values for "on"
i = (xx == 3) ? on : bytes[3] & 255;
i <<= 7;
i |= (xx == 2) ? on : bytes[2] & 255;
i <<= 7;
i |= (xx == 1) ? on : bytes[1] & 255;
i <<= 7;
i |= (xx == 0) ? on : bytes[0] & 255;
scanline[1] = i;
int errorOn = getError((x + xx) * 7 - overlap + c, y, 28 + (xx * 7) + c - overlap + pixelShift, errorWindow, pixels, tmpScaled.getPixelReader(), scanline);
int on1 = pixels.get(xx * 7 + c + 28 + pixelShift);
int[] col1;
if (errorOff < errorOn) {
int[] col1;
if (errorOff < errorOn) {
// totalError += errorOff;
b1 = off;
col1 = Palette.parseIntColor(off1);
} else {
b1 = off;
col1 = Palette.parseIntColor(off1);
} else {
// totalError += errorOn;
b1 = on;
col1 = Palette.parseIntColor(on1);
}
if (pass >= nonErrorPasses) {
propagateError((x + xx) * 7 + c, y, tmpScaled, col1, false, false);
}
b1 = on;
col1 = Palette.parseIntColor(on1);
}
if (pass >= nonErrorPasses) {
propagateError((x + xx) * 7 + c, y, tmpScaled, col1, false, false);
}
}
// if (totalError < leastError) {
keepScaled.getPixelWriter().setPixels(0, y, 560, (y < 191) ? 2 : 1, tmpScaled.getPixelReader(), 0, y);
keepScaled.getPixelWriter().setPixels(0, y, 560, (y < 191) ? 2 : 1, tmpScaled.getPixelReader(), 0, y);
// leastError = totalError;
bytes[xx] = b1;
bytes[xx] = b1;
// } else {
// tmpScaled.getPixelWriter().setPixels(0, y, 560, (y < 191) ? 2 : 1, keepScaled.getPixelReader(), 0, y);
}
screen[(y+startY) * bufferWidth + startX + x] = (byte) bytes[0];
screen[(y+startY) * bufferWidth + startX + x + 1] = (byte) bytes[1];
screen[(y+startY) * bufferWidth + startX + x + 2] = (byte) bytes[2];
screen[(y+startY) * bufferWidth + startX + x + 3] = (byte) bytes[3];
screen[(y + startY) * bufferWidth + startX + x] = (byte) bytes[0];
screen[(y + startY) * bufferWidth + startX + x + 1] = (byte) bytes[1];
screen[(y + startY) * bufferWidth + startX + x + 2] = (byte) bytes[2];
screen[(y + startY) * bufferWidth + startX + x + 3] = (byte) bytes[3];
}
});
t.start();
@ -478,4 +476,4 @@ public class FloydSteinbergDither {
c.snapshot(sp, newImg);
return newImg;
}
}
}

View File

@ -4,31 +4,32 @@ import java.util.ArrayList;
import java.util.List;
public abstract class Palette {
public int MATCH_TOLERANCE = 0;
List colors = null;
public static int COLOR_DISTANCE_MAX = 0x2f708fd;
public Palette() {
MATCH_TOLERANCE = 64;
colors = new ArrayList();
initPalette();
}
protected abstract void initPalette();
public int[] getColor(int col) {
return (int[])colors.get(col);
return (int[]) colors.get(col);
}
public int getColorInt(int c) {
int col[] = getColor(c);
return toRGBInt(col);
}
public void addColor(int col[]) {
/* 45*/ colors.add(col);
/* 45*/ colors.add(col);
}
public void addColor(int r, int g, int b) {
int col[] = new int[3];
col[0] = r;
@ -36,53 +37,61 @@ public abstract class Palette {
col[2] = b;
addColor(col);
}
public int findColor(int color) {
int col[] = parseIntColor(color);
return findColor(col);
}
public static int[] parseIntColor(int color) {
return new int[] {getR(color), getG(color), getB(color)};
return new int[]{getR(color), getG(color), getB(color)};
}
public static int toRGBInt(int[] col) {
public static int toRGBInt(int[] col) {
return 0x10000 * col[0] + 256 * col[1] + col[2];
}
public int findColor(int color[]) {
int lastDiff = COLOR_DISTANCE_MAX;
int bestFit = 0;
for(int i = 0; i < colors.size(); i++) {
int test[] = (int[])colors.get(i);
int diff = (int)distance(color, test);
if(diff < lastDiff) {
for (int i = 0; i < colors.size(); i++) {
int test[] = (int[]) colors.get(i);
int diff = (int) distance(color, test);
if (diff < lastDiff) {
lastDiff = diff;
bestFit = i;
}
}
return bestFit;
}
public static double distance(int color[], int test[]) {
return Math.pow(Math.abs(color[0] - test[0]), 3D) + Math.pow(Math.abs(color[1] - test[1]), 3D) + Math.pow(Math.abs(color[2] - test[2]), 3D);
}
public static int getR(int color) {
return ((color >> 16) & 255);
}
public static int getG(int color) {
return ((color >> 8) & 255);
}
public static int getB(int color) {
return color & 255;
}
public static int getComponent(int color, int component) {
switch (component) {
case 0: return getR(color);
case 1: return getG(color);
case 2: return getB(color);
default: return 0;
case 0:
return getR(color);
case 1:
return getG(color);
case 2:
return getB(color);
default:
return 0;
}
}
@ -91,4 +100,4 @@ public abstract class Palette {
sourceColor[component] = Math.max(0, Math.min(255, sourceColor[component] + error));
return toRGBInt(sourceColor);
}
}
}

View File

@ -1,6 +1,5 @@
package org.badvision.outlaweditor.apple.dhgr;
import org.badvision.outlaweditor.apple.*;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.control.Menu;

View File

@ -1,7 +1,5 @@
package org.badvision.outlaweditor.data;
import org.badvision.outlaweditor.*;
/**
*
* @author brobert

View File

@ -9,19 +9,21 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static org.badvision.outlaweditor.data.TileUtils.clear;
/**
*
* @author brobert
*/
public class DataProducer {
static Map<Object, List<WeakReference<DataObserver>>> observers;
static Map<Object, List<WeakReference<DataObserver>>> observers;
static {
clear();
}
public static void clear() {
observers = new ConcurrentHashMap<>();
observers = new ConcurrentHashMap<>();
}
public static List<WeakReference<DataObserver>> getObservers(Object o) {
@ -34,7 +36,7 @@ public class DataProducer {
public static void addObserver(Object o, DataObserver observer) {
getObservers(o).add(new WeakReference<>(observer));
}
public static void notifyObservers(Object o) {
for (WeakReference<DataObserver> ref : getObservers(o)) {
DataObserver observer = ref.get();

View File

@ -92,9 +92,9 @@ public class PropertyHelper {
public static JavaBeanStringProperty stringProp(Object t, String fieldName) throws NoSuchMethodException {
return new JavaBeanStringPropertyBuilder().bean(t).name(fieldName).build();
}
static private Map<Property, Property> boundProperties = new HashMap<>();
static public void bind(Property formProp, Property sourceProp) {
if (boundProperties.containsKey(formProp)) {
formProp.unbindBidirectional(boundProperties.get(formProp));
@ -107,5 +107,5 @@ public class PropertyHelper {
formProp.bindBidirectional(sourceProp);
boundProperties.put(formProp, sourceProp);
}
}
}
}

View File

@ -1,8 +1,6 @@
package org.badvision.outlaweditor.data;
import java.io.Serializable;
import java.util.Collection;
import org.badvision.outlaweditor.data.xml.Script;
import org.badvision.outlaweditor.data.xml.Tile;
/**

View File

@ -46,8 +46,8 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
}
public void put(int x, int y, Tile t) {
width = Math.max(x+1, width);
height = Math.max(y+1, height);
width = Math.max(x + 1, width);
height = Math.max(y + 1, height);
for (int i = size(); i <= y; i++) {
add(null);
}
@ -129,4 +129,4 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
public static boolean isNullTile(String tileId) {
return tileId.equalsIgnoreCase(NULL_TILE_ID);
}
}
}

View File

@ -47,5 +47,5 @@ public abstract class ApplicationMenuController {
@FXML
abstract public void onHelpAbout(ActionEvent event);
}

View File

@ -14,7 +14,9 @@ public abstract class ApplicationUIController {
}
abstract public void rebuildTileSelectors();
abstract public void rebuildMapSelectors();
abstract public void rebuildImageSelectors();
public abstract Editor getVisibleEditor();
@ -51,6 +53,8 @@ public abstract class ApplicationUIController {
abstract public void completeInflightOperations();
abstract public void clearData();
abstract public void updateSelectors();
abstract public void redrawScripts();
}

View File

@ -17,18 +17,25 @@ import org.badvision.outlaweditor.data.xml.Script;
* @author blurry
*/
public abstract class MapEditorTabController {
private MapEditor currentEditor;
public MapEditor getCurrentEditor() {
return currentEditor;
}
public void setCurrentEditor(MapEditor editor) {
currentEditor = editor;
}
public abstract Map getCurrentMap();
public abstract void setCurrentMap(Map m);
public abstract void rebuildMapSelectors();
public abstract void redrawMapScripts();
@FXML // fx:id="mapEditorAnchorPane"
protected AnchorPane mapEditorAnchorPane; // Value injected by FXMLLoader
@FXML // fx:id="mapHeightField"

View File

@ -3,7 +3,6 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.badvision.outlaweditor.ui;
import javafx.event.ActionEvent;
@ -21,22 +20,27 @@ import org.badvision.outlaweditor.data.xml.Tile;
* @author blurry
*/
public abstract class TileEditorTabController {
private Tile currentTile;
public Tile getCurrentTile() {
return currentTile;
}
public void setCurrentTile(Tile tile) {
currentTile = tile;
}
private TileEditor currentEditor;
public TileEditor getCurrentTileEditor() {
return currentEditor;
}
public void setCurrentTileEditor(TileEditor editor) {
currentEditor = editor;
}
@FXML // fx:id="tileCategoryField"
protected TextField tileCategoryField; // Value injected by FXMLLoader
@FXML // fx:id="tileEditorAnchorPane"
@ -80,5 +84,5 @@ public abstract class TileEditorTabController {
abstract public void tileShift(ActionEvent event);
abstract public void rebuildTileSelectors();
}

View File

@ -99,8 +99,8 @@ public class UIAction {
currentSaveFile = f;
case Save:
if (currentSaveFile == null) {
currentSaveFile = FileUtils.getFile(currentSaveFile, "Save game data", Boolean.TRUE, FileUtils.Extension.XML, FileUtils.Extension.ALL);
}
currentSaveFile = FileUtils.getFile(currentSaveFile, "Save game data", Boolean.TRUE, FileUtils.Extension.XML, FileUtils.Extension.ALL);
}
if (currentSaveFile != null) {
currentSaveFile.delete();
JAXB.marshal(Application.gameData, currentSaveFile);
@ -143,7 +143,7 @@ public class UIAction {
@Override
public void run() {
Platform.exit();
}
}
}, null);
}
@ -160,8 +160,10 @@ public class UIAction {
}
public static class Choice {
String text;
Runnable handler;
public Choice(String text, Runnable handler) {
this.text = text;
this.handler = handler;
@ -171,7 +173,7 @@ public class UIAction {
public static void confirm(String message, Runnable yes, Runnable no) {
choose(message, new Choice("Yes", yes), new Choice("No", no));
}
public static void choose(String message, Choice... choices) {
final Stage dialogStage = new Stage();
@ -197,14 +199,14 @@ public class UIAction {
alignment(Pos.CENTER).padding(new Insets(5)).build()));
dialogStage.show();
}
public static Script createAndEditScript() {
Script script = new Script();
script.setName("New Script");
ApplicationUIController.getController().getVisibleEditor().addScript(script);
return editScript(script);
}
public static Script editScript(Script script) {
if (script == null) {
System.err.println("Requested to edit a null script object, ignoring!");
@ -212,6 +214,6 @@ public class UIAction {
}
MythosEditor editor = new MythosEditor(script);
editor.show();
return script;
return script;
}
}

View File

@ -16,7 +16,7 @@ import org.badvision.outlaweditor.ui.UIAction;
* @author blurry
*/
public class ApplicationMenuControllerImpl extends ApplicationMenuController {
@Override
public void onChangePlatformAppleSolid(ActionEvent event) {
AppleTileRenderer.useSolidPalette = true;
@ -117,5 +117,4 @@ public class ApplicationMenuControllerImpl extends ApplicationMenuController {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -50,13 +50,13 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
public void redrawAllTabs() {
if (mapController.getCurrentEditor() != null) {
mapController.getCurrentEditor().redraw();
mapController.getCurrentEditor().redraw();
}
if (imageController.getCurrentEditor() != null) {
imageController.getCurrentEditor().redraw();
}
}
@Override
public void updateSelectors() {
rebuildImageSelectors();

View File

@ -27,6 +27,7 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
public Image currentImage = null;
public ImageEditor currentImageEditor = null;
/**
* Initializes the controller class.
*/
@ -58,8 +59,8 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
};
}
});
}
}
@Override
public Editor getCurrentEditor() {
return currentImageEditor;
@ -170,7 +171,6 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
setCurrentImage(imageSelector.getSelectionModel().getSelectedItem());
}
@Override
public void scrollImageDown(ActionEvent event) {
if (currentImageEditor != null) {
@ -198,6 +198,7 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
currentImageEditor.scrollBy(0, -1);
}
}
private void setCurrentImage(Image i) {
if (currentImage != null && currentImage.equals(i)) {
return;

View File

@ -188,9 +188,9 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
public void completeInflightOperations() {
if (getCurrentEditor() != null) {
getCurrentEditor().getCurrentMap().updateBackingMap();
}
}
}
@Override
public void setCurrentMap(Map m) {
if (getCurrentMap() != null && getCurrentMap().equals(m)) {
@ -335,4 +335,4 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
}
}
}
}
}

View File

@ -28,12 +28,13 @@ import org.badvision.outlaweditor.ui.TileEditorTabController;
*
* @author blurry
*/
public class TileEditorTabControllerImpl extends TileEditorTabController {
public class TileEditorTabControllerImpl extends TileEditorTabController {
@Override
public void onCurrentTileSelected(ActionEvent event) {
setCurrentTile(tileSelector.getSelectionModel().getSelectedItem());
}
@Override
public void onTileClonePressed(ActionEvent event) {
ApplicationUIController mainController = ApplicationUIController.getController();
@ -124,7 +125,6 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
/**
* Initializes the controller class.
*/
@ -136,7 +136,7 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
assert tileObstructionField != null : "fx:id=\"tileObstructionField\" was not injected: check your FXML file 'tileEditorTab.fxml'.";
assert tilePatternMenu != null : "fx:id=\"tilePatternMenu\" was not injected: check your FXML file 'tileEditorTab.fxml'.";
assert tileSelector != null : "fx:id=\"tileSelector\" was not injected: check your FXML file 'tileEditorTab.fxml'.";
tileSelector.setButtonCell(new ComboBoxListCell<Tile>() {
{
super.setPrefWidth(125);
@ -163,9 +163,9 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
}
};
}
});
}
});
}
@Override
public void setCurrentTileEditor(TileEditor editor) {
if (editor != null) {