本文整理汇总了Java中javafx.scene.canvas.GraphicsContext.restore方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsContext.restore方法的具体用法?Java GraphicsContext.restore怎么用?Java GraphicsContext.restore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.canvas.GraphicsContext
的用法示例。
在下文中一共展示了GraphicsContext.restore方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
* Draws the image representing the nucleotide on a graphics context, with specified rotation.
* @param GraphicsContext gc: The GraphicsContext you want to draw the object on
* @param x: The x coord you want to draw the image at
* @param y: The y coord you want to draw the image at
* @param r: The rotation, in degrees, you want to draw the nucleotide at. 0 would draw it with the base pointing up.
*/
public void draw(GraphicsContext gc, int x, int y, int r) {
gc.save();
gc.translate(x, y);
gc.rotate(r);
gc.translate(-x, -y);
gc.drawImage(image, x, y);
gc.restore();
}
示例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: draw
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
* Draws the content of the canvas and updates the
* {@code renderingInfo} attribute with the latest rendering
* information.
*/
public final void draw() {
GraphicsContext ctx = getGraphicsContext2D();
ctx.save();
double width = getWidth();
double height = getHeight();
if (width > 0 && height > 0) {
ctx.clearRect(0, 0, width, height);
this.info = new ChartRenderingInfo();
if (this.chart != null) {
this.chart.draw(this.g2, new Rectangle((int) width,
(int) height), this.anchor, this.info);
}
}
ctx.restore();
for (OverlayFX overlay : this.overlays) {
overlay.paintOverlay(g2, this);
}
this.anchor = null;
}
示例4: 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();
}
示例5: render
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public void render(Bullet bullet, GraphicsContext gc) {
gc.save();
gc.translate(bullet.getX(), bullet.getY());
gc.transform(new Affine(new Rotate(bullet.getAngle()))); //Rotate the gc to the angle of the bullet's path
//TODO increase bullet size in general
if (this == STANDARD) {
gc.translate(-2, -3); //Move SVG to center of Bullet
gc.setFill(Color.GRAY);
gc.beginPath();
gc.appendSVGPath("M 0 3 Q 0 1 2 0 Q 4 1 4 3 L 4 7 L 0 7 Z"); //SVG PATH OF BULLET
gc.fill();
gc.closePath();
} else if (this == ROCKET) {
//TODO create rocket SVG
gc.setFill(Color.GRAY);
gc.beginPath();
gc.appendSVGPath("M 0 3 Q 0 1 2 0 Q 4 1 4 3 L 4 7 L 0 7 Z"); //SVG PATH OF BULLET
gc.fill();
gc.closePath();
} else if (this == BOUNCY) {
gc.setFill(Color.GRAY);
gc.fillOval(bullet.getX() - bullet.getRadius(), bullet.getY() - bullet.getRadius(), bullet.getRadius() * 2, bullet.getRadius() * 2);
}
gc.restore();
}
示例6: update
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public void update(GraphicsContext gc) {
angle += rotation;
x += Math.sin(Math.toRadians(-angle)) * velocity;
y += Math.cos(Math.toRadians(-angle)) * velocity;
bounds.setLocation(x, y, 64, 64, angle);
//RENDER
gc.save();
Affine transform = new Affine(new Rotate(angle, x, y));
gc.transform(transform);
gc.setFill(Color.GREY);
gc.fillRoundRect(x - 32, y - 32, 64, 64, 3, 3);
gc.setFill(color);
gc.fillRect(x - 32 + 12, y - 32, 64 - 24, 64);
gc.restore();
//Update turret
turret.update(gc);
if (currentPickUp != null && currentPickUp.getTime() == 0) {
currentPickUp = null;
bulletType = BulletType.STANDARD;
}
}
示例7: draw
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
* Draws both strands next to each other
* @param gc- graphics context to draw helix on
* @param x- left start of the drawing
* @param y- upper start of the drawing
*/
public void draw(GraphicsContext gc) {
gc.save();
gc.translate(x, y-imageSize);
gc.rotate(r);
gc.translate(-x, -(y-imageSize));
strands[0].draw(gc);
strands[1].draw(gc);
gc.restore();
}
示例8: drawCursor
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public static void drawCursor(GraphicsContext g, ViewPort v, Vector2fc mouse)
{
Vector2dc offset = ViewPort.getScreenPos(v,
(int) Math.floor(mouse.x()),
(int) Math.floor(mouse.y()),
new Vector2d());
g.save();
g.translate(offset.x(), offset.y());
g.scale(v.getUnitScale(), v.getUnitScale());
g.setFill(COLOR_CURSOR);
g.fillRect(0, 0, 1, 1);
g.restore();
}
示例9: drawTile
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public static void drawTile(GraphicsContext g, DungeonTileRenderer renderer, DungeonTile tile, double x, double y, double width, double height)
{
renderer.tile = tile;
g.save();
g.translate(x, y);
g.scale(width, height);
renderer.tile.draw(renderer, g);
g.restore();
}
示例10: render
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public void render(GraphicsContext g)
{
for(DungeonSlot slot : this.slots)
{
g.save();
slot.render(g);
g.restore();
}
}
示例11: 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();
}
示例12: 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();
}
示例13: draw
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
/**
* Draws all nucleotides in strand from left to right
* @param gc: GraphicsContext on which to draw strand
* Add type functionality
*/
public void draw(GraphicsContext gc) {
int x2 = x;
int y2 = y;
if(r!=0) {
gc.save();
gc.translate(x, y);
gc.rotate(r);
gc.translate(-x, -y);
}
if(type==1){
for(int i = 0; i < bases.size(); i++) {
if(bases.get(i) != null){
bases.get(i).draw(gc,x2,y);
if(i+1< bases.size()){
if(bases.get(i+1) != null && bonds.get(i)){
gc.strokeLine(x2+Nucleotide.getImageSize()*.81, y+Nucleotide.getImageSize()*.81, x2+Nucleotide.getImageSize()*1.10, y+Nucleotide.getImageSize()*.73);
}
}
}
x2+=Nucleotide.getImageSize();
}
}
else if(type == 0){
int lx = x2+Nucleotide.getImageSize()*2;
y2+=Nucleotide.getImageSize();
x2+=Nucleotide.getImageSize();
for(int i = 0; i < bases.size(); i++) {
if(bases.get(i) != null){
bases.get(i).draw(gc,x2,y2,180);
if(i+1< bases.size()){
if(bases.get(i+1) != null && bonds.get(i)){
//gc.strokeLine(x2,y2,x2+50,y2+50);
gc.strokeLine(lx-Nucleotide.getImageSize()*.81, y2-Nucleotide.getImageSize()*.81, lx-Nucleotide.getImageSize()*1.10, y2-Nucleotide.getImageSize()*.73);
}
}
}
x2+=Nucleotide.getImageSize();
lx+=Nucleotide.getImageSize();
}
}
else{
System.out.println("Type is not 0 or 1");
}
if(r!=0) {
gc.restore();
}
}
示例14: drawGrid
import javafx.scene.canvas.GraphicsContext; //导入方法依赖的package包/类
public static void drawGrid(GraphicsContext g, ViewPort v)
{
double dx = v.getX() % v.getUnitScale();
double dy = v.getY() % v.getUnitScale();
g.setStroke(COLOR_GRID);
g.setLineWidth(GRID_LINE_WIDTH);
while(dx < v.getWidth())
{
double x = v.getX() - dx;
if (Math.abs(x) < v.getUnitScale() / 2)
{
g.save();
g.setLineWidth(AXIS_LINE_WIDTH);
g.setStroke(COLOR_YAXIS);
g.strokeLine(dx, 0, dx, v.getHeight());
g.restore();
}
else
{
g.strokeLine(dx, 0, dx, v.getHeight());
}
dx += v.getUnitScale();
}
while(dy < v.getHeight())
{
double y = v.getY() - dy;
if (Math.abs(y) < v.getUnitScale() / 2)
{
g.save();
g.setLineWidth(AXIS_LINE_WIDTH);
g.setStroke(COLOR_XAXIS);
g.strokeLine(0, dy, v.getWidth(), dy);
g.restore();
}
else
{
g.strokeLine(0, dy, v.getWidth(), dy);
}
dy += v.getUnitScale();
}
}