本文整理汇总了Java中javafx.scene.canvas.GraphicsContext.setFill方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsContext.setFill方法的具体用法?Java GraphicsContext.setFill怎么用?Java GraphicsContext.setFill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.canvas.GraphicsContext
的用法示例。
在下文中一共展示了GraphicsContext.setFill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawYValueBox
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
@Override
public void drawYValueBox() {
if (showMouseHoverIndicator.getValue()){
double y = mouseY.getValue();
y = y - 10;
double x = 0;
double wd = 150;
double ht = 18;
if (mouseY == null) {
return;
}
int yIntPos = (int)Math.round(mouseY.getValue());
Float yValue = this.getValueByYPos(yIntPos);
if ( yValue != null && yValue != 0){
String strVolume = String.format("%.2f", yValue);
GraphicsContext gc = getGraphicsContext2D();
gc.setFill(Color.web("#010a23"));
gc.fillRect(x, y, wd, ht);
gc.setFill(Color.web("#4bf221"));
gc.fillText(strVolume, x + 13, y+13);
}
}
}
示例2: paintStone
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
* Paint a black/white stone onto a graphics context with a grid
* @param gc Graphics context
* @param startX Start (top left) x coordinate of the grid
* @param startY Start (top left) y coordinate of the grid
* @param cellSize Size of the grid cells
* @param row Row position of the stone
* @param col Column position of the stone
* @param index Index of the stone (1 = black, 2 = white)
* @param transparent Transparency value, 0.5 alpha if true
*/
private static void paintStone(GraphicsContext gc, double startX, double
startY, double cellSize, int row, int col, int index,
boolean transparent) {
double x = startX + col*cellSize;
double y = startY + row*cellSize;
double offset = (cellSize * 0.7) / 2;
gc.save();
if(transparent) {
gc.setGlobalAlpha(0.5);
}
switch(index) {
case 1:
gc.setFill(blackGradient);
gc.fillOval(x - offset, y - offset, cellSize * 0.7,
cellSize * 0.7);
break;
case 2:
gc.setFill(whiteGradient);
gc.fillOval(x - offset, y - offset, cellSize * 0.7,
cellSize * 0.7);
break;
}
gc.restore();
}
示例3: initDraw
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
private void initDraw(GraphicsContext gc) {
double canvasWidth = gc.getCanvas().getWidth();
double canvasHeight = gc.getCanvas().getHeight();
log.info("canvasWidth = {}, canvasHeight = {}", canvasWidth, canvasHeight);
gc.clearRect(0, 0, canvasWidth, canvasHeight);
gc.setStroke(borderRectangleColor);
gc.setLineWidth(5);
gc.strokeRect(0, // x of the upper left corner
0, // y of the upper left corner
canvasWidth, // width of the rectangle
canvasHeight); // height of the rectangle
gc.setFill(Color.RED);
gc.setStroke(Color.BLUE);
gc.setLineWidth(drawLineWidth);
}
示例4: setCanvasSize
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
* 设置canvas大小
*/
private void setCanvasSize() {
try {
FXMLLoader fxmlLoader = new FXMLLoader((getClass().getResource("size_chooser.fxml")));
Parent root1 = fxmlLoader.load();
Stage stage = new Stage(DECORATED);
stage.setTitle("选择画布");
Scene scene = new Scene(root1);
sizeChooser = fxmlLoader.getController();
stage.setScene(scene);
stage.showAndWait();
if (sizeChooser.getCanvas() != null) {
canvas.setHeight(sizeChooser.getCanvas().getHeight());
canvas.setWidth(sizeChooser.getCanvas().getWidth());
canvas.setLayoutX(450 - canvas.getWidth() / 2);
canvas.setLayoutY(300 - canvas.getHeight() / 2);
Rectangle rectangle = new Rectangle(canvas.getWidth(), canvas.getHeight());
rectangle.setLayoutX(canvas.getLayoutX());
rectangle.setLayoutY(canvas.getLayoutY());
mainPane.setClip(rectangle);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
} else {
//不选择就退出程序
System.exit(0);
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: initialize
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
@Override
public void initialize(URL location, ResourceBundle resources) {
LOG.info("Loading map data.");
worldMapCanvas.setOnDragDetected(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
LOG.info("Drag detected.");
}
});
worldMapCanvas.setOnMouseClicked(event -> {
LOG.info("Click detected.");
});
// Testing
final GraphicsContext gc = worldMapCanvas.getGraphicsContext2D();
gc.setFill(Color.AZURE);
gc.fillRect(0, 0, worldMapCanvas.getWidth(), worldMapCanvas.getHeight());
gc.setFill(Color.GREEN);
gc.strokeLine(40, 10, 10, 40);
}
示例6: draw
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
@Override
public void draw(DungeonTileRenderer renderer, GraphicsContext g)
{
g.setFill(this.stairPaint);
g.fillRect(0, 0, 1, 1);
g.setFill(this.stairPaint);
g.setEffect(new ColorAdjust(0, 0, -0.3, 0));
g.fillRect(0, SIZE_STEP, 1, SIZE_STEP);
}
示例7: drawStone
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
private void drawStone(DrawCoords position, StoneColour colour, double radius) {
GraphicsContext context = getGraphicsContext();
if ( colour == BLACK )
context.setFill(javafx.scene.paint.Paint.valueOf("#000000"));
else
context.setFill(Paint.valueOf("#FFFFFF"));
drawCircle(position, radius);
}
示例8: 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();
}
示例9: 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();
}
示例10: drawTextTick
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
@Override
public void drawTextTick(double x, double y, double value) {
GraphicsContext gc = getGraphicsContext2D();
double bigTickLength = 10; //Big Tick
//Draw ticks and draw texts
gc.setLineWidth(0.1);
gc.setStroke(ChartTickColorProperty.getValue());
gc.strokeLine(x, y, x + bigTickLength, y);
String strValue = "";
if (value >= 0 && value <= 0.01) {
strValue = String.format("%.4f", value);
}
else if (value > 0.01 && value <= 0.1) {
strValue = String.format("%.3f", value);
}
else if (value > 0.1 && value <= 1.0) {
strValue = String.format("%.3f", value);
}
else if (value > 1.0 && value <= 10.0) {
strValue = String.format("%.2f", value);
}
else {
strValue = String.format("%.2f", value);
}
gc.setFill(ChartTickColorProperty.getValue());
gc.fillText(strValue, x + bigTickLength + 3, y + 5);
}
示例11: update
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public void update(GraphicsContext gc) {
gc.setFill(Color.LIGHTBLUE);
gc.fillOval(x - radius, y - radius, radius * 2, radius * 2);
if (time > 0) {
time--;
}
if (time <= 0) {
expired = true;
}
}
示例12: drawTextTick
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
* Draw text tick
* @param x POS
* @param y POS
* @param value - the text to be drawn
*/
@Override
public void drawTextTick(double x, double y, double value) {
GraphicsContext gc = getGraphicsContext2D();
double bigTickLength = 10; //Big Tick
//Draw ticks and draw texts
gc.setLineWidth(0.1);
gc.setStroke(ChartTickColorProperty.getValue());
gc.strokeLine(x, y, x + bigTickLength, y);
String strValue = "";
if (value >= 0 && value <= 0.01) {
strValue = String.format("%.4f", value);
}
else if (value > 0.01 && value <= 0.1) {
strValue = String.format("%.3f", value);
}
else if (value > 0.1 && value <= 1.0) {
strValue = String.format("%.3f", value);
}
else if (value > 1.0 && value <= 10.0) {
strValue = String.format("%.2f", value);
}
else {
strValue = String.format("%.2f", value);
}
gc.setFill(ChartTickColorProperty.getValue());
gc.fillText(strValue, x + bigTickLength + 3, y + 5);
}
示例13: showPaint
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public void showPaint(Paint paint) {
GraphicsContext graphics = canvas.getGraphicsContext2D();
graphics.clearRect(0, 0, width, height);
// graphics.setStroke(Color.BLACK);
// graphics.setLineWidth(line);
// graphics.strokeRect(line / 2, line / 2, width + line, height + line);
graphics.setFill(paint);
graphics.fillRect(0, 0, width, height);
contentPane.getChildren().setAll(canvas);
showPopup();
}
示例14: showPlayerInfo
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public void showPlayerInfo(GraphicsContext gc) {
for (Tank tank : framework.getTanks()) {
int width = tank.getId().name().length() * 7 + 10;
gc.setFill(Color.LIGHTGRAY);
gc.fillRoundRect(tank.getX() - width / 2, tank.getY() - 65, width, 25, 4, 4);
gc.setFill(Color.WHITESMOKE);
gc.fillText(tank.getId().name(), tank.getX() - width / 2 + 5, tank.getY() - 50);
}
}
示例15: eraseAll
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
* It does a canvas clean up
*/
public void eraseAll() {
GraphicsContext gc = getGraphicsContext2D();
gc.clearRect(0,0, widthProperty().doubleValue(), heightProperty().doubleValue());
gc.setFill(Color.WHITESMOKE);
gc.fillRect(0,0, widthProperty().doubleValue(), heightProperty().doubleValue());
}