Beispiel #1
0
 @Override
 public void draw(
     Graphics2D gfx,
     float dx,
     float dy,
     float dw,
     float dh,
     float sx,
     float sy,
     float sw,
     float sh) {
   // adjust our source rect to account for the scale factor
   sx *= scale.factor;
   sy *= scale.factor;
   sw *= scale.factor;
   sh *= scale.factor;
   // now render the image through a clip and with a scaling transform, so that only the desired
   // source rect is rendered, and is rendered into the desired target region
   float scaleX = dw / sw, scaleY = dh / sh;
   Shape oclip = gfx.getClip();
   gfx.clipRect(MathUtil.ifloor(dx), MathUtil.ifloor(dy), MathUtil.iceil(dw), MathUtil.iceil(dh));
   gfx.drawImage(
       img, new AffineTransform(scaleX, 0f, 0f, scaleY, dx - sx * scaleX, dy - sy * scaleY), null);
   gfx.setClip(oclip);
 }
Beispiel #2
0
 @Override
 protected Pattern toSubPattern(
     AbstractImageGL<?> image,
     boolean repeatX,
     boolean repeatY,
     float x,
     float y,
     float width,
     float height) {
   CanvasElement canvas = Document.get().createElement("canvas").<CanvasElement>cast();
   canvas.setWidth(MathUtil.iceil(width));
   canvas.setHeight(MathUtil.iceil(height));
   canvas.getContext2d().drawImage(img, x, y, width, height, 0, 0, width, height);
   ImageElement subelem = canvas.cast();
   return new HtmlPattern(image, subelem, repeatX, repeatY);
 }