/// <summary>
        /// Конструктор
        /// </summary>
        /// <param name="BackBuffer">Буффер на который будем рисовать, наш холст</param>
        /// <param name="Width">Ширина области в которую будем рисовать</param>
        /// <param name="Height">Высота объласти в которую будем рисовать</param>
        public TextWirter(SharpDX.Direct3D11.Device2 device, SwapChain2 swapChain, Color color, float dpi = 96f, string font = "Calibri", int size = 14)
        {
#if DEBUG
            var debug = SharpDX.Direct2D1.DebugLevel.Error;
#else
            var debug = SharpDX.Direct2D1.DebugLevel.None;
#endif

            _Factory2D = new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.SingleThreaded, debug);
            using (var dxgiDevice = device.QueryInterface <SharpDX.DXGI.Device>())
            {
                d2dDevice = new SharpDX.Direct2D1.Device(_Factory2D, dxgiDevice);
            }
            _RenderTarget2D = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);

            BitmapProperties1 properties = new BitmapProperties1(
                new PixelFormat(
                    SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                    SharpDX.Direct2D1.AlphaMode.Premultiplied),
                dpi,
                dpi,
                BitmapOptions.Target | BitmapOptions.CannotDraw);
            Surface backBuffer = swapChain.GetBackBuffer <Surface>(0);
            d2dTarget        = new Bitmap1(_RenderTarget2D, backBuffer, properties);
            this.TextFont    = font;
            this.TextSize    = size;
            _FactoryDWrite   = new SharpDX.DirectWrite.Factory();
            _SceneColorBrush = new SolidColorBrush(_RenderTarget2D, color);
            InitTextFormat();
            _RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype;
        }
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="BackBuffer">Буффер на который будем рисовать, наш холст</param>
 /// <param name="Width">Ширина области в которую будем рисовать</param>
 /// <param name="Height">Высота объласти в которую будем рисовать</param>
 public TextWirter(SharpDX.Direct3D11.Texture2D BackBuffer, int Width, int Height)
 {
     this.TextFont = "Calibri";
     this.TextSize = 14;
     _width        = Width;
     _heght        = Height;
     _Factory2D    = new SharpDX.Direct2D1.Factory();
     using (var surface = BackBuffer.QueryInterface <Surface>())
     {
         _RenderTarget2D = new RenderTarget(
             _Factory2D,
             surface,
             new RenderTargetProperties(
                 new PixelFormat(
                     Format.R8G8B8A8_UNorm,
                     AlphaMode.Premultiplied)));
     }
     _RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;
     _FactoryDWrite   = new SharpDX.DirectWrite.Factory();
     _SceneColorBrush = new SolidColorBrush(_RenderTarget2D, Color.White);
     // Initialize a TextFormat
     InitTextFormat();
     _RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype;
     // Initialize a TextLayout
     // _TextLayout = new TextLayout(_FactoryDWrite, "SharpDX D2D1 - DWrite", _TextFormat, Width, Height);
 }
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="BackBuffer">Буффер на который будем рисовать, наш холст</param>
 /// <param name="Width">Ширина области в которую будем рисовать</param>
 /// <param name="Height">Высота объласти в которую будем рисовать</param>
 public TextWirter(SharpDX.Direct3D11.Texture2D BackBuffer, int Width, int Height)
 {
     _width = Width;
     _heght = Height;
     _sw    = new Stopwatch();
     _sw.Start();
     _Factory2D = new SharpDX.Direct2D1.Factory();
     using (var surface = BackBuffer.QueryInterface <Surface>())
     {
         _RenderTarget2D = new RenderTarget(_Factory2D, surface,
                                            new RenderTargetProperties(
                                                new PixelFormat(
                                                    Format.R8G8B8A8_UNorm,
                                                    AlphaMode.Premultiplied)));
     }
     _RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;
     _FactoryDWrite   = new SharpDX.DirectWrite.Factory();
     _SceneColorBrush = new SolidColorBrush(_RenderTarget2D, Color.White);
     // Initialize a TextFormat
     _TextFormat = new TextFormat(_FactoryDWrite, "Calibri", 14)
     {
         TextAlignment      = TextAlignment.Leading,
         ParagraphAlignment = ParagraphAlignment.Near
     };
     _RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype;
     // Initialize a TextLayout
     _TextLayout = new TextLayout(_FactoryDWrite, "SharpDX D2D1 - DWrite", _TextFormat, Width, Height);
 }
Esempio n. 4
0
            public Core()
            {
                using (var dxgiDevice =
                           ImageFramework.DirectX.Device.Get().Handle.QueryInterface <SharpDX.DXGI.Device>())
                {
#if DEBUG
                    var debugLevel = DebugLevel.Information;
#else
                    var debugLevel = DebugLevel.None;
#endif
                    var factory = new SharpDX.Direct2D1.Factory1(FactoryType.MultiThreaded, debugLevel);
                    Factory = factory;
                    Handle  = new SharpDX.Direct2D1.Device(factory, dxgiDevice);
                    Context = new SharpDX.Direct2D1.DeviceContext(Handle, DeviceContextOptions.None);
                }

                WriteFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared);

                RoundStroke = new StrokeStyle(Factory, new StrokeStyleProperties
                {
                    StartCap = CapStyle.Round,
                    EndCap   = CapStyle.Round
                });
                HardStroke = new StrokeStyle(Factory, new StrokeStyleProperties
                {
                    StartCap = CapStyle.Flat,
                    EndCap   = CapStyle.Flat
                });

                ImageFramework.DirectX.Device.Get().DeviceDispose += (sender, args) => Dispose();
            }
