Наследование: IDrawingState
Пример #1
0
        /**
            Create a drawing target from an already existing RenderTarget.

            Note that the RenderTarget must use the the same Factory the
            drawing backend does.
        **/
        public IDrawingTarget CreateDrawingTarget(RenderTarget renderTarget)
        {
            var width = renderTarget.Size.Width;
            var height = renderTarget.Size.Height;

            var state = new DrawingState();
            var transform = new DrawingTransform();
            var drawingTarget = new DrawingTarget(state, transform, renderTarget, (int)Math.Floor(width), (int)Math.Floor(height));

            var target = new DrawingTargetSplitter(
                this,
                state,
                transform,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                () =>
                {
                    drawingTarget.Dispose();
                });

            var pixelAligner = PixelAligningDrawingTarget.Create(target, target.Dispose, state, transform);
            return pixelAligner;
        }
Пример #2
0
        PixelAligningDrawingTarget(IDrawingTarget target, DrawingState state, DrawingTransform transform)
        {
            _target    = target;
            _state     = state;
            _transform = transform;

            _transform.Changed += transformChanged;

            transformChanged();
        }
        PixelAligningDrawingTarget(IDrawingTarget target, DrawingState state, DrawingTransform transform)
        {
            _target = target;
            _state = state;
            _transform = transform;

            _transform.Changed += transformChanged;

            transformChanged();
        }
Пример #4
0
        // Fill bounds of a stroke aligned rect that gets drawed stroke + filled

        public static Bounds StrokeFillBounds(this DrawingState state, Rectangle r)
        {
            if (!state.StrokeEnabled)
            {
                return(new Bounds(r.X, r.Y, r.Right, r.Bottom));
            }

            var fs = StrokeFillShift(state);

            return(new Bounds(r.X + fs, r.Y + fs, r.Right - fs, r.Bottom - fs));
        }
Пример #5
0
        public void RestoreState()
        {
            var p = _previous_;

            if (p == null)
            {
                throw new Exception("No Previous State found");
            }

            Copy(p, this);
            _previous_ = p._previous_;
        }
Пример #6
0
        public DrawingTarget(DrawingState state, DrawingTransform transform, RenderTarget target, int width, int height)
        {
            _state = state;
            _transform = transform;

            _target = target;
            _target.AntialiasMode = AntialiasMode.PerPrimitive;

            Width = width;
            Height = height;

            _strokeBrush = new BrushCache(createBrush, () => _state.StrokeColor);
            _fillBrush = new BrushCache(createBrush, () => state.FillColor);
            _textBrush = new BrushCache(createBrush, () => state.TextColor);

            _transform.Changed += transformChanged;
        }
Пример #7
0
        public static double StrokeFillShift(this DrawingState state)
        {
            var width = state.StrokeWeight;

            switch (state.StrokeAlignment)
            {
            case StrokeAlignment.Center:
                return(width / 2);

            case StrokeAlignment.Inside:
                return(width);

            case StrokeAlignment.Outside:
                return(0);
            }

            Debug.Assert(false);
            return(0);
        }
Пример #8
0
        public static IDrawingTarget Create(IDrawingTarget target, Action disposer, DrawingState state, DrawingTransform transform)
        {
            var pixelAligner = new PixelAligningDrawingTarget(target, state, transform);

            return(new DrawingTargetSplitter
                   (
                       target.Backend,
                       state,
                       transform,
                       pixelAligner,
                       pixelAligner,
                       target,
                       target,
                       target, () =>
            {
                pixelAligner.Dispose();
                disposer();
            }
                   ));
        }
        public static IDrawingTarget Create(IDrawingTarget target, Action disposer, DrawingState state, DrawingTransform transform)
        {
            var pixelAligner = new PixelAligningDrawingTarget(target, state, transform);

            return new DrawingTargetSplitter
                (
                    target.Backend,
                    state,
                    transform,
                    pixelAligner,
                    pixelAligner,
                    target,
                    target,
                    target, () =>
                        {
                            pixelAligner.Dispose();
                            disposer();
                        }
                    );
        }
