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 virtual IPoint CreatePoint(object[] obj) { IPoint p = new PointBase((double)obj[0], (double)obj[1]); int[] col = new int[3]; for (int i = 0; i < col.Length; i++) { double c = (double)obj[i + 2]; int x = (int)(c * 255); if (x < 0) { x = 0; } if (x > 255) { x = 255; } col[i] = x; } Color color = Color.FromArgb(255, col[0], col[1], col[2]); double s = (double)obj[5]; ColoredCircle circle = new ColoredCircle((int)s, color); p.Properties = circle; return(p); }
static void ShapeWork() { Rectangle r = new Rectangle(); Console.WriteLine("Enter the length: "); r.Length = int.Parse(Console.ReadLine()); r.Width = 3; Console.WriteLine(r.GetPerimeter()); Console.WriteLine(r.Area); //BetterCircle circle = new BetterCircle(); NoisyCircle noisyCircle = new NoisyCircle(); BetterCircle circle = noisyCircle; // upcasting circle.Radius = 8; noisyCircle.GetPerimeter(); circle.GetPerimeter(); Console.WriteLine(); PrintShapeDetails(r, "rectangle"); PrintShapeDetails(circle, "circle"); ColoredCircle blueCircle = new ColoredCircle(); }
//Idem PathAction avec des cercles private void CircleAction(SKTouchEventArgs e, SKColor color) { switch (e.ActionType) { case SKTouchAction.Pressed: var c = new ColoredCircle { Color = color, Center = e.Location, Radius = 0.1F, StrokeWidth = strokeWidth }; temporaryForms[e.Id] = c; break; case SKTouchAction.Moved: if (e.InContact && temporaryForms.ContainsKey(e.Id)) { c = (ColoredCircle)temporaryForms[e.Id]; c.Radius = (float)Math.Sqrt(Math.Pow(e.Location.X - c.Center.X, 2) + Math.Pow(e.Location.Y - c.Center.Y, 2)); } break; case SKTouchAction.Released: if (temporaryForms.ContainsKey(e.Id)) { forms.Add(temporaryForms[e.Id]); asyncClient.Send((ColoredCircle)temporaryForms[e.Id]); temporaryForms.Remove(e.Id); } break; case SKTouchAction.Cancelled: temporaryForms.Remove(e.Id); break; } }
static void Main(string[] args) { // if what you need is in a different project (assembly)... // you need a project reference (right click on Dependencies in Soln Explorer.) // if what you need is in a different namespace... // you need a using statement at the top of the file. // if it's in both, you need both those things. var circle = new Circle(); circle.Radius = 4; // property initialization syntax - // lets you set a bunch of properties just after constructing object // without having to type the variable name again and again. var circle2 = new Circle { Radius = 4 }; PrintCircleDetails(circle); var rect = new Rectangle { Length = 5, Width = 3 }; PrintShapeDetails(circle); PrintShapeDetails(rect); var blackCircle = new ColoredCircle { Radius = 5, Color = "black" }; PrintCircleDetails(blackCircle); // upcasting - we put an object in a variable which is of a higher-up type (less specific) Circle circle3 = blackCircle; // downcasting must be explicit - potentially could fail, so, we explicitly cast with () ColoredCircle y = (ColoredCircle)circle3; // the type of the variable affects what we can see/use on that object. //circle3.Color; // error var x = blackCircle.Color; }
private JObject Jsonify(ColoredCircle circle) { string colourHash = circle.Color.ToString(); float x = circle.Center.X; float y = circle.Center.Y; string coordinates = x.ToString() + " " + y.ToString(); float strokeWidth = circle.StrokeWidth; float radius = circle.Radius; JObject json = new JObject(new JProperty("type", "CIRCLE"), new JProperty("content", new JObject( new JProperty("colorHash", colourHash), new JProperty("coordinates", coordinates), new JProperty("radius", radius), 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(); } }
static void Main(string[] args) { var circle = new Circle(); circle.Radius = 4; var circle2 = new Circle { Radius = 4 }; PrintCircleDetails(circle); var rect = new Rectangle { Length = 5, Width = 3 }; PrintShapeDetails(circle); PrintShapeDetails(rect); var blackCircle = new ColoredCircle { Radius = 5, Color = "Black" }; PrintCircleDetails(blackCircle); //upcasting Circle circle3 = blackCircle; //circle3.Color; ERROR var x = blackCircle.Color; ColoredCircle y = (ColoredCircle)circle3; }
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(ColoredCircle circle) { JObject json = Jsonify(circle); SendData(json); }
private void LoadGeometry() { Circle = new ColoredCircle(200, 200, 200, new Vector3(255, 0, 255), 32); Batch.Add(Circle); }