本文整理匯總了Java中com.google.gwt.canvas.dom.client.Context2d.translate方法的典型用法代碼示例。如果您正苦於以下問題:Java Context2d.translate方法的具體用法?Java Context2d.translate怎麽用?Java Context2d.translate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.gwt.canvas.dom.client.Context2d
的用法示例。
在下文中一共展示了Context2d.translate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: render
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void render(Context2d g, double timestamp) {
if (!isVisible()) {
return;
}
resizeContent();
content.x = scrollOffset.x = Math.min(0, Math.max(width - content.width, scrollOffset.x));
content.y = scrollOffset.y = Math.min(0, Math.max(height - content.height, scrollOffset.y));
g.save();
g.beginPath();
g.translate(x, y);
g.rect(0, 0, width, height);
g.clip();
g.translate(scrollOffset.x, scrollOffset.y);
for (UiElement c : children) {
c.render(g, timestamp);
}
g.restore();
redrawNeeded = false;
}
示例2: createBillboard
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
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;
}
示例3: drawCone
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
/**
* Draw a cone. Does not call beginPath().
*/
public static void drawCone(Context2d g, double x, double y, double radius, double height) {
double kappa = .5522848;
double w = (2 * radius) * SQRT1_5;
double h = (2 * radius) * SQRT0_5;
double xm = w / 2f; // x-middle
double ym = h / 2f; // y-middle
double ox = xm * kappa; // control point offset horizontal
double oy = ym * kappa; // control point offset vertical
g.translate(x, y);
g.moveTo(w, ym);
g.bezierCurveTo(w, ym + oy, xm + ox, h, xm, h);
g.bezierCurveTo(xm - ox, h, 0, ym + oy, 0, ym);
g.lineTo(xm, ym - height);
g.closePath();
g.translate(-x, -y);
}
示例4: drawEllipse
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
/**
* Draw an ellipse. Does not call beginPath().
*/
public static void drawEllipse(Context2d g, double x, double y, double w, double h) {
double kappa = .5522848;
double xm = w / 2f; // x-middle
double ym = h / 2f; // y-middle
double ox = xm * kappa; // control point offset horizontal
double oy = ym * kappa; // control point offset vertical
g.translate(x, y);
g.moveTo(0, ym);
g.bezierCurveTo(0, ym - oy, xm - ox, 0, xm, 0);
g.bezierCurveTo(xm + ox, 0, w, ym - oy, w, ym);
g.bezierCurveTo(w, ym + oy, xm + ox, h, xm, h);
g.bezierCurveTo(xm - ox, h, 0, ym + oy, 0, ym);
g.translate(-x, -y);
}
示例5: drawRoundedRect
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
/**
* Draw a rounded rect. Does not call beginPath().
*/
public static void drawRoundedRect(Context2d g, double x, double y, double width, double height,
double topLeftRadiusX, double topLeftRadiusY, double topRightRadiusX, double topRightRadiusY,
double bottomLeftRadiusX, double bottomLeftRadiusY, double bottomRightRadiusX,
double bottomRightRadiusY) {
g.translate(x, y);
g.moveTo(topLeftRadiusX, 0);
g.lineTo(width - topRightRadiusX, 0);
x = width;
y = 0;
g.bezierCurveTo(x, y, x, y, width, topRightRadiusY);
g.lineTo(width, height - bottomRightRadiusY);
x = width;
y = height;
g.bezierCurveTo(x, y, x, y, width - bottomRightRadiusX, height);
g.lineTo(bottomLeftRadiusX, height);
x = 0;
y = height;
g.bezierCurveTo(x, y, x, y, 0, height - bottomLeftRadiusY);
g.lineTo(0, topLeftRadiusY);
x = 0;
y = 0;
g.bezierCurveTo(x, y, x, y, topLeftRadiusX, 0);
g.translate(-x, -y);
}
示例6: redrawIfNecessary
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void redrawIfNecessary(Context2d g, double timestamp) {
if (!isVisible()) {
return;
}
if (redrawNeeded) {
clearRect(g);
render(g, timestamp);
} else {
g.save();
g.beginPath();
g.rect(x, y, width, height);
g.clip();
g.translate(x + scrollOffset.x, y + scrollOffset.y);
for (UiElement c : children) {
c.redrawIfNecessary(g, timestamp);
}
g.restore();
}
}
示例7: render
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void render(Context2d g, double timestamp) {
if (!isVisible()) {
return;
}
redrawNeeded = false;
g.save();
g.translate(x, y);
if (redrawBufferNeeded) {
buffer.render();
redrawBufferNeeded = false;
}
if (null != backgroundColor) {
g.beginPath();
g.rect(0, 0, width, height);
g.setFillStyle(backgroundColor);
g.fill();
}
buffer.flip(g);
g.restore();
}
示例8: redrawIfNecessary
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void redrawIfNecessary(Context2d g, double timestamp) {
if (!isVisible()) {
return;
}
if (redrawNeeded) {
clearRect(g);
render(g, timestamp);
} else {
g.save();
g.translate(x, y);
for (UiElement c : children) {
c.redrawIfNecessary(g, timestamp);
}
g.restore();
}
}
示例9: render
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void render(Context2d g, double timestamp) {
if (!isVisible()) {
return;
}
redrawNeeded = false;
g.save();
g.translate(x, y);
if (clip) {
g.beginPath();
g.rect(0, 0, width, height);
g.clip();
}
for (UiElement c : children) {
c.render(g, timestamp);
}
g.restore();
}
示例10: setTextAlign
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
/**
* Apply the text align.
*/
public static void setTextAlign(Context2d g, TextAlign textAlign, int width) {
switch (textAlign) {
case RIGHT:
g.translate(width, 0);
break;
case CENTER:
g.translate(width / 2, 0);
break;
case END:
break;
case LEFT:
break;
case START:
break;
default:
break;
}
}
示例11: setTextBaseline
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
/**
* Apply the text baseline.
*/
public static void setTextBaseline(Context2d g, TextBaseline textBaseline, int height) {
switch (textBaseline) {
case BOTTOM:
g.translate(0, height);
break;
case MIDDLE:
g.translate(0, height / 2);
break;
case ALPHABETIC:
break;
case HANGING:
break;
case IDEOGRAPHIC:
break;
case TOP:
break;
default:
break;
}
}
示例12: redraw
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
public void redraw() {
Context2d graphics2d = canvas.getContext2d();
int w = canvas.getCoordinateSpaceWidth(), h = canvas.getCoordinateSpaceHeight();
graphics2d.setFillStyle(background);
graphics2d.fillRect(0, 0, w, h);
if (pageInfo == null)
return;
int subsample = toSubsample(zoom);
double scale = zoom / toZoom(subsample);
graphics2d.save();
int startX = w / 2 - centerX, startY = h / 2 - centerY;
graphics2d.translate(startX, startY);
graphics2d.scale(scale, scale);
graphics2d.translate(-startX, -startY);
graphics2d.scale(1, -1); // DjVu images have y-axis inverted
int tileSize = DjvuContext.getTileSize();
int pw = (int) (pageInfo.width * zoom), ph = (int) (pageInfo.height * zoom);
range.xmin = (int) (Math.max(0, centerX - w * 0.5) / tileSize / scale);
range.xmax = (int) Math.ceil(Math.min(pw, centerX + w * 0.5) / tileSize / scale);
range.ymin = (int) (Math.max(0, centerY - h * 0.5) / tileSize / scale);
range.ymax = (int) Math.ceil(Math.min(ph, centerY + h * 0.5) / tileSize / scale);
imagesArray = dataStore.getTileImages(page, subsample, range , imagesArray);
for (int y = range.ymin; y <= range.ymax; y++) {
for (int x = range.xmin; x <= range.xmax; x++) {
CanvasElement canvasElement = imagesArray[y - range.ymin][x - range.xmin];
for (int repeats = scale == 1 ? 1 : 3; repeats > 0; repeats--) {
graphics2d.drawImage(canvasElement, startX + x * tileSize,
-startY - y * tileSize - canvasElement.getHeight());
}
}
}
graphics2d.restore();
// missing tile graphics may exceed the page boundary
graphics2d.fillRect(startX + pw, 0, w, h);
graphics2d.fillRect(0, startY + ph, w, h);
DjvuContext.setTileRange(range, subsample);
}
示例13: drawGrid
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
private void drawGrid() {
Context2d ctx = canvasLayer.getContext();
ctx.save();
ctx.translate(0.5, 0.5);
ctx.setStrokeStyle(CssColors.BLACK);
ctx.setLineWidth(1);
ctx.beginPath();
// Horizontal grid lines
for (int i = startX; i < height; i += stepY) {
if (dashed) {
drawDashedLine(startX, i, width, 2, 2, true, ctx);
} else {
ctx.moveTo(startX, i);
ctx.lineTo(width, i);
}
}
// Vertical grid lines
for (int i = startY; i < width; i += stepX) {
if (dashed) {
drawDashedLine(i, startY, height, 2, 2, false, ctx);
} else {
ctx.moveTo(i, startY);
ctx.lineTo(i, height);
}
}
ctx.stroke();
ctx.restore();
}
示例14: render
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
private void render() {
Context2d context = canvas.getContext2d();
context.setFillStyle("white");
context.setStrokeStyle("grey");
context.fillRect(0, 0, 600, 600);
context.save();
context.translate(0, 600);
context.scale(1, -1);
context.scale(100, 100);
context.setLineWidth(0.01);
for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
Vec2 center = body.getPosition();
context.save();
context.translate(center.x, center.y);
context.rotate(body.getAngle());
for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
Shape shape = fixture.getShape();
if (shape.getType() == ShapeType.CIRCLE) {
CircleShape circle = (CircleShape) shape;
context.beginPath();
context.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
context.closePath();
context.stroke();
} else if (shape.getType() == ShapeType.POLYGON) {
PolygonShape poly = (PolygonShape) shape;
Vec2[] vertices = poly.getVertices();
context.beginPath();
context.moveTo(vertices[0].x, vertices[0].y);
for (int i = 1; i < poly.getVertexCount(); ++i) {
context.lineTo(vertices[i].x, vertices[i].y);
}
context.closePath();
context.stroke();
}
}
context.restore();
}
context.restore();
}
示例15: draw
import com.google.gwt.canvas.dom.client.Context2d; //導入方法依賴的package包/類
@Override
public void draw(Context2d context, DisplayArea area, OnDrawnCallback cb) {
double zoom = area.zoom();
context.save();
context.translate(-area.viewportLeft(), -area.viewportTop());
context.scale(zoom, zoom);
// outline
int[][] coords = el.coordinates();
context.beginPath();
context.moveTo(coords[0][0], coords[0][1]);
for (int i = 1; i < coords.length; i++) {
context.lineTo(coords[i][0], coords[i][1]);
}
context.setLineWidth(6);
context.stroke();
context.setGlobalAlpha(0.3);
context.setFillStyle("white");
context.fill();
context.setGlobalAlpha(1.0);
context.closePath();
// text
context.setFillStyle("black");
context.setFont("bold 60px sans-serif");
context.setTextBaseline("top");
context.fillText(el.text(), el.baseLeft(), el.baseTop(), el.baseWidth());
context.restore();
cb.onDrawn();
}