下面列出了javafx.scene.effect.Effect#javafx.scene.effect.BlendMode 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initComponent() {
this.getChildren().add(webView);
webEngine = webView.getEngine();
webPage = Accessor.getPageFor(webEngine);
// webPage.setEditable(false);
// webPage.setContextMenuEnabled(false);
webView.setFocusTraversable(true);
webView.setContextMenuEnabled(false);
webView.setBlendMode(BlendMode.DARKEN);// 透明
// webView.setBlendMode(BlendMode.LIGHTEN);
webView.setOnContextMenuRequested(e -> {
if (isLoad) {
contextMenu.show(webView.getScene().getWindow(), e.getScreenX(), e.getScreenY());
}
});
initializeHtml();
}
private void initComponent() {
this.getChildren().add(webView);
webEngine = webView.getEngine();
webPage = Accessor.getPageFor(webEngine);
webPage.setEditable(true);
webView.setFocusTraversable(true);
// webView.getEngine().setUserStyleSheetLocation(getClass().getResource("/resources/common/css/webview.css").toExternalForm());
// webPage.setBackgroundColor(255);
webView.setPrefWidth(300);
// webView.setOpacity(0.92);
webView.setBlendMode(BlendMode.DARKEN);
webView.setOnDragDropped(a -> {
});
initializeHtml();
}
static Node[] setModeOnCircle(BlendMode bm1, BlendMode bm2){
Node txt1 = new Text(bm1.name());
Node txt2 = new Text(bm2.name());
Node c1 = createCircle();
Node s1 = createSquare();
c1.setBlendMode(bm1);
Node c2 = createCircle();
Node s2 = createSquare();
c2.setBlendMode(bm1);
Node c3 = createCircle();
Node s3 = createSquare();
c3.setBlendMode(bm2);
Node c4 = createCircle();
Node s4 = createSquare();
c4.setBlendMode(bm2);
Node[] arr = {txt1, new Group(s1, c1), new Group(c2, s2), txt2, new Group(s3, c3), new Group(c4, s4) };
return arr;
}
static Node[] setModeOnSquare(BlendMode bm1, BlendMode bm2){
Node txt1 = new Text(bm1.name());
Node txt2 = new Text(bm2.name());
Node c1 = createCircle();
Node s1 = createSquare();
s1.setBlendMode(bm1);
Node c2 = createCircle();
Node s2 = createSquare();
s2.setBlendMode(bm1);
Node c3 = createCircle();
Node s3 = createSquare();
s3.setBlendMode(bm2);
Node c4 = createCircle();
Node s4 = createSquare();
s4.setBlendMode(bm2);
Node[] arr = {txt1, new Group(s1, c1), new Group(c2, s2), txt2, new Group(s3, c3), new Group(c4, s4) };
return arr;
}
@Spawns("Player")
public Entity newPlayer(SpawnData data) {
ParticleEmitter emitter = ParticleEmitters.newFireEmitter();
emitter.setBlendMode(BlendMode.SRC_OVER);
emitter.setStartColor(Color.WHITE);
emitter.setEndColor(Color.YELLOW);
emitter.setSize(1, 3);
emitter.setNumParticles(25);
emitter.setEmissionRate(1.0);
emitter.setExpireFunction(i -> Duration.seconds(0.2));
emitter.setSpawnPointFunction(i -> new Point2D(4, 17 + FXGLMath.random(-5, 5)));
emitter.setVelocityFunction(i -> new Point2D(FXGLMath.random(360, 400), FXGLMath.random(0.0, 1.0)));
emitter.setAccelerationFunction(() -> Point2D.ZERO);
return entityBuilder()
.type(SpaceRunnerType.PLAYER)
.from(data)
.viewWithBBox(texture("sprite_player.png", 40, 40))
.with(new CollidableComponent(true), new ParticleComponent(emitter))
.with(new HealthIntComponent(20))
.with(new PlayerComponent(), new EffectComponent(), new KeepOnScreenComponent().onlyVertically())
.build();
}
@Spawns("sparks")
public Entity newSparks(SpawnData data) {
Color color = data.get("color");
var e = entityBuilder()
.from(data)
.with(new ExpireCleanComponent(Duration.seconds(1.5)))
.build();
if (!getSettings().isExperimentalNative()) {
var emitter = ParticleEmitters.newExplosionEmitter(24);
emitter.setSourceImage(texture("particles/smoke_06.png", 16, 16).multiplyColor(color));
emitter.setSize(4, 16);
emitter.setMaxEmissions(1);
emitter.setExpireFunction(i -> Duration.seconds(FXGLMath.random(0.25, 1.0)));
emitter.setBlendMode(BlendMode.ADD);
emitter.setNumParticles(20);
e.addComponent(new ParticleComponent(emitter));
}
return e;
}
protected static Effect createShadowEffect() {
final DropShadow outerShadow = new DropShadow();
outerShadow.setRadius(3);
outerShadow.setSpread(0.2);
outerShadow.setOffsetX(3);
outerShadow.setOffsetY(3);
outerShadow.setColor(new Color(0.3, 0.3, 0.3, 1));
final Distant light = new Distant();
light.setAzimuth(-135.0f);
final Lighting l = new Lighting();
l.setLight(light);
l.setSurfaceScale(3.0f);
final Blend effects = new Blend(BlendMode.MULTIPLY);
effects.setTopInput(l);
effects.setBottomInput(outerShadow);
return effects;
}
private static Effect createShadowEffect() {
DropShadow outerShadow = new DropShadow();
outerShadow.setRadius(3);
outerShadow.setSpread(0.2);
outerShadow.setOffsetX(3);
outerShadow.setOffsetY(3);
outerShadow.setColor(new Color(0.3, 0.3, 0.3, 1));
Distant light = new Distant();
light.setAzimuth(-135.0f);
Lighting l = new Lighting();
l.setLight(light);
l.setSurfaceScale(3.0f);
Blend effects = new Blend(BlendMode.MULTIPLY);
effects.setTopInput(l);
effects.setBottomInput(outerShadow);
return effects;
}
@Spawns("Player")
public Entity newPlayer(SpawnData data) {
ParticleEmitter emitter = ParticleEmitters.newFireEmitter();
emitter.setBlendMode(BlendMode.SRC_OVER);
emitter.setStartColor(Color.WHITE);
emitter.setEndColor(Color.YELLOW);
emitter.setSize(1, 3);
emitter.setNumParticles(25);
emitter.setEmissionRate(1.0);
emitter.setExpireFunction(i -> Duration.seconds(0.2));
emitter.setSpawnPointFunction(i -> new Point2D(4, 17 + FXGLMath.random(-5, 5)));
emitter.setVelocityFunction(i -> new Point2D(FXGLMath.random(360, 400), FXGLMath.random(0.0, 1.0)));
emitter.setAccelerationFunction(() -> Point2D.ZERO);
return entityBuilder()
.type(SpaceRunnerType.PLAYER)
.from(data)
.viewWithBBox(texture("sprite_player.png", 40, 40))
.with(new CollidableComponent(true), new ParticleComponent(emitter))
.with(new HealthIntComponent(20))
.with(new PlayerComponent(), new EffectComponent(), new KeepOnScreenComponent().onlyVertically())
.build();
}
@Spawns("sparks")
public Entity newSparks(SpawnData data) {
Color color = data.get("color");
var e = entityBuilder()
.from(data)
.with(new ExpireCleanComponent(Duration.seconds(1.5)))
.build();
if (!getSettings().isExperimentalNative()) {
var emitter = ParticleEmitters.newExplosionEmitter(24);
emitter.setSourceImage(texture("particles/smoke_06.png", 16, 16).multiplyColor(color));
emitter.setSize(4, 16);
emitter.setMaxEmissions(1);
emitter.setExpireFunction(i -> Duration.seconds(FXGLMath.random(0.25, 1.0)));
emitter.setBlendMode(BlendMode.ADD);
emitter.setNumParticles(20);
e.addComponent(new ParticleComponent(emitter));
}
return e;
}
private void createTargetButton() {
target = (StackPane) lookup("#targetAnchor");
Image image = IconFactory.getTargetIcon();
ImageView targetIcon = new ImageView(image);
targetIcon.setClip(new ImageView(image));
ColorAdjust monochrome = new ColorAdjust();
monochrome.setSaturation(-1.0);
Blend red = new Blend(BlendMode.MULTIPLY, monochrome,
new ColorInput(0, 0, targetIcon.getImage().getWidth(), targetIcon.getImage().getHeight(), Color.RED));
Blend green = new Blend(BlendMode.MULTIPLY, monochrome,
new ColorInput(0, 0, targetIcon.getImage().getWidth(), targetIcon.getImage().getHeight(), new Color(0, 1, 0, 0.5)));
targetButton = targetIcon;
targetIcon.effectProperty().bind(Bindings.when(targetButton.hoverProperty()).then((Effect) green).otherwise((Effect) red));
targetButton.setId("target_button");
hideTargetMarker();
target.getChildren().add(targetButton);
}
private List<Text> getTextNodes(final String title, final double startAngle) {
final List<Text> texts = new ArrayList<Text>();
final char[] titleCharArray = title.toCharArray();
for (int i = titleCharArray.length - 1; i >= 0; i--) {
final Text charText = new Text(
Character.toString(titleCharArray[i]));
charText.setFontSmoothingType(FontSmoothingType.LCD);
charText.setSmooth(true);
charText.setMouseTransparent(true);
charText.setFill(textColor);
charText.setBlendMode(BlendMode.COLOR_BURN);
charText.setFont(textFont);
texts.add(charText);
}
return texts;
}
private void initComponent() {
this.getChildren().add(webView);
webEngine = webView.getEngine();
webPage = Accessor.getPageFor(webEngine);
webPage.setEditable(true);
webView.setFocusTraversable(true);
webView.setPrefWidth(300);
webView.setBlendMode(BlendMode.DARKEN);// 透明
initializeHtml();
}
public void initDisabledBuild(){
isDisabledInLauncher = true;
BoxBlur b = new BoxBlur();
b.setWidth(5.0);
b.setHeight(5.0);
b.setIterations(1);
Blend bl = new Blend();
bl.setMode(BlendMode.SRC_OVER);
bl.setOpacity(1.0);
bl.setTopInput(b);
disabledPanel.setEffect(b);
//disabledPanel.setVisible(true);
nonValidPanel.setVisible(true);
}
public static Image addTextFx(Image image, String textString,
Font font, Color color, int x, int y, float transparent, int shadow) {
try {
Group group = new Group();
Text text = new Text(x, y, textString);
text.setFill(color);
text.setFont(font);
if (shadow > 0) {
DropShadow dropShadow = new DropShadow();
dropShadow.setOffsetX(shadow);
dropShadow.setOffsetY(shadow);
text.setEffect(dropShadow);
}
group.getChildren().add(text);
Blend blend = new Blend(BlendMode.SRC_OVER);
blend.setBottomInput(new ImageInput(image));
blend.setOpacity(1.0 - transparent);
group.setEffect(blend);
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
WritableImage newImage = group.snapshot(parameters, null);
return newImage;
} catch (Exception e) {
logger.error(e.toString());
return null;
}
}
public static Image addArcFx(Image image, int arc, Color bgColor) {
try {
if (image == null || arc <= 0) {
return null;
}
Group group = new Group();
double imageWidth = image.getWidth(), imageHeight = image.getHeight();
Scene scene = new Scene(group);
ImageView view = new ImageView(image);
view.setPreserveRatio(true);
view.setFitWidth(imageWidth);
view.setFitHeight(imageHeight);
Rectangle clip = new Rectangle(imageWidth, imageHeight);
clip.setArcWidth(arc);
clip.setArcHeight(arc);
view.setClip(clip);
group.getChildren().add(view);
Blend blend = new Blend(BlendMode.SRC_OVER);
blend.setBottomInput(new ColorInput(0, 0, imageWidth, imageHeight, bgColor));
group.setEffect(blend);
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
WritableImage newImage = group.snapshot(parameters, null);
return newImage;
} catch (Exception e) {
// logger.error(e.toString());
return null;
}
}
public static Image addArcFx2(Image image, int arc, Color bgColor) {
try {
if (image == null || arc <= 0) {
return null;
}
double imageWidth = image.getWidth(), imageHeight = image.getHeight();
final Canvas canvas = new Canvas(imageWidth, imageHeight);
final GraphicsContext g = canvas.getGraphicsContext2D();
g.setGlobalBlendMode(BlendMode.ADD);
g.setFill(bgColor);
g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
g.drawImage(image, 0, 0);
Rectangle clip = new Rectangle(imageWidth, imageHeight);
clip.setArcWidth(arc);
clip.setArcHeight(arc);
canvas.setClip(clip);
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
WritableImage newImage = canvas.snapshot(parameters, null);
return newImage;
} catch (Exception e) {
// logger.error(e.toString());
return null;
}
}
public void start1(Stage primaryStage) {
try {
BlendMode bm1 = BlendMode.MULTIPLY;
BlendMode bm2 = BlendMode.SRC_OVER;
Node[] node = setEffectOnGroup(bm1, bm2);
//Node[] node = setModeOnGroup(bm1, bm2);
//Node[] node = setEffectOnCircle(bm1, bm2);
//Node[] node = setEffectOnSquare(bm1, bm2);
//Node[] node = setModeOnCircle(bm1, bm2);
//Node[] node = setModeOnSquare(bm1, bm2);
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(40);
grid.setVgap(15);
grid.setPadding(new Insets(20, 20, 20, 20));
int i = 0;
grid.addRow(i++, new Text("Circle top"), new Text("Square top"));
grid.add(node[0], 0, i++, 2, 1);
GridPane.setHalignment(node[0], HPos.CENTER);
grid.addRow(i++, node[1], node[2]);
grid.add(node[3], 0, i++, 2, 1);
GridPane.setHalignment(node[3], HPos.CENTER);
grid.addRow(i++, node[4], node[5]);
Text txt = new Text("Circle opacity - 0.5\nSquare opacity - 1.0");
grid.add(txt, 0, i++, 2, 1);
GridPane.setHalignment(txt, HPos.CENTER);
Scene scene = new Scene(grid, 350, 350);
primaryStage.setScene(scene);
primaryStage.setTitle("JavaFX blend effect");
primaryStage.onCloseRequestProperty()
.setValue(e -> System.out.println("Bye! See you later!"));
primaryStage.show();
} catch (Exception ex){
ex.printStackTrace();
}
}
@Override
public void run(){
try {
for(String effect: effects){
for(int i = 0; i < 11; i++){
double opacity = Math.round(i * 0.1 * 10.0) / 10.0;
System.out.println(effect + " = " + opacity);
String[] e = effect.split(",");
txt1.setText("The blend mode opacity: " + opacity);
txt2.setText(e[0]);
txt3.setText(e[1]);
Blend b1 = new Blend();
BlendMode bm1 = Enum.valueOf(BlendMode.class, e[0]);
b1.setMode(bm1);
b1.setOpacity(opacity);
g1.setEffect(b1);
Blend b2 = new Blend();
BlendMode bm2 = Enum.valueOf(BlendMode.class, e[1]);
b2.setMode(bm2);
b2.setOpacity(opacity);
g2.setEffect(b2);
TimeUnit.SECONDS.sleep(1);
if(pause){
while(true){
TimeUnit.SECONDS.sleep(1);
if(!pause){
break;
}
}
}
}
}
Platform.exit();
} catch (Exception ex){
ex.printStackTrace();
}
}
static Node[] setEffectOnGroup(BlendMode bm1, BlendMode bm2){
Node txt1 = new Text(bm1.name());
Node txt2 = new Text(bm2.name());
Blend blnd1 = new Blend();
blnd1.setMode(bm1);
Node c1 = createCircle();
Node s1 = createSquare();
Node g1 = new Group(s1, c1);
g1.setEffect(blnd1);
Node c2 = createCircle();
Node s2 = createSquare();
Node g2 = new Group(c2, s2);
g2.setEffect(blnd1);
Blend blnd2 = new Blend();
blnd2.setMode(bm2);
Node c3 = createCircle();
Node s3 = createSquare();
Node g3 = new Group(s3, c3);
g3.setEffect(blnd2);
Node c4 = createCircle();
Node s4 = createSquare();
Node g4 = new Group(c4, s4);
g4.setEffect(blnd2);
Node[] arr = {txt1, g1, g2, txt2, g3, g4 };
return arr;
}
static Node[] setModeOnGroup(BlendMode bm1, BlendMode bm2){
Node txt1 = new Text(bm1.name());
Node txt2 = new Text(bm2.name());
Node c1 = createCircle();
Node s1 = createSquare();
Node g1 = new Group(s1, c1);
g1.setBlendMode(bm1);
Node c2 = createCircle();
Node s2 = createSquare();
Node g2 = new Group(c2, s2);
g2.setBlendMode(bm1);
Node c3 = createCircle();
Node s3 = createSquare();
Node g3 = new Group(s3, c3);
g3.setBlendMode(bm2);
Node c4 = createCircle();
Node s4 = createSquare();
Node g4 = new Group(c4, s4);
g4.setBlendMode(bm2);
Node[] arr = {txt1, g1, g2, txt2, g3, g4 };
return arr;
}
static Node[] setEffectOnCircle(BlendMode bm1, BlendMode bm2){
Node txt1 = new Text(bm1.name());
Node txt2 = new Text(bm2.name());
Blend blnd1 = new Blend();
blnd1.setMode(bm1);
Node c1 = createCircle();
Node s1 = createSquare();
c1.setEffect(blnd1);
Node c2 = createCircle();
Node s2 = createSquare();
c2.setEffect(blnd1);
Blend blnd2 = new Blend();
blnd2.setMode(bm2);
Node c3 = createCircle();
Node s3 = createSquare();
c3.setEffect(blnd2);
Node c4 = createCircle();
Node s4 = createSquare();
c4.setEffect(blnd2);
Node[] arr = {txt1, new Group(s1, c1), new Group(c2, s2), txt2, new Group(s3, c3), new Group(c4, s4) };
return arr;
}
static Node[] setEffectOnSquare(BlendMode bm1, BlendMode bm2){
Node txt1 = new Text(bm1.name());
Node txt2 = new Text(bm2.name());
Blend blnd1 = new Blend();
blnd1.setMode(bm1);
Node c1 = createCircle();
Node s1 = createSquare();
s1.setEffect(blnd1);
Node c2 = createCircle();
Node s2 = createSquare();
s2.setEffect(blnd1);
Blend blnd2 = new Blend();
blnd2.setMode(bm2);
Node c3 = createCircle();
Node s3 = createSquare();
s3.setEffect(blnd2);
Node c4 = createCircle();
Node s4 = createSquare();
s4.setEffect(blnd2);
Node[] arr = {txt1, new Group(s1, c1), new Group(c2, s2), txt2, new Group(s3, c3), new Group(c4, s4) };
return arr;
}
@Spawns("ball")
public Entity newBall(SpawnData data) {
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
physics.setFixtureDef(new FixtureDef().density(0.3f).restitution(1.0f));
physics.setOnPhysicsInitialized(() -> physics.setLinearVelocity(5 * 60, -5 * 60));
var endGame = getip("player1score").isEqualTo(10).or(getip("player2score").isEqualTo(10));
ParticleEmitter emitter = ParticleEmitters.newFireEmitter();
emitter.startColorProperty().bind(
Bindings.when(endGame)
.then(Color.LIGHTYELLOW)
.otherwise(Color.LIGHTYELLOW)
);
emitter.endColorProperty().bind(
Bindings.when(endGame)
.then(Color.RED)
.otherwise(Color.LIGHTBLUE)
);
emitter.setBlendMode(BlendMode.SRC_OVER);
emitter.setSize(5, 10);
emitter.setEmissionRate(1);
return entityBuilder()
.from(data)
.type(EntityType.BALL)
.bbox(new HitBox(BoundingShape.circle(5)))
.with(physics)
.with(new CollidableComponent(true))
.with(new ParticleComponent(emitter))
.with(new BallComponent())
.build();
}
private void addGraphBackground(Paint paint) {
double margin = 5;
GraphPart graphPart = (GraphPart) getContentViewer().getRootPart()
.getContentPartChildren().get(0);
Group group = graphPart.getVisual();
Bounds bounds = group.getLayoutBounds();
group.setEffect(new Blend(BlendMode.SRC_OVER,
new ColorInput(bounds.getMinX() - margin,
bounds.getMinY() - margin,
bounds.getWidth() + 2 * margin,
bounds.getHeight() + 2 * margin, paint),
null));
}
/**
* Creates the {@link ImageView}s for the base and overlay image. Sets the
* opacity of the overlay {@link ImageView} to <code>0%</code> and the
* opacity of the base {@link ImageView} to <code>80%</code>.
*/
protected void createImageViews() {
baseImageView = new ImageView();
overlayImageView = new ImageView();
getChildren().addAll(baseImageView, overlayImageView);
setBlendMode(BlendMode.SRC_OVER);
// hide hover image, and show normal image
overlayImageView.setOpacity(0);
baseImageView.setOpacity(0.8); // 20% transparent
}
@Spawns("ball")
public Entity newBall(SpawnData data) {
PhysicsComponent physics = new PhysicsComponent();
physics.setBodyType(BodyType.DYNAMIC);
physics.setFixtureDef(new FixtureDef().density(0.3f).restitution(1.0f));
physics.setOnPhysicsInitialized(() -> physics.setLinearVelocity(5 * 60, -5 * 60));
var endGame = getip("player1score").isEqualTo(10).or(getip("player2score").isEqualTo(10));
ParticleEmitter emitter = ParticleEmitters.newFireEmitter();
emitter.startColorProperty().bind(
Bindings.when(endGame)
.then(Color.LIGHTYELLOW)
.otherwise(Color.LIGHTYELLOW)
);
emitter.endColorProperty().bind(
Bindings.when(endGame)
.then(Color.RED)
.otherwise(Color.LIGHTBLUE)
);
emitter.setBlendMode(BlendMode.SRC_OVER);
emitter.setSize(5, 10);
emitter.setEmissionRate(1);
return entityBuilder()
.from(data)
.type(EntityType.BALL)
.bbox(new HitBox(BoundingShape.circle(5)))
.with(physics)
.with(new CollidableComponent(true))
.with(new ParticleComponent(emitter))
.with(new BallComponent())
.build();
}
/**
* highlights the matching text in the specified pane
* @param pane node to search into its text
* @param query search text
*/
public synchronized void highlight(Parent pane, String query) {
if (this.parent != null && !boxes.isEmpty()) {
clear();
}
if(query == null || query.isEmpty()) return;
this.parent = pane;
Set<Node> nodes = getTextNodes(pane);
ArrayList<Rectangle> allRectangles = new ArrayList<>();
for (Node node : nodes) {
Text text = ((Text) node);
final int beginIndex = text.getText().toLowerCase().indexOf(query.toLowerCase());
if (beginIndex > -1 && node.impl_isTreeVisible()) {
ArrayList<Bounds> boundingBoxes = getMatchingBounds(query, text);
ArrayList<Rectangle> rectangles = new ArrayList<>();
for (Bounds boundingBox : boundingBoxes) {
HighLightRectangle rect = new HighLightRectangle(text);
rect.setCacheHint(CacheHint.SPEED);
rect.setCache(true);
rect.setMouseTransparent(true);
rect.setBlendMode(BlendMode.MULTIPLY);
rect.fillProperty().bind(paintProperty());
rect.setManaged(false);
rect.setX(boundingBox.getMinX());
rect.setY(boundingBox.getMinY());
rect.setWidth(boundingBox.getWidth());
rect.setHeight(boundingBox.getHeight());
rectangles.add(rect);
allRectangles.add(rect);
}
boxes.put(node, rectangles);
}
}
JFXUtilities.runInFXAndWait(()-> getParentChildren(pane).addAll(allRectangles));
}
private static void applyFontColor(ImageView image, Color color) {
ColorAdjust monochrome = new ColorAdjust();
monochrome.setSaturation(-1.0);
Effect colorInput = new ColorInput(0, 0, image.getImage().getWidth(), image.getImage().getHeight(), color);
Blend blend = new Blend(BlendMode.MULTIPLY, new ImageInput(image.getImage()), colorInput);
image.setClip(new ImageView(image.getImage()));
image.setEffect(blend);
image.setCache(true);
}
/**
* Retrieve an overlay image.
*
* @param overlayType
* The overlay type.
* @param side
* The side of the eye.
* @param color
* The overlay color.
*
* @return The overlay image.
*/
private static Image getOverlayImage(final int overlayType, final RightLeft side, final Color color) {
URL imageUrl = ClassLoader.getSystemResource("overlay/" + getOverlayFileName(overlayType, side));
Image image = new Image(imageUrl.toExternalForm());
Canvas canvas = new Canvas(OVERLAY_SIZE, OVERLAY_SIZE);
Color colorNoAlpha = new Color(color.getRed(), color.getGreen(), color.getBlue(), 1);
Blend effect = new Blend(
BlendMode.SRC_ATOP,
null,
new ColorInput(
0,
0,
OVERLAY_SIZE,
OVERLAY_SIZE,
colorNoAlpha));
// Type 2 is not changed in color.
if (overlayType != 2) {
canvas.getGraphicsContext2D().setEffect(effect);
}
canvas.getGraphicsContext2D().setGlobalAlpha(color.getOpacity());
canvas.getGraphicsContext2D().drawImage(image, 0, 0, OVERLAY_SIZE, OVERLAY_SIZE);
SnapshotParameters parameters = new SnapshotParameters();
parameters.setFill(Color.TRANSPARENT);
return canvas.snapshot(parameters, null);
}