internal GradientStrokeContent(ILottieDrawable lottieDrawable, BaseLayer layer, GradientStroke stroke) : base(lottieDrawable, layer, ShapeStroke.LineCapTypeToPaintCap(stroke.CapType), ShapeStroke.LineJoinTypeToPaintLineJoin(stroke.JoinType), stroke.MiterLimit, stroke.Opacity, stroke.Width, stroke.LineDashPattern, stroke.DashOffset) { Name = stroke.Name; _type = stroke.GradientType; _hidden = stroke.IsHidden; _cacheSteps = (int)(lottieDrawable.Composition.Duration / CacheStepsMs); _colorAnimation = stroke.GradientColor.CreateAnimation(); _colorAnimation.ValueChanged += OnValueChanged; layer.AddAnimation(_colorAnimation); _startPointAnimation = stroke.StartPoint.CreateAnimation(); _startPointAnimation.ValueChanged += OnValueChanged; layer.AddAnimation(_startPointAnimation); _endPointAnimation = stroke.EndPoint.CreateAnimation(); _endPointAnimation.ValueChanged += OnValueChanged; layer.AddAnimation(_endPointAnimation); }
YamlObject FromShapeStroke(ShapeStroke content, YamlMap superclassContent) { superclassContent.Add(nameof(content.Opacity), FromAnimatable(content.Opacity)); superclassContent.Add(nameof(content.StrokeWidth), FromAnimatable(content.StrokeWidth)); superclassContent.Add(nameof(content.CapType), Scalar(content.CapType)); superclassContent.Add(nameof(content.JoinType), Scalar(content.JoinType)); superclassContent.Add(nameof(content.MiterLimit), Scalar(content.MiterLimit)); switch (content.StrokeKind) { case ShapeStroke.ShapeStrokeKind.SolidColor: return(FromSolidColorStroke((SolidColorStroke)content, superclassContent)); case ShapeStroke.ShapeStrokeKind.LinearGradient: return(FromLinearGradientStroke((LinearGradientStroke)content, superclassContent)); case ShapeStroke.ShapeStrokeKind.RadialGradient: return(FromRadialGradientStroke((RadialGradientStroke)content, superclassContent)); default: throw Unreachable; } }
// On retire le trait du dessus de la pile de traits retirés et on le place sur la surface de dessin. public void Depiler(object o) { try { isStackUpToDate = false; CustomStroke trait = (CustomStroke)traitsRetires.Last(); if (trait.isLinkStroke()) { LinkStroke linkStroke = trait as LinkStroke; linkStroke.from.SetDefaults(); linkStroke.to.SetDefaults(); } else { ShapeStroke shapeStroke = trait as ShapeStroke; shapeStroke.linksTo = new List <string> { }; shapeStroke.linksFrom = new List <string> { }; } traits.Add(trait); if (trait.isLinkStroke()) { DrawingService.CreateLink(trait as LinkStroke); } else { DrawingService.CreateShape(trait as ShapeStroke); } traitsRetires.Remove(trait); } catch { } }
internal StrokeContent(LottieDrawable lottieDrawable, BaseLayer layer, ShapeStroke stroke) : base(lottieDrawable, layer, ShapeStroke.LineCapTypeToPaintCap(stroke.CapType), ShapeStroke.LineJoinTypeToPaintLineJoin(stroke.JoinType), stroke.MiterLimit, stroke.Opacity, stroke.Width, stroke.LineDashPattern, stroke.DashOffset) { _layer = layer; Name = stroke.Name; _colorAnimation = stroke.Color.CreateAnimation(); _colorAnimation.ValueChanged += OnValueChanged; layer.AddAnimation(_colorAnimation); }
public void Add(ShapeStroke shape) { shape.DrawingAttributes.Color = this.lastPenColor; this.inkCanvas.Strokes.Add(shape); }
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(); }