示例#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);
 }
示例#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);
 }
示例#3
0
 @Override
 public Surface setAlpha(float alpha) {
   int ialpha = (int) (0xFF * MathUtil.clamp(alpha, 0, 1));
   this.tint = (ialpha << 24) | (tint & 0xFFFFFF);
   return this;
 }
示例#4
0
 @Override
 protected Float updateAndNotifyIf(Float value) {
   return super.updateAndNotifyIf(MathUtil.clamp(value, 0, 1));
 }