List of usage examples for com.google.gwt.canvas.dom.client Context2d setStrokeStyle
public final void setStrokeStyle(String strokeStyleColor)
From source file:org.oscim.gdx.client.GwtCanvas.java
License:Open Source License
@Override public void drawText(String string, float x, float y, Paint fill, Paint stroke) { if (bitmap == null) { //log.debug("no bitmap set"); return;//from w w w. ja va2 s .com } GwtPaint p = (GwtPaint) fill; if (p.stroke && GwtGdxGraphics.NO_STROKE_TEXT) return; Context2d ctx = bitmap.pixmap.getContext(); ctx.setFont(p.font); if (p.stroke) { ctx.setLineWidth(p.strokeWidth); ctx.setStrokeStyle(p.color); ctx.strokeText(string, (int) (x + 1), (int) (y + 1)); } else { ctx.setFillStyle(p.color); ctx.fillText(string, (int) (x + 1), (int) (y + 1)); } }
From source file:org.peergreen.vaadin.diagram.client.ui.IntermediateConnectorUI.java
License:Apache License
@Override public void draw() { // Draw a line from the source port to the current mouse coordinates Context2d canvas = getCanvas(); IPoint coordinates = getModel().getMouseCoordinates(); canvas.save();/* www. j a v a 2s .c o m*/ canvas.beginPath(); canvas.setStrokeStyle("#000"); canvas.moveTo(sourcePort.getConnectorX(), sourcePort.getConnectorY()); canvas.lineTo(coordinates.getX(), coordinates.getY()); canvas.closePath(); canvas.stroke(); canvas.restore(); }
From source file:org.primaresearch.web.gwt.client.ui.page.renderer.PolygonRendererHelper.java
License:Apache License
private static void setLineColor(Context2d context, RenderStyle style) { if (style != null) context.setStrokeStyle(style.getLineColor()); else/*ww w .j a va2s.c o m*/ context.setStrokeStyle(CssColor.make("rgb(128, 128, 128)")); }
From source file:org.primaresearch.web.gwt.client.ui.page.tool.drawing.EditOutlineTool.java
License:Apache License
@Override public void render(PageRenderer renderer) { if (!isEnabled()) return;//from www .j a va 2 s.co m Context2d context = renderer.getContext(); //Draw the selected outline in red RenderStyle style = new RenderStyle("rgb(255,0,0)", "transparent", 1.0); PolygonRendererHelper.drawPolygon(context, polygon, style, renderer.getZoomFactor(), true, false); //Delete mode if (deletePointsMode) { if (currentPolygonPoint != null) { context.setFillStyle(DELETE_POINT_FILL_COLOR); context.setStrokeStyle(DELETE_POINT_LINE_COLOR); context.setLineWidth(1.0 / renderer.getZoomFactor()); //Cross context.beginPath(); int size = (int) (3.0 / view.getZoomFactor()); context.moveTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y - 3 * size); context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y - size); context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y - 3 * size); context.lineTo(currentPolygonPoint.x + 3 * size, currentPolygonPoint.y - 2 * size); context.lineTo(currentPolygonPoint.x + size, currentPolygonPoint.y); context.lineTo(currentPolygonPoint.x + 3 * size, currentPolygonPoint.y + 2 * size); context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y + 3 * size); context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y + size); context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y + 3 * size); context.lineTo(currentPolygonPoint.x - 3 * size, currentPolygonPoint.y + 2 * size); context.lineTo(currentPolygonPoint.x - size, currentPolygonPoint.y); context.lineTo(currentPolygonPoint.x - 3 * size, currentPolygonPoint.y - 2 * size); context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y - 3 * size); context.fill(); context.stroke(); } } //Add or move mode else { //Move point if (currentPolygonPoint != null) { context.setFillStyle(POINT_HIGHLIGHT_FILL_COLOR); context.setStrokeStyle(POINT_HIGHLIGHT_LINE_COLOR); context.setLineWidth(1.0 / renderer.getZoomFactor()); int size = (int) (3.0 / view.getZoomFactor()); //Rect in centre context.beginPath(); context.rect(currentPolygonPoint.x - size, currentPolygonPoint.y - size, 2 * size + 1, 2 * size + 1); context.fill(); context.stroke(); //Arrows // Left context.beginPath(); context.moveTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y + size); context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y - size); context.lineTo(currentPolygonPoint.x - 3 * size, currentPolygonPoint.y); context.lineTo(currentPolygonPoint.x - 2 * size, currentPolygonPoint.y + size); context.fill(); context.stroke(); // Right context.beginPath(); context.moveTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y + size); context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y - size); context.lineTo(currentPolygonPoint.x + 3 * size, currentPolygonPoint.y); context.lineTo(currentPolygonPoint.x + 2 * size, currentPolygonPoint.y + size); context.fill(); context.stroke(); // Top context.beginPath(); context.moveTo(currentPolygonPoint.x + size, currentPolygonPoint.y - 2 * size); context.lineTo(currentPolygonPoint.x - size, currentPolygonPoint.y - 2 * size); context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y - 3 * size); context.lineTo(currentPolygonPoint.x + size, currentPolygonPoint.y - 2 * size); context.fill(); context.stroke(); // Bottom context.beginPath(); context.moveTo(currentPolygonPoint.x + size, currentPolygonPoint.y + 2 * size); context.lineTo(currentPolygonPoint.x - size, currentPolygonPoint.y + 2 * size); context.lineTo(currentPolygonPoint.x, currentPolygonPoint.y + 3 * size); context.lineTo(currentPolygonPoint.x + size, currentPolygonPoint.y + 2 * size); context.fill(); context.stroke(); } //Add point if (newPolygonPointCandidate != null) { context.setFillStyle(POINT_HIGHLIGHT_FILL_COLOR); context.setStrokeStyle(POINT_HIGHLIGHT_LINE_COLOR); context.setLineWidth(1.0 / renderer.getZoomFactor()); //Plus sign context.beginPath(); int size = (int) (3.0 / view.getZoomFactor()); context.moveTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y - 3 * size); context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y - 3 * size); context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y - size); context.lineTo(newPolygonPointCandidate.x + 3 * size, newPolygonPointCandidate.y - size); context.lineTo(newPolygonPointCandidate.x + 3 * size, newPolygonPointCandidate.y + size); context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y + size); context.lineTo(newPolygonPointCandidate.x + size, newPolygonPointCandidate.y + 3 * size); context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y + 3 * size); context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y + size); context.lineTo(newPolygonPointCandidate.x - 3 * size, newPolygonPointCandidate.y + size); context.lineTo(newPolygonPointCandidate.x - 3 * size, newPolygonPointCandidate.y - size); context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y - size); context.lineTo(newPolygonPointCandidate.x - size, newPolygonPointCandidate.y - 3 * size); context.fill(); context.stroke(); } } }
From source file:org.primaresearch.web.gwt.client.ui.page.tool.drawing.RectangleTool.java
License:Apache License
@Override public void render(PageRenderer renderer) { if (p1 == null || !isEnabled()) return;// ww w . j a v a2s.c o m Context2d context = renderer.getContext(); //Blue rectangle context.setStrokeStyle(CssColor.make(0, 128, 255)); context.setLineWidth(1.0 / renderer.getZoomFactor()); int x1 = Math.min(p1.x, p2.x); int x2 = Math.max(p1.x, p2.x); int y1 = Math.min(p1.y, p2.y); int y2 = Math.max(p1.y, p2.y); context.beginPath(); context.rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1); context.stroke(); }
From source file:org.rstudio.core.client.widget.ProgressSpinner.java
License:Open Source License
private void redraw() { Context2d ctx = canvas_.getContext2d(); double center = COORD_SIZE / 2; // clear canvas (we draw with an alpha channel so otherwise would stack) ctx.clearRect(0, 0, COORD_SIZE, COORD_SIZE); for (int i = 0; i < NUM_BLADES; i++) { // compute angle for this blade double theta = ((2 * Math.PI) / NUM_BLADES) * i; double sin = Math.sin(theta); double cos = Math.cos(theta); // set line drawing context ctx.beginPath();/*from ww w . j a va2s . c o m*/ ctx.setLineWidth(BLADE_WIDTH); ctx.setLineCap(LineCap.ROUND); // compute transparency for this blade double alpha = 1.0 - (((double) ((i + frame_) % NUM_BLADES)) / ((double) NUM_BLADES)); ctx.setStrokeStyle("rgba(" + color_ + ", " + alpha + ")"); // draw the blade ctx.moveTo(center + sin * innerRadius_, center + cos * innerRadius_); ctx.lineTo(center + sin * outerRadius_, center + cos * outerRadius_); ctx.stroke(); } }
From source file:org.rstudio.studio.client.workbench.views.vcs.dialog.graph.GraphLine.java
License:Open Source License
private void draw(Canvas canvas, GraphTheme theme) { int height = theme.getRowHeight(); int colWidth = theme.getColumnWidth(); double pad = theme.getVerticalLinePadding(); canvas.setCoordinateSpaceHeight(height); canvas.setCoordinateSpaceWidth(colWidth * getTotalWidth(theme)); Context2d ctx = canvas.getContext2d(); //ctx.clearRect(0, 0, colWidth * columns_.length, height); ctx.translate(colWidth / 2.0, 0);//from w w w . ja v a 2 s .c o m int startPos = -1; int endPos = -1; int nexusColumn = -1; for (int i = 0; i < columns_.length; i++) { GraphColumn c = columns_[i]; if (!c.start) startPos++; if (!c.end) endPos++; ctx.setStrokeStyle(theme.getColorForId(c.id)); ctx.setLineWidth(theme.getStrokeWidth()); ctx.setLineJoin(LineJoin.ROUND); if (!c.nexus && !c.start && !c.end) { // Just draw a line from start to end position ctx.beginPath(); ctx.moveTo(startPos * colWidth, 0); ctx.lineTo(startPos * colWidth, pad); // This next lineTo helps ensure that the shape of the line looks // congruous to any specials on the same line ctx.lineTo(Math.min(startPos, endPos) * colWidth, height / 2.0); ctx.lineTo(endPos * colWidth, height - pad); ctx.lineTo(endPos * colWidth, height); ctx.stroke(); } else { // something special if (c.nexus) { nexusColumn = i; ctx.setFillStyle(theme.getColorForId(c.id)); } if (!c.start) { // draw from i to nexusColumn; ctx.beginPath(); ctx.moveTo(startPos * colWidth, 0); ctx.lineTo(startPos * colWidth, pad); ctx.lineTo(nexusColumn * colWidth, height / 2.0); ctx.stroke(); } if (!c.end) { // draw from nexusColumn to endPosition ctx.beginPath(); ctx.moveTo(nexusColumn * colWidth, height / 2.0); ctx.lineTo(endPos * colWidth, height - pad); ctx.lineTo(endPos * colWidth, height); ctx.stroke(); } } } // draw a circle on the nexus ctx.beginPath(); ctx.arc(nexusColumn * colWidth, height / 2.0, theme.getCircleRadius() + theme.getStrokeWidth(), 0, Math.PI * 2); ctx.closePath(); ctx.fill(); ctx.beginPath(); ctx.arc(nexusColumn * colWidth, height / 2.0, theme.getCircleRadius(), 0, Math.PI * 2); ctx.closePath(); ctx.setFillStyle("white"); ctx.fill(); }
From source file:org.teavm.samples.benchmark.gwt.BenchmarkStarter.java
License:Apache License
private void render() { Context2d context = canvas.getContext2d(); context.setFillStyle("white"); context.setStrokeStyle("grey"); context.fillRect(0, 0, 600, 600);//from w w w. j av a 2s .c o m context.save(); context.translate(0, 600); context.scale(1, -1); context.scale(100, 100); context.setLineWidth(0.01); for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) { Vec2 center = body.getPosition(); context.save(); context.translate(center.x, center.y); context.rotate(body.getAngle()); for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) { Shape shape = fixture.getShape(); if (shape.getType() == ShapeType.CIRCLE) { CircleShape circle = (CircleShape) shape; context.beginPath(); context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true); context.closePath(); context.stroke(); } else if (shape.getType() == ShapeType.POLYGON) { PolygonShape poly = (PolygonShape) shape; Vec2[] vertices = poly.getVertices(); context.beginPath(); context.moveTo(vertices[0].x, vertices[0].y); for (int i = 1; i < poly.getVertexCount(); ++i) { context.lineTo(vertices[i].x, vertices[i].y); } context.closePath(); context.stroke(); } } context.restore(); } context.restore(); }
From source file:stroom.widget.htree.client.BracketConnectorRenderer.java
License:Apache License
private void drawTop(final Context2d ctx, final double midX, final double minX, final double maxX, final double y1, final double y2) { final double maxY = y1 - RADIUS; final double minY = y2 + RADIUS; // Draw top of bracket ctx.beginPath();//www .j a va 2 s.com ctx.moveTo(midX, maxY); ctx.arc(minX, maxY, RADIUS, 0, HALF_PI); ctx.moveTo(midX, maxY); ctx.lineTo(midX, minY); ctx.moveTo(midX, minY); ctx.arc(maxX, minY, RADIUS, Math.PI, ONE_AND_HALF_PI); ctx.setStrokeStyle(lineColor); ctx.stroke(); }
From source file:stroom.widget.htree.client.BracketConnectorRenderer.java
License:Apache License
private void drawBottom(final Context2d ctx, final double midX, final double minX, final double maxX, final double y1, final double y2) { final double minY = y1 + RADIUS; final double maxY = y2 - RADIUS; // Draw bottom of bracket ctx.beginPath();//w ww . j a va 2 s . c o m ctx.moveTo(minX, y1); ctx.arc(minX, minY, RADIUS, ONE_AND_HALF_PI, 0); ctx.moveTo(midX, minY); ctx.lineTo(midX, maxY); ctx.moveTo(maxX, y2); ctx.arc(maxX, maxY, RADIUS, HALF_PI, Math.PI); ctx.setStrokeStyle(lineColor); ctx.stroke(); }