Add a hue selector widget.
This commit is contained in:
@@ -77,7 +77,7 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
float ValueFromPx(int x) { return MinimumValue + (MaximumValue - MinimumValue) * (1f * x / RenderBounds.Width); }
|
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); }
|
public override Widget Clone() { return new SliderWidget(this); }
|
||||||
|
|
||||||
|
|||||||
@@ -433,6 +433,7 @@
|
|||||||
<Compile Include="Widgets\Logic\SpawnSelectorTooltipLogic.cs" />
|
<Compile Include="Widgets\Logic\SpawnSelectorTooltipLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\ClientTooltipLogic.cs" />
|
<Compile Include="Widgets\Logic\ClientTooltipLogic.cs" />
|
||||||
<Compile Include="Widgets\ColorMixerWidget.cs" />
|
<Compile Include="Widgets\ColorMixerWidget.cs" />
|
||||||
|
<Compile Include="Widgets\HueSliderWidget.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user