Пример #1
0
        private void BDirectX_Load(object sender, EventArgs e)
        {
            this.ShowInTaskbar = false;

            this.Width  = 1280;
            this.Height = 1024;
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);

            HwndRenderTargetProperties renderProperties = new HwndRenderTargetProperties()
            {
                Hwnd           = this.Handle,
                PixelSize      = new Size2(1280, 1024),
                PresentOptions = PresentOptions.None
            };

            Factory factory = new Factory();

            device = new WindowRenderTarget(factory, new RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)), renderProperties);
            DrawingInit();

            Thread BDirectX = new Thread(new ParameterizedThreadStart(ThreadDirectX));

            BDirectX.Priority     = ThreadPriority.Highest;
            BDirectX.IsBackground = true;
            BDirectX.Start();
        }
Пример #2
0
 public CustomTextRenderer(Direct2DFactory factory, WindowRenderTarget renderTarget, SolidColorBrush outlineBrush, BitmapBrush fillBrush)
 {
     _factory      = factory;
     _renderTarget = renderTarget;
     _outlineBrush = outlineBrush;
     _fillBrush    = fillBrush;
 }
Пример #3
0
        private SharpDX.Direct2D1.Bitmap SDXBitmapFromSysBitmap(WindowRenderTarget device, System.Drawing.Bitmap bitmap)
        {
            var sourceArea       = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
            var bitmapProperties = new BitmapProperties(new PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied));
            var size             = new Size2(bitmap.Width, bitmap.Height);

            // Transform pixels from BGRA to RGBA
            int stride = bitmap.Width * sizeof(int);

            using (var tempStream = new DataStream(bitmap.Height * stride, true, true))
            {
                // Lock System.Drawing.Bitmap
                var bitmapData = bitmap.LockBits(sourceArea, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                // Convert all pixels
                for (int y = 0; y < bitmap.Height; y++)
                {
                    int offset = bitmapData.Stride * y;
                    for (int x = 0; x < bitmap.Width; x++)
                    {
                        // Not optimized
                        byte B    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte G    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte R    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte A    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        int  rgba = R | (G << 8) | (B << 16) | (A << 24);
                        tempStream.Write(rgba);
                    }
                }
                bitmap.UnlockBits(bitmapData);
                tempStream.Position = 0;

                return(new SharpDX.Direct2D1.Bitmap(device, size, tempStream, stride, bitmapProperties));
            }
        }
Пример #4
0
        private void DrawW2SBox(WindowRenderTarget device, Color color, Vector3 bottomCenter, float width, float height, float degreeRotation, float strokeWidth = 1f)
        {
            Vector3[] pointsBottom = Geometry.Create3DFlatBox(bottomCenter, width, degreeRotation);
            Vector3[] pointsUpper  =
                Geometry.OffsetVectors(
                    Vector3.UnitZ * height,
                    Geometry.CopyVectors(pointsBottom)
                    );

            Vector2[] pointsBottom2D = Geometry.WorldToScreen(csgo.ViewMatrix, csgo.ScreenSize, pointsBottom);
            Vector2[] pointsUpper2D  = Geometry.WorldToScreen(csgo.ViewMatrix, csgo.ScreenSize, pointsUpper);

            foreach (Vector2 pnt in pointsBottom2D)
            {
                if (pnt == Vector2.Zero)
                {
                    return;
                }
            }
            foreach (Vector2 pnt in pointsUpper2D)
            {
                if (pnt == Vector2.Zero)
                {
                    return;
                }
            }
            this.DrawLines(device, color, strokeWidth, pointsBottom2D);
            this.DrawLines(device, color, strokeWidth, pointsUpper2D);
            this.ConnectLines(device, color, strokeWidth, pointsBottom2D, pointsUpper2D);
        }
Пример #5
0
        public static void Init()
        {
            _Factory = new SharpDX.Direct2D1.Factory();

            var renderTargetProperties = new RenderTargetProperties()
            {
                PixelFormat = new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Ignore)
            };
            var hwndRenderTargetProperties = new HwndRenderTargetProperties()
            {
                Hwnd           = Memory.FindWindow(null, "Steam"),
                PixelSize      = new Size2(1920, 1080),
                PresentOptions = PresentOptions.RetainContents,
            };

            //Memory.FindWindow(null, "Steam")

            _textFormat   = new TextFormat(new SharpDX.DirectWrite.Factory(), "Segoe UI", 15);
            _renderTarget = new WindowRenderTarget(_Factory, renderTargetProperties, hwndRenderTargetProperties);
            _LineBrush    = new SolidColorBrush(_renderTarget, new RawColor4(255, 0, 0, 1f));
            _LineBrush2   = new SolidColorBrush(_renderTarget, new RawColor4(0, 255, 0, 1f));

            /*_renderTarget.BeginDraw();
             * _renderTarget.Clear(null);
             * _renderTarget.DrawLine(new RawVector2(960, 0), new RawVector2(960, 540), brush, 3);
             * _renderTarget.EndDraw();*/
        }
Пример #6
0
 protected override void OnRender(WindowRenderTarget renderTarget)
 {
     if (_textLayout != null)
     {
         renderTarget.DrawTextLayout(new PointF(), _textLayout, _blackBrush, DrawTextOptions.None);
     }
 }
Пример #7
0
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);
            this._blackBrush       = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1));
            this._yellowGreenBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(0x9ACD32, 1));

            GradientStop[] stops = new GradientStop[] {
                new GradientStop(0, Color.FromARGB(Colors.Yellow, 1)),
                new GradientStop(1, Color.FromARGB(Colors.ForestGreen, 1))
            };

            using (GradientStopCollection collection = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp))
            {
                this._linearGradientBrush = renderTarget.CreateLinearGradientBrush(
                    new LinearGradientBrushProperties(new PointF(0, 0), new PointF(150, 150)),
                    BrushProperties.Default,
                    collection);
                this._radialGradientBrush = renderTarget.CreateRadialGradientBrush(
                    new RadialGradientBrushProperties(new PointF(75, 75), new PointF(0, 0), 75, 75),
                    BrushProperties.Default,
                    collection);
            }

            using (Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "fern.jpg"))
            {
                this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap,
                                                                   new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.Linear),
                                                                   BrushProperties.Default);
            }

            this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f));
        }
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);

            _blackBrush     = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1));
            _customRenderer = new CustomTextRendererWithEffects(Direct2DFactory, renderTarget, _blackBrush);
        }
