Exemple #1
0
        private void ApplicationIdle(object sender, EventArgs e)
        {
            while (IsApplicationIdle())
            {
                // TODO : process input

                // update game objects
                double gameTime  = (double)gameTimer.ElapsedTicks / Stopwatch.Frequency;
                float  deltaTime = (float)(gameTime - lastGameTime);
                if (deltaTime >= 0.008)
                {
                    lastGameTime = gameTime;
                    foreach (IGameObject gameObj in gameObjects)
                    {
                        gameObj.Update(deltaTime);
                    }

                    moveAIPaddle();
                    checkBallCollisions();

                    if (!firstPaint)
                    {
                        renderTarget.BeginDraw();
                        renderTarget.Transform = Matrix3x2.Identity;
                        renderTarget.Clear(new Color4(0.0f, 0.0f, 0.0f));
                        foreach (IGameObject gameObj in gameObjects)
                        {
                            gameObj.Render(factory, dwFactory, renderTarget);
                        }
                        renderTarget.EndDraw();
                    }
                    // Debug.WriteLine("deltaTime = " + deltaTime);
                }
            }
        }
Exemple #2
0
        public void DrawText(WindowRenderTarget renderTarget, string titleText, string xAxisText, string yAxisText, float baseTextSize)
        {
            var sgOffsetY       = renderTarget.Size.Height * 1 / 15;
            var sgOffsetX       = renderTarget.Size.Width * 1 / 15;
            var containerHeight = renderTarget.Size.Height - sgOffsetY * 2;
            var containerWidth  = renderTarget.Size.Width - sgOffsetX * 2; // not used?
            var textWidth       = (int)containerHeight;
            var textHeight      = (int)sgOffsetY;

            var factoryDWrite = new SharpDX.DirectWrite.Factory();

            _textFormatTitle = new TextFormat(factoryDWrite, "Segoe", baseTextSize * 5 / 4)
            {
                TextAlignment      = TextAlignment.Center,
                ParagraphAlignment = ParagraphAlignment.Center
            };
            _textFormatHorizontal = new TextFormat(factoryDWrite, "Segoe", baseTextSize)
            {
                TextAlignment      = TextAlignment.Center,
                ParagraphAlignment = ParagraphAlignment.Far
            };
            _textFormatVertical = new TextFormat(factoryDWrite, "Segoe", baseTextSize)
            {
                TextAlignment      = TextAlignment.Center,
                ParagraphAlignment = ParagraphAlignment.Far
            };

            renderTarget.AntialiasMode     = AntialiasMode.PerPrimitive;
            renderTarget.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Cleartype;

            var ClientRectangleTitle = new RectangleF(0, 0, textWidth, textHeight);
            var ClientRectangleXAxis = new RectangleF(0,
                                                      containerHeight - textHeight + sgOffsetY * 2, textWidth, textHeight);
            var ClientRectangleYAxis = new RectangleF(-sgOffsetX,
                                                      containerHeight - textHeight + sgOffsetY, textWidth, textHeight);

            _textSceneColorBrush.Color = _black;

            // Draw title and x axis text.
            renderTarget.BeginDraw();

            renderTarget.Clear(_white);
            renderTarget.DrawText(titleText, _textFormatTitle, ClientRectangleTitle, _textSceneColorBrush);
            renderTarget.DrawText(xAxisText, _textFormatHorizontal, ClientRectangleXAxis, _textSceneColorBrush);

            renderTarget.EndDraw();

            // Rotate render target to draw y axis text.
            renderTarget.Transform = Matrix3x2.Rotation((float)(-Math.PI / 2), new SharpDX.Vector2(0, containerHeight));

            renderTarget.BeginDraw();

            renderTarget.DrawText(yAxisText, _textFormatVertical, ClientRectangleYAxis, _textSceneColorBrush);

            renderTarget.EndDraw();

            // Rotate the RenderTarget back.
            renderTarget.Transform = Matrix3x2.Identity;
        }
Exemple #3
0
 private void MainWindow_Paint(object sender, PaintEventArgs e)
 {
     _renderTarget.BeginDraw();
     _renderTarget.Clear(Color.FromKnown(Colors.Black, 1));
     if (_cache != null)
     {
         _renderTarget.DrawBitmap(_cache, new RectF(0, 0, ClientSize.Width, ClientSize.Height),
                                  1, BitmapInterpolationMode.Linear);
     }
     _renderTarget.EndDraw();
 }
Exemple #4
0
 public override bool Begin()
 {
     if (stateDraw)
     {
         return(false);
     }
     while (tLock)
     {
         ;
     }
     stateDraw = true;
     mainRenderTarget.BeginDraw();
     return(true);
 }
Exemple #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (!graphicsInitialized)
            {
                return;
            }

            windowRenderTarget.AntialiasMode = AntialiasMode.PerPrimitive;
            windowRenderTarget.BeginDraw();

            try
            {
                windowRenderTarget.Clear(backgroundColor);

                if (scene != null)
                {
                    DrawScene();
                }
            }
            finally
            {
                windowRenderTarget.EndDraw();
            }
        }
Exemple #6
0
        /// <summary>
        /// Renderloop
        /// </summary>
        public void Render()
        {
            WindowRenderTarget.BeginDraw();

            WindowRenderTarget.Clear(Colors.AdvancedColors.DarkGray);

            for (int i = 0; i < screens.Count; i++)
            {
                screens[i].Render(windowBounds, WindowRenderTarget);
            }

            WindowRenderTarget.EndDraw();

            //if (sw == null)
            //    sw = Stopwatch.StartNew();
            //else
            //{
            //    if (sw.ElapsedMilliseconds >= 1000)
            //    {
            //        sw.Restart();
            //        Console.WriteLine("FPS: " + fps);
            //        fps = 0;
            //    }

            //    fps++;
            //}
        }
Exemple #7
0
        public void Run()
        {
            SharpDX.Threading.TaskUtil.Run(() =>
            {
                while (!_cancelTask.IsCancellationRequested)
                {
                    lock (_lockObj)
                    {
                        hwndRenderTarget.BeginDraw();
                        hwndRenderTarget.Clear(Color.White);

                        if (_opacity > 0.0f)//表示切换中
                        {
                            RectangleF preRenderRect = ZoomBitmap(RenderTargetClientSize, _preBmp.Size);
                            hwndRenderTarget.DrawBitmap(_preBmp.Bmp, preRenderRect, _opacity, BitmapInterpolationMode.NearestNeighbor, _preBmp.BitmapRectangleF);

                            _opacity -= 0.02f;
                        }
                        else
                        {
                            if (_preBmp != null)
                            {
                                _preBmp.Dispose();
                            }
                        }
                        RectangleF renderRect = ZoomBitmap(RenderTargetClientSize, _bmp.Size);
                        hwndRenderTarget.DrawBitmap(_bmp.Bmp, renderRect, 1f - _opacity, BitmapInterpolationMode.NearestNeighbor, _bmp.BitmapRectangleF);

                        hwndRenderTarget.EndDraw();
                    }
                    Thread.Sleep(40);
                }
            });
        }
Exemple #8
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);
        }
        private void ThreadDirectX(object sender)
        {
            while (true)
            {
                device.BeginDraw();
                device.Clear(Color.Transparent);
                device.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased;

                List <BHelper.PlayerDraw> PlayerDataBuffer = Bluehack.PlayerDraws;
                for (int i = 0; i < PlayerDataBuffer.Count; i++)
                {
                    BHelper.PlayerDraw PlayerData = PlayerDataBuffer[i];

                    DrawPlayerHealth(PlayerData.espX, PlayerData.espY, PlayerData.espDistance, PlayerData.PlayerHealth);
                    DrawPlayerHead(PlayerData.espX, PlayerData.espY, PlayerData.espDistance);
                    DrawPlayerBones(PlayerData.Bones);
                }

                List <BHelper.EntityDraw> EntityDataBuffer = Bluehack.EntityDraws;
                for (int i = 0; i < EntityDataBuffer.Count; i++)
                {
                    BHelper.EntityDraw EntityData = EntityDataBuffer[i];
                    if (Enum.IsDefined(typeof(BHelper.AcceptedGrenadeIDS), EntityData.EntityClassID))
                    {
                        DrawEntityGrenade(EntityData.espX, EntityData.espY, EntityData.espDistance, EntityData.EntityClassID, EntityData.EntityModel);
                    }
                }

                float[] Punch = BHelper.LocalPlayer.GetPunch();
                DrawPlayerCrosshair(Punch[0], Punch[1]);

                device.EndDraw();
                Thread.Sleep(10);
            }
        }
Exemple #10
0
        public void RenderBuffer(int[] buffer)
        {
            int widthOfBox  = _box.Width;
            int heightOfBox = _box.Height;
            int newWidth    = Math.Min(widthOfBox, heightOfBox * 256 / 224);
            int newHeight   = newWidth * 224 / 256;
            int leftOffSet  = (_box.Width - newWidth) / 2;
            int topOffSet   = (_box.Height - newHeight) / 2;

            var d2dBitmap = Bitmap.New(_renderTarget2D, new Size2(256, 224), buffer,
                                       new BitmapProperties(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)));

            if (_renderTarget2D.Size.Width != _box.Width || _renderTarget2D.Size.Height != _box.Height)
            {
                _renderTarget2D.Resize(new Size2(_box.Width, _box.Height));
            }
            _renderTarget2D.BeginDraw();
            _renderTarget2D.AntialiasMode = AntialiasMode.Aliased;
            _renderTarget2D.DrawBitmap(d2dBitmap,
                                       new RawRectangleF(leftOffSet, topOffSet, leftOffSet + newWidth, topOffSet + newHeight),
                                       1.0f, BitmapInterpolationMode.Linear);

            try
            {
                _renderTarget2D.EndDraw();
            }
            catch (SharpDXException ex) when((uint)ex.HResult == 0x8899000C)
            {
            }
            d2dBitmap.Dispose();
        }
Exemple #11
0
        public void BeginScene()
        {
            if (_device == null)
            {
                return;
            }
            if (_isDrawing)
            {
                return;
            }

            if (MeasureFPS && !_stopwatch.IsRunning)
            {
                _stopwatch.Restart();
            }

            if (_resize)
            {
                _device.Resize(new Size2(_resizeWidth, _resizeHeight));
                _resize = false;
            }

            _device.BeginDraw();

            _isDrawing = true;
        }
Exemple #12
0
        private void Render(bool shouldRecompose, bool shouldRetry)
        {
            var interpolationMode = false ? BitmapInterpolationMode.Linear : BitmapInterpolationMode.NearestNeighbor;

            _windowRenderTarget.BeginDraw();

            if (BorderVisible)
            {
                CreateCompositeRenderTarget();

                _compositeRenderTarget.BeginDraw();
                _compositeRenderTarget.Clear(_clearColor);
                _compositeRenderTarget.DrawBitmap(_screenRenderTarget.Bitmap, new RawRectangleF(48, 40, 48 + 160, 40 + 144), 1.0f, BitmapInterpolationMode.NearestNeighbor);
                _compositeRenderTarget.DrawBitmap(_borderBitmap, 1.0f, BitmapInterpolationMode.NearestNeighbor);
                _compositeRenderTarget.EndDraw();
                _windowRenderTarget.DrawBitmap(_compositeRenderTarget.Bitmap, _drawRectangle, 1.0f, interpolationMode);
            }
            else
            {
                _windowRenderTarget.DrawBitmap(_screenRenderTarget.Bitmap, _drawRectangle, 1.0f, interpolationMode);
            }

            try { _windowRenderTarget.EndDraw(); }
            catch (COMException)
            {
                // If needed, try to recreate the target.
                ResetRendering();
                // Try to render again, but only once. (We don't want to enter an infinite recursion… AKA Stack Overflow)
                if (shouldRetry)
                {
                    Render(true, false);
                }
            }
        }
Exemple #13
0
        private void MainWindow_Paint(object sender, PaintEventArgs e)
        {
            _renderTarget.BeginDraw();
            _renderTarget.Clear(Color.FromKnown(Colors.Blue, 1));

            PointF center = new PointF(ClientSize.Width / 2, ClientSize.Height / 2);

            _renderTarget.Transform = Matrix3x2.Rotation(_angle, center);

            RoundedRect rr = new RoundedRect(new RectF(30, 30, ClientSize.Width - 60, ClientSize.Height - 60), ClientSize.Width / 2.5f, ClientSize.Height / 2.5f);

            _renderTarget.FillRoundedRect(RectBrush, rr);
            _renderTarget.DrawRoundedRect(_strokeBrush, 5, _strokeStyle, rr);

            Ellipse ellipse = new Ellipse(ClientSize.Width / 2, ClientSize.Height / 2, ClientSize.Width / 4, ClientSize.Height / 4);

            using (EllipseGeometry eg = _factory.CreateEllipseGeometry(ellipse))
            {
                using (Brush b = CreateEllipseBrush(ellipse))
                {
                    _renderTarget.FillGeometry(b, eg);
                    _renderTarget.DrawGeometry(_strokeBrush, 5, _strokeStyle, eg);
                }
            }
            RectF textBounds = new RectF(0, 0, ClientSize.Width, ClientSize.Height);

            _renderTarget.DrawText("Hello, world!", _textFormat, textBounds, _strokeBrush, DrawTextOptions.None, MeasuringMode.Natural);

            _renderTarget.DrawLine(_strokeBrush, 5, _strokeStyle, new PointF(0, 0), new PointF(ClientSize.Width, ClientSize.Height));

            _renderTarget.EndDraw();
        }
Exemple #14
0
        private void Draw()
        {
            //begin rendering
            target.BeginDraw();
            //clear target
            target.Clear(SharpDX.Color.CornflowerBlue);

            //draw a rounded box
            target.FillRoundedRectangle(new RoundedRectangle()
            {
                RadiusX = 10,
                RadiusY = 10,
                Rect    = new SharpDX.RectangleF(0, 0, ClientSize.Width, ClientSize.Height)
            }, gradient);

            //draw some ellipse
            for (int i = 0; i < 20; i++)
            {
                target.DrawEllipse(new Ellipse(new Vector2(ClientSize.Width / 2, ClientSize.Height / 2), 20 * i, 20 * i), redBrush);
            }

            //draw text
            target.DrawText("Hello Direct2D", textFormat, new SharpDX.RectangleF(0, 0, 400, 200), whiteBrush);

            //end drawing
            target.EndDraw();
        }
Exemple #15
0
 private void StartRendering()
 {
     try
     {
         if (renderTarget == null)
         {
             CreateRenderObjects();
         }
         renderTarget.BeginDraw();
         try
         {
             OnRender();
         }
         catch (Exception ex)
         {
             OnRenderError(ex);
         }
         finally
         {
             renderTarget.EndDraw();
         }
     }
     catch (SharpDXException ex)
     {
         if (ex.ResultCode.Code == unchecked ((int)0x8899000C))
         {
             DisposeRenderObjects();
             CreateRenderObjects();
             Invalidate();
         }
     }
 }
Exemple #16
0
 /// <summary>
 ///     This is the thread where we draw
 /// </summary>
 /// <param name="sender"></param>
 private void SDxThread(object sender)
 {
     Main.Alert("Overlay launched!");
     while (Shouldrun)
     {
         _device.BeginDraw();
         _device.Clear(new RawColor4(Color.Transparent.R, Color.Transparent.G, Color.Transparent.B,
                                     Color.Transparent.A));
         _device.TextAntialiasMode = TextAntialiasMode.Default;
         using (var g = Graphics.FromHwnd(IntPtr.Zero))
         {
             if (!string.IsNullOrEmpty(Currentwindow))
             {
                 if (GameTitles.Any(x => Currentwindow.ToUpper().Contains(x)))
                 {
                     _device.DrawText(Demodata,
                                      new TextFormat(_fontFactory,
                                                     TextFont.FontFamily.Name,
                                                     FontWeight.Normal,
                                                     FontStyle.Normal,
                                                     TextFont.Size),
                                      new RawRectangleF(0, 0,
                                                        (int)g.MeasureString(Demodata, TextFont).Width + 5,
                                                        (int)g.MeasureString(Demodata, TextFont).Height + 5),
                                      _solidColorBrush);
                 }
             }
         }
         _device.EndDraw();
     }
 }
Exemple #17
0
        private void MyChart_Paint(object sender, PaintEventArgs e)
        {
            _renderTarget.BeginDraw();
            _renderTarget.Clear(new RawColor4(1.0f, 1.0f, 1.0f, 1.0f));//用白色清空

            DrawGrid();
            if (Setting.ShowWave)
            {
                DrawWave();
            }
            if (Setting.ShowFrameSeparator)
            {
                DrawFrameSepa();
            }
            if (Setting.ShowSpec)
            {
                DrawSpec();
            }
            if (Setting.ShowSpecSpec)
            {
                DrawSpecSpec();
            }
            if (Setting.ShowLogSpec)
            {
                DrawLogSpec();
            }
            if (Setting.ShowCepstrum)
            {
                DrawCepstrum();
            }

            if (_isMouseMoving)
            {
                RawRectangleF rect = new RawRectangleF
                {
                    Left   = Math.Min(_mouseStartPoint.X, _mouseEndPoint.X),
                    Right  = Math.Max(_mouseStartPoint.X, _mouseEndPoint.X),
                    Top    = Math.Min(_mouseStartPoint.Y, _mouseEndPoint.Y),
                    Bottom = Math.Max(_mouseStartPoint.Y, _mouseEndPoint.Y)
                };
                _renderTarget.FillRectangle(rect, _blueBrush);
            }
            if (_chosenAreaMin < _chosenAreaMax)
            {
                var x = (_chosenAreaMin - _minX) * _scale_times_X + 40.0f;
                if (x > 40 && x < renderControl.ClientSize.Width)
                {
                    _renderTarget.DrawLine(new RawVector2(x, 0),
                                           new RawVector2(x, this.Height), _blueBrush, 2);
                }
                x = (_chosenAreaMax - _minX) * _scale_times_X + 40.0f;
                if (x > 40 && x < renderControl.ClientSize.Width)
                {
                    _renderTarget.DrawLine(new RawVector2(x, 0),
                                           new RawVector2(x, this.Height), _blueBrush, 2);
                }
            }
            _renderTarget.EndDraw();
        }
Exemple #18
0
        private void DirectXThread(object obj)
        {
            while (Options.EspIsEnabled)
            {
                _device.BeginDraw();

                _device.Clear(new RawColor4(Color.Transparent.R, Color.Transparent.G, Color.Transparent.B,
                                            Color.Transparent.A));
                _device.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Aliased;

                //Get all players in the game
                var players = Utils.GetPlayers();

                //Get our local player
                var localPlayer = Utils.GetLocalPlayer();

                //If there aren't any players, we continue looping
                if (players.Count == 0)
                {
                    continue;
                }

                foreach (var player in players)
                {
                    //If the player is dead, or it's in our team or is dormant, it's not a valid one, so we continue looping
                    if (player.GetHealth() == 0 || player.GetTeam() == localPlayer.GetTeam() || player.IsDormant())
                    {
                        continue;
                    }

                    //Get player position
                    var playerPosition = player.GetPosition();
                    //Get player head position
                    var head = player.GetBonePos((int)Utils.PlayerBones.Head);
                    //Get height based on the head positon, and the player position (which is always between the player's foot)
                    var height = head.Y - playerPosition.Y;
                    //Divide height by 4 to get the player's width
                    var width = height / 4;

                    //Bottom Line
                    _device.DrawLine(new RawVector2(playerPosition.X - width, playerPosition.Y), new RawVector2(playerPosition.X + width, playerPosition.Y), _brush, 2f);
                    //Top line
                    _device.DrawLine(new RawVector2(playerPosition.X - width, playerPosition.Y + height), new RawVector2(playerPosition.X + width, playerPosition.Y + height), _brush, 2f);
                    //Right line
                    _device.DrawLine(new RawVector2(playerPosition.X - width, playerPosition.Y), new RawVector2(playerPosition.X - width, playerPosition.Y + height), _brush, 2f);
                    //Left line
                    _device.DrawLine(new RawVector2(playerPosition.X + width, playerPosition.Y), new RawVector2(playerPosition.X + width, playerPosition.Y + height), _brush, 2f);

                    //Draw Health
                    _device.DrawTextLayout(new RawVector2(playerPosition.X, playerPosition.Y + 10), new TextLayout(_fontFactory, "Health: " + player.GetHealth(), _font, 50, 12), _brush);
                    //Draw Armor
                    _device.DrawTextLayout(new RawVector2(playerPosition.X, playerPosition.Y + 40), new TextLayout(_fontFactory, "Armor: " + player.GetArmor(), _font, 50, 12), _brush);
                }

                _device.EndDraw();

                Thread.Sleep(17);
            }
        }
Exemple #19
0
 public void Render()
 {
     wndRender.BeginDraw();
     wndRender.Clear(Colors.DarkBlue);
     wndRender.DrawRectangle(new SharpDX.RectangleF(10, 10, 50, 50), scenebrush, 2.00F);
     wndRender.Flush();
     wndRender.EndDraw();
 }
        /// <summary>
        /// 描画
        /// </summary>
        public void Paint()
        {
            render.BeginDraw();

            render.Clear(background);

            //Value2Map();
            var fontFactory = new SharpDX.DirectWrite.Factory();
            var textFormat  = new TextFormat(fontFactory, "メイリオ", 24.0f);

            textFormat.TextAlignment = TextAlignment.Center;
            var textBrush = new SharpDX.Direct2D1.SolidColorBrush(render, new RawColor4(1f, 1f, 1f, 1f));

            render.DrawText("ここにカルノー図が表示されます", textFormat, new RawRectangleF(10, (this.height / 2) - 12, target.Width - 10, target.Height - 10), textBrush, DrawTextOptions.None);

            render.EndDraw();
        }
Exemple #21
0
 public override void BeginDraw()
 {
     if (device == null)
     {
         throw new SharpDXException("The device was not initialized yet");
     }
     device.BeginDraw();
 }
Exemple #22
0
 //重绘
 private void Renders()
 {
     target.BeginDraw();
     target.Clear(Global.ToColor4(this.BackColor));
     for (int i = 0; i < Figures.Count; i++)
     {
     }
     target.EndDraw();
 }
        /// <summary>
        /// Do your drawing after this
        /// </summary>
        public void BeginScene()
        {
            if (this.DoResize)
            {
                this.device.Resize(new Size2(this.ResizeX, this.ResizeY));

                this.DoResize = false;
            }
            device.BeginDraw();
        }
Exemple #24
0
        private void Draw()
        {
            Converter.Render(objects, this);

            SceneBuffer.CopyFromMemory(SceneCache, 4 * Width);
            CameraView.BeginDraw();
            CameraView.Clear(new Color4(0, 0, 0, 1f));
            CameraView.DrawBitmap(SceneBuffer, 1f, BitmapInterpolationMode.Linear);
            CameraView.EndDraw();
        }
        /// <summary>
        ///     Do your drawing after this
        /// </summary>
        public void BeginScene()
        {
            if (_doResize)
            {
                _device.Resize(new Size2(_resizeX, _resizeY));

                _doResize = false;
            }
            _device.BeginDraw();
        }
Exemple #26
0
        /// <summary>
        /// 绘制图片
        /// </summary>
        /// <param name="pic1"></param>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="pic2"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        private void DrawPicture(SharpDX.Direct2D1.Bitmap pic)
        {
            _renderTarget.BeginDraw();
            _renderTarget.Clear(SharpDX.Color.White.ToColor4());

            RawRectangleF point = new RawRectangleF(0, 0, _picContainer.Width, _picContainer.Height);

            _renderTarget.DrawBitmap(pic, point, 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.NearestNeighbor);

            _renderTarget.EndDraw();
        }
Exemple #27
0
        public Example()
        {
            InitializeComponent();
            Screen[] sc;
            sc                   = Screen.AllScreens;
            this.Bounds          = sc[0].Bounds; //better results than FormWindowState.Maximum!
            this.BackColor       = System.Drawing.Color.Black;
            this.FormBorderStyle = FormBorderStyle.None;
            this.ShowIcon        = false;
            this.ShowInTaskbar   = false;
            this.TopMost         = false;
            this.WindowState     = FormWindowState.Normal;


            Win32.SetWindowLong(this.Handle, Win32.GWL_EXSTYLE, (IntPtr)(Win32.GetWindowLong(this.Handle, Win32.GWL_EXSTYLE) ^ Win32.WS_EX_LAYERED ^ Win32.WS_EX_TRANSPARENT));
            //Clickable
            Win32.SetLayeredWindowAttributes(this.Handle, 0, 255, Win32.LWA_ALPHA);

            var targetProperties = new HwndRenderTargetProperties
            {
                Hwnd           = this.Handle,
                PixelSize      = new Size2(this.Bounds.Right - this.Bounds.Left, this.Bounds.Bottom - this.Bounds.Top),
                PresentOptions = PresentOptions.Immediately
            };
            var prop = new RenderTargetProperties(RenderTargetType.Hardware, new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), 0, 0, RenderTargetUsage.None, FeatureLevel.Level_DEFAULT);

            var d3dFactory = new SharpDX.Direct2D1.Factory();

            var device = new WindowRenderTarget(d3dFactory, prop, targetProperties)
            {
                TextAntialiasMode = TextAntialiasMode.Cleartype,
                AntialiasMode     = AntialiasMode.Aliased
            };

            var dxthread = new Thread(() =>
            {
                //define your text and colors here!
                while (true)
                {
                    device.BeginDraw();
                    device.Clear(null);

                    //drawing code goes here!

                    device.EndDraw();
                    Thread.Sleep(1000 / 60);
                }
            });

            dxthread.IsBackground = true;
            dxthread.Start();
        }
Exemple #28
0
 public bool HookD2D()
 {
     Process[] RobloxIndex = Process.GetProcessesByName("RobloxPlayerBeta");
     if (RobloxIndex.Length == 0)
     {
         return(false);
     }
     else
     {
         Process Roblox = RobloxIndex[0];
         target = new WindowRenderTarget(Roblox.MainWindowHandle);
         target.BeginDraw();
         return(true);
     }
 }
Exemple #29
0
        private void sDXThread(object sender)
        {
            while (true)
            {
                device.BeginDraw();
                device.Clear(Color.Transparent);
                device.TextAntialiasMode = TextAntialiasMode.Aliased;// you can set another text mode


                //place your rendering things here

                device.EndDraw();
            }

            //whatever you want
        }
        public void Draw()
        {
            if (!Program.GameController.IsInGame)
            {
                if (!UpdateWhenIdle)
                {
                    return;
                }
            }
            device.BeginDraw();
            device.Clear(SharpDX.Color.Transparent);

            this.OnDraw(device);

            device.EndDraw();
        }
Exemple #31
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);
        }