void _paintBackgroundImage(Canvas canvas, Rect rect, ImageConfiguration configuration)
        {
            if (this._decoration.image == null)
            {
                return;
            }

            this._imagePainter = this._imagePainter ?? this._decoration.image.createPainter(this.onChanged);

            Path clipPath = null;

            switch (this._decoration.shape)
            {
            case BoxShape.circle:
                clipPath = new Path();
                clipPath.addOval(rect);
                break;

            case BoxShape.rectangle:
                if (this._decoration.borderRadius != null)
                {
                    clipPath = new Path();
                    clipPath.addRRect(this._decoration.borderRadius.toRRect(rect));
                }

                break;
            }

            this._imagePainter.paint(canvas, rect, clipPath, configuration);
        }
Ejemplo n.º 2
0
 public override Future <AssetBundleImageKey> obtainKey(ImageConfiguration configuration)
 {
     return(new SynchronousFuture <AssetBundleImageKey>(new AssetBundleImageKey(
                                                            bundle: bundle?bundle: configuration.bundle,
                                                            name: assetName,
                                                            scale: scale
                                                            )));
 }
Ejemplo n.º 3
0
 protected override IPromise <AssetBundleImageKey> obtainKey(ImageConfiguration configuration)
 {
     return(Promise <AssetBundleImageKey> .Resolved(new AssetBundleImageKey(
                                                        bundle : this.bundle ? this.bundle : configuration.bundle,
                                                        name : this.assetName,
                                                        scale : this.scale
                                                        )));
 }
Ejemplo n.º 4
0
 void _paintImage(Canvas canvas, ImageConfiguration configuration)
 {
     if (this._decoration.image == null)
     {
         return;
     }
     this._imagePainter = this._imagePainter ?? this._decoration.image.createPainter(this.onChanged);
     this._imagePainter.paint(canvas, this._lastRect, this._innerPath, configuration);
 }
Ejemplo n.º 5
0
        void _paintImage(Canvas canvas, ImageConfiguration configuration)
        {
            if (_decoration.image == null)
            {
                return;
            }

            _imagePainter = _imagePainter ?? _decoration.image.createPainter(onChanged);
            _imagePainter.paint(canvas, _lastRect, _innerPath, configuration);
        }
Ejemplo n.º 6
0
        public override void paint(Canvas canvas, Offset offset, ImageConfiguration configuration)
        {
            D.assert(configuration != null);
            D.assert(configuration.size != null);
            Rect rect = offset & configuration.size;

            this._precache(rect);
            this._paintShadows(canvas);
            this._paintInterior(canvas);
            this._paintImage(canvas, configuration);
            this._decoration.shape.paint(canvas, rect);
        }
        internal string _chooseVariant(string main, ImageConfiguration config, List <string> candidates)
        {
            if (config.devicePixelRatio == null || candidates == null || candidates.isEmpty())
            {
                return(main);
            }
            SplayTree <float, string> mapping = new SplayTree <float, string>();

            foreach (string candidate in candidates)
            {
                mapping[_parseScale(candidate)] = candidate;
            }

            return(_findNearest(mapping, config.devicePixelRatio ?? 0));
        }
        public override void paint(Canvas canvas, Offset offset, ImageConfiguration configuration)
        {
            D.assert(configuration != null);
            D.assert(configuration.size != null);

            Rect rect = offset & configuration.size;

            this._paintShadows(canvas, rect);
            this._paintBackgroundColor(canvas, rect);
            this._paintBackgroundImage(canvas, rect, configuration);
            this._decoration.border?.paint(
                canvas,
                rect,
                shape: this._decoration.shape,
                borderRadius: this._decoration.borderRadius
                );
        }
