예제 #1
0
        internal static void DrawLine(D2DEnviroment d2d, UIElement u)
        {
            Line l = u as Line;

            D2D1.Brush br;
            if (l.SurfaceBrush == null)
            {
                d2d.ColorBrush.Color = u.Forground;
                br = d2d.ColorBrush;
            }
            else
            {
                br = l.SurfaceBrush;
            }
            var render = d2d.d2dContext;

            render.Transform = Matrix3x2.Identity;
            if (l.Style == null)
            {
                render.DrawLine(l.Start, l.End, br, l.Storke);
            }
            else
            {
                render.DrawLine(l.Start, l.End, br, l.Storke, l.Style);
            }
        }
예제 #2
0
        internal static void DrawGeometry(D2DEnviroment d2d, UIElement u)
        {
            Geometry geo    = u as Geometry;
            var      render = d2d.d2dContext;

            if (u.Angle != 0)
            {
                render.Transform = geo.Matri;
            }
            else
            {
                render.Transform = Matrix3x2.Identity;
            }
            D2D1.Brush br;
            if (geo.SurfaceBrush == null)
            {
                d2d.ColorBrush.Color = geo.Forground;
                br = d2d.ColorBrush;
            }
            else
            {
                br = geo.SurfaceBrush;
            }
            render.DrawGeometry(geo.geometry, br);
            if (u.FillBrush != null)
            {
                render.FillGeometry(geo.geometry, u.FillBrush);
            }
            else if (u.FillImage != null)
            {
                if (u.FillImage.d2dmap == null)
                {
                    return;
                }
                if (d2d.ImgBrush == null)
                {
                    d2d.ImgBrush = new D2D1.ImageBrush(render, u.FillImage.d2dmap, new D2D1.ImageBrushProperties()
                    {
                        ExtendModeX       = D2D1.ExtendMode.Wrap,
                        ExtendModeY       = D2D1.ExtendMode.Wrap,
                        InterpolationMode = D2D1.InterpolationMode.HighQualityCubic
                    });
                }
                else
                {
                    d2d.ImgBrush.Image = u.FillImage.d2dmap;
                }
                var s = u.FillImage.Bitmap.Size;
                d2d.ImgBrush.SourceRectangle = new RawRectangleF(0, 0, s.Width, s.Height);
                render.FillGeometry(geo.geometry, d2d.ImgBrush);
            }
            else if (u.Background.A > 0)
            {
                d2d.ColorBrush.Color = u.Background;
                render.FillGeometry(geo.geometry, d2d.ColorBrush);
            }
        }
예제 #3
0
        void DrawMap(D2DEnviroment d2d, UIPanel port)
        {
            RawRectangleF rect;

            rect.Left   = port.Location.X;
            rect.Top    = port.Location.Y;
            rect.Right  = port.Size.Width + rect.Left;
            rect.Bottom = port.Size.Height + rect.Top;
            var d2dcontext = d2d.d2dContext;

            d2dcontext.Transform = Matrix3x2.Identity;
            d2dcontext.DrawBitmap(port.bitmap, rect, 1, D2D1.BitmapInterpolationMode.NearestNeighbor);
        }
예제 #4
0
        void DrawClipMap(D2DEnviroment d2d, UIPanel port)
        {
            RawRectangleF rect = port.Rect;
            RawRectangleF rc;

            rc.Left   = rect.Left + 3;
            rc.Right  = rect.Right - 3;
            rc.Top    = rect.Top + 3;
            rc.Bottom = rect.Bottom - 3;

            var d2dcontext = d2d.d2dContext;

            d2dcontext.Transform = Matrix3x2.Identity;
            d2dcontext.PushAxisAlignedClip(rc, D2D1.AntialiasMode.Aliased);
            d2dcontext.Clear(background);
            d2dcontext.DrawBitmap(port.bitmap, rect, 1, D2D1.BitmapInterpolationMode.NearestNeighbor);
            d2dcontext.PopAxisAlignedClip();
        }
예제 #5
0
        internal static void DrawImage(D2DEnviroment d2d, UIElement u)
        {
            UIImage img = u as UIImage;

            if (img.d2dmap == null)
            {
                return;
            }
            var render = d2d.d2dContext;

            if (u.Angle != 0)
            {
                render.Transform = u.Matri;
            }
            else
            {
                render.Transform = Matrix3x2.Identity;
            }
            render.DrawBitmap(img.d2dmap, img.Rect, img.opacity, D2D1.BitmapInterpolationMode.NearestNeighbor);
        }
예제 #6
0
        internal static void DrawText(D2DEnviroment d2d, UIElement u)
        {
            TextBlock tb = u as TextBlock;

            if (tb.Text == null)
            {
                return;
            }
            var render = d2d.d2dContext;

            if (u.Angle == 0)
            {
                render.Transform = Matrix3x2.Identity;
            }
            else
            {
                render.Transform = tb.Matri;
            }
            if (u.Background.A > 0)
            {
                d2d.ColorBrush.Color = u.Background;
                render.FillRectangle(u.Rect, d2d.ColorBrush);
            }
            D2D1.Brush br;
            if (tb.SurfaceBrush == null)
            {
                d2d.ColorBrush.Color = tb.Forground;
                br = d2d.ColorBrush;
            }
            else
            {
                br = tb.SurfaceBrush;
                (br as IGradientBrush).SetRect(tb.Rect);
            }
            TextFormat tf = TextBlock.GetFormat(tb.FontStyle, tb.FontSize);

            tf.WordWrapping  = tb.Warpping;
            tf.TextAlignment = tb.Alignment;
            render.DrawText(tb.Text, tf, u.Rect, br, (D2D1.DrawTextOptions) 2);
        }
        /// <summary>
        /// main thread
        /// </summary>
        public static void Initial()
        {
            D2D = new D2DEnviroment();
            using (var defaultDevice = new D3D11.Device(DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport, featureLevels))
            {
                D2D.d3dDevice = defaultDevice.QueryInterface <D3D11.Device>();
            }

            D2D.d3dContext = D2D.d3dDevice.ImmediateContext.QueryInterface <D3D11.DeviceContext>();
            // Create the Direct2D device.
            using (var dxgiDevice = D2D.d3dDevice.QueryInterface <Dxgi.Device>())
            {
                D2D.d2dDevice = new D2D1.Device(dxgiDevice, cp);
            }
            // Create Direct2D context
            D2D.d2dContext = new D2D1.DeviceContext(D2D.d2dDevice, D2D1.DeviceContextOptions.None);
            D2D.d3dContext.OutputMerger.SetTargets((D3D11.DepthStencilView)null,
                                                   (D3D11.RenderTargetView)null);
            D2D.d3dContext.Flush();

            D2D.ColorBrush = new D2D1.SolidColorBrush(D2D.d2dContext, new RawColor4(0, 0, 0, 0));
        }
