Java Code Examples for javafx.scene.canvas.Canvas#getWidth()
The following examples show how to use
javafx.scene.canvas.Canvas#getWidth() .
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: ImageScaling.java From phoebus with Eclipse Public License 1.0 | 6 votes |
@Override public void start(final Stage stage) { // Image with red border final WritableImage image = new WritableImage(WIDTH, HEIGHT); final PixelWriter writer = image.getPixelWriter(); for (int x=0; x<WIDTH; ++x) { writer.setColor(x, 0, Color.RED); writer.setColor(x, HEIGHT-1, Color.RED); } for (int y=0; y<HEIGHT; ++y) { writer.setColor(0, y, Color.RED); writer.setColor(WIDTH-1, y, Color.RED); } // Draw into canvas, scaling 'up' final Canvas canvas = new Canvas(800, 600); canvas.getGraphicsContext2D().drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight()); final Scene scene = new Scene(new Group(canvas), canvas.getWidth(), canvas.getHeight()); stage.setScene(scene); stage.show(); }
Example 2
Source File: ShipImage.java From logbook-kai with MIT License | 6 votes |
/** * 経験値ゲージ * @param chara キャラクター * @param canvas Canvas * @param gc GraphicsContext */ private static void writeExpGauge(Ship ship, Canvas canvas, GraphicsContext gc) { double w = canvas.getWidth() - 7; double h = canvas.getHeight(); double gaugeHeight = 6; double exp = ship.getExp().get(0); double next = ship.getExp().get(1); double expPer; if (next > 0) { Integer nowLvExp = ExpTable.get().get(ship.getLv()); Integer nextLvExp = ExpTable.get().get(ship.getLv() + 1); if (nowLvExp != null && nextLvExp != null) { expPer = (exp - nowLvExp.doubleValue()) / (nextLvExp.doubleValue() - nowLvExp.doubleValue()); } else { expPer = 0; } } else { expPer = 0; } Color color = Color.TRANSPARENT.interpolate(Color.DEEPSKYBLUE, 0.9); gc.drawImage(createGauge(w, gaugeHeight, expPer, k -> color, EXPGAUGE_CACHE), 0, h - gaugeHeight); }
Example 3
Source File: SegmentController.java From Sword_emulator with GNU General Public License v3.0 | 5 votes |
public SegmentController(Canvas canvas, Machine machine) { this.machine = machine; this.gc = canvas.getGraphicsContext2D(); gc.setStroke(Color.RED); gc.setLineWidth(LINE_WIDTH); length = canvas.getWidth() / 16; padding = canvas.getHeight() / 2 - length; segmentMem = (SegmentMemory) machine.getAddressRedirector().getMemory(MemoryType.SEGMENT); TimingRenderer.register(this); }
Example 4
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 5
Source File: ShipImage.java From logbook-kai with MIT License | 5 votes |
/** * HPゲージ * @param chara キャラクター * @param canvas Canvas * @param gc GraphicsContext */ private static void writeHpGauge(Chara chara, Canvas canvas, GraphicsContext gc) { double w = canvas.getWidth(); double h = canvas.getHeight(); double gaugeWidth = 7; double hpPer = (double) chara.getNowhp() / (double) chara.getMaxhp(); gc.drawImage(createGauge(gaugeWidth, h, hpPer, ShipImage::hpGaugeColor, HPGAUGE_CACHE), w - gaugeWidth, 0); }