Пример #9
0
        // INIT
        private void DrawWindow_Load(object sender, EventArgs e)
        {
            this.TopMost         = true;
            this.Visible         = true;
            this.FormBorderStyle = FormBorderStyle.None;
            //this.WindowState = FormWindowState.Maximized;
            this.Width  = rect.Width;
            this.Height = rect.Height;

            // Window name
            this.Name = Process.GetCurrentProcess().ProcessName + "~Overlay";
            this.Text = Process.GetCurrentProcess().ProcessName + "~Overlay";

            // Init factory
            factory     = new Factory();
            fontFactory = new FontFactory();

            // Render settings
            renderProperties = new HwndRenderTargetProperties()
            {
                Hwnd           = this.Handle,
                PixelSize      = new Size2(rect.Width, rect.Height),
                PresentOptions = PresentOptions.None
            };

            // Init device
            device = new WindowRenderTarget(factory, new RenderTargetProperties(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)), renderProperties);

            // Init brush
            solidColorBrush = new SolidColorBrush(device, Color.White);

            // Init font's
            font      = new TextFormat(fontFactory, fontFamily, fontSize);
            fontSmall = new TextFormat(fontFactory, fontFamily, fontSizeSmall);

            // Open process
            RPM.OpenProcess(process.Id);

            // Init player array
            players     = new List <Player>();
            localPlayer = new Player();

            // Init update thread
            updateStream = new Thread(new ParameterizedThreadStart(Update));
            updateStream.Start();

            // Init window thread (resize / position)
            windowStream = new Thread(new ParameterizedThreadStart(SetWindow));
            windowStream.Start();

            // Init Key Listener
            manager = new KeysManager();
            manager.AddKey(Keys.F5);
            manager.AddKey(Keys.F6);
            manager.AddKey(Keys.F7);
            manager.AddKey(Keys.F8);
            manager.AddKey(Keys.F9);
            //manager.KeyUpEvent += new KeysManager.KeyHandler(KeyUpEvent);
            manager.KeyDownEvent += new KeysManager.KeyHandler(KeyDownEvent);
        }
Пример #10
0
        public void Draw(IList <Element> elements, GameTime gameTime)
        {
            var context = _renderContext;

            lock (_sizeLock) {
                if (_isSizeChanged)
                {
                    foreach (var element in elements)
                    {
                        element.OnLostContext(context);
                    }
                    _renderTarget.Dispose();
                    _hwndRenderTargetProperties.PixelSize = _newSize;
                    _renderTarget = new WindowRenderTarget(_factory, _renderTargetProperties, _hwndRenderTargetProperties);
                    context       = _renderContext = new RenderContext(this, _renderTarget, new Size(_newSize.Width, _newSize.Height));
                    foreach (var element in elements)
                    {
                        element.OnGotContext(context);
                    }
                    _isSizeChanged = false;
                }
            }

            context.BeginDraw();
            foreach (var element in elements)
            {
                element.Draw(gameTime, context);
            }
            context.EndDraw();
        }
Пример #11
0
 public static bool Init()
 {
     try {
         factory     = new Factory(FactoryType.SingleThreaded);
         renderProps = new RenderTargetProperties()
         {
             PixelFormat = new PixelFormat {
                 AlphaMode = AlphaMode.Ignore, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm
             },
             Usage = RenderTargetUsage.None,
             Type  = RenderTargetType.Default
         };
         hwndProps = new HwndRenderTargetProperties()
         {
             Hwnd           = Program.main.MainPanel.Handle,
             PixelSize      = new Size2(Program.main.MainPanel.Width, Program.main.MainPanel.Height),
             PresentOptions = PresentOptions.None
         };
         renderTarget = new WindowRenderTarget(factory, renderProps, hwndProps)
         {
             AntialiasMode = AntialiasMode.PerPrimitive,
             DotsPerInch   = new Size2F(96, 96)
         };
         bkgndPen        = new SolidColorBrush(renderTarget, new RawColor4(0.3f, 0.3f, 0.3f, 1.0f));
         selectRectBrush = new SolidColorBrush(renderTarget, new RawColor4(0x00 / 256.0f, 0x97 / 256.0f, 0xA7 / 256.0f, 0.5f));
         selectRectPen   = new SolidColorBrush(renderTarget, new RawColor4(0x1A / 256.0f, 0x23 / 256.0f, 0x7E / 256.0f, 1));
         selectCellPen   = new SolidColorBrush(renderTarget, new RawColor4(0x1B / 256.0f, 0x5E / 256.0f, 0x20 / 256.0f, 1));
         copyBrush       = new SolidColorBrush(renderTarget, new RawColor4(0x66 / 256.0f, 0xBB / 256.0f, 0x6A / 256.0f, 0.5f));
         copyPen         = selectRectPen;
         bkgndGeometry   = new PathGeometry(factory);
     } catch { return(false); }
     return(true);
 }
Пример #12
0
 public CustomTextRenderer(Direct2DFactory factory, WindowRenderTarget renderTarget, SolidColorBrush outlineBrush, BitmapBrush fillBrush)
 {
     _factory = factory;
     _renderTarget = renderTarget;
     _outlineBrush = outlineBrush;
     _fillBrush = fillBrush;
 }
Пример #13
0
        private void LoadOverlay(object sender, EventArgs e)
        {
            DoubleBuffered = true;
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |
                     ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);

            _factory          = new Factory();
            _renderProperties = new HwndRenderTargetProperties
            {
                Hwnd           = Handle,
                PixelSize      = new SharpDX.Size2(Size.Width, Size.Height),
                PresentOptions = PresentOptions.None
            };

            marg.Left   = 0;
            marg.Top    = 0;
            marg.Right  = this.Width;
            marg.Bottom = this.Height;

            DwmExtendFrameIntoClientArea(this.Handle, ref marg);
            // Initialize DirectX
            _device = new WindowRenderTarget(_factory, new RenderTargetProperties(new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)), _renderProperties);

            _threadDx = new Thread(new ParameterizedThreadStart(DirectXThread))
            {
                Priority     = ThreadPriority.Highest,
                IsBackground = true
            };

            _running     = true;
            this.TopMost = true;
            _threadDx.Start();
        }
