/// <summary> /// Create a new Gradient using 4 Colors for each corner. /// </summary> /// <param name="width">The width of the gradient.</param> /// <param name="height">The height of the gradient.</param> /// <param name="TopLeft">The Color of the top left corner.</param> /// <param name="TopRight">The Color of the top right corner.</param> /// <param name="BottomRight">The Color of the bottom right corner.</param> /// <param name="BottomLeft">The Color of the bottom left corner.</param> public Gradient(int width, int height, Color TopLeft, Color TopRight, Color BottomRight, Color BottomLeft) { baseColors.Add(TopLeft); baseColors.Add(TopRight); baseColors.Add(BottomRight); baseColors.Add(BottomLeft); colors.Add(TopLeft); colors.Add(TopRight); colors.Add(BottomRight); colors.Add(BottomLeft); Width = width; Height = height; }
/// <summary> /// Creates a rectangle. /// </summary> /// <param name="width">The width of the rectangle.</param> /// <param name="height">The height of the rectangle.</param> /// <param name="color">The color of the rectangle.</param> /// <returns>A new image containing the rectangle.</returns> static public Image CreateRectangle(int width, int height, Color color) { Image img = new Image(width, height); img.Color = color; img.Width = width; img.Height = height; img.rectWidth = width; img.rectHeight = height; img.isShape = true; img.Batchable = false; // Cant batch rectangles for now img.OutlineColor = Color.None; return img; }
protected override void UpdateDrawable() { base.UpdateDrawable(); Color nextColor = ColorA; Color rowColor = nextColor; SFMLVertices = new VertexArray(PrimitiveType.Quads); for (float j = 0; j < Height; j += GridHeight) { for (float i = 0; i < Width; i += GridWidth) { var color = new Color(nextColor) * Color; SFMLVertices.Append(new Vertex(new Vector2f(i, j), color.SFMLColor)); SFMLVertices.Append(new Vertex(new Vector2f(i + GridWidth, j), color.SFMLColor)); SFMLVertices.Append(new Vertex(new Vector2f(i + GridWidth, j + GridHeight), color.SFMLColor)); SFMLVertices.Append(new Vertex(new Vector2f(i, j + GridHeight), color.SFMLColor)); nextColor = nextColor == ColorA ? ColorB : ColorA; } rowColor = nextColor = rowColor == ColorA ? ColorB : ColorA; } }
/// <summary> /// Create a new Grid. /// </summary> /// <param name="width">The width of the Grid in pixels.</param> /// <param name="height">The height of the Gird in pixels.</param> /// <param name="gridWidth">The width of each cell on the Grid.</param> /// <param name="gridHeight">The height of each cell on the Grid.</param> /// <param name="colorA">The first Color of the Grid.</param> /// <param name="colorB">The second Color of the Grid.</param> public Grid(int width, int height, int gridWidth, int gridHeight, Color colorA, Color colorB = null) { Width = width; Height = height; ColorA = colorA; if (colorB == null) { ColorB = colorA.Copy(); ColorB.R -= 0.02f; ColorB.G -= 0.02f; ColorB.B -= 0.02f; } else { ColorB = colorB; } GridWidth = gridWidth; GridHeight = gridHeight; }
protected override void UpdateDrawable() { base.UpdateDrawable(); SFMLVertices.Clear(); var finalColors = new List<Color>() { Color.None, Color.None, Color.None, Color.None}; for (int i = 0; i < baseColors.Count; i++) { finalColors[i] = new Color(baseColors[i]); finalColors[i].A *= Alpha; } SFMLVertices.Append(new Vertex(new Vector2f(0, 0), finalColors[0].SFMLColor)); SFMLVertices.Append(new Vertex(new Vector2f(Width, 0), finalColors[1].SFMLColor)); SFMLVertices.Append(new Vertex(new Vector2f(Width, Height), finalColors[2].SFMLColor)); SFMLVertices.Append(new Vertex(new Vector2f(0, Height), finalColors[3].SFMLColor)); }
/// <summary> /// Create a circle. /// </summary> /// <param name="radius">The radius of the circle.</param> /// <param name="color">The color of the circle.</param> /// <returns>A new image containing the circle.</returns> static public Image CreateCircle(int radius, Color color) { Image img = new Image(); img.Width = radius * 2; img.Height = radius * 2; img.Color = color; img.radius = radius; img.OutlineColor = Color.None; img.isCircle = true; img.isShape = true; img.Batchable = false; return img; }
/// <summary> /// Set the Color of a specific position. /// </summary> /// <param name="color">The new Color.</param> /// <param name="position">The position to change the Color on.</param> public void SetColor(Color color, ColorPosition position) { colors[(int)position] = color; NeedsUpdate = true; }
/// <summary> /// Draws a line with rounded ends. /// </summary> /// <param name="x1">The X position of the first point.</param> /// <param name="y1">The Y position of the first point.</param> /// <param name="x2">The X position of the second point.</param> /// <param name="y2">The Y position of the second point.</param> /// <param name="color">The color of the line.</param> /// <param name="thickness">The thickness of the line.</param> static public void RoundedLine(float x1, float y1, float x2, float y2, Color color, float thickness) { VertexArray vertices = new VertexArray(PrimitiveType.TrianglesFan); int rotationSteps = 10; var line = new Vector2(x2 - x1, y2 - y1); var normalUp = new Vector2(y1 - y2, x2 - x1); var normalDown = new Vector2(y2 - y1, x1 - x2); normalUp.Normalize(thickness * 0.5f); normalDown.Normalize(thickness * 0.5f); var nextPoint = new Vector2(); float vx, vy; vx = x1; vy = y1; vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); vx = (float)(x1 + normalUp.X); vy = (float)(y1 + normalUp.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); nextPoint.X = normalUp.X; nextPoint.Y = normalUp.Y; for (int i = 0; i < rotationSteps; i++) { nextPoint = Util.Rotate(nextPoint, -180 / rotationSteps); vx = (float)(x1 + nextPoint.X); vy = (float)(y1 + nextPoint.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); } vx = (float)(x1 + normalDown.X); vy = (float)(y1 + normalDown.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); vx = (float)(x2 + normalDown.X); vy = (float)(y2 + normalDown.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); for (int i = 0; i < rotationSteps; i++) { nextPoint = Util.Rotate(nextPoint, -180 / rotationSteps); vx = (float)(x2 + nextPoint.X); vy = (float)(y2 + nextPoint.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); } vx = (float)(x2 + normalUp.X); vy = (float)(y2 + normalUp.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); vx = (float)(x1 + normalUp.X); vy = (float)(y1 + normalUp.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); Drawable(vertices, RenderStates.Default); }
/// <summary> /// Draws a line using an OpenGL line. /// </summary> /// <param name="x1">The X position of the first point.</param> /// <param name="y1">The Y position of the first point.</param> /// <param name="x2">The X position of the second point.</param> /// <param name="y2">The Y position of the second point.</param> /// <param name="color">The color of the line.</param> static public void Line(float x1, float y1, float x2, float y2, Color color) { VertexArray vertices = new VertexArray(PrimitiveType.Lines); vertices.Append(new Vertex(new Vector2f(x1, y1), color.SFMLColor)); vertices.Append(new Vertex(new Vector2f(x2, y2), color.SFMLColor)); Drawable(vertices, RenderStates.Default); }
/// <summary> /// Draws a rectangle. Recommended to use only for debugging purposes. /// </summary> /// <param name="x">The X position of the top left of the rectangle.</param> /// <param name="y">The Y position of the top left of the rectangle.</param> /// <param name="width">The width of the rectangle.</param> /// <param name="height">The height of the rectangle.</param> /// <param name="fill">The fill color of the rectangle.</param> /// <param name="outline">The outline color of the rectangle.</param> /// <param name="outlineThickness">The outline thickness of the rectangle.</param> static public void Rectangle(float x, float y, float width, float height, Color fill = null, Color outline = null, float outlineThickness = 0) { tempRect.Size = new Vector2f(width, height); tempRect.Position = new Vector2f(x, y); if (outline == null) { tempRect.OutlineColor = Color.None.SFMLColor; } else { tempRect.OutlineColor = outline.SFMLColor; } tempRect.OutlineThickness = outlineThickness; if (fill == null) { tempRect.FillColor = Color.White.SFMLColor; } else { tempRect.FillColor = fill.SFMLColor; } Target.Draw(tempRect); }
/// <summary> /// Draws a circle. Recommended to use only for debugging purposes. /// </summary> /// <param name="x">The X position of the top left of the circle.</param> /// <param name="y">The Y position of the top left of the circle.</param> /// <param name="radius">The radius of the circle.</param> /// <param name="color">The fill color of the circle.</param> static public void Circle(float x, float y, float radius, Color color) { tempCircle.Radius = radius; tempCircle.Position = new Vector2f(x, y); tempCircle.FillColor = color.SFMLColor; Target.Draw(tempCircle); }
/// <summary> /// Draws a circle. Recommended to use only for debugging purposes. /// </summary> /// <param name="x">The X position of the top left of the circle.</param> /// <param name="y">The Y position of the top left of the circle.</param> /// <param name="radius">The radius of the circle.</param> /// <param name="fill">The fill color of the circle.</param> /// <param name="outline">The outline color of the circle.</param> /// <param name="outlineThickness">The outline thickness of the circle.</param> static public void Circle(float x, float y, int radius, Color fill = null, Color outline = null, float outlineThickness = 0) { tempCircle.Radius = radius; tempCircle.Position = new Vector2f(x, y); if (fill == null) { tempCircle.FillColor = Color.White.SFMLColor; } else { tempCircle.FillColor = fill.SFMLColor; } tempCircle.OutlineThickness = outlineThickness; if (outline == null) { tempCircle.OutlineColor = Color.None.SFMLColor; } else { tempCircle.OutlineColor = outline.SFMLColor; } Target.Draw(tempCircle); }
protected void Append(float x, float y, Color color = null) { SFMLVertices.Append(x, y, color); }
protected void Append(float x, float y, Color color, float u, float v) { SFMLVertices.Append(x, y, color, u, v); }
/// <summary> /// Creates a rectangle the size of the active Game window. /// </summary> /// <param name="color">The color of the rectangle.</param> /// <returns>A new image containing the rectangle.</returns> static public Image CreateRectangle(Color color) { int w = Game.Instance.Width; int h = Game.Instance.Height; return Image.CreateRectangle(w, h, color); }
/// <summary> /// Creates a rectangle. /// </summary> /// <param name="size">The width and height of the rectangle.</param> /// <param name="color">The color of the rectangle.</param> /// <returns>A new image containing the rectangle.</returns> static public Image CreateRectangle(int size, Color color) { return CreateRectangle(size, size, color); }
/// <summary> /// Draws a line with a thickness using a quad. /// </summary> /// <param name="x1">The X position of the first point.</param> /// <param name="y1">The Y position of the first point.</param> /// <param name="x2">The X position of the second point.</param> /// <param name="y2">The Y position of the second point.</param> /// <param name="color">The color of the line.</param> /// <param name="thickness">The thickness of the line.</param> static public void Line(float x1, float y1, float x2, float y2, Color color, float thickness) { VertexArray vertices = new VertexArray(PrimitiveType.Quads); var line = new Vector2(x2 - x1, y2 - y1); var normalUp = new Vector2(y1 - y2, x2 - x1); var normalDown = new Vector2(y2 - y1, x1 - x2); normalUp.Normalize(thickness * 0.5f); normalDown.Normalize(thickness * 0.5f); float vx, vy; vx = (float)(x1 + normalUp.X); vy = (float)(y1 + normalUp.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); vx = (float)(x1 + normalDown.X); vy = (float)(y1 + normalDown.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); vx = (float)(x2 + normalDown.X); vy = (float)(y2 + normalDown.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); vx = (float)(x2 + normalUp.X); vy = (float)(y2 + normalUp.Y); vertices.Append(new Vertex(new Vector2f(vx, vy), color.SFMLColor)); Drawable(vertices, RenderStates.Default); }