Example #1
0
        public override void Prepare()
        {
            base.Prepare();

            if (Config != null)
            {
                ShapeManager = new ShapeManager(this);
                ShapeManager.WindowCaptureMode = Config.DetectWindows;
                ShapeManager.IncludeControls   = Config.DetectControls;

                if (Mode == RectangleRegionMode.Annotation)
                {
                    ShapeManager.CurrentShapeTypeChanged += ShapeManager_CurrentShapeTypeChanged;
                }

                if (Mode == RectangleRegionMode.OneClick || ShapeManager.WindowCaptureMode)
                {
                    IntPtr handle = Handle;

                    TaskEx.Run(() =>
                    {
                        WindowsRectangleList wla = new WindowsRectangleList();
                        wla.IgnoreHandle         = handle;
                        wla.IncludeChildWindows  = ShapeManager.IncludeControls;
                        ShapeManager.Windows     = wla.GetWindowInfoListAsync(5000);
                    });
                }

                if (Config.UseCustomInfoText || Mode == RectangleRegionMode.ScreenColorPicker)
                {
                    bmpBackgroundImage = new Bitmap(backgroundImage);
                }
            }
        }
Example #2
0
 public ScrollbarManager(RegionCaptureForm regionCaptureForm, ShapeManager shapeManager)
 {
     form = regionCaptureForm;
     horizontalScrollbar = new ImageEditorScrollbar(Orientation.Horizontal, form);
     shapeManager.DrawableObjects.Add(horizontalScrollbar);
     verticalScrollbar = new ImageEditorScrollbar(Orientation.Vertical, form);
     shapeManager.DrawableObjects.Add(verticalScrollbar);
 }
Example #3
0
        private new void Update()
        {
            if (!timerStart.IsRunning)
            {
                timerStart.Start();
                timerFPS.Start();
            }

            InputManager.Update();

            DrawableObject[] objects = DrawableObjects.OrderByDescending(x => x.Order).ToArray();

            if (objects.All(x => !x.IsDragging))
            {
                for (int i = 0; i < objects.Count(); i++)
                {
                    DrawableObject obj = objects[i];

                    if (obj.Visible)
                    {
                        obj.IsCursorHover = obj.Rectangle.Contains(InputManager.MousePosition0Based);

                        if (obj.IsCursorHover)
                        {
                            if (InputManager.IsMousePressed(MouseButtons.Left))
                            {
                                obj.IsDragging = true;
                            }

                            for (int y = i + 1; y < objects.Count(); y++)
                            {
                                objects[y].IsCursorHover = false;
                            }

                            break;
                        }
                    }
                }
            }
            else
            {
                if (InputManager.IsMouseReleased(MouseButtons.Left))
                {
                    foreach (DrawableObject obj in objects)
                    {
                        obj.IsDragging = false;
                    }
                }
            }

            borderDotPen.DashOffset = (float)timerStart.Elapsed.TotalSeconds * -15;

            ShapeManager.Update();
        }
Example #4
0
        public virtual BaseShape Duplicate()
        {
            ShapeManager manager = Manager;

            Manager = null;
            BaseShape shape = this.Copy();

            Manager       = manager;
            shape.Manager = manager;
            return(shape);
        }
Example #5
0
        private void RegionCaptureForm_MouseDown(object sender, MouseEventArgs e)
        {
            if ((Mode == RegionCaptureMode.OneClick || Mode == RegionCaptureMode.ScreenColorPicker) && e.Button == MouseButtons.Left)
            {
                CurrentPosition = InputManager.MousePosition;

                if (Mode == RegionCaptureMode.OneClick)
                {
                    SelectedWindow = ShapeManager.FindSelectedWindow();
                }

                Close(RegionResult.Region);
            }
        }
Example #6
0
        public ResizeManager(BaseRegionForm form, ShapeManager shapeManager)
        {
            this.shapeManager = shapeManager;

            form.KeyDown += form_KeyDown;
            form.KeyUp += form_KeyUp;

            nodes = new NodeObject[8];

            for (int i = 0; i < 8; i++)
            {
                nodes[i] = form.MakeNode();
            }

            nodes[(int)NodePosition.BottomRight].Order = 10;
        }
Example #7
0
        public ResizeManager(BaseRegionForm form, ShapeManager shapeManager)
        {
            this.shapeManager = shapeManager;

            form.KeyDown += form_KeyDown;
            form.KeyUp   += form_KeyUp;

            nodes = new NodeObject[8];

            for (int i = 0; i < 8; i++)
            {
                nodes[i] = form.MakeNode();
            }

            nodes[(int)NodePosition.BottomRight].Order = 10;
        }
