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


Java GraphicsContext.setTextAlign方法代码示例

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


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

示例1: drawNumbers

import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
 * Draw numbers along the X axis for a previously drawn grid. Each number
 * aligns with the corresponding intersection on the grid.
 * @param gc Graphics context
 * @param startX Start point on x axis
 * @param startY Start point on y axis
 * @param rows Number of rows
 * @param columns Number of columns
 * @param cellSize Size of each cell in the grid
 * @param distance Draw distance away from the left of the grid
 */
private void drawNumbers(GraphicsContext gc, double startX, double
        startY, int rows, int columns, double cellSize, double distance) {
    gc.save();
    gc.setFont(BOARD_FONT);
    gc.setFill(Color.rgb(0,0,0, 0.75));
    for(int i = 0; i < size; i++) {
        double offset = i*cellSize;
        gc.setTextAlign(TextAlignment.CENTER);
        gc.setTextBaseline(VPos.CENTER);
        gc.fillText(Integer.toString(rows + 1 - i), startX - distance,
                startY + offset);
    }
    gc.restore();
}
 
开发者ID:haslam22,项目名称:gomoku,代码行数:26,代码来源:BoardPane.java

示例2: drawLetters

import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
 * Draw letters along the Y axis for a previously drawn grid. Each letter
 * aligns with the corresponding intersection on the grid.
 * @param gc Graphics context
 * @param startX Start point on x axis
 * @param startY Start point on y axis
 * @param rows Number of rows
 * @param columns Number of columns
 * @param cellSize Size of each cell in the grid
 * @param distance Draw distance away from the bottom of the grid
 */
private void drawLetters(GraphicsContext gc, double startX, double
        startY, int rows, int columns, double cellSize, double distance) {
    gc.save();
    gc.setFont(BOARD_FONT);
    gc.setFill(Color.rgb(0,0,0, 0.75));
    for(int i = 0; i < size; i++) {
        double offset = i*cellSize;
        gc.setTextAlign(TextAlignment.CENTER);
        gc.setTextBaseline(VPos.CENTER);
        gc.fillText(Character.toString((char)('A' + i)), startX + offset,
                startY + cellSize*(rows) + distance);
    }
    gc.restore();
}
 
开发者ID:haslam22,项目名称:gomoku,代码行数:26,代码来源:BoardPane.java

示例3: drawTextWithBackground

import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public static final void drawTextWithBackground(final GraphicsContext CTX, final String TEXT, final Font FONT, final Color TEXT_BACKGROUND, final Color TEXT_FILL, final double X, final double Y) {
    CtxDimension dim = getTextDimension(TEXT, FONT);
    double textWidth  = dim.getWidth() * 1.2;
    double textHeight = dim.getHeight();
    CTX.save();
    CTX.setFont(FONT);
    CTX.setTextBaseline(VPos.CENTER);
    CTX.setTextAlign(TextAlignment.CENTER);
    CTX.setFill(TEXT_BACKGROUND);
    CTX.fillRect(X - textWidth * 0.5, Y - textHeight * 0.5, textWidth, textHeight);
    CTX.setFill(TEXT_FILL);
    CTX.fillText(TEXT, X, Y);
    CTX.restore();
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:15,代码来源:Helper.java


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