//every pencil must be displayed in the grid (when window is initialized and user didn't use the pencil so far //and in large cavas (Name=Panel, same size as visual table) as well, so the pencil can be moved on the whole screen (not including header!!) public PencilProvider(Controller con) { this.controller = con; brush = new SolidColorBrush(Colors.Black); //initialize Images pencil = new Pencil(controller.Ui.Pencil, Colors.Gray, 2); pencil.SetOffset(0.5, -0.5); marker = new Pencil(controller.Ui.Marker, controller.Ui.Marker_Open, Color.FromArgb(100, 0, 0, 255), 10); marker.SetOffset(0.5, 0); eraser = new Pencil(controller.Ui.Eraser, Colors.White, 20); eraser.SetOffset(0.5, -0.5); hand = new Pencil(controller.Ui.handcursor, Colors.White); hand.DrawingEnabled = false; pencils = new Pencil[] {pencil, marker, eraser}; int i = 0; foreach (Pencil p in pencils) { controller.Ui.Panel.Children.Add(p.CanvasImage); Canvas.SetLeft(p.CanvasImage, controller.Ui.Panel.ActualWidth / 9 * 8); Canvas.SetTop(p.CanvasImage, controller.Ui.Panel.ActualHeight / 3 * i); i++; } controller.Ui.Panel.Children.Add(hand.CanvasImage); Canvas.SetLeft(hand.CanvasImage, controller.Ui.Panel.ActualWidth / 9 * 2); Canvas.SetTop(hand.CanvasImage, 50); cursor = hand; }
/// <summary> /// Method for changing the Pencil to the nearest Pencil next to Cursor /// </summary> /// <param name="Max_Distance">Maximum Range where pencil is grabbed</param> public void ChangeCursorToNearestPencil(double Max_Distance) { Pencil nearest = null; double nearest_distance = Max_Distance; foreach (Pencil p in pencils) { if (cursor != p) { //get difference between two pictures double distance_x = Canvas.GetLeft(p.CanvasImage) - Canvas.GetLeft(cursor.CanvasImage); distance_x = Math.Sqrt(distance_x * distance_x); double distance_y = Canvas.GetTop(p.CanvasImage) - Canvas.GetTop(cursor.CanvasImage); distance_y = Math.Sqrt(distance_y * distance_y); double distance = Math.Sqrt(distance_x * distance_x + distance_y * distance_y); if (nearest_distance >= distance) { nearest_distance = distance; nearest = p; } } } if (nearest == marker) { changeCursorToMarker(); } if (nearest == pencil) { changeCursorToPencil(); } if (nearest == eraser) { changeCursorToEraser(); } if (nearest == null) { changeCursorToHand(); } }
//function for changing the displayed cursor icon to eraser //change eraser color to white //TODO: how to erase points instead of drawing white lines?? --> if paper is switched to ColorFrame, white lines are visible //hide hand image and eraser image in grid public void changeCursorToEraser() { cursor = eraser; eraser.GrabPencil(); hand.HideAllImages(); }
//function for changing the displayed cursor icon to marker //change marker color to blue //hide hand image and marker image in grid public void changeCursorToMarker() { cursor = marker; marker.GrabPencil(controller.Ui.Marker_Cover); hand.HideAllImages(); }
//function for changing the displayed cursor icon to pencil //change pencil color to gray //hide hand image and pencil image in grid public void changeCursorToPencil() { cursor = pencil; pencil.GrabPencil(); hand.HideAllImages(); }
//function for changing the displayed cursor icon to hand image public void changeCursorToHand() { cursor = hand; hand.GrabPencil(); }
/// <summary> /// Draws a line between the two passed points in the passed color /// </summary> /// <param name="a">Position of point A</param> /// <param name="b">Position of point B</param> /// <param name="color">Color of the line</param> public void DrawLine(Point a, Point b, Pencil pencil) { if (provider.GetDrawingState()) { if (b.X > controller.Ui.canvas.ActualWidth / 100 && a.X < controller.Ui.canvas.ActualWidth - controller.Ui.canvas.ActualWidth / 100 && a.Y > controller.Ui.canvas.ActualHeight / 100 && b.Y < controller.Ui.canvas.ActualHeight - controller.Ui.canvas.ActualHeight / 100) { if (b == null || b == null || double.IsInfinity(a.X) || double.IsInfinity(b.X) || double.IsInfinity(a.Y) || double.IsInfinity(b.Y)) { return; } //create line Line line = new Line { X1 = a.X, Y1 = a.Y, X2 = b.X, Y2 = b.Y, StrokeThickness = pencil.thickness, Stroke = pencil.getBrush() }; //add line to canvas ui.canvas.Children.Add(line); } } }