Esempio n. 5
0
        public Graphics()
        {
            RenderForm = new RenderForm("Apple & Cinnamon")
            {
                Width         = (int)(Screen.PrimaryScreen.Bounds.Width * ScreenSizeScale),
                Height        = (int)(Screen.PrimaryScreen.Bounds.Height * ScreenSizeScale),
                StartPosition = FormStartPosition.CenterScreen
            };

            Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new SwapChainDescription
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(RenderForm.ClientSize.Width, RenderForm.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = RenderForm.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            }, out var device, out var swapChain);

            Device    = device;
            SwapChain = swapChain;

            D2dFactory = new Factory();

            D2DeviceContext =
                new _d2d.DeviceContext3(
                    new _d2d.Device3(new Factory().QueryInterface <_d2d.Factory4>(),
                                     device.QueryInterface <_dxgi.Device>()), DeviceContextOptions.None);
            D2DeviceContext.Target = D2DeviceContext.CreateBitmapRenderTarget(swapChain);
            SpriteBatch            = new SpriteBatch(D2DeviceContext);

            SwapChain.GetParent <SharpDX.DXGI.Factory>().MakeWindowAssociation(RenderForm.Handle, WindowAssociationFlags.IgnoreAll);

            var backBuffer = FromSwapChain <Texture2D>(SwapChain, 0);

            RenderTargetView = new RenderTargetView(Device, backBuffer);
            RenderTarget2D   = new RenderTarget(D2dFactory, backBuffer.QueryInterface <Surface>(), new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            DepthStencilView = new DepthStencilView(Device, new Texture2D(Device, new Texture2DDescription
            {
                Format            = Format.D32_Float_S8X24_UInt,
                ArraySize         = 1,
                MipLevels         = 1,
                Width             = RenderForm.ClientSize.Width,
                Height            = RenderForm.ClientSize.Height,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.DepthStencil,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.None
            }));

            DirectWrite = new SharpDX.DirectWrite.Factory();



            Device.ImmediateContext.Rasterizer.SetViewport(new Viewport(0, 0, RenderForm.ClientSize.Width, RenderForm.ClientSize.Height, 0.0f, 1.0f));
        }
        protected override void InternalInitialize()
        {
            base.InternalInitialize();

            _factory2D     = new Factory();
            _factoryDWrite = new SharpDX.DirectWrite.Factory();

            using (var surface = BackBuffer.QueryInterface <Surface>())
            {
                _renderTarget2D = new RenderTarget(_factory2D, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            }
            _renderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;
        }
Esempio n. 7
0
        protected override void Initialize(Configuration configuration)
        {
            base.Initialize(configuration);
            Factory2D = new Factory();
            using (var surface = BackBuffer.QueryInterface <Surface>())
            {
                _renderTarget2D = new RenderTarget(Factory2D, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            }
            _renderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            SceneColorBrush = new SolidColorBrush(_renderTarget2D, Color.White);
        }
Esempio n. 8
0
        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            base.Initialize(demoConfiguration);
            Factory2D = new SharpDX.Direct2D1.Factory();
            using (var surface = BackBuffer.QueryInterface<Surface>())
            {
                RenderTarget2D = new RenderTarget(Factory2D, surface,
                                                  new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            }
            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.White);
        }
Esempio n. 9
0
        private void CreateD2DResources()
        {
            Factory2D     = new Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            HwndRenderTargetProperties properties = new HwndRenderTargetProperties();

            properties.Hwnd           = m_displayHandle;
            properties.PixelSize      = new SharpDX.Size2(1024, 768);
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);

            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;
        }
        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            base.Initialize(demoConfiguration);
            Factory2D = new SharpDX.Direct2D1.Factory();
            Surface surface = BackBuffer.QueryInterface <Surface>();

            RenderTarget2D = new RenderTarget(Factory2D, surface,
                                              new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));

            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            surface.Release();
            SceneColorBrush = new SolidColorBrush(RenderTarget2D, new Color4(1, 1, 1, 1));
        }
        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            Factory2D = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            HwndRenderTargetProperties properties = new HwndRenderTargetProperties();
            properties.Hwnd = DisplayHandle;
            properties.PixelSize = new System.Drawing.Size(demoConfiguration.Width, demoConfiguration.Height);
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);

            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, new Color4(1, 1, 1, 1));
        }
Esempio n. 12
0
        /// <summary>
        /// Inits the direct2D and direct write.
        /// </summary>
        private void InitDirect2DAndDirectWrite()
        {
            Factory2D     = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties();

            properties.Hwnd           = renderControl.Handle;
            properties.PixelSize      = new Size2(renderControl.ClientSize.Width, renderControl.ClientSize.Height);
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);
            RenderTarget2D.AntialiasMode     = AntialiasMode.PerPrimitive;
            RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype;

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.Black);
        }
