Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is what I came up with. Basically what it does is, it encapsulates an image and a 0.5 opacity canvas on top of each other in a composite widget. The animation draws lines on the canvas from the center towards the edges in a circular fashion in a given time interval. Canvas has a clickHandler to start the animation. Hope it helps. It uses GWT Canvas so this widget may not be supported on all browsers.</p> <p>Class CoolDownAnimation :</p> <pre><code> public class CoolDownAnimation extends Animation { Canvas canvas; Context2d context; int centerX; int centerY; static final CssColor BLACK = CssColor.make("rgba(0,0,0,0.6)"); static final CssColor WHITE = CssColor.make("rgba(255,255,255,0.6)"); public CoolDownAnimation(Canvas canvas) { this.canvas = canvas; canvas.setCoordinateSpaceHeight(20); canvas.setCoordinateSpaceWidth(20); canvas.getElement().getStyle().setOpacity(0.5); this.context = canvas.getContext2d(); centerX = canvas.getCoordinateSpaceWidth() / 2; centerY = canvas.getCoordinateSpaceHeight() / 2; } @Override protected void onStart() { context.beginPath(); context.setStrokeStyle(BLACK); context.fillRect(0, 0, centerX * 2, centerY * 2); context.setStrokeStyle(WHITE); super.onStart(); } @Override protected void onUpdate(double progress) { context.moveTo(centerX, centerY); context.lineTo( centerX + 2 * centerX * Math.cos((progress * Math.PI * 2)-Math.PI/2), centerY + 2 * centerY * Math.sin((progress * Math.PI * 2)-Math.PI/2)); context.stroke(); } @Override protected void onComplete() { super.onComplete(); context.closePath(); context.clearRect(0, 0, centerX*2, centerY*2); } } </code></pre> <p>Class CoolDownWidget : </p> <pre><code> public class CoolDownWidget extends Composite { private CoolDownAnimation coolDown; private AbsolutePanel wrapper; private Image image; private Canvas canvas; private int sizeX = 50; private int sizeY = 50; private int coolDownDuration = 5000; public CoolDownWidget(){ canvas = Canvas.createIfSupported(); if (canvas==null){ Window.alert("Fail! You dont have canvas support"); } canvas.getElement().getStyle().setOpacity(0.5); canvas.setPixelSize(sizeX,sizeY); coolDown = new CoolDownAnimation(canvas); image = new Image("images/icon.png"); image.setPixelSize(sizeX, sizeY); canvas.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { coolDown.cancel(); coolDown.run(coolDownDuration); } }); wrapper = new AbsolutePanel(); wrapper.setPixelSize(sizeX, sizeY); wrapper.add(image, 0, 0); wrapper.add(canvas,0,0); initWidget(wrapper); } } </code></pre> <p>finally onModuleLoad to wrap things up :</p> <pre><code> public void onModuleLoad() { RootPanel.get().add(new CoolDownWidget()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload