adjustClip method

Quality? adjustClip(
  1. Point<num> mouse,
  2. bool click
)

Implementation

Quality? adjustClip(Point mouse, bool click) {
  if (click) return null;
  if (_clip == null) return null;

  //print('--- adjustClip ---');

  var point = _getMousePointInCanvas(mouse);

  var clip = _clip?.value ?? _defaultClip();
  var edges = _toEdgePoints(clip);

  var target = nearestPoint(edges, point);

  //print(target);

  Rectangle? clip2;

  if (target == edges[0] ||
      target == edges[1] ||
      target == edges[2] ||
      target == edges[3] ||
      target == edges[4]) {
    var diffW = point.x - clip.left as int;
    clip2 = Rectangle(point.x, clip.top, clip.width - diffW, clip.height);
  } else if (target == edges[5] ||
      target == edges[6] ||
      target == edges[7] ||
      target == edges[8] ||
      target == edges[9]) {
    var diffH = point.y - clip.top as int;
    clip2 = Rectangle(clip.left, point.y, clip.width, clip.height - diffH);
  } else if (target == edges[10] ||
      target == edges[11] ||
      target == edges[12] ||
      target == edges[13] ||
      target == edges[14]) {
    clip2 = Rectangle(clip.left, clip.top, point.x - clip.left, clip.height);
  } else if (target == edges[15] ||
      target == edges[16] ||
      target == edges[17] ||
      target == edges[18] ||
      target == edges[19]) {
    clip2 = Rectangle(clip.left, clip.top, clip.width, point.y - clip.top);
  } else {
    clip2 = Rectangle<num>(clip.left, clip.top, clip.width, clip.height);
  }

  clip2 = clip2.intersection(Rectangle(0, 0, width, height));

  if (clip2 != null) {
    var clipArea = clip2.width * clip2.height;
    if (clipArea > 1) {
      _clip = clipViewerElement(clip2, _clip?.color);
      return Quality.high;
    }
  }

  return Quality.high;
}