Esempio n. 13
0
        protected virtual void Initialize2D()
        {
#if DEBUG
            Factory2D = new SharpDX.Direct2D1.Factory(FactoryType.SingleThreaded, DebugLevel.Information);
#else
            Factory2D = new SharpDX.Direct2D1.Factory(FactoryType.SingleThreaded);
#endif
            using (var surface = BackBuffer.QueryInterface <Surface>())
            {
                RenderTarget = new RenderTarget(Factory2D, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            }
            RenderTarget.AntialiasMode = AntialiasMode.PerPrimitive;

            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            SceneColorBrush = new SolidColorBrush(RenderTarget, Color.White);
        }
        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            Factory2D     = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            HwndRenderTargetProperties properties = new HwndRenderTargetProperties();

            properties.Hwnd           = DisplayHandle;
            properties.PixelSize      = new SharpDX.Size2(demoConfiguration.Width, demoConfiguration.Height);
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);

            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;


            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.White);
        }
        public SharpDxGraphicsManagerWrapper(Panel targetPanel, Action renderAction)
            : base(renderAction)
        {
            var Factory2D     = new SharpDX.Direct2D1.Factory();
            var FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties();

            properties.Hwnd           = targetPanel.Handle;
            properties.PixelSize      = new SharpDX.Size2(targetPanel.Width, targetPanel.Height);
            properties.PresentOptions = PresentOptions.None;

            _renderTarget = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);

            _renderTarget.AntialiasMode = AntialiasMode.PerPrimitive;

            _wrapper = new DxGraphicsWrapper(_renderTarget, FactoryDWrite, new ImagingFactory());
        }
            public DxGraphicsWrapper(WindowRenderTarget renderTarget2D, SharpDX.DirectWrite.Factory factory2D, ImagingFactory imagingFactory)
            {
                _renderTarget2D = renderTarget2D;
                _factory2D      = factory2D;
                _imagingFactory = imagingFactory;

                _solidColorBrushConverter = new ConverterAndCacher <SolidBrush, SolidColorBrush>(
                    brush => new SolidColorBrush(_renderTarget2D, new Color4(
                                                     red: ((float)brush.Color.R) / byte.MaxValue,
                                                     green: ((float)brush.Color.G) / byte.MaxValue,
                                                     blue: ((float)brush.Color.B) / byte.MaxValue,
                                                     alpha: 1
                                                     )
                                                 ));

                _textFormatConverterAndCacher = new ConverterAndCacher <Font, TextFormat>(
                    f => new TextFormat(_factory2D, f.FontFamily.Name, f.Size));
            }
Esempio n. 17
0
        /// <summary>
        /// Inits the direct2D and direct write.
        /// </summary>
        private void InitDirect2DAndDirectWrite()
        {
            Factory2D     = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties {
                Hwnd = Handle, PixelSize = ClientSize, PresentOptions = PresentOptions.None
            };

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(), properties)
            {
                AntialiasMode     = AntialiasMode.PerPrimitive,
                TextAntialiasMode = TextAntialiasMode.Cleartype
            };

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, new Color4(1, 0, 0, 0));

            CustomTextRenderer = new CustomTextRenderer(Factory2D, RenderTarget2D);
        }
Esempio n. 18
0
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                _currentFont = GetFont(fontName, fontSize);

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
                CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
            }
            else
            {
                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
            }

            return(_currentFont);
        }
Esempio n. 19
0
        protected override void Initialize(Configuration configuration)
        {
            Factory2D     = new Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties
            {
                Hwnd           = DisplayHandle,
                PixelSize      = new Size2(configuration.Width, configuration.Height),
                PresentOptions = PresentOptions.None
            };

            RenderTarget2D = new WindowRenderTarget(Factory2D,
                                                    new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties)
            {
                AntialiasMode = AntialiasMode.PerPrimitive
            };

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.White);
        }
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;

            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            FontCollection fontCollection;

            if (!_fontCollectionCache.TryGetValue(fontName, out fontCollection))
            {
                var ext = Path.GetExtension(fontName);

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    try
                    {
                        var fileFontLoader = new FileFontLoader(FactoryDWrite, fontName);
                        var fileFontCollection = new FontCollection(FactoryDWrite, fileFontLoader, fileFontLoader.Key);
                        _currentFontCollection = fileFontCollection;
                        fontFamily = _currentFontCollection.GetFontFamily(0);
                        var ffn = fontFamily.FamilyNames;
                        _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);

                        _fontCollectionCache.Add(fontName, fileFontCollection);
                        _currentFontCollection = fileFontCollection;
                    }
                    catch
                    {
                        _currentFont = GetFont(fontName, fontSize);
                        CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
                    }
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                }

            }
            else
            {
                fontFamily = fontCollection.GetFontFamily(0);

                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontCollection = fontCollection;
            }

            return _currentFont;
        }
Esempio n. 21
0
 public SharpDX.DirectWrite.TextLayout TextLayout(string szText, SharpDX.DirectWrite.Factory factory, SharpDX.DirectWrite.TextFormat font) => new SharpDX.DirectWrite.TextLayout(factory, szText, font, float.MaxValue, float.MaxValue);
