List of usage examples for com.google.gwt.canvas.dom.client Context2d lineTo
public final native void lineTo(double x, double y) ;
From source file:net.exclaimindustries.paste.braket.client.ui.BracketCell.java
License:BSD License
private void drawRightBracket() { Context2d con = initBracketCanvas(mCanvas); con.beginPath();/*from ww w . j a v a 2s . com*/ int width = mCanvas.getOffsetWidth(); int height = mCanvas.getOffsetHeight(); if (!mTerminus) { con.moveTo(width, height / 4.0); con.lineTo(width / 2.0, height / 4.0); con.lineTo(width / 2.0, (3.0 * height) / 4.0); con.lineTo(width, (3.0 * height) / 4.0); con.stroke(); } con.moveTo(width / 2.0, height / 2.0); con.lineTo(0, height / 2.0); con.stroke(); }
From source file:net.exclaimindustries.paste.braket.client.ui.BracketCell.java
License:BSD License
private void drawFinalBracket() { Context2d con = initBracketCanvas(mCanvas); con.beginPath();//from w w w. j a v a2 s . c o m int width = mCanvas.getOffsetWidth(); int height = mCanvas.getOffsetHeight(); con.moveTo(0, height / 2.0); con.lineTo(width, height / 2.0); con.stroke(); }
From source file:org.catrobat.html5player.client.Scene.java
License:Open Source License
/** * FOR TESING//from w w w . ja v a 2 s . c o m */ public void drawAxis() { Context2d ctx = sceneCanvas.getContext2d(); ctx.beginPath(); ctx.moveTo(getSceneWidth() / 2, 0); ctx.lineTo(getSceneWidth() / 2, getSceneHeight()); ctx.stroke(); ctx.closePath(); ctx.beginPath(); ctx.moveTo(0, getSceneHeight() / 2); ctx.lineTo(getSceneWidth(), getSceneHeight() / 2); ctx.stroke(); ctx.closePath(); }
From source file:org.cruxframework.crux.widgets.client.colorpicker.HuePicker.java
License:Apache License
private void drawGradient() { Context2d ctx = canvas.getContext2d(); // draw gradient ctx.setFillStyle("#ffffff"); ctx.fillRect(0, 0, 26, 180);//ww w.j a v a 2 s . c o m for (int y = 0; y <= 179; y++) { String hex = ColorUtils.hsl2hex(y * 2, 100, 100); ctx.setFillStyle("#" + hex); ctx.fillRect(3, y, 20, 1); } // draw handle if (handleY >= 0) { ctx.setFillStyle("#000000"); 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(); } }
From source file:org.openstreetmap.beboj.client.actions.mapmode.edit.DrawWay.java
License:GNU General Public License
@Override public void paint(Graphics2D g, MapView mv, Bounds bbox) { Context2d c = ((CanvasGraphics2D) g).getContext2d(); // don't draw line if we don't know where to if (lastMousePos == null) return;// w ww. j a v a 2 s . c o m // don't draw line if mouse is outside window if (!Main.map.mapView.view.getBounds().contains(lastMousePos)) return; Point p1 = mv.getPoint(lastNode); Point p2 = lastMousePos; c.setStrokeStyle("#ffff00"); c.beginPath(); c.moveTo(p1.x, p1.y); c.lineTo(p2.x, p2.y); c.stroke(); }
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();//from w w w. ja v a 2s. co 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 drawPolygon(Context2d context, Polygon polygon, boolean outline, boolean fill) { if (polygon == null || polygon.getSize() < 3 || (!outline && !fill)) return;/*from w ww . j a va2 s . c om*/ context.beginPath(); context.moveTo(polygon.getPoint(0).x, polygon.getPoint(0).y); for (int i = 1; i < polygon.getSize(); i++) context.lineTo(polygon.getPoint(i).x, polygon.getPoint(i).y); context.lineTo(polygon.getPoint(0).x, polygon.getPoint(0).y); if (fill) context.fill(); if (outline) context.stroke(); }
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 ww w . ja va 2 s . c om 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.primordion.xholon.io.GridPanel.java
License:Open Source License
/** * Draw a polygon./*from w ww . j a v a 2 s . com*/ */ protected void drawPolygon(Context2d ctx, int x, int y, int xCoor[], int yCoor[], int sides) { ctx.save(); ctx.translate(x, y); ctx.beginPath(); ctx.moveTo(xCoor[0], yCoor[0]); for (int i = 1; i < sides; i++) { ctx.lineTo(xCoor[i], yCoor[i]); } ctx.lineTo(xCoor[0], yCoor[0]); ctx.fill(); ctx.closePath(); ctx.restore(); }
From source file:org.primordion.xholon.io.GridPanel.java
License:Open Source License
/** * Draw a regular polygon.//w w w . ja v a 2 s . co m * Example: <code> context.beginPath(); polygon(context,350,125,100,6,-Math.PI/2); context.fillStyle="rgba(51,128,255,0.75)"; context.fill(); context.stroke(); </code> * @param ctx A GWT Context2d object. * @param x X coordinate of the grid cell. * @param y Y coordinate of the grid cell. * @param radius * @param sides The number of sides in the polygon. This value must be >= 3. * @param startAngle Angle in radians. * @param anticlockwise Draw clockwise (false) or anticlockwise (true). * @see http://www.storminthecastle.com/2013/07/24/how-you-can-draw-regular-polygons-with-the-html5-canvas-api/ */ protected void drawPolygon(Context2d ctx, int x, int y, double radius, int sides, double startAngle, boolean anticlockwise) { if (sides < 3) return; double a = (Math.PI * 2) / sides; a = anticlockwise ? -a : a; ctx.save(); ctx.translate(x, y); ctx.rotate(startAngle); ctx.moveTo(radius, 0); for (int i = 1; i < sides; i++) { //double xcoor = radius * Math.cos(a * i); //double ycoor = radius * Math.sin(a * i); //System.out.println("i:" + i + " xcoor:" + xcoor + " ycoor:" + ycoor); //ctx.lineTo(xcoor, ycoor); ctx.lineTo(radius * Math.cos(a * i), radius * Math.sin(a * i)); } ctx.closePath(); ctx.restore(); }