Пример #10
0
        public static void Copy(DrawingState @from, DrawingState to)
        {
            to.FillEnabled = @from.FillEnabled;
            to.FillColor   = @from.FillColor;

            to.StrokeEnabled   = @from.StrokeEnabled;
            to.StrokeWeight    = @from.StrokeWeight;
            to.StrokeAlignment = @from.StrokeAlignment;

            to.FontName   = @from.FontName;
            to.FontWeight = @from.FontWeight;
            to.FontStyle  = @from.FontStyle;

            to.TextSize      = @from.TextSize;
            to.TextColor     = @from.TextColor;
            to.TextAlignment = @from.TextAlignment;

            to.ParagraphAlignment = @from.ParagraphAlignment;
            to.WordWrapping       = @from.WordWrapping;

            to.PixelAligned = @from.PixelAligned;
        }
Пример #11
0
        public IDrawingTarget BeginDraw(Color? clearColor)
        {
            #if NETFX_CORE
            var surface = _texture.QueryInterface<Surface>();
            #else
            var surface = _texture.AsSurface();
            #endif

            var rtProperties = new RenderTargetProperties
            {
                DpiX = 96,
                DpiY = 96,
                Type = RenderTargetType.Default,
                PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
            };

            var renderTarget = new RenderTarget(_factory, surface, rtProperties);

            renderTarget.BeginDraw();
            // required to clear the render target
            // not required on all machines, seems to be a driver decision.
            renderTarget.Clear(clearColor != null ? clearColor.Value.import() : (Color4?)null);

            var state = new DrawingState();
            var transform = new DrawingTransform();
            var drawingTarget = new DrawingTarget(state, transform, renderTarget, _width, _height);

            var target = new DrawingTargetSplitter(
                _backend,
                state,
                transform,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                drawingTarget,
                () =>
                    {
                        drawingTarget.Dispose();

                        renderTarget.EndDraw();
                        renderTarget.Dispose();
                        surface.Dispose();
                    });

            var pixelAligner = PixelAligningDrawingTarget.Create(target, target.Dispose, state, transform);
            return pixelAligner;
        }
Пример #12
0
        public void RestoreState()
        {
            var p = _previous_;
            if (p == null)
                throw new Exception("No Previous State found");

            Copy(p, this);
            _previous_ = p._previous_;
        }
Пример #13
0
        public static void Copy(DrawingState @from, DrawingState to)
        {
            to.FillEnabled = @from.FillEnabled;
            to.FillColor = @from.FillColor;

            to.StrokeEnabled = @from.StrokeEnabled;
            to.StrokeWeight = @from.StrokeWeight;
            to.StrokeAlignment = @from.StrokeAlignment;

            to.FontName = @from.FontName;
            to.FontWeight = @from.FontWeight;
            to.FontStyle = @from.FontStyle;

            to.TextSize = @from.TextSize;
            to.TextColor = @from.TextColor;
            to.TextAlignment = @from.TextAlignment;

            to.ParagraphAlignment = @from.ParagraphAlignment;
            to.WordWrapping = @from.WordWrapping;

            to.PixelAligned = @from.PixelAligned;
        }
Пример #14
0
        public static Bounds StrokeAlignedBounds(this DrawingState state, Rectangle rectangle)
        {
            var strokeShift = StrokeAlignShift(state);

            return(new Bounds(rectangle.X + strokeShift, rectangle.Y + strokeShift, rectangle.Right - strokeShift, rectangle.Bottom - strokeShift));
        }
Пример #15
0
 public void SaveState()
 {
     var clone = Clone();
     _previous_ = clone;
 }
Пример #16
0
        public void SaveState()
        {
            var clone = Clone();

            _previous_ = clone;
        }
Пример #17
0
 public BoundsTracker(DrawingState state, DrawingTransform transform)
 {
     State     = state;
     Transform = transform;
 }
Пример #18
0
 public BoundsTracker(DrawingState state, DrawingTransform transform)
 {
     State = state;
     Transform = transform;
 }