private List <object> DictToFormsList(JArray content) { List <object> forms = new List <object>(); foreach (JObject coloredForm in content) { Dictionary <string, object> pdict = JsonConvert.DeserializeObject <Dictionary <string, object> >(coloredForm.ToString()); Dictionary <string, string> formElement = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); switch (pdict["type"]) { case "LINE": ColoredLine line = DictToLine(formElement); forms.Add(line); break; case "CIRCLE": ColoredCircle circle = DictToCircle(formElement); forms.Add(circle); break; case "PATH": ColoredPath path = DictToPath(formElement); forms.Add(path); break; case "RECTANGLE": ColoredRectangle rectangle = DictToRectangle(formElement); forms.Add(rectangle); break; } } return(forms); }
public static void Main(string[] args) { ColoredPoint obj = new ColoredPoint(2, 3, "black"); ColoredLine obj1 = new ColoredLine(1, 2, 3, 4, "red"); Line obj2 = new Line(1, 2, 3, 4); PolyLine obj3 = new PolyLine(1, 2, 3, 4, 5, 6, 7, 8); }
//Idem PathAction avec des lignes droites private void LineAction(SKTouchEventArgs e, SKColor color) { switch (e.ActionType) { case SKTouchAction.Pressed: var l = new ColoredLine { Color = color, Start = e.Location, End = e.Location, StrokeWidth = strokeWidth }; temporaryForms[e.Id] = l; break; case SKTouchAction.Moved: if (e.InContact && temporaryForms.ContainsKey(e.Id)) { l = (ColoredLine)temporaryForms[e.Id]; l.End = e.Location; } break; case SKTouchAction.Released: if (temporaryForms.ContainsKey(e.Id)) { forms.Add(temporaryForms[e.Id]); asyncClient.Send((ColoredLine)temporaryForms[e.Id]); temporaryForms.Remove(e.Id); } break; case SKTouchAction.Cancelled: temporaryForms.Remove(e.Id); break; } }
/// <summary> /// Generates a line to be added to the canvas. Line color is determined by the position on the grid /// </summary> protected void AddLine(int position, SolidColorBrush ValueFillColor) { ColoredLine line = new ColoredLine() { StrokeThickness = 2, EmptyFillColor = EmptyColor, ValueFillColor = ValueFillColor, X1 = ResolveX1(position), X2 = ResolveX2(position), Y1 = ResolveY1(position), Y2 = ResolveY2(position), }; GaugeLines.Add(line); Children.Add(line); line.UseEmptyColor(); }
private JObject Jsonify(ColoredLine line) { string colourHash = line.Color.ToString(); float strokeWidth = line.StrokeWidth; float x1 = line.Start.X; float x2 = line.End.X; float y1 = line.Start.Y; float y2 = line.End.Y; string coordinates = x1.ToString() + " " + x2.ToString() + " " + y1.ToString() + " " + y2.ToString(); JObject json = new JObject(new JProperty("type", "LINE"), new JProperty("content", new JObject( new JProperty("colorHash", colourHash), new JProperty("coordinates", coordinates), new JProperty("strokeWidth", strokeWidth)))); return(json); }
//Evenement déclenché quand une nouvelle forme ou instruction est reçue par le client private void UpdateUi(Object o, UpdateUIEventArgs eventArgs) { lock (forms) { switch (eventArgs.Type) { case "PATH": ColoredPath coloredPath = eventArgs.Path; forms.Add(coloredPath); break; case "CIRCLE": ColoredCircle coloredCircle = eventArgs.Circle; forms.Add(coloredCircle); break; case "LINE": ColoredLine coloredLine = eventArgs.Line; forms.Add(coloredLine); break; case "RECTANGLE": ColoredRectangle coloredRectangle = eventArgs.Rectangle; forms.Add(coloredRectangle); break; case "CLEAR": forms.Clear(); break; case "SIZE": width = eventArgs.Width; height = eventArgs.Height; break; case "REQUEST_STATUS": asyncClient.RestoreWhiteboard(this.forms, eventArgs.client_id); break; case "RESTORE": forms = eventArgs.Forms; break; } View.InvalidateSurface(); } }
public override void DrawComponentLayout() { Children.Clear(); GaugeLines.Clear(); numLines = 0; var centerPoint = GetCenterPoint(this); double factorDelimiter = (Width > Height) ? centerPoint.Y : centerPoint.X; var lineStartFactor = factorDelimiter - ((factorDelimiter / 2)); var lineEndFactor = factorDelimiter - ((factorDelimiter / 10)); var fillColor = new SolidColorBrush(Colors.Green); var emptyColor = new SolidColorBrush(Colors.Black); var lineSeparationFactor = GetLineSeparationFactor(); for (double degrees = 135d; degrees < 405d; degrees += lineSeparationFactor) { var radians = ((Math.PI / 180) * degrees); var startX = (centerPoint.X + (lineStartFactor * Math.Cos(radians))); var startY = (centerPoint.Y + (lineStartFactor * Math.Sin(radians))); var endX = (centerPoint.X + (lineEndFactor * Math.Cos(radians))); var endY = (centerPoint.Y + (lineEndFactor * Math.Sin(radians))); ColoredLine line = new ColoredLine() { X1 = startX, X2 = endX, Y1 = startY, Y2 = endY, StrokeThickness = 2, ValueFillColor = fillColor, EmptyFillColor = emptyColor, }; GaugeLines.Add(line); Children.Add(line); line.UseEmptyColor(); numLines++; } PreviousLineNumber = 0; Update(); }
private void ReceivePackage(Object o, PacketReceivedEventArgs eventArgs) { Dictionary <string, object> pdict = JsonConvert.DeserializeObject <Dictionary <string, object> >(eventArgs.data); Dictionary <string, string> content;; UpdateUIEventArgs UiEventArgs; switch (pdict["type"]) { case "PATH": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); ColoredPath path = DictToPath(content); UiEventArgs = new UpdateUIEventArgs { Type = "PATH", Path = path }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "CIRCLE": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); ColoredCircle circle = DictToCircle(content); UiEventArgs = new UpdateUIEventArgs { Type = "CIRCLE", Circle = circle }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "LINE": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); ColoredLine line = DictToLine(content); UiEventArgs = new UpdateUIEventArgs { Type = "LINE", Line = line }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "REQUEST_STATUS": //Called for the host, when a new client is requesting the whiteboard's current state content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); int id = int.Parse(content["id"]); //the id corresponds to the client's id from the server's perspective UiEventArgs = new UpdateUIEventArgs { Type = "REQUEST_STATUS", client_id = id }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "RECTANGLE": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); ColoredRectangle rectangle = DictToRectangle(content); UiEventArgs = new UpdateUIEventArgs { Rectangle = rectangle, Type = "RECTANGLE" }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "SIZE": content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString()); float w = float.Parse(content["width"]); float h = float.Parse(content["height"]); UiEventArgs = new UpdateUIEventArgs { Width = w, Height = h, Type = "SIZE" }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "CLEAR": UiEventArgs = new UpdateUIEventArgs { Type = "CLEAR" }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; case "RESTORE": JArray jArray = JArray.Parse(pdict["content"].ToString()); List <object> forms = DictToFormsList(jArray); UiEventArgs = new UpdateUIEventArgs { Type = "RESTORE", Forms = forms }; UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs); break; default: Console.WriteLine("error parsing received data: {0}", eventArgs.data); throw new ArgumentException(eventArgs.data); } }
public void Send(ColoredLine line) { JObject json = Jsonify(line); SendData(json); }