private void canvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { canvas.ContextMenu = null; Point p = Mouse.GetPosition(canvas); var copiedCollection = new List <GraphPoint>(graphPoints); foreach (var gp in copiedCollection) { if (gp.CanRemove && p.X <= gp.PositionX + GraphConsts.PointPadding && p.X >= gp.PositionX - GraphConsts.PointPadding && p.Y <= gp.PositionY + GraphConsts.PointPadding && p.Y >= gp.PositionY - GraphConsts.PointPadding) { var removePointMenuItem = new MenuItem(); removePointMenuItem.Header = "Remove point"; var removeContextMenu = new ContextMenu(); removeContextMenu.Closed += (s, ee) => { canvas.ContextMenu = null; }; removePointMenuItem.Click += (s, ee) => { canvas.Children.Remove(gp.UIElement); graphPoints.Remove(gp); UpdateGraph(); RecalculateColorOutputFunction(); }; removeContextMenu.Items.Add(removePointMenuItem); canvas.ContextMenu = removeContextMenu; return; } } var addPointMenuItem = new MenuItem(); addPointMenuItem.Header = "Add point"; var addContextMenu = new ContextMenu(); addContextMenu.Closed += (s, ee) => { canvas.ContextMenu = null; }; addPointMenuItem.Click += (s, ee) => { var graphPoint = GraphPoint.Create(p.X, p.Y); graphPoints.Add(graphPoint); dragger.EnableDraggingOnElement(graphPoint, graphPoints); placeEllipseElement(graphPoint.UIElement, p.X, p.Y); canvas.Children.Add(graphPoint.UIElement); UpdateGraph(); RecalculateColorOutputFunction(); }; addContextMenu.Items.Add(addPointMenuItem); canvas.ContextMenu = addContextMenu; }
private void drawInversionGraphPoints() { ClearGraph(); var graphPoint1 = GraphPoint.Create(0, 255, false); var graphPoint2 = GraphPoint.Create(255, 0, false); placeEllipseElement(graphPoint1.UIElement, 0, 255); placeEllipseElement(graphPoint2.UIElement, 255, 0); canvas.Children.Add(graphPoint1.UIElement); canvas.Children.Add(graphPoint2.UIElement); graphPoints.Add(graphPoint1); graphPoints.Add(graphPoint2); }
public void EnableDraggingOnElement(GraphPoint graphPoint, List <GraphPoint> graphPoints) { Nullable <Point> dragStart = null; MouseButtonEventHandler mouseDown = (sender, args) => { var element = (UIElement)sender; dragStart = args.GetPosition(element); element.CaptureMouse(); }; MouseButtonEventHandler mouseUp = (sender, args) => { var element = (UIElement)sender; dragStart = null; element.ReleaseMouseCapture(); }; MouseEventHandler mouseMove = (sender, args) => { if (dragStart != null && args.LeftButton == MouseButtonState.Pressed) { var element = (UIElement)sender; var p2 = args.GetPosition(canvas); var newX = p2.X - dragStart.Value.X; var newY = p2.Y - dragStart.Value.Y; if (newX <= 0 || newX >= 255 || newY <= 0 || newY >= 255) { return; } graphPoint.PositionX = newX; graphPoint.PositionY = newY; Canvas.SetLeft(element, newX); Canvas.SetTop(element, newY); DragUpdated(this, null); } }; graphPoint.UIElement.MouseDown += mouseDown; graphPoint.UIElement.MouseMove += mouseMove; graphPoint.UIElement.MouseUp += mouseUp; }
private void drawBrightnessCorrectionAdditionalGraphPoints(int c) { drawInitialGraphPoints(); var graphPoint1 = GraphPoint.Create(0, c); var graphPoint2 = GraphPoint.Create(255 - c, 255); placeEllipseElement(graphPoint1.UIElement, 0, c); placeEllipseElement(graphPoint2.UIElement, 255 - c, 255); canvas.Children.Add(graphPoint1.UIElement); canvas.Children.Add(graphPoint2.UIElement); graphPoints.Add(graphPoint1); graphPoints.Add(graphPoint2); dragger.EnableDraggingOnElement(graphPoint1, graphPoints); dragger.EnableDraggingOnElement(graphPoint2, graphPoints); }
private void drawConstrastEnhancementAdditionalGraphPoints(int c) { drawInitialGraphPoints(); int cx1 = ((255 / 2) * (c - 1)) / c; int cx2 = ((255 / 2) * (c + 1)) / c; var graphPoint1 = GraphPoint.Create(cx1, 0); var graphPoint2 = GraphPoint.Create(cx2, 255); placeEllipseElement(graphPoint1.UIElement, cx1, 0); placeEllipseElement(graphPoint2.UIElement, cx2, 255); canvas.Children.Add(graphPoint1.UIElement); canvas.Children.Add(graphPoint2.UIElement); graphPoints.Add(graphPoint1); graphPoints.Add(graphPoint2); dragger.EnableDraggingOnElement(graphPoint1, graphPoints); dragger.EnableDraggingOnElement(graphPoint2, graphPoints); }