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


Java GraphicsContext类代码示例

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


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

示例1: render

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
public void render(GraphicsContext gc)
{
	currentFrame++;
	if(currentFrame/frameRepeat >= frameCount)
	{
		currentFrame = 0;
	}
	gc.drawImage
	(
		source,
		(int)(currentFrame/frameRepeat)*sourceWidth,
		0,
		sourceWidth,
		sourceHeight,
		x - (width/2),
		y - (height/2),
		width,
		height
	);
}
 
开发者ID:GabrielCT,项目名称:Chase-R,代码行数:21,代码来源:AnimatedImage.java

示例2: drawRoundedRect

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
public static final void drawRoundedRect(final GraphicsContext CTX, final CtxBounds BOUNDS, final CtxCornerRadii RADII) {
    double x           = BOUNDS.getX();
    double y           = BOUNDS.getY();
    double width       = BOUNDS.getWidth();
    double height      = BOUNDS.getHeight();
    double xPlusWidth  = x + width;
    double yPlusHeight = y + height;

    CTX.beginPath();
    CTX.moveTo(x + RADII.getTopLeft(), y);
    CTX.lineTo(xPlusWidth - RADII.getTopRight(), y);
    CTX.quadraticCurveTo(xPlusWidth, y, xPlusWidth, y + RADII.getTopRight());
    CTX.lineTo(xPlusWidth, yPlusHeight - RADII.getBottomRight());
    CTX.quadraticCurveTo(xPlusWidth, yPlusHeight, xPlusWidth - RADII.getBottomRight(), yPlusHeight);
    CTX.lineTo(x + RADII.getBottomLeft(), yPlusHeight);
    CTX.quadraticCurveTo(x, yPlusHeight, x, yPlusHeight - RADII.getBottomLeft());
    CTX.lineTo(x, y + RADII.getTopLeft());
    CTX.quadraticCurveTo(x, y, x + RADII.getTopLeft(), y);
    CTX.closePath();
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:21,代码来源:Helper.java

示例3: drawTimeBox

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
/**
 * Draw little time box to indicate exactly the date time when
 * showMouseHoverIndicator is on
 */
public void drawTimeBox() {
    if (showMouseHoverIndicator.getValue()){
        double x = mouseX.getValue();
        double w = 45;
        x = x - w;
        double wd = 2 * w;
        double hi = 20;
        Calendar curDate = getDayByXPos(mouseX.getValue());
        if (curDate != null) {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            String strDateLabel = sf.format(curDate.getTime());
            GraphicsContext gc = getGraphicsContext2D();
            gc.setFill(Color.web("#010a23"));
            gc.fillRect(x, 0, wd, hi);
            gc.setFill(Color.web("#4bf221"));
            gc.fillText(strDateLabel, x+14, 14);
        }
    }
}
 
开发者ID:ztan5,项目名称:TechnicalAnalysisTool,代码行数:24,代码来源:BaseTimeCanvas.java

示例4: 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();
}
 
开发者ID:haslam22,项目名称:gomoku,代码行数:36,代码来源:BoardPane.java

示例5: 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);
        }
    }
}
 
开发者ID:ztan5,项目名称:TechnicalAnalysisTool,代码行数:24,代码来源:OBVYCanvas.java

示例6: TrainView

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
/**
 * Instantiates a new Train view.
 *
 * @param graphicsContext the graphics context
 */
public TrainView(GraphicsContext graphicsContext) {
    this.graphicsContext = graphicsContext;
    try {
        trainCarts = new HashMap<>();
        for (String color: model.util.Color.getValidColors()) {
            try (FileInputStream fi = new FileInputStream("sprites/cart_" + color + ".png")) {
                trainCarts.put(color, new Image(fi));
            }
        }
        trainParts = new HashMap<>();
        for (String type: trainPartTypes) {
            try (FileInputStream fi = new FileInputStream("sprites/" + type + ".png")) {
                trainParts.put(type, new Image(fi));
            }
        }
    } catch (IOException e) {
        System.err.println("TrainView.TrainView(): File error: " + e.getMessage());
    }
}
 