Пример #14
0
 protected virtual void OnCreateDeviceResources(WindowRenderTarget renderTarget)
 {
     if (CreateDeviceResources != null)
     {
         CreateDeviceResources(this, new RenderTargetEventArgs(renderTarget));
     }
 }
Пример #15
0
        /// <summary>
        /// 初始化<see cref="Sence" />的新实例.
        /// </summary>
        /// <param name="id">标识</param>
        /// <param name="control">渲染的目标控件</param>
        protected Sence(string id = "", [MustNotEqualNull] Control control = null)
            : base(id)
        {
            Control = control;

            Direct2D1Factory = new SharpDX.Direct2D1.Factory();

            SurfaceRenderTarget = new WindowRenderTarget(Direct2D1Factory,
                                                         new RenderTargetProperties
                                                         (
                                                             //此处必须为B8G8R8A8格式,否则至少Win7不支持
                                                             new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Ignore)
                                                         ),
                                                         new HwndRenderTargetProperties
            {
                Hwnd           = Control.Handle,
                PixelSize      = new Size2(Control.Width, Control.Height),
                PresentOptions = PresentOptions.None,
            })
            {
                AntialiasMode = AntialiasMode.PerPrimitive
            };

            DirectWriteFactory = new SharpDX.DirectWrite.Factory();
        }
Пример #16
0
 private void CreateDeviceIndependentResources()
 {
     this._factory      = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None);
     this._renderTarget = this._factory.CreateWindowRenderTarget(this);
     OnCreateDeviceIndependentResources(this._factory);
     this._deviceIndependedResourcesCreated = true;
 }
Пример #17
0
        public TileGameWindow(string title, int width, int height, bool fullscreen)
            : base(title, width, height, fullscreen)
        {
            this.m_Factory = new Factory();

            RenderTargetProperties rtProperties = new RenderTargetProperties
            {
                PixelFormat = new SlimDXPixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)
            };

            WindowRenderTargetProperties properties = new WindowRenderTargetProperties
            {
                Handle    = FormObject.Handle,
                PixelSize = new Size(width, height)
            };

            this.m_RenderTarget = new WindowRenderTarget(this.m_Factory, rtProperties, properties);

            this.m_DebugBrush = new SolidColorBrush(this.m_RenderTarget, new Color4(1.0f, 1.0f, 1.0f, 0.0f));

            this.m_PlayerSprites = LoadBitmap(Application.StartupPath + "\\Robot.png");
            this.m_Player        = new Player
            {
                PositionX = 4,
                PositionY = 8
            };

            this.InitalizeTileGameWorld();
        }
Пример #18
0
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);
            // Create an array of gradient stops to put in the gradient stop
            // collection that will be used in the gradient brush.
            GradientStop[] stops = new GradientStop[] {
                new GradientStop(0, Color.FromKnown(Colors.Gold, 1)),
                new GradientStop(0.85f, Color.FromKnown(Colors.Orange, 1)),
                new GradientStop(1, Color.FromKnown(Colors.OrangeRed, 1))
            };

            using (GradientStopCollection gradiendStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp))
            {
                // The center of the gradient is in the center of the box.
                // The gradient origin offset was set to zero(0, 0) or center in this case.
                _radialGradientBrush = renderTarget.CreateRadialGradientBrush(
                    new RadialGradientBrushProperties(
                        new PointF(330, 330),
                        new PointF(140, 140),
                        140,
                        140),
                    BrushProperties.Default,
                    gradiendStops);
            }

            _sceneBrush       = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1));
            _gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromRGB(0.93f, 0.94f, 0.96f));
        }
Пример #19
0
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);

            float width  = ClientSize.Width / _dpiScaleX;
            float height = ClientSize.Height / _dpiScaleY;

            this._textLayout = DirectWriteFactory.CreateTextLayout(
                _text,
                this._textFormat,
                width,
                height);

            using (Typography typography = DirectWriteFactory.CreateTypography())
            {
                typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1);
                this._textLayout.SetTypography(typography, new TextRange(0, _text.Length));
            }

            Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "heart.png");

            this._bitmapInlineObject = new BitmapInlineObject(RenderTarget, bitmap);

            this._textLayout.SetInlineObject(this._bitmapInlineObject, new TextRange(2, 1));

            this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1));
        }
Пример #20
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Direct2DRenderer" /> class.
        /// </summary>
        /// <param name="hwnd">The HWND.</param>
        /// <param name="limitFps">if set to <c>true</c> [limit FPS].</param>
        public Direct2DRenderer(IntPtr hwnd, bool limitFps)
        {
            _factory = new SharpDX.Direct2D1.Factory();

            _fontFactory = new Factory();

            Native.Rect bounds;
            Native.GetWindowRect(hwnd, out bounds);

            var targetProperties = new HwndRenderTargetProperties
            {
                Hwnd           = hwnd,
                PixelSize      = new Size2(bounds.Right - bounds.Left, bounds.Bottom - bounds.Top),
                PresentOptions = limitFps ? PresentOptions.None : PresentOptions.Immediately
            };

            var prop = new RenderTargetProperties(RenderTargetType.Hardware,
                                                  new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied), 0, 0, RenderTargetUsage.None,
                                                  FeatureLevel.Level_DEFAULT);

            _device = new WindowRenderTarget(_factory, prop, targetProperties)
            {
                TextAntialiasMode = TextAntialiasMode.Aliased,
                AntialiasMode     = AntialiasMode.Aliased
            };
        }
Пример #21
0
        public Direct2DRenderer(IntPtr hwnd, bool limitFps)
        {
            _factory = new Factory();

            _fontFactory = new FontFactory();

            RECT bounds;//immer 1920x1080. resizing muss durch die Overlay klasse geregelt sein

            NativeMethods.GetWindowRect(hwnd, out bounds);

            var targetProperties = new HwndRenderTargetProperties
            {
                Hwnd           = hwnd,
                PixelSize      = new Size2(bounds.Right - bounds.Left, bounds.Bottom - bounds.Top),
                PresentOptions = limitFps ? PresentOptions.None : PresentOptions.Immediately //Immediatly -> Zeichnet sofort ohne auf 60fps zu locken. None lockt auf 60fps
            };

            var prop = new RenderTargetProperties(RenderTargetType.Hardware, new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied), 0, 0, RenderTargetUsage.None, FeatureLevel.Level_DEFAULT);

            _device = new WindowRenderTarget(_factory, prop, targetProperties)
            {
                TextAntialiasMode = TextAntialiasMode.Cleartype,
                AntialiasMode     = AntialiasMode.PerPrimitive
            };
        }
Пример #22
0
        private void LoadOverlay(object sender, EventArgs e)
        {
            DoubleBuffered = true;
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |
                     ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);

            _factory          = new Factory();
            _fontFactory      = new FontFactory();
            _renderProperties = new HwndRenderTargetProperties
            {
                Hwnd           = Handle,
                PixelSize      = new SharpDX.Size2(Size.Width, Size.Height),
                PresentOptions = PresentOptions.None
            };

            // Initialize DirectX
            _device          = new WindowRenderTarget(_factory, new RenderTargetProperties(new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)), _renderProperties);
            _solidColorBrush = new SolidColorBrush(_device, new RawColor4(Color.White.R, Color.White.G, Color.White.B, Color.White.A));

            _boxBrush = new SolidColorBrush(_device, new RawColor4(255, 0, 0, 0.5f));

            // Initialize Fonts
            _font      = new TextFormat(_fontFactory, _fontFamily, _fontSize);
            _fontSmall = new TextFormat(_fontFactory, _fontFamily, _fontSizeSmall);

            _threadDx = new Thread(new ParameterizedThreadStart(DirectXThread))
            {
                Priority     = ThreadPriority.Highest,
                IsBackground = true
            };

            _running = true;
            _threadDx.Start();
        }
Пример #23
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            RectF bounds = new RectF(new PointF(), renderTarget.Size);

            renderTarget.FillRect(_gridPatternBrush, bounds);

            RectF brushRect = new RectF(0, 0, 150, 150);
            RectF textRect  = new RectF(0, 165, 150, 35);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(5.5f, 5.5f));
            renderTarget.FillRect(_yellowGreenBrush, brushRect);
            renderTarget.DrawRect(_blackBrush, 1, brushRect);
            renderTarget.DrawText("SolidColorBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(200.5f, 5.5f));
            renderTarget.FillRect(_linearGradientBrush, brushRect);
            renderTarget.DrawRect(_blackBrush, 1, brushRect);
            renderTarget.DrawText("LinearGradientBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(5.5f, 200.5f));
            renderTarget.FillEllipse(_radialGradientBrush, new Ellipse(brushRect));
            renderTarget.DrawEllipse(_blackBrush, 1, new Ellipse(brushRect));
            renderTarget.DrawText("RadialGradientBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(200.5f, 200.5f));
            renderTarget.FillRect(_bitmapBrush, brushRect);
            renderTarget.DrawRect(_blackBrush, 1, brushRect);
            renderTarget.DrawText("BitmapBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);
        }
Пример #24
0
        public override void Init()
        {
            // create Direct2D1 Factory
            factory = new Factory();

            //Set Rendering properties
            RenderTargetProperties renderProp = new RenderTargetProperties()
            {
                PixelFormat = new PixelFormat(SharpDX.DXGI.Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
            };

            //set hwnd target properties (permit to attach Direct2D to window)
            HwndRenderTargetProperties winProp = new HwndRenderTargetProperties()
            {
                Hwnd           = UIForm.Handle,
                PixelSize      = new Size2(Width, Height),
                PresentOptions = PresentOptions.None
            };

            //target creation
            DrawTarget = new WindowRenderTarget(factory, renderProp, winProp);

            // create Bitmap
            BitmapBuffer = new SharpDX.Direct2D1.Bitmap(DrawTarget, new Size2(Width, Height), new BitmapProperties(DrawTarget.PixelFormat));

            //Start to draw
            DrawTarget.BeginDraw();
            DrawTarget.Clear(new SharpDX.Mathematics.Interop.RawColor4(0f, 0f, 0f, 1f));
            DrawTarget.EndDraw();

            // init events
            UIForm.KeyDown    += new KeyEventHandler(EventsKeyboardDown);
            UIForm.KeyUp      += new KeyEventHandler(EventsKeyboardUp);
            UIForm.FormClosed += new FormClosedEventHandler(EventsQuit);
        }
Пример #25
0
        public void Dispose()
        {
            foreach (var grad in verticalGradientCache.Values)
            {
                grad.Dispose();
            }
            verticalGradientCache.Clear();

            if (renderTarget != null)
            {
                renderTarget.Dispose();
                renderTarget = null;
            }

            if (directWriteFactory != null)
            {
                directWriteFactory.Dispose();
                directWriteFactory = null;
            }

            if (factory != null)
            {
                factory.Dispose();
                factory = null;
            }
        }
Пример #26
0
        private void LoadOverlay(object sender, EventArgs e)
        {
            this.DoubleBuffered = true;
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.ResizeRedraw | ControlStyles.Opaque | ControlStyles.UserPaint, true);
            this._factory     = new SharpDX.Direct2D1.Factory();
            this._fontFactory = new SharpDX.DirectWrite.Factory();
            HwndRenderTargetProperties properties = new HwndRenderTargetProperties
            {
                Hwnd           = base.Handle,
                PixelSize      = new Size2(base.Size.Width, base.Size.Height),
                PresentOptions = PresentOptions.None
            };

            this._renderProperties = properties;
            this._device           = new WindowRenderTarget(this._factory, new RenderTargetProperties(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)), this._renderProperties);
            this._brush            = new SolidColorBrush(this._device, new RawColor4((float)Color.Red.R, (float)Color.Red.G, (float)Color.Red.B, (float)Color.Red.A));
            this._font             = new TextFormat(this._fontFactory, "Verdana", FontWeight.Bold, FontStyle.Normal, 12f);
            this._fontSmall        = new TextFormat(this._fontFactory, "Verdana", FontWeight.Bold, FontStyle.Normal, 10f);
            Console.WriteLine("Starting Maler Thread");
            Thread thread1 = new Thread(new ParameterizedThreadStart(this.DirectXThread))
            {
                Priority     = ThreadPriority.Highest,
                IsBackground = true
            };

            this._threadDx = thread1;
            this._running  = true;
            this._threadDx.Start();
        }
Пример #27
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            RectF bounds = new RectF(new PointF(), renderTarget.Size);

            renderTarget.FillRect(_gridPatternBrush, bounds);

            renderTarget.FillGeometry(_radialGradientBrush, _sunGeometry);

            _sceneBrush.Color = Color.FromKnown(Colors.Black, 1);
            renderTarget.DrawGeometry(_sceneBrush, 1, _sunGeometry);

            _sceneBrush.Color = Color.FromKnown(Colors.OliveDrab, 1);
            renderTarget.FillGeometry(_sceneBrush, _leftMountainGeometry);

            _sceneBrush.Color = Color.FromKnown(Colors.Black, 1);
            renderTarget.DrawGeometry(_sceneBrush, 1, _leftMountainGeometry);

            _sceneBrush.Color = Color.FromKnown(Colors.LightSkyBlue, 1);
            renderTarget.FillGeometry(_sceneBrush, _riverGeometry);

            _sceneBrush.Color = Color.FromKnown(Colors.Black, 1);
            renderTarget.DrawGeometry(_sceneBrush, 1, _riverGeometry);

            _sceneBrush.Color = Color.FromKnown(Colors.YellowGreen, 1);
            renderTarget.FillGeometry(_sceneBrush, _rightMountainGeometry);

            _sceneBrush.Color = Color.FromKnown(Colors.Black, 1);
            renderTarget.DrawGeometry(_sceneBrush, 1, _rightMountainGeometry);
        }
Пример #28
0
 private void CleanUpDeviceIndependentResources()
 {
     if (this._deviceIndependedResourcesCreated)
     {
         OnCleanUpDeviceIndependentResources();
     }
     if (this._imagingFactory != null)
     {
         this._imagingFactory.Dispose();
         this._imagingFactory = null;
     }
     if (this._directWriteFactory != null)
     {
         this._directWriteFactory.Dispose();
         this._directWriteFactory = null;
     }
     if (this._renderTarget != null)
     {
         this._renderTarget.Dispose();
         this._renderTarget = null;
     }
     if (this._factory != null)
     {
         this._factory.Dispose();
         this._factory = null;
     }
 }
Пример #29
0
 /// <summary>
 /// .The Main Drawing Thread for DirectX. Pretty much a delegate, passes rendering into the current form/menu.
 /// </summary>
 /// <param name="DirectX_Graphics_Window">Window that you are drawing upon.</param>
 static void Draw_DirectX(WindowRenderTarget DirectX_Graphics_Window)
 {
     if (Draw_Current_Menu && (Current_Menu != null))
     {
         Current_Menu.Render_This_Menu(DirectX_Graphics_Window);
     }
 }
Пример #30
0
 protected virtual void OnRender(WindowRenderTarget renderTarget)
 {
     if (Render != null)
     {
         Render(this, new RenderTargetEventArgs(renderTarget));
     }
 }
Пример #31
0
        public void D3DInit()
        {
            RenderTargetProperties renderProp = new RenderTargetProperties()
            {
                DpiX        = 0,
                DpiY        = 0,
                MinLevel    = FeatureLevel.Level_10,
                PixelFormat = new PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied),
                Type        = RenderTargetType.Hardware,
                Usage       = RenderTargetUsage.None
            };

            //set hwnd target properties (permit to attach Direct2D to window)
            HwndRenderTargetProperties winProp = new HwndRenderTargetProperties()
            {
                Hwnd           = handle,
                PixelSize      = new Size2(this.ClientSize.Width, this.ClientSize.Height),
                PresentOptions = PresentOptions.Immediately
            };

            //target creation
            target = new WindowRenderTarget(Global.Instance.factory2D1, renderProp, winProp);

            fpsCounter = new SharpFPS();
            fpsCounter.Reset();
            dsp = new DisplayUpdate();

            initialized = true;
        }
