Advertisement
Guest User

only redraw on window resize!?

a guest
Aug 9th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     Canvas {
  2.  
  3.         /*
  4.         draw a circle that corresponds to the variable progress.
  5.         progress goes from 1 to 0, so the circle has full circumference and then shrinks.
  6.         */
  7.  
  8.         id: circleProgress
  9.         anchors.fill: parent
  10.  
  11.         onPaint: {
  12.             var ctx = circleProgress.getContext("2d");
  13.  
  14.             drawProgressCircle(ctx, progress);
  15.  
  16.             // those do not work, only window resizing shows the progress...:
  17.            
  18.             // circleProgress.paint();
  19.             // circleProgress.requestPaint();
  20.             // ctx.clearRect(0, 0, width, height);
  21.         }
  22.  
  23.         function drawProgressCircle(ctx, progress) {
  24.  
  25.             var centreX    = width / 2
  26.             var centreY    = width / 2
  27.             var lineWidth  = diameter / 40
  28.             // to start at top
  29.             var startAngle = 1.5 * Math.PI
  30.  
  31.             ctx.beginPath();
  32.             ctx.fillStyle = "black";
  33.             ctx.lineWidth = lineWidth;
  34.             ctx.lineCap   = "round";
  35.             ctx.moveTo(centreX, centreY - diameter / 2); // move to highest point in circle
  36.  
  37.             // draw a circle that is full in the beginning, but as progress shrinks            
  38.             ctx.arc(centreX, centreY, diameter / 2 - lineWidth / 2, startAngle,
  39.                     startAngle + 2 * progress * Math.PI, false);
  40.             ctx.stroke();
  41.             ctx.closePath();
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement