mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
b02427417c
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@5614 21ef857c-d57f-4fe0-8362-d861dc6d29cd
81 lines
1.9 KiB
C#
81 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Drawing;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Aga.Controls.Tree.NodeControls
|
|
{
|
|
/// <summary>
|
|
/// Displays an animated icon for those nodes, who are in expanding state.
|
|
/// Parent TreeView must have AsyncExpanding property set to true.
|
|
/// </summary>
|
|
public class ExpandingIcon: NodeControl
|
|
{
|
|
private static GifDecoder _gif;
|
|
private static int _index = 0;
|
|
private static Thread _animatingThread;
|
|
|
|
private static GifDecoder Gif
|
|
{
|
|
get
|
|
{
|
|
if (_gif == null)
|
|
_gif = ResourceHelper.LoadingIcon;
|
|
|
|
return _gif;
|
|
}
|
|
}
|
|
|
|
public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
|
|
{
|
|
return ResourceHelper.LoadingIcon.FrameSize;
|
|
}
|
|
|
|
protected override void OnIsVisibleValueNeeded(NodeControlValueEventArgs args)
|
|
{
|
|
args.Value = args.Node.IsExpandingNow;
|
|
base.OnIsVisibleValueNeeded(args);
|
|
}
|
|
|
|
public override void Draw(TreeNodeAdv node, DrawContext context)
|
|
{
|
|
Rectangle rect = GetBounds(node, context);
|
|
Image img = Gif.GetFrame(_index).Image;
|
|
context.Graphics.DrawImage(img, rect.Location);
|
|
}
|
|
|
|
public static void Start()
|
|
{
|
|
_index = 0;
|
|
if (_animatingThread == null)
|
|
{
|
|
_animatingThread = new Thread(new ThreadStart(IterateIcons));
|
|
_animatingThread.IsBackground = true;
|
|
_animatingThread.Priority = ThreadPriority.Lowest;
|
|
_animatingThread.Start();
|
|
}
|
|
}
|
|
|
|
private static void IterateIcons()
|
|
{
|
|
while (true)
|
|
{
|
|
if (_index < Gif.FrameCount - 1)
|
|
_index++;
|
|
else
|
|
_index = 0;
|
|
|
|
if (IconChanged != null)
|
|
IconChanged(null, EventArgs.Empty);
|
|
|
|
int delay = Gif.GetFrame(_index).Delay;
|
|
Thread.Sleep(delay);
|
|
}
|
|
}
|
|
|
|
public static event EventHandler IconChanged;
|
|
}
|
|
}
|