Search in sources :

Example 1 with ConicalGradient

use of eu.hansolo.enzo.common.ConicalGradient in project Board-Instrumentation-Framework by intel.

the class RadialBargraphSkin method recalculateBarGradient.

private void recalculateBarGradient() {
    double angleFactor = 1d / 360d;
    double emptyRange = 360d - getSkinnable().getAngleRange();
    double offset = angleFactor * ((360 - getSkinnable().getStartAngle() + 180 - emptyRange * 0.5) % 360);
    List<Stop> stops = new LinkedList<>();
    double emptyOffset = (emptyRange * 0.5) * angleFactor;
    double minFraction = 1.0;
    double maxFraction = 0.0;
    Color minFractionColor = Color.TRANSPARENT;
    Color maxFractionColor = Color.TRANSPARENT;
    for (Stop stop : getSkinnable().getBarGradient()) {
        double fraction = stop.getOffset();
        if (fraction < minFraction) {
            minFraction = fraction;
            minFractionColor = stop.getColor();
        }
        if (fraction > maxFraction) {
            maxFraction = fraction;
            maxFractionColor = stop.getColor();
        }
    }
    stops.add(new Stop(0d, minFractionColor));
    stops.add(new Stop(0d + emptyOffset, minFractionColor));
    stops.add(new Stop(1d - emptyOffset, maxFractionColor));
    stops.add(new Stop(1d, maxFractionColor));
    if (getSkinnable().getBarGradient().size() == 2) {
        stops.add(new Stop((maxFraction - minFraction) * 0.5, (Color) Interpolator.LINEAR.interpolate(minFractionColor, maxFractionColor, 0.5)));
    }
    for (Stop stop : getSkinnable().getBarGradient()) {
        if (Double.compare(stop.getOffset(), minFraction) == 0 || Double.compare(stop.getOffset(), maxFraction) == 0)
            continue;
        stops.add(stop);
    }
    barGradient = new ConicalGradient(new Point2D(size * 0.5, size * 0.5), offset, stops);
}
Also used : ConicalGradient(eu.hansolo.enzo.common.ConicalGradient) Stop(javafx.scene.paint.Stop) Point2D(javafx.geometry.Point2D) Color(javafx.scene.paint.Color) LinkedList(java.util.LinkedList)

Example 2 with ConicalGradient

use of eu.hansolo.enzo.common.ConicalGradient in project Board-Instrumentation-Framework by intel.

the class RadialBargraphSkin method initGraphics.