Example #8
0
 public WindowInfo GetWindowInfo()
 {
     return(ShapeManager.FindSelectedWindowInfo(CurrentPosition));
 }
Example #9
0
        // Must be called before show form
        public void Prepare(Image img)
        {
            Image = img;

            if (IsEditorMode)
            {
                Rectangle rect = CaptureHelpers.GetActiveScreenBounds0Based();

                if (Image.Width > rect.Width || Image.Height > rect.Height)
                {
                    rect = ScreenRectangle0Based;
                }

                ImageRectangle = new Rectangle(rect.X + rect.Width / 2 - Image.Width / 2, rect.Y + rect.Height / 2 - Image.Height / 2, Image.Width, Image.Height);

                using (Image background = ImageHelpers.DrawCheckers(ScreenRectangle0Based.Width, ScreenRectangle0Based.Height))
                    using (Graphics g = Graphics.FromImage(background))
                    {
                        g.DrawImage(Image, ImageRectangle);

                        backgroundBrush = new TextureBrush(background)
                        {
                            WrapMode = WrapMode.Clamp
                        };
                    }
            }
            else if (Config.UseDimming)
            {
                using (Bitmap darkBackground = (Bitmap)Image.Clone())
                    using (Graphics g = Graphics.FromImage(darkBackground))
                        using (Brush brush = new SolidBrush(Color.FromArgb(30, Color.Black)))
                        {
                            g.FillRectangle(brush, 0, 0, darkBackground.Width, darkBackground.Height);

                            backgroundBrush = new TextureBrush(darkBackground)
                            {
                                WrapMode = WrapMode.Clamp
                            };
                        }

                backgroundHighlightBrush = new TextureBrush(Image)
                {
                    WrapMode = WrapMode.Clamp
                };
            }
            else
            {
                backgroundBrush = new TextureBrush(Image)
                {
                    WrapMode = WrapMode.Clamp
                };
            }

            ShapeManager = new ShapeManager(this);
            ShapeManager.WindowCaptureMode = Config.DetectWindows;
            ShapeManager.IncludeControls   = Config.DetectControls;

            if (Mode == RegionCaptureMode.OneClick || ShapeManager.WindowCaptureMode)
            {
                IntPtr handle = Handle;

                TaskEx.Run(() =>
                {
                    WindowsRectangleList wla = new WindowsRectangleList();
                    wla.IgnoreHandle         = handle;
                    wla.IncludeChildWindows  = ShapeManager.IncludeControls;
                    ShapeManager.Windows     = wla.GetWindowInfoListAsync(5000);
                });
            }

            if (Config.UseCustomInfoText || Mode == RegionCaptureMode.ScreenColorPicker)
            {
                bmpBackgroundImage = new Bitmap(Image);
            }
        }
Example #10
0
        protected override void Dispose(bool disposing)
        {
            if (ShapeManager != null)
            {
                ShapeManager.Dispose();
            }

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

            if (disposing && (components != null))
            {
                components.Dispose();
            }

            if (backgroundBrush != null)
            {
                backgroundBrush.Dispose();
            }
            if (backgroundHighlightBrush != null)
            {
                backgroundHighlightBrush.Dispose();
            }
            if (borderPen != null)
            {
                borderPen.Dispose();
            }
            if (borderDotPen != null)
            {
                borderDotPen.Dispose();
            }
            if (nodeBackgroundBrush != null)
            {
                nodeBackgroundBrush.Dispose();
            }
            if (infoFont != null)
            {
                infoFont.Dispose();
            }
            if (infoFontMedium != null)
            {
                infoFontMedium.Dispose();
            }
            if (infoFontBig != null)
            {
                infoFontBig.Dispose();
            }
            if (textBackgroundBrush != null)
            {
                textBackgroundBrush.Dispose();
            }
            if (textOuterBorderPen != null)
            {
                textOuterBorderPen.Dispose();
            }
            if (textInnerBorderPen != null)
            {
                textInnerBorderPen.Dispose();
            }
            if (markerPen != null)
            {
                markerPen.Dispose();
            }

            if (regionFillPath != null)
            {
                if (Result == RegionResult.Region)
                {
                    if (LastRegionFillPath != null)
                    {
                        LastRegionFillPath.Dispose();
                    }

                    LastRegionFillPath = regionFillPath;
                }
                else
                {
                    regionFillPath.Dispose();
                }
            }

            if (regionDrawPath != null)
            {
                regionDrawPath.Dispose();
            }
            if (Image != null)
            {
                Image.Dispose();
            }

            base.Dispose(disposing);
        }
