Esempio n. 1
0
        private void InputOnLeftMouseButtonReleased(object sender, Blish_HUD.Input.MouseEventArgs e)
        {
            if (_screenshotPickerActive && Control.ActiveControl != null)
            {
                GameService.Graphics.QueueMainThreadRender((graphicsDevice) => {
                    var activeControl  = Control.ActiveControl;
                    var absoluteBounds = activeControl.AbsoluteBounds;

                    var bounds = absoluteBounds.WithPadding(activeControl.Padding);

                    var screenshotTarget = new RenderTarget2D(graphicsDevice,
                                                              GameService.Graphics.SpriteScreen.Width,
                                                              GameService.Graphics.SpriteScreen.Height,
                                                              false,
                                                              graphicsDevice.PresentationParameters.BackBufferFormat,
                                                              DepthFormat.Depth24);

                    graphicsDevice.SetRenderTarget(screenshotTarget);
                    graphicsDevice.Clear(Color.Transparent);

                    using (var screenshotSpriteBatch = new SpriteBatch(graphicsDevice)) {
                        //GameService.Graphics.SpriteScreen.Draw(screenshotSpriteBatch, new Rectangle(Point.Zero, GameService.Graphics.SpriteScreen.Size), new Rectangle(Point.Zero, GameService.Graphics.SpriteScreen.Size));
                        activeControl.Draw(screenshotSpriteBatch, new Rectangle(Point.Zero, activeControl.Size), new Rectangle(Point.Zero, GameService.Graphics.SpriteScreen.Size));
                    }

                    using (var pngStream = new MemoryStream()) {
                        var croppedTarget = screenshotTarget.GetRegion(bounds);

                        croppedTarget.SaveAsPng(pngStream, screenshotTarget.Width, screenshotTarget.Height);
                        pngStream.Seek(0, SeekOrigin.Begin);

                        var sysImg = System.Drawing.Image.FromStream(pngStream);

                        ClipboardUtils.SetClipboardImage(new Bitmap(sysImg), null, null);
                    }

                    ScreenNotification.ShowNotification("Screenshot copied to clipboard!");

                    graphicsDevice.SetRenderTarget(null);
                });

                _screenshotPickerActive = false;
            }
            else if (_magentaPickerActive && Control.ActiveControl != null)
            {
                Control.ActiveControl.BackgroundColor = Color.Magenta;

                _magentaPickerActive = false;
            }
            else if (_runtimeViewerPickerActive && Control.ActiveControl != null)
            {
                _toolboxForm?.SetActiveControl(Control.ActiveControl);

                _runtimeViewerPickerActive = false;
            }

            _controlHighlighter.Hide();
        }