javafx.scene.effect.BlendMode Java Examples

The following examples show how to use javafx.scene.effect.BlendMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RadialMovieMenu.java    From RadialFx with GNU Lesser General Public License v3.0 7 votes vote down vote up
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;
   }
 
Example #2
Source File: ChatShowPane.java    From oim-fx with MIT License 6 votes vote down vote up
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();
}
 
Example #3
Source File: GeometryNodeSnippet.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: WritePane.java    From oim-fx with MIT License 6 votes vote down vote up
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();
}
 
Example #5
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 6 votes vote down vote up
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;
}
 
Example #6
Source File: BreakoutFactory.java    From FXGLGames with MIT License 6 votes vote down vote up
@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;
}
 
Example #7
Source File: SpaceRunnerFactory.java    From FXGLGames with MIT License 6 votes vote down vote up
@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();
}
 
Example #8
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 6 votes vote down vote up
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;
}
 
Example #9
Source File: SpaceRunnerFactory.java    From FXGLGames with MIT License 6 votes vote down vote up
@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();
}
 
Example #10
Source File: BreakoutFactory.java    From FXGLGames with MIT License 6 votes vote down vote up
@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;
}
 
Example #11
Source File: GameToken.java    From metastone with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #12
Source File: MvcLogoExample.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #13
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
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;
    }
 
Example #14
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
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;
}
 
Example #15
Source File: PongFactory.java    From FXGLGames with MIT License 5 votes vote down vote up
@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();
}
 
Example #16
Source File: PongFactory.java    From FXGLGames with MIT License 5 votes vote down vote up
@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();
}
 
Example #17
Source File: HoverOverlayImageView.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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
}
 
Example #18
Source File: DotGraphView.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
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));
}
 
Example #19
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
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;
}
 
Example #20
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
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;
}
 
Example #21
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
@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();
    }
}
 
Example #22
Source File: JFXHighlighter.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #23
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
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();
    }
}
 
Example #24
Source File: DigitFactory.java    From metastone with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example #25
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #26
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
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;
        }

    }
 
Example #27
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
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;
        }

    }
 
Example #28
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #29
Source File: BuildEntry_Controller.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
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);
}
 
Example #30
Source File: ChatWritePane.java    From oim-fx with MIT License 5 votes vote down vote up
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();
}