本文整理汇总了Java中javafx.scene.canvas.GraphicsContext.setTextBaseline方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsContext.setTextBaseline方法的具体用法?Java GraphicsContext.setTextBaseline怎么用?Java GraphicsContext.setTextBaseline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.canvas.GraphicsContext
的用法示例。
在下文中一共展示了GraphicsContext.setTextBaseline方法的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();
}
示例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();
}
示例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();
}