CanvasImageViewer constructor

CanvasImageViewer({
  1. CanvasElement? canvas,
  2. int? width,
  3. int? height,
  4. int? maxWidth,
  5. int? maxHeight,
  6. bool canvasSizeSameOfRenderedImageSize = true,
  7. CanvasImageSource? image,
  8. ImageFilter? imageFilter,
  9. ViewerElement<Rectangle<num>>? clip,
  10. ViewerElement<List<Rectangle<num>>>? rectangles,
  11. ViewerElement<List<Point<num>>>? points,
  12. ViewerElement<List<Label<num>>>? labels,
  13. ViewerElement<List<Point<num>>>? perspective,
  14. ViewerElement<num>? gridSize,
  15. bool? cropPerspective,
  16. DateTime? time,
  17. EditionType? editable,
})

Implementation

CanvasImageViewer(
    {CanvasElement? canvas,
    int? width,
    int? height,
    int? maxWidth,
    int? maxHeight,
    this.canvasSizeSameOfRenderedImageSize = true,
    CanvasImageSource? image,
    ImageFilter? imageFilter,
    ViewerElement<Rectangle<num>>? clip,
    ViewerElement<List<Rectangle<num>>>? rectangles,
    ViewerElement<List<Point<num>>>? points,
    ViewerElement<List<Label<num>>>? labels,
    ViewerElement<List<Point<num>>>? perspective,
    ViewerElement<num>? gridSize,
    bool? cropPerspective,
    this.time,
    EditionType? editable})
    : _clip = clip,
      _rectangles = rectangles,
      _points = points,
      _labels = labels,
      _perspective = perspective,
      _gridSize = gridSize,
      _editionType = editable,
      _maxWidth = isPositiveNumber(maxWidth) ? maxWidth : null,
      _maxHeight = isPositiveNumber(maxHeight) ? maxHeight : null,
      _imageFilter = imageFilter {
  if (_imageFilter != null) {
    var imgW = 100;
    var imgH = 100;

    var wh = getImageDimension(image!);
    if (wh != null) {
      imgW = wh.width;
      imgH = wh.height;
    }

    image = _imageFilter(image, imgW, imgH);
  }

  _image = image;

  var w = width;
  var h = height;

  if (w == null || h == null) {
    var wh = getImageDimension(_image!);
    if (wh != null) {
      w ??= wh.width;
      h ??= wh.height;
    }
  }

  w ??= 100;
  h ??= 100;

  if (_image is ImageElement) {
    var img = _image;
    img.onLoad.listen((_) => _onLoadImage());
  }

  _renderedImageWidth = _width = w;
  _renderedImageHeight = _height = h;

  _canvas = canvas ?? CanvasElement(width: w, height: h);

  _imagePerspectiveFilterCache = ImagePerspectiveFilterCache(_image!, w, h);

  _setCanvasSizeSameOfRenderedImageSize(w, h);

  if (isEditable) {
    _canvas.onMouseDown.listen(_onMouseDown);
    _canvas.onMouseUp.listen(_onMouseUp);
    _canvas.onClick.listen(_onMouseClick);
    _canvas.onMouseLeave.listen(_onMouseLeave);
    _canvas.onMouseMove.listen(_onMouseMove);
  } else if (_labels != null && _labels.isNotEmpty) {
    _canvas.onMouseMove.listen(_onMouseMove);
  }

  cropPerspective ??= !isEditable || editable != EditionType.perspective;

  _cropPerspective = cropPerspective;
}