Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas Clipping Not Working in JPro - "Canvas Path2D is not supported yet!" Error #191

Open
butthurter opened this issue Nov 15, 2024 · 0 comments

Comments

@butthurter
Copy link

butthurter commented Nov 15, 2024

I'm experiencing an issue with JavaFX Canvas clipping not working when running my application with JPro. Clipping operations on the Canvas do not seem to have any effect—the content outside the clipping region is still rendered as if clipping is not supported:

image

Additionally, the following message is logged to the console:
Canvas Path2D is not supported yet!

I believe this message may be related to the problem, suggesting that certain path operations required for clipping are not yet implemented in JPro.

Environment:

JPro Version: 2024.4.1
JavaFX Plugin Version: 0.1.0
JavaFX Version: 23.0.1
JVM: Eclipse Temurin 21.0.5
Operating System: Windows 11
Web Browser: Chrome 131.0.6778.70 (Official Build) (64-bit)

Source Code used to reproduce:

public class HelloJPro extends Application {

    public static final int CANVAS_WIDTH = 1920;
    public static final int CANVAS_HEIGHT = 1024;

    @Override
    public void start(Stage stage) {
        BorderPane root = new BorderPane();

        Canvas canvas = new Canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
        root.setCenter(canvas);
        root.setStyle("-fx-background-color: white;");

        final GraphicsContext gc = canvas.getGraphicsContext2D();

        root.setOnMousePressed(e -> {
            redrawCanvas(gc);
        });

        redrawCanvas(gc);

        stage.setScene(new Scene(root, CANVAS_WIDTH, CANVAS_HEIGHT));
        stage.show();
    }

    private long iteration = 0L;

    private void redrawCanvas(final GraphicsContext gc) {
        gc.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);

        // draw rectangle which represent clipping area for text
        gc.save();
        gc.rect(100, 90, 50, 50);
        gc.setFill(Color.LIGHTGREEN);
        gc.fill();
        gc.restore();

        gc.save();
        gc.beginPath();
        // introduce clip rectangle path
        gc.rect(100, 90, 50, 50);
        gc.clip();

        // filling rectangle, should be clipped
        gc.setFill(Color.GOLD);
        gc.fillRect(90, 80, 20, 30);

        // filling text, should be clipped
        gc.setFill(Color.BLACK);
        gc.fillText(this.iteration++ + "#Some text", 100, 100);

        gc.restore();
    }

    /**
     * Application entry point.
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant