use of com.google.gwt.canvas.dom.client.Context2d in project gwt-cs by iSergio.
the class ParticleSystemFireworks method getImage.
private CanvasElement getImage() {
if (!Cesium.defined(particleCanvas)) {
particleCanvas = RootPanel.get().getElement().getOwnerDocument().createCanvasElement();
particleCanvas.setWidth(20);
particleCanvas.setHeight(20);
Context2d context2d = particleCanvas.getContext2d();
context2d.beginPath();
context2d.arc(8, 8, 8, 0, Math.TWO_PI(), true);
context2d.closePath();
context2d.setFillStyle("rgb(255, 255, 255)");
context2d.fill();
Cesium.log(particleCanvas);
}
return particleCanvas;
}
use of com.google.gwt.canvas.dom.client.Context2d in project rstudio by rstudio.
the class FontDetector method isFontSupported.
public static boolean isFontSupported(String fontName) {
SimplePanel panel = null;
try {
// default font name as a reference point
final String defaultFontName = "Arial";
if (defaultFontName.equals(fontName))
return true;
// make sure canvas is supported
if (!Canvas.isSupported())
return false;
// add a temporary div to the dom
panel = new SimplePanel();
panel.setHeight("200px");
panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
panel.getElement().getStyle().setOverflow(Overflow.SCROLL);
RootPanel.get().add(panel, -2000, -2000);
// add a canvas element to the div and get the 2d drawing context
final Canvas canvas = Canvas.createIfSupported();
canvas.setWidth("512px");
canvas.setHeight("64px");
canvas.getElement().getStyle().setLeft(400, Unit.PX);
canvas.getElement().getStyle().setBackgroundColor("#ffe");
panel.add(canvas);
final Context2d ctx = canvas.getContext2d();
ctx.setFillStyle("#000000");
// closure to generate a hash for a font
class HashGenerator {
public String getHash(String fontName) {
ctx.setFont("57px " + fontName + ", " + defaultFontName);
int width = canvas.getOffsetWidth();
int height = canvas.getOffsetHeight();
ctx.clearRect(0, 0, width, height);
ctx.fillText("TheQuickBrownFox", 2, 50);
return canvas.toDataUrl();
}
}
;
// get hashes and compare them
HashGenerator hashGenerator = new HashGenerator();
String defaultHash = hashGenerator.getHash(defaultFontName);
String fontHash = hashGenerator.getHash(fontName);
return !defaultHash.equals(fontHash);
} catch (Exception ex) {
Debug.log(ex.toString());
return false;
} finally {
if (panel != null)
RootPanel.get().remove(panel);
}
}
use of com.google.gwt.canvas.dom.client.Context2d in project rstudio by rstudio.
the class ProgressSpinner method redraw.
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();
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();
}
}
use of com.google.gwt.canvas.dom.client.Context2d in project playn by threerings.
the class HtmlImage method getRgb.
@Override
public void getRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) {
assert isReady() : "Cannot getRgb() a non-ready image";
if (canvas == null) {
canvas = img.getOwnerDocument().createCanvasElement();
canvas.setHeight(img.getHeight());
canvas.setWidth(img.getWidth());
canvas.getContext2d().drawImage(img, 0, 0);
// img.getOwnerDocument().getBody().appendChild(canvas);
}
Context2d ctx = canvas.getContext2d();
ImageData imageData = ctx.getImageData(startX, startY, width, height);
CanvasPixelArray pixelData = imageData.getData();
int i = 0;
int dst = offset;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int r = pixelData.get(i++);
int g = pixelData.get(i++);
int b = pixelData.get(i++);
int a = pixelData.get(i++);
rgbArray[dst + x] = a << 24 | r << 16 | g << 8 | b;
}
dst += scanSize;
}
}
use of com.google.gwt.canvas.dom.client.Context2d in project gwt-cs by iSergio.
the class MarkerGroup method createBillboard.
public static BillboardOptions createBillboard(DrawInteractionOptions options) {
Canvas canvas = Canvas.createIfSupported();
Context2d context = canvas.getContext2d();
context.setFillStyle(options.color.toCssColorString());
context.setStrokeStyle(options.outlineColor.toCssColorString());
context.setLineWidth(options.outlineWidth);
context.translate(canvas.getCoordinateSpaceWidth() / 2, canvas.getCoordinateSpaceHeight() / 2);
context.beginPath();
context.arc(0, 0, options.pixelSize, 0, Math.PI * 2, true);
context.closePath();
context.stroke();
context.fill();
BillboardOptions billboard = new BillboardOptions();
billboard.horizontalOrigin = HorizontalOrigin.CENTER();
billboard.verticalOrigin = VerticalOrigin.CENTER();
billboard.imageCanvas = canvas.getCanvasElement();
return billboard;
}
Aggregations