List of usage examples for com.google.gwt.canvas.dom.client Context2d stroke
public final native void stroke() ;
From source file:examples.geometry.containment.AbstractPolygonContainmentExample.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape1(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override//from w ww .j ava 2 s . c o m public void createControlPoints() { // no control points => user cannot change it } @Override public Polygon createGeometry() { double w = canvas.getCoordinateSpaceWidth(), wg = w / 6, h = canvas.getCoordinateSpaceHeight(), hg = h / 6; return new Polygon(new Point[] { new Point(wg, hg), new Point(w - wg, h - hg), new Point(wg, h - hg), new Point(w - wg, hg) }); } @Override public void drawShape() { Context2d context2d = canvas.getContext2d(); Polygon polygon = createGeometry(); context2d.setStrokeStyle("black"); for (Line segment : polygon.getOutlineSegments()) { context2d.beginPath(); context2d.moveTo(segment.getX1(), segment.getY1()); context2d.lineTo(segment.getX2(), segment.getY2()); context2d.stroke(); } } }; }
From source file:examples.geometry.containment.PolygonLineContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override/*from w ww.j a v a 2 s .c o m*/ public void createControlPoints() { addControlPoint(new Point(100, 100)); addControlPoint(new Point(300, 300)); } @Override public Line createGeometry() { Point[] points = getControlPoints(); return new Line(points[0], points[1]); } @Override public void drawShape() { Line line = createGeometry(); Context2d c = canvas.getContext2d(); c.beginPath(); c.moveTo(line.getX1(), line.getY1()); c.lineTo(line.getX2(), line.getY2()); c.closePath(); c.stroke(); } @Override public void fillShape(CssColor color) { Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getFillStyle(); context2d.setLineWidth(3); context2d.setStrokeStyle(color.value()); drawShape(); context2d.setLineWidth(1); // context2d.setStrokeStyle(CssColor.make(0, 0, 0).value()); context2d.setStrokeStyle(style); } }; }
From source file:examples.geometry.containment.PolygonRectangleContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { private final double WIDTH = 50; private final double HEIGHT = 75; @Override/*from w w w .j av a2 s .com*/ public void createControlPoints() { addControlPoint(new Point(110, 70)); } @Override public Rectangle createGeometry() { Point[] points = getControlPoints(); return new Rectangle(points[0].x - WIDTH / 2, points[0].y - HEIGHT / 2, WIDTH, HEIGHT); } @Override public void drawShape() { Rectangle rect = createGeometry(); Context2d context2d = canvas.getContext2d(); context2d.rect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); context2d.stroke(); } @Override public void fillShape(CssColor color) { Rectangle rect = createGeometry(); Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getFillStyle(); context2d.setFillStyle(color.value()); context2d.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); context2d.setFillStyle(style); } }; }
From source file:examples.geometry.demos.BezierApproximationExample.java
License:Open Source License
@Override protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) { ControllableShape shape = new ControllableShape(canvas, eventBus) { @Override//from ww w .ja v a2 s . c o m public BezierCurve getShape() { return new BezierCurve(getPoints()); } @Override public void onDraw(Canvas canvas) { Context2d context = canvas.getContext2d(); // Construct the Bezier curve. BezierCurve curve = getShape(); CanvasDrawer.strokePath(curve.toPath(), context); // Display the connection line of its control points. context.beginPath(); for (Point p : curve.getPoints()) { context.lineTo(p.x, p.y); context.stroke(); } } }; shape.addControlPoints(new Point(100, 200), new Point(150, 250), new Point(200, 150), new Point(250, 250), new Point(300, 150), new Point(350, 250), new Point(400, 200)); return new ControllableShape[] { shape }; }
From source file:examples.geometry.demos.ConvexHullExample.java
License:Open Source License
protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) { ControllableShape shape = new ControllableShape(canvas, eventBus) { {/*from w ww . ja v a 2s .c o m*/ // These are the points which are displayed on the screen. // We will compute their convex hull later. addControlPoints(new Point(100, 100), new Point(150, 400), new Point(200, 300), new Point(250, 150), new Point(300, 250), new Point(350, 200), new Point(400, 350)); } @Override public Polygon getShape() { // Compute the convex hull of the defined point list. // We return the convex hull as a Polygon. return new Polygon(Point.getConvexHull(getPoints())); } @Override public void onDraw(Canvas canvas) { Context2d context = canvas.getContext2d(); // This is the code to display the computed convex hull. // Compute the convex hull. Polygon convexHull = getShape(); for (Line s : convexHull.getOutlineSegments()) { Point p1 = s.getP1(); Point p2 = s.getP2(); context.moveTo(p1.x, p1.y); context.lineTo(p2.x, p2.y); context.stroke(); } // Display the convex hull as an SWT Path. // gc.drawPath(new org.eclipse.swt.graphics.Path(Display // .getCurrent(), Geometry2SWT.toSWTPathData(convexHull // .toPath()))); } }; return new ControllableShape[] { shape }; }
From source file:examples.geometry.demos.CubicCurveDeCasteljauExample.java
License:Open Source License
@Override protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) { return new ControllableShape[] { new ControllableShape(canvas, eventBus) { {//from www .j a va2 s.c o m /* * These are the control points used to construct the CubicCurve * later. */ addControlPoints(new Point(100, 200), new Point(200, 100), new Point(300, 300), new Point(400, 200)); } @Override public CubicCurve getShape() { /* * Constructs the CubicCurve of the defined control points. */ return new CubicCurve(getPoints()); } @Override public void onDraw(Canvas canvas) { Context2d context = canvas.getContext2d(); /* * Draws the CubicCurve and the de Casteljau construction for * the current parameter value. */ // Construct the CubicCurve from the defined control points. CubicCurve curve = getShape(); CanvasDrawer.strokePath(curve.toPath(), context); /* * Retrieve control points to compute the linear interpolations * of the de Casteljau algorithm. */ Point[] points = getPoints(); /* * Define the colors for the intermediate lines. We have three * stages and therefore three different colors for a cubic * Bezier curve. This is the case, because the de Casteljau * algorithm reduces the number of control points in each * iteration until it reaches the actual point on the curve. */ String[] colors = new String[] { "green", "blue", "red" }; for (int ci = 0; ci < colors.length; ci++) { for (int i = 0; i < 3 - ci; i++) { context.beginPath(); context.moveTo(points[i].x, points[i].y); context.lineTo(points[i + 1].x, points[i + 1].y); context.setStrokeStyle(colors[ci]); context.stroke(); context.closePath(); // interpolate point for the next iteration points[i] = new Line(points[i], points[i + 1]).get(parameterValue); // draw point context.beginPath(); context.arc(points[i].x, points[i].y, 2, 0, 180); context.setStrokeStyle("black"); context.stroke(); context.closePath(); } } } } }; }
From source file:examples.geometry.demos.RegionOutlineExample.java
License:Open Source License
@Override protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) { return new ControllableShape[] { new ControllableShape(canvas, eventBus) { {//from ww w . j av a2s .c o m addControlPoints(new Point(100, 50), new Point(300, 100)); addControlPoints(new Point(250, 200), new Point(350, 330)); addControlPoints(new Point(100, 200), new Point(190, 325)); addControlPoints(new Point(150, 300), new Point(280, 380)); } @Override public Region getShape() { Point[] cp = getPoints(); Rectangle[] rectangles = new Rectangle[cp.length / 2]; for (int i = 0; i < rectangles.length; i++) { rectangles[i] = new Rectangle(cp[2 * i], cp[2 * i + 1]); } return new Region(rectangles); } @Override public void onDraw(Canvas canvas) { Context2d context = canvas.getContext2d(); Region region = getShape(); context.setFillStyle("rgba(0, 0, 255, 0.5)"); context.setGlobalAlpha(0.5); context.beginPath(); for (Rectangle r : region.getShapes()) { context.fillRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); } context.closePath(); // gc.setAlpha(255); context.setFillStyle("rgba(255, 255, 255, 1)"); context.setGlobalAlpha(1); // gc.setForeground(Display.getCurrent().getSystemColor( // SWT.COLOR_RED)); // for (Rectangle r : region.getShapes()) { // gc.drawRectangle(r.toSWTRectangle()); // } // gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); context.beginPath(); for (Line l : region.getOutlineSegments()) { Point p1 = l.getP1(); Point p2 = l.getP2(); context.moveTo(p1.x, p1.y); context.lineTo(p2.x, p2.y); context.stroke(); } context.closePath(); } } }; }
From source file:examples.geometry.demos.RingOutlineExample.java
License:Open Source License
@Override protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) { return new ControllableShape[] { new ControllableShape(canvas, eventBus) { {/* ww w . j a va 2 s . c om*/ addControlPoints(new Point(100, 100), new Point(400, 100), new Point(400, 200)); addControlPoints(new Point(400, 100), new Point(400, 400), new Point(300, 400)); addControlPoints(new Point(400, 400), new Point(100, 400), new Point(100, 300)); addControlPoints(new Point(100, 400), new Point(100, 100), new Point(200, 100)); } @Override public Ring getShape() { Point[] cp = getPoints(); Polygon[] polygons = new Polygon[cp.length / 3]; for (int i = 0; i < polygons.length; i++) { polygons[i] = new Polygon(cp[3 * i], cp[3 * i + 1], cp[3 * i + 2]); } return new Ring(polygons); } @Override public void onDraw(Canvas canvas) { Context2d context = canvas.getContext2d(); Ring ring = getShape(); context.setStrokeStyle("black"); double lineWidth = context.getLineWidth(); context.setLineWidth(1); for (Polyline outline : ring.getOutlines()) { context.beginPath(); for (Line l : outline.getCurves()) { Point p1 = l.getP1(); Point p2 = l.getP2(); context.moveTo(p1.x, p1.y); context.lineTo(p2.x, p2.y); context.setLineWidth(lineWidth + 1); context.stroke(); } context.closePath(); } context.setLineWidth(lineWidth); } } }; }
From source file:examples.geometry.demos.TriangulationExample.java
License:Open Source License
@Override protected ControllableShape[] createShapes(Canvas canvas, EventBus eventBus) { return new ControllableShape[] { new ControllableShape(canvas, eventBus) { {/*from w ww . ja v a 2s . c o m*/ addControlPoints(new Point(300 / 2, 100 / 2), new Point(100 / 2, 200 / 2), new Point(200 / 2, 300 / 2), new Point(100 / 2, 500 / 2), new Point(300 / 2, 400 / 2), new Point(500 / 2, 600 / 2), new Point(600 / 2, 300 / 2), new Point(500 / 2, 400 / 2), new Point(500 / 2, 200 / 2), new Point(300 / 2, 200 / 2)); } @Override public Polygon getShape() { Polygon p = new Polygon(getPoints()); return p; } @Override public void onDraw(Canvas canvas) { Context2d context = canvas.getContext2d(); Polygon p = getShape(); Polygon[] triangulation; try { triangulation = p.getTriangulation(); } catch (NonSimplePolygonException x) { triangulation = new Polygon[] { p }; } for (Polygon triangle : triangulation) { context.beginPath(); context.setStrokeStyle("red"); for (Line s : triangle.getOutlineSegments()) { Point p1 = s.getP1(); Point p2 = s.getP2(); context.moveTo(p1.x, p1.y); context.lineTo(p2.x, p2.y); context.stroke(); } context.closePath(); } double lineWidth = context.getLineWidth(); context.setLineWidth(lineWidth + 2); context.setStrokeStyle("black"); context.beginPath(); for (Line s : p.getOutlineSegments()) { Point p1 = s.getP1(); Point p2 = s.getP2(); context.moveTo(p1.x, p1.y); context.lineTo(p2.x, p2.y); context.stroke(); } context.closePath(); context.setLineWidth(lineWidth); } } }; }
From source file:net.exclaimindustries.paste.braket.client.ui.BracketCell.java
License:BSD License
private void drawLeftBracket() { Context2d con = initBracketCanvas(mCanvas); con.beginPath();/*www .j a v a 2 s.co m*/ int width = mCanvas.getOffsetWidth(); int height = mCanvas.getOffsetHeight(); if (!mTerminus) { con.moveTo(0, height / 4.0); con.lineTo(width / 2.0, height / 4.0); con.lineTo(width / 2.0, (3.0 * height) / 4.0); con.lineTo(0, (3.0 * height) / 4); con.stroke(); } con.moveTo(width / 2.0, height / 2.0); con.lineTo(width, height / 2.0); con.stroke(); }