Пример #32
0
 protected override void OnRender(WindowRenderTarget renderTarget)
 {
     string text = "Hello World using  DirectWrite!";
     renderTarget.DrawText(text, this._textFormat,
         new RectF(0, 0, ClientSize.Width, ClientSize.Height),
         _blackBrush,
         DrawTextOptions.None, MeasuringMode.Natural);
 }
Пример #33
0
        public BitmapInlineObject(WindowRenderTarget renderer, Bitmap bitmap)
        {
            this._renderer = renderer;
            this._bitmap = bitmap;
            SizeF size = this._bitmap.Size;

            this.metrics = new InlineObjectMetrics(size.Width, size.Height, size.Height * 2 / 3, false);
        }
Пример #34
0
 void MainWindow_Load(object sender, EventArgs e)
 {
     this._factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None);
     StrokeStyleProperties ssp = new StrokeStyleProperties(LineCapStyle.Round, LineCapStyle.Round,
         LineCapStyle.Round, LineJoin.Round, 10, DashStyle.Solid, 0);
     this._strokeStyle = this._factory.CreateStrokeStyle(ssp, null);
     this._renderTarget = this._factory.CreateWindowRenderTarget(this);
     this.Resize += new EventHandler(MainWindow_Resize);
 }
        void D2Lines_Shown(object sender, EventArgs e)
        {
            this.d2factory = new Factory(FactoryType.SingleThreaded, DebugLevel.None);
            this.d2target = new WindowRenderTarget(this.d2factory, new WindowRenderTargetProperties {
                Handle = this.Handle,
                PixelSize = this.ClientSize,
            });

            this.Resize += delegate { this.d2target.Resize(this.ClientSize); };
            this.Paint += new PaintEventHandler(D2Lines_Paint);
        }
Пример #36
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceContext2D"/> class.
        /// </summary>
        /// <param name="handle">The window handle to associate with the device.</param>
        /// <param name="settings">The settings used to configure the device.</param>
        public DeviceContext2D(IntPtr handle, DeviceSettings2D settings) {
            if (handle == IntPtr.Zero)
                throw new ArgumentException("Value must be a valid window handle.", "handle");
            if (settings == null)
                throw new ArgumentNullException("settings");

            this.settings = settings;

            factory = new Factory();
            RenderTarget = new WindowRenderTarget(factory, new WindowRenderTargetProperties {
                Handle = handle,
                PixelSize = new Size(settings.Width, settings.Height)
            });
        }