Example #11
0
 private Image GetOutputImage()
 {
     return(ShapeManager.RenderOutputImage(Image));
 }
Example #12
0
        public override void Prepare()
        {
            base.Prepare();

            if (Config != null)
            {
                ShapeManager = new ShapeManager(this);
                ShapeManager.WindowCaptureMode = Config.DetectWindows;
                ShapeManager.IncludeControls = Config.DetectControls;

                if (Mode == RectangleRegionMode.Annotation)
                {
                    ShapeManager.CurrentShapeTypeChanged += ShapeManager_CurrentShapeTypeChanged;
                }

                if (Mode == RectangleRegionMode.OneClick || ShapeManager.WindowCaptureMode)
                {
                    IntPtr handle = Handle;

                    TaskEx.Run(() =>
                    {
                        WindowsRectangleList wla = new WindowsRectangleList();
                        wla.IgnoreHandle = handle;
                        wla.IncludeChildWindows = ShapeManager.IncludeControls;
                        ShapeManager.Windows = wla.GetWindowInfoListAsync(5000);
                    });
                }

                if (Config.UseCustomInfoText || Mode == RectangleRegionMode.ScreenColorPicker)
                {
                    bmpBackgroundImage = new Bitmap(backgroundImage);
                }
            }
        }
Example #13
0
 protected override Image GetOutputImage()
 {
     return(ShapeManager.RenderOutputImage(backgroundImage));
 }
Example #14
0
        protected override void Draw(Graphics g)
        {
            // Draw snap rectangles
            if (ShapeManager.IsCreating && ShapeManager.IsSnapResizing)
            {
                BaseShape shape = ShapeManager.CurrentShape;

                if (shape != null)
                {
                    foreach (Size size in Config.SnapSizes)
                    {
                        Rectangle snapRect = CaptureHelpers.CalculateNewRectangle(shape.StartPosition, shape.EndPosition, size);
                        g.DrawRectangleProper(markerPen, snapRect);
                    }
                }
            }

            List <BaseShape> areas = ShapeManager.ValidRegions.ToList();

            if (areas.Count > 0)
            {
                // Create graphics path from all regions
                UpdateRegionPath();

                // If background is dimmed then draw non dimmed background to region selections
                if (Config.UseDimming)
                {
                    using (Region region = new Region(regionDrawPath))
                    {
                        g.Clip = region;
                        g.FillRectangle(lightBackgroundBrush, ScreenRectangle0Based);
                        g.ResetClip();
                    }
                }

                // Blink borders of all regions slightly to make non active regions to be visible in both dark and light backgrounds
                using (Pen blinkBorderPen = new Pen(colorBlinkAnimation.GetColor()))
                {
                    g.DrawPath(blinkBorderPen, regionDrawPath);
                }
            }

            // Draw effect shapes
            foreach (BaseEffectShape effectShape in ShapeManager.EffectShapes)
            {
                effectShape.OnDraw(g);
            }

            ShapeManager.OrderStepShapes();

            // Draw drawing shapes
            foreach (BaseDrawingShape drawingShape in ShapeManager.DrawingShapes)
            {
                drawingShape.OnDraw(g);
            }

            // Draw animated rectangle on hover area
            if (ShapeManager.IsCurrentHoverAreaValid)
            {
                using (GraphicsPath hoverDrawPath = new GraphicsPath {
                    FillMode = FillMode.Winding
                })
                {
                    ShapeManager.CreateShape(ShapeManager.CurrentHoverRectangle).AddShapePath(hoverDrawPath, -1);

                    g.DrawPath(borderPen, hoverDrawPath);
                    g.DrawPath(borderDotPen, hoverDrawPath);
                }
            }

            // Draw animated rectangle on selection area
            if (ShapeManager.IsCurrentShapeTypeRegion && ShapeManager.IsCurrentRectangleValid)
            {
                g.DrawRectangleProper(borderPen, ShapeManager.CurrentRectangle);
                g.DrawRectangleProper(borderDotPen, ShapeManager.CurrentRectangle);

                if (Mode == RectangleRegionMode.Ruler)
                {
                    DrawRuler(g, ShapeManager.CurrentRectangle, borderPen, 5, 10);
                    DrawRuler(g, ShapeManager.CurrentRectangle, borderPen, 15, 100);

                    Point centerPos = new Point(ShapeManager.CurrentRectangle.X + ShapeManager.CurrentRectangle.Width / 2, ShapeManager.CurrentRectangle.Y + ShapeManager.CurrentRectangle.Height / 2);
                    int   markSize  = 10;
                    g.DrawLine(borderPen, centerPos.X, centerPos.Y - markSize, centerPos.X, centerPos.Y + markSize);
                    g.DrawLine(borderPen, centerPos.X - markSize, centerPos.Y, centerPos.X + markSize, centerPos.Y);
                }
            }

            // Draw all regions rectangle info
            if (Config.ShowInfo)
            {
                // Add hover area to list so rectangle info can be shown
                if (ShapeManager.IsCurrentShapeTypeRegion && ShapeManager.IsCurrentHoverAreaValid && areas.All(area => area.Rectangle != ShapeManager.CurrentHoverRectangle))
                {
                    BaseShape shape = ShapeManager.CreateShape(ShapeManager.CurrentHoverRectangle);
                    areas.Add(shape);
                }

                foreach (BaseShape regionInfo in areas)
                {
                    if (regionInfo.Rectangle.IsValid())
                    {
                        string areaText = GetAreaText(regionInfo.Rectangle);
                        DrawAreaText(g, areaText, regionInfo.Rectangle);
                    }
                }
            }

            // Draw resize nodes
            DrawObjects(g);

            // Draw F1 tips
            if (Config.ShowTips)
            {
                DrawTips(g);
            }

            if (Mode == RectangleRegionMode.Annotation)
            {
                if (Config.ShowMenuTip)
                {
                    // Draw right click menu tip
                    DrawMenuTip(g);
                }
                else
                {
                    // If current shape changed then draw it temporary
                    DrawCurrentShapeText(g);
                }
            }

            // Draw magnifier
            if (Config.ShowMagnifier)
            {
                DrawMagnifier(g);
            }

            // Draw screen wide crosshair
            if (Config.ShowCrosshair)
            {
                DrawCrosshair(g);
            }
        }
