public OverlayNotification(D2DDevice device, ID2DBrush background, ID2DBrush foreground, D2DFont font)
 {
     _device         = device;
     BackgroundBrush = background;
     ForegroundBrush = foreground;
     Font            = font;
 }
예제 #2
0
        private IWcR2Font LoadXnaFont(string assetName)
        {
            string[] fontDesc   = assetName.Split(new[] { ',' }, 3);
            string   familyName = fontDesc[0];
            float    size;

            System.Drawing.FontStyle fStyle;
            if (float.TryParse(fontDesc[1], out size) &&
                Enum.TryParse(fontDesc[2], out fStyle))
            {
                if (this.UseD2DFont)
                {
                    var d2dFont = new D2DFont(familyName, size,
                                              (fStyle & System.Drawing.FontStyle.Bold) != 0,
                                              (fStyle & System.Drawing.FontStyle.Italic) != 0
                                              );
                    return(new D2DFontAdapter(d2dFont));
                }
                else
                {
                    var baseFont = new System.Drawing.Font(familyName, size, fStyle, System.Drawing.GraphicsUnit.Pixel);
                    var xnaFont  = new XnaFont(GraphicsDevice, baseFont);
                    return(new XnaFontAdapter(xnaFont));
                }
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
 public static SizeF MeasureText(Factory factory, string text, D2DFont font, float maxWidth, float maxHeight)
 {
     using (var layout = new TextLayout(factory, text, font.NativeFont, maxWidth, maxHeight)) {
         var metrics = layout.Metrics;
         return(new SizeF(PointToDip(metrics.Width), PointToDip(metrics.Height)));
     }
 }
예제 #4
0
 public D2DFontAdapter(D2DFont baseFont)
 {
     if (baseFont == null)
     {
         throw new ArgumentNullException("baseFont");
     }
     this._baseFont = baseFont;
 }
예제 #5
0
        static void Main(string[] args)
        {
            _window = new OverlayWindow(new OverlayOptions()
            {
                BypassTopmost = false,
                Height        = 600,
                Width         = 800,
                WindowTitle   = "GameOverlayExample",
                X             = 0,
                Y             = 0
            });

            _device = new D2DDevice(new DeviceOptions()
            {
                AntiAliasing  = true,
                Hwnd          = _window.WindowHandle,
                MeasureFps    = true,
                MultiThreaded = false,
                VSync         = false
            });

            _image = _device.LoadImage(@"C:\Users\Michel\Desktop\NotificationBackOrange.png");

            _backgroundBrush = _device.CreateSolidColorBrush(0xF1, 0x9A, 0x4C, 255);

            _foregroundBrush = _device.CreateSolidColorBrush(0, 0, 0, 255);

            _font = _device.CreateFont(new FontOptions()
            {
                Bold           = false,
                FontFamilyName = "Arial",
                FontSize       = 14,
                Italic         = false,
                WordWrapping   = false
            });

            _notification = new OverlayNotification(_device, _backgroundBrush, _foregroundBrush, _font)
            {
                Body       = "You earned an achievement!",
                BodySize   = 14,
                Header     = "Achievement",
                HeaderSize = 18
            };

            _frameTimer = new FrameTimer(_device, 0);

            _window.OnWindowBoundsChanged += _window_OnWindowBoundsChanged;

            _frameTimer.OnFrame += _frameTimer_OnFrame;

            _frameTimer.Start();

            Console.WriteLine("Press enter to exit");

            Console.ReadLine();
        }
예제 #6
0
        protected override void OnGotContext(RenderContext context)
        {
            base.OnGotContext(context);
            var fontPath   = Path.GetFullPath(GetFontFilePath());
            var familyName = DirectWriteHelper.GetFontFamilyName(fontPath);

            _font = new D2DFont(context.DirectWriteFactory, familyName, FontSize, FontStyle.Regular, 10);

            _textBrush = new D2DSolidBrush(context, FillColor);
        }
예제 #7
0
        public static Size GetDrawingTextSize(string text, D2DFont font)
        {
            Font     stringFont = new Font(font.FontFamilyName, font.FontSize, FontStyle.Regular, GraphicsUnit.Pixel);
            Image    fakeImage  = new Bitmap(1, 1);
            Graphics graphics   = Graphics.FromImage(fakeImage);
            SizeF    textSize   = graphics.MeasureString(text, stringFont);

            int x1SizeW = (int)textSize.Width;
            int x1SizeH = (int)textSize.Height;

            return(new Size(x1SizeW, x1SizeH));
        }
예제 #8
0
        private static void Main(string[] args)
        {
            Console.WindowHeight = Console.LargestWindowHeight / 2;
            Console.WindowWidth  = Console.LargestWindowWidth / 2;

            OverlayCreationOptions overlayOptions = new OverlayCreationOptions()
            {
                BypassTopmost = true,
                Height        = 600,
                Width         = 600,
                WindowTitle   = HelperMethods.GenerateRandomString(5, 11),
                X             = Console.WindowLeft,
                Y             = Console.WindowTop
            };

            StickyOverlayWindow overlay = new StickyOverlayWindow(Process.GetCurrentProcess().MainWindowHandle, overlayOptions);

            DeviceOptions rendererOptions = new DeviceOptions()
            {
                AntiAliasing = true,
                Hwnd         = overlay.WindowHandle,
                MeasureFps   = true,
                VSync        = false
            };

            gfx = new D2DDevice(rendererOptions);

            font            = gfx.CreateFont("Arial", 22);
            red             = gfx.CreateSolidColorBrush(255, 0, 0, 255);
            black           = gfx.CreateSolidColorBrush(0, 0, 0, 255);
            green           = gfx.CreateSolidColorBrush(0, 255.0f, 0, 255.0f);
            backgroundBrush = gfx.CreateSolidColorBrush(0xCC, 0xCC, 0xCC, 80);

            skeleton = CreateSkeleton(gfx);
            radar    = CreateRadarBackground(gfx, new Rectangle(100, 100, 400, 400), 10.0f);

            overlay.OnWindowBoundsChanged += Overlay_OnWindowBoundsChanged;

            FrameTimer timer = new FrameTimer(0, gfx);

            timer.FrameStarting += Timer_OnFrameStart;

            timer.Start();

            Console.ReadLine();

            timer.Stop();

            gfx.Dispose();
            overlay.Dispose();
        }
예제 #9
0
        public MusicSelect(RenderTaskerHandler drawer)
        {
            D2DSprite.resetData();
            D2DFont.resetData();
            this.drawer = drawer;
            drawer.sprite.setBackground("background", new SpriteData(D2DSprite.makeBitmapBrush(drawer.sprite.renderTarget, "musicSelect.png"), 0, 0));
            drawer.sprite.addButton("2musiccard1", new ClickableSprite(D2DSprite.makeBitmapBrush(drawer.sprite.renderTarget, "music-1.png"), 70, 120, 0));
            D2DSprite._LClickableSprite["2musiccard1"].OnMouseClick += _EmusicCard1Selected;


            /*((ClickableSprite)data).OnMouseClick += (Object sender, EventArgs e) =>
             * {
             *      Console.WriteLine("{0} 클릭됨.", tag);
             * };*/
        }
예제 #10
0
        public ResultScreen(RenderTaskerHandler drawer, string musicName, ScoreData data)
        {
            if (PublicDataManager.deviceCreated)
            {
                drawer.targetForm.KeyDown += _EkeyDown;

                D2DFont.resetData();
                D2DSprite.resetData();
                this.drawer    = drawer;
                this.data      = data;
                this.musicName = musicName;

                initialize();
            }
        }
예제 #11
0
        protected override void OnGotContext(RenderContext context)
        {
            base.OnGotContext(context);
            var fontPath   = Path.GetFullPath(GetFontFilePath());
            var familyName = DirectWriteHelper.GetFontFamilyName(fontPath);

            _font       = new D2DFont(context.DirectWriteFactory, familyName, FontSize, FontStyle.Regular, 10);
            _textFill   = new D2DSolidBrush(context, FillColor);
            _textStroke = new D2DPen(context, StrokeColor, StrokeWidth);
            _fontFile   = new FontFile(context.DirectWriteFactory, fontPath);
            _fontFace   = new FontFace(context.DirectWriteFactory, FontFaceType.OpenTypeCollection, new[] { _fontFile }, 0, FontSimulations.None);
            _glyphRun   = new GlyphRun {
                FontFace = _fontFace,
                FontSize = FontSize
            };
            RegenerateFontPath(context);
        }
예제 #12
0
        private void _frameTimer_OnFrameStarting(FrameTimer timer, D2DDevice device)
        {
            if (!_initializeGraphicObjects)
            {
                return;
            }

            if (!device.IsInitialized)
            {
                return;
            }
            if (device.IsDrawing)
            {
                return;
            }

            _backgroundColor = new D2DColor(0x24, 0x29, 0x2E, 0xFF);

            _font = _device.CreateFont(new FontOptions()
            {
                Bold           = false,
                FontFamilyName = "Arial",
                FontSize       = 16,
                Italic         = false,
                WordWrapping   = true
            });

            // colors automatically normalize values to fit. you can use 1.0f but also 255.0f.
            _blackBrush = device.CreateSolidColorBrush(0x0, 0x0, 0x0, 0xFF);

            _redBrush   = device.CreateSolidColorBrush(0xFF, 0x0, 0x0, 0xFF);
            _greenBrush = device.CreateSolidColorBrush(0x0, 0xFF, 0x0, 0xFF);
            _blueBrush  = device.CreateSolidColorBrush(0x0, 0x0, 0xFF, 0xFF);

            _gradient = new D2DLinearGradientBrush(device, new D2DColor(0, 0, 80), new D2DColor(0x88, 0, 125), new D2DColor(0, 0, 225));

            // loads an image from resource bytes (.png in this case)
            _image = device.LoadImage(Properties.Resources.placeholder_image_bytes);

            _initializeGraphicObjects = false;
        }
예제 #13
0
        private void _frameTimer_OnFrameStarting(FrameTimer timer, D2DDevice device)
        {
            if (!_initializeGraphicObjects)
            {
                return;
            }

            if (!device.IsInitialized)
            {
                return;
            }
            if (device.IsDrawing)
            {
                return;
            }

            _backgroundColor = new D2DColor(0, 0, 0, 0);

            _font = _device.CreateFont(new FontOptions()
            {
                Bold           = false,
                FontFamilyName = "Times New Roman",
                FontSize       = 10,
                Italic         = false,
                WordWrapping   = true
            });

            // colors automatically normalize values to fit. you can use 1.0f but also 255.0f.
            _blackBrush = device.CreateSolidColorBrush(0x0, 0x0, 0x0, 0xFF);

            _redBrush   = device.CreateSolidColorBrush(0xFF, 0x0, 0x0, 0xFF);
            _greenBrush = device.CreateSolidColorBrush(0x0, 0xFF, 0x0, 0xFF);
            _blueBrush  = device.CreateSolidColorBrush(0x0, 0x0, 0xFF, 0xFF);

            _initializeGraphicObjects = false;
        }
예제 #14
0
        private void Initialize(RenderContext context, string text, D2DFont d2dFont, FontFace fontFace)
        {
            Text     = text;
            D2DFont  = d2dFont;
            FontFace = fontFace;

            var fontSizeInEm = DirectWriteHelper.PointToDip(d2dFont.Size);

            LineHeight = fontSizeInEm;

            if (text.IndexOf('\n') >= 0)
            {
                var processedText = text.Replace("\r", string.Empty);
                var lines         = processedText.Split('\n');

                _pathDataArray = new D2DPathData[lines.Length];
                _lineHeights   = new float[lines.Length];

                for (var i = 0; i < lines.Length; ++i)
                {
                    var line = lines[i];
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        var pathData = GetPathData(context, line, fontFace, fontSizeInEm);
                        _pathDataArray[i] = pathData;
                    }
                    _lineHeights[i] = fontSizeInEm;
                }
            }
            else
            {
                var pathData = GetPathData(context, text, fontFace, fontSizeInEm);
                _pathDataArray = new[] { pathData };
                _lineHeights   = new[] { fontSizeInEm };
            }
        }
예제 #15
0
 public D2DFontPathData([NotNull] string text, RenderContext context, D2DFont d2dFont, FontFace fontFace, float maxWidth, float maxHeight)
 {
     Initialize(context, text, d2dFont, fontFace);
     Size = context.MeasureText(text, d2dFont, maxWidth, maxHeight);
 }
예제 #16
0
 public D2DFontPathData([NotNull] string text, RenderContext context, D2DFont d2dFont, FontFace fontFace)
 {
     Initialize(context, text, d2dFont, fontFace);
     Size = context.MeasureText(text, d2dFont);
 }
예제 #17
0
        private void _frameTimer_OnFrame(FrameTimer timer, D2DDevice device)
        {
            #region non drawing things
            D2DSolidColorBrush GetDXColor(Color color)
            {
                return(device.CreateSolidColorBrush(color.R, color.G, color.B, color.A));
            }

            if (!device.IsDrawing)
            {
                _initializeGraphicObjects = true;
                return;
            }
            device.ClearScene();
            #endregion
            DrawTextWithBackground("ZBase", 0, 0, 16, Color.Blue, Color.DimGray);

            if (Main.S.ESP)
            {
                foreach (Entity Player in Globals.EntityList)
                {
                    if (Player.EntityBase != Globals.LocalPlayer.EntityBase)
                    {
                        Vector2 Player2DPos     = Tools.WorldToScreen(Player.Position);
                        Vector2 Player2DHeadPos = Tools.WorldToScreen(Player.HeadPosition);
                        Vector2 Player2DNeckPos = Tools.WorldToScreen(Player.GetBonePosition(7));
                        if (!Tools.IsNullVector2(Player2DPos) && !Tools.IsNullVector2(Player2DHeadPos) && Player.Valid)
                        {
                            float FromHeadToNeck = (Player2DNeckPos.Y - Player2DHeadPos.Y);
                            Player2DHeadPos.Y -= FromHeadToNeck * 2.3f;
                            Player2DPos.Y     += FromHeadToNeck;
                            float BoxHeight = Player2DPos.Y - Player2DHeadPos.Y;
                            float BoxWidth  = (BoxHeight / 2);
                            //wierd ass calculations for box height, dont judge
                            Color drawcolor;
                            if (Player.IsTeammate)
                            {
                                drawcolor = Color.Blue;
                            }
                            else
                            {
                                drawcolor = Color.Red;
                            }
                            DrawOutlineBox(Player2DPos.X - (BoxWidth / 2), Player2DHeadPos.Y, BoxWidth, BoxHeight, drawcolor);
                            DrawLine(Main.MidScreen.X, Main.MidScreen.Y + Main.MidScreen.Y, Player2DPos.X, Player2DPos.Y, drawcolor);
                        }
                    }
                }
            }

            #region drawing functions
            void DrawBoxEdge(float x, float y, float width, float height, Color color, float thiccness = 2.0f)
            {
                device.DrawRectangleEdges(Rectangle.Create(x, y, width, height), thiccness, GetDXColor(color));
            }

            void DrawText(string text, float x, float y, int size, Color color, bool bold = false, bool italic = false)
            {
                D2DFont f = _device.CreateFont(new FontOptions()
                {
                    Bold           = bold,
                    FontFamilyName = "Arial",
                    FontSize       = size,
                    Italic         = italic,
                    WordWrapping   = true
                });

                device.DrawText(text, new Point(x, y), f, GetDXColor(color));
            }

            void DrawTextWithBackground(string text, float x, float y, int size, Color color, Color backcolor, bool bold = false, bool italic = false)
            {
                D2DFont f = _device.CreateFont(new FontOptions()
                {
                    Bold           = bold,
                    FontFamilyName = "Arial",
                    FontSize       = size,
                    Italic         = italic,
                    WordWrapping   = true
                });

                device.DrawTextWithBackground(text, new Point(x, y), f, GetDXColor(color), GetDXColor(backcolor));
            }

            void DrawLine(float fromx, float fromy, float tox, float toy, Color color, float thiccness = 2.0f)
            {
                device.DrawLine(fromx, fromy, tox, toy, thiccness, GetDXColor(color));
            }

            void DrawFilledRectangle(float x, float y, float width, float height, Color color)
            {
                device.FillRectangle(Rectangle.Create(x, y, width, height), GetDXColor(color));
            }

            void DrawCircle(float x, float y, float radius, Color color)
            {
                device.DrawCircle(new Circle(x, y, radius), 1, GetDXColor(color));
            }

            void DrawCrosshair(CrosshairStyle style, float x, float y, float size, float stroke, Color color)
            {
                device.DrawCrosshair(style, new Point(x, y), size, stroke, GetDXColor(color));
            }

            void DrawBox(float x, float y, float width, float height, Color color, float thiccness = 2.0f)
            {
                device.DrawRectangle(Rectangle.Create(x, y, width, height), thiccness, GetDXColor(color));
            }

            void DrawOutlineBox(float x, float y, float width, float height, Color color, float thiccness = 2.0f)
            {
                device.OutlineRectangle(Rectangle.Create(x, y, width, height), thiccness, GetDXColor(color), GetDXColor(Color.Black));
            }

            void DrawRoundedBox(float x, float y, float width, float height, float radius, Color color, float thiccness = 2.0f)
            {
                device.DrawRoundedRectangle(RoundedRectangle.Create(x, y, width, height, radius), thiccness, GetDXColor(color));
            }

            #endregion
        }
예제 #18
0
        private void createDevice()
        {
            int    currentWindowWidth  = 0;
            int    currentWindowHeight = 0;
            IntPtr OutputHandle        = IntPtr.Zero;

            targetForm.Invoke(new MethodInvoker(() =>
            {
                currentWindowWidth  = targetForm.ClientSize.Width;
                currentWindowHeight = targetForm.ClientSize.Height;
                OutputHandle        = targetForm.Handle;
            }));

            desc = new SwapChainDescription()
            {
                BufferCount     = 1,//buffer count
                ModeDescription = new ModeDescription(currentWindowWidth, currentWindowHeight, new Rational(60, 1), RENDER_FORMAT),
                //IsWindowed = bool.Parse(GlobalDataManager.settings.getSetting("windowded")),
                IsWindowed        = true,
                OutputHandle      = OutputHandle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            FeatureLevel[]      levels = new FeatureLevel[] { FeatureLevel.Level_11_0 };
            DeviceCreationFlags flag   = DeviceCreationFlags.None | DeviceCreationFlags.BgraSupport;

            Device.CreateWithSwapChain(DriverType.Hardware, flag, levels, desc, out _device, out _swapChain);

            _deviceContext = _device.ImmediateContext;

            _backBufferTexture = _swapChain.GetBackBuffer <Texture2D>(0);

            FontLoader     fontLoader     = new FontLoader(resourceManageCore, "/fonts");
            FontCollection fontCollection = new FontCollection(new SharpDX.DirectWrite.Factory(), fontLoader, fontLoader.Key);

            font = new D2DFont(_backBufferTexture);
            font.add("fps", new FontData(frame + " fps", font.renderTarget, fontCollection, Color.White, fontName: "applemint", fontSize: 20, x: 710));
            font.add("score", new FontData("0", font.renderTarget, fontCollection, Color.White, fontName: "applemint", fontSize: 20, x: 710, y: 25));
            sprite = new D2DSprite(_backBufferTexture);

            _backbufferView = new RenderTargetView(_device, _backBufferTexture);
            _backBufferTexture.Dispose();

            var _zbufferTexture = new Texture2D(_device, new Texture2DDescription()
            {
                Format    = Format.D24_UNorm_S8_UInt,
                ArraySize = 1,
                MipLevels = 1,
                //Width = int.Parse(GlobalDataManager.settings.getSetting("width")),
                //Height = int.Parse(GlobalDataManager.settings.getSetting("height")),
                Width             = 1280,
                Height            = 720,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.DepthStencil,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.None
            });

            // Create the depth buffer view
            _zbufferView = new DepthStencilView(_device, _zbufferTexture);
            _zbufferTexture.Dispose();

            _deviceContext.Rasterizer.SetViewport(0, 0, targetForm.ClientSize.Width, targetForm.ClientSize.Height);
            _deviceContext.OutputMerger.SetTargets(_zbufferView, _backbufferView);

            //GlobalDataManager.deviceCreated = true;
        }
예제 #19
0
 public static SizeF MeasureText(this RenderContext context, string text, D2DFont font, float maxWidth, float maxHeight)
 {
     return(DirectWriteHelper.MeasureText(context.DirectWriteFactory, text, font, maxWidth, maxHeight));
 }
예제 #20
0
 public static void DrawText(this SharpDX.Direct2D1.RenderTarget target, string text, ID2DBrush brush, D2DFont font, float destX, float destY)
 {
     target.DrawText(text, brush, font, destX, destY, float.MaxValue, float.MaxValue);
 }
예제 #21
0
        public static void DrawText(this SharpDX.Direct2D1.RenderTarget target, string text, ID2DBrush brush, D2DFont font, float destX, float destY, float destWidth, float destHeight)
        {
            var destRect = new RawRectangleF(destX, destY, destX + destWidth, destY + destHeight);

            target.DrawText(text, font.NativeFont, destRect, brush.NativeBrush);
        }
예제 #22
0
 public static void DrawText(this RenderContext context, string text, ID2DBrush brush, D2DFont font, float destX, float destY)
 {
     context.RenderTarget.DeviceContext2D.DrawText(text, brush, font, destX, destY);
 }
예제 #23
0
 public static SizeF MeasureText(Factory factory, string text, D2DFont font)
 {
     return(MeasureText(factory, text, font, float.MaxValue, float.MaxValue));
 }