GraphicsFXValue для canvasfx

This commit is contained in:
Victor 2016-05-24 14:40:11 +03:00
parent 5e1f52024a
commit a0f1355f31
5 changed files with 247 additions and 400 deletions

View File

@ -2,23 +2,22 @@ use "canvasfx"
// https://docs.oracle.com/javafx/2/canvas/jfxpub-canvas.htm // https://docs.oracle.com/javafx/2/canvas/jfxpub-canvas.htm
window("JavaFX Basic shapes", 300, 250) g = window("JavaFX Basic shapes", 300, 250)
g.setFill(Color.GREEN)
setFill(Color.GREEN) g.setStroke(Color.BLUE)
setStroke(Color.BLUE) g.setLineWidth(5)
setLineWidth(5) g.strokeLine(40, 10, 10, 40)
strokeLine(40, 10, 10, 40) g.fillOval(10, 60, 30, 30)
fillOval(10, 60, 30, 30) g.strokeOval(60, 60, 30, 30)
strokeOval(60, 60, 30, 30) g.fillRoundRect(110, 60, 30, 30, 10, 10)
fillRoundRect(110, 60, 30, 30, 10, 10) g.strokeRoundRect(160, 60, 30, 30, 10, 10)
strokeRoundRect(160, 60, 30, 30, 10, 10) g.fillArc(10, 110, 30, 30, 45, 240, ArcType.OPEN)
fillArc(10, 110, 30, 30, 45, 240, ArcType.OPEN) g.fillArc(60, 110, 30, 30, 45, 240, ArcType.CHORD)
fillArc(60, 110, 30, 30, 45, 240, ArcType.CHORD) g.fillArc(110, 110, 30, 30, 45, 240, ArcType.ROUND)
fillArc(110, 110, 30, 30, 45, 240, ArcType.ROUND) g.strokeArc(10, 160, 30, 30, 45, 240, ArcType.OPEN)
strokeArc(10, 160, 30, 30, 45, 240, ArcType.OPEN) g.strokeArc(60, 160, 30, 30, 45, 240, ArcType.CHORD)
strokeArc(60, 160, 30, 30, 45, 240, ArcType.CHORD) g.strokeArc(110, 160, 30, 30, 45, 240, ArcType.ROUND)
strokeArc(110, 160, 30, 30, 45, 240, ArcType.ROUND) g.fillPolygon([10, 40, 10, 40], [210, 210, 240, 240], 4)
fillPolygon([10, 40, 10, 40], [210, 210, 240, 240], 4) g.strokePolygon([60, 90, 60, 90], [210, 210, 240, 240], 4)
strokePolygon([60, 90, 60, 90], [210, 210, 240, 240], 4) g.strokePolyline([110, 140, 110, 140], [210, 210, 240, 240], 4)
strokePolyline([110, 140, 110, 140], [210, 210, 240, 240], 4)
repaint() repaint()

View File

@ -2,7 +2,7 @@ use "canvasfx"
use "std" use "std"
w = 800 h = 600 w = 800 h = 600
window("JavaFX Event handler example", w, h) g = window("JavaFX Event handler example", w, h)
addEventHandler(Events.MOUSE_MOVED, ::onMouseMoved) addEventHandler(Events.MOUSE_MOVED, ::onMouseMoved)
addEventHandler(Events.MOUSE_DRAGGED, ::onMouseMoved) addEventHandler(Events.MOUSE_DRAGGED, ::onMouseMoved)
@ -11,8 +11,8 @@ addEventHandler(Events.KEY_PRESSED, def(e) {
}) })
def onMouseMoved(e) { def onMouseMoved(e) {
setFill(Color.rgb(rand(255), rand(255), rand(255), rand())) g.setFill(Color.rgb(rand(255), rand(255), rand(255), rand()))
m = 1 + e.isPrimaryButtonDown + e.isSecondaryButtonDown m = 1 + e.isPrimaryButtonDown + e.isSecondaryButtonDown
radius = m * rand(30, 50) radius = m * rand(30, 50)
fillOval(e.x - radius/2, e.y - radius/2, radius, radius) g.fillOval(e.x - radius/2, e.y - radius/2, radius, radius)
} }

View File

