// $Author: asskoala $ // $Date: 2005/12/11 21:07:21 $ // $Revision: 1.1 $ using System; using System.Drawing; using Icarus.Graphics.Animation; namespace Icarus.LUCIE { /// /// This is just like a component grid, except it also can highlight an item with a special image. /// public class HighlightGrid : ComponentGrid { /// /// The animation used to highlight the selected component. /// private FramesetAnimation mHighlightAnimation; /// /// Which component is highlighted. /// private AbstractComponent mHighlightedComponent; /// /// The position of the highlight animation. /// private Point mHighlightPosition = new Point(0, 0); /// /// Initializes the highlight grid. /// /// The layout of the components. /// The animation used to highlight the selected item. public HighlightGrid(Layout l, FramesetAnimation highlightAnimation) : base(l) { this.HighlightAnimation = highlightAnimation; } /// /// The animation used to highlight the selected component. /// public FramesetAnimation HighlightAnimation { get { return this.mHighlightAnimation; } set { this.mHighlightAnimation = value; } } /// /// Which child should be highlighted? /// public AbstractComponent HighlightedComponent { get { return this.mHighlightedComponent; } set { this.mHighlightedComponent = value; this.UpdateHighlight(); } } /// /// Updates the position of the highlight depending on which component is currently selected. /// 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); } } } }