当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.getWidth方法代码示例

本文整理汇总了Java中javafx.scene.canvas.Canvas.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.getWidth方法的具体用法?Java Canvas.getWidth怎么用?Java Canvas.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.scene.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.getWidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: take

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
/**
 * Takes a snapshot of a canvas and saves it to the destination.
 * <p>
 * After the screenshot is taken it shows a dialogue to the user indicating the location of the snapshot.
 *
 * @param canvas a JavaFX {@link Canvas} object
 * @return the destination of the screenshot
 */
public String take(final Canvas canvas) {
    final WritableImage writableImage = new WritableImage((int) canvas.getWidth(), (int) canvas.getHeight());
    final WritableImage snapshot = canvas.snapshot(new SnapshotParameters(), writableImage);

    try {
        ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), FILE_FORMAT, destination);
        new InformationDialogue(
                "Snapshot taken",
                "You can find your snapshot here: " + destination.getAbsolutePath()
        ).show();
    } catch (final IOException e) {
        LOGGER.error("Snapshot could not be taken.", e);
        new ErrorDialogue(e).show();
    }

    return destination.getAbsolutePath();
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:26,代码来源:Snapshot.java

示例2: getTopLeftCorner

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
public static DrawCoords getTopLeftCorner(Canvas canvas) {
	double length = getBoardLength(canvas);
	double canvasWidth = canvas.getWidth();
	double canvasHeight = canvas.getHeight();

	double x = 0;
	double y = 0;

	if ( canvasWidth > length )
		x = (canvasWidth - length) / 2;
	else
		y = (canvasHeight - length) / 2;

	return new DrawCoords(x, y);
}
 
开发者ID:GoSuji,项目名称:Suji,代码行数:16,代码来源:DimensionHelper.java

示例3: getBoardLength

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
public static double getBoardLength(Canvas canvas) {
	double canvasWidth = canvas.getWidth();
	double canvasHeight = canvas.getHeight();

	return Math.min(canvasHeight, canvasWidth);
}
 
开发者ID:GoSuji,项目名称:Suji,代码行数:7,代码来源:DimensionHelper.java

示例4: drawStrokes

import javafx.scene.canvas.Canvas; //导入方法依赖的package包/类
/**
 * Draws out the all of the phonemes in stroke form on the canvas of the Application.
 *
 * @param s The string that is to be split up and put into phonemes, and then drawn out.
 */
private void drawStrokes(String s, GraphicsContext gc){

    Canvas canvas = gc.getCanvas();

    // Clears all of the previous drawings
    gc.clearRect(0,0, canvas.getWidth(), canvas.getHeight());


    Character[][] phones = TextProc.phones(s);
    int x = 90;
    int y = 100;
    int line = 1;
    Stroke current;

    //Iterates through the sentence
    for (Character[] word : phones) {

        // Checks to see if it is necessary to wrap at the word. The on the end is for padding
        if((canvas.getWidth() - 90)  - x < GraphicsCalculations.wordLength(word)){
            line++;
            x = 80;
            y = line * 80;
        }

        y -= GraphicsCalculations.wordHeight(word);
        // Iterates through the word
        for (Character c : word) {

            // Don't bother with the vowels yet, only draw outlines.
            if (TextProc.isVowel(c)){
                continue;
            }

            current = TextProc.strokeMap.get(c);

            // The starting and ending points of the current stroke
            Point start = current.getStart();
            Point end = current.getEnd();

            // Draw the image
            gc.drawImage(current.getImage(), x - start.x, y - start.y);

            // Moves the pointer to the end of the stroke
            x += end.x - start.x;
            y += end.y - start.y;

        }

        // Puts 80 pixels in between words to fo indicate a space until joining is funtioning
        x += 80;
        y = line * 100;
    }

}
 
开发者ID:squablyScientist,项目名称:Pitman-Translator,代码行数:60,代码来源:Scratchpad.java


注:本文中的javafx.scene.canvas.Canvas.getWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。