private void DupliquerSelection(object sender, RoutedEventArgs e) { VueModele vueModele = ((VueModele)this.DataContext); List <CustomStroke> selectedStrokes = vueModele.Traits.Where(stroke => ((CustomStroke)stroke).isSelected()).Cast <CustomStroke>().ToList(); //If no stroke is selected ==> Cut/Paste operation if (selectedStrokes.Count == 0) { vueModele.Traits.Add(ClipBoard); ClipBoard.ToList().ForEach(stroke => { EditionSocket.AddStroke(((Savable)stroke).toJson()); Editeur.instance.Do(new NewStroke(((CustomStroke)stroke).Id.ToString(), ((Savable)stroke).toJson())); }); ClipBoard.Clear(); } else { EditionSocket.UnlockStrokes(); vueModele.editeur.EditingStroke = null; selectedStrokes.ForEach(stroke => { CustomStroke duplicate = stroke.Duplicate(); ((VueModele)this.DataContext).Traits.Add(duplicate); duplicate.Select(); EditionSocket.AddStroke(((Savable)duplicate).toJson()); Editeur.instance.Do(new NewStroke(((CustomStroke)duplicate).Id.ToString(), ((Savable)duplicate).toJson())); }); } }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { CustomStroke parent = this.strokes.get(this.ParentId); if (parent is ShapeStroke) { drawingContext.PushTransform(new RotateTransform(((ShapeStroke)parent).Rotation, ((ShapeStroke)parent).Center.X, ((ShapeStroke)parent).Center.Y)); } DrawingAttributes originalDa = drawingAttributes.Clone(); Pen pen = new Pen(new SolidColorBrush(Colors.Gray), 1.5); Point up = this.StylusPoints[0].ToPoint(); up.Y = up.Y - 6; Point down = this.StylusPoints[0].ToPoint(); down.Y = down.Y + 6; Point left = this.StylusPoints[0].ToPoint(); left.X = left.X - 6; Point right = this.StylusPoints[0].ToPoint(); right.X = right.X + 6; drawingContext.DrawLine(pen, left, right); drawingContext.DrawLine(pen, up, down); if (parent is ShapeStroke) { drawingContext.Pop(); } }
public void setParameters(CustomStroke stroke) { _label = stroke.name; _borderColor = (Color)ColorConverter.ConvertFromString((stroke as ShapeStroke).shapeStyle.borderColor); _fillColor = (Color)ColorConverter.ConvertFromString((stroke as ShapeStroke).shapeStyle.backgroundColor); switch ((stroke as ShapeStroke).shapeStyle.borderStyle) { case (int)LineStyles.FULL: _lineStyle = "Full"; break; case (int)LineStyles.DASHED: _lineStyle = "Dashed"; break; case (int)LineStyles.DOTTED: _lineStyle = "Dotted"; break; default: _lineStyle = "Full"; break; } _lineStylesList = new List <string> { "Full", "Dashed" }; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Label")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("BorderColor")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("FillColor")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LineStyle")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LineStylesList")); }
private void MergeStrokes(DrawingAttributes attr) { try { StylusPointCollection points = new StylusPointCollection(); StrokeCollection strokesToRemove = new StrokeCollection(); foreach (CustomStroke trait in Traits) { if (trait.uid == currentStrokeId) { points.Add(trait.StylusPoints); strokesToRemove.Add(trait); } } CustomStroke fullStroke = new CustomStroke(points, attr); fullStroke.uid = currentStrokeId; App.Current.Dispatcher.Invoke(delegate { Traits.Add(fullStroke); Traits.Remove(strokesToRemove); }); currentStrokeId = Guid.NewGuid(); } catch (Exception) { App.Current.Dispatcher.Invoke(delegate { Traits.Clear(); }); } }
private void Canvas_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e) { Point point = e.GetPosition((IInputElement)sender); CustomStroke clicked = null; Canvas.Strokes.ToList().ForEach(stroke => { CustomStroke customStroke = (CustomStroke)stroke; if (!customStroke.isSelectable()) { return; } if (!customStroke.HitTest(point)) { return; } clicked = customStroke; }); if (clicked != null) { ((VueModele)this.DataContext).Edit.Execute(clicked); } }
public void SendNewStroke(CustomStroke stroke) { //drawingService.createStroke(); Coordinates coordinates = new Coordinates(stroke.StylusPoints[0].X, stroke.StylusPoints[0].Y); ShapeStyle shapeStyle = new ShapeStyle(); shapeStyle.coordinates = coordinates; }
private void SetStroke() { if (_Stroke != null) { InkCanvas_StrokeCollected(_InkCanvas, new InkCanvasStrokeCollectedEventArgs(_Stroke)); _Stroke = null; } }
private void OpenFile(string _FilePath) //Loaddata { if (!File.Exists(_FilePath)) { Trace.WriteLine("file not exists " + _FilePath); return; } byte[] _Buffer = File.ReadAllBytes(_FilePath); MemoryStream _MemoryStream = new MemoryStream(_Buffer); _MapDatabase = (MapDatabase)_XmlSerializer.Deserialize(_MemoryStream); _InkCanvas.Strokes.Clear(); InkCanvas.SetLeft(_CStartPos, _MapDatabase._CStartPos.X); InkCanvas.SetTop(_CStartPos, _MapDatabase._CStartPos.Y); InkCanvas.SetLeft(_TStartPos, _MapDatabase._TStartPos.X); InkCanvas.SetTop(_TStartPos, _MapDatabase._TStartPos.Y); for (int i = 0; i < _MapDatabase._Layers.Count; i++) { MapDatabase.Layer _Layer = _MapDatabase._Layers[i]; InkCanvas _InkCanvas1 = (InkCanvas)_CanvasList.Children[i]; foreach (MapDatabase.Image _DImage in _Layer._Images) { Image _Image = new Image(); if (!File.Exists(_DImage.Path)) { Debugger.Break(); } BitmapImage _BitmapImage = new BitmapImage(new Uri(_DImage.Path, UriKind.Relative)); double a = _BitmapImage.Width; _Image.Source = _BitmapImage; _Image.Width = _DImage.Width; _Image.Height = _DImage.Height; InkCanvas.SetLeft(_Image, _DImage.X); InkCanvas.SetTop(_Image, _DImage.Y); _InkCanvas1.Children.Add(_Image); } foreach (MapDatabase.Polygon _Polygon in _Layer._Polygons) { StylusPointCollection _StylusPointCollection = new StylusPointCollection(); foreach (Point _Point in _Polygon._Points) { StylusPoint _StylusPoint = new StylusPoint(_Point.X, _Point.Y); _StylusPointCollection.Add(_StylusPoint); } CustomStroke _Stroke = new CustomStroke(_StylusPointCollection); _Stroke.DrawingAttributes.Color = _Polygon._Color; _InkCanvas1.Strokes.Add(_Stroke); } } }
public override void Undo(CustomStrokeCollection strokes) { if (strokes.has(Id)) { CustomStroke old = strokes.get(Id); if (old.isLocked()) { throw new Exception("Stroke is Locked"); } strokes.Remove(strokes.get(Id)); EditionSocket.RemoveStroke(Id); } }
private void Canvas_StrokeErasing(object sender, InkCanvasStrokeErasingEventArgs e) { VueModele vueModele = ((VueModele)this.DataContext); //Empiler la modification if (e.Stroke is Savable && !((CustomStroke)e.Stroke).isLocked()) { CustomStroke erasedStroke = (CustomStroke)e.Stroke; vueModele.editeur.Do(new DeleteStroke(erasedStroke.Id.ToString(), ((Savable)erasedStroke).toJson())); EditionSocket.RemoveStroke(erasedStroke.Id.ToString()); } else if (((CustomStroke)e.Stroke).isLocked()) { e.Cancel = true; } }
public override void Undo(CustomStrokeCollection strokes) { if (strokes.has(Id)) { CustomStroke old = strokes.get(Id); if (old.isLocked()) { throw new Exception("Stroke is Locked"); } EditionSocket.EditStroke(SerializedStrokeBefore); CustomStroke updated = SerializationHelper.stringToStroke(JObject.Parse(SerializedStrokeBefore), strokes); bool selected = ((CustomStroke)old).isSelected(); bool editting = ((CustomStroke)old).isEditing(); ((CustomStroke)old).stopEditing(); strokes.Remove(strokes.get(Id)); int newindex = strokes.ToList().FindIndex(stroke => ((CustomStroke)stroke).Index > updated.Index); try { strokes.Insert(newindex, updated); } catch { strokes.Add(updated); } if (selected) { strokes.get(updated.Id.ToString()).Select(); } if (editting) { strokes.get(updated.Id.ToString()).startEditing(); } if (updated is Anchorable) { strokes.ToList().FindAll(stroke => stroke is BaseLine).ForEach(stroke => ((BaseLine)stroke).anchorableMoved((Anchorable)updated)); } } }
public void DrawTextInRectangle(object sender, RoutedEventArgs e) { StylusPointCollection pts = new StylusPointCollection(); pts.Add(new StylusPoint(100, 100)); pts.Add(new StylusPoint(100, 300)); pts.Add(new StylusPoint(300, 300)); pts.Add(new StylusPoint(300, 100)); pts.Add(new StylusPoint(100, 100)); CustomStroke st = new CustomStroke(pts); st.DrawingAttributes.Color = Colors.Red; inkCanvas1.Strokes.Add(st); }
private void ReceiveDrawingInk(JObject data) { try { double?X1 = (double?)data.GetValue("startPosX"); double?X2 = (double?)data.GetValue("endPosX"); double?Y1 = (double?)data.GetValue("startPosY"); double?Y2 = (double?)data.GetValue("endPosY"); if (!(X1.HasValue && X2.HasValue && Y1.HasValue && Y2.HasValue)) { return; } StylusPointCollection coll = new StylusPointCollection(); coll.Add(new StylusPoint(X1.Value, Y1.Value)); coll.Add(new StylusPoint(X2.Value, Y2.Value)); DrawingAttributes attr = new DrawingAttributes(); attr.Color = (Color)ColorConverter.ConvertFromString((string)data.GetValue("color")); attr.Height = (double)data.GetValue("width"); attr.Width = attr.Height; attr.StylusTip = (string)data.GetValue("format") == "circle" ? StylusTip.Ellipse : StylusTip.Rectangle; CustomStroke str = new CustomStroke(coll, attr); str.uid = currentStrokeId; App.Current.Dispatcher.Invoke(delegate { Traits.Add(str); }); if ((bool)data.GetValue("isEnd")) { MergeStrokes(attr); } } catch (Exception) { // fail silently } }
public static void Post(CustomStroke customStroke) { var request = new RestRequest(Settings.API_VERSION + Settings.SHAPE_OBJECT_PATH, Method.POST); if (customStroke is ShapeStroke) { request.AddJsonBody(((ShapeStroke)customStroke).toJson()); } else if (customStroke is BaseLine) { request.AddJsonBody(((BaseLine)customStroke).toJson()); } ServerService.instance.server.ExecuteAsync(request, response => { Application.Current.Dispatcher.Invoke(() => { if (response.StatusCode != HttpStatusCode.Created) { MessageBox.Show("Could not save the image", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }); }); }
// Quand une nouvelle nouvelle stroke a ete ajoute private void surfaceDessin_OnMouseUp(object sender, MouseButtonEventArgs e) { if ((DataContext as VueModele)?.OutilSelectionne == "crayon" && surfaceDessin.SelectedStrokes.Count > 0) { CustomStroke newStroke = (DataContext as VueModele).AddStrokeFromView( (CustomStroke)surfaceDessin.SelectedStrokes[0] ); surfaceDessin.Select(new StrokeCollection { newStroke }); if (newStroke.GetType() != typeof(LinkStroke)) { Path path = new Path(); path.Data = new RectangleGeometry(newStroke.GetBounds()); surfaceDessin.Children.Add(path); AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(path); myAdornerLayer.Add(new RotateAdorner(path, newStroke, surfaceDessin)); myAdornerLayer.Add(new AnchorPointAdorner(path, newStroke, surfaceDessin)); Adorner[] ad = myAdornerLayer.GetAdorners(path); myAdornerLayer.Add(new EditionAdorner(path, newStroke, surfaceDessin)); } } else { foreach (CustomStroke stroke in surfaceDessin.GetSelectedStrokes()) { if (stroke is LinkStroke) { surfaceDessin.modifyLinkStrokePath(stroke as LinkStroke, e.GetPosition(surfaceDessin)); } } } // Pour que les boutons soient de la bonne couleur (DataContext as VueModele)?.ChoisirOutil.Execute("lasso"); }
public override bool HitTest(Point point) { if (!this.strokes.has(this.ParentId)) { return(false); } CustomStroke parent = this.strokes.get(this.ParentId); Point thisDisplayedPosition; if (parent is ShapeStroke) { ShapeStroke shapeParent = (ShapeStroke)parent; Matrix rotationMatix = new Matrix(); rotationMatix.RotateAt(shapeParent.Rotation, shapeParent.Center.X, shapeParent.Center.Y); thisDisplayedPosition = rotationMatix.Transform(this.StylusPoints[0].ToPoint()); } else { thisDisplayedPosition = this.StylusPoints[0].ToPoint(); } return(6 > Math.Sqrt(Math.Pow(point.X - thisDisplayedPosition.X, 2) + Math.Pow(point.Y - thisDisplayedPosition.Y, 2))); }
private void Canvas_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { Point point = e.GetPosition((IInputElement)sender); CustomStroke scrolled = null; Canvas.Strokes.ToList().ForEach(stroke => { CustomStroke customStroke = (CustomStroke)stroke; if (!customStroke.isSelected()) { return; } if (!customStroke.HitTest(point)) { return; } scrolled = customStroke; }); /* UNCOMMENT TO ENABLE ROTATING */ //if (scrolled is ShapeStroke) // ((ShapeStroke)scrolled).Rotation = ((ShapeStroke)scrolled).Rotation += e.Delta / 8.0; }
public static void Initialize(object o) { socket.On(Socket.EVENT_RECONNECT, () => { if (canvasName != null) { // Stocker le mot de passe? ADD JoinCanvas(canvasName, ""); } }); #region canvas .On socket.On("createCanvasResponse", (data) => { CreateCanvasResponse response = serializer.Deserialize <CreateCanvasResponse>((string)data); if (response.isCreated) { canvasName = response.canvasName; RefreshCanvases(); } else { Application.Current?.Dispatcher?.Invoke(new Action(() => { CanvasCreationFailed(); }), DispatcherPriority.Render); } }); socket.On("canvasCreated", (data) => { RefreshCanvases(); }); socket.On("updateCanvasPasswordResponse", (data) => { UpdateCanvasPasswordResponse response = serializer.Deserialize <UpdateCanvasPasswordResponse>((string)data); if (response.isPasswordUpdated) { RefreshCanvases(); } }); socket.On("canvasPasswordUpdated", (data) => { LeaveCanvas(); Application.Current?.Dispatcher?.Invoke(new Action(() => { BackToGallery(); }), DispatcherPriority.Render); }); socket.On("accessCanvasResponse", (data) => { AccessCanvasResponse response = serializer.Deserialize <AccessCanvasResponse>((string)data); if (response.isPasswordValid) { canvasName = response.canvasName; } Application.Current?.Dispatcher?.Invoke(new Action(() => { JoinCanvasRoom(response); }), DispatcherPriority.Render); }); socket.On("canvasSelected", (data) => { EditGalleryData response = serializer.Deserialize <EditGalleryData>((string)data); if (!username.Equals((string)response.username) && response.canevasName.Equals(canvasName)) { isCanvasSizeRemotelyEditing = true; } }); socket.On("canvasDeselected", (data) => { EditGalleryData response = serializer.Deserialize <EditGalleryData>((string)data); if (!username.Equals((string)response.username) && response.canevasName.Equals(canvasName)) { isCanvasSizeRemotelyEditing = false; } }); socket.On("canvasResized", (data) => { ResizeCanevasData response = serializer.Deserialize <ResizeCanevasData>((string)data); if (username != null && !username.Equals((string)response.username)) { Application.Current?.Dispatcher?.Invoke(new Action(() => { OnResizeCanvas(response.dimensions); }), DispatcherPriority.Render); } }); socket.On("getPublicCanvasResponse", (data) => { PublicCanvases canvases = serializer.Deserialize <PublicCanvases>((string)data); ExtractCanvasesShapes(canvases.publicCanvas); try { Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdatePublicCanvases(canvases); }), DispatcherPriority.Render); } catch { } }); socket.On("getPrivateCanvasResponse", (data) => { PrivateCanvases canvases = serializer.Deserialize <PrivateCanvases>((string)data); ExtractCanvasesShapes(canvases.privateCanvas); Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdatePrivateCanvases(canvases); }), DispatcherPriority.Render); }); #endregion #region links .On socket.On("linkCreated", (data) => { dynamic response = JObject.Parse((string)data); if (!username.Equals((string)response.username)) { LinkStroke linkStroke = createLinkStroke(response.links[0]); linkStroke.owner = response.username; InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(linkStroke); Application.Current?.Dispatcher?.Invoke(new Action(() => { AddStroke(eventArgs); }), DispatcherPriority.ContextIdle); } }); socket.On("linksDeleted", (data) => { dynamic response = JObject.Parse((string)data); if (!username.Equals((string)response.username)) { StrokeCollection strokes = new StrokeCollection(); foreach (dynamic link in response.links) { strokes.Add(createLinkStroke(link)); } Application.Current?.Dispatcher?.Invoke(new Action(() => { RemoveStrokes(strokes); }), DispatcherPriority.ContextIdle); } }); socket.On("linksUpdated", (data) => { dynamic response = JObject.Parse((string)data); if (!username.Equals((string)response.username)) { foreach (dynamic link in response.links) { InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(createLinkStroke(link)); Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateStroke(eventArgs); }), DispatcherPriority.Render); } } }); socket.On("linksSelected", (data) => { dynamic response = JObject.Parse((string)data); if (!username.Equals((string)response.username)) { StrokeCollection strokes = new StrokeCollection(); foreach (dynamic link in response.links) { LinkStroke linkStroke = createLinkStroke(link); strokes.Add(linkStroke); if (!remoteSelectedStrokes.Contains(linkStroke.guid.ToString())) { remoteSelectedStrokes.Add(linkStroke.guid.ToString()); } Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateSelection(); }), DispatcherPriority.Render); } } }); socket.On("linksDeselected", (data) => { dynamic response = JObject.Parse((string)data); if (!username.Equals((string)response.username)) { StrokeCollection strokes = new StrokeCollection(); foreach (dynamic link in response.links) { LinkStroke linkStroke = createLinkStroke(link); strokes.Add(linkStroke); if (remoteSelectedStrokes.Contains(linkStroke.guid.ToString())) { remoteSelectedStrokes.Remove(linkStroke.guid.ToString()); } Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateDeselection(); }), DispatcherPriority.Render); } } }); #endregion #region forms .On socket.On("formCreated", (data) => { dynamic response = JObject.Parse((string)data); //Console.WriteLine("FORM CREATED: \n" + "position: " + response.forms[0].shapeStyle.coordinates.x + ", " // + response.forms[0].shapeStyle.coordinates.y + "/n" + "size: " + response.forms[0].shapeStyle.width + ", " // + response.forms[0].shapeStyle.height); if (!username.Equals((string)response.username)) { CustomStroke customStroke = createShapeStroke(response.forms[0]); InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(customStroke); Application.Current?.Dispatcher?.Invoke(new Action(() => { AddStroke(eventArgs); }), DispatcherPriority.ContextIdle); } }); socket.On("formsDeleted", (data) => { dynamic response = JObject.Parse((string)data); if (!username.Equals((string)response.username)) { StrokeCollection strokes = new StrokeCollection(); foreach (dynamic shape in response.forms) { ShapeStroke shapeStroke = createShapeStroke(shape); if (remoteSelectedStrokes.Contains(shapeStroke.guid.ToString())) { remoteSelectedStrokes.Remove(shapeStroke.guid.ToString()); } strokes.Add(shapeStroke); } Application.Current?.Dispatcher?.Invoke(new Action(() => { RemoveStrokes(strokes); }), DispatcherPriority.ContextIdle); } }); socket.On("formsUpdated", (data) => { dynamic response = JObject.Parse((string)data); if (!username.Equals((string)response.username)) { foreach (dynamic shape in response.forms) { InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(createShapeStroke(shape)); Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateStroke(eventArgs); }), DispatcherPriority.Render); } } }); socket.On("formsSelected", (data) => { dynamic response = JObject.Parse((string)data); if (!username.Equals((string)response.username)) { StrokeCollection strokes = new StrokeCollection(); foreach (dynamic shape in response.forms) { ShapeStroke stroke = createShapeStroke(shape); strokes.Add(stroke); if (!remoteSelectedStrokes.Contains(stroke.guid.ToString())) { remoteSelectedStrokes.Add(stroke.guid.ToString()); } Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateSelection(); }), DispatcherPriority.Render); } } }); socket.On("formsDeselected", (data) => { dynamic response = JObject.Parse((string)data); if (!username.Equals((string)response.username)) { StrokeCollection strokes = new StrokeCollection(); foreach (dynamic shape in response.forms) { ShapeStroke stroke = createShapeStroke(shape); strokes.Add(stroke); if (remoteSelectedStrokes.Contains(stroke.guid.ToString())) { remoteSelectedStrokes.Remove(stroke.guid.ToString()); } Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateDeselection(); }), DispatcherPriority.Render); } } }); #endregion socket.On("selectedForms", (data) => { dynamic response = JObject.Parse((string)data); foreach (string id in response.selectedForms) { if (!remoteSelectedStrokes.Contains(id)) { remoteSelectedStrokes.Add(id); } } Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateDeselection(); }), DispatcherPriority.Render); }); socket.On("selectedLinks", (data) => { dynamic response = JObject.Parse((string)data); foreach (string id in response.selectedLinks) { if (!remoteSelectedStrokes.Contains(id)) { remoteSelectedStrokes.Add(id); } } Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateDeselection(); }), DispatcherPriority.Render); }); socket.On("canvasSaved", (data) => { EditCanevasData response = serializer.Deserialize <EditCanevasData>((string)data); RefreshCanvases(); saving = false; }); socket.On("getCanvasResponse", (data) => { Templates.Canvas canvas = serializer.Deserialize <Templates.Canvas>((string)data); canvasName = canvas.name; currentCanvas = canvas; Application.Current?.Dispatcher?.Invoke(new Action(() => { OnResizeCanvas(canvas.dimensions); }), DispatcherPriority.ContextIdle); localSelectedStrokes = new List <string>(); localAddedStrokes = new List <string>(); EditGalleryData editGallerysData = new EditGalleryData(username, canvasName, ""); foreach (Link link in canvas.links) { LinkStroke linkStroke = LinkStrokeFromLink(link); InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(linkStroke); Application.Current?.Dispatcher?.Invoke(new Action(() => { AddStroke(eventArgs); }), DispatcherPriority.ContextIdle); } List <BasicShape> basicShapes = ExtractShapesFromCanvas(canvas); foreach (BasicShape shape in basicShapes) { ShapeStroke shapeStroke = ShapeStrokeFromShape(shape); InkCanvasStrokeCollectedEventArgs eventArgs = new InkCanvasStrokeCollectedEventArgs(shapeStroke); Application.Current?.Dispatcher?.Invoke(new Action(() => { AddStroke(eventArgs); }), DispatcherPriority.ContextIdle); } socket.Emit("getSelectedForms", serializer.Serialize(editGallerysData)); socket.Emit("getSelectedLinks", serializer.Serialize(editGallerysData)); Application.Current?.Dispatcher?.Invoke(new Action(() => { RefreshChildren(); }), DispatcherPriority.ContextIdle); }); socket.On("canvasReinitialized", (data) => { localAddedStrokes = new List <string>(); localSelectedStrokes = new List <string>(); remoteSelectedStrokes = new List <string>(); Application.Current?.Dispatcher?.Invoke(new Action(() => { RemoteReset(); }), DispatcherPriority.Render); }); socket.On("getCanvasLogHistoryResponse", (data) => { HistoryData[] historyData = serializer.Deserialize <HistoryData[]>((string)data); History history = new History(historyData); Application.Current?.Dispatcher?.Invoke(new Action(() => { UpdateHistory(history); }), DispatcherPriority.Render); }); socket.On("disconnect", (data) => { // Application.Current?.Dispatcher?.Invoke(new Action(() => { BackToGallery(); }), DispatcherPriority.ContextIdle); }); RefreshCanvases(); }
void InkCanvasKeyDown(object sender, KeyEventArgs e) { oldkey = e.Key; for (int i = 0; i < 5; i++) if (Keyboard.IsKeyDown(Key.D1 + i)) SelectCanvas(i); //D = (int)e.Key - 83; //if (D >= 0 && D <= 5) // SelectCanvas(D); if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.Z)) { if (_Stroke != null) { if (_curentPoint > 0) { _Stroke.StylusPoints.RemoveAt(_curentPoint); _curentPoint--; } else { _InkCanvas.Strokes.Remove(_Stroke); _Stroke = null; } } } if (e.Key == Key.Q) { SetMode(InkCanvasEditingMode.Select, CustomMode.select); } if (e.Key == Key.W) { SetMode(InkCanvasEditingMode.None, CustomMode.polygon); } if (e.Key == Key.E) { SetMode(InkCanvasEditingMode.EraseByPoint, CustomMode.erase); } if (e.Key == Key.Add || e.Key == Key.Subtract) { double _ScaleFactor = e.Key == Key.Add ? 1.2 : .8; _Scale *= _ScaleFactor; _ScaleText.Text = _Scale.ToString(); foreach (InkCanvas _InkCanvas in _CanvasList.Children) { foreach (Stroke _Stroke in _InkCanvas.Strokes) for (int i = 0; i < _Stroke.StylusPoints.Count; i++) { StylusPoint _StylusPoint = _Stroke.StylusPoints[i]; _Stroke.StylusPoints[i] = new StylusPoint(_StylusPoint.X * _ScaleFactor, _StylusPoint.Y * _ScaleFactor); } foreach (FrameworkElement _Image in _InkCanvas.Children) { InkCanvas.SetLeft(_Image, InkCanvas.GetLeft(_Image) * _ScaleFactor); InkCanvas.SetTop(_Image, InkCanvas.GetTop(_Image) * _ScaleFactor); _Image.Width = _Image.ActualWidth * _ScaleFactor; _Image.Height = _Image.ActualHeight * _ScaleFactor; } } } if (e.Key == Key.C) { SelectColor(); } if (e.Key == Key.PageUp) { StrokeCollection _StrokeCollection = _InkCanvas.GetSelectedStrokes(); foreach (Stroke _Stroke in _StrokeCollection) { _InkCanvas.Strokes.Remove(_Stroke); _InkCanvas.Strokes.Add(_Stroke); } } if (e.Key == Key.PageDown) { StrokeCollection _StrokeCollection = _InkCanvas.GetSelectedStrokes(); foreach (Stroke _Stroke in _StrokeCollection) { _InkCanvas.Strokes.Remove(_Stroke); _InkCanvas.Strokes.Insert(0, _Stroke); } } if (Keyboard.IsKeyDown(Key.C) && Keyboard.IsKeyDown(Key.LeftCtrl)) { _InkCanvas.CopySelection(); } //if (Keyboard.IsKeyDown(Key.X) && Keyboard.IsKeyDown(Key.LeftCtrl)) //{ // _InkCanvas.CutSelection(); //} if (Keyboard.IsKeyDown(Key.V) && Keyboard.IsKeyDown(Key.LeftCtrl)) { _InkCanvas.Paste(); } if (e.Key == Key.B) { if (_PolygonsCanvas.Children.Count > 0) _PolygonsCanvas.Children.Clear(); else foreach (InkCanvas _InkCanvas1 in _CanvasList.Children) foreach (Stroke _Stroke in _InkCanvas1.Strokes) { if (_Stroke.StylusPoints.Last() == _Stroke.StylusPoints.First()) { Polygon _Polygon = new Polygon(); foreach (StylusPoint _Point in _Stroke.StylusPoints) { _Polygon.Points.Add(new Point(_Point.X, _Point.Y)); } _Polygon.Fill = new SolidColorBrush(_Stroke.DrawingAttributes.Color); _PolygonsCanvas.Children.Add(_Polygon); } } } }
void InkCanvas_MouseDown(object sender, MouseButtonEventArgs e) { Point _pos = e.GetPosition(_InkCanvas); if (e.RightButton == MouseButtonState.Pressed) { SetStroke(); if (_CurCustomMode == CustomMode.polygon) { foreach (InkCanvas _InkCanvas1 in _CanvasList.Children) foreach (CustomStroke _Stroke1 in _InkCanvas1.Strokes) for (int i = 0; i < _Stroke1.StylusPoints.Count; i++) { StylusPoint _StylusPoint = _Stroke1.StylusPoints[i]; double l = ((Vector)(Convert(_StylusPoint) - _pos)).Length; if (l < 10) { _curentPoint = i; _Stroke = _Stroke1; } } } } if (e.LeftButton == MouseButtonState.Pressed) { if (_CurCustomMode == CustomMode.polygon) { //if (Keyboard.IsKeyDown(Key.LeftCtrl)) { foreach (InkCanvas _InkCanvas1 in _CanvasList.Children) foreach (CustomStroke _Stroke1 in _InkCanvas1.Strokes) for (int i = 0; i < _Stroke1.StylusPoints.Count; i++) { StylusPoint _StylusPoint = _Stroke1.StylusPoints[i]; double l = ((Vector)(Convert(_StylusPoint) - _pos)).Length; if (l < 5) { _pos = Convert(_StylusPoint); } } } if (_Stroke == null) { StylusPointCollection _StylusPointCollection = new StylusPointCollection(); Point _Point = _pos; _StylusPointCollection.Add(new StylusPoint(_Point.X, _Point.Y)); _Stroke = new CustomStroke(_StylusPointCollection); _InkCanvas.Strokes.Add(_Stroke); _curentPoint = 0; } else { StylusPoint _StylusPoint = new StylusPoint(_pos.X, _pos.Y); _curentPoint++; _Stroke.StylusPoints.Insert(_curentPoint, _StylusPoint); } } } }
//Loaddata private void OpenFile(string _FilePath) { if (!File.Exists(_FilePath)) { Trace.WriteLine("file not exists " + _FilePath); return; } byte[] _Buffer = File.ReadAllBytes(_FilePath); MemoryStream _MemoryStream = new MemoryStream(_Buffer); _MapDatabase = (MapDatabase)_XmlSerializer.Deserialize(_MemoryStream); _InkCanvas.Strokes.Clear(); InkCanvas.SetLeft(_CStartPos, _MapDatabase._CStartPos.X); InkCanvas.SetTop(_CStartPos, _MapDatabase._CStartPos.Y); InkCanvas.SetLeft(_TStartPos, _MapDatabase._TStartPos.X); InkCanvas.SetTop(_TStartPos, _MapDatabase._TStartPos.Y); for (int i = 0; i < _MapDatabase._Layers.Count; i++) { MapDatabase.Layer _Layer = _MapDatabase._Layers[i]; InkCanvas _InkCanvas1 = (InkCanvas)_CanvasList.Children[i]; foreach (MapDatabase.Image _DImage in _Layer._Images) { Image _Image = new Image(); if (!File.Exists(_DImage.Path)) Debugger.Break(); BitmapImage _BitmapImage = new BitmapImage(new Uri(_DImage.Path, UriKind.Relative)); double a = _BitmapImage.Width; _Image.Source = _BitmapImage; _Image.Width = _DImage.Width; _Image.Height = _DImage.Height; InkCanvas.SetLeft(_Image, _DImage.X); InkCanvas.SetTop(_Image, _DImage.Y); _InkCanvas1.Children.Add(_Image); } foreach (MapDatabase.Polygon _Polygon in _Layer._Polygons) { StylusPointCollection _StylusPointCollection = new StylusPointCollection(); foreach (Point _Point in _Polygon._Points) { StylusPoint _StylusPoint = new StylusPoint(_Point.X, _Point.Y); _StylusPointCollection.Add(_StylusPoint); } CustomStroke _Stroke = new CustomStroke(_StylusPointCollection); _Stroke.DrawingAttributes.Color = _Polygon._Color; _InkCanvas1.Strokes.Add(_Stroke); } } }
void InkCanvas_MouseDown(object sender, MouseButtonEventArgs e) { Point _pos = e.GetPosition(_InkCanvas); if (e.RightButton == MouseButtonState.Pressed) { SetStroke(); if (_CurCustomMode == CustomMode.polygon) { foreach (InkCanvas _InkCanvas1 in _CanvasList.Children) { foreach (CustomStroke _Stroke1 in _InkCanvas1.Strokes) { for (int i = 0; i < _Stroke1.StylusPoints.Count; i++) { StylusPoint _StylusPoint = _Stroke1.StylusPoints[i]; double l = ((Vector)(Convert(_StylusPoint) - _pos)).Length; if (l < 10) { _curentPoint = i; _Stroke = _Stroke1; } } } } } } if (e.LeftButton == MouseButtonState.Pressed) { if (_CurCustomMode == CustomMode.polygon) { //if (Keyboard.IsKeyDown(Key.LeftCtrl)) { foreach (InkCanvas _InkCanvas1 in _CanvasList.Children) { foreach (CustomStroke _Stroke1 in _InkCanvas1.Strokes) { for (int i = 0; i < _Stroke1.StylusPoints.Count; i++) { StylusPoint _StylusPoint = _Stroke1.StylusPoints[i]; double l = ((Vector)(Convert(_StylusPoint) - _pos)).Length; if (l < 5) { _pos = Convert(_StylusPoint); } } } } } if (_Stroke == null) { StylusPointCollection _StylusPointCollection = new StylusPointCollection(); Point _Point = _pos; _StylusPointCollection.Add(new StylusPoint(_Point.X, _Point.Y)); _Stroke = new CustomStroke(_StylusPointCollection); _InkCanvas.Strokes.Add(_Stroke); _curentPoint = 0; } else { StylusPoint _StylusPoint = new StylusPoint(_pos.X, _pos.Y); _curentPoint++; _Stroke.StylusPoints.Insert(_curentPoint, _StylusPoint); } } } }
internal CustomStroke AddStrokeFromView(CustomStroke selectedStroke /*StylusPoint firstPoint, StrokeTypes strokeType*/) { return(editeur.AddStrokeFromView(selectedStroke)); }