Esempio n. 1
0
        private static void innerDrawCircle(Vector2 center, int radius, Color color, bool filled, int thickness)
        {
            bool containsKeyRadius = CirclesCache.ContainsKey(radius);

            if (containsKeyRadius)
            {
                foreach (Circle c in CirclesCache[radius])
                {
                    if (c.Filled == filled && (filled || c.Thickness == thickness))
                    {
                        SpriteBatch.Draw(c.Texture, center, null, color, 0, new Vector2(radius + 1, radius + 1), 1, SpriteEffects.None, 0);
                        return;
                    }
                }
            }
            int       outerRadius = radius * 2 + 2;
            Texture2D texture     = new Texture2D(Primitives.GraphicsDevice, outerRadius, outerRadius);

            if (filled)
            {
                thickness = radius + 1;
            }

            Color[] data = new Color[outerRadius * outerRadius];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = Color.Transparent;
            }

            double angleStep = 0.5f / radius;

            int lowpoint = radius - thickness;

            for (double angle = 0; angle < Math.PI * 2; angle += angleStep)
            {
                for (int i = radius; i > lowpoint; i--)
                {
                    int x = (int)Math.Round(radius + i * Math.Cos(angle));
                    int y = (int)Math.Round(radius + i * Math.Sin(angle));
                    data[y * outerRadius + x + 1] = color;
                }
            }
            texture.SetData(data);
            if (containsKeyRadius)
            {
                CirclesCache[radius].Add(new Circle(texture, radius, filled, thickness));
            }
            else
            {
                CirclesCache.Add(radius, new List <Circle>(new Circle[] { new Circle(texture, radius, filled, thickness) }));
            }

            SpriteBatch.Draw(texture, center, null, color, 0, new Vector2(radius + 1, radius + 1), 1, SpriteEffects.None, 0);
        }
Esempio n. 2
0
 /// <summary>
 /// Clears all cached Circle textures. This will clear space from memory, but drawing circles will take longer.
 /// </summary>
 public static void ClearCircleCache()
 {
     CirclesCache.Clear();
     GC.Collect();
 }