Пример #37
0
        public ProgressUpdate(WindowRenderTarget rt1) {
            _rt = rt1;
            _brush = new SolidColorBrush(_rt, Color.Green);
            _clearColor = new SolidColorBrush(_rt, Color.Black);

            _borderBounds = new Rectangle(18, rt1.PixelSize.Height / 2 - 2, rt1.PixelSize.Width - 36, 24);
            _barBounds = new Rectangle(20, rt1.PixelSize.Height / 2, rt1.PixelSize.Width - 40, 20);

            _factory = new Factory(FactoryType.Isolated);
            _txtFormat = new TextFormat(_factory, "Arial", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 18, "en-us") {
                TextAlignment = TextAlignment.Center
            };
            _textRect = new Rectangle(100, rt1.PixelSize.Height / 2 - 25, _rt.PixelSize.Width - 200, 20);
        }
Пример #38
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            RectF bounds = new RectF(new PointF(), renderTarget.Size);
            renderTarget.FillRect(_gridPatternBrush, bounds);

            RectF brushRect = new RectF(0, 0, 150, 150);
            RectF textRect = new RectF(0, 165, 150, 35);
            renderTarget.Transform = Matrix3x2.Translation(new SizeF(5.5f, 5.5f));
            renderTarget.FillRect(_yellowGreenBrush, brushRect);
            renderTarget.DrawRect(_blackBrush, 1, brushRect);
            renderTarget.DrawText("SolidColorBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(200.5f, 5.5f));
            renderTarget.FillRect(_linearGradientBrush, brushRect);
            renderTarget.DrawRect(_blackBrush, 1, brushRect);
            renderTarget.DrawText("LinearGradientBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(5.5f, 200.5f));
            renderTarget.FillEllipse(_radialGradientBrush, new Ellipse(brushRect));
            renderTarget.DrawEllipse(_blackBrush, 1, new Ellipse(brushRect));
            renderTarget.DrawText("RadialGradientBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(200.5f, 200.5f));
            renderTarget.FillRect(_bitmapBrush, brushRect);
            renderTarget.DrawRect(_blackBrush, 1, brushRect);
            renderTarget.DrawText("BitmapBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);
        }
 public CustomTextRendererWithEffects(Direct2DFactory factory, WindowRenderTarget renderTarget, SolidColorBrush defaultBrush)
 {
     _factory = factory;
     _renderTarget = renderTarget;
     _defaultBrush = defaultBrush;
 }
Пример #40
0
 private void CleanUpDeviceIndependentResources()
 {
     if(this._deviceIndependedResourcesCreated)
         OnCleanUpDeviceIndependentResources();
     if (this._imagingFactory != null)
     {
         this._imagingFactory.Dispose();
         this._imagingFactory = null;
     }
     if (this._directWriteFactory != null)
     {
         this._directWriteFactory.Dispose();
         this._directWriteFactory = null;
     }
     if (this._renderTarget != null)
     {
         this._renderTarget.Dispose();
         this._renderTarget = null;
     }
     if (this._factory != null)
     {
         this._factory.Dispose();
         this._factory = null;
     }
 }
Пример #41
0
 protected virtual void OnCreateDeviceResources(WindowRenderTarget renderTarget)
 {
 }
Пример #42
0
        void MainWindow_Load(object sender, EventArgs e)
        {
            DirectWriteFactory f = DirectWriteFactory.Create(DirectWriteFactoryType.Shared);
            _textFormat = f.CreateTextFormat("Verdana", null, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 110, null);
            _textFormat.ParagraphAlignment = ParagraphAlignment.Far;
            _textFormat.TextAlignment = TextAlignment.Center;

            this.ClientSize = new System.Drawing.Size(600, 600);
            this._factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None);

            this._renderTarget = this._factory.CreateWindowRenderTarget(this, PresentOptions.None, RenderTargetProperties.Default);
            AntialiasMode amode = this._renderTarget.AntialiasMode;
            TextAntialiasMode tamode = this._renderTarget.TextAntialiasMode;
            this._strokeBrush = this._renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Cyan, 1));
            this._strokeStyle = this._factory.CreateStrokeStyle(new StrokeStyleProperties(LineCapStyle.Flat,
                LineCapStyle.Flat, LineCapStyle.Round, LineJoin.Miter, 10, DashStyle.Dot, 0), null);

            this.Resize += new EventHandler(MainWindow_Resize);
        }
Пример #43
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            RectF bounds = new RectF(new PointF(), renderTarget.Size);
            renderTarget.FillRect(_gridPatternBrush, bounds);

            renderTarget.FillGeometry(this._radialGradientBrush, this._sunGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.Black, 1);
            renderTarget.DrawGeometry(this._sceneBrush, 1, _sunGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.OliveDrab, 1);
            renderTarget.FillGeometry(this._sceneBrush, this._leftMountainGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.Black, 1);
            renderTarget.DrawGeometry(this._sceneBrush, 1, this._leftMountainGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.LightSkyBlue, 1);
            renderTarget.FillGeometry(this._sceneBrush, this._riverGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.Black, 1);
            renderTarget.DrawGeometry(this._sceneBrush, 1, this._riverGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.YellowGreen, 1);
            renderTarget.FillGeometry(this._sceneBrush, this._rightMountainGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.Black, 1);
            renderTarget.DrawGeometry(this._sceneBrush, 1, this._rightMountainGeometry);
        }
 protected override void OnRender(WindowRenderTarget renderTarget)
 {
     PointF origin = new PointF(0, 0);
     this._textLayout.Draw(this._customRenderer, origin.X, origin.Y);
 }
Пример #45
0
        public void Using_DirectWrite()
        {
            Device device;
            SwapChain swapChain;
            RenderTargetView renderTarget;

            EmptyWindow.CreateDeviceSwapChainAndRenderTarget(mForm, out device, out swapChain, out renderTarget);

            var direct2dfactory = new Direct2DFactory();
            var directWriteFactory = new DirectWriteFactory();

            var properties = new WindowRenderTargetProperties { Handle = mForm.Handle, PixelSize = mForm.ClientSize };
            var windowRenderTarget = new WindowRenderTarget(direct2dfactory, properties);
            var brush = new SolidColorBrush(windowRenderTarget, Color.Black);

            var textFormat = new TextFormat(directWriteFactory, "Gabriola",
                FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 72.0f, "en-us")
            {
                TextAlignment = TextAlignment.Center,
                ParagraphAlignment = ParagraphAlignment.Center
            };

            Application.Idle +=
                delegate
                {
                    device.ClearRenderTargetView(renderTarget, new Color4(1, 0, 0));

                    if (!windowRenderTarget.IsOccluded)
                    {
                        windowRenderTarget.BeginDraw();
                        windowRenderTarget.Transform = Matrix3x2.Identity;
                        windowRenderTarget.Clear(Color.White);

                        windowRenderTarget.DrawText("Hello World using DirectWrite!", textFormat, mForm.ClientRectangle, brush);

                        windowRenderTarget.EndDraw();
                    }

                    swapChain.Present(0, PresentFlags.None);

                    Application.DoEvents();
                };

            Application.Run(mForm);
        }
