use of javafx.scene.paint.ImagePattern in project gs-ui-javafx by graphstream.
the class GraphBackgroundRenderer method fillImageTiled.
private void fillImageTiled(GraphicsContext g, DefaultCamera2D camera) {
GraphMetrics metrics = camera.getMetrics();
double px2gu = metrics.ratioPx2Gu;
Image img = null;
img = ImageCache.loadImage(style.getFillImage());
if (img == null) {
img = ImageCache.dummyImage();
}
// + ( padx * 2 ) // consider the padding ???
double gw = (metrics.graphWidthGU() * px2gu);
// + ( pady * 2 ) // probably not.
double gh = (metrics.graphHeightGU() * px2gu);
double x = (metrics.viewport[2] / 2) - (gw / 2);
double y = metrics.viewport[3] - (metrics.viewport[3] / 2) - (gh / 2);
g.setFill(new ImagePattern(img));
g.fillRect(0, 0, metrics.viewport[2], metrics.viewport[3]);
}
use of javafx.scene.paint.ImagePattern in project org.csstudio.display.builder by kasemir.
the class JFXRepresentation method updateBackground.
/**
* Update background, using background color and grid information from model
*/
private void updateBackground() {
final WidgetColor background = model.propBackgroundColor().getValue();
// Setting the "-fx-background:" of the root node propagates
// to all child nodes in the scene graph.
//
// if (isEditMode())
// model_root.setStyle("-fx-background: linear-gradient(from 0px 0px to 10px 10px, reflect, #D2A2A2 48%, #D2A2A2 2%, #D2D2A2 48% #D2D2A2 2%)");
// else
// model_root.setStyle("-fx-background: " + JFXUtil.webRGB(background));
//
// In edit mode, this results in error messages because the linear-gradient doesn't "work" for all nodes:
//
// javafx.scene.CssStyleHelper (calculateValue)
// Caught java.lang.ClassCastException: javafx.scene.paint.LinearGradient cannot be cast to javafx.scene.paint.Color
// while converting value for
// '-fx-background-color' from rule '*.text-input' in stylesheet ..jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
// '-fx-effect' from rule '*.scroll-bar:vertical>*.increment-button>*.increment-arrow' in StyleSheet ... jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
// '-fx-effect' from rule '*.scroll-bar:vertical>*.decrement-button>*.decrement-arrow' in stylesheet ... modena.bss
// '-fx-effect' from rule '*.scroll-bar:horizontal>*.increment-button>*.increment-arrow' in stylesheet ... modena.bss
//
// In the runtime, the background color style is applied to for example the TextEntryRepresentation,
// overriding its jfx_node.setBackground(..) setting.
// Setting just the scroll body background to a plain color or grid image provides basic color control.
// In edit mode, the horiz_bound, vert_bound lines and grid provide sufficient
// visual indication of the display size.
final Color backgroundColor = new Color(background.getRed(), background.getGreen(), background.getBlue());
final boolean gridVisible = isEditMode() ? model.propGridVisible().getValue() : false;
final int gridStepX = model.propGridStepX().getValue(), gridStepY = model.propGridStepY().getValue();
final WidgetColor grid_rgb = model.propGridColor().getValue();
final Color gridColor = new Color(grid_rgb.getRed(), grid_rgb.getGreen(), grid_rgb.getBlue());
final BufferedImage image = new BufferedImage(gridStepX, gridStepY, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = image.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2d.setBackground(backgroundColor);
g2d.clearRect(0, 0, gridStepX, gridStepY);
if (gridVisible) {
g2d.setColor(gridColor);
g2d.setStroke(new BasicStroke(GRID_LINE_WIDTH));
g2d.drawLine(0, 0, gridStepX, 0);
g2d.drawLine(0, 0, 0, gridStepY);
}
final WritableImage wimage = new WritableImage(gridStepX, gridStepY);
SwingFXUtils.toFXImage(image, wimage);
final ImagePattern pattern = new ImagePattern(wimage, 0, 0, gridStepX, gridStepY, false);
widget_parent.setBackground(new Background(new BackgroundFill(pattern, CornerRadii.EMPTY, Insets.EMPTY)));
}
use of javafx.scene.paint.ImagePattern in project FXyzLib by Birdasaur.
the class Patterns method createPattern.
public Image createPattern(CarbonPatterns cp, boolean save) {
ImagePattern pattern;
switch(cp) {
case DARK_CARBON:
pattern = createCarbonPattern();
break;
case LIGHT_CARBON:
pattern = createLightCarbonPattern();
break;
case CARBON_KEVLAR:
pattern = createCarbonKevlarPattern();
break;
default:
pattern = createCarbonPattern();
break;
}
Rectangle rectangle = new Rectangle(width, height);
if (pattern != null) {
rectangle.setFill(pattern);
}
rectangle.setStrokeWidth(0);
imgPattern = rectangle.snapshot(new SnapshotParameters(), null);
if (save) {
saveImage();
}
return imgPattern;
}
use of javafx.scene.paint.ImagePattern 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;
}
use of javafx.scene.paint.ImagePattern 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;
}
Aggregations