當前位置: 首頁>>代碼示例>>Java>>正文


Java Context2d類代碼示例

本文整理匯總了Java中com.google.gwt.canvas.dom.client.Context2d的典型用法代碼示例。如果您正苦於以下問題:Java Context2d類的具體用法?Java Context2d怎麽用?Java Context2d使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Context2d類屬於com.google.gwt.canvas.dom.client包,在下文中一共展示了Context2d類的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;
}
 
開發者ID:cjmalloy,項目名稱:GwtGameUi,代碼行數:24,代碼來源:ScrollPanel.java

示例2: createCanvas

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
public static Canvas createCanvas(int [] pixels, int width, int height) {
	
	Canvas canvas = Canvas.createIfSupported();
	
	if(canvas == null) return null;
	
	canvas.setCoordinateSpaceWidth(width);
	canvas.setCoordinateSpaceHeight(height);
	
	Context2d context = canvas.getContext2d();
	ImageData data = context.createImageData(width, height);

	CanvasPixelArray array = data.getData();
	for(int i=0; i<width*height; i++) { // ABGR
		array.set(4*i+0, pixels[i] & 0xFF);
		array.set(4*i+1, (pixels[i] >> 8) & 0xFF);
		array.set(4*i+2, (pixels[i] >> 16) & 0xFF);
		array.set(4*i+3, (pixels[i] >> 24) & 0xFF);
	}
	context.putImageData(data, 0, 0);
	
	return canvas;
	
}
 
開發者ID:npedotnet,項目名稱:npe-image-library,代碼行數:25,代碼來源:GwtImageReader.java

示例3: createImageCanvas

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
Canvas createImageCanvas(int [] pixels, int width, int height) {

	    Canvas canvas = Canvas.createIfSupported();
	    canvas.setCoordinateSpaceWidth(width);
	    canvas.setCoordinateSpaceHeight(height);

	    Context2d context = canvas.getContext2d();
	    ImageData data = context.createImageData(width, height);

	    CanvasPixelArray array = data.getData();
	    for(int i=0; i<width*height; i++) {
	        array.set(4*i+0, pixels[i] & 0xFF);
	        array.set(4*i+1, (pixels[i] >> 8) & 0xFF);
	        array.set(4*i+2, (pixels[i] >> 16) & 0xFF);
	        array.set(4*i+3, (pixels[i] >> 24) & 0xFF);
	    }
	    context.putImageData(data, 0, 0);

	    return canvas;

	}
 
開發者ID:npedotnet,項目名稱:TGAReader,代碼行數:22,代碼來源:TexturedCube.java

示例4: createImageCanvas

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
private Canvas createImageCanvas(int [] pixels, int width, int height) {
	
	Canvas canvas = Canvas.createIfSupported();
	canvas.setCoordinateSpaceWidth(width);
	canvas.setCoordinateSpaceHeight(height);
	
	Context2d context = canvas.getContext2d();
	ImageData data = context.createImageData(width, height);

	CanvasPixelArray array = data.getData();
	for(int i=0; i<width*height; i++) { // ABGR
		array.set(4*i+0, pixels[i] & 0xFF);
		array.set(4*i+1, (pixels[i] >> 8) & 0xFF);
		array.set(4*i+2, (pixels[i] >> 16) & 0xFF);
		array.set(4*i+3, (pixels[i] >> 24) & 0xFF);
	}
	context.putImageData(data, 0, 0);
	
	canvas.getElement().getStyle().setMargin(4, Unit.PX);
	
	return canvas;
	
}
 
開發者ID:npedotnet,項目名稱:TGAReader,代碼行數:24,代碼來源:ImageCanvasTest.java

示例5: TextDisplayElement

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
public TextDisplayElement(String id, int x, int y, int width, int height,
        String text, int[][] coords) {
    super(id, x, y, width, height);
    this.coords = coords;
    this.text = text;
    
 // Create a canvas containing the filled polygon with no border
    Canvas sub_canvas = Canvas.createIfSupported();
    sub_canvas.setCoordinateSpaceWidth(width);
    sub_canvas.setCoordinateSpaceHeight(height);
    
    Context2d context = sub_canvas.getContext2d();
    context.beginPath();
    context.moveTo(coords[0][0] - baseLeft(), coords[0][1] - baseTop());

    for (int i = 1; i < coords.length; i++) {
    	context.lineTo(coords[i][0] - baseLeft(), coords[i][1] - baseTop());
    }
	
    context.setFillStyle(color_fill);
    context.fill();
    
    context.closePath();
    
    this.image_data = context.getImageData(0, 0, width, height);
}
 
