示例#1
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, MacBook Air + Win7 seems to recycle old textures)
            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);
        }
示例#2
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;
        }