/** * Convenience method to set the context's fillStyle to a {@link CssColor}, * specified in String form. * * @param fillStyleColor the color as a String * @see #getFillStyle() */ public final void setFillStyle(String fillStyleColor) { setFillStyle(CssColor.make(fillStyleColor)); }
/** * Convenience method to set the context's strokeStyle to a {@link CssColor}. * * @param strokeStyleColor the stroke color as a String * @see #getStrokeStyle() */ public final void setStrokeStyle(String strokeStyleColor) { setStrokeStyle(CssColor.make(strokeStyleColor)); }
@Override public void draw(Context2d ctx, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { // adjust our source rect to account for the scale factor sx *= scale.factor; sy *= scale.factor; sw *= scale.factor; sh *= scale.factor; ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh); }
private void addRoundRectPath(float x, float y, float width, float height, float radius) { float midx = x + width/2, midy = y + height/2, maxx = x + width, maxy = y + height; ctx.beginPath(); ctx.moveTo(x, midy); ctx.arcTo(x, y, midx, y, radius); ctx.arcTo(maxx, y, maxx, midy, radius); ctx.arcTo(maxx, maxy, midx, maxy, radius); ctx.arcTo(x, maxy, x, midy, radius); ctx.closePath(); }
ctx.save(); appendPath(ctx, transPath); } else { ctx.beginPath(); ctx.rect(clip.getX(), clip.getY(), clip.getWidth(), clip.getHeight()); ctx.closePath(); ctx.clip(); ctx.transform(matrix.get(0, 0), matrix.get(1, 0), matrix.get(0, 1), matrix.get(1, 1), matrix.get(0, 2), matrix.get(1, 2)); ctx.scale(size, size); ctx.translate(-viewbox.getX(), -viewbox.getY()); PreciseRectangle untransformedBbox = sprite.getPathSprite().dimensions(); if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setLineWidth(Double.isNaN(sprite.getStrokeWidth()) ? 1.0 : sprite.getStrokeWidth()); ctx.setStrokeStyle(getColor(sprite.getStroke(), untransformedBbox));//TODO read bbox from cache ctx.setFillStyle(getColor(sprite.getFill(), untransformedBbox));//TODO read bbox from cache ctx.setFont(text.getFontSize() + "px " + text.getFont()); ctx.setTextAlign(getTextAlign(text.getTextAnchor())); ctx.setTextBaseline(getTextBaseline(text.getTextBaseline())); ctx.fillText(text.getText(), text.getX(), text.getY()); } else if (sprite instanceof RectangleSprite) {
@Override public void paint(Canvas canvas, Matrix matrix) { if (Geometry.POLYGON.equals(geometry.getGeometryType())) { canvas.getContext2d().save(); canvas.getContext2d().setFillStyle(fillStyle); canvas.getContext2d().setStrokeStyle(strokeStyle); canvas.getContext2d().setLineWidth(strokeWidthPixels / matrix.getXx()); canvas.getContext2d().beginPath(); for (Geometry ring : geometry.getGeometries()) { Coordinate[] coords = ring.getCoordinates(); canvas.getContext2d().moveTo(coords[0].getX(), coords[0].getY()); for (int i = 1; i < coords.length - 1; i++) { canvas.getContext2d().lineTo(coords[i].getX(), coords[i].getY()); } } canvas.getContext2d().closePath(); canvas.getContext2d().fill(); canvas.getContext2d().stroke(); canvas.getContext2d().restore(); } }
context.beginPath(); context.setStrokeStyle(BLACK); context.fillRect(0, 0, centerX * 2, centerY * 2); context.setStrokeStyle(WHITE); super.onStart(); context.moveTo(centerX, centerY); context.lineTo( centerX + 2 * centerX * Math.cos((progress * Math.PI * 2)-Math.PI/2), centerY + 2 * centerY * Math.sin((progress * Math.PI * 2)-Math.PI/2)); context.stroke(); context.closePath(); context.clearRect(0, 0, centerX*2, centerY*2);
context.clearRect(0, 0, context.getCanvas().getWidth(), context.getCanvas().getHeight()); context.setGlobalAlpha(1.0); context.setLineWidth(1.0); context.setStrokeStyle("black"); context.beginPath(); context.moveTo(child.getIntAttribute("from_x"), child.getIntAttribute("from_y")); context.lineTo(child.getIntAttribute("to_x"), child.getIntAttribute("to_y")); context.closePath(); context.stroke();
void replay(Context2d ctx) { ctx.beginPath(); x = list.get(i++); y = list.get(i++); ctx.moveTo(x, y); break; x = list.get(i++); y = list.get(i++); ctx.lineTo(x, y); break; x = list.get(i++); y = list.get(i++); ctx.quadraticCurveTo(cpx, cpy, x, y); break; x = list.get(i++); y = list.get(i++); ctx.bezierCurveTo(c1x, c1y, c2x, c2y, x, y); break; ctx.closePath(); break;
private void drawGradient() { final Context2d ctx = canvas.getContext2d(); // draw gradient ctx.setFillStyle("#ffffff"); //$NON-NLS-1$ ctx.fillRect(0, 0, 26, 180); final Hsl hsl = new Hsl(0, 100, 50); for (int y = 0; y <= 179; y++) { hsl.setH(y * 2); ctx.setFillStyle(Colors.hsl2html(hsl)); ctx.fillRect(3, y, 20, 1); } // draw handle if (handleY >= 0) { ctx.setFillStyle("#000000"); //$NON-NLS-1$ ctx.beginPath(); ctx.moveTo(3, handleY); ctx.lineTo(0, handleY - 3); ctx.lineTo(0, handleY + 3); ctx.closePath(); ctx.fill(); ctx.moveTo(23, handleY); ctx.lineTo(26, handleY - 3); ctx.lineTo(26, handleY + 3); ctx.closePath(); ctx.fill(); } }
@Override public void paint(Canvas canvas, Matrix matrix) { canvas.getContext2d().save(); canvas.getContext2d().setFillStyle(fillStyle); canvas.getContext2d().fillRect(box.getX(), box.getY(), box.getWidth(), box.getHeight()); canvas.getContext2d().setStrokeStyle(strokeStyle); canvas.getContext2d().setLineWidth(strokeWidthPixels / matrix.getXx()); canvas.getContext2d().strokeRect(box.getX(), box.getY(), box.getWidth(), box.getHeight()); canvas.getContext2d().restore(); }
double yPosition = (-newY * zoom) + newY; backContext.clearRect(0, 0, width, height); backContext.translate(xPosition, yPosition); backContext.scale(zoom, zoom); backContext.setFillStyle("white"); backContext.fillRect(-5, -5, width + 5, height + 5); backContext.setFillStyle("black"); double xPos = event.getRelativeX(image.getElement()); double yPos = event.getRelativeY(image.getElement()); backContext.translate((xPos - mouseDownXPos) / totalZoom, (yPos - mouseDownYPos) / totalZoom); backContext.drawImage(imageElement, 100, 100); front.beginPath(); front.clearRect(0, 0, width, height); front.drawImage(back.getCanvas(), 0, 0);
private void drawGradient(final boolean drawHandle) { final Context2d ctx = canvas.getContext2d(); // draw gradient final Hsl hsl = new Hsl(hue, 0, 50); for (int x = 0; x <= 179; x++) { hsl.setS(Math.round(x * 100 / 179)); final CanvasGradient grad = ctx.createLinearGradient(x, 0, x, 179); grad.addColorStop(0, "#000000"); //$NON-NLS-1$ grad.addColorStop(0.5, Colors.hsl2html(hsl)); grad.addColorStop(1, "#ffffff"); //$NON-NLS-1$ ctx.setFillStyle(grad); ctx.fillRect(x, 0, 1, 180); } // draw handle if (drawHandle) { ctx.beginPath(); ctx.arc(handleX, handleY, 4, 0, Math.PI * 2, false); ctx.closePath(); ctx.setFillStyle("#ffffff"); //$NON-NLS-1$ ctx.fill(); ctx.beginPath(); ctx.arc(handleX, handleY, 3, 0, Math.PI * 2, false); ctx.closePath(); ctx.setFillStyle("#000000"); //$NON-NLS-1$ ctx.fill(); } }
@Override public void paint(Canvas canvas, Matrix matrix) { /* * paint image on canvas based on the original and with the transformations of the matrix. * */ Context2d context2d = canvas.getContext2d(); context2d.save(); boolean xReversal = matrix.getXx() < 0; boolean yReversal = matrix.getYy() < 0; context2d.scale(xReversal ? -1 : 1, yReversal ? -1 : 1); double xValue = xReversal ? box.getMaxX() * -1 : box.getX(); double yValue = yReversal ? box.getMaxY() * -1 : box.getY(); context2d.drawImage(hiddenImageCanvas.getCanvasElement(), xValue, yValue, box.getWidth(), box.getHeight()); context2d.restore(); }
private void clearCanvas(Canvas canvas) { canvas.getContext2d().save(); canvas.getContext2d().setTransform(1, 0, 0, 1, 0, 0); canvas.getContext2d().clearRect(0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight()); canvas.getContext2d().restore(); }
@UiHandler("slPicker") void onChangeColor(final ColorChangedEvent event) { if (canvasSupported) { final Context2d ctx = color.getContext2d(); ctx.setFillStyle(event.getColor()); ctx.fillRect(0, 0, color.getCoordinateSpaceWidth(), color.getCoordinateSpaceHeight()); } else { textColor.setValue(event.getColor()); } }