开发者ID:AdjustmentBeaver,项目名称:szoftlab,代码行数:25,代码来源:TrainView.java

示例7: NodeTooltip

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
/**
 * Constructs {@link NodeTooltip}.
 *
 * @param graphicsContext the context
 * @param node            the node
 * @param middleX         the middle x position of the node
 * @param belowY          the below y position of the node
 */
public NodeTooltip(final GraphVisualizer graphVisualizer, final GraphicsContext graphicsContext,
                   final GfaNode node, final double middleX, final double belowY) {
    int tempHeight = DEFAULT_HEIGHT;

    this.graphVisualizer = graphVisualizer;
    this.graphicsContext = graphicsContext;
    this.node = node;
    this.middleX = middleX;
    this.belowY = belowY;

    if (node.hasMetadata()) {
        tempHeight += Math.min(node.getMetadata().getGenomes().size(), MAX_GENOME_COUNT + 1) * LINE_HEIGHT + 10;
    }
    if (node.getSegments().get(0).getSequenceLength() > MAX_SEQUENCE_LENGTH) {
        tempHeight += LINE_HEIGHT * 1.5;
    }

    this.height = tempHeight;
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:28,代码来源:NodeTooltip.java

示例8: drawFireworks

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
private void drawFireworks(GraphicsContext gc) {
    Iterator<Particle> iter = particles.iterator();
    List<Particle> newParticles = new ArrayList<Particle>();
    while(iter.hasNext()) {
        Particle firework = iter.next();
        // if the update returns true then particle has expired
        if(firework.update()) {
            // remove particle from those drawn
            iter.remove();
            // check if it should be exploded
            if(firework.shouldExplodeChildren) {
                if(firework.size == 9) {
                    explodeCircle(firework, newParticles);
                } else if(firework.size == 8) {
                    explodeSmallCircle(firework, newParticles);
                }
            }
        }
        firework.draw(gc);
    }
    particles.addAll(newParticles);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:Fireworks.java

示例9: draw

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
public void draw(GraphicsContext context) {
    final double x = Math.round(posX);
    final double y = Math.round(posY);
    final double xVel = (x - lastPosX) * -5;
    final double yVel = (y - lastPosY) * -5;
    // set the opacity for all drawing of this particle
    context.setGlobalAlpha(Math.random() * this.alpha);
    // draw particle
    context.setFill(color);
    context.fillOval(x-size, y-size, size+size, size+size);
    // draw the arrow triangle from where we were to where we are now
    if (hasTail) {
        context.setFill(Color.rgb(255,255,255,0.3));
        context.fillPolygon(new double[]{posX + 1.5,posX + xVel,posX - 1.5}, 
                new double[]{posY,posY + yVel,posY}, 3);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:Fireworks.java

示例10: NodeView

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
public NodeView(GraphicsContext graphicsContext) {
    this.graphicsContext = graphicsContext;
    graphicsContext.setLineWidth(12);
    try {
        spriteNodes = new HashMap<>();
        for (String type: nodeTypes) {
            try (FileInputStream fi = new FileInputStream("sprites/" + type + ".png")) {
                spriteNodes.put(type, new Image(fi));
            }
        }
        spriteStations=new HashMap<>();
        spriteLoaderStations=new HashMap<>();
        for (String color: model.util.Color.getValidColors()) {
            try (FileInputStream fi = new FileInputStream("sprites/station_" + color + ".png")) {
                spriteStations.put(color, new Image(fi));
            }
            try (FileInputStream fi = new FileInputStream("sprites/loader_" + color + ".png")) {
                spriteLoaderStations.put(color, new Image(fi));
            }
        }
    } catch (IOException e) {
        System.err.println("NodeView.NodeView: File error: " + e.getMessage());
    }
}
 
开发者ID:AdjustmentBeaver,项目名称:szoftlab,代码行数:25,代码来源:NodeView.java

示例11: 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);
	
}
 
开发者ID:tfelix,项目名称:bestia-palantir,代码行数:27,代码来源:MapController.java

示例12: rotateContextForText

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
private void rotateContextForText(final GraphicsContext CTX, final double START_ANGLE, final double TEXT_ANGLE, final TickLabelOrientation ORIENTATION) {
    switch (ORIENTATION) {
        case ORTHOGONAL:
            if ((360 - START_ANGLE - TEXT_ANGLE) % 360 > 90 && (360 - START_ANGLE - TEXT_ANGLE) % 360 < 270) {
                CTX.rotate((180 - START_ANGLE - TEXT_ANGLE) % 360);
            } else {
                CTX.rotate((360 - START_ANGLE - TEXT_ANGLE) % 360);
            }
            break;
        case TANGENT:
            if ((360 - START_ANGLE - TEXT_ANGLE - 90) % 360 > 90 && (360 - START_ANGLE - TEXT_ANGLE - 90) % 360 < 270) {
                CTX.rotate((90 - START_ANGLE - TEXT_ANGLE) % 360);
            } else {
                CTX.rotate((270 - START_ANGLE - TEXT_ANGLE) % 360);
            }
            break;
        case HORIZONTAL:
        default:
            break;
    }
}
 
开发者ID:HanSolo,项目名称:circularplot,代码行数:22,代码来源:CircularPlot.java

示例13: render

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
public void render(int indexX, int indexY, GraphicsContext gc) {

        if (this == STANDARD) {
            gc.setFill(Color.valueOf("#debf89"));
            gc.fillRoundRect(indexX * 64, indexY * 64, 64, 64, 10, 10);
        }

        if (this == CORK) {
            gc.setFill(Color.valueOf("#debf89").brighter().brighter());
            gc.fillRoundRect(indexX * 64, indexY * 64, 64, 64, 10, 10);
        }

        if (this == HOLE) {
            gc.setFill(Color.GRAY.brighter());
            gc.fillOval(indexX * 64, indexY * 64, 64, 64);
        }
    }
 
开发者ID:TheBromo,项目名称:netTanks,代码行数:18,代码来源:Block.java

示例14: drawConner

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
/**
 * 设置图形节点为选中样式
 */
@Override
public void drawConner() {
    canvas.setMouseTransparent(true);
    isConnerShow = true;

    GraphicsContext gc = canvas.getGraphicsContext2D();
    double whiteR = 12;
    double blueR = 10;

    if (x1 != null) {
        double X = x.doubleValue();
        double Y = y.doubleValue();

        gc.setFill(Color.WHITE);
        gc.fillOval(x1.doubleValue() -6+ X, y1.doubleValue() -6+ Y, whiteR, whiteR);
        gc.fillOval(x2.doubleValue() - 6+ X, y2.doubleValue() - 6 + Y, whiteR, whiteR);

        gc.setFill(Color.color(0.03, 0.43, 0.81));
        gc.fillOval(x1.doubleValue() -5 + X, y1.doubleValue() -5 + Y, blueR, blueR);
        gc.fillOval(x2.doubleValue()-5+ X, y2.doubleValue() - 5 + Y, blueR, blueR);
    }


}
 
开发者ID:xfangfang,项目名称:PhotoScript,代码行数:28,代码来源:DragBoxWithLine.java

示例15: drawGrid

import javafx.scene.canvas.GraphicsContext; //导入依赖的package包/类
public void drawGrid() {
    GraphicsContext gc = drawingCanvas.getGraphicsContext2D();
    // Task: draw a grid paper with horizontal lines 20 pixels apart
    // and the vertical lines 20 pixels apart, as well
    
    double width = drawingCanvas.getWidth();
    double height = drawingCanvas.getHeight();
    
    gc.setStroke(Color.RED);
    for (int x = 0; x <= width; x += 20)
        gc.strokeLine(x, 0, x, height);
    
    for (int y = 0; y <= height; y += 20)
        gc.strokeLine(0, y, width, y);
    
    gc.setStroke(Color.BLUE);
    for (int x = 0; x <= width; x += 100)
        gc.strokeLine(x, 0, x, height);
    
    for (int y = 0; y <= height; y += 100)
        gc.strokeLine(0, y, width, y);
    
}
 
开发者ID:kmhasan-class,项目名称:spring2017java,代码行数:24,代码来源:FXMLDocumentController.java


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