Files
TuxHunter/trunk/src/Icarus/LUCIE/HighlightGrid.cs
2025-06-07 11:39:25 -04:00

101 lines
2.8 KiB
C#

// $Author: asskoala $
// $Date: 2005/12/11 21:07:21 $
// $Revision: 1.1 $
using System;
using System.Drawing;
using Icarus.Graphics.Animation;
namespace Icarus.LUCIE
{
/// <summary>
/// This is just like a component grid, except it also can highlight an item with a special image.
/// </summary>
public class HighlightGrid : ComponentGrid
{
/// <summary>
/// The animation used to highlight the selected component.
/// </summary>
private FramesetAnimation mHighlightAnimation;
/// <summary>
/// Which component is highlighted.
/// </summary>
private AbstractComponent mHighlightedComponent;
/// <summary>
/// The position of the highlight animation.
/// </summary>
private Point mHighlightPosition = new Point(0, 0);
/// <summary>
/// Initializes the highlight grid.
/// </summary>
/// <param name="l">The layout of the components.</param>
/// <param name="highlightAnimation">The animation used to highlight the selected item.</param>
public HighlightGrid(Layout l, FramesetAnimation highlightAnimation) : base(l)
{
this.HighlightAnimation = highlightAnimation;
}
/// <summary>
/// The animation used to highlight the selected component.
/// </summary>
public FramesetAnimation HighlightAnimation
{
get { return this.mHighlightAnimation; }
set { this.mHighlightAnimation = value; }
}
/// <summary>
/// Which child should be highlighted?
/// </summary>
public AbstractComponent HighlightedComponent
{
get { return this.mHighlightedComponent; }
set
{
this.mHighlightedComponent = value;
this.UpdateHighlight();
}
}
/// <summary>
/// Updates the position of the highlight depending on which component is currently selected.
/// </summary>
private void UpdateHighlight()
{
if (this.HighlightedComponent != null)
{
//Find the center of the component:
switch (this.Layout)
{
case Layout.Column:
mHighlightPosition.X = this.Size.Width / 2;
mHighlightPosition.Y = this.HighlightedComponent.Location.Y + this.HighlightedComponent.Size.Height / 2;
break;
case Layout.Row:
mHighlightPosition.X = this.HighlightedComponent.Location.X + this.HighlightedComponent.Size.Width / 2;
mHighlightPosition.Y = this.Size.Height / 2;
break;
}
}
}
protected override void RenderSelf(Rectangle coordinates, IRenderParameters parameters)
{
base.RenderSelf(coordinates, parameters);
if (this.HighlightAnimation != null && this.HighlightedComponent != null)
{
coordinates.Offset(mHighlightPosition);
this.HighlightAnimation.CurrentFrame.Render(coordinates, parameters);
this.HighlightAnimation.update(1);
coordinates.Offset(-mHighlightPosition.X, -mHighlightPosition.Y);
}
}
}
}