開發者ID:jhu-digital-manuscripts,項目名稱:rosa,代碼行數:27,代碼來源:TextDisplayElement.java

示例6: drawShape

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
/**
 * Rysuje zakonczenie linii
 *
 * @param shapeName
 * @param context
 * @param centerX
 * @param centerY
 * @param startX
 * @param startY
 */
private void drawShape(String shapeName, Context2d context, double centerX, double centerY, double startX, double startY) {
    if ("dot".equals(shapeName)) {
        context.beginPath();
        context.arc(centerX, centerY, 3, 0, 2 * Math.PI, false);
        context.closePath();
        context.fill();
    } else if ("arrow".equals(shapeName)) {
        CanvasArrow canvas = new CanvasArrow(context, startX, startY, centerX, centerY);
        canvas.draw();
    }
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:22,代碼來源:LabelledImgContent.java

示例7: 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;
}
 
開發者ID:iSergio,項目名稱:gwt-cs,代碼行數:22,代碼來源:MarkerGroup.java

示例8: setRgb

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
@Override public void setRgb(int startX, int startY, int width, int height,
                             int[] rgbArray, int offset, int scanSize) {
  Context2d ctx = canvas.getContext2d();
  ImageData imageData = ctx.createImageData(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 argb = rgbArray[dst + x];
      pixelData.set(i++, (argb >> 16) & 255);
      pixelData.set(i++, (argb >> 8) & 255);
      pixelData.set(i++, (argb) & 255);
      pixelData.set(i++, (argb >> 24) & 255);
    }
    dst += scanSize;
  }
  ctx.putImageData(imageData, startX, startY);
}
 
開發者ID:playn,項目名稱:playn,代碼行數:20,代碼來源:HtmlImage.java

示例9: layoutText

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
public static TextLayout[] layoutText(HtmlGraphics gfx, Context2d ctx, String text,
                                      TextFormat format, TextWrap wrap) {
  HtmlFontMetrics metrics = gfx.getFontMetrics(getFont(format));
  configContext(ctx, format);
  List<TextLayout> layouts = new ArrayList<TextLayout>();

  // normalize newlines in the text (Windows: CRLF -> LF, Mac OS pre-X: CR -> LF)
  text = normalizeEOL(text);
  for (String line : text.split("\\n")) {
    String[] words = line.split("\\s"); // TODO: preserve intra-line whitespace
    for (int idx = 0; idx < words.length; ) {
      // note: measureLine has the side effect of adding the measured line to this.lines and
      // setting this.width to the maximum of the current width and the measured line width
      idx = measureLine(ctx, format, wrap, metrics, words, idx, layouts);
    }
  }
  return layouts.toArray(new TextLayout[layouts.size()]);
}
 
開發者ID:playn,項目名稱:playn,代碼行數:19,代碼來源:HtmlTextLayout.java

示例10: mousePressed

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
protected void mousePressed(MouseDownEvent event) {
	int bar = findBar( event.getX(), event.getY() );
	if( bar == -1 ) return;
	double val = findValue( bar, event.getY() );
	List<Double> v = distribution.getValues();
	v.set( bar, val );
	distribution.flatten( bar );
	distribution.setValues( v ); // not needed because distribution.getValues() returns a reference
	this.bars = mkBars( distribution, mleft, mtop, canvas.getCoordinateSpaceWidth() -(mleft + mright), canvas.getCoordinateSpaceHeight() -(mtop + mbottom) );
	Context2d g = canvas.getContext2d();
	g.clearRect( 0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight() );
	paint( distribution, g, mleft, mtop, canvas.getCoordinateSpaceWidth() -(mleft + mright), canvas.getCoordinateSpaceHeight() -(mtop + mbottom) );
	for( Listener l : listeners ) {
		l.IndicatorValueChanged();
	}
}
 
開發者ID:RISCOSS,項目名稱:riscoss-corporate,代碼行數:17,代碼來源:IndicatorWidget.java