예제 #8
0
        internal static void DrawEllipse(D2DEnviroment d2d, UIElement u)
        {
            Ellipse ell    = u as Ellipse;
            var     render = d2d.d2dContext;

            if (u.Angle != 0)
            {
                render.Transform = ell.Matri;
            }
            else
            {
                render.Transform = Matrix3x2.Identity;
            }
            D2D1.Brush br;
            if (u.SurfaceBrush == null)
            {
                d2d.ColorBrush.Color = ell.Forground;
                br = d2d.ColorBrush;
            }
            else
            {
                br = u.SurfaceBrush;
            }
            render.DrawEllipse(ell.ellipse, br, ell.Stroke);
            if (u.FillBrush != null)
            {
                RawRectangleF rect = new RawRectangleF();
                rect.Left   = ell.ellipse.Point.X - ell.ellipse.RadiusX;
                rect.Right  = ell.ellipse.Point.X + ell.ellipse.RadiusX;
                rect.Top    = ell.ellipse.Point.Y - ell.ellipse.RadiusY;
                rect.Bottom = ell.ellipse.Point.Y + ell.ellipse.RadiusY;
                (u.FillBrush as IGradientBrush).SetRect(rect);
                render.FillEllipse(ell.ellipse, u.FillBrush);
            }
            else if (u.FillImage != null)
            {
                if (u.FillImage.d2dmap == null)
                {
                    return;
                }
                if (d2d.ImgBrush == null)
                {
                    d2d.ImgBrush = new D2D1.ImageBrush(render, u.FillImage.d2dmap, new D2D1.ImageBrushProperties()
                    {
                        ExtendModeX       = D2D1.ExtendMode.Wrap,
                        ExtendModeY       = D2D1.ExtendMode.Wrap,
                        InterpolationMode = D2D1.InterpolationMode.HighQualityCubic
                    });
                }
                else
                {
                    d2d.ImgBrush.Image = u.FillImage.d2dmap;
                }
                var s = u.FillImage.Bitmap.Size;
                d2d.ImgBrush.SourceRectangle = new RawRectangleF(0, 0, s.Width, s.Height);
                render.FillEllipse(ell.ellipse, d2d.ImgBrush);
            }
            else if (u.Background.A > 0)
            {
                d2d.ColorBrush.Color = u.Background;
                render.FillEllipse(ell.ellipse, d2d.ColorBrush);
            }
        }
예제 #9
0
        internal static void DrawRoundRect(D2DEnviroment d2d, UIElement u)
        {
            RoundBorder bor = u as RoundBorder;

            D2D1.Brush br;
            if (bor.SurfaceBrush == null)
            {
                d2d.ColorBrush.Color = bor.Forground;
                br = d2d.ColorBrush;
            }
            else
            {
                br = bor.SurfaceBrush;
            }
            var render = d2d.d2dContext;

            if (u.Angle != 0)
            {
                render.Transform = bor.Matri;
            }
            else
            {
                render.Transform = Matrix3x2.Identity;
            }
            if (u.Forground.A > 0)
            {
                if (bor.Style == null)
                {
                    render.DrawRoundedRectangle(bor.RoundRect, br, bor.Stroke);
                }
                else
                {
                    render.DrawRoundedRectangle(bor.RoundRect, br, bor.Stroke, bor.Style);
                }
            }
            if (u.FillBrush != null)
            {
                (u.FillBrush as IGradientBrush).SetRect(bor.RoundRect.Rect);
                render.FillRoundedRectangle(bor.RoundRect, u.FillBrush);
            }
            else if (u.FillImage != null)
            {
                if (u.FillImage.d2dmap == null)
                {
                    return;
                }
                if (d2d.ImgBrush == null)
                {
                    d2d.ImgBrush = new D2D1.ImageBrush(render, u.FillImage.d2dmap, new D2D1.ImageBrushProperties()
                    {
                        ExtendModeX       = D2D1.ExtendMode.Wrap,
                        ExtendModeY       = D2D1.ExtendMode.Wrap,
                        InterpolationMode = D2D1.InterpolationMode.HighQualityCubic
                    });
                }
                else
                {
                    d2d.ImgBrush.Image = u.FillImage.d2dmap;
                }
                var s = u.FillImage.Bitmap.Size;
                d2d.ImgBrush.SourceRectangle = new RawRectangleF(0, 0, s.Width, s.Height);
                render.FillRoundedRectangle(bor.RoundRect, d2d.ImgBrush);
            }
            else if (u.Background.A > 0)
            {
                d2d.ColorBrush.Color = u.Background;
                render.FillRoundedRectangle(bor.RoundRect, d2d.ColorBrush);
            }
        }