Search in sources :

Example 1 with LinearGradient

use of javafx.scene.paint.LinearGradient in project fxexperience2 by EricCanull.

the class ColorPickerControl method initialize.

/**
     * Private
     */
private void initialize() {
    final FXMLLoader loader = new FXMLLoader();
    //NOI18N
    loader.setLocation(ColorPickerControl.class.getResource("/fxml/FXMLColorPicker.fxml"));
    loader.setController(this);
    loader.setRoot(this);
    try {
        loader.load();
    } catch (IOException ex) {
        Logger.getLogger(ColorPickerControl.class.getName()).log(Level.SEVERE, null, ex);
    }
    assert hue_slider != null;
    assert picker_region != null;
    assert hue_textfield != null;
    assert saturation_textfield != null;
    assert brightness_textfield != null;
    assert alpha_textfield != null;
    assert red_textfield != null;
    assert green_textfield != null;
    assert blue_textfield != null;
    assert alpha_slider != null;
    // Make the grad for hue slider
    hue_slider.setStyle(makeHueSliderCSS());
    // Investigate why height + width listeners do not work
    // Indeed, the picker_handle_stackpane bounds may still be null at this point
    // UPDATE BELOW TO BE CALLED ONCE ONLY AT DISPLAY TIME
    picker_region.boundsInParentProperty().addListener((ov, oldb, newb) -> {
        picker_scrollpane.setHvalue(0.5);
        picker_scrollpane.setVvalue(0.5);
        // Init time only
        final Paint paint = paintPickerController.getPaintProperty();
        if (paint instanceof Color) {
            updateUI((Color) paint);
        } else if (paint instanceof LinearGradient || paint instanceof RadialGradient) {
            final GradientPicker gradientPicker = paintPickerController.getGradientPicker();
            final GradientPickerStop gradientPickerStop = gradientPicker.getSelectedStop();
            // Update the color preview with the color of the selected stop
            if (gradientPickerStop != null) {
                updateUI(gradientPickerStop.getColor());
            }
        }
    });
    final ChangeListener<Boolean> onHSBFocusedChange = (ov, oldValue, newValue) -> {
        if (newValue == false) {
            // Update UI
            final Color color = updateUI_OnHSBChange();
            // Update model
            setPaintProperty(color);
        }
    };
    final ChangeListener<Boolean> onRGBFocusedChange = (ov, oldValue, newValue) -> {
        if (newValue == false) {
            // Update UI
            final Color color = updateUI_OnRGBChange();
            // Update model
            setPaintProperty(color);
        }
    };
    final ChangeListener<Boolean> onHexaFocusedChange = (ov, oldValue, newValue) -> {
        if (newValue == false) {
            try {
                // Update UI
                final Color color = updateUI_OnHexaChange();
                // Update model
                setPaintProperty(color);
            } catch (IllegalArgumentException iae) {
                handleHexaException();
            }
        }
    };
    // TextField ON FOCUS LOST event handler
    hue_textfield.focusedProperty().addListener(onHSBFocusedChange);
    saturation_textfield.focusedProperty().addListener(onHSBFocusedChange);
    brightness_textfield.focusedProperty().addListener(onHSBFocusedChange);
    alpha_textfield.focusedProperty().addListener(onHSBFocusedChange);
    red_textfield.focusedProperty().addListener(onRGBFocusedChange);
    green_textfield.focusedProperty().addListener(onRGBFocusedChange);
    blue_textfield.focusedProperty().addListener(onRGBFocusedChange);
    hexa_textfield.focusedProperty().addListener(onHexaFocusedChange);
    // Slider ON VALUE CHANGE event handler
    hue_slider.valueProperty().addListener((ov, oldValue, newValue) -> {
        if (updating == true) {
            return;
        }
        double hue = newValue.doubleValue();
        // retrieve HSB TextFields values
        double saturation = Double.valueOf(saturation_textfield.getText()) / 100.0;
        double brightness = Double.valueOf(brightness_textfield.getText()) / 100.0;
        double alpha = Double.valueOf(alpha_textfield.getText());
        // Update UI
        final Color color = updateUI(hue, saturation, brightness, alpha);
        // Update model
        setPaintProperty(color);
    });
    alpha_slider.valueProperty().addListener((ov, oldValue, newValue) -> {
        if (updating == true) {
            return;
        }
        double alpha = newValue.doubleValue();
        // retrieve HSB TextFields values
        double hue = Double.valueOf(hue_textfield.getText());
        double saturation = Double.valueOf(saturation_textfield.getText()) / 100.0;
        double brightness = Double.valueOf(brightness_textfield.getText()) / 100.0;
        // Update UI
        final Color color = updateUI(hue, saturation, brightness, alpha);
        // Update model
        setPaintProperty(color);
    });
    final ChangeListener<Boolean> liveUpdateListener = (ov, oldValue, newValue) -> paintPickerController.setLiveUpdate(newValue);
    picker_region.pressedProperty().addListener(liveUpdateListener);
    hue_slider.pressedProperty().addListener(liveUpdateListener);
    alpha_slider.pressedProperty().addListener(liveUpdateListener);
}
Also used : Color(javafx.scene.paint.Color) TextField(javafx.scene.control.TextField) Mode(com.fxexperience.javafx.scene.control.paintpicker.PaintPicker.Mode) MouseEvent(javafx.scene.input.MouseEvent) IOException(java.io.IOException) StackPane(javafx.scene.layout.StackPane) LinearGradient(javafx.scene.paint.LinearGradient) GradientPickerStop(com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop) Logger(java.util.logging.Logger) VBox(javafx.scene.layout.VBox) Level(java.util.logging.Level) FXML(javafx.fxml.FXML) PaintPickerController(com.fxexperience.javafx.scene.control.paintpicker.PaintPickerController) ActionEvent(javafx.event.ActionEvent) ScrollPane(javafx.scene.control.ScrollPane) Slider(javafx.scene.control.Slider) Region(javafx.scene.layout.Region) Paint(javafx.scene.paint.Paint) FXMLLoader(javafx.fxml.FXMLLoader) RadialGradient(javafx.scene.paint.RadialGradient) GradientPicker(com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker) ChangeListener(javafx.beans.value.ChangeListener) Circle(javafx.scene.shape.Circle) Bounds(javafx.geometry.Bounds) Color(javafx.scene.paint.Color) RadialGradient(javafx.scene.paint.RadialGradient) IOException(java.io.IOException) Paint(javafx.scene.paint.Paint) FXMLLoader(javafx.fxml.FXMLLoader) GradientPickerStop(com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop) GradientPicker(com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker) LinearGradient(javafx.scene.paint.LinearGradient)

