public override void Arrange <TRenderSize>(TRenderSize availableSpace,
                                                   IRenderContext renderContext)
        {
            if (!TryGetImage(availableSpace, out var img))
            {
                return;
            }

            ValueRectangle rect;

            if ((!availableSpace.Width.AreEqualEnough(img.Width) ||
                 !availableSpace.Height.AreEqualEnough(availableSpace.Height)) &&
                availableSpace.Height < img.Height)
            {
                var scale = availableSpace.Height / img.Height;
                rect = new ValueRectangle(ValuePoint2D.Empty,
                                          new ValueRenderSize(img.Width * scale, availableSpace.Height,
                                                              availableSpace.Offset));
                //availableSpace = new ValueRenderSize(img.Width * scale, availableSpace.Height,
                //        availableSpace.Offset);
            }
            else
            {
                rect = new ValueRectangle(ValuePoint2D.Empty, availableSpace);
            }

            renderContext.DrawImage(img, rect);
        }
Ejemplo n.º 2
0
        protected override void OnMeasure(Int32 widthMeasureSpec,
                                          Int32 heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            var w = MeasuredWidth;
            var h = MeasuredHeight;

            var sz = new ValueRenderSize(w, h);

            _measureContext.MeasureMainView(_view, sz, _viewState);

            _targetRect = new ValueRectangle(
                0, // X
                0, // Y
                sz.Width / _viewState.ZoomLevel,
                sz.Height / _viewState.ZoomLevel);
        }
Ejemplo n.º 3
0
        public void DrawString <TBrush, TPoint>(String text,
                                                TBrush brush,
                                                TPoint point2D)
            where TBrush : IBrush
            where TPoint : IPoint2D
        {
            if (_isCacheStaticLayouts)
            {
                var layout = GetOrCreateStaticLayout(text);
                DrawStringWithCachedLayout(brush, point2D.X, point2D.Y, layout);
                return;
            }

            var size = MeasureString(text);
            var test = new ValueRectangle(point2D, size.Width, size.Height);

            DrawStringInRect(text, brush, test);
        }
Ejemplo n.º 4
0
        protected override void OnMeasure(Int32 widthMeasureSpec,
                                          Int32 heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
            var w = MeasuredWidth;
            var h = MeasuredHeight;

            var sz = new ValueRenderSize(w, h);

            _targetRect = new ValueRectangle(
                0, // X
                0, // Y
                sz.Width / ZoomLevel,
                sz.Height / ZoomLevel);

            var count = ChildCount;

            for (var c = 0; c < count; c++)
            {
                var current = GetChildAt(c);

                if (current is IVisualSurrogate)
                {
                    current.Measure(Convert.ToInt32(_targetRect.Width),
                                    Convert.ToInt32(_targetRect.Height));
                }
                else
                {
                    current?.Measure(widthMeasureSpec, heightMeasureSpec);
                }
            }

            _measured = new ValueSize(sz.Width, sz.Height);
            RenderKit.MeasureContext.MeasureMainView(_view, sz, _viewState);

            if (_refreshLoopCount == 0)
            {
                _refreshLoopCount++;
                var _ = RefreshLoop();
            }
        }
        private void OnHostSizeChanged(ISize newValue)
        {
            lock (_lock)
            {
                if (newValue.IsEmpty)
                {
                    return;
                }

                _hostRect = new ValueRectangle(0, 0, newValue);

                _gdiDevice.UpdateSize(newValue);

                var view = _viewHost.View;
                if (view == null)
                {
                    return;
                }

                view.InvalidateMeasure();
            }
        }
        public BitmapRenderer(IViewHost <Bitmap> viewHost,
                              GdiMeasureContext measureContext,
                              GdiRenderContext renderContext,
                              Color backgroundColor)
        {
            _eventLock = new Object();

            _lock       = new Object();
            _viewHost   = viewHost;
            _visualHost = viewHost;

            _visualHost.AvailableSizeChanged += OnHostSizeChanged;

            _measureContext = measureContext;
            _renderContext  = renderContext;
            _layoutQueue    = measureContext.LayoutQueue;
            _gdiDevice      = new GdiDevice(backgroundColor,
                                            _viewHost.AvailableSize);

            _renderRect = new Rectangle(0, 0, 1, 1);

            _hostRect = new ValueRectangle(0, 0, viewHost.AvailableSize);
        }