Esempio n. 22
0
        public override void InitDevice()
        {
            Width  = 100;
            Height = 100;
            DriverType[] driverTypes = new DriverType[] {
                DriverType.Hardware,
                DriverType.Warp,
                DriverType.Reference,
            };

            DeviceCreationFlags deviceCreationFlags = DeviceCreationFlags.BgraSupport;

            if (IsDebugMode)
            {
                deviceCreationFlags |= DeviceCreationFlags.Debug;
            }

            FeatureLevel[] levels = new FeatureLevel[] {
                FeatureLevel.Level_11_0,
                FeatureLevel.Level_10_1,
                FeatureLevel.Level_10_0,
            };

            foreach (var driverType in driverTypes)
            {
                DeviceRef = new Device(driverType, deviceCreationFlags, levels);
                if (DeviceRef != null)
                {
                    CurrentDriverType = driverType;
                    break;
                }
            }

            DeviceRef.DebugName = "Interop Device";
            DeviceRef.ImmediateContext.DebugName = "Interop Context";

            CheckFeatures();

            ZBufferTextureDescription = new Texture2DDescription
            {
                Format            = Format.R32_Typeless,
                ArraySize         = 1,
                MipLevels         = 1,
                Width             = Width,
                Height            = Height,
                SampleDescription = new SampleDescription(MSamplesCount, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.DepthStencil | BindFlags.ShaderResource,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.None,
            };

            Factory2D                = new Factory(FactoryType.SingleThreaded, DebugLevel.Information);
            FactoryDWrite            = new SharpDX.DirectWrite.Factory();
            RenderTarget2DProperites = new RenderTargetProperties()
            {
                MinLevel = SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT,
                //PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
                PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied),
                Type        = RenderTargetType.Default,
                Usage       = RenderTargetUsage.None,
            };
        }
Esempio n. 23
0
        /// <summary>
        /// Initialize DirectX factories, swap chain and render targets.
        /// </summary>
        protected void InitGraphics()
        {
            var width  = Size.Width;
            var height = Size.Height;

            Factory2D          = new Factory();
            FactoryDirectWrite = new SharpDX.DirectWrite.Factory();

            var desc = new SwapChainDescription
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput | Usage.BackBuffer,
            };

            // use software driver if RDP or VirtualMachine
            _driverType = MM_System_Profiling.IsTerminalOrVirtual() ? DriverType.Warp : DriverType.Hardware;
            bool swapChainCreated = false;

            while (!swapChainCreated)
            {
                try
                {
                    Device.CreateWithSwapChain(_driverType, DeviceCreationFlags.BgraSupport, desc, out _device, out _swapChain);
                    MM_System_Interfaces.LogError("Initialized DirectX Driver: {0}", _driverType);
                    swapChainCreated = true;
                }
                catch (Exception ex)
                {
                    // downgrade driver and try again using outer while loop
                    if (_driverType == DriverType.Hardware)
                    {
                        _driverType = DriverType.Warp;
                    }
                    else if (_driverType == DriverType.Warp)
                    {
                        _driverType = DriverType.Software;
                    }
                    else
                    {
                        MM_System_Interfaces.LogError(ex);
                        throw new NotSupportedException("DirectX Rendering could not be initialized using hardware of software.", ex);
                    }
                }
            }

            Context = _device.ImmediateContext;

            // Ignore all windows events
            FactoryDxgi = _swapChain.GetParent <SharpDX.DXGI.Factory>();
            FactoryDxgi.MakeWindowAssociation(Handle, WindowAssociationFlags.IgnoreAll);

            // New RenderTargetView from the backbuffer
            _backBuffer                  = Resource.FromSwapChain <Texture2D>(_swapChain, 0);
            RenderTargetView             = new RenderTargetView(_device, _backBuffer);
            DxgiSurface                  = _backBuffer.QueryInterface <Surface>();
            RenderTarget2D               = new RenderTarget(Factory2D, DxgiSurface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
            RenderTarget2D.AntialiasMode = AntialiasMode;

            PresenterReady = true;
        }
Esempio n. 24
0
        public void DrawText(string szText, int x, int y, SharpDX.Direct2D1.Brush textColor, SharpDX.DirectWrite.Factory fontFactory, SharpDX.DirectWrite.TextFormat font)
        {
            var tempTextLayout = TextLayout(szText, fontFactory, font);

            device.DrawTextLayout(new RawVector2(x + 1, y), tempTextLayout, new SolidColorBrush(device, RGB(0, 0, 0)), DrawTextOptions.NoSnap);
            device.DrawTextLayout(new RawVector2(x - 1, y), tempTextLayout, new SolidColorBrush(device, RGB(0, 0, 0)), DrawTextOptions.NoSnap);
            device.DrawTextLayout(new RawVector2(x, y + 1), tempTextLayout, new SolidColorBrush(device, RGB(0, 0, 0)), DrawTextOptions.NoSnap);
            device.DrawTextLayout(new RawVector2(x, y - 1), tempTextLayout, new SolidColorBrush(device, RGB(0, 0, 0)), DrawTextOptions.NoSnap);
            device.DrawTextLayout(new RawVector2(x, y), tempTextLayout, textColor, DrawTextOptions.NoSnap);

            tempTextLayout.Dispose();
        }