Пример #46
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            RectF bounds = new RectF(new PointF(), renderTarget.Size);
            renderTarget.FillRect(_gridPatternBrush, bounds);

            // Draw the geomtries before merging.
            renderTarget.FillGeometry(this._shapeFillBrush, this._circleGeometry1);
            renderTarget.DrawGeometry(this._outlineBrush, 1, _circleGeometry1);
            renderTarget.FillGeometry(this._shapeFillBrush, this._circleGeometry2);
            renderTarget.DrawGeometry(this._outlineBrush, 1, _circleGeometry2);

            renderTarget.DrawText(
                "The circles before combining",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(200, 0);

            // Draw the geometries merged using the union combine mode.
            renderTarget.FillGeometry(this._shapeFillBrush, this._geometryUnion);
            renderTarget.DrawGeometry(this._outlineBrush, 1, this._geometryUnion);

            renderTarget.DrawText(
                "CombineMode.Union",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(400, 0);

            // Draw the geometries merged using the intersect combine mode.
            renderTarget.FillGeometry(this._shapeFillBrush, this._geometryIntersect);
            renderTarget.DrawGeometry(this._outlineBrush, 1, this._geometryIntersect);

            renderTarget.DrawText(
                "CombineMode.Intersect",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(200, 150);

            // Draw the geometries merged using the XOR combine mode.
            renderTarget.FillGeometry(this._shapeFillBrush, this._geometryXor);
            renderTarget.DrawGeometry(this._outlineBrush, 1, this._geometryXor);

            renderTarget.DrawText(
                "CombineMode.Xor",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(400, 150);

            // Draw the geometries merged using the Exclude combine mode.
            renderTarget.FillGeometry(this._shapeFillBrush, this._geometryExclude);
            renderTarget.DrawGeometry(this._outlineBrush, 1, this._geometryExclude);

            renderTarget.DrawText(
                "CombineMode.Exclude",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            //// The following code demonstrates how to call various geometric operations. Depending on
            //// your needs, it lets you decide how to use those output values.
            //D2D1_GEOMETRY_RELATION result = D2D1_GEOMETRY_RELATION_UNKNOWN;

            //// Compare circle1 with circle2
            //hr = m_pCircleGeometry1->CompareWithGeometry(
            //    m_pCircleGeometry2,
            //    D2D1::IdentityMatrix(),
            //    0.1f,
            //    &result
            //    );

            //if (SUCCEEDED(hr))
            //{
            //    static const WCHAR szGeometryRelation[] = L"Two circles overlap.";
            //    renderTarget.SetTransform(D2D1::IdentityMatrix());
            //    if (result == D2D1_GEOMETRY_RELATION_OVERLAP)
            //    {
            //        renderTarget.DrawText(
            //            szGeometryRelation,
            //            ARRAYSIZE(szGeometryRelation) - 1,
            //            m_pTextFormat,
            //            D2D1::RectF(25.0f, 160.0f, 200.0f, 300.0f),
            //            m_pTextBrush
            //            );
            //    }
            //}

            //float area;

            //// Compute the area of circle1
            //hr = m_pCircleGeometry1->ComputeArea(
            //    D2D1::IdentityMatrix(),
            //    &area
            //    );

            //float length;

            //// Compute the area of circle1
            //hr = m_pCircleGeometry1->ComputeLength(
            //    D2D1::IdentityMatrix(),
            //    &length
            //    );

            //if (SUCCEEDED(hr))
            //{
            //    // Process the length of the geometry.
            //}

            //D2D1_POINT_2F point;
            //D2D1_POINT_2F tangent;

            //hr = m_pCircleGeometry1->ComputePointAtLength(
            //    10,
            //    NULL,
            //    &point,
            //    &tangent);

            //if (SUCCEEDED(hr))
            //{
            //    // Retrieve the point and tangent point.
            //}

            //D2D1_RECT_F bounds;

            //hr = m_pCircleGeometry1->GetBounds(
            //      D2D1::IdentityMatrix(),
            //      &bounds
            //     );

            //if (SUCCEEDED(hr))
            //{
            //    // Retrieve the bounds.
            //}

            //D2D1_RECT_F bounds1;
            //hr = m_pCircleGeometry1->GetWidenedBounds(
            //      5.0,
            //      m_pStrokeStyle,
            //      D2D1::IdentityMatrix(),
            //      &bounds1
            //     );
            //if (SUCCEEDED(hr))
            //{
            //    // Retrieve the widened bounds.
            //}

            //BOOL containsPoint;

            //hr = m_pCircleGeometry1->StrokeContainsPoint(
            //    D2D1::Point2F(0,0),
            //    10,     // stroke width
            //    NULL,   // stroke style
            //    NULL,   // world transform
            //    &containsPoint
            //    );

            //if (SUCCEEDED(hr))
            //{
            //    // Process containsPoint.
            //}

            //BOOL containsPoint1;
            //hr = m_pCircleGeometry1->FillContainsPoint(
            //    D2D1::Point2F(0,0),
            //    D2D1::Matrix3x2F::Identity(),
            //    &containsPoint1
            //    );
        }
Пример #47
0
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);

            this._outlineBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.DarkSlateBlue, 1), 1);
            this._shapeFillBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.CornflowerBlue, 1), 0.5f);
            this._textFillBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1), 1);
            this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f));
        }
