Java Code Examples for javafx.scene.canvas.GraphicsContext#fillRect()
The following examples show how to use
javafx.scene.canvas.GraphicsContext#fillRect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenderedRegion.java From BlockMap with MIT License | 7 votes |
public void drawForeground(GraphicsContext gc, AABBd frustum, double scale) { if (this.level != 0) throw new IllegalStateException("Only the base level can draw the foreground"); double x = position.x() * 512, y = position.y() * 512, w = 512, h = 512, m = Math.min(6 / scale, 35); double xw = Math.min(frustum.maxX, x + w); double yh = Math.min(frustum.maxY, y + h); x = Math.max(frustum.minX, x); y = Math.max(frustum.minY, y); w = xw - x; h = yh - y; // gc.translate(x, y); gc.fillRect(x, y, w, m); gc.fillRect(x, y + h - m, w, m); gc.fillRect(x, y, m, h); gc.fillRect(x + w - m, y, m, h); }
Example 2
Source File: DefaultControlTreeItemGraphic.java From arma-dialog-creator with MIT License | 6 votes |
private void fillBox(Color color) { GraphicsContext gc = box.getGraphicsContext2D(); gc.save(); gc.clearRect(0, 0, box.getWidth(), box.getHeight()); gc.setFill(color); gc.fillRect(0, 0, box.getWidth(), box.getHeight()); gc.restore(); //generate hex string and bind it to tooltip final double f = 255.0; int r = (int) (color.getRed() * f); int g = (int) (color.getGreen() * f); int b = (int) (color.getBlue() * f); String opacity = DecimalFormat.getNumberInstance().format(color.getOpacity() * 100); Tooltip.install(box, new Tooltip(String.format( "red:%d, green:%d, blue:%d, opacity:%s%%", r, g, b, opacity)) ); }
Example 3
Source File: DiagramCanvas.java From JetUML with GNU General Public License v3.0 | 6 votes |
/** * Paints the panel and all the graph elements in aDiagramView. * Called after the panel is resized. */ public void paintPanel() { GraphicsContext context = getGraphicsContext2D(); context.setFill(Color.WHITE); context.fillRect(0, 0, getWidth(), getHeight()); if(UserPreferences.instance().getBoolean(BooleanPreference.showGrid)) { Grid.draw(context, new Rectangle(0, 0, (int) getWidth(), (int) getHeight())); } DiagramType.viewerFor(aDiagram).draw(aDiagram, context); aController.synchronizeSelectionModel(); aController.getSelectionModel().forEach( selected -> ViewerUtilities.drawSelectionHandles(selected, context)); aController.getSelectionModel().getRubberband().ifPresent( rubberband -> ToolGraphics.drawRubberband(context, rubberband)); aController.getSelectionModel().getLasso().ifPresent( lasso -> ToolGraphics.drawLasso(context, lasso)); }
Example 4
Source File: TileImage.java From mcaselector with MIT License | 6 votes |
public static void draw(Tile tile, GraphicsContext ctx, float scale, Point2f offset) { if (tile.image != null) { ctx.drawImage(tile.getImage(), offset.getX(), offset.getY(), Tile.SIZE / scale, Tile.SIZE / scale); } else { ctx.drawImage(ImageHelper.getEmptyTileImage(), offset.getX(), offset.getY(), Tile.SIZE / scale, Tile.SIZE / scale); } if (tile.marked) { //draw marked region ctx.setFill(Config.getRegionSelectionColor().makeJavaFXColor()); ctx.fillRect(offset.getX(), offset.getY(), Tile.SIZE / scale, Tile.SIZE / scale); } else if (tile.markedChunks.size() > 0) { if (tile.markedChunksImage == null) { createMarkedChunksImage(tile, Tile.getZoomLevel(scale)); } // apply markedChunksImage to ctx ctx.drawImage(tile.markedChunksImage, offset.getX(), offset.getY(), Tile.SIZE / scale, Tile.SIZE / scale); } }
Example 5
Source File: TileImage.java From mcaselector with MIT License | 6 votes |
static void createMarkedChunksImage(Tile tile, int zoomLevel) { WritableImage wImage = new WritableImage(Tile.SIZE / zoomLevel, Tile.SIZE / zoomLevel); Canvas canvas = new Canvas(Tile.SIZE / (float) zoomLevel, Tile.SIZE / (float) zoomLevel); GraphicsContext ctx = canvas.getGraphicsContext2D(); ctx.setFill(Config.getChunkSelectionColor().makeJavaFXColor()); for (Point2i markedChunk : tile.markedChunks) { Point2i regionChunk = markedChunk.mod(Tile.SIZE_IN_CHUNKS); if (regionChunk.getX() < 0) { regionChunk.setX(regionChunk.getX() + Tile.SIZE_IN_CHUNKS); } if (regionChunk.getY() < 0) { regionChunk.setY(regionChunk.getY() + Tile.SIZE_IN_CHUNKS); } ctx.fillRect(regionChunk.getX() * Tile.CHUNK_SIZE / (float) zoomLevel, regionChunk.getY() * Tile.CHUNK_SIZE / (float) zoomLevel, Tile.CHUNK_SIZE / (float) zoomLevel, Tile.CHUNK_SIZE / (float) zoomLevel); } SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT.makeJavaFXColor()); canvas.snapshot(params, wImage); tile.markedChunksImage = wImage; }
Example 6
Source File: FxmlImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
public static Image addArcFx2(Image image, int arc, Color bgColor) { try { if (image == null || arc <= 0) { return null; } double imageWidth = image.getWidth(), imageHeight = image.getHeight(); final Canvas canvas = new Canvas(imageWidth, imageHeight); final GraphicsContext g = canvas.getGraphicsContext2D(); g.setGlobalBlendMode(BlendMode.ADD); g.setFill(bgColor); g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); g.drawImage(image, 0, 0); Rectangle clip = new Rectangle(imageWidth, imageHeight); clip.setArcWidth(arc); clip.setArcHeight(arc); canvas.setClip(clip); SnapshotParameters parameters = new SnapshotParameters(); parameters.setFill(Color.TRANSPARENT); WritableImage newImage = canvas.snapshot(parameters, null); return newImage; } catch (Exception e) { // logger.error(e.toString()); return null; } }
Example 7
Source File: ShipImage.java From logbook-kai with MIT License | 5 votes |
/** * 補給ゲージ(燃料・弾薬)を取得します * * @param ship 艦娘 * @return 補給ゲージ */ static Image getSupplyGauge(Ship ship) { Canvas canvas = new Canvas(36, 12); GraphicsContext gc = canvas.getGraphicsContext2D(); Optional<ShipMst> mstOpt = Ships.shipMst(ship); if (mstOpt.isPresent()) { double width = canvas.getWidth(); ShipMst mst = mstOpt.get(); double fuelPer = (double) ship.getFuel() / (double) mst.getFuelMax(); double ammoPer = (double) ship.getBull() / (double) mst.getBullMax(); gc.setFill(Color.GRAY); gc.fillRect(0, 3, width, 2); gc.setFill(Color.GRAY); gc.fillRect(0, 10, width, 2); Color fuelColor = fuelPer >= 0.5D ? Color.GREEN : fuelPer >= 0.4D ? Color.ORANGE : Color.RED; Color ammoColor = ammoPer >= 0.5D ? Color.SADDLEBROWN : ammoPer >= 0.4D ? Color.ORANGE : Color.RED; gc.setFill(fuelColor); gc.fillRect(0, 0, width * fuelPer, 4); gc.setFill(ammoColor); gc.fillRect(0, 7, width * ammoPer, 4); } SnapshotParameters sp = new SnapshotParameters(); sp.setFill(Color.TRANSPARENT); return canvas.snapshot(sp, null); }
Example 8
Source File: TintedImageHelperRenderer.java From arma-dialog-creator with MIT License | 5 votes |
/** This method applies to {@link #setToPreviewMode(boolean)} */ public void paintTintedImage(@NotNull GraphicsContext gc) { gc.save(); if (rotated) { gc.translate(x + w / 2, y + h / 2); //move to center gc.rotate(rotateDeg); } if (flipped) { gc.scale(-1, 1); } gc.setFill(Color.TRANSPARENT); gc.setEffect(previewMode ? effect2 : effect1); gc.fillRect(0, 0, 1, 1); //this is just to trigger drawing the effect. Won't draw anything itself gc.restore(); }
Example 9
Source File: MoleculeViewSkin.java From openchemlib-js with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void drawBackground(GraphicsContext ctx, double w, double h) { ctx.save(); ctx.clearRect(0, 0, w, h); if (!control.isTransparent()) { ctx.setFill(getBackgroundColor()); ctx.fillRect(0, 0, w, h); } else { // System.out.println("Controle is Transparent"); } ctx.restore(); }
Example 10
Source File: ToolGraphics.java From JetUML with GNU General Public License v3.0 | 5 votes |
/** * Draws a handle on pGraphics that is centered at the position * (pX, pY). * * @param pGraphics The graphics context on which to draw the handle. * @param pX The x-coordinate of the center of the handle. * @param pY The y-coordinate of the center of the handle. */ private static void drawHandle(GraphicsContext pGraphics, int pX, int pY) { Paint oldStroke = pGraphics.getStroke(); Paint oldFill = pGraphics.getFill(); pGraphics.setStroke(SELECTION_COLOR); pGraphics.strokeRect((int)(pX - HANDLE_SIZE / 2.0) + 0.5, (int)(pY - HANDLE_SIZE / 2.0)+ 0.5, HANDLE_SIZE, HANDLE_SIZE); pGraphics.setFill(SELECTION_FILL_COLOR); pGraphics.fillRect((int)(pX - HANDLE_SIZE / 2.0)+0.5, (int)(pY - HANDLE_SIZE / 2.0)+0.5, HANDLE_SIZE, HANDLE_SIZE); pGraphics.setStroke(oldStroke); pGraphics.setFill(oldFill); }
Example 11
Source File: ScaleBarOverlayRenderer.java From paintera with GNU General Public License v2.0 | 4 votes |
@Override public synchronized void drawOverlays(GraphicsContext graphicsContext) { if (width > 0.0 && height > 0.0 && config.getIsShowing()) { double targetLength = Math.min(width, config.getTargetScaleBarLength()); double[] onePixelWidth = {1.0, 0.0, 0.0}; transform.applyInverse(onePixelWidth, onePixelWidth); final double globalCoordinateWidth = LinAlgHelpers.length(onePixelWidth); // length of scale bar in global coordinate system final double scaleBarWidth = targetLength * globalCoordinateWidth; final double pot = Math.floor( Math.log10( scaleBarWidth ) ); final double l2 = scaleBarWidth / Math.pow( 10, pot ); final int fracs = ( int ) ( 0.1 * l2 * subdivPerPowerOfTen ); final double scale1 = ( fracs > 0 ) ? Math.pow( 10, pot + 1 ) * fracs / subdivPerPowerOfTen : Math.pow( 10, pot ); final double scale2 = ( fracs == 3 ) ? Math.pow( 10, pot + 1 ) : Math.pow( 10, pot + 1 ) * ( fracs + 1 ) / subdivPerPowerOfTen; final double lB1 = scale1 / globalCoordinateWidth; final double lB2 = scale2 / globalCoordinateWidth; final double scale; final double scaleBarLength; if (Math.abs(lB1 - targetLength) < Math.abs(lB2 - targetLength)) { scale = scale1; scaleBarLength = lB1; } else { scale = scale2; scaleBarLength = lB2; } final double[] ratios = UNITS.stream().mapToDouble(unit -> config.getBaseUnit().getConverterTo(unit).convert(scale)).toArray(); int firstSmallerThanZeroIndex = 0; for (; firstSmallerThanZeroIndex < ratios.length; ++firstSmallerThanZeroIndex) { if (ratios[firstSmallerThanZeroIndex] < 1.0) break; } final int unitIndex = Math.max(firstSmallerThanZeroIndex - 1, 0); final Unit<Length> targetUnit = UNITS.get(unitIndex); final double targetScale = config.getBaseUnit().getConverterTo(targetUnit).convert(scale); final double x = 20; final double y = height - 30; final DecimalFormat format = new DecimalFormat(String.format("0.%s", String.join("", Collections.nCopies(config.getNumDecimals(), "#")))); final String scaleBarText = format.format(targetScale) + targetUnit.toString(); final Text text = new Text(scaleBarText); text.setFont(config.getOverlayFont()); final Bounds bounds = text.getBoundsInLocal(); final double tx = 20 + (scaleBarLength - bounds.getMaxX()) / 2; final double ty = y - 5; graphicsContext.setFill(config.getBackgroundColor()); // draw background graphicsContext.fillRect( x - 7, ty - bounds.getHeight() - 3, scaleBarLength + 14, bounds.getHeight() + 25 ); // draw scalebar graphicsContext.setFill(config.getForegroundColor()); graphicsContext.fillRect(x, y, ( int ) scaleBarLength, 10); // draw label graphicsContext.setFont(config.getOverlayFont()); graphicsContext.fillText(scaleBarText, tx, ty); } }
Example 12
Source File: GanttDisplay.java From Open-Lowcode with Eclipse Public License 2.0 | 4 votes |
private void draw() { GraphicsContext gc = getGraphicsContext2D(); gc.setFill(Color.WHITE); gc.fillRect(0, 0, getWidth(), getHeight()); Date[] allstartsofday = DateUtils.getAllStartOfDays(startdatedisplaywindow, enddatedisplaywindow, businesscalendar); logger.fine(" |-- treating " + allstartsofday.length + " starts of days"); GanttTaskCell.drawSeparators(gc, startdatedisplaywindow, enddatedisplaywindow, getHeight() / 2, 0, getHeight(), latestCellWidth, businesscalendar, 1); Font font = Font.font(10); gc.setFont(font); gc.setLineDashes(null); gc.setStroke(Color.BLACK); gc.setFill(Color.BLACK); double lasthourx = -50; double lastdayx = -200; for (int i = 0; i < allstartsofday.length; i++) { Date separatortoprint = allstartsofday[i]; double separatorratio = DateUtils.genericDateToCoordinates(separatortoprint, startdatedisplaywindow, enddatedisplaywindow, businesscalendar).getValue(); double xdate = separatorratio * latestCellWidth + 2; if (xdate - lastdayx > 50) { // gc.strokeText(dateformat.format(separatortoprint),xdate, 14); gc.fillText(dateformat.format(separatortoprint), xdate, 14); lastdayx = xdate; } if (!GanttTaskCell.isReducedDisplay(allstartsofday)) for (int j = businesscalendar.getDaywindowhourstart() + 1; j < businesscalendar .getDaywindowhourend(); j++) { Date hour = new Date(separatortoprint.getTime() + (j - businesscalendar.getDaywindowhourstart()) * 3600 * 1000); double hourratio = DateUtils.genericDateToCoordinates(hour, startdatedisplaywindow, enddatedisplaywindow, businesscalendar).getValue(); double x = hourratio * latestCellWidth - 3; if (x - lasthourx > 15) { // gc.strokeText(""+j,x, 28); gc.fillText("" + j, x, 28); lasthourx = x; } } } }
Example 13
Source File: MnistTestFXApp.java From java-ml-projects with Apache License 2.0 | 4 votes |
private void clear(GraphicsContext ctx) { ctx.setFill(Color.BLACK); ctx.fillRect(0, 0, 300, 300); }
Example 14
Source File: WidgetColorPopOverController.java From phoebus with Eclipse Public License 1.0 | 4 votes |
@Override protected void updateItem ( final NamedWidgetColor color, final boolean empty ) { super.updateItem(color, empty); if ( color == null || empty ) { setText(null); setGraphic(null); } else { setText(color.getName()); setGraphic(blob); final GraphicsContext gc = blob.getGraphicsContext2D(); gc.setFill(JFXUtil.convert(color)); gc.fillRect(0, 0, SIZE, SIZE); } }
Example 15
Source File: Helper.java From Medusa with Apache License 2.0 | 4 votes |
public static final ImagePattern createCarbonPattern() { final double SIZE = 12; final Canvas CANVAS = new Canvas(SIZE, SIZE); final GraphicsContext CTX = CANVAS.getGraphicsContext2D(); CTX.setFill(new LinearGradient(0, 0, 0, 0.5 * SIZE, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(35, 35, 35)), new Stop(1, Color.rgb(23, 23, 23)))); CTX.fillRect(0, 0, SIZE * 0.5, SIZE * 0.5); CTX.setFill(new LinearGradient(0, 0, 0, 0.416666 * SIZE, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(38, 38, 38)), new Stop(1, Color.rgb(30, 30, 30)))); CTX.fillRect(SIZE * 0.083333, 0, SIZE * 0.333333, SIZE * 0.416666); CTX.setFill(new LinearGradient(0, 0.5 * SIZE, 0, SIZE, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(35, 35, 35)), new Stop(1, Color.rgb(23, 23, 23)))); CTX.fillRect(SIZE * 0.5, SIZE * 0.5, SIZE * 0.5, SIZE * 0.5); CTX.setFill(new LinearGradient(0, 0.5 * SIZE, 0, 0.916666 * SIZE, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(38, 38, 38)), new Stop(1, Color.rgb(30, 30, 30)))); CTX.fillRect(SIZE * 0.583333, SIZE * 0.5, SIZE * 0.333333, SIZE * 0.416666); CTX.setFill(new LinearGradient(0, 0, 0, 0.5 * SIZE, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(40, 40, 40)))); CTX.fillRect(SIZE * 0.5, 0, SIZE * 0.5, SIZE * 0.5); CTX.setFill(new LinearGradient(0, 0.083333 * SIZE, 0, 0.5 * SIZE, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45)))); CTX.fillRect(SIZE * 0.583333, SIZE * 0.083333, SIZE * 0.333333, SIZE * 0.416666); CTX.setFill(new LinearGradient(0, 0.5 * SIZE, 0, SIZE, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(48, 48, 48)), new Stop(1, Color.rgb(40, 40, 40)))); CTX.fillRect(0, SIZE * 0.5, SIZE * 0.5, SIZE * 0.5); CTX.setFill(new LinearGradient(0, 0.583333 * SIZE, 0, SIZE, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(53, 53, 53)), new Stop(1, Color.rgb(45, 45, 45)))); CTX.fillRect(SIZE * 0.083333, SIZE * 0.583333, SIZE * 0.333333, SIZE * 0.416666); final Image PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null); final ImagePattern PATTERN = new ImagePattern(PATTERN_IMAGE, 0, 0, SIZE, SIZE, false); return PATTERN; }
Example 16
Source File: Tile.java From FXTutorials with MIT License | 4 votes |
public void draw(GraphicsContext g) { g.setFill(Color.color(life / MAX_LIFE, life / MAX_LIFE, life / MAX_LIFE)); g.fillRect(x * AlgorithmApp.TILE_SIZE, y * AlgorithmApp.TILE_SIZE, AlgorithmApp.TILE_SIZE, AlgorithmApp.TILE_SIZE); }
Example 17
Source File: HexDisplay.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void drawDigit(GraphicsContext graphics, int num) { GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION)); int x = getScreenX(); int y = getScreenY(); int width = getScreenWidth(); int height = getScreenHeight(); int margin = 4; int size = 6; if(top.contains(num)) { graphics.setFill(Color.RED); } else { graphics.setFill(Color.LIGHTGRAY); } graphics.fillRect(x + margin + size, y + margin, width - 2 * margin - 2 * size, size); if(middle.contains(num)) { graphics.setFill(Color.RED); } else { graphics.setFill(Color.LIGHTGRAY); } graphics.fillRect(x + margin + size, y + (height - size) / 2, width - 2 * margin - 2 * size, size); if(bottom.contains(num)) { graphics.setFill(Color.RED); } else { graphics.setFill(Color.LIGHTGRAY); } graphics.fillRect(x + margin + size, y + height - margin - size, width - 2 * margin - 2 * size, size); if(topRight.contains(num)) { graphics.setFill(Color.RED); } else { graphics.setFill(Color.LIGHTGRAY); } graphics.fillRect(x + width - margin - size, y + margin + size / 2, size, (height - size) / 2 - margin); if(topLeft.contains(num)) { graphics.setFill(Color.RED); } else { graphics.setFill(Color.LIGHTGRAY); } graphics.fillRect(x + margin, y + margin + size / 2, size, (height - size) / 2 - margin); if(botRight.contains(num)) { graphics.setFill(Color.RED); } else { graphics.setFill(Color.LIGHTGRAY); } graphics.fillRect(x + width - margin - size, y + height / 2, size, (height - size) / 2 - margin); if(botLeft.contains(num)) { graphics.setFill(Color.RED); } else { graphics.setFill(Color.LIGHTGRAY); } graphics.fillRect(x + margin, y + height / 2, size, (height - size) / 2 - margin); }
Example 18
Source File: ColorGradientAxis.java From chart-fx with Apache License 2.0 | 4 votes |
@Override protected void drawAxisLine(final GraphicsContext gc, final double axisLength, final double axisWidth, final double axisHeight) { // N.B. axis canvas is (by-design) larger by 'padding' w.r.t. // required/requested axis length (needed for nicer label placements on // border. final double paddingX = getSide().isHorizontal() ? getAxisPadding() : 0.0; final double paddingY = getSide().isVertical() ? getAxisPadding() : 0.0; // for relative positioning of axes drawn on top of the main canvas final double axisCentre = getCenterAxisPosition(); final double gradientWidth = getGradientWidth(); // save css-styled line parameters final Path tickStyle = getMajorTickStyle(); gc.save(); gc.setStroke(tickStyle.getStroke()); gc.setLineWidth(tickStyle.getStrokeWidth()); if (getSide().isHorizontal()) { gc.setFill(new LinearGradient(0, 0, axisLength, 0, false, NO_CYCLE, getColorGradient().getStops())); } else { gc.setFill(new LinearGradient(0, axisLength, 0, 0, false, NO_CYCLE, getColorGradient().getStops())); } // N.B. important: translate by padding ie. canvas is +padding larger on // all size compared to region gc.translate(paddingX, paddingY); switch (getSide()) { case LEFT: // axis line on right side of canvas gc.fillRect(snap(axisWidth - gradientWidth), snap(0), snap(axisWidth), snap(axisLength)); gc.strokeRect(snap(axisWidth - gradientWidth), snap(0), snap(axisWidth), snap(axisLength)); break; case RIGHT: // axis line on left side of canvas gc.fillRect(snap(0), snap(0), snap(gradientWidth), snap(axisLength)); gc.strokeRect(snap(0), snap(0), snap(gradientWidth), snap(axisLength)); break; case TOP: // line on bottom side of canvas (N.B. (0,0) is top left corner) gc.fillRect(snap(0), snap(axisHeight - gradientWidth), snap(axisLength), snap(axisHeight)); gc.strokeRect(snap(0), snap(axisHeight - gradientWidth), snap(axisLength), snap(axisHeight)); break; case BOTTOM: // line on top side of canvas (N.B. (0,0) is top left corner) gc.rect(snap(0), snap(0), snap(axisLength), snap(gradientWidth)); break; case CENTER_HOR: // axis line at the centre of the canvas gc.fillRect(snap(0), axisCentre * axisHeight - 0.5 * gradientWidth, snap(axisLength), snap(axisCentre * axisHeight + 0.5 * gradientWidth)); gc.strokeRect(snap(0), axisCentre * axisHeight - 0.5 * gradientWidth, snap(axisLength), snap(axisCentre * axisHeight + 0.5 * gradientWidth)); break; case CENTER_VER: // axis line at the centre of the canvas gc.fillRect(snap(axisCentre * axisWidth - 0.5 * gradientWidth), snap(0), snap(axisCentre * axisWidth + 0.5 * gradientWidth), snap(axisLength)); gc.strokeRect(snap(axisCentre * axisWidth - 0.5 * gradientWidth), snap(0), snap(axisCentre * axisWidth + 0.5 * gradientWidth), snap(axisLength)); break; default: break; } gc.restore(); }
Example 19
Source File: ColorArrayValueEditor.java From arma-dialog-creator with MIT License | 4 votes |
public ArrayEditorPopup(@Nullable Color initialColor) { VBox root = new VBox(5); root.setPadding(new Insets(10)); getContent().add(root); root.setStyle("-fx-background-color:-fx-background"); root.setBorder(new Border( new BorderStroke(Color.GRAY, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderStroke.THIN ) ) ); Canvas canvas = new Canvas(128, 32); StackPane stackPaneCanvas = new StackPane(canvas); stackPaneCanvas.setBorder(root.getBorder()); stackPaneCanvas.setMaxWidth(canvas.getWidth()); stackPaneCanvas.setAlignment(Pos.CENTER_LEFT); HBox paneHeader = new HBox(5, stackPaneCanvas, tfAsArray); root.getChildren().add(paneHeader); HBox.setHgrow(tfAsArray, Priority.ALWAYS); tfAsArray.setEditable(false); GraphicsContext gc = canvas.getGraphicsContext2D(); ValueListener<Double> valListener = (observer, oldValue, newValue) -> { Color c = getCurrentColor(); if (c != null) { if (c.getOpacity() < 1) { //draw a grid to show theres transparency gc.setGlobalAlpha(1); gc.setFill(Color.WHITE); Region.paintCheckerboard( gc, 0, 0, (int) canvas.getWidth(), (int) canvas.getHeight(), Color.GRAY, Color.WHITE, 5); } gc.setGlobalAlpha(c.getOpacity()); gc.setFill(c); gc.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); tfAsArray.setText(SVColor.toStringF(c.getRed(), c.getGreen(), c.getBlue(), c.getOpacity())); } }; r.getValueObserver().addListener(valListener); g.getValueObserver().addListener(valListener); b.getValueObserver().addListener(valListener); a.getValueObserver().addListener(valListener); if (initialColor != null) { r.getValueObserver().updateValue(getRounded(initialColor.getRed())); g.getValueObserver().updateValue(getRounded(initialColor.getGreen())); b.getValueObserver().updateValue(getRounded(initialColor.getBlue())); a.getValueObserver().updateValue(getRounded(initialColor.getOpacity())); } //r root.getChildren().add(getColorEditor("r", r)); //g root.getChildren().add(getColorEditor("g", g)); //b root.getChildren().add(getColorEditor("b", b)); //a root.getChildren().add(getColorEditor("a", a)); //footer root.getChildren().add(new Separator(Orientation.HORIZONTAL)); GenericResponseFooter footer = new GenericResponseFooter(true, true, false, null, cancelEvent -> { cancelled = true; ArrayEditorPopup.this.hide(); }, okEvent -> { if (!hasInvalid()) { return; } cancelled = false; ArrayEditorPopup.this.hide(); } ); ResourceBundle bundle = Lang.ApplicationBundle(); footer.getBtnOk().setText(bundle.getString("ValueEditors.ColorArrayEditor.use")); root.getChildren().add(footer); setAutoHide(true); setHideOnEscape(true); //when push esc key, hide it valListener.valueUpdated(r.getValueObserver(), null, null); }
Example 20
Source File: ErrorDataSetRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
/** * @param gc the graphics context from the Canvas parent * @param localCachedPoints reference to local cached data point object */ protected void drawBars(final GraphicsContext gc, final CachedDataPoints localCachedPoints) { if (!isDrawBars()) { return; } final int xOffset = localCachedPoints.dataSetIndex >= 0 ? localCachedPoints.dataSetIndex : 0; final int minRequiredWidth = Math.max(getDashSize(), localCachedPoints.minDistanceX); final double barWPercentage = getBarWidthPercentage(); final double dynBarWidth = minRequiredWidth * barWPercentage / 100; final double constBarWidth = getBarWidth(); final double localBarWidth = isDynamicBarWidth() ? dynBarWidth : constBarWidth; final double barWidthHalf = localBarWidth / 2 - (isShiftBar() ? xOffset * getShiftBarOffset() : 0); gc.save(); DefaultRenderColorScheme.setMarkerScheme(gc, localCachedPoints.defaultStyle, localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex); DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle); if (localCachedPoints.polarPlot) { for (int i = 0; i < localCachedPoints.actualDataCount; i++) { if (localCachedPoints.styles[i] == null) { gc.strokeLine(localCachedPoints.xZero, localCachedPoints.yZero, localCachedPoints.xValues[i], localCachedPoints.yValues[i]); } else { // work-around: bar colour controlled by the marker color gc.save(); gc.setFill(StyleParser.getColorPropertyValue(localCachedPoints.styles[i], XYChartCss.FILL_COLOR)); gc.setLineWidth(barWidthHalf); gc.strokeLine(localCachedPoints.xZero, localCachedPoints.yZero, localCachedPoints.xValues[i], localCachedPoints.yValues[i]); gc.restore(); } } } else { for (int i = 0; i < localCachedPoints.actualDataCount; i++) { double yDiff = localCachedPoints.yValues[i] - localCachedPoints.yZero; final double yMin; if (yDiff > 0) { yMin = localCachedPoints.yZero; } else { yMin = localCachedPoints.yValues[i]; yDiff = Math.abs(yDiff); } if (localCachedPoints.styles[i] == null) { gc.fillRect(localCachedPoints.xValues[i] - barWidthHalf, yMin, localBarWidth, yDiff); } else { gc.save(); gc.setFill(StyleParser.getColorPropertyValue(localCachedPoints.styles[i], XYChartCss.FILL_COLOR)); gc.fillRect(localCachedPoints.xValues[i] - barWidthHalf, yMin, localBarWidth, yDiff); gc.restore(); } } } gc.restore(); }