Exemplo n.º 1
0
        /// <summary>
        /// Initializes the data for this frame.
        /// </summary>
        /// <param name="options">
        /// The options that are to be rendered into this frame.  Cannot
        /// be null, nor can it contain less than one option.
        /// </param>
        /// <param name="radius">
        /// The radius to apply to the menu layout.
        /// </param>
        /// <param name="frameIndex">
        /// Ignored.
        /// </param>
        /// <param name="frameCount">
        /// The number of frames comprising the animation, including this
        /// frame.  Must be at least one.
        /// </param>
        /// <param name="layout">
        /// The object to use for performing layout of the frame.  Cannot be
        /// null.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if any of the arguments are null references.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown if the provided options collection contains no elements.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown if any of the arguments are out of range.
        /// </exception>
        public FinalFrame( 
            MenuOptionCollection options,
            int radius,
            int frameIndex,
            int frameCount,
            IFrameLayoutManager layout
            )
        {
            if( options == null )
                throw new ArgumentNullException(
                    "options",
                    "The options parameter cannot be null"
                    );

            else if( options.Count == 0 )
                throw new ArgumentException(
                    "The options collection must contain at least one option",
                    "options"
                    );

            else if( layout == null )
                throw new ArgumentNullException(
                    "layout",
                    "The layout manager cannot be null"
                    );

            else if( frameCount < 1 )
                throw new ArgumentOutOfRangeException(
                    "frameCount",
                    frameCount,
                    "The frame count must be at least one."
                    );

            else
            {
                // Track the boundaries of this frame...
                int left = 0, top = 0, right = 0, bottom = 0;

                // Position the options...
                for( int i = 0; i < options.Count; i++ )
                {
                    // Get the position and default image.
                    FinalFrameOptionData option = new FinalFrameOptionData(
                        layout.GetOptionPosition(
                            radius,
                            i,
                            options.Count,
                            frameCount - 1,
                            frameCount
                            ),
                        options[ i ]
                        );

                    m_options.Add( option );

                    // Get the width of the normal option.
                    int l = option.CenterPixelPosition.X -
                        option.OptionBitmap.Width / 2;

                    int t = option.CenterPixelPosition.Y -
                        option.OptionBitmap.Height / 2;

                    int r = option.CenterPixelPosition.X +
                        option.OptionBitmap.Width / 2;

                    int b = option.CenterPixelPosition.Y +
                        option.OptionBitmap.Height / 2;

                    if( l < left ) left = l;
                    if( t < top ) top = t;
                    if( r > right ) right = r;
                    if( b > bottom ) bottom = b;

                    // Adjust for the height of the hover image.
                    l = option.CenterPixelPosition.X -
                        option.Option.CachedPrimaryHoverImage.Width / 2;

                    t = option.CenterPixelPosition.Y -
                        option.Option.CachedPrimaryHoverImage.Height / 2;

                    r = option.CenterPixelPosition.X +
                        option.Option.CachedPrimaryHoverImage.Width / 2;

                    b = option.CenterPixelPosition.Y +
                        option.Option.CachedPrimaryHoverImage.Height / 2;

                    if( l < left ) left = l;
                    if( t < top ) top = t;
                    if( r > right ) right = r;
                    if( b > bottom ) bottom = b;

                    // Adjust for the height of the pressed image.
                    l = option.CenterPixelPosition.X -
                        option.Option.CachedPrimaryPressedImage.Width / 2;

                    t = option.CenterPixelPosition.Y -
                        option.Option.CachedPrimaryPressedImage.Height / 2;

                    r = option.CenterPixelPosition.X +
                        option.Option.CachedPrimaryPressedImage.Width / 2;

                    b = option.CenterPixelPosition.Y +
                        option.Option.CachedPrimaryPressedImage.Height / 2;

                    if( l < left ) left = l;
                    if( t < top ) top = t;
                    if( r > right ) right = r;
                    if( b > bottom ) bottom = b;
                }

                // Set our bounds.
                m_bounds = Rectangle.FromLTRB( left, top, right, bottom );
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes the data for the given frame.
        /// </summary>
        /// <param name="options">
        /// The options that are to be rendered into this frame.  Cannot
        /// be null.
        /// </param>
        /// <param name="radius">
        /// The radius to apply to the menu layout.
        /// </param>
        /// <param name="frameIndex">
        /// The index of the frame to render.  Must be at least zero and
        /// must be less than frameCount - 1.
        /// </param>
        /// <param name="frameCount">
        /// The number of frames to render.  Must be at least 1.
        /// </param>
        /// <param name="layout">
        /// The object to use for performing layout of the frame.  Cannot be
        /// null.
        /// </param>
        /// <param name="modifier">
        /// The modifications to apply to the rendered options.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if any of the arguments are null references.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown if any of the arguments are out of range.
        /// </exception>
        public Frame( 
            MenuOptionCollection options,
            int radius,
            int frameIndex,
            int frameCount,
            IFrameLayoutManager layout,
            IFrameModifier modifier
            )
        {
            if( options == null )
                throw new ArgumentNullException(
                    "options",
                    "The options parameter cannot be null"
                    );

            else if( layout == null )
                throw new ArgumentNullException(
                    "layout",
                    "The layout manager cannot be null"
                    );

            else if( modifier == null )
                throw new ArgumentNullException(
                    "modifier",
                    "You must provide a frame modifier"
                    );

            else if( frameCount < 1 )
                throw new ArgumentOutOfRangeException(
                    "frameCount",
                    frameCount,
                    "The frame count must be at least one."
                    );

            else if( frameIndex < 0 || frameIndex >= frameCount - 1 )
                throw new ArgumentOutOfRangeException(
                    "frameIndex",
                    frameIndex,
                    "The frame index must be at least zero, and must be strictly less than frameCount - 1"
                    );

            else
            {
                // Track the boundaries of this frame...
                int left = 0, top = 0, right = 0, bottom = 0;

                // Position and modify the options...
                for( int i = 0; i < options.Count; i++ )
                {
                    // Get the position and default image.
                    FrameOptionData original = new FrameOptionData(
                        layout.GetOptionPosition(
                        radius,
                        i,
                        options.Count,
                        frameIndex,
                        frameCount
                        ),
                        options[ i ].CachedPrimaryImage
                        );

                    FrameOptionData current = new FrameOptionData(
                        original.CenterPixelPosition,
                        (Bitmap)original.OptionBitmap.Clone()
                        );

                    // Modify the default image.
                    current = modifier.ModifyFrame(
                        original,
                        frameIndex,
                        frameCount
                        );

                    // Was the data cleared?
                    if( current != null && current.HasBitmap )
                    {
                        m_options.Add( current );

                        int l = current.CenterPixelPosition.X -
                            current.OptionBitmap.Width / 2;

                        int t = current.CenterPixelPosition.Y -
                            current.OptionBitmap.Height / 2;

                        int r = current.CenterPixelPosition.X +
                            current.OptionBitmap.Width / 2;

                        int b = current.CenterPixelPosition.Y +
                            current.OptionBitmap.Height / 2;

                        if( l < left ) left = l;
                        if( t < top ) top = t;
                        if( r > right ) right = r;
                        if( b > bottom ) bottom = b;
                    }
                }

                // Set our bounds.
                m_bounds = Rectangle.FromLTRB( left, top, right, bottom );
            }
        }