public void DrawObject(string url, string mimeType, float x, float y, float width, float height)
        {
            if (_imageLoader == null)
            {
                return;
            }

            var transform = _transform;
            var tl        = transform.Apply(x, y);
            var br        = transform.Apply(x + width, y + height);
            var screenMin = new Graphics.Point(Math.Min(tl.X, br.X), Math.Min(tl.Y, br.Y));
            var screenMax = new Graphics.Point(Math.Max(tl.X, br.X), Math.Max(tl.Y, br.Y));

            var image = _imageLoader.getImage(url, mimeType);

            if (image == null)
            {
                // image is not ready yet...
                if (_fillColor.Color.A > 0)
                {
                    var rect = new Rect(x, y, width, height);
                    PushRenderStates();
                    _drawingContext.DrawRectangle(_fillColor, null, rect);
                    PopRenderStates();
                }
            }
            else
            {
                // draw the image
                var rect = new Rect(x, y, width, height);
                PushRenderStates();
                _drawingContext.DrawImage(image, rect);
                PopRenderStates();
            }
        }
        public void DrawObject(string url, string mimeType, float x, float y, float width, float height)
        {
            if (_imageLoader == null)
            {
                return;
            }

            var transform = _transform;
            var screenMin = transform.Apply(x, y);
            var screenMax = transform.Apply(x + width, y + height);

            var image = _imageLoader.getImage(url, mimeType,
                                              (url_, image_) =>
            {
                var renderer = _imageLoader.Editor.Renderer;
                var x_       = (int)Math.Floor(screenMin.X);
                var y_       = (int)Math.Floor(screenMin.Y);
                var width_   = (int)Math.Ceiling(screenMax.X) - x_;
                var height_  = (int)Math.Ceiling(screenMax.Y) - y_;
                _target.Invalidate(renderer, x_, y_, width_, height_, LayerType.LayerType_ALL);
            });

            if (image == null)
            {
                // image is not ready yet...
                if (_fillColor.Color.A > 0)
                {
                    var rect    = new Rect(x, y, width, height);
                    var clipped = PushRenderStates();
                    _drawingContext.DrawRectangle(_fillColor, null, rect);
                    PopRenderStates(clipped);
                }
            }
            else
            {
                // adjust rectangle so that the image gets fit into original rectangle
                float fx = width / (float)image.Width;
                float fy = height / (float)image.Height;

                if (fx > fy)
                {
                    float w = (float)(image.Width * fy);
                    x    += (width - w) / 2;
                    width = w;
                }
                else
                {
                    float h = (float)(image.Height * fx);
                    y     += (height - h) / 2;
                    height = h;
                }

                // draw the image
                var rect    = new Rect(x, y, width, height);
                var clipped = PushRenderStates();
                _drawingContext.DrawImage(image, rect);
                PopRenderStates(clipped);
            }
        }
        public void DrawObject(string url, string mimeType, float x, float y, float width, float height)
        {
            if (_imageLoader == null)
            {
                return;
            }

            var transform = _transform;
            var screenMin = transform.Apply(x, y);
            var screenMax = transform.Apply(x + width, y + height);

            var image = _imageLoader.getImage(url, mimeType,
                                              (url_, image_) =>
            {
                var renderer = _imageLoader.Editor.Renderer;
                var x_       = (int)Math.Floor(screenMin.X);
                var y_       = (int)Math.Floor(screenMin.Y);
                var width_   = (int)Math.Ceiling(screenMax.X) - x_;
                var height_  = (int)Math.Ceiling(screenMax.Y) - y_;
                _target.Invalidate(renderer, x_, y_, width_, height_, LayerType.LayerType_ALL);
            });

            if (image == null)
            {
                // image is not ready yet...
                if (_fillColor.A > 0)
                {
                    _session.FillRectangle(x, y, width, height, _fillColor);
                }
            }
            else
            {
                // adjust rectangle so that the image gets fit into original rectangle
                var   size = image.SizeInPixels;
                float fx   = width / (float)size.Width;
                float fy   = height / (float)size.Height;

                if (fx > fy)
                {
                    float w = (float)(size.Width) * fy;
                    x    += (width - w) / 2;
                    width = w;
                }
                else
                {
                    float h = (float)(size.Height) * fx;
                    y     += (height - h) / 2;
                    height = h;
                }

                // draw the image
                var rect = new Rect(x, y, width, height);
                _session.DrawImage(image, rect, new Rect(0, 0, size.Width, size.Height));
            }
        }
Exemplo n.º 4
0
        public void DrawObject(string url, string mimeType, float x, float y, float width, float height)
        {
            if (_imageLoader == null)
            {
                return;
            }

            var transform = _transform;
            var screenMin = transform.Apply(x, y);
            var screenMax = transform.Apply(x + width, y + height);

            var image = _imageLoader.getImage(url, mimeType);

            if (image == null)
            {
                // image is not ready yet...
                if (_fillColor.A > 0)
                {
                    _session.FillRectangle(x, y, width, height, _fillColor);
                }
            }
            else
            {
                // adjust rectangle so that the image gets fit into original rectangle
                var   size = image.SizeInPixels;
                float fx   = width / (float)size.Width;
                float fy   = height / (float)size.Height;

                if (fx > fy)
                {
                    float w = (float)(size.Width) * fy;
                    x    += (width - w) / 2;
                    width = w;
                }
                else
                {
                    float h = (float)(size.Height) * fx;
                    y     += (height - h) / 2;
                    height = h;
                }

                // draw the image
                var rect = new Rect(x, y, width, height);
                _session.DrawImage(image, rect, new Rect(0, 0, size.Width, size.Height));
            }
        }