Example 2 with LinearGradient

use of javafx.scene.paint.LinearGradient in project fxexperience2 by EricCanull.

the class ColorPickerPopover method createHueGradient.

private static LinearGradient createHueGradient() {
    double offset;
    Stop[] stops = new Stop[255];
    for (int y = 0; y < 255; y++) {
        offset = 1 - (1.0 / 255) * y;
        int h = (int) ((y / 255.0) * 360);
        stops[y] = new Stop(offset, Color.hsb(h, 1.0, 1.0));
    }
    return new LinearGradient(0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE, stops);
}
Also used : LinearGradient(javafx.scene.paint.LinearGradient) Stop(javafx.scene.paint.Stop) Paint(javafx.scene.paint.Paint)

Example 3 with LinearGradient

use of javafx.scene.paint.LinearGradient in project FXyzLib by Birdasaur.

the class ClothMeshTest method start.

@Override
public void start(Stage stage) throws Exception {
    camera = new PerspectiveCamera(true);
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().addAll(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(1000000.0);
    camera.setFieldOfView(42);
    camera.setVerticalFieldOfView(true);
    camera.setTranslateZ(-1500);
    PointLight light = new PointLight(Color.LIGHTSKYBLUE);
    //cameraTransform.getChildren().add(light);
    light.translateXProperty().bind(camera.translateXProperty());
    light.translateYProperty().bind(camera.translateYProperty());
    light.translateZProperty().bind(camera.translateZProperty());
    ClothMesh cloth = new ClothMesh();
    cloth.setPerPointMass(10);
    cloth.setBendStrength(0.5);
    cloth.setStretchStrength(1.0);
    cloth.setShearStrength(0.55);
    cloth.setDrawMode(DrawMode.LINE);
    cloth.setCullFace(CullFace.NONE);
    //        cloth.setDiffuseMap(new Image("https://kenai.com/attachments/wiki_images/duke/Duke3DprogressionSmall.jpg"));
    cloth.setSpecularPower(5);
    StackPane root = new StackPane();
    root.setPickOnBounds(false);
    PointLight light2 = new PointLight(Color.GAINSBORO);
    light2.setTranslateZ(-1500);
    PointLight light3 = new PointLight(Color.AZURE);
    light3.setTranslateZ(2500);
    Group g = new Group();
    g.getChildren().addAll(cameraTransform, cloth, light2, light3);
    root.getChildren().add(g);
    Scene scene = new Scene(root, 1200, 600, true, SceneAntialiasing.BALANCED);
    Stop[] stops = new Stop[] { new Stop(0, Color.BLACK), new Stop(1, Color.RED) };
    LinearGradient lg = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stops);
    scene.setFill(lg);
    scene.setCamera(camera);
    //First person shooter keyboard movement
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        if (event.isShiftDown()) {
            change = 50.0;
        }
        KeyCode keycode = event.getCode();
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        if (keycode == KeyCode.A) {
            camera.setTranslateX(camera.getTranslateX() - change);
        }
        if (keycode == KeyCode.D) {
            camera.setTranslateX(camera.getTranslateX() + change);
        }
    });
    scene.setOnMousePressed((MouseEvent me) -> {
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseOldX = me.getSceneX();
        mouseOldY = me.getSceneY();
    });
    scene.setOnMouseDragged((MouseEvent me) -> {
        if (!cloth.isHover()) {
            mouseOldX = mousePosX;
            mouseOldY = mousePosY;
            mousePosX = me.getSceneX();
            mousePosY = me.getSceneY();
            mouseDeltaX = (mousePosX - mouseOldX);
            mouseDeltaY = (mousePosY - mouseOldY);
            double modifier = 10.0;
            double modifierFactor = 0.1;
            if (me.isControlDown()) {
                modifier = 0.1;
            }
            if (me.isShiftDown()) {
                modifier = 50.0;
            }
            if (me.isPrimaryButtonDown()) {
                // +
                cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
                // - 
                cameraTransform.rx.setAngle(((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
            } else if (me.isSecondaryButtonDown()) {
                double z = camera.getTranslateZ();
                double newZ = z + mouseDeltaX * modifierFactor * modifier;
                camera.setTranslateZ(newZ);
            } else if (me.isMiddleButtonDown()) {
                // -
                cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
                // -
                cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
            }
        }
    });
    stage.setScene(scene);
    //stage.setMaximized(true);
    stage.show();
    cloth.startSimulation();
}
Also used : Group(javafx.scene.Group) LinearGradient(javafx.scene.paint.LinearGradient) MouseEvent(javafx.scene.input.MouseEvent) Stop(javafx.scene.paint.Stop) KeyCode(javafx.scene.input.KeyCode) PerspectiveCamera(javafx.scene.PerspectiveCamera) PointLight(javafx.scene.PointLight) ClothMesh(org.fxyz.shapes.complex.cloth.ClothMesh) Scene(javafx.scene.Scene) StackPane(javafx.scene.layout.StackPane)

Example 4 with LinearGradient

use of javafx.scene.paint.LinearGradient in project FXyzLib by Birdasaur.

the class Patterns method createLightCarbonPattern.

public static final ImagePattern createLightCarbonPattern() {
    final double WIDTH = 12;
    final double HEIGHT = 12;
    final Canvas CANVAS = new Canvas(WIDTH, HEIGHT);
    final GraphicsContext CTX = CANVAS.getGraphicsContext2D();
    double offsetY = 0;
    CTX.beginPath();
    CTX.rect(0, 0, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(108, 108, 108)), new Stop(1, Color.rgb(100, 100, 100))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.083333, 0, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(142, 142, 142)), new Stop(1, Color.rgb(130, 130, 130))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.5, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    offsetY = 0.5;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(108, 108, 108)), new Stop(1, Color.rgb(100, 100, 100))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.583333, HEIGHT * 0.5, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0.5;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(142, 142, 142)), new Stop(1, Color.rgb(130, 130, 130))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.5, 0, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    offsetY = 0;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(152, 152, 152)), new Stop(1, Color.rgb(146, 146, 146))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.583333, HEIGHT * 0.083333, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0.083333;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(160, 160, 160)), new Stop(1, Color.rgb(152, 152, 152))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(0, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    offsetY = 0.5;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(152, 152, 152)), new Stop(1, Color.rgb(146, 146, 146))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.083333, HEIGHT * 0.583333, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0.583333;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(160, 160, 160)), new Stop(1, Color.rgb(152, 152, 152))));
    CTX.fill();
    final Image PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null);
    final ImagePattern PATTERN = new ImagePattern(PATTERN_IMAGE, 0, 0, WIDTH, HEIGHT, false);
    return PATTERN;
}
Also used : LinearGradient(javafx.scene.paint.LinearGradient) SnapshotParameters(javafx.scene.SnapshotParameters) GraphicsContext(javafx.scene.canvas.GraphicsContext) Stop(javafx.scene.paint.Stop) Canvas(javafx.scene.canvas.Canvas) ImagePattern(javafx.scene.paint.ImagePattern) Image(javafx.scene.image.Image)