Ejemplo n.º 9
0
        public void paint(Canvas canvas, Rect rect, Path clipPath, ImageConfiguration configuration)
        {
            D.assert(canvas != null);
            D.assert(rect != null);
            D.assert(configuration != null);

            ImageStream newImageStream = this._details.image.resolve(configuration);

            if (newImageStream.key != this._imageStream?.key)
            {
                this._imageStream?.removeListener(this._imageListener);
                this._imageStream = newImageStream;
                this._imageStream.addListener(this._imageListener);
            }

            if (this._image == null)
            {
                return;
            }

            if (clipPath != null)
            {
                canvas.save();
                canvas.clipPath(clipPath);
            }

            ImageUtils.paintImage(
                canvas: canvas,
                rect: rect,
                image: this._image.image,
                scale: this._image.scale,
                colorFilter: this._details.colorFilter,
                fit: this._details.fit,
                alignment: this._details.alignment,
                centerSlice: this._details.centerSlice,
                repeat: this._details.repeat
                );

            if (clipPath != null)
            {
                canvas.restore();
            }
        }
        public override Future <AssetBundleImageKey> obtainKey(ImageConfiguration configuration)
        {
            AssetImageConfiguration assetConfig = new AssetImageConfiguration(configuration, assetName);
            AssetBundleImageKey     key;
            var cache = AssetBundleCache.instance.get(configuration.bundle);

            if (cache.TryGetValue(assetConfig, out key))
            {
                return(new SynchronousFuture <AssetBundleImageKey>(key));
            }

            AssetBundle chosenBundle     = bundle ? bundle : configuration.bundle;
            var         devicePixelRatio = configuration.devicePixelRatio ?? Window.instance.devicePixelRatio;

            key = _loadAsset(chosenBundle, devicePixelRatio);
            cache[assetConfig] = key;

            return(new SynchronousFuture <AssetBundleImageKey>(key));
        }
Ejemplo n.º 11
0
        protected override IPromise <AssetBundleImageKey> obtainKey(ImageConfiguration configuration)
        {
            AssetImageConfiguration assetConfig = new AssetImageConfiguration(configuration, this.assetName);
            AssetBundleImageKey     key;
            var cache = AssetBundleCache.instance.get(configuration.bundle);

            if (cache.TryGetValue(assetConfig, out key))
            {
                return(Promise <AssetBundleImageKey> .Resolved(key));
            }

            AssetBundle chosenBundle     = this.bundle ? this.bundle : configuration.bundle;
            var         devicePixelRatio = configuration.devicePixelRatio ?? Window.instance.devicePixelRatio;

            key = this._loadAsset(chosenBundle, devicePixelRatio);
            cache[assetConfig] = key;

            return(Promise <AssetBundleImageKey> .Resolved(key));
        }
Ejemplo n.º 12
0
        IPromise <AssetBundleImageKey> obtainKey(ImageConfiguration configuration)
        {
            AssetImageConfiguration assetConfig = new AssetImageConfiguration(configuration, this.assetName);
            AssetBundleImageKey     key;
            var cache = AssetBundleCache.instance.get(configuration.bundle);

            if (cache.TryGetValue(assetConfig, out key))
            {
                return(Promise <AssetBundleImageKey> .Resolved(key));
            }

            AssetBundle chosenBundle     = this.bundle ? this.bundle : configuration.bundle;
            var         devicePixelRatio = configuration.devicePixelRatio ?? Window.instance.devicePixelRatio;
            var         coroutine        = Window.instance.startCoroutine(this._loadAssetAsync(chosenBundle, devicePixelRatio));

            return(coroutine.promise.Then(result => {
                D.assert(result != null);

                key = (AssetBundleImageKey)result;
                cache[assetConfig] = key;
                return key;
            }));
        }
