示例#1
0
        /// <summary>
        /// Initializes an animation for the provided collection.
        /// </summary>
        /// <param name="options">
        /// The options to animate.  This parameter cannot be null,
        /// nor can the result of its 
        /// <see cref="MenuOptionCollection.GetVisibleOptions"/>
        /// method be empty.
        /// </param>
        /// <param name="radius">
        /// The radius to apply to the menu layout.
        /// </param>
        /// <param name="frameCount">
        /// The number of frames to render.  Must be at least one.
        /// </param>
        /// <param name="layout">
        /// The object used to lay out the menu options during the animation.
        /// </param>
        /// <param name="modifier">
        /// An object that transforms images during the animation.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if any of the provided parameters are null.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown if the provided frameCount option is less than one.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown if there are no visible options in the provided collection.
        /// </exception>
        public ReverseFrameCollection(
            MenuOptionCollection options,
            int radius,
            int frameCount,
            IFrameLayoutManager layout,
            IFrameModifier modifier
            )
        {
            if( options == null )
                throw new ArgumentNullException(
                    "options",
                    "You must provide a set of options"
                    );

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

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

            else if( frameCount < 1 )
                throw new ArgumentOutOfRangeException(
                    "frameCount",
                    frameCount,
                    "You must provide at least one frame to render"
                    );

            else
            {
                MenuOptionCollection visibleOptions =
                    options.GetVisibleOptions();

                if( visibleOptions.Count == 0 )
                    throw new ArgumentException(
                        "There were no visible options to render",
                        "options"
                        );

                else
                {
                    // Final frame.
                    m_finalFrame = new FinalFrame(
                        visibleOptions,
                        radius,
                        frameCount - 1,
                        frameCount,
                        layout
                        );

                    m_frames.Add( m_finalFrame );

                    // Animate.
                    for( int i = frameCount - 2; i >= 0; i-- )
                        m_frames.Add( new Frame(
                            visibleOptions,
                            radius,
                            i,
                            frameCount,
                            layout,
                            modifier
                            ) );
                }
            }
        }
示例#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 );
            }
        }