Zielony Smok

JavaFX canvas: Atrybut ścieżki ‘fill rule’

Atrybut: fill rule

Typ: FillRule

Wartość domyślna: FillRule.NON_ZERO.

Getter: FillRule getFillRule()

Setter: void setFillRule(FillRule)

Save/restore: true

Opis: Metoda używana do określania wnętrza ścieżki dla operacji wypełniania ścieżki lub klipowania.

Atrybut ścieżki ‘fill rule’

Klasa Listing25_54a

Ściągnij klasę Listing25_54a

package rozdzial25c;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.shape.FillRule;
import javafx.stage.Stage;

public class Listing25_54a extends Application {

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        try {
            Group root = new Group();
            Canvas cv = new Canvas(400, 300);
            GraphicsContext gc = cv.getGraphicsContext2D();
            //
            gc.setStroke(Color.BLACK);
            gc.setFill(Color.AQUAMARINE);
            //-
            gc.setFillRule(FillRule.EVEN_ODD);
            //-
            gc.moveTo(0,200);
            gc.quadraticCurveTo(200,400,400,200);
            gc.quadraticCurveTo(200,0,0,200);
            gc.moveTo(100,250);
            gc.lineTo(100,150);
            gc.lineTo(300,250);
            gc.lineTo(300,150);
            gc.closePath();
            gc.fill();
            gc.stroke();
            //-
            FillRule fr = gc.getFillRule();
            System.out.println(fr);
            //-
            root.getChildren().add(cv);
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.setTitle("Atrybut ścieżki 'fill rule'");
            stage.setOnCloseRequest(e -> Platform.exit());
            stage.show();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
EVEN_ODD
Atrybut ścieżki 'fill rule'
Rys. 25_60. Atrybut ścieżki ‘fill rule’ (EVEN_ODD)
Klasa Listing25_54b

Ściągnij klasę Listing25_54b

package rozdzial25c;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.shape.FillRule;
import javafx.stage.Stage;

public class Listing25_54b extends Application {

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        try {
            Group root = new Group();
            Canvas cv = new Canvas(400, 300);
            GraphicsContext gc = cv.getGraphicsContext2D();
            gc.setStroke(Color.BLACK);
            gc.setFill(Color.AQUAMARINE);
            gc.setFillRule(FillRule.NON_ZERO);
            gc.moveTo(0,200);
            gc.quadraticCurveTo(200,400,400,200);
            gc.quadraticCurveTo(200,0,0,200);
            gc.moveTo(100,250);
            gc.lineTo(100,150);
            gc.lineTo(300,250);
            gc.lineTo(300,150);
            gc.closePath();
            gc.fill();
            gc.stroke();
            //-
            FillRule fr = gc.getFillRule();
            System.out.println(fr);
            //-
            root.getChildren().add(cv);
            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.setTitle("Atrybut ścieżki 'fill rule'");
            stage.setOnCloseRequest(e -> Platform.exit());
            stage.show();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}          
NON_ZERO
Atrybut ścieżki 'fill rule'
Rys. 25_61. Atrybut ścieżki ‘fill rule’ (NON_ZERO)