@ -7,11 +7,11 @@ h = size * 1.5
step = 1.0 / steps step = 1.0 / steps
window("JavaFX Global Alpha example", w, h) g = window("JavaFX Global Alpha example", w, h)
setFill(Color.RED) g.setFill(Color.RED)
y = size * 0.25 y = size * 0.25
for a = 0, a <= 1.0, a += step { for a = 0, a <= 1.0, a += step {
setGlobalAlpha(a) g.setGlobalAlpha(a)
fillRect(a * w, y, size, size) g.fillRect(a * w, y, size, size)
} }

View File

@ -4,21 +4,21 @@ use "std"
// http://www.developer.com/java/data/using-graphics-in-javafx.html // http://www.developer.com/java/data/using-graphics-in-javafx.html
width = 800 height = 600 width = 800 height = 600
window("JavaFX Rotation example", width, height) g = window("JavaFX Rotation example", width, height)
translate(width / 2, height / 2) g.translate(width / 2, height / 2)
def randomColor() = Color.rgb(rand(255), rand(255), rand(255), 0.9) def randomColor() = Color.rgb(rand(255), rand(255), rand(255), 0.9)
for i = 0, i < 60, i++ { for i = 0, i < 60, i++ {
rotate(6.0) g.rotate(6.0)
setFill(randomColor()) g.setFill(randomColor())
fillOval(10, 60, 30, 30) g.fillOval(10, 60, 30, 30)
setStroke(randomColor()) g.setStroke(randomColor())
strokeOval(60, 60, 30, 30) g.strokeOval(60, 60, 30, 30)
setFill(randomColor()) g.setFill(randomColor())
fillRoundRect(110, 60, 30, 30, 10, 10) g.fillRoundRect(110, 60, 30, 30, 10, 10)
setFill(randomColor()) g.setFill(randomColor())
fillPolygon([105, 117, 159, 123, 133, 105, 77, 87, 51, 93], g.fillPolygon([105, 117, 159, 123, 133, 105, 77, 87, 51, 93],
[150, 186, 186, 204, 246, 222, 246, 204, 186, 186], 10) [150, 186, 186, 204, 246, 222, 246, 204, 186, 186], 10)
} }

View File

@ -5,6 +5,7 @@ import com.annimon.ownlang.lib.*;
import java.awt.Dimension; import java.awt.Dimension;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javafx.application.Platform; import javafx.application.Platform;
@ -116,68 +117,6 @@ public final class canvasfx implements Module {
Functions.set("addEventFilter", new addEventFilter()); Functions.set("addEventFilter", new addEventFilter());
Functions.set("addEventHandler", new addEventHandler()); Functions.set("addEventHandler", new addEventHandler());
Functions.set("applyEffect", new applyEffect());
Functions.set("appendSVGPath", new appendSVGPath());
Functions.set("arc", new arc());
Functions.set("arcTo", new arcTo());
Functions.set("beginPath", new beginPath());
Functions.set("bezierCurveTo", new bezierCurveTo());
Functions.set("clearRect", new clearRect());
Functions.set("clip", new clip());
Functions.set("closePath", new closePath());
Functions.set("fill", new fill());
Functions.set("fillArc", new fillArc());
Functions.set("fillOval", new fillOval());
Functions.set("fillPolygon", new fillPolygon());
Functions.set("fillRect", new fillRect());
Functions.set("fillRoundRect", new fillRoundRect());
Functions.set("fillText", new fillText());
Functions.set("getGlobalAlpha", new getGlobalAlpha());
Functions.set("getLineWidth", new getLineWidth());
Functions.set("getMiterLimit", new getMiterLimit());
Functions.set("getFill", new getFill());
Functions.set("getFillRule", new getFillRule());
Functions.set("getGlobalAlpha", new getGlobalAlpha());
Functions.set("getGlobalBlendMode", new getGlobalBlendMode());
Functions.set("getLineCap", new getLineCap());
Functions.set("getLineJoin", new getLineJoin());
Functions.set("getLineWidth", new getLineWidth());
Functions.set("getMiterLimit", new getMiterLimit());
Functions.set("getStroke", new getStroke());
Functions.set("getTextAlign", new getTextAlign());
Functions.set("getTextBaseline", new getTextBaseline());
Functions.set("isPointInPath", new isPointInPath());
Functions.set("lineTo", new lineTo());
Functions.set("moveTo", new moveTo());
Functions.set("quadraticCurveTo", new quadraticCurveTo());
Functions.set("rect", new rect());
Functions.set("restore", new restore());
Functions.set("rotate", new rotate());
Functions.set("save", new save());
Functions.set("scale", new scale());
Functions.set("setEffect", new setEffect());
Functions.set("setFill", new setFill());
Functions.set("setFillRule", new setFillRule());
Functions.set("setGlobalAlpha", new setGlobalAlpha());
Functions.set("setGlobalBlendMode", new setGlobalBlendMode());
Functions.set("setLineCap", new setLineCap());
Functions.set("setLineJoin", new setLineJoin());
Functions.set("setLineWidth", new setLineWidth());
Functions.set("setMiterLimit", new setMiterLimit());
Functions.set("setStroke", new setStroke());
Functions.set("setTextAlign", new setTextAlign());
Functions.set("setTextBaseline", new setTextBaseline());
Functions.set("stroke", new stroke());
Functions.set("strokeArc", new strokeArc());
Functions.set("strokeLine", new strokeLine());
Functions.set("strokeOval", new strokeOval());
Functions.set("strokePolygon", new strokePolygon());
Functions.set("strokePolyline", new strokePolyline());
Functions.set("strokeRect", new strokeRect());
Functions.set("strokeRoundRect", new strokeRoundRect());
Functions.set("strokeText", new strokeText());
Functions.set("transform", new transform());
Functions.set("translate", new translate());
final MapValue arcType = new MapValue(ArcType.values().length); final MapValue arcType = new MapValue(ArcType.values().length);
for (ArcType value : ArcType.values()) { for (ArcType value : ArcType.values()) {
@ -632,119 +571,161 @@ public final class canvasfx implements Module {
} }
//</editor-fold> //</editor-fold>
private static class applyEffect implements Function { public static class GraphicsFXValue extends MapValue {
@Override
public Value execute(Value... args) { private final GraphicsContext graphics;
public GraphicsFXValue(GraphicsContext graphics) {
super(64);
this.graphics = graphics;
init();
}
private void init() {
Map<String, Function> functions = new HashMap<>();
functions.put("applyEffect", this::applyEffect);
functions.put("appendSVGPath", this::appendSVGPath);
functions.put("arc", this::arc);
functions.put("arcTo", this::arcTo);
functions.put("beginPath", this::beginPath);
functions.put("bezierCurveTo", this::bezierCurveTo);
functions.put("clearRect", this::clearRect);
functions.put("clip", this::clip);
functions.put("closePath", this::closePath);
functions.put("fill", this::fill);
functions.put("fillArc", this::fillArc);
functions.put("fillOval", this::fillOval);
functions.put("fillPolygon", this::fillPolygon);
functions.put("fillRect", this::fillRect);
functions.put("fillRoundRect", this::fillRoundRect);
functions.put("fillText", this::fillText);
functions.put("getGlobalAlpha", this::getGlobalAlpha);
functions.put("getLineWidth", this::getLineWidth);
functions.put("getMiterLimit", this::getMiterLimit);
functions.put("getFill", this::getFill);
functions.put("getFillRule", this::getFillRule);
functions.put("getGlobalAlpha", this::getGlobalAlpha);
functions.put("getGlobalBlendMode", this::getGlobalBlendMode);
functions.put("getLineCap", this::getLineCap);
functions.put("getLineJoin", this::getLineJoin);
functions.put("getLineWidth", this::getLineWidth);
functions.put("getMiterLimit", this::getMiterLimit);
functions.put("getStroke", this::getStroke);
functions.put("getTextAlign", this::getTextAlign);
functions.put("getTextBaseline", this::getTextBaseline);
functions.put("isPointInPath", this::isPointInPath);
functions.put("lineTo", this::lineTo);
functions.put("moveTo", this::moveTo);
functions.put("quadraticCurveTo", this::quadraticCurveTo);
functions.put("rect", this::rect);
functions.put("restore", this::restore);
functions.put("rotate", this::rotate);
functions.put("save", this::save);
functions.put("scale", this::scale);
functions.put("setEffect", this::setEffect);
functions.put("setFill", this::setFill);
functions.put("setFillRule", this::setFillRule);
functions.put("setGlobalAlpha", this::setGlobalAlpha);
functions.put("setGlobalBlendMode", this::setGlobalBlendMode);
functions.put("setLineCap", this::setLineCap);
functions.put("setLineJoin", this::setLineJoin);
functions.put("setLineWidth", this::setLineWidth);
functions.put("setMiterLimit", this::setMiterLimit);
functions.put("setStroke", this::setStroke);
functions.put("setTextAlign", this::setTextAlign);
functions.put("setTextBaseline", this::setTextBaseline);
functions.put("stroke", this::stroke);
functions.put("strokeArc", this::strokeArc);
functions.put("strokeLine", this::strokeLine);
functions.put("strokeOval", this::strokeOval);
functions.put("strokePolygon", this::strokePolygon);
functions.put("strokePolyline", this::strokePolyline);
functions.put("strokeRect", this::strokeRect);
functions.put("strokeRoundRect", this::strokeRoundRect);
functions.put("strokeText", this::strokeText);
functions.put("transform", this::transform);
functions.put("translate", this::translate);
for (Map.Entry<String, Function> entry : functions.entrySet()) {
set(new StringValue(entry.getKey()), new FunctionValue(entry.getValue()));
}
}
public Value applyEffect(Value... args) {
if (args[0].type() != FX_EFFECT_TYPE) { if (args[0].type() != FX_EFFECT_TYPE) {
throw new TypeException("Effect expected, found " + Types.typeToString(args[0].type())); throw new TypeException("Effect expected, found " + Types.typeToString(args[0].type()));
} }
graphics.applyEffect((Effect) args[0].raw()); graphics.applyEffect((Effect) args[0].raw());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class appendSVGPath implements Function { public Value arc(Value... args) {
@Override
public Value execute(Value... args) {
graphics.appendSVGPath(args[0].asString());
return NumberValue.ZERO;
}
}
private static class arc implements Function {
@Override
public Value execute(Value... args) {
graphics.arc(args[0].asNumber(), args[1].asNumber(), graphics.arc(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber(), args[2].asNumber(), args[3].asNumber(),
args[4].asNumber(), args[5].asNumber()); args[4].asNumber(), args[5].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
public Value appendSVGPath(Value... args) {
graphics.appendSVGPath(args[0].asString());
return NumberValue.ZERO;
} }
private static class arcTo implements Function { public Value arcTo(Value... args) {
@Override
public Value execute(Value... args) {
graphics.arcTo(args[0].asNumber(), args[1].asNumber(), graphics.arcTo(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber(), args[2].asNumber(), args[3].asNumber(),
args[4].asNumber()); args[4].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class beginPath implements Function { public Value beginPath(Value... args) {
@Override
public Value execute(Value... args) {
graphics.beginPath(); graphics.beginPath();
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class bezierCurveTo implements Function { public Value bezierCurveTo(Value... args) {
@Override
public Value execute(Value... args) {
graphics.bezierCurveTo(args[0].asNumber(), args[1].asNumber(), graphics.bezierCurveTo(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber(), args[2].asNumber(), args[3].asNumber(),
args[4].asNumber(), args[5].asNumber()); args[4].asNumber(), args[5].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class clearRect implements Function { public Value clearRect(Value... args) {
@Override
public Value execute(Value... args) {
graphics.clearRect(args[0].asNumber(), args[1].asNumber(), graphics.clearRect(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber()); args[2].asNumber(), args[3].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class clip implements Function { public Value clip(Value... args) {
@Override
public Value execute(Value... args) {
graphics.clip(); graphics.clip();
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class closePath implements Function { public Value closePath(Value... args) {
@Override
public Value execute(Value... args) {
graphics.closePath(); graphics.closePath();
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class fill implements Function { public Value fill(Value... args) {
@Override
public Value execute(Value... args) {
graphics.fill(); graphics.fill();
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class fillArc implements Function { public Value fillArc(Value... args) {
@Override
public Value execute(Value... args) {
graphics.fillArc(args[0].asNumber(), args[1].asNumber(), graphics.fillArc(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber(), args[2].asNumber(), args[3].asNumber(),
args[4].asNumber(), args[5].asNumber(), args[4].asNumber(), args[5].asNumber(),
ArcType.values()[args[6].asInt()]); ArcType.values()[args[6].asInt()]);
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class fillOval implements Function { public Value fillOval(Value... args) {
@Override
public Value execute(Value... args) {
graphics.fillOval(args[0].asNumber(), args[1].asNumber(), graphics.fillOval(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber()); args[2].asNumber(), args[3].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class fillPolygon implements Function { public Value fillPolygon(Value... args) {
@Override
public Value execute(Value... args) {
final ArrayValue xarr = (ArrayValue) args[0]; final ArrayValue xarr = (ArrayValue) args[0];
final ArrayValue yarr = (ArrayValue) args[1]; final ArrayValue yarr = (ArrayValue) args[1];
@ -759,30 +740,21 @@ public final class canvasfx implements Module {
graphics.fillPolygon(xPoints, yPoints, args[2].asInt()); graphics.fillPolygon(xPoints, yPoints, args[2].asInt());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class fillRect implements Function { public Value fillRect(Value... args) {
@Override
public Value execute(Value... args) {
graphics.fillRect(args[0].asNumber(), args[1].asNumber(), graphics.fillRect(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber()); args[2].asNumber(), args[3].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class fillRoundRect implements Function { public Value fillRoundRect(Value... args) {
@Override
public Value execute(Value... args) {
graphics.fillRoundRect(args[0].asNumber(), args[1].asNumber(), graphics.fillRoundRect(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber(), args[2].asNumber(), args[3].asNumber(),
args[4].asNumber(), args[5].asNumber() ); args[4].asNumber(), args[5].asNumber() );
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class fillText implements Function { public Value fillText(Value... args) {
@Override
public Value execute(Value... args) {
if (args.length < 4) { if (args.length < 4) {
// str x y // str x y
graphics.fillText(args[0].asString(), args[1].asNumber(), graphics.fillText(args[0].asString(), args[1].asNumber(),
@ -793,297 +765,186 @@ public final class canvasfx implements Module {
} }
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class getFill implements Function { public Value getFill(Value... args) {
@Override
public Value execute(Value... args) {
return new ColorValue((Color)graphics.getFill()); return new ColorValue((Color)graphics.getFill());
} }
}
private static class getFillRule implements Function { public Value getFillRule(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.of(graphics.getFillRule().ordinal()); return NumberValue.of(graphics.getFillRule().ordinal());
} }
}
private static class getGlobalAlpha implements Function { public Value getGlobalAlpha(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.of(graphics.getGlobalAlpha()); return NumberValue.of(graphics.getGlobalAlpha());
} }
}
private static class getGlobalBlendMode implements Function { public Value getGlobalBlendMode(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.of(graphics.getGlobalBlendMode().ordinal()); return NumberValue.of(graphics.getGlobalBlendMode().ordinal());
} }
}
private static class getLineCap implements Function { public Value getLineCap(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.of(graphics.getLineCap().ordinal()); return NumberValue.of(graphics.getLineCap().ordinal());
} }
}
private static class getLineJoin implements Function { public Value getLineJoin(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.of(graphics.getLineJoin().ordinal()); return NumberValue.of(graphics.getLineJoin().ordinal());
} }
}
private static class getLineWidth implements Function { public Value getLineWidth(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.of(graphics.getLineWidth()); return NumberValue.of(graphics.getLineWidth());
} }
}
private static class getMiterLimit implements Function { public Value getMiterLimit(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.of(graphics.getMiterLimit()); return NumberValue.of(graphics.getMiterLimit());
} }
}
private static class getStroke implements Function { public Value getStroke(Value... args) {
@Override
public Value execute(Value... args) {
return new ColorValue((Color)graphics.getStroke()); return new ColorValue((Color)graphics.getStroke());
} }
}
private static class getTextAlign implements Function { public Value getTextAlign(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.of(graphics.getTextAlign().ordinal()); return NumberValue.of(graphics.getTextAlign().ordinal());
} }
}
private static class getTextBaseline implements Function { public Value getTextBaseline(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.of(graphics.getTextBaseline().ordinal()); return NumberValue.of(graphics.getTextBaseline().ordinal());
} }
}
private static class isPointInPath implements Function { public Value isPointInPath(Value... args) {
@Override
public Value execute(Value... args) {
return NumberValue.fromBoolean(graphics.isPointInPath(args[0].asNumber(), args[1].asNumber())); return NumberValue.fromBoolean(graphics.isPointInPath(args[0].asNumber(), args[1].asNumber()));
} }
}
private static class lineTo implements Function { public Value lineTo(Value... args) {
@Override
public Value execute(Value... args) {
graphics.lineTo(args[0].asNumber(), args[1].asNumber()); graphics.lineTo(args[0].asNumber(), args[1].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class moveTo implements Function { public Value moveTo(Value... args) {
@Override
public Value execute(Value... args) {
graphics.moveTo(args[0].asNumber(), args[1].asNumber()); graphics.moveTo(args[0].asNumber(), args[1].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class quadraticCurveTo implements Function { public Value quadraticCurveTo(Value... args) {
@Override
public Value execute(Value... args) {
graphics.quadraticCurveTo(args[0].asNumber(), args[1].asNumber(), graphics.quadraticCurveTo(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber()); args[2].asNumber(), args[3].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class rect implements Function { public Value rect(Value... args) {
@Override
public Value execute(Value... args) {
graphics.rect(args[0].asNumber(), args[1].asNumber(), graphics.rect(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber()); args[2].asNumber(), args[3].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class restore implements Function { public Value restore(Value... args) {
@Override
public Value execute(Value... args) {
graphics.restore(); graphics.restore();
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class rotate implements Function { public Value rotate(Value... args) {
@Override
public Value execute(Value... args) {
graphics.rotate(args[0].asNumber()); graphics.rotate(args[0].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class save implements Function { public Value save(Value... args) {
@Override
public Value execute(Value... args) {
graphics.save(); graphics.save();
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class scale implements Function { public Value scale(Value... args) {
@Override
public Value execute(Value... args) {
graphics.scale(args[0].asNumber(), args[1].asNumber()); graphics.scale(args[0].asNumber(), args[1].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setEffect implements Function { public Value setEffect(Value... args) {
@Override
public Value execute(Value... args) {
if (args[0].type() != FX_EFFECT_TYPE) { if (args[0].type() != FX_EFFECT_TYPE) {
throw new TypeException("Effect expected, found " + Types.typeToString(args[0].type())); throw new TypeException("Effect expected, found " + Types.typeToString(args[0].type()));
} }
graphics.setEffect((Effect) args[0].raw()); graphics.setEffect((Effect) args[0].raw());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setFill implements Function { public Value setFill(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setFill((Color) args[0].raw()); graphics.setFill((Color) args[0].raw());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setFillRule implements Function { public Value setFillRule(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setFillRule(FillRule.values()[args[0].asInt()]); graphics.setFillRule(FillRule.values()[args[0].asInt()]);
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setGlobalAlpha implements Function { public Value setGlobalAlpha(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setGlobalAlpha(args[0].asNumber()); graphics.setGlobalAlpha(args[0].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setGlobalBlendMode implements Function { public Value setGlobalBlendMode(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setGlobalBlendMode(BlendMode.values()[args[0].asInt()]); graphics.setGlobalBlendMode(BlendMode.values()[args[0].asInt()]);
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setLineCap implements Function { public Value setLineCap(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setLineCap(StrokeLineCap.values()[args[0].asInt()]); graphics.setLineCap(StrokeLineCap.values()[args[0].asInt()]);
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setLineJoin implements Function { public Value setLineJoin(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setLineJoin(StrokeLineJoin.values()[args[0].asInt()]); graphics.setLineJoin(StrokeLineJoin.values()[args[0].asInt()]);
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setLineWidth implements Function { public Value setLineWidth(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setLineWidth(args[0].asNumber()); graphics.setLineWidth(args[0].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setMiterLimit implements Function { public Value setMiterLimit(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setMiterLimit(args[0].asNumber()); graphics.setMiterLimit(args[0].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setStroke implements Function { public Value setStroke(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setStroke((Color) args[0].raw()); graphics.setStroke((Color) args[0].raw());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setTextAlign implements Function { public Value setTextAlign(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setTextAlign(TextAlignment.values()[args[0].asInt()]); graphics.setTextAlign(TextAlignment.values()[args[0].asInt()]);
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class setTextBaseline implements Function { public Value setTextBaseline(Value... args) {
@Override
public Value execute(Value... args) {
graphics.setTextBaseline(VPos.values()[args[0].asInt()]); graphics.setTextBaseline(VPos.values()[args[0].asInt()]);
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class stroke implements Function { public Value stroke(Value... args) {
@Override
public Value execute(Value... args) {
graphics.stroke(); graphics.stroke();
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class strokeArc implements Function { public Value strokeArc(Value... args) {
@Override
public Value execute(Value... args) {
graphics.strokeArc(args[0].asNumber(), args[1].asNumber(), graphics.strokeArc(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber(), args[2].asNumber(), args[3].asNumber(),
args[4].asNumber(), args[5].asNumber(), args[4].asNumber(), args[5].asNumber(),
ArcType.values()[args[6].asInt()]); ArcType.values()[args[6].asInt()]);
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class strokeLine implements Function { public Value strokeLine(Value... args) {
@Override
public Value execute(Value... args) {
graphics.strokeLine(args[0].asNumber(), args[1].asNumber(), graphics.strokeLine(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber()); args[2].asNumber(), args[3].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class strokeOval implements Function { public Value strokeOval(Value... args) {
@Override
public Value execute(Value... args) {
graphics.strokeOval(args[0].asNumber(), args[1].asNumber(), graphics.strokeOval(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber()); args[2].asNumber(), args[3].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class strokePolygon implements Function { public Value strokePolygon(Value... args) {
@Override
public Value execute(Value... args) {
final ArrayValue xarr = (ArrayValue) args[0]; final ArrayValue xarr = (ArrayValue) args[0];
final ArrayValue yarr = (ArrayValue) args[1]; final ArrayValue yarr = (ArrayValue) args[1];
@ -1098,11 +959,8 @@ public final class canvasfx implements Module {
graphics.strokePolygon(xPoints, yPoints, args[2].asInt()); graphics.strokePolygon(xPoints, yPoints, args[2].asInt());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class strokePolyline implements Function { public Value strokePolyline(Value... args) {
@Override
public Value execute(Value... args) {
final ArrayValue xarr = (ArrayValue) args[0]; final ArrayValue xarr = (ArrayValue) args[0];
final ArrayValue yarr = (ArrayValue) args[1]; final ArrayValue yarr = (ArrayValue) args[1];
@ -1117,30 +975,21 @@ public final class canvasfx implements Module {
graphics.strokePolyline(xPoints, yPoints, args[2].asInt()); graphics.strokePolyline(xPoints, yPoints, args[2].asInt());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class strokeRect implements Function { public Value strokeRect(Value... args) {
@Override
public Value execute(Value... args) {
graphics.strokeRect(args[0].asNumber(), args[1].asNumber(), graphics.strokeRect(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber()); args[2].asNumber(), args[3].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class strokeRoundRect implements Function { public Value strokeRoundRect(Value... args) {
@Override
public Value execute(Value... args) {
graphics.strokeRoundRect(args[0].asNumber(), args[1].asNumber(), graphics.strokeRoundRect(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber(), args[2].asNumber(), args[3].asNumber(),
args[4].asNumber(), args[5].asNumber() ); args[4].asNumber(), args[5].asNumber() );
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class strokeText implements Function { public Value strokeText(Value... args) {
@Override
public Value execute(Value... args) {
if (args.length < 4) { if (args.length < 4) {
// str x y // str x y
graphics.strokeText(args[0].asString(), args[1].asNumber(), graphics.strokeText(args[0].asString(), args[1].asNumber(),
@ -1151,24 +1000,23 @@ public final class canvasfx implements Module {
} }
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class transform implements Function { public Value transform(Value... args) {
@Override
public Value execute(Value... args) {
graphics.transform(args[0].asNumber(), args[1].asNumber(), graphics.transform(args[0].asNumber(), args[1].asNumber(),
args[2].asNumber(), args[3].asNumber(), args[2].asNumber(), args[3].asNumber(),
args[4].asNumber(), args[5].asNumber()); args[4].asNumber(), args[5].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
}
private static class translate implements Function { public Value translate(Value... args) {
@Override
public Value execute(Value... args) {
graphics.translate(args[0].asNumber(), args[1].asNumber()); graphics.translate(args[0].asNumber(), args[1].asNumber());
return NumberValue.ZERO; return NumberValue.ZERO;
} }
@Override
public String toString() {
return "GraphicsFXValue " + asString();
}
} }
private static class CreateWindow implements Function { private static class CreateWindow implements Function {
@ -1212,7 +1060,7 @@ public final class canvasfx implements Module {
root.getChildren().add(canvas); root.getChildren().add(canvas);
panel.setScene(scene); panel.setScene(scene);
}); });
return NumberValue.ZERO; return new GraphicsFXValue(graphics);
} }
} }