Esempio n. 25
0
        private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        {

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();
                
                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                    //var contentPath = Path.Combine(appPath, CCApplication.SharedApplication.Content.RootDirectory);
                    //var fontPath = Path.Combine(contentPath, fontName);

                    //if (File.Exists(fontPath))
                    //{
                       // try
                        //{
                            //var fontFileReference = new FontCollection(
                            //_loadedFonts.AddFontFile(fontPath);

                    //        //fontFamily = _loadedFonts.Families[_loadedFonts.Families.Length - 1];

                    //        //_currentFont = new Font(fontFamily, fontSize);
                    //    }
                    //    catch
                    //    {
                    //        _currentFont = _defaultFont;
                    //    }
                    //}
                    //else
                    //{
                        _currentFont = _defaultFont;
                        _currentFontSizeEm = fontSize;
                        _currentDIP = ConvertPointSizeToDIP(fontSize);
                    //}
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                    _currentFontSizeEm = fontSize;
                    _currentDIP = ConvertPointSizeToDIP(fontSize);
                }

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP = ConvertPointSizeToDIP(fontSize);
            }
            fontName = _currentFont.FontFamily.FamilyNames.GetString(0); 
            textFormat = new TextFormat(FactoryDWrite, fontName, _currentDIP);
            
            GetKerningInfo(charset);

            return _currentFont.ToString();
        }
        /// <summary>
        /// Inits the direct2D and direct write.
        /// </summary>
        private void InitDirect2DAndDirectWrite()
        {
            Factory2D = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties {Hwnd = Handle, PixelSize = ClientSize, PresentOptions = PresentOptions.None};

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(), properties)
                                 {
                                     AntialiasMode = AntialiasMode.PerPrimitive,
                                     TextAntialiasMode = TextAntialiasMode.Cleartype
                                 };

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, new Color4(1, 0, 0, 0));

            CustomTextRenderer = new CustomTextRenderer(Factory2D, RenderTarget2D);
        }
Esempio n. 27
0
        private void Update(object sender)
        {
            var       brushWhite   = new SolidColorBrush(device, new RawColor4(1, 1, 1, 1));
            var       brushWhiteF  = new SolidColorBrush(device, new RawColor4(1, 1, 1, 0.6f));
            var       brushDarkRed = new SolidColorBrush(device, new RawColor4(0.62f, 0, 0, 0.6f));
            var       brushBlack   = new SolidColorBrush(device, new RawColor4(0, 0, 0, 1));
            var       brushBlackF  = new SolidColorBrush(device, new RawColor4(0, 0, 0, 0.6f));
            var       brushBlue    = new SolidColorBrush(device, new RawColor4(0.14f, 0.58f, 1, 1));
            var       brushOrange  = new SolidColorBrush(device, new RawColor4(1, 0.49f, 0, 1));
            var       brushGray    = new SolidColorBrush(device, new RawColor4(0.5f, 0.5f, 0.5f, 1));
            var       brushGrayF   = new SolidColorBrush(device, new RawColor4(0.3f, 0.3f, 0.3f, 1));
            var       brushLtGray  = new SolidColorBrush(device, new RawColor4(0.65f, 0.65f, 0.65f, 1));
            RawColor4 black        = new RawColor4(0, 0, 0, 1);
            RawColor4 white        = new RawColor4(1, 1, 1, 1);
            RawColor4 gray         = new RawColor4(0.3f, 0.3f, 0.3f, 1);
            var       brushGreen   = new SolidColorBrush(device, RawColorFromColor(Color.Green));
            var       brushRed     = new SolidColorBrush(device, RawColorFromColor(Color.Red));
            var       brushYellow  = new SolidColorBrush(device, RawColorFromColor(Color.Yellow));
            var       brushPurple  = new SolidColorBrush(device, RawColorFromColor(Color.Purple));

            var fontFactory = new SharpDX.DirectWrite.Factory();
            var font        = new SharpDX.DirectWrite.TextFormat(fontFactory, "Tahoma", 12);

            while (true)
            {
                device.BeginDraw();
                device.Clear(null);

                //Read local player info
                GetLocalInfo(G.PlayerList);
                GetWeaponInfo();

                //Get ViewMatrix
                viewMatrix = M.Read <ViewMatrix>(G.clientDLL + Offsets.dwViewMatrix);

                //Get Punch Angle
                VecPunch = M.Read <Vector3>(G.pLocalPlayer + Offsets.VecPunchAngle);

                //Generate screen coordinates for Recoil Crosshair
                GetRecoilCoords(out Vector2 RecoilCross);
                if (VecPunch.X != 0 || VecPunch.Y != 0)
                {
                    if (Config.visuals)
                    {
                        DrawMarker(RecoilCross.X, RecoilCross.Y, 10, brushRed);
                    }
                }

                //Reset Target list
                List <Player> Players = new List <Player>();

                for (int i = 0; i < 32; i++)
                {
                    Player player = new Player();

                    //Read player info
                    uint pPlayer = M.Read <uint>(G.PlayerList + (uint)i * 0x10);

                    int team = M.Read <int>(pPlayer + Offsets.TeamNum);
                    if (team == G.MyTeam)
                    {
                        continue;
                    }

                    int health = M.Read <int>(pPlayer + Offsets.Health);
                    if (health < 1)
                    {
                        continue;
                    }

                    int dormant = M.Read <int>(pPlayer + Offsets.Dormant);
                    if (dormant == 1)
                    {
                        continue;
                    }

                    int spotted_by = M.Read <int>(pPlayer + Offsets.SpottedByMask);
                    int bSpotted   = spotted_by & (1 << G.MyIndex - 1);

                    Vector3 playerLocation = M.Read <Vector3>(pPlayer + Offsets.VecOrigin);



                    if (WorldToScreen(playerLocation, out Vector2 screenpos2))
                    {
                        uint    headBone = 8;
                        Vector3 plr_bone = GetBonePos(headBone, pPlayer);

                        Vector3 vDelta   = playerLocation - G.MyLocation;
                        int     distance = (int)(vDelta.Length / 10);
                        if (Config.visuals)
                        {
                            DrawText(distance.ToString() + 'm', (int)screenpos2.X, (int)screenpos2.Y - 5, brushYellow, brushBlack, fontFactory, font);
                        }
                        //Set Player info & add to player list
                        player.BaseAddress        = pPlayer;
                        player.Index              = i;
                        player.Health             = health;
                        player.TargetBoneLocation = plr_bone;
                        player.Distance           = distance;
                        player.bSpotted           = bSpotted;
                        player.bDormant           = dormant;
                        Players.Add(player);

                        if (WorldToScreen(plr_bone, out Vector2 screenpos))
                        {
                            //Center of head screen position
                            //DrawMarker((int)screenpos.X, (int)screenpos.Y, 14, brushBlue, brushBlack);
                        }

                        Vector3 bottomHead = new Vector3(plr_bone.X, plr_bone.Y, plr_bone.Z - 4f);
                        Vector3 topHead    = new Vector3(plr_bone.X, plr_bone.Y, plr_bone.Z + 3f);
                        if (WorldToScreen(bottomHead, out Vector2 screenpos3))
                        {
                            if (WorldToScreen(topHead, out Vector2 screenpos4))
                            {
                                float height = Math.Abs(screenpos2.Y - screenpos4.Y);
                                float width  = height / 2f;
                                if (Config.visuals)
                                {
                                    DrawVertHBar(screenpos4.X - ((width / 2) - 2), screenpos4.Y - 1, height, health, brushGreen);
                                }
                                float headHeight = Math.Abs(screenpos3.Y - screenpos4.Y);
                                float headWidth  = headHeight / 2f;
                                if (Config.visuals)
                                {
                                    DrawRect(screenpos.X - headWidth, screenpos.Y - headWidth, headHeight, headHeight, brushBlue);
                                }
                            }
                        }
                    }
                }

                if (Players.Count > 0)
                {
                    G.Players = Players;
                }
                else
                {
                    G.Players = new List <Player>();
                }

                //Draw Crosshair
                if (Config.visuals)
                {
                    DrawCross((int)(windowWidth / 2) + 1, (int)(windowHeight / 2) + 1, 20, brushGreen);
                }

                //Draw Menu
                if (Config.Menu)
                {
                    DrawMenu(400, 400, brushWhite, brushLtGray, brushDarkRed, fontFactory, white, font);
                }

                //Recoil Control
                if (IsKeyDown(Config.ControlRecoilKey) && G.ShotsFired > 1)
                {
                    ControlRecoil();
                }
                LastPunch = VecPunch;

                device.EndDraw();
                Thread.Sleep(10);
            }
        }