Example 5 with LinearGradient

use of javafx.scene.paint.LinearGradient in project FXyzLib by Birdasaur.

the class Patterns method createCarbonPattern.

public static final ImagePattern createCarbonPattern() {
    final double WIDTH = 12;
    final double HEIGHT = 12;
    final Canvas CANVAS = new Canvas(WIDTH, HEIGHT);
    final GraphicsContext CTX = CANVAS.getGraphicsContext2D();
    double offsetY = 0;
    CTX.beginPath();
    CTX.rect(0, 0, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(35, 35, 35)), new Stop(1, Color.rgb(23, 23, 23))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.083333, 0, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(38, 38, 38)), new Stop(1, Color.rgb(30, 30, 30))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.5, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    offsetY = 0.5;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(35, 35, 35)), new Stop(1, Color.rgb(23, 23, 23))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.583333, HEIGHT * 0.5, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0.5;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(38, 38, 38)), new Stop(1, Color.rgb(30, 30, 30))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.5, 0, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    offsetY = 0;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(40, 40, 40))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.583333, HEIGHT * 0.083333, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0.083333;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(0, HEIGHT * 0.5, WIDTH * 0.5, HEIGHT * 0.5);
    CTX.closePath();
    offsetY = 0.5;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.5 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(40, 40, 40))));
    CTX.fill();
    CTX.beginPath();
    CTX.rect(WIDTH * 0.083333, HEIGHT * 0.583333, WIDTH * 0.333333, HEIGHT * 0.416666);
    CTX.closePath();
    offsetY = 0.583333;
    CTX.setFill(new LinearGradient(0, offsetY * HEIGHT, 0, 0.416666 * HEIGHT + offsetY * HEIGHT, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45))));
    CTX.fill();
    final Image PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null);
    final ImagePattern PATTERN = new ImagePattern(PATTERN_IMAGE, 0, 0, WIDTH, HEIGHT, false);
    return PATTERN;
}
Also used : LinearGradient(javafx.scene.paint.LinearGradient) SnapshotParameters(javafx.scene.SnapshotParameters) GraphicsContext(javafx.scene.canvas.GraphicsContext) Stop(javafx.scene.paint.Stop) Canvas(javafx.scene.canvas.Canvas) ImagePattern(javafx.scene.paint.ImagePattern) Image(javafx.scene.image.Image)

Aggregations

LinearGradient (javafx.scene.paint.LinearGradient)9 Stop (javafx.scene.paint.Stop)6 Paint (javafx.scene.paint.Paint)4 SnapshotParameters (javafx.scene.SnapshotParameters)3 Canvas (javafx.scene.canvas.Canvas)3 GraphicsContext (javafx.scene.canvas.GraphicsContext)3 Image (javafx.scene.image.Image)3 ImagePattern (javafx.scene.paint.ImagePattern)3 Mode (com.fxexperience.javafx.scene.control.paintpicker.PaintPicker.Mode)2 FXML (javafx.fxml.FXML)2 PerspectiveCamera (javafx.scene.PerspectiveCamera)2 PointLight (javafx.scene.PointLight)2 Scene (javafx.scene.Scene)2 KeyCode (javafx.scene.input.KeyCode)2 MouseEvent (javafx.scene.input.MouseEvent)2 StackPane (javafx.scene.layout.StackPane)2 Color (javafx.scene.paint.Color)2 RadialGradient (javafx.scene.paint.RadialGradient)2 GradientPicker (com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker)1 GradientPickerStop (com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop)1