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); }
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); }