Merge pull request #3169 from pchote/colorpicker
New Colorpicker with graphical mixer
This commit is contained in:
@@ -14,59 +14,41 @@ namespace OpenRA.FileFormats
|
||||
{
|
||||
public struct ColorRamp
|
||||
{
|
||||
public byte H,S,L,R;
|
||||
public readonly HSLColor Color;
|
||||
public byte Ramp;
|
||||
|
||||
public ColorRamp(HSLColor color, byte ramp)
|
||||
{
|
||||
Color = color;
|
||||
Ramp = ramp;
|
||||
}
|
||||
|
||||
public ColorRamp(byte h, byte s, byte l, byte r)
|
||||
{
|
||||
H = h; S = s; L = l; R = r;
|
||||
Color = new HSLColor(h, s, l);
|
||||
Ramp = r;
|
||||
}
|
||||
|
||||
/* returns a color along the Lum ramp */
|
||||
public Color GetColor( float t )
|
||||
public Color GetColor(float t)
|
||||
{
|
||||
return ColorFromHSL( H / 255f, S / 255f, float2.Lerp( L / 255f, L*R / (255f * 255f), t ) );
|
||||
var l = float2.Lerp(Color.L, Color.L*Ramp/255f, t);
|
||||
return HSLColor.RGBFromHSL(Color.H/255f, Color.S/255f, l/255f);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{0},{1},{2},{3}".F(H, S, L, R);
|
||||
}
|
||||
|
||||
// hk is hue in the range [0,1] instead of [0,360]
|
||||
static Color ColorFromHSL(float hk, float s, float l)
|
||||
{
|
||||
// Convert from HSL to RGB
|
||||
var q = (l < 0.5f) ? l * (1 + s) : l + s - (l * s);
|
||||
var p = 2 * l - q;
|
||||
|
||||
float[] trgb = { hk + 1 / 3.0f, hk, hk - 1/3.0f };
|
||||
float[] rgb = { 0, 0, 0 };
|
||||
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
while (trgb[k] < 0) trgb[k] += 1.0f;
|
||||
while (trgb[k] > 1) trgb[k] -= 1.0f;
|
||||
}
|
||||
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
if (trgb[k] < 1 / 6.0f) { rgb[k] = (p + ((q - p) * 6 * trgb[k])); }
|
||||
else if (trgb[k] >= 1 / 6.0f && trgb[k] < 0.5) { rgb[k] = q; }
|
||||
else if (trgb[k] >= 0.5f && trgb[k] < 2.0f / 3) { rgb[k] = (p + ((q - p) * 6 * (2.0f / 3 - trgb[k]))); }
|
||||
else { rgb[k] = p; }
|
||||
}
|
||||
|
||||
return Color.FromArgb((int)(rgb[0] * 255), (int)(rgb[1] * 255), (int)(rgb[2] * 255));
|
||||
return "{0},{1}".F(Color.ToString(), Ramp);
|
||||
}
|
||||
|
||||
public static bool operator ==(ColorRamp me, ColorRamp other)
|
||||
{
|
||||
return (me.H == other.H && me.S == other.S && me.L == other.L && me.R == other.R );
|
||||
return (me.Color == other.Color && me.Ramp == other.Ramp);
|
||||
}
|
||||
|
||||
public static bool operator !=(ColorRamp me, ColorRamp other) { return !(me == other); }
|
||||
|
||||
public override int GetHashCode() { return H.GetHashCode() ^ S.GetHashCode() ^ L.GetHashCode() ^ R.GetHashCode(); }
|
||||
public override int GetHashCode() { return Color.GetHashCode() ^ Ramp.GetHashCode(); }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
||||
99
OpenRA.FileFormats/HSLColor.cs
Normal file
99
OpenRA.FileFormats/HSLColor.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
public struct HSLColor
|
||||
{
|
||||
public readonly byte H;
|
||||
public readonly byte S;
|
||||
public readonly byte L;
|
||||
|
||||
public HSLColor(byte h, byte s, byte l)
|
||||
{
|
||||
H = h;
|
||||
S = s;
|
||||
L = l;
|
||||
}
|
||||
|
||||
public Color ToColor()
|
||||
{
|
||||
return RGBFromHSL(H / 255f, S / 255f, L / 255f);
|
||||
}
|
||||
|
||||
public void ToHSV(out float h, out float s, out float v)
|
||||
{
|
||||
var ll = 2*L / 255f;
|
||||
var ss = S / 255f * ((ll <= 1) ? ll : 2 - ll);
|
||||
|
||||
h = H / 255f;
|
||||
s = (2 * ss) / (ll + ss);
|
||||
v = (ll + ss) / 2;
|
||||
}
|
||||
|
||||
public static HSLColor FromHSV(float h, float s, float v)
|
||||
{
|
||||
var ll = 0.5f*(2 - s)*v;
|
||||
var ss = (ll >= 1 || v <= 0) ? 0 : 0.5f*s*v / (ll <= 0.5f ? ll : 1 - ll);
|
||||
return new HSLColor((byte)(255*h), (byte)(255*ss), (byte)(255*ll));
|
||||
}
|
||||
|
||||
public static Color RGBFromHSL(float h, float s, float l)
|
||||
{
|
||||
// Convert from HSL to RGB
|
||||
var q = (l < 0.5f) ? l * (1 + s) : l + s - (l * s);
|
||||
var p = 2 * l - q;
|
||||
|
||||
float[] trgb = { h + 1 / 3.0f, h, h - 1/3.0f };
|
||||
float[] rgb = { 0, 0, 0 };
|
||||
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
while (trgb[k] < 0) trgb[k] += 1.0f;
|
||||
while (trgb[k] > 1) trgb[k] -= 1.0f;
|
||||
}
|
||||
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
if (trgb[k] < 1 / 6.0f) { rgb[k] = (p + ((q - p) * 6 * trgb[k])); }
|
||||
else if (trgb[k] >= 1 / 6.0f && trgb[k] < 0.5) { rgb[k] = q; }
|
||||
else if (trgb[k] >= 0.5f && trgb[k] < 2.0f / 3) { rgb[k] = (p + ((q - p) * 6 * (2.0f / 3 - trgb[k]))); }
|
||||
else { rgb[k] = p; }
|
||||
}
|
||||
|
||||
return Color.FromArgb((int)(rgb[0] * 255), (int)(rgb[1] * 255), (int)(rgb[2] * 255));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{0},{1},{2}".F(H, S, L);
|
||||
}
|
||||
|
||||
public static bool operator ==(HSLColor me, HSLColor other)
|
||||
{
|
||||
return (me.H == other.H && me.S == other.S && me.L == other.L);
|
||||
}
|
||||
|
||||
public static bool operator !=(HSLColor me, HSLColor other) { return !(me == other); }
|
||||
|
||||
public override int GetHashCode() { return H.GetHashCode() ^ S.GetHashCode() ^ L.GetHashCode(); }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
HSLColor o = (HSLColor)obj;
|
||||
return o == this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,6 +137,7 @@
|
||||
<Compile Include="WAngle.cs" />
|
||||
<Compile Include="WRot.cs" />
|
||||
<Compile Include="WRange.cs" />
|
||||
<Compile Include="HSLColor.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
||||
@@ -62,7 +62,8 @@ namespace OpenRA.Widgets
|
||||
panel = fullscreenMask = null;
|
||||
}
|
||||
|
||||
public void AttachPanel(Widget p)
|
||||
public void AttachPanel(Widget p) { AttachPanel(p, null); }
|
||||
public void AttachPanel(Widget p, Action onCancel)
|
||||
{
|
||||
if (panel != null)
|
||||
throw new InvalidOperationException("Attempted to attach a panel to an open dropdown");
|
||||
@@ -71,7 +72,10 @@ namespace OpenRA.Widgets
|
||||
// Mask to prevent any clicks from being sent to other widgets
|
||||
fullscreenMask = new MaskWidget();
|
||||
fullscreenMask.Bounds = new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height);
|
||||
fullscreenMask.OnMouseDown = mi => RemovePanel();
|
||||
fullscreenMask.OnMouseDown += mi => RemovePanel();
|
||||
if (onCancel != null)
|
||||
fullscreenMask.OnMouseDown += _ => onCancel();
|
||||
|
||||
Ui.Root.AddChild(fullscreenMask);
|
||||
|
||||
var oldBounds = panel.Bounds;
|
||||
@@ -105,7 +109,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public class MaskWidget : Widget
|
||||
{
|
||||
public Action<MouseInput> OnMouseDown = _ => {};
|
||||
public event Action<MouseInput> OnMouseDown = _ => {};
|
||||
public MaskWidget() : base() { }
|
||||
public MaskWidget(MaskWidget other)
|
||||
: base(other)
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Widgets
|
||||
}
|
||||
|
||||
float ValueFromPx(int x) { return MinimumValue + (MaximumValue - MinimumValue) * (1f * x / RenderBounds.Width); }
|
||||
int PxFromValue(float x) { return (int)(RenderBounds.Width * (x - MinimumValue) / (MaximumValue - MinimumValue)); }
|
||||
protected int PxFromValue(float x) { return (int)(RenderBounds.Width * (x - MinimumValue) / (MaximumValue - MinimumValue)); }
|
||||
|
||||
public override Widget Clone() { return new SliderWidget(this); }
|
||||
|
||||
|
||||
@@ -155,12 +155,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
|
||||
bool ShowColorPicker(DropDownButtonWidget color, PlayerSettings s)
|
||||
{
|
||||
Action<ColorRamp> onSelect = c => {s.ColorRamp = c; color.RemovePanel();};
|
||||
Action<ColorRamp> onExit = c => {s.ColorRamp = c; color.RemovePanel();};
|
||||
Action<ColorRamp> onChange = c => {colorPreview.Ramp = c;};
|
||||
|
||||
var colorChooser = Game.LoadWidget(world, "COLOR_CHOOSER", null, new WidgetArgs()
|
||||
{
|
||||
{ "onSelect", onSelect },
|
||||
{ "onExit", onExit },
|
||||
{ "onChange", onChange },
|
||||
{ "initialRamp", s.ColorRamp }
|
||||
});
|
||||
|
||||
@@ -433,6 +433,8 @@
|
||||
<Compile Include="ServerTraits\PlayerPinger.cs" />
|
||||
<Compile Include="Widgets\Logic\SpawnSelectorTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ClientTooltipLogic.cs" />
|
||||
<Compile Include="Widgets\ColorMixerWidget.cs" />
|
||||
<Compile Include="Widgets\HueSliderWidget.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
228
OpenRA.Mods.RA/Widgets/ColorMixerWidget.cs
Executable file
228
OpenRA.Mods.RA/Widgets/ColorMixerWidget.cs
Executable file
@@ -0,0 +1,228 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class ColorMixerWidget : Widget
|
||||
{
|
||||
public float[] SRange = {0.2f, 1.0f};
|
||||
public float[] VRange = {0.2f, 1.0f};
|
||||
public event Action OnChange = () => {};
|
||||
|
||||
float H, S, V;
|
||||
Bitmap frontBitmap, swapBitmap, backBitmap;
|
||||
Sprite mixerSprite;
|
||||
bool isMoving;
|
||||
|
||||
bool updateFront, updateBack;
|
||||
object syncWorker = new object();
|
||||
Thread workerThread;
|
||||
bool workerAlive;
|
||||
|
||||
public ColorMixerWidget() : base() {}
|
||||
public ColorMixerWidget(ColorMixerWidget other)
|
||||
: base(other)
|
||||
{
|
||||
OnChange = other.OnChange;
|
||||
H = other.H;
|
||||
S = other.S;
|
||||
V = other.V;
|
||||
}
|
||||
|
||||
public override void Initialize(WidgetArgs args)
|
||||
{
|
||||
base.Initialize(args);
|
||||
|
||||
// Bitmap data is generated in a background thread and then flipped
|
||||
frontBitmap = new Bitmap(256, 256);
|
||||
swapBitmap = new Bitmap(256, 256);
|
||||
backBitmap = new Bitmap(256, 256);
|
||||
|
||||
var rect = new Rectangle((int)(255*SRange[0]), (int)(255*(1 - VRange[1])), (int)(255*(SRange[1] - SRange[0]))+1, (int)(255*(VRange[1] - VRange[0])) + 1);
|
||||
mixerSprite = new Sprite(new Sheet(new Size(256, 256)), rect, TextureChannel.Alpha);
|
||||
mixerSprite.sheet.Texture.SetData(frontBitmap);
|
||||
}
|
||||
|
||||
void GenerateBitmap()
|
||||
{
|
||||
// Generating the selection bitmap is slow,
|
||||
// so we do it in a background thread
|
||||
lock (syncWorker)
|
||||
{
|
||||
updateBack = true;
|
||||
|
||||
if (workerThread == null || !workerAlive)
|
||||
{
|
||||
workerThread = new Thread(GenerateBitmapWorker);
|
||||
workerThread.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateBitmapWorker()
|
||||
{
|
||||
lock (syncWorker)
|
||||
workerAlive = true;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
float hue;
|
||||
lock (syncWorker)
|
||||
{
|
||||
if (!updateBack)
|
||||
{
|
||||
workerAlive = false;
|
||||
break;
|
||||
}
|
||||
updateBack = false;
|
||||
|
||||
// Take a local copy of the hue to generate to avoid tearing
|
||||
hue = H;
|
||||
}
|
||||
|
||||
var bitmapData = backBitmap.LockBits(backBitmap.Bounds(),
|
||||
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||
|
||||
unsafe
|
||||
{
|
||||
int* c = (int*)bitmapData.Scan0;
|
||||
|
||||
// Generate palette in HSV
|
||||
for (var v = 0; v < 256; v++)
|
||||
for (var s = 0; s < 256; s++)
|
||||
*(c + (v * bitmapData.Stride >> 2) + s) = HSLColor.FromHSV(hue, s / 255f, (255 - v) / 255f).ToColor().ToArgb();
|
||||
}
|
||||
|
||||
backBitmap.UnlockBits(bitmapData);
|
||||
lock (syncWorker)
|
||||
{
|
||||
var swap = swapBitmap;
|
||||
swapBitmap = backBitmap;
|
||||
backBitmap = swap;
|
||||
updateFront = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
lock (syncWorker)
|
||||
{
|
||||
if (updateFront)
|
||||
{
|
||||
var swap = swapBitmap;
|
||||
swapBitmap = frontBitmap;
|
||||
frontBitmap = swap;
|
||||
|
||||
mixerSprite.sheet.Texture.SetData(frontBitmap);
|
||||
updateFront = false;
|
||||
}
|
||||
}
|
||||
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(mixerSprite, RenderOrigin, new float2(RenderBounds.Size));
|
||||
|
||||
var sprite = ChromeProvider.GetImage("lobby-bits", "colorpicker");
|
||||
var pos = RenderOrigin + PxFromValue() - new int2(sprite.bounds.Width/2, sprite.bounds.Height/2);
|
||||
WidgetUtils.FillRectWithColor(new Rectangle(pos.X + 3, pos.Y + 3, 10, 10), Color.ToColor());
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos);
|
||||
}
|
||||
|
||||
void SetValueFromPx(int2 xy)
|
||||
{
|
||||
var rb = RenderBounds;
|
||||
var s = SRange[0] + xy.X*(SRange[1] - SRange[0])/rb.Width;
|
||||
var v = SRange[1] - xy.Y*(VRange[1] - VRange[0])/rb.Height;
|
||||
S = s.Clamp(SRange[0], SRange[1]);
|
||||
V = v.Clamp(VRange[0], VRange[1]);
|
||||
}
|
||||
|
||||
int2 PxFromValue()
|
||||
{
|
||||
var rb = RenderBounds;
|
||||
var x = RenderBounds.Width*(S - SRange[0])/(SRange[1] - SRange[0]);
|
||||
var y = RenderBounds.Height*(1 - (V - VRange[0])/(VRange[1] - VRange[0]));
|
||||
return new int2((int)x.Clamp(0, rb.Width), (int)y.Clamp(0, rb.Height));
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Button != MouseButton.Left)
|
||||
return false;
|
||||
if (mi.Event == MouseInputEvent.Down && !TakeFocus(mi))
|
||||
return false;
|
||||
if (!Focused)
|
||||
return false;
|
||||
|
||||
switch (mi.Event)
|
||||
{
|
||||
case MouseInputEvent.Up:
|
||||
isMoving = false;
|
||||
LoseFocus(mi);
|
||||
break;
|
||||
|
||||
case MouseInputEvent.Down:
|
||||
isMoving = true;
|
||||
SetValueFromPx(mi.Location - RenderOrigin);
|
||||
OnChange();
|
||||
break;
|
||||
|
||||
case MouseInputEvent.Move:
|
||||
if (isMoving)
|
||||
{
|
||||
SetValueFromPx(mi.Location - RenderOrigin);
|
||||
OnChange();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public HSLColor Color { get { return HSLColor.FromHSV(H, S, V); } }
|
||||
|
||||
public void Set(float hue)
|
||||
{
|
||||
if (H != hue)
|
||||
{
|
||||
H = hue;
|
||||
GenerateBitmap();
|
||||
OnChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(HSLColor color)
|
||||
{
|
||||
float h,s,v;
|
||||
color.ToHSV(out h, out s, out v);
|
||||
|
||||
if (H != h || S != s || V != v)
|
||||
{
|
||||
if (H != h)
|
||||
{
|
||||
H = h;
|
||||
GenerateBitmap();
|
||||
}
|
||||
|
||||
S = s.Clamp(SRange[0], SRange[1]);
|
||||
V = v.Clamp(VRange[0], VRange[1]);
|
||||
OnChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
63
OpenRA.Mods.RA/Widgets/HueSliderWidget.cs
Executable file
63
OpenRA.Mods.RA/Widgets/HueSliderWidget.cs
Executable file
@@ -0,0 +1,63 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
public class HueSliderWidget : SliderWidget
|
||||
{
|
||||
Bitmap hueBitmap;
|
||||
Sprite hueSprite;
|
||||
|
||||
public HueSliderWidget() : base() {}
|
||||
public HueSliderWidget(HueSliderWidget other) : base(other) {}
|
||||
|
||||
public override void Initialize(WidgetArgs args)
|
||||
{
|
||||
base.Initialize(args);
|
||||
|
||||
hueBitmap = new Bitmap(256, 256);
|
||||
hueSprite = new Sprite(new Sheet(new Size(256, 256)), new Rectangle(0, 0, 256, 1), TextureChannel.Alpha);
|
||||
|
||||
var bitmapData = hueBitmap.LockBits(hueBitmap.Bounds(),
|
||||
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
||||
unsafe
|
||||
{
|
||||
int* c = (int*)bitmapData.Scan0;
|
||||
for (var h = 0; h < 256; h++)
|
||||
*(c + h) = HSLColor.FromHSV(h/255f, 1, 1).ToColor().ToArgb();
|
||||
}
|
||||
hueBitmap.UnlockBits(bitmapData);
|
||||
|
||||
hueSprite.sheet.Texture.SetData(hueBitmap);
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (!IsVisible())
|
||||
return;
|
||||
|
||||
var ro = RenderOrigin;
|
||||
var rb = RenderBounds;
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(hueSprite, ro, new float2(rb.Size));
|
||||
|
||||
var sprite = ChromeProvider.GetImage("lobby-bits", "huepicker");
|
||||
var pos = RenderOrigin + new int2(PxFromValue(Value).Clamp(0, rb.Width-1) - sprite.bounds.Width/2, (rb.Height-sprite.bounds.Height)/2);
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,56 +17,32 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class ColorPickerLogic
|
||||
{
|
||||
ColorRamp ramp;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ColorPickerLogic(Widget widget, ColorRamp initialRamp, Action<ColorRamp> onChange,
|
||||
Action<ColorRamp> onSelect, WorldRenderer worldRenderer)
|
||||
public ColorPickerLogic(Widget widget, HSLColor initialColor, Action<HSLColor> onChange, WorldRenderer worldRenderer)
|
||||
{
|
||||
var panel = widget;
|
||||
ramp = initialRamp;
|
||||
var hueSlider = panel.Get<SliderWidget>("HUE");
|
||||
var satSlider = panel.Get<SliderWidget>("SAT");
|
||||
var lumSlider = panel.Get<SliderWidget>("LUM");
|
||||
var hueSlider = widget.Get<SliderWidget>("HUE");
|
||||
var mixer = widget.Get<ColorMixerWidget>("MIXER");
|
||||
var randomButton = widget.GetOrNull<ButtonWidget>("RANDOM_BUTTON");
|
||||
|
||||
Action sliderChanged = () =>
|
||||
{
|
||||
ramp = new ColorRamp((byte)(255*hueSlider.Value),
|
||||
(byte)(255*satSlider.Value),
|
||||
(byte)(255*lumSlider.Value),
|
||||
10);
|
||||
onChange(ramp);
|
||||
};
|
||||
hueSlider.OnChange += _ => mixer.Set(hueSlider.Value);
|
||||
mixer.OnChange += () => onChange(mixer.Color);
|
||||
|
||||
hueSlider.OnChange += _ => sliderChanged();
|
||||
satSlider.OnChange += _ => sliderChanged();
|
||||
lumSlider.OnChange += _ => sliderChanged();
|
||||
|
||||
Action updateSliders = () =>
|
||||
{
|
||||
hueSlider.Value = ramp.H / 255f;
|
||||
satSlider.Value = ramp.S / 255f;
|
||||
lumSlider.Value = ramp.L / 255f;
|
||||
};
|
||||
|
||||
panel.Get<ButtonWidget>("SAVE_BUTTON").OnClick = () => onSelect(ramp);
|
||||
|
||||
var randomButton = panel.Get<ButtonWidget>("RANDOM_BUTTON");
|
||||
if (randomButton != null)
|
||||
randomButton.OnClick = () =>
|
||||
{
|
||||
// Avoid colors with low sat or lum
|
||||
var hue = (byte)Game.CosmeticRandom.Next(255);
|
||||
var sat = (byte)Game.CosmeticRandom.Next(255);
|
||||
var lum = (byte)Game.CosmeticRandom.Next(51,255);
|
||||
var sat = (byte)Game.CosmeticRandom.Next(70, 255);
|
||||
var lum = (byte)Game.CosmeticRandom.Next(70, 255);
|
||||
|
||||
ramp = new ColorRamp(hue, sat, lum, 10);
|
||||
updateSliders();
|
||||
sliderChanged();
|
||||
mixer.Set(new HSLColor(hue, sat, lum));
|
||||
hueSlider.Value = hue / 255f;
|
||||
};
|
||||
|
||||
// Set the initial state
|
||||
updateSliders();
|
||||
onChange(ramp);
|
||||
mixer.Set(initialColor);
|
||||
hueSlider.Value = initialColor.H / 255f;
|
||||
onChange(mixer.Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,28 +103,27 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
public static void ShowColorDropDown(DropDownButtonWidget color, Session.Client client,
|
||||
OrderManager orderManager, ColorPreviewManagerWidget preview)
|
||||
{
|
||||
Action<ColorRamp> onSelect = c =>
|
||||
Action onExit = () =>
|
||||
{
|
||||
if (client.Bot == null)
|
||||
{
|
||||
Game.Settings.Player.ColorRamp = c;
|
||||
Game.Settings.Player.ColorRamp = preview.Ramp;
|
||||
Game.Settings.Save();
|
||||
}
|
||||
|
||||
color.RemovePanel();
|
||||
orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, c)));
|
||||
orderManager.IssueOrder(Order.Command("color {0} {1}".F(client.Index, preview.Ramp)));
|
||||
};
|
||||
|
||||
Action<ColorRamp> onChange = c => preview.Ramp = c;
|
||||
Action<HSLColor> onChange = c => preview.Ramp = new ColorRamp(c, 10);
|
||||
|
||||
var colorChooser = Game.LoadWidget(orderManager.world, "COLOR_CHOOSER", null, new WidgetArgs()
|
||||
{
|
||||
{ "onSelect", onSelect },
|
||||
{ "onChange", onChange },
|
||||
{ "initialRamp", client.ColorRamp }
|
||||
{ "initialColor", client.ColorRamp.Color }
|
||||
});
|
||||
|
||||
color.AttachPanel(colorChooser);
|
||||
color.AttachPanel(colorChooser, onExit);
|
||||
}
|
||||
|
||||
public static Dictionary<int2, Session.Client> GetSpawnClients(OrderManager orderManager, Map map)
|
||||
|
||||
@@ -61,9 +61,9 @@
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="11.313708"
|
||||
inkscape:cx="352.22285"
|
||||
inkscape:cy="474.91804"
|
||||
inkscape:zoom="5.656854"
|
||||
inkscape:cx="366.7043"
|
||||
inkscape:cy="471.90817"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
@@ -1276,11 +1276,23 @@
|
||||
inkscape:export-ydpi="90" />
|
||||
<path
|
||||
style="fill:#ffc000;fill-opacity:1;stroke:none"
|
||||
d="m 340,584.3622 0,-5 1.81818,2 2.18182,-2 2.18182,2 1.81818,-2 0,5 z"
|
||||
d="m 340,584.3622 0,-5 1.59091,2 1.90909,-2 1.90909,2 1.59091,-2 0,5 z"
|
||||
id="path3179"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cccccccc"
|
||||
inkscape:export-xdpi="90"
|
||||
inkscape:export-ydpi="90" />
|
||||
<path
|
||||
sodipodi:nodetypes="ccccc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path4066"
|
||||
d="m 395,651.3622 -3.5,-4 0,0 -3.5,4 z"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none" />
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||
d="m 395,636.3622 -3.5,4 0,0 -3.5,-4 z"
|
||||
id="path4070"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccccc" />
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 71 KiB |
@@ -390,6 +390,8 @@ lobby-bits: chrome.png
|
||||
spawn-claimed: 256,32,16,16
|
||||
spawn-unclaimed: 256,48,16,16
|
||||
admin: 340,39,7,5
|
||||
colorpicker: 256,32,16,16
|
||||
huepicker: 388,96,7,15
|
||||
|
||||
checkbox-bits: chrome.png
|
||||
checked: 272,32,16,16
|
||||
|
||||
@@ -1,71 +1,46 @@
|
||||
Background@COLOR_CHOOSER:
|
||||
Logic:ColorPickerLogic
|
||||
Background:panel-black
|
||||
Width:315
|
||||
Height:130
|
||||
Width:234
|
||||
Height:105
|
||||
Children:
|
||||
Button@SAVE_BUTTON:
|
||||
Key:return
|
||||
X:210
|
||||
Y:90
|
||||
Width:90
|
||||
Height:25
|
||||
Text:Save
|
||||
Button@RANDOM_BUTTON:
|
||||
X:15
|
||||
Y:90
|
||||
Width:90
|
||||
Height:25
|
||||
Text:Random
|
||||
ShpImage@FACT:
|
||||
X:220
|
||||
Y:15
|
||||
Image:fact
|
||||
Palette:colorpicker
|
||||
Label@HUE_LABEL:
|
||||
Background@HUEBG:
|
||||
Background:panel-black
|
||||
X:5
|
||||
Y:5
|
||||
Width:40
|
||||
Height:20
|
||||
Align:Right
|
||||
Text:Hue:
|
||||
Font:Bold
|
||||
Slider@HUE:
|
||||
X:43
|
||||
Y:10
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
Label@SAT_LABEL:
|
||||
Width:148
|
||||
Height:13
|
||||
Children:
|
||||
HueSlider@HUE:
|
||||
X:2
|
||||
Y:2
|
||||
Width:144
|
||||
Height:9
|
||||
Ticks:5
|
||||
Background@MIXERBG:
|
||||
Background:panel-black
|
||||
X:5
|
||||
Y:30
|
||||
Width:40
|
||||
Height:20
|
||||
Align:Right
|
||||
Text:Sat:
|
||||
Font:Bold
|
||||
Slider@SAT:
|
||||
X:43
|
||||
Y:35
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
Label@LUM_LABEL:
|
||||
X:5
|
||||
Y:55
|
||||
Width:40
|
||||
Height:20
|
||||
Align:Right
|
||||
Text:Lum:
|
||||
Font:Bold
|
||||
Slider@LUM:
|
||||
X:43
|
||||
Y:60
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
MinimumValue: 0.2
|
||||
MaximumValue: 1
|
||||
Y:23
|
||||
Width:148
|
||||
Height:76
|
||||
Children:
|
||||
ColorMixer@MIXER:
|
||||
X:2
|
||||
Y:2
|
||||
Width:144
|
||||
Height:72
|
||||
ShpImage@FACT:
|
||||
X:160
|
||||
Y:13
|
||||
Image:fact
|
||||
Palette:colorpicker
|
||||
Button@RANDOM_BUTTON:
|
||||
Key:tab
|
||||
X:158
|
||||
Y:74
|
||||
Width:70
|
||||
Height:25
|
||||
Text:Random
|
||||
|
||||
ScrollPanel@LABEL_DROPDOWN_TEMPLATE:
|
||||
Width:DROPDOWN_WIDTH
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
@@ -240,6 +240,8 @@ lobby-bits: spawnpoints.png
|
||||
spawn-unclaimed: 528,128,16,16
|
||||
spawn-claimed: 512,128,16,16
|
||||
admin: 37,5,7,5
|
||||
colorpicker: 512,128,16,16
|
||||
huepicker: 45,0,7,15
|
||||
|
||||
strategic: strategic.png
|
||||
unowned: 0,0,32,32
|
||||
|
||||
@@ -1,66 +1,44 @@
|
||||
Background@COLOR_CHOOSER:
|
||||
Logic:ColorPickerLogic
|
||||
Background:dialog2
|
||||
Width:310
|
||||
Height:120
|
||||
Width:234
|
||||
Height:105
|
||||
Children:
|
||||
Button@SAVE_BUTTON:
|
||||
X:210
|
||||
Y:85
|
||||
Width:90
|
||||
Height:25
|
||||
Text:Save
|
||||
Font:Bold
|
||||
Background@HUEBG:
|
||||
Background:dialog3
|
||||
X:5
|
||||
Y:5
|
||||
Width:148
|
||||
Height:13
|
||||
Children:
|
||||
HueSlider@HUE:
|
||||
X:2
|
||||
Y:2
|
||||
Width:144
|
||||
Height:9
|
||||
Ticks:5
|
||||
Background@MIXERBG:
|
||||
Background:dialog3
|
||||
X:5
|
||||
Y:23
|
||||
Width:148
|
||||
Height:76
|
||||
Children:
|
||||
ColorMixer@MIXER:
|
||||
X:2
|
||||
Y:2
|
||||
Width:144
|
||||
Height:72
|
||||
ShpImage@FACT:
|
||||
X:160
|
||||
Y:8
|
||||
Image:carryall
|
||||
Frame:13
|
||||
Palette:colorpicker
|
||||
Button@RANDOM_BUTTON:
|
||||
X:115
|
||||
Y:85
|
||||
Width:90
|
||||
Key:tab
|
||||
X:158
|
||||
Y:74
|
||||
Width:70
|
||||
Height:25
|
||||
Text:Random
|
||||
Font:Bold
|
||||
ShpImage@CARRYALL:
|
||||
X:220
|
||||
Y:10
|
||||
Image:carryall
|
||||
Palette:colorpicker
|
||||
Label@HUE_LABEL:
|
||||
X:0
|
||||
Y:5
|
||||
Width:40
|
||||
Height:20
|
||||
Align: Right
|
||||
Text: Hue:
|
||||
Slider@HUE:
|
||||
X:43
|
||||
Y:10
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
Label@SAT_LABEL:
|
||||
X:0
|
||||
Y:30
|
||||
Width:40
|
||||
Height:20
|
||||
Align: Right
|
||||
Text: Sat:
|
||||
Slider@SAT:
|
||||
X:43
|
||||
Y:35
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
Label@LUM_LABEL:
|
||||
X:0
|
||||
Y:55
|
||||
Width:40
|
||||
Height:20
|
||||
Align: Right
|
||||
Text: Lum:
|
||||
Slider@LUM:
|
||||
X:43
|
||||
Y:60
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
MinimumValue: 0.2
|
||||
MaximumValue: 1
|
||||
|
||||
@@ -173,6 +173,8 @@ lobby-bits: spawnpoints.png
|
||||
spawn-unclaimed: 528,128,16,16
|
||||
spawn-claimed: 512,128,16,16
|
||||
admin: 37,5,7,5
|
||||
colorpicker: 512,128,16,16
|
||||
huepicker: 45,0,7,15
|
||||
|
||||
strategic: strategic.png
|
||||
unowned: 0,0,32,32
|
||||
|
||||
@@ -1,66 +1,43 @@
|
||||
Background@COLOR_CHOOSER:
|
||||
Logic:ColorPickerLogic
|
||||
Background:dialog2
|
||||
Width:310
|
||||
Height:120
|
||||
Width:234
|
||||
Height:105
|
||||
Children:
|
||||
Button@SAVE_BUTTON:
|
||||
X:210
|
||||
Y:85
|
||||
Width:90
|
||||
Height:25
|
||||
Text:Save
|
||||
Font:Bold
|
||||
Button@RANDOM_BUTTON:
|
||||
X:115
|
||||
Y:85
|
||||
Width:90
|
||||
Height:25
|
||||
Text:Random
|
||||
Font:Bold
|
||||
Background@HUEBG:
|
||||
Background:dialog3
|
||||
X:5
|
||||
Y:5
|
||||
Width:148
|
||||
Height:13
|
||||
Children:
|
||||
HueSlider@HUE:
|
||||
X:2
|
||||
Y:2
|
||||
Width:144
|
||||
Height:9
|
||||
Ticks:5
|
||||
Background@MIXERBG:
|
||||
Background:dialog3
|
||||
X:5
|
||||
Y:23
|
||||
Width:148
|
||||
Height:76
|
||||
Children:
|
||||
ColorMixer@MIXER:
|
||||
X:2
|
||||
Y:2
|
||||
Width:144
|
||||
Height:72
|
||||
ShpImage@FACT:
|
||||
X:220
|
||||
Y:10
|
||||
X:156
|
||||
Y:1
|
||||
Image:fact
|
||||
Palette:colorpicker
|
||||
Label@HUE_LABEL:
|
||||
X:0
|
||||
Y:5
|
||||
Width:40
|
||||
Height:20
|
||||
Align: Right
|
||||
Text: Hue:
|
||||
Slider@HUE:
|
||||
X:43
|
||||
Y:10
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
Label@SAT_LABEL:
|
||||
X:0
|
||||
Y:30
|
||||
Width:40
|
||||
Height:20
|
||||
Align: Right
|
||||
Text: Sat:
|
||||
Slider@SAT:
|
||||
X:43
|
||||
Y:35
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
Label@LUM_LABEL:
|
||||
X:0
|
||||
Y:55
|
||||
Width:40
|
||||
Height:20
|
||||
Align: Right
|
||||
Text: Lum:
|
||||
Slider@LUM:
|
||||
X:43
|
||||
Y:60
|
||||
Width:160
|
||||
Height:20
|
||||
Ticks:5
|
||||
MinimumValue: 0.2
|
||||
MaximumValue: 1
|
||||
Button@RANDOM_BUTTON:
|
||||
Key:tab
|
||||
X:158
|
||||
Y:74
|
||||
Width:70
|
||||
Height:25
|
||||
Text:Random
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.6 KiB |
Reference in New Issue
Block a user