Added GradientColorBlockWidget

This commit is contained in:
teinarss
2019-04-16 20:24:07 +02:00
committed by Paul Chote
parent b25d0694b8
commit dad29cd3b3
3 changed files with 91 additions and 0 deletions

View File

@@ -238,6 +238,29 @@ namespace OpenRA.Graphics
parent.DrawRGBAVertices(vertices); parent.DrawRGBAVertices(vertices);
} }
public void FillRect(float3 a, float3 b, float3 c, float3 d, Color topLeftColor, Color topRightColor, Color bottomRightColor, Color bottomLeftColor)
{
vertices[0] = VertexWithColor(a + Offset, topLeftColor);
vertices[1] = VertexWithColor(b + Offset, topRightColor);
vertices[2] = VertexWithColor(c + Offset, bottomRightColor);
vertices[3] = VertexWithColor(c + Offset, bottomRightColor);
vertices[4] = VertexWithColor(d + Offset, bottomLeftColor);
vertices[5] = VertexWithColor(a + Offset, topLeftColor);
parent.DrawRGBAVertices(vertices);
}
static Vertex VertexWithColor(float3 xyz, Color color)
{
color = Util.PremultiplyAlpha(color);
var cr = color.R / 255.0f;
var cg = color.G / 255.0f;
var cb = color.B / 255.0f;
var ca = color.A / 255.0f;
return new Vertex(xyz, cr, cg, cb, ca, 0, 0);
}
public void FillEllipse(float3 tl, float3 br, Color color, int vertices = 32) public void FillEllipse(float3 tl, float3 br, Color color, int vertices = 32)
{ {
// TODO: Create an ellipse polygon instead // TODO: Create an ellipse polygon instead

View File

@@ -71,6 +71,17 @@ namespace OpenRA.Widgets
Game.Renderer.RgbaColorRenderer.FillRect(tl, br, c); Game.Renderer.RgbaColorRenderer.FillRect(tl, br, c);
} }
public static void FillRectWithColor(Rectangle r, Color topLeftColor, Color topRightColor, Color bottomRightColor, Color bottomLeftColor)
{
var tl = new float2(r.Left - 0.5f, r.Top - 0.5f);
var br = new float2(r.Right - 0.5f, r.Bottom - 0.5f);
var tr = new float3(br.X, tl.Y, 0);
var bl = new float3(tl.X, br.Y, 0);
Game.Renderer.RgbaColorRenderer.FillRect(tl, tr, br, bl, topLeftColor, topRightColor, bottomRightColor, bottomLeftColor);
}
public static void FillEllipseWithColor(Rectangle r, Color c) public static void FillEllipseWithColor(Rectangle r, Color c)
{ {
var tl = new float2(r.Left, r.Top); var tl = new float2(r.Left, r.Top);

View File

@@ -0,0 +1,57 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using OpenRA.Primitives;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets
{
public class GradientColorBlockWidget : Widget
{
public Color TopLeftColor { get; set; }
public Color TopRightColor { get; set; }
public Color BottomRightColor { get; set; }
public Color BottomLeftColor { get; set; }
public Func<Color> GetTopLeftColor;
public Func<Color> GetTopRightColor;
public Func<Color> GetBottomRightColor;
public Func<Color> GetBottomLeftColor;
public GradientColorBlockWidget()
{
GetTopLeftColor = () => TopLeftColor;
GetTopRightColor = () => TopRightColor;
GetBottomRightColor = () => BottomRightColor;
GetBottomLeftColor = () => BottomLeftColor;
}
protected GradientColorBlockWidget(GradientColorBlockWidget widget)
: base(widget)
{
GetTopLeftColor = widget.GetTopLeftColor;
GetTopRightColor = widget.GetTopRightColor;
GetBottomRightColor = widget.GetBottomRightColor;
GetBottomLeftColor = widget.GetBottomLeftColor;
}
public override Widget Clone()
{
return new GradientColorBlockWidget(this);
}
public override void Draw()
{
WidgetUtils.FillRectWithColor(RenderBounds, GetTopLeftColor(), GetTopRightColor(), GetBottomRightColor(), GetBottomLeftColor());
}
}
}