/// <summary> /// Mark a line as complete and remove it from the incubator. /// </summary> /// <param name="lineId">The id of the line to complete.</param> /// <returns>The completed line.</returns> public DrawnLine CompleteLine(string lineId) { if (!currentLines.ContainsKey(lineId)) { throw new KeyNotFoundException("Error: A line with that id wasn't found in this LineIncubator."); } DrawnLine completedLine = currentLines[lineId]; currentLines.Remove(lineId); int originalPointCount = completedLine.Points.Count; completedLine.Points = LineSimplifier.SimplifyLine(completedLine.Points, 6); Log.WriteLine( "[LineIncubator] [LineComplete] #{0}: {1} -> {2} points ({3:0.00}% reduction)", lineId, originalPointCount, completedLine.Points.Count, ((float)completedLine.Points.Count / (float)originalPointCount) * 100f ); return(completedLine); }
/// <summary> /// Handles notifications from clients telling us that they've finished drawing a line. /// </summary> /// <param name="message">The message to handle.</param> protected async Task handleLineCompleteMessage(LineCompleteMessage message) { // If the line doesn't exist, then ignore it if (!manager.LineIncubator.LineExists(message.LineId)) { Log.WriteLine("[NibriClient#{0}/handlers] Ignoring LineComplete event for line that doesn't exist", Id); return; } DrawnLine line = manager.LineIncubator.CompleteLine(message.LineId); if (CurrentPlane == null) { Log.WriteLine("[NibriClient#{0}] Attempt to complete a line before selecting a plane - ignoring", Id); await Send(new ExceptionMessage( 401, "Error: You can't complete a line until you've selected a plane to draw it on!" )); return; } Log.WriteLine("[NibriClient#{0}] Adding {1}px {2} line", Id, line.Width, line.Colour); await Task.WhenAll( manager.BroadcastPlane(this, new LineCompleteReflectionMessage() { OtherClientId = Id, LineId = line.LineId }), CurrentPlane.AddLine(line) ); }
private void DrawRectangle(DrawnRectangle rectangle) { DrawnLine top = new DrawnLine { Name = rectangle.Name, Color = rectangle.Color, X = rectangle.X, Y = rectangle.Y, EndX = rectangle.X + rectangle.Size.Width, EndY = rectangle.Y, Thickness = rectangle.Thickness }; DrawnLine right = new DrawnLine { Name = rectangle.Name, Color = rectangle.Color, X = rectangle.X + rectangle.Size.Width, Y = rectangle.Y, EndX = rectangle.X + rectangle.Size.Width, EndY = rectangle.Y + rectangle.Size.Height, Thickness = rectangle.Thickness }; DrawnLine bottom = new DrawnLine { Name = rectangle.Name, Color = rectangle.Color, X = rectangle.X + rectangle.Size.Width, Y = rectangle.Y + rectangle.Size.Height, EndX = rectangle.X, EndY = rectangle.Y + rectangle.Size.Height, Thickness = rectangle.Thickness }; DrawnLine left = new DrawnLine { Name = rectangle.Name, Color = rectangle.Color, X = rectangle.X, Y = rectangle.Y + rectangle.Size.Height, EndX = rectangle.X, EndY = rectangle.Y, Thickness = rectangle.Thickness }; DrawLine(top); DrawLine(right); DrawLine(bottom); DrawLine(left); }
private void DrawLine(DrawnLine line) { Vector2 position = new Vector2(line.X, line.Y); Vector2 endPos = new Vector2(line.EndX, line.EndY); Vector2 edge = endPos - position; float angle = (float)Math.Atan2(edge.Y, edge.X); Texture2D pixelTexture = textureManager.PixelTextures[line.Name]; SpriteBatch.Draw(pixelTexture, new Rectangle((int)position.X, (int)position.Y, (int)edge.Length(), (int)line.Thickness), null, line.Color, angle, Vector2.Zero, SpriteEffects.None, 1); }
public GraphicsData(Dictionary <string, IDrawn> drawnObjects, Dictionary <string, Texture2D> animationTextures, Dictionary <string, Texture2D> pixelTextures) { DrawnObjects = new List <IDrawn>(); AnimationTextures = new List <BinaryTexture>(); PixelTextures = new List <BinaryTexture>(); foreach (KeyValuePair <string, IDrawn> drawnObject in drawnObjects) { switch (drawnObject.Value.DrawnType) { case DrawnType.Animation: Animation animation = (Animation)drawnObject.Value; DrawnObjects.Add(animation.CloneAnimation(animation.Name)); break; case DrawnType.Shape: IDrawnShape shape = (IDrawnShape)drawnObject.Value; switch (shape.Shape) { case ShapeType.Line: DrawnLine line = (DrawnLine)shape; DrawnObjects.Add(line.Clone(line.Name)); break; case ShapeType.Rectangle: DrawnRectangle rectangle = (DrawnRectangle)shape; DrawnObjects.Add(rectangle.Clone(rectangle.Name)); break; } break; case DrawnType.String: DrawnString drawString = (DrawnString)drawnObject.Value; DrawnObjects.Add(drawString.Clone(drawString.Name)); break; } } foreach (BinaryTexture newTexture in animationTextures.Select(pair => new BinaryTexture(pair.Value))) { AnimationTextures.Add(newTexture); } foreach (BinaryTexture pixelTexture in pixelTextures.Select(pair => new BinaryTexture(pair.Value))) { PixelTextures.Add(pixelTexture); } }
public void Draw() { foreach (KeyValuePair <string, IDrawn> drawable in drawList) { switch (drawable.Value.DrawnType) { case DrawnType.Animation: Animation animation = (Animation)drawable.Value; Texture2D drawTexture = textureManager.Textures[animation.Texture]; Rectangle frameRectangle = GameRectangle.ConvertToRectangle(animation.Frames[animation.Frame].TextureSource); SpriteBatch.Draw(drawTexture, animation.GetPosition(), frameRectangle, Color.White, animation.Rotation, animation.GetOrigin(), animation.Scale, SpriteEffects.None, animation.Depth); break; case DrawnType.Shape: IDrawnShape shape = (IDrawnShape)drawable.Value; switch (shape.Shape) { case ShapeType.Line: DrawnLine drawLine = (DrawnLine)shape; DrawLine(drawLine); break; case ShapeType.Rectangle: DrawnRectangle drawRectangle = (DrawnRectangle)shape; DrawRectangle(drawRectangle); break; } break; case DrawnType.String: DrawnString drawString = (DrawnString)drawable.Value; DrawString(drawString); break; } } }
public bool UpdateDrawList(DrawParam param) { if (!drawList.ContainsKey(param.ObjectName)) { return(false); } if (drawCache.Cache.ContainsKey(param.ObjectName)) { ObjectCache cache = drawCache.Cache[param.ObjectName]; if (cache.Cache.ContainsKey(param.DrawableName)) { IDrawn drawableObject = cache.Cache[param.DrawableName]; drawableObject.X = param.Position.X; drawableObject.Y = param.Position.Y; switch (drawableObject.DrawnType) { case DrawnType.Animation: Animation animation = (Animation)drawableObject; animation.Reset(); drawList[param.ObjectName] = animation; return(true); default: drawList[param.ObjectName] = drawableObject; return(true); } } } else { drawCache.Cache.Add(param.ObjectName, new ObjectCache()); } ObjectCache objCache = drawCache.Cache[param.ObjectName]; switch (param.DrawType) { case DrawnType.Animation: if (!animationList.ContainsKey(param.DrawableName)) { return(false); } Animation animation = animationList[param.DrawableName].CloneAnimation(param.DrawableName); animation.Reset(); animation.X = param.Position.X; animation.Y = param.Position.Y; drawList.Add(param.ObjectName, animation); objCache.Cache.Add(animation.Name, animation); break; case DrawnType.Shape: if (!shapeList.ContainsKey(param.DrawableName)) { return(false); } IDrawnShape shape = shapeList[param.DrawableName]; switch (shape.Shape) { case ShapeType.Line: DrawnLine line = (DrawnLine)shape; DrawnLine drawLine = line.Clone(line.Name); drawLine.X = param.Position.X; drawLine.Y = param.Position.Y; drawList.Add(param.ObjectName, drawLine); objCache.Cache.Add(drawLine.Name, drawLine); return(true); case ShapeType.Rectangle: DrawnRectangle rectangle = (DrawnRectangle)shape; DrawnRectangle drawRectangle = rectangle.Clone(rectangle.Name); drawRectangle.X = param.Position.X; drawRectangle.Y = param.Position.Y; drawList.Add(param.ObjectName, drawRectangle); objCache.Cache.Add(drawRectangle.Name, drawRectangle); return(true); } break; case DrawnType.String: if (!stringList.ContainsKey(param.DrawableName)) { return(false); } DrawnString drawString = stringList[param.DrawableName].Clone(param.DrawableName); drawString.X = param.Position.X; drawString.Y = param.Position.Y; drawList.Add(param.ObjectName, drawString); objCache.Cache.Add(drawString.Name, drawString); return(true); } return(false); }