Example usage for com.google.gwt.canvas.dom.client Context2d getLineWidth

List of usage examples for com.google.gwt.canvas.dom.client Context2d getLineWidth

Introduction

In this page you can find the example usage for com.google.gwt.canvas.dom.client Context2d getLineWidth.

Prototype

public final native double getLineWidth() ;

Source Link

Document

Gets the current line-width.

Usage

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) {
        {//from   ww  w  . j  a  v  a2s . c o  m
            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) {
        {/*w  w w .  jav  a2 s  . 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);
        }
    } };
}