Example #15
0
 protected override void Update()
 {
     base.Update();
     ShapeManager.Update();
 }
Example #16
0
        // Must be called before show form
        public void Prepare(Image img)
        {
            Image = img;

            if (Mode == RegionCaptureMode.Editor)
            {
                Rectangle rect = CaptureHelpers.GetActiveScreenBounds0Based();

                if (Image.Width > rect.Width || Image.Height > rect.Height)
                {
                    rect = ScreenRectangle0Based;
                }

                ImageRectangle = new Rectangle(rect.X + rect.Width / 2 - Image.Width / 2, rect.Y + rect.Height / 2 - Image.Height / 2, Image.Width, Image.Height);

                using (Image background = ImageHelpers.DrawCheckers(ScreenRectangle0Based.Width, ScreenRectangle0Based.Height))
                using (Graphics g = Graphics.FromImage(background))
                {
                    g.DrawImage(Image, ImageRectangle);

                    backgroundBrush = new TextureBrush(background) { WrapMode = WrapMode.Clamp };
                }
            }
            else if (Config.UseDimming)
            {
                using (Bitmap darkBackground = (Bitmap)Image.Clone())
                using (Graphics g = Graphics.FromImage(darkBackground))
                using (Brush brush = new SolidBrush(Color.FromArgb(30, Color.Black)))
                {
                    g.FillRectangle(brush, 0, 0, darkBackground.Width, darkBackground.Height);

                    backgroundBrush = new TextureBrush(darkBackground) { WrapMode = WrapMode.Clamp };
                }

                backgroundHighlightBrush = new TextureBrush(Image) { WrapMode = WrapMode.Clamp };
            }
            else
            {
                backgroundBrush = new TextureBrush(Image) { WrapMode = WrapMode.Clamp };
            }

            ShapeManager = new ShapeManager(this);
            ShapeManager.WindowCaptureMode = Config.DetectWindows;
            ShapeManager.IncludeControls = Config.DetectControls;

            if (Mode == RegionCaptureMode.OneClick || ShapeManager.WindowCaptureMode)
            {
                IntPtr handle = Handle;

                TaskEx.Run(() =>
                {
                    WindowsRectangleList wla = new WindowsRectangleList();
                    wla.IgnoreHandle = handle;
                    wla.IncludeChildWindows = ShapeManager.IncludeControls;
                    ShapeManager.Windows = wla.GetWindowInfoListAsync(5000);
                });
            }

            if (Config.UseCustomInfoText || Mode == RegionCaptureMode.ScreenColorPicker)
            {
                bmpBackgroundImage = new Bitmap(Image);
            }
        }