當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。