Java Code Examples for javafx.scene.canvas.Canvas#getHeight()

The following examples show how to use javafx.scene.canvas.Canvas#getHeight() . 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 vote down vote up
@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 vote down vote up
/**
 * 経験値ゲージ
 * @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 vote down vote up
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 vote down vote up
/**
 * 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);
}