示例11: drawGridOn

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
public static void drawGridOn(Context2d context2d) {
	if (gridCanvas == null) {
		gridCanvas = Canvas.createIfSupported();
		gridCanvas.setCoordinateSpaceWidth(3000);
		gridCanvas.setCoordinateSpaceHeight(2000);
		int width = gridCanvas.getCoordinateSpaceWidth();
		int height = gridCanvas.getCoordinateSpaceHeight();
		Context2d backgroundContext = gridCanvas.getContext2d();
		backgroundContext.setStrokeStyle(Converter.convert(ColorOwn.BLACK.transparency(Transparency.SELECTION_BACKGROUND)));
		for (int i = 0; i < width; i += SharedConstants.DEFAULT_GRID_SIZE) {
			drawLine(backgroundContext, i, 0, i, height);
		}
		for (int i = 0; i < height; i += SharedConstants.DEFAULT_GRID_SIZE) {
			drawLine(backgroundContext, 0, i, width, i);
		}
	}
	context2d.drawImage(gridCanvas.getCanvasElement(), 0, 0);
}
 
開發者ID:umlet,項目名稱:umlet,代碼行數:19,代碼來源:CanvasUtils.java

示例12: drawEllipseHelper

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
/**
 * based on http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas/2173084#2173084
 */
private static void drawEllipseHelper(Context2d ctx, boolean drawOuterLine, double x, double y, double w, double h) {
	double kappa = .5522848f;
	double ox = w / 2 * kappa; // control point offset horizontal
	double oy = h / 2 * kappa; // control point offset vertical
	double xe = x + w; // x-end
	double ye = y + h; // y-end
	double xm = x + w / 2; // x-middle
	double ym = y + h / 2; // y-middle

	ctx.beginPath();
	ctx.moveTo(x, ym);
	ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
	ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
	ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
	ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
	ctx.fill();
	if (drawOuterLine) {
		ctx.stroke();
	}
}
 
開發者ID:umlet,項目名稱:umlet,代碼行數:24,代碼來源:DrawHandlerGwt.java

示例13: drawRoundRectHelper

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
/**
 * based on http://js-bits.blogspot.co.at/2010/07/canvas-rounded-corner-rectangles.html
 */
private static void drawRoundRectHelper(Context2d ctx, boolean drawOuterLine, final double x, final double y, final double width, final double height, final double radius) {
	ctx.beginPath();
	ctx.moveTo(x + radius, y);
	ctx.lineTo(x + width - radius, y);
	ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
	ctx.lineTo(x + width, y + height - radius);
	ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
	ctx.lineTo(x + radius, y + height);
	ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
	ctx.lineTo(x, y + radius);
	ctx.quadraticCurveTo(x, y, x + radius, y);
	ctx.closePath();
	ctx.fill();
	if (drawOuterLine) {
		ctx.stroke();
	}
}
 
開發者ID:umlet,項目名稱:umlet,代碼行數:21,代碼來源:DrawHandlerGwt.java

示例14: setLineDash

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
private void setLineDash(Context2d ctx, LineType lineType, double lineThickness) {
	try {
		switch (lineType) {
			case DASHED: // large linethickness values need longer dashes
				setLineDash(ctx, 6 * Math.max(1, lineThickness / 2));
				break;
			case DOTTED: // minimum must be 2, otherwise the dotting is not really visible
				setLineDash(ctx, Math.max(2, lineThickness));
				break;
			default: // default is a solid line
				setLineDash(ctx, 0);
		}
	} catch (Exception e) {
		log.debug("No browser support for dashed lines", e);
		Notification.showFeatureNotSupported("Dashed and dotted lines are shown as solid lines<br/>To correctly display them, please use Firefox or Chrome", true);
	}
}
 
開發者ID:umlet,項目名稱:umlet,代碼行數:18,代碼來源:DrawHandlerGwt.java

示例15: prepareMissingTileImage

import com.google.gwt.canvas.dom.client.Context2d; //導入依賴的package包/類
private CanvasElement prepareMissingTileImage() {
	int tileSize = DjvuContext.getTileSize();
	CanvasElement canvas = createImage(tileSize, tileSize);
	Context2d context2d = canvas.getContext2d();
	context2d.setFillStyle("white");
	context2d.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
	Image image = new Image();
	final ImageElement imageElement = image.getElement().cast();
	imageElement.getStyle().setProperty("visibility", "hidden");
	Event.setEventListener(imageElement, event -> {
		if (Event.ONLOAD == event.getTypeInt()) {
			missingTileImage.getContext2d().drawImage(imageElement, 0, 0);
			RootPanel.get().getElement().removeChild(imageElement);
		}
	});
	RootPanel.get().getElement().appendChild(imageElement);
	image.setUrl(getBlankImageUrl());
	return canvas;
}
 
開發者ID:mateusz-matela,項目名稱:djvu-html5,代碼行數:20,代碼來源:DataStore.java


注:本文中的com.google.gwt.canvas.dom.client.Context2d類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。