Esempio n. 28
0
        public override void InitDevice()
        {
            Width  = Surface.ClientSize.Width;
            Height = Surface.ClientSize.Height;

            SwapChainDescription SwapDesc = new SwapChainDescription()
            {
                BufferCount     = 1,
                ModeDescription = new ModeDescription(
                    Width, Height,
                    new Rational(60, 1),
                    Format.R8G8B8A8_UNorm//R8G8B8A8_UNorm
                    ),
                IsWindowed        = true,
                OutputHandle      = Surface.Handle,
                SampleDescription = new SampleDescription(MSamplesCount, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput,
            };

            Device    device;
            SwapChain swapChain;

            DeviceCreationFlags deviceCreationFlags = DeviceCreationFlags.BgraSupport;

            if (IsDebugMode)
            {
                deviceCreationFlags |= DeviceCreationFlags.Debug;
            }

            Device.CreateWithSwapChain(
                DriverType.Hardware,
                deviceCreationFlags,
                //DeviceCreationFlags.None,
                SwapDesc,
                out device,
                out swapChain
                );
            DeviceRef           = device;
            DeviceRef.DebugName = "The Device";
            DeviceRef.ImmediateContext.DebugName = "The Context";

            CheckFeatures();

            SwapChainRef           = swapChain;
            SwapChainRef.DebugName = "The SwapChain";

            // Ignore all windows events
            FactoryDXGI factory = swapChain.GetParent <FactoryDXGI>();

            factory.MakeWindowAssociation(Surface.Handle, WindowAssociationFlags.IgnoreAll);

            ZBufferTextureDescription = new Texture2DDescription {
                Format            = Format.R32_Typeless,
                ArraySize         = 1,
                MipLevels         = 1,
                Width             = Width,
                Height            = Height,
                SampleDescription = new SampleDescription(MSamplesCount, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.DepthStencil | BindFlags.ShaderResource,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.None,
            };

            Factory2D                = new Factory(FactoryType.SingleThreaded, DebugLevel.Information);
            FactoryDWrite            = new SharpDX.DirectWrite.Factory();
            RenderTarget2DProperites = new RenderTargetProperties(new PixelFormat(
                                                                      Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied));
        }
Esempio n. 29
0
        private string CreateFont(string fontName, float fontSize, CCRawList <char> charset)
        {
            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                    //var contentPath = Path.Combine(appPath, CCApplication.SharedApplication.Content.RootDirectory);
                    //var fontPath = Path.Combine(contentPath, fontName);

                    //if (File.Exists(fontPath))
                    //{
                    // try
                    //{
                    //var fontFileReference = new FontCollection(
                    //_loadedFonts.AddFontFile(fontPath);

                    //        //fontFamily = _loadedFonts.Families[_loadedFonts.Families.Length - 1];

                    //        //_currentFont = new Font(fontFamily, fontSize);
                    //    }
                    //    catch
                    //    {
                    //        _currentFont = _defaultFont;
                    //    }
                    //}
                    //else
                    //{
                    _currentFont       = _defaultFont;
                    _currentFontSizeEm = fontSize;
                    _currentDIP        = ConvertPointSizeToDIP(fontSize);
                    //}
                }
                else
                {
                    _currentFont       = GetFont(fontName, fontSize);
                    _currentFontSizeEm = fontSize;
                    _currentDIP        = ConvertPointSizeToDIP(fontSize);
                }

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont       = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP        = ConvertPointSizeToDIP(fontSize);
            }
            fontName   = _currentFont.FontFamily.FamilyNames.GetString(0);
            textFormat = new TextFormat(FactoryDWrite, fontName, _currentDIP);

            GetKerningInfo(charset);

            return(_currentFont.ToString());
        }
