paint method

  1. @override
void paint (Canvas canvas, Size size)

Called whenever the object needs to paint. The given Canvas has its coordinate space configured such that the origin is at the top left of the box. The area of the box is the size of the size argument.

Paint operations should remain inside the given area. Graphical operations outside the bounds may be silently ignored, clipped, or not clipped.

Implementations should be wary of correctly pairing any calls to Canvas.save/Canvas.saveLayer and Canvas.restore, otherwise all subsequent painting on this canvas may be affected, with potentially hilarious but confusing results.

To paint text on a Canvas, use a TextPainter.

To paint an image on a Canvas:

  1. Obtain an ImageStream, for example by calling ImageProvider.resolve on an AssetImage or NetworkImage object.

  2. Whenever the ImageStream's underlying ImageInfo object changes (see ImageStream.addListener), create a new instance of your custom paint delegate, giving it the new ImageInfo object.

  3. In your delegate's paint method, call the Canvas.drawImage, Canvas.drawImageRect, or Canvas.drawImageNine methods to paint the ImageInfo.image object, applying the ImageInfo.scale value to obtain the correct rendering size.

Implementation

@override
void paint(Canvas canvas, Size size) {
  int maxSize = 1100;
  int leftLine = 100;
  int rightLine = 950;

  void _drawCircle(int x, int y, Color v) {
    double xCircle;
    double yCircle;
    xCircle = x.toDouble() / maxSize * size.width;
    yCircle = y.toDouble() / maxSize * size.height;

    Paint line = Paint()
      ..color = v
      ..strokeCap = StrokeCap.round
      ..style = PaintingStyle.stroke
      ..strokeWidth = 4.0;
//      print("C: $xCircle / ${size.width}");
    canvas.drawCircle(Offset(xCircle, yCircle), 8.0, line);
  }

  void _drawSlider(int x, int y, Color v) {
    double topSlider = 65.0;
    double bottomSlider = 940.0;
    int sliderPercent;
    double range = bottomSlider - topSlider;
    double sliderPosition;
    double sliderValue;

    if (y > topSlider) {
      sliderPosition = y - topSlider;
    } else {
      sliderPosition = 0;
    }
    sliderValue = sliderPosition / range; // 0...1

    sliderPercent = (sliderValue * 100).round(); // %
    if (sliderPercent > 100) sliderPercent = 100;
    if (sliderPercent < 0) sliderPercent = 0;

/*      print("range: $range");
    print("sliderPosition = $sliderPosition");
    print("%: $sliderValue");
    print("%R: $sliderPercent");*/

    Paint line = Paint()
      ..color = v
      ..strokeCap = StrokeCap.round
      ..style = PaintingStyle.stroke
      ..strokeWidth = 5.0;
    var xLine = rightLine;
    var yLine = size.height * (y / maxSize);
//      print("$yLine / ${size.height}");
    canvas.drawLine(

        ///Slider line
        Offset(xLine / maxSize * size.width, yLine),
        Offset(
            (xLine + (maxSize - xLine) / 1.2) / maxSize * size.width, yLine),
        line);
    TextSpan percentage =
        new TextSpan(style: new TextStyle(color: v), text: "$sliderPercent");
    TextPainter tp = new TextPainter(
        text: percentage,
        textAlign: TextAlign.left,
        textDirection: TextDirection.rtl);
    tp.layout();
    tp.paint(canvas,
        new Offset(rightLine / maxSize * size.width - 50.0, yLine - 15.0));

  }



  touchCollection.forEach((k, v) {
//      print("${k.f}  ${k.e}  ${k.x}  ${k.y}");
    if (k.x <= 1023 && k.y < maxSize) {
      switch (k.e) {
        case 5:
          {
            break;
          }
        case 4:
          {
            continue move;
          }
        move:
        case 1:
          {


/*              _drawCircle(0, maxSize, v); //L U
            _drawCircle(0, 550, v); // L M
            _drawCircle(0, 0, v); // L O

            _drawCircle(550, 0, v); // M O
            _drawCircle(550, 550, v); // MITTE
            _drawCircle(550, maxSize, v); // M U

            _drawCircle(maxSize, 0, v); // R O
            _drawCircle(maxSize, 550, v); // R M
            _drawCircle(maxSize, maxSize, v); //R U*/

//          _drawCircle(175, 511, v); // L M
//          _drawCircle(850, 511, v); // L M
//              _drawCircle(180, 550, v); // L M

            /// middle touch pad
            if (k.x > leftLine && k.x < rightLine) {
              _drawCircle(k.x, k.y, v);
            }

            /// right slider
            else if (k.x >= rightLine) {
              _drawSlider(k.x, k.y, v);
            }
            break;
          }
        default:
          {
            print("       W.T.F");
            print("tE: $k.e");
            break;
          }
      }
    }
  });
}