List of usage examples for com.google.gwt.canvas.dom.client Context2d getFillStyle
public final FillStrokeStyle getFillStyle()
From source file:examples.geometry.AbstractExample.java
License:Open Source License
@Override public void draw() { Context2d context = canvas.getContext2d(); // reset/*from w ww . ja v a 2 s .co m*/ context.clearRect(0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight()); context.setFillStyle("black"); context.setStrokeStyle("black"); context.setLineWidth(1); for (ControllableShape shape : getControllableShapes()) { // e.gc.setForeground(canvas.getDisplay().getSystemColor(shape.shapeColor)); // e.gc.setBackground(canvas.getDisplay().getSystemColor(shape.shapeColor)); shape.onDraw(canvas); } for (ControllableShape shape : getControllableShapes()) { if (shape.isActive()) { FillStrokeStyle fillStyle = context.getFillStyle(); for (ControlPoint cp : shape.controlPoints) { context.beginPath(); context.arc(cp.getX(), cp.getY(), shape.controlRadius, 0, 180); context.setFillStyle(shape.controlColor); context.fill(); context.closePath(); } context.setFillStyle(fillStyle); } } }
From source file:examples.geometry.containment.PolygonCubicCurveContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override/* w ww . jav a 2 s . co m*/ public void createControlPoints() { addControlPoint(new Point(200, 100)); addControlPoint(new Point(190, 310)); addControlPoint(new Point(410, 90)); addControlPoint(new Point(400, 300)); } @Override public CubicCurve createGeometry() { return new CubicCurve(getControlPoints()); } @Override public void drawShape() { CubicCurve c = createGeometry(); Path path = c.toPath(); CanvasDrawer.strokePath(path, canvas.getContext2d()); // gc.drawPath(new org.eclipse.swt.graphics.Path(Display // .getCurrent(), Geometry2SWT.toSWTPathData(c.toPath()))); } @Override public void fillShape(CssColor color) { // int lineWidth = gc.getLineWidth(); // Color fg = gc.getForeground(); Context2d context2d = canvas.getContext2d(); FillStrokeStyle fillStyle = context2d.getFillStyle(); context2d.setLineWidth(3); context2d.setStrokeStyle(color.value()); // gc.setLineWidth(3); // gc.setForeground(gc.getBackground()); drawShape(); context2d.setLineWidth(1); context2d.setStrokeStyle(fillStyle); // gc.setForeground(fg); // gc.setLineWidth(lineWidth); } }; }
From source file:examples.geometry.containment.PolygonEllipseContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override//from w ww. j av a2 s . c o m public void createControlPoints() { ControlPoint center = addControlPoint(new Point(300, 300)); ControlPoint a = addControlPoint(new Point(400, 300)); ControlPoint b = addControlPoint(new Point(300, 200)); a.setYLink(center); b.setXLink(center); } @Override public Ellipse createGeometry() { double a = Math.abs(points.get(0).getPoint().x - points.get(1).getPoint().x); double b = Math.abs(points.get(0).getPoint().y - points.get(2).getPoint().y); return new Ellipse(points.get(0).getPoint().x - a, points.get(0).getPoint().y - b, 2 * a, 2 * b); } @Override public void drawShape() { Ellipse ellipse = createGeometry(); CanvasDrawer.drawOval(ellipse, canvas.getContext2d()); } @Override public void fillShape(CssColor color) { Ellipse ellipse = createGeometry(); Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getFillStyle(); CanvasDrawer.drawOval(ellipse, context2d); context2d.setFillStyle(color.value()); context2d.fill(); context2d.setFillStyle(style); } }; }
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 w w .j a va2s . c om*/ 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.PolygonPolygonContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override/*from www.j a v a2s. co m*/ public void createControlPoints() { addControlPoint(new Point(200, 200)); } @Override public Polygon createGeometry() { Point[] points = getControlPoints(); Polygon polygon = new Polygon(points[0].x - 30, points[0].y - 30, points[0].x + 80, points[0].y - 20, points[0].x - 20, points[0].y + 40); return polygon; } @Override public void drawShape() { Polygon polygon = createGeometry(); Context2d c = canvas.getContext2d(); CanvasDrawer.strokePath(polygon.toPath(), c); } @Override public void fillShape(CssColor color) { Polygon polygon = createGeometry(); Context2d c = canvas.getContext2d(); FillStrokeStyle style = c.getFillStyle(); c.setFillStyle(color.value()); CanvasDrawer.fillPath(polygon.toPath(), c); c.setFillStyle(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// w ww .j a va2 s . co m 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); } }; }