private void initGraphics() {
    // "OpenSans"
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/opensans-semibold.ttf"), (0.06 * PREFERRED_HEIGHT));
    barColor = getSkinnable().getBarColor();
    barGradient = new ConicalGradient(new Stop(0.0, Color.TRANSPARENT), new Stop(1.0, Color.TRANSPARENT));
    valueBlendBottomShadow = new DropShadow();
    valueBlendBottomShadow.setBlurType(BlurType.TWO_PASS_BOX);
    valueBlendBottomShadow.setColor(Color.rgb(255, 255, 255, 0.5));
    valueBlendBottomShadow.setOffsetX(0);
    valueBlendBottomShadow.setOffsetY(0.005 * PREFERRED_WIDTH);
    valueBlendBottomShadow.setRadius(0);
    valueBlendTopShadow = new InnerShadow();
    valueBlendTopShadow.setBlurType(BlurType.TWO_PASS_BOX);
    valueBlendTopShadow.setColor(Color.rgb(0, 0, 0, 0.7));
    valueBlendTopShadow.setOffsetX(0);
    valueBlendTopShadow.setOffsetY(0.005 * PREFERRED_WIDTH);
    valueBlendTopShadow.setRadius(0.005 * PREFERRED_WIDTH);
    blend = new Blend();
    blend.setMode(BlendMode.MULTIPLY);
    blend.setBottomInput(valueBlendBottomShadow);
    blend.setTopInput(valueBlendTopShadow);
    background = new Region();
    background.getStyleClass().setAll("background");
    ticksAndSectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ticksAndSections = ticksAndSectionsCanvas.getGraphicsContext2D();
    minMeasuredValue = new Region();
    minMeasuredValue.getStyleClass().setAll("min-measured-value");
    minMeasuredValueRotate = new Rotate(180 - getSkinnable().getStartAngle());
    minMeasuredValue.getTransforms().setAll(minMeasuredValueRotate);
    minMeasuredValue.setOpacity(getSkinnable().isMinMeasuredValueVisible() ? 1 : 0);
    minMeasuredValue.setManaged(getSkinnable().isMinMeasuredValueVisible());
    maxMeasuredValue = new Region();
    maxMeasuredValue.getStyleClass().setAll("max-measured-value");
    maxMeasuredValueRotate = new Rotate(180 - getSkinnable().getStartAngle());
    maxMeasuredValue.getTransforms().setAll(maxMeasuredValueRotate);
    maxMeasuredValue.setOpacity(getSkinnable().isMaxMeasuredValueVisible() ? 1 : 0);
    maxMeasuredValue.setManaged(getSkinnable().isMaxMeasuredValueVisible());
    threshold = new Region();
    threshold.getStyleClass().setAll("threshold");
    thresholdRotate = new Rotate(180 - getSkinnable().getStartAngle());
    threshold.getTransforms().setAll(thresholdRotate);
    threshold.setOpacity(getSkinnable().isThresholdVisible() ? 1 : 0);
    threshold.setManaged(getSkinnable().isThresholdVisible());
    thresholdExceeded = false;
    bar = new Arc();
    bar.setType(ArcType.ROUND);
    bar.setCenterX(PREFERRED_WIDTH * 0.5);
    bar.setCenterY(PREFERRED_HEIGHT * 0.5);
    bar.setRadiusX(PREFERRED_WIDTH * 0.5 - 4);
    bar.setRadiusY(PREFERRED_HEIGHT * 0.5 - 4);
    bar.setStartAngle(getSkinnable().getStartAngle() - 90);
    bar.setLength(0);
    bar.setStrokeType(StrokeType.CENTERED);
    bar.setStroke(null);
    bar.setFill(new RadialGradient(0, 0, PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.45, false, CycleMethod.NO_CYCLE, new Stop(0.0, barColor), // -5 for on the barColorHue)
    new Stop(0.76, barColor.deriveColor(-5, 1, 1, 1)), new Stop(0.79, barColor), new Stop(0.97, barColor), // -5 for on the barColorHue)
    new Stop(1.0, barColor.deriveColor(-5, 1, 1, 1))));
    knob = new Region();
    knob.setPickOnBounds(false);
    knob.getStyleClass().setAll("knob");
    dropShadow = new DropShadow();
    dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
    dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
    dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
    dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);
    title = new Text(getSkinnable().getTitle());
    title.setMouseTransparent(true);
    title.setTextOrigin(VPos.CENTER);
    title.getStyleClass().setAll("title");
    title.setEffect(getSkinnable().isPlainValue() ? null : blend);
    unit = new Text(getSkinnable().getUnit());
    unit.setMouseTransparent(true);
    unit.setTextOrigin(VPos.CENTER);
    unit.getStyleClass().setAll("unit");
    unit.setEffect(getSkinnable().isPlainValue() ? null : blend);
    value = new Text();
    value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getValue()));
    value.setMouseTransparent(true);
    value.setTextOrigin(VPos.CENTER);
    value.getStyleClass().setAll("value");
    value.setEffect(getSkinnable().isPlainValue() ? null : blend);
    // Set initial value
    double range = (getSkinnable().getMaxValue() - getSkinnable().getMinValue());
    double angleRange = getSkinnable().getAngleRange();
    angleStep = angleRange / range;
    double targetAngle = getSkinnable().getValue() * angleStep;
    angle.set(targetAngle);
    double currentValue = angle.get() / angleStep;
    value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", currentValue));
    value.setTranslateX((size - value.getLayoutBounds().getWidth()) * 0.5);
    bar.setLength(-currentValue * angleStep);
    // Add all nodes
    pane = new Pane();
    pane.getChildren().setAll(background, bar, ticksAndSectionsCanvas, minMeasuredValue, maxMeasuredValue, threshold, knob, title, unit, value);
    pane.getChildren().addAll(getSkinnable().getMarkers().keySet());
    getChildren().setAll(pane);
}
Also used : ConicalGradient(eu.hansolo.enzo.common.ConicalGradient) Rotate(javafx.scene.transform.Rotate) Stop(javafx.scene.paint.Stop) InnerShadow(javafx.scene.effect.InnerShadow) Blend(javafx.scene.effect.Blend) Canvas(javafx.scene.canvas.Canvas) RadialGradient(javafx.scene.paint.RadialGradient) Text(javafx.scene.text.Text) Pane(javafx.scene.layout.Pane) DropShadow(javafx.scene.effect.DropShadow) Arc(javafx.scene.shape.Arc) Region(javafx.scene.layout.Region)

Aggregations

ConicalGradient (eu.hansolo.enzo.common.ConicalGradient)2 Stop (javafx.scene.paint.Stop)2 LinkedList (java.util.LinkedList)1 Point2D (javafx.geometry.Point2D)1 Canvas (javafx.scene.canvas.Canvas)1 Blend (javafx.scene.effect.Blend)1 DropShadow (javafx.scene.effect.DropShadow)1 InnerShadow (javafx.scene.effect.InnerShadow)1 Pane (javafx.scene.layout.Pane)1 Region (javafx.scene.layout.Region)1 Color (javafx.scene.paint.Color)1 RadialGradient (javafx.scene.paint.RadialGradient)1 Arc (javafx.scene.shape.Arc)1 Text (javafx.scene.text.Text)1 Rotate (javafx.scene.transform.Rotate)1