private void AddShape(BaseShape shape) { Shapes.Add(shape); CurrentShape = shape; }
private void Draw(Graphics g) { // Draw snap rectangles if (ShapeManager.IsCreating && ShapeManager.IsSnapResizing) { BaseShape shape = ShapeManager.CurrentShape; if (shape != null && shape.ShapeType != ShapeType.RegionFreehand && shape.ShapeType != ShapeType.DrawingFreehand) { 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(backgroundHighlightBrush, 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); } // Draw drawing shapes foreach (BaseDrawingShape drawingShape in ShapeManager.DrawingShapes) { drawingShape.OnDraw(g); } // Draw animated rectangle on hover area if (ShapeManager.IsCurrentHoverShapeValid) { using (GraphicsPath hoverDrawPath = new GraphicsPath { FillMode = FillMode.Winding }) { ShapeManager.CurrentHoverShape.AddShapePath(hoverDrawPath, -1); g.DrawPath(borderPen, hoverDrawPath); g.DrawPath(borderDotPen, hoverDrawPath); } } // Draw animated rectangle on selection area if (ShapeManager.IsCurrentShapeTypeRegion && ShapeManager.IsCurrentShapeValid) { g.DrawRectangleProper(borderPen, ShapeManager.CurrentRectangle); g.DrawRectangleProper(borderDotPen, ShapeManager.CurrentRectangle); if (Mode == RegionCaptureMode.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.IsCurrentHoverShapeValid && areas.All(area => area.Rectangle != ShapeManager.CurrentHoverShape.Rectangle)) { areas.Add(ShapeManager.CurrentHoverShape); } 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.ShowHotkeys) { DrawTips(g); } // Draw magnifier if (Config.ShowMagnifier || Config.ShowInfo) { DrawCursorGraphics(g); } // Draw screen wide crosshair if (Config.ShowCrosshair) { DrawCrosshair(g); } // Draw menu tooltips if (IsAnnotationMode && ShapeManager.MenuTextAnimation.Update()) { DrawTextAnimation(g, ShapeManager.MenuTextAnimation); } }
public void Update() { BaseShape shape = shapeManager.CurrentShape; if (shape != null && Visible && nodes != null) { if (InputManager.IsMouseDown(MouseButtons.Left)) { if (shape.NodeType == NodeType.Rectangle) { for (int i = 0; i < 8; i++) { if (nodes[i].IsDragging) { IsResizing = true; if (!InputManager.IsBeforeMouseDown(MouseButtons.Left)) { tempRect = shape.Rectangle; } NodePosition nodePosition = (NodePosition)i; int x = InputManager.MouseVelocity.X; switch (nodePosition) { case NodePosition.TopLeft: case NodePosition.Left: case NodePosition.BottomLeft: tempRect.X += x; tempRect.Width -= x; break; case NodePosition.TopRight: case NodePosition.Right: case NodePosition.BottomRight: tempRect.Width += x; break; } int y = InputManager.MouseVelocity.Y; switch (nodePosition) { case NodePosition.TopLeft: case NodePosition.Top: case NodePosition.TopRight: tempRect.Y += y; tempRect.Height -= y; break; case NodePosition.BottomLeft: case NodePosition.Bottom: case NodePosition.BottomRight: tempRect.Height += y; break; } shape.Rectangle = CaptureHelpers.FixRectangle(tempRect); break; } } } else if (shape.NodeType == NodeType.Line) { if (nodes[(int)NodePosition.TopLeft].IsDragging) { IsResizing = true; shape.StartPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y); } else if (nodes[(int)NodePosition.BottomRight].IsDragging) { IsResizing = true; shape.EndPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y); } } } else { IsResizing = false; } UpdateNodePositions(); } }
private void form_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.ControlKey: IsCornerMoving = true; break; case Keys.ShiftKey: IsProportionalResizing = true; break; case Keys.Menu: IsSnapResizing = true; break; case Keys.Left: case Keys.A: isLeftPressed = true; break; case Keys.Right: case Keys.D: isRightPressed = true; break; case Keys.Up: case Keys.W: isUpPressed = true; break; case Keys.Down: case Keys.S: isDownPressed = true; break; } switch (e.KeyData) { case Keys.Insert: if (IsCreating) { EndRegionSelection(); } else { StartRegionSelection(); } break; case Keys.Delete: DeleteCurrentShape(); if (IsCreating) { EndRegionSelection(); } break; case Keys.Shift | Keys.Delete: DeleteAllShapes(); break; case Keys.F1: Config.ShowHotkeys = !Config.ShowHotkeys; tsmiTips.Checked = Config.ShowHotkeys; break; } if (!IsCreating) { if (form.Mode == RegionCaptureMode.Annotation) { switch (e.KeyData) { case Keys.Tab: SwapShapeType(); break; case Keys.NumPad0: CurrentShapeType = ShapeType.RegionRectangle; break; } } if (form.IsAnnotationMode) { switch (e.KeyData) { case Keys.NumPad1: CurrentShapeType = ShapeType.DrawingRectangle; break; case Keys.NumPad2: CurrentShapeType = ShapeType.DrawingEllipse; break; case Keys.NumPad3: CurrentShapeType = ShapeType.DrawingFreehand; break; case Keys.NumPad4: CurrentShapeType = ShapeType.DrawingLine; break; case Keys.NumPad5: CurrentShapeType = ShapeType.DrawingArrow; break; case Keys.NumPad6: CurrentShapeType = ShapeType.DrawingText; break; case Keys.NumPad7: CurrentShapeType = ShapeType.DrawingStep; break; case Keys.NumPad8: CurrentShapeType = ShapeType.EffectBlur; break; case Keys.NumPad9: CurrentShapeType = ShapeType.EffectPixelate; break; case Keys.Control | Keys.V: PasteFromClipboard(); break; case Keys.Control | Keys.Z: UndoShape(); break; case Keys.Home: MoveCurrentShapeTop(); break; case Keys.End: MoveCurrentShapeBottom(); break; case Keys.PageUp: MoveCurrentShapeUp(); break; case Keys.PageDown: MoveCurrentShapeDown(); break; case Keys.Q: Config.QuickCrop = !Config.QuickCrop; tsmiQuickCrop.Checked = !Config.QuickCrop; break; } } } int speed; if (e.Shift) { speed = RegionCaptureOptions.MoveSpeedMaximum; } else { speed = RegionCaptureOptions.MoveSpeedMinimum; } int x = 0; if (isLeftPressed) { x -= speed; } if (isRightPressed) { x += speed; } int y = 0; if (isUpPressed) { y -= speed; } if (isDownPressed) { y += speed; } if (x != 0 || y != 0) { BaseShape shape = CurrentShape; if (shape == null || IsCreating) { Cursor.Position = Cursor.Position.Add(x, y); } else { if (e.Control) { shape.Move(x, y); } else { shape.Resize(x, y, !e.Alt); } } } }
private void DeselectShape(BaseShape shape) { if (shape == CurrentShape) { CurrentShape = null; NodesVisible = false; } }
public void DeleteShape(BaseShape shape) { if (shape != null) { shape.Dispose(); Shapes.Remove(shape); DeselectShape(shape); UpdateMenu(); } }
private void AddShape(BaseShape shape) { Shapes.Add(shape); CurrentShape = shape; }
private void SelectShape(BaseShape shape) { if (shape != null) { shape.ShowNodes(); } }
private void OnCurrentShapeChanged(BaseShape shape) { if (CurrentShapeChanged != null) { CurrentShapeChanged(shape); } }
private void OnShapeCreated(BaseShape shape) { if (ShapeCreated != null) { ShapeCreated(shape); } }
public void MoveShapeUp(BaseShape shape) { if (shape != null) { for (int i = 0; i < Shapes.Count - 1; i++) { if (Shapes[i] == shape) { Shapes.Move(i, ++i); return; } } } }
public void MoveShapeDown(BaseShape shape) { if (shape != null) { for (int i = 1; i < Shapes.Count; i++) { if (Shapes[i] == shape) { Shapes.Move(i, --i); return; } } } }
public void MoveShapeBottom(BaseShape shape) { if (shape != null) { for (int i = 0; i < Shapes.Count; i++) { if (Shapes[i] == shape) { Shapes.Move(i, 0); return; } } } }