Sheets carry a managed buffer of data that allows updates to be made without having to constantly fetch and set data to the texture memory of the video card. This is useful for things like SheetBuilder which make small progressive changes to sheets. However these buffers are often large and are kept alive because sheets are referenced by the sprites that use them. If this buffer is explicitly null'ed when it is no longer needed then the GC can reclaim it. Sometimes a buffer need not even be created because the object using the sheet only works on the texture directly anyway. In practise, this reduced memory consumed by such buffers from ~165 MiB to ~112 MiB (at the start of a new RA skirmish mission).
62 lines
1.7 KiB
C#
Executable File
62 lines
1.7 KiB
C#
Executable File
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2014 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;
|
|
using System.Drawing.Imaging;
|
|
using OpenRA.Graphics;
|
|
using OpenRA.Widgets;
|
|
|
|
namespace OpenRA.Mods.RA.Widgets
|
|
{
|
|
public class HueSliderWidget : SliderWidget
|
|
{
|
|
Sprite hueSprite;
|
|
|
|
public HueSliderWidget() { }
|
|
public HueSliderWidget(HueSliderWidget other) : base(other) { }
|
|
|
|
public override void Initialize(WidgetArgs args)
|
|
{
|
|
base.Initialize(args);
|
|
|
|
using (var hueBitmap = new Bitmap(256, 256))
|
|
{
|
|
var hueSheet = new Sheet(new Size(256, 256), false);
|
|
hueSprite = new Sprite(hueSheet, new Rectangle(0, 0, 256, 1), TextureChannel.Alpha);
|
|
|
|
var bitmapData = hueBitmap.LockBits(hueBitmap.Bounds(),
|
|
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
|
|
unsafe
|
|
{
|
|
var c = (int*)bitmapData.Scan0;
|
|
for (var h = 0; h < 256; h++)
|
|
*(c + h) = HSLColor.FromHSV(h / 255f, 1, 1).RGB.ToArgb();
|
|
}
|
|
hueBitmap.UnlockBits(bitmapData);
|
|
hueSheet.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);
|
|
}
|
|
}
|
|
}
|