use of javafx.scene.paint.RadialGradient in project org.csstudio.display.builder by kasemir.
the class BaseLEDRepresentation method updateChanges.
@Override
public void updateChanges() {
if (typeChanged.checkAndClear()) {
createLED();
styleChanged.mark();
dirty_content.mark();
}
super.updateChanges();
if (styleChanged.checkAndClear()) {
final Color color = JFXUtil.convert(model_widget.propForegroundColor().getValue());
label.setTextFill(color);
label.setFont(JFXUtil.convert(model_widget.propFont().getValue()));
final int w = model_widget.propWidth().getValue();
final int h = model_widget.propHeight().getValue();
jfx_node.setPrefSize(w, h);
if (led instanceof Ellipse) {
final Ellipse ell = (Ellipse) led;
ell.setCenterX(w / 2);
ell.setCenterY(h / 2);
ell.setRadiusX(w / 2);
ell.setRadiusY(h / 2);
} else if (led instanceof Rectangle) {
final Rectangle rect = (Rectangle) led;
rect.setWidth(w);
rect.setHeight(h);
}
label.setPrefSize(w, h);
}
if (dirty_content.checkAndClear()) {
led.setFill(// relative to actual size of LED
new RadialGradient(0, 0, 0.3, 0.3, 0.4, true, CycleMethod.NO_CYCLE, new Stop(0, value_color.interpolate(Color.WHITESMOKE, 0.8)), new Stop(1, value_color)));
label.setText(value_label);
}
}
use of javafx.scene.paint.RadialGradient in project tilesfx by HanSolo.
the class RadarChart method drawChart.
private void drawChart() {
final double CENTER_X = 0.5 * size;
final double CENTER_Y = CENTER_X;
final double CIRCLE_SIZE = 0.9 * size;
final double DATA_RANGE = getRange();
final double RANGE = 0.35714 * CIRCLE_SIZE;
final double OFFSET = 0.14286 * CIRCLE_SIZE;
final int NO_OF_SECTORS = getNoOfSectors();
final double MIN_VALUE = getMinValue();
final double MAX_VALUE = getMaxValue();
// clear the chartCanvas
chartCtx.clearRect(0, 0, size, size);
// draw the chart data
chartCtx.save();
if (gradientStops.isEmpty()) {
chartCtx.setFill(getChartFill());
} else {
chartCtx.setFill(new RadialGradient(0, 0, CENTER_X, CENTER_Y, CIRCLE_SIZE * 0.5, false, CycleMethod.NO_CYCLE, stops));
}
double radiusFactor;
switch(getMode()) {
case POLYGON:
if (isSmoothing()) {
double radAngle = Math.toRadians(180);
double radAngleStep = Math.toRadians(angleStep);
List<Point> points = new ArrayList<>();
double x = CENTER_X + (-Math.sin(radAngle) * (CENTER_Y - (0.36239 * size)));
double y = CENTER_Y + (+Math.cos(radAngle) * (CENTER_Y - (0.36239 * size)));
points.add(new Point(x, y));
for (int i = 0; i < NO_OF_SECTORS; i++) {
double r1 = (CENTER_Y - (CENTER_Y - OFFSET - ((data.get(i).getValue() - MIN_VALUE) / DATA_RANGE) * RANGE));
x = CENTER_X + (-Math.sin(radAngle) * r1);
y = CENTER_Y + (+Math.cos(radAngle) * r1);
points.add(new Point(x, y));
radAngle += radAngleStep;
}
double r3 = (CENTER_Y - (CENTER_Y - OFFSET - ((data.get(NO_OF_SECTORS - 1).getValue() - MIN_VALUE) / DATA_RANGE) * RANGE));
x = CENTER_X + (-Math.sin(radAngle) * r3);
y = CENTER_Y + (+Math.cos(radAngle) * r3);
points.add(new Point(x, y));
Point[] interpolatedPoints = Helper.subdividePoints(points.toArray(new Point[0]), 8);
chartCtx.beginPath();
chartCtx.moveTo(interpolatedPoints[0].getX(), interpolatedPoints[0].getY());
for (int i = 0; i < interpolatedPoints.length - 1; i++) {
Point point = interpolatedPoints[i];
chartCtx.lineTo(point.getX(), point.getY());
}
chartCtx.lineTo(interpolatedPoints[interpolatedPoints.length - 1].getX(), interpolatedPoints[interpolatedPoints.length - 1].getY());
chartCtx.closePath();
chartCtx.fill();
} else {
chartCtx.beginPath();
chartCtx.moveTo(CENTER_X, 0.36239 * size);
for (int i = 0; i < NO_OF_SECTORS; i++) {
radiusFactor = (clamp(MIN_VALUE, MAX_VALUE, (data.get(i).getValue()) - MIN_VALUE) / DATA_RANGE);
// chartCtx.lineTo(CENTER_X, CENTER_Y - OFFSET - radiusFactor * RANGE);
chartCtx.lineTo(CENTER_X, CENTER_Y - OFFSET - radiusFactor * RANGE);
chartCtx.translate(CENTER_X, CENTER_Y);
chartCtx.rotate(angleStep);
chartCtx.translate(-CENTER_X, -CENTER_Y);
}
radiusFactor = ((clamp(MIN_VALUE, MAX_VALUE, data.get(NO_OF_SECTORS - 1).getValue()) - MIN_VALUE) / DATA_RANGE);
chartCtx.lineTo(CENTER_X, CENTER_Y - OFFSET - radiusFactor * RANGE);
chartCtx.closePath();
chartCtx.fill();
}
break;
case SECTOR:
chartCtx.translate(CENTER_X, CENTER_Y);
chartCtx.rotate(-90);
chartCtx.translate(-CENTER_X, -CENTER_Y);
// sector mode
for (int i = 0; i < NO_OF_SECTORS; i++) {
radiusFactor = (clamp(MIN_VALUE, MAX_VALUE, (data.get(i).getValue() - MIN_VALUE)) / DATA_RANGE);
chartCtx.beginPath();
chartCtx.moveTo(CENTER_X, CENTER_Y);
chartCtx.arc(CENTER_X, CENTER_Y, radiusFactor * RANGE + OFFSET, radiusFactor * RANGE + OFFSET, 0, -angleStep);
chartCtx.closePath();
chartCtx.fill();
chartCtx.translate(CENTER_X, CENTER_Y);
chartCtx.rotate(angleStep);
chartCtx.translate(-CENTER_X, -CENTER_Y);
}
break;
}
chartCtx.restore();
}
use of javafx.scene.paint.RadialGradient in project gs-ui-javafx by graphstream.
the class GradientFactory method radialGradientFromStyle.
/**
* Generate a radial gradient between whose center is at (cx,cy) with the
* given radius. The focus (fx,fy) is the start position of the gradient in
* the circle.
*
* @param cx
* The center point abscissa.
* @param cy
* The center point ordinate.
* @param fx
* The start point abscissa.
* @param fy
* The start point ordinate.
* @param radius
* The gradient radius.
* @param style
* The style.
* @return A paint for the gradient or null if the style specifies no
* gradient (the fill mode is not a radial gradient or there is only
* one fill colour).
*/
public static Paint radialGradientFromStyle(float cx, float cy, float radius, float fx, float fy, Style style) {
Paint paint = null;
if (style.getFillColorCount() > 1 && style.getFillMode() == FillMode.GRADIENT_RADIAL) {
Stop[] colors = createColors(style);
paint = new RadialGradient(0, 0, cx, cy, radius, false, CycleMethod.REFLECT, colors);
}
return paint;
}
use of javafx.scene.paint.RadialGradient in project Board-Instrumentation-Framework by intel.
the class SimpleRadarChartSkin method draw.
// ******************** Private Methods ***********************************
private final void draw() {
ctx.clearRect(0, 0, size, size);
final double CENTER_X = 0.5 * size;
final double CENTER_Y = 0.5 * size;
final double CIRCLE_SIZE = 0.95 * size;
final double DATA_RANGE = (getSkinnable().getMaxValue() - getSkinnable().getMinValue());
final double RANGE = 0.35714 * CIRCLE_SIZE;
final double OFFSET = 0.14286 * CIRCLE_SIZE;
// draw the chart background
ctx.setFill(getSkinnable().getChartBackground());
ctx.fillOval(0.5 * (size - CIRCLE_SIZE), 0.5 * (size - CIRCLE_SIZE), CIRCLE_SIZE, CIRCLE_SIZE);
// draw the chart data
ctx.save();
if (getSkinnable().getGradientStops().isEmpty()) {
ctx.setFill(getSkinnable().getChartFill());
} else {
ctx.setFill(new RadialGradient(0, 0, CENTER_X, CENTER_Y, 0.5 * CIRCLE_SIZE, false, CycleMethod.NO_CYCLE, gradientStops));
}
ctx.setStroke(getSkinnable().getChartStroke());
double radius;
if (getSkinnable().isPolygonMode()) {
// polygon mode
ctx.beginPath();
ctx.moveTo(CENTER_X, 0.36239 * size);
for (int i = 0; i < getSkinnable().getNoOfSectors(); i++) {
radius = ((getSkinnable().getData().get(i).getYValue() - getSkinnable().getMinValue()) / DATA_RANGE);
ctx.lineTo(CENTER_X, CENTER_Y - OFFSET - radius * RANGE);
ctx.translate(CENTER_X, CENTER_Y);
ctx.rotate(angleStep);
ctx.translate(-CENTER_X, -CENTER_Y);
}
radius = ((getSkinnable().getData().get(getSkinnable().getNoOfSectors()).getYValue() - getSkinnable().getMinValue()) / DATA_RANGE);
ctx.lineTo(CENTER_X, CENTER_Y - OFFSET - radius * RANGE);
ctx.closePath();
} else {
// prerotate ctx to have 0 at 12 o'clock
ctx.translate(CENTER_X, CENTER_Y);
ctx.rotate(-90);
ctx.translate(-CENTER_X, -CENTER_Y);
// sector mode
for (int i = 0; i < getSkinnable().getNoOfSectors(); i++) {
radius = ((getSkinnable().getData().get(i).getYValue() - getSkinnable().getMinValue()) / DATA_RANGE);
ctx.beginPath();
ctx.moveTo(CENTER_X, CENTER_Y);
ctx.arc(CENTER_X, CENTER_Y, radius * RANGE + OFFSET, radius * RANGE + OFFSET, 0, -angleStep);
ctx.closePath();
ctx.translate(CENTER_X, CENTER_Y);
ctx.rotate(angleStep);
ctx.translate(-CENTER_X, -CENTER_Y);
}
}
if (getSkinnable().isFilled()) {
ctx.fill();
} else {
ctx.stroke();
}
ctx.restore();
// draw center point
ctx.save();
ctx.setFill(getSkinnable().getChartBackground());
ctx.translate(CENTER_X - OFFSET, CENTER_Y - OFFSET);
ctx.fillOval(0, 0, 2 * OFFSET, 2 * OFFSET);
ctx.restore();
// draw concentric rings
ctx.setStroke(getSkinnable().getChartForeground());
double ringStepSize = (CIRCLE_SIZE - CIRCLE_SIZE * 0.28571) / 20.0;
double pos = 0.5 * (size - CIRCLE_SIZE);
double ringSize = CIRCLE_SIZE;
for (int i = 0; i < 11; i++) {
ctx.strokeOval(pos, pos, ringSize, ringSize);
pos += ringStepSize;
ringSize -= 2 * ringStepSize;
}
// draw star lines
ctx.save();
for (int i = 0; i < getSkinnable().getNoOfSectors(); i++) {
ctx.strokeLine(CENTER_X, 0.36239 * size, CENTER_X, 0.5 * (size - CIRCLE_SIZE));
ctx.translate(CENTER_X, CENTER_Y);
ctx.rotate(angleStep);
ctx.translate(-CENTER_X, -CENTER_Y);
}
ctx.restore();
// draw zero line
if (getSkinnable().isZeroLineVisible()) {
ctx.setStroke(getSkinnable().getZeroLineColor());
radius = ((-getSkinnable().getMinValue()) / DATA_RANGE);
ctx.strokeOval(0.5 * size - OFFSET - radius * RANGE, 0.5 * size - OFFSET - radius * RANGE, 2 * (radius * RANGE + OFFSET), 2 * (radius * RANGE + OFFSET));
}
// prerotate if sectormode
ctx.save();
if (!getSkinnable().isPolygonMode()) {
ctx.translate(CENTER_X, CENTER_Y);
ctx.rotate(angleStep * 0.5);
ctx.translate(-CENTER_X, -CENTER_Y);
}
// draw text
ctx.setFont(Fonts.robotoLight(0.025 * size));
ctx.setTextAlign(TextAlignment.CENTER);
ctx.setTextBaseline(VPos.CENTER);
ctx.setFill(getSkinnable().getChartText());
for (int i = 0; i < getSkinnable().getNoOfSectors(); i++) {
ctx.fillText(getSkinnable().getData().get(i).getXValue(), CENTER_X, 0.01 * size);
ctx.translate(CENTER_X, CENTER_Y);
ctx.rotate(angleStep);
ctx.translate(-CENTER_X, -CENTER_Y);
}
ctx.restore();
}
use of javafx.scene.paint.RadialGradient in project Board-Instrumentation-Framework by intel.
the class RadialBargraphSkin method resize.
private void resize() {
size = getSkinnable().getWidth() < getSkinnable().getHeight() ? getSkinnable().getWidth() : getSkinnable().getHeight();
centerX = size * 0.5;
centerY = size * 0.5;
if (size > 0) {
pane.setMaxSize(size, size);
pane.relocate((getSkinnable().getWidth() - size) * 0.5, (getSkinnable().getHeight() - size) * 0.5);
final double RADIUS = size * 0.5 - 2;
valueBlendBottomShadow.setOffsetY(0.005 * size);
valueBlendTopShadow.setOffsetY(0.005 * size);
valueBlendTopShadow.setRadius(0.005 * size);
dropShadow.setRadius(0.015 * size);
dropShadow.setOffsetY(0.015 * size);
background.setPrefSize(size, size);
ticksAndSectionsCanvas.setWidth(size);
ticksAndSectionsCanvas.setHeight(size);
ticksAndSections.clearRect(0, 0, size, size);
drawSections(ticksAndSections);
drawTickMarks(ticksAndSections);
ticksAndSectionsCanvas.setCache(true);
ticksAndSectionsCanvas.setCacheHint(CacheHint.QUALITY);
drawMarkers();
minMeasuredValue.setPrefSize(0.03 * size, 0.03 * size);
minMeasuredValue.relocate((size - minMeasuredValue.getPrefWidth()) * 0.5, size * 0.11);
minMeasuredValueRotate.setPivotX(minMeasuredValue.getPrefWidth() * 0.5);
minMeasuredValueRotate.setPivotY(size * 0.39);
minMeasuredValueRotate.setAngle(getSkinnable().getMinMeasuredValue() * angleStep - 180 - getSkinnable().getStartAngle());
maxMeasuredValue.setPrefSize(0.03 * size, 0.03 * size);
maxMeasuredValue.relocate((size - maxMeasuredValue.getPrefWidth()) * 0.5, size * 0.11);
maxMeasuredValueRotate.setPivotX(maxMeasuredValue.getPrefWidth() * 0.5);
maxMeasuredValueRotate.setPivotY(size * 0.39);
maxMeasuredValueRotate.setAngle(getSkinnable().getMaxMeasuredValue() * angleStep - 180 - getSkinnable().getStartAngle());
threshold.setPrefSize(0.06 * size, 0.055 * size);
threshold.relocate((size - threshold.getPrefWidth()) * 0.5, size * 0.08);
thresholdRotate.setPivotX(threshold.getPrefWidth() * 0.5);
thresholdRotate.setPivotY(size * 0.42);
thresholdRotate.setAngle(getSkinnable().getThreshold() * angleStep - 180 - getSkinnable().getStartAngle());
bar.setCenterX(centerX);
bar.setCenterY(centerY);
bar.setRadiusX(RADIUS);
bar.setRadiusY(RADIUS);
if (getSkinnable().isBarGradientEnabled()) {
recalculateBarGradient();
Image image = barGradient.getImage(size, size);
bar.setFill(new ImagePattern(image, 0, 0, size, size, false));
} else {
bar.setFill(new RadialGradient(0, 0, centerX, centerY, RADIUS, 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.setPrefSize(size * 0.75, size * 0.75);
knob.setTranslateX((size - knob.getPrefWidth()) * 0.5);
knob.setTranslateY((size - knob.getPrefHeight()) * 0.5);
resizeText();
}
}
Aggregations