Пример #48
0
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);
            this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1));
            this._yellowGreenBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(0x9ACD32, 1));

            GradientStop[] stops = new GradientStop[] {
                new GradientStop(0, Color.FromARGB(Colors.Yellow, 1)),
                new GradientStop(1, Color.FromARGB(Colors.ForestGreen, 1))
            };

            using (GradientStopCollection collection = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp))
            {
                this._linearGradientBrush = renderTarget.CreateLinearGradientBrush(
                    new LinearGradientBrushProperties(new PointF(0, 0), new PointF(150, 150)),
                    BrushProperties.Default,
                    collection);
                this._radialGradientBrush = renderTarget.CreateRadialGradientBrush(
                    new RadialGradientBrushProperties(new PointF(75, 75), new PointF(0, 0), 75, 75),
                    BrushProperties.Default,
                    collection);
            }

            using (Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "fern.jpg"))
            {
                this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap,
                    new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.Linear),
                    BrushProperties.Default);
            }

            this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f));
        }
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);

            this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1));
            this._customRenderer = new CustomTextRendererWithEffects(this.Direct2DFactory, renderTarget, this._blackBrush);
        }
Пример #50
0
 protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
 {
     base.OnCreateDeviceResources(renderTarget);
     this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1));
     using (Bitmap bitmap = renderTarget.CreateBitmap(this.GetType(), "flowers.jpg"))
     {
         this._bitmapBrush = renderTarget.CreateBitmapBrush(bitmap, new BitmapBrushProperties(ExtendMode.Wrap, ExtendMode.Wrap, BitmapInterpolationMode.NearestNeighbor), BrushProperties.Default);
     }
     _customRenderer = new CustomTextRenderer(this.Direct2DFactory, renderTarget, this._blackBrush, this._bitmapBrush);
 }
Пример #51
0
        protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
        {
            base.OnCreateDeviceResources(renderTarget);
            // Create an array of gradient stops to put in the gradient stop
            // collection that will be used in the gradient brush.
            GradientStop[] stops = new GradientStop[] {
                new GradientStop(0, Color.FromARGB(Colors.Gold, 1)),
                new GradientStop(0.85f, Color.FromARGB(Colors.Orange, 1)),
                new GradientStop(1, Color.FromARGB(Colors.OrangeRed, 1))
            };

            using (GradientStopCollection gradiendStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Gamma22, ExtendMode.Clamp))
            {
                // The center of the gradient is in the center of the box.
                // The gradient origin offset was set to zero(0, 0) or center in this case.
                this._radialGradientBrush = renderTarget.CreateRadialGradientBrush(
                    new RadialGradientBrushProperties(
                        new PointF(330, 330),
                        new PointF(140, 140),
                        140,
                        140),
                        BrushProperties.Default,
                        gradiendStops);
            }

            this._sceneBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1));
            this._gridPatternBrush = renderTarget.CreateGridPatternBrush(new SizeF(10, 10), Color.FromARGB(1, 0.93f, 0.94f, 0.96f));
        }
 public IWindowRenderTarget CreateWindow()
 {
     var renderer = new WindowRenderTarget(_graphicsContext, _input);
     renderer.Initialize();
     return renderer;
 }
Пример #53
0
        private bool InitDirect2D()
        {
            try {
                var factory = new SlimDX.Direct2D.Factory(FactoryType.SingleThreaded);

                _dxWRT = new WindowRenderTarget(factory, new WindowRenderTargetProperties {
                    Handle = Window.Handle,
                    PixelSize = Window.ClientSize,
                    PresentOptions = PresentOptions.Immediately
                });
                Util.ReleaseCom(ref factory);
                _progressUpdate = new ProgressUpdate(_dxWRT);

            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                return false;
            }
            return true;
        }
Пример #54
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            float y = 0;

            for (int index = 0; index < this._paragraphs.Count; ++index)
            {
                using (TextFormat textFormat = DirectWriteFactory.CreateTextFormat(
                    this._paragraphs[index].FontFamily,
                    this._paragraphs[index].Weight,
                    this._paragraphs[index].FontSize * 96f / 72f))
                {

                    textFormat.TextAlignment = _paragraphs[index].TextAlignment;
                    LineSpacing lineSpacing = textFormat.LineSpacing;

                    if (_paragraphs[index].LineSpacing == 0)
                        textFormat.LineSpacing = LineSpacing.Default;
                    else
                        textFormat.LineSpacing = new LineSpacing(_paragraphs[index].LineSpacing);

                    float width = ClientSize.Width / DpiScaleX - (_marginLeft + _marginRight);

                    using (TextLayout textLayout = DirectWriteFactory.CreateTextLayout(
                        this._paragraphs[index].Text,
                        textFormat,
                        width,
                        0))
                    {

                        y += _paragraphs[index].SpaceBefore;

                        renderTarget.DrawTextLayout(
                            new PointF(_marginLeft, y),
                            textLayout,
                            _blackBrush,
                            DrawTextOptions.None);

                        TextMetrics metrics = textLayout.Metrics;

                        y += metrics.Height + _paragraphs[index].SpaceAfter;
                    }
                }
            }
        }
 private void CreateDeviceIndependentResources()
 {
     try {
         this._factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None);
         this._renderTarget = this._factory.CreateWindowRenderTarget(this);
         OnCreateDeviceIndependentResources(this._factory);
         this._deviceIndependedResourcesCreated = true;
     } catch (Exception ex) {
         Debug.WriteLine(ex.ToString());
         throw;
     }
 }
Пример #56
0
 protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget)
 {
     base.OnCreateDeviceResources(renderTarget);
     this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromARGB(Colors.Black, 1));
 }
Пример #57
0
 protected virtual void OnRender(WindowRenderTarget renderTarget)
 {
 }
        void MainWindow_Load(object sender, EventArgs e)
        {
            _factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None);
            _renderTarget = _factory.CreateWindowRenderTarget(pictArea);
            Resize += MainWindow_Resize;

            _frameTimer.Tick += (_, __) => Redraw();
        }
Пример #59
0
 private void CreateDeviceIndependentResources()
 {
     this._factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None);
     this._renderTarget = this._factory.CreateWindowRenderTarget(this);
     OnCreateDeviceIndependentResources(this._factory);
     this._deviceIndependedResourcesCreated = true;
 }
Пример #60
0
 protected override void OnRender(WindowRenderTarget renderTarget)
 {
     PointF origin = new PointF();
     renderTarget.DrawTextLayout(origin, this._textLayout, _blackBrush, DrawTextOptions.None);
 }