Esempio n. 30
0
 public DrawSurface(GxContext context)
 {
     DirectWriteFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated);
     Direct2DFactory = new Factory();
     mDevice = context;
 }
        /// <summary>
        /// Inits the direct2D and direct write.
        /// </summary>
        private void InitDirect2DAndDirectWrite()
        {
            Factory2D = new SharpDX.Direct2D1.Factory();
            FactoryDWrite = new SharpDX.DirectWrite.Factory();

            var properties = new HwndRenderTargetProperties();
            properties.Hwnd = renderControl.Handle;
            properties.PixelSize = renderControl.ClientSize;
            properties.PresentOptions = PresentOptions.None;

            RenderTarget2D = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)), properties);
            RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;
            RenderTarget2D.TextAntialiasMode = TextAntialiasMode.Cleartype;

            SceneColorBrush = new SolidColorBrush(RenderTarget2D, new Color4(1, 0, 0, 0));
        }
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            FontCollection fontCollection;

            if (!_fontCollectionCache.TryGetValue(fontName, out fontCollection))
            {
                var ext = Path.GetExtension(fontName);

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    try
                    {
                        var fileFontLoader     = new FileFontLoader(FactoryDWrite, fontName);
                        var fileFontCollection = new FontCollection(FactoryDWrite, fileFontLoader, fileFontLoader.Key);
                        _currentFontCollection = fileFontCollection;
                        fontFamily             = _currentFontCollection.GetFontFamily(0);
                        var ffn = fontFamily.FamilyNames;
                        _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);

                        _fontCollectionCache.Add(fontName, fileFontCollection);
                        _currentFontCollection = fileFontCollection;
                    }
                    catch
                    {
                        _currentFont = GetFont(fontName, fontSize);
                        CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
                    }
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                }
            }
            else
            {
                fontFamily = fontCollection.GetFontFamily(0);

                _currentFont           = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontCollection = fontCollection;
            }

            return(_currentFont);
        }
Esempio n. 33
0
        private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        {

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();
                
                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;

            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                //if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                //{

                //    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                //    //var contentPath = Path.Combine(appPath, CCContentManager.SharedContentManager.RootDirectory);
                //    //var fontPath = Path.Combine(contentPath, fontName);

                //    //if (File.Exists(fontPath))
                //    //{
                //    //    try
                //    //    {
                //    //        if (privateFontLoader == null)
                //    //        {
                //    //            privateFontLoader = new PrivateFontLoader(FactoryDWrite, fontName);
                //    //            privateFontCollection = new FontCollection(FactoryDWrite, privateFontLoader, privateFontLoader.Key);
                //    //        }

                //    //        _currentFontCollection = privateFontCollection;

                //    //        var family = _currentFontCollection.GetFontFamily(0);
                //    //        // This is generic right now.  We should be able to handle different styles in the future
                //    //        var font = family.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                //    //        _currentFont = font;
                //    //        _currentFontSizeEm = fontSize;
                //    //        _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //    }
                //    //    catch
                //    //    {
                //    //        _currentFont = _defaultFont;
                //    //        _currentFontSizeEm = fontSize;
                //    //        _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //    }
                //    //}

                //    //else
                //    //{
                //    //    _currentFont = _defaultFont;
                //    //    _currentFontSizeEm = fontSize;
                //    //    _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //}
                //}
                //else
                //{
                    _currentFont = GetFont(fontName, fontSize);
                    _currentFontSizeEm = fontSize;
                    _currentDIP = ConvertPointSizeToDIP(fontSize);
                //}

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP = ConvertPointSizeToDIP(fontSize);
            }

            fontName = _currentFont.FontFamily.FamilyNames.GetString(0); 
            textFormat = new TextFormat(FactoryDWrite, fontName, 
                _currentFontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, _currentDIP);
            
            GetKerningInfo(charset);

            return _currentFont.ToString();
        }