Ejemplo n.º 13
0
        public override Future <_SizeAwareCacheKey> obtainKey(ImageConfiguration configuration)
        {
            Completer completer = null;
            SynchronousFuture <_SizeAwareCacheKey> result = null;

            imageProvider.obtainKey(configuration).then((object key) => {
                // TODO: completer is always null?
                if (completer == null)
                {
                    result = new SynchronousFuture <_SizeAwareCacheKey>(new _SizeAwareCacheKey(key, width, height));
                }
                else
                {
                    completer.complete(FutureOr.value(new _SizeAwareCacheKey(key, width, height)));
                }
            });
            if (result != null)
            {
                return(result);
            }

            completer = Completer.create();
            return(completer.future.to <_SizeAwareCacheKey>());
        }
Ejemplo n.º 14
0
 protected override IPromise <MemoryImage> obtainKey(ImageConfiguration configuration)
 {
     return(Promise <MemoryImage> .Resolved(this));
 }
Ejemplo n.º 15
0
 public abstract ImageStream resolve(ImageConfiguration configuration);
Ejemplo n.º 16
0
        public void paint(Canvas canvas, Rect rect, Path clipPath, ImageConfiguration configuration)
        {
            D.assert(canvas != null);
            D.assert(rect != null);
            D.assert(configuration != null);

            bool flipHorizontally = false;

            if (_details.matchTextDirection)
            {
                D.assert(() => {
                    // We check this first so that the assert will fire immediately, not just
                    // when the image is ready.
                    if (configuration.textDirection == null)
                    {
                        throw new UIWidgetsError(new List <DiagnosticsNode>()
                        {
                            new ErrorSummary(
                                "DecorationImage.matchTextDirection can only be used when a TextDirection is available."),
                            new ErrorDescription(
                                "When DecorationImagePainter.paint() was called, there was no text direction provided " +
                                "in the ImageConfiguration object to match."
                                ),
                            new DiagnosticsProperty <DecorationImage>("The DecorationImage was", _details,
                                                                      style: DiagnosticsTreeStyle.errorProperty),
                            new DiagnosticsProperty <ImageConfiguration>("The ImageConfiguration was", configuration,
                                                                         style: DiagnosticsTreeStyle.errorProperty)
                        });
                    }

                    return(true);
                });
                if (configuration.textDirection == TextDirection.rtl)
                {
                    flipHorizontally = true;
                }
            }

            ImageStream newImageStream = _details.image.resolve(configuration);

            if (newImageStream.key != _imageStream?.key)
            {
                ImageStreamListener listener = new ImageStreamListener(
                    _handleImage,
                    onError: _details.onError
                    );
                _imageStream?.removeListener(listener);
                _imageStream = newImageStream;
                _imageStream.addListener(listener);
            }

            if (_image == null)
            {
                return;
            }

            if (clipPath != null)
            {
                canvas.save();
                canvas.clipPath(clipPath);
            }

            painting_.paintImage(
                canvas: canvas,
                rect: rect,
                image: _image.image,
                scale: _image.scale,
                colorFilter: _details.colorFilter,
                fit: _details.fit,
                alignment: _details.alignment.resolve(configuration.textDirection),
                centerSlice: _details.centerSlice,
                repeat: _details.repeat,
                flipHorizontally: flipHorizontally,
                filterQuality: FilterQuality.low
                );

            if (clipPath != null)
            {
                canvas.restore();
            }
        }
Ejemplo n.º 17
0
 public AssetImageConfiguration(ImageConfiguration configuration, string assetName)
 {
     this.configuration = configuration;
     this.assetName     = assetName;
 }
Ejemplo n.º 18
0
 public abstract void paint(Canvas canvas, Offset offset, ImageConfiguration configuration);
Ejemplo n.º 19
0
 public override Future <FileImage> obtainKey(ImageConfiguration configuration)
 {
     return(new SynchronousFuture <FileImage>(this));
 }
Ejemplo n.º 20
0
 public override Future <MemoryImage> obtainKey(ImageConfiguration configuration)
 {
     return(new SynchronousFuture <MemoryImage>(this));
     //Future.value(FutureOr.value(this)).to<MemoryImage>();
 }