Добавлен конвертор enumOrdinal

This commit is contained in:
Victor 2016-07-30 11:39:26 +03:00
parent a0b6bc168d
commit 33f1057ebd
2 changed files with 14 additions and 30 deletions

View File

@ -29,6 +29,10 @@ public final class Converters {
String apply();
}
public interface VoidToEnumFunction<E extends Enum<E>> {
Enum<E> apply();
}
public interface BooleanToVoidFunction {
void apply(boolean b);
}
@ -89,6 +93,10 @@ public final class Converters {
return new FunctionValue(args -> new StringValue(f.apply()));
}
public static <E extends Enum<E>> FunctionValue enumOrdinal(VoidToEnumFunction<E> f) {
return new FunctionValue(args -> NumberValue.of(f.apply().ordinal()));
}
public static FunctionValue booleanToVoid(BooleanToVoidFunction f) {
return new FunctionValue(args -> {
Arguments.check(1, args.length);

View File

@ -689,17 +689,17 @@ public final class canvasfx implements Module {
set("fillRoundRect", this::fillRoundRect);
set("fillText", this::fillText);
set("getFill", this::getFill);
set("getFillRule", this::getFillRule);
set("getFillRule", enumOrdinal(graphics::getFillRule));
set("getGlobalAlpha", voidToDouble(graphics::getGlobalAlpha));
set("getGlobalBlendMode", this::getGlobalBlendMode);
set("getLineCap", this::getLineCap);
set("getGlobalBlendMode", enumOrdinal(graphics::getGlobalBlendMode));
set("getLineCap", enumOrdinal(graphics::getLineCap));
set("getLineDashOffset", voidToDouble(graphics::getLineDashOffset));
set("getLineJoin", this::getLineJoin);
set("getLineJoin", enumOrdinal(graphics::getLineJoin));
set("getLineWidth", voidToDouble(graphics::getLineWidth));
set("getMiterLimit", voidToDouble(graphics::getMiterLimit));
set("getStroke", this::getStroke);
set("getTextAlign", this::getTextAlign);
set("getTextBaseline", this::getTextBaseline);
set("getTextAlign", enumOrdinal(graphics::getTextAlign));
set("getTextBaseline", enumOrdinal(graphics::getTextBaseline));
set("isPointInPath", this::isPointInPath);
set("lineTo", double2ToVoid(graphics::lineTo));
set("moveTo", double2ToVoid(graphics::moveTo));
@ -846,34 +846,10 @@ public final class canvasfx implements Module {
return new ColorValue((Color)graphics.getFill());
}
private Value getFillRule(Value... args) {
return NumberValue.of(graphics.getFillRule().ordinal());
}
private Value getGlobalBlendMode(Value... args) {
return NumberValue.of(graphics.getGlobalBlendMode().ordinal());
}
private Value getLineCap(Value... args) {
return NumberValue.of(graphics.getLineCap().ordinal());
}
private Value getLineJoin(Value... args) {
return NumberValue.of(graphics.getLineJoin().ordinal());
}
private Value getStroke(Value... args) {
return new ColorValue((Color)graphics.getStroke());
}
private Value getTextAlign(Value... args) {
return NumberValue.of(graphics.getTextAlign().ordinal());
}
private Value getTextBaseline(Value... args) {
return NumberValue.of(graphics.getTextBaseline().ordinal());
}
private Value isPointInPath(Value... args) {
return NumberValue.fromBoolean(graphics.isPointInPath(args[0].asNumber(), args[1].asNumber()));
}