Esempio n. 34
0
 public DrawSurface(GxContext context)
 {
     DirectWriteFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated);
     Direct2DFactory    = new Factory();
     mDevice            = context;
 }
Esempio n. 35
0
        private string CreateFont(string fontName, float fontSize, CCRawList <char> charset)
        {
            if (Factory2D == null)
            {
                Factory2D      = new SharpDX.Direct2D1.Factory();
                FactoryDWrite  = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi      = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                //if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                //{

                //    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                //    //var contentPath = Path.Combine(appPath, CCContentManager.SharedContentManager.RootDirectory);
                //    //var fontPath = Path.Combine(contentPath, fontName);

                //    //if (File.Exists(fontPath))
                //    //{
                //    //    try
                //    //    {
                //    //        if (privateFontLoader == null)
                //    //        {
                //    //            privateFontLoader = new PrivateFontLoader(FactoryDWrite, fontName);
                //    //            privateFontCollection = new FontCollection(FactoryDWrite, privateFontLoader, privateFontLoader.Key);
                //    //        }

                //    //        _currentFontCollection = privateFontCollection;

                //    //        var family = _currentFontCollection.GetFontFamily(0);
                //    //        // This is generic right now.  We should be able to handle different styles in the future
                //    //        var font = family.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                //    //        _currentFont = font;
                //    //        _currentFontSizeEm = fontSize;
                //    //        _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //    }
                //    //    catch
                //    //    {
                //    //        _currentFont = _defaultFont;
                //    //        _currentFontSizeEm = fontSize;
                //    //        _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //    }
                //    //}

                //    //else
                //    //{
                //    //    _currentFont = _defaultFont;
                //    //    _currentFontSizeEm = fontSize;
                //    //    _currentDIP = ConvertPointSizeToDIP(fontSize);
                //    //}
                //}
                //else
                //{
                _currentFont       = GetFont(fontName, fontSize);
                _currentFontSizeEm = fontSize;
                _currentDIP        = ConvertPointSizeToDIP(fontSize);
                //}

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont       = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP        = ConvertPointSizeToDIP(fontSize);
            }

            fontName   = _currentFont.FontFamily.FamilyNames.GetString(0);
            textFormat = new TextFormat(FactoryDWrite, fontName,
                                        _currentFontCollection, FontWeight.Regular, FontStyle.Normal, FontStretch.Normal, _currentDIP);

            GetKerningInfo(charset);

            return(_currentFont.ToString());
        }
Esempio n. 36
0
        public void DrawMenu(int X, int Y, Brush SelectedColor, Brush UnselectedColor, Brush titleColor, SharpDX.DirectWrite.Factory fontFactory, RawColor4 background, SharpDX.DirectWrite.TextFormat font)
        {
            string[] menuArray = new string[]
            {
                String.Format("Visuals: {0}", Config.visuals ? "(1)" : "(0)"),
                String.Format("Trigger Bot: {0}", Config.triggerbot ? "(1)" : "(0)"),
                String.Format("Recoil Xhair: ({0})", Config.RecoilOffsetXhair),
                String.Format("Recoil Ctrl: ({0})", Config.RecoilOffset),
                String.Format("Smoothing: ({0})", Config.smooth),
                String.Format("Aim FOV: ({0})", Config.FOV / 10)
            };

            string title = "Cole's Sample Project Menu";

            System.Drawing.Size nameSize = TextRenderer.MeasureText(title, Font);
            DrawFillRect(X - 2, Y - 2, nameSize.Width, 4 + (nameSize.Height * (menuArray.Count() + 1)), background);
            DrawFillRect(X - 2, Y + (nameSize.Height * (currentMenuIndex + 1)) + 1, nameSize.Width, nameSize.Height, background);
            DrawText(title, X, Y, titleColor, fontFactory, font);
            DrawText(menuArray[0], X, Y + (nameSize.Height * 1), currentMenuIndex == 0 ? SelectedColor : UnselectedColor, fontFactory, font);
            DrawText(menuArray[1], X, Y + (nameSize.Height * 2), currentMenuIndex == 1 ? SelectedColor : UnselectedColor, fontFactory, font);
            DrawText(menuArray[2], X, Y + (nameSize.Height * 3), currentMenuIndex == 2 ? SelectedColor : UnselectedColor, fontFactory, font);
            DrawText(menuArray[3], X, Y + (nameSize.Height * 4), currentMenuIndex == 3 ? SelectedColor : UnselectedColor, fontFactory, font);
            DrawText(menuArray[4], X, Y + (nameSize.Height * 5), currentMenuIndex == 4 ? SelectedColor : UnselectedColor, fontFactory, font);
            DrawText(menuArray[5], X, Y + (nameSize.Height * 6), currentMenuIndex == 5 ? SelectedColor : UnselectedColor, fontFactory, font);
        }