/// <summary>
        /// Does the "burn-in" portion of the frame modifier.
        /// </summary>
        private FrameOptionData BurnIn( 
            FrameOptionData option,
            float percentAlpha
            )
        {
            Bitmap mask = GetMask( option.OptionBitmap );
            Effects.SetImageOpacity(
                mask,
                (byte)(255 * percentAlpha )
                );

            return new FrameOptionData(
                option.CenterPixelPosition,
                mask
                );
        }
        /// <summary>
        /// Applies the burn-in modification to the provided frame option.
        /// </summary>
        public FrameOptionData ModifyFrame(
            FrameOptionData option, 
            int frameIndex, 
            int frameCount
            )
        {
            if( option != null && option.HasBitmap )
            {
                // Get the transition frame.
                int transition = (int)Math.Max( 1, frameCount / 3 );

                if( frameIndex < transition )
                {
                    // Burn in.
                    int frames = transition;
                    float percent = (float)Math.Pow(
                        (frameIndex + 1.0) / transition,
                        2
                        );

                    return BurnIn( option, percent );
                }
                else
                {
                    // Calm down.
                    int frames = frameCount - transition;
                    float percent = (float)Math.Pow(
                        1 - (frameIndex - transition) / (float)frameCount,
                        2
                        );

                    return CalmDown( option, percent );
                }
            }
            else
                return option;
        }
Пример #3
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 );
            }
        }
        /// <summary>
        /// Fades the white down to the menu option.
        /// </summary>
        private FrameOptionData CalmDown(
            FrameOptionData option,
            float percentAlpha
            )
        {
            Bitmap mask = GetMask( option.OptionBitmap );
            Effects.SetImageOpacity(
                mask,
                (byte)(255 * percentAlpha )
                );

            Bitmap newImage = new Bitmap( option.OptionBitmap );
            Graphics g = Graphics.FromImage( newImage );

            g.DrawImage( mask, 0, 0 );
            g.Dispose();

            return new FrameOptionData(
                option.CenterPixelPosition,
                newImage
                );
        }
        /// <summary>
        /// Returns a new option that is the result of the image resized by
        /// a percentage that is dependent on the current position of the
        /// animation.
        /// </summary>
        public FrameOptionData ModifyFrame(
            FrameOptionData option, 
            int frameIndex, 
            int frameCount
            )
        {
            if( option != null && option.HasBitmap )
            {
                float scale = (float)Math.Sqrt(
                    (float)frameIndex / (float)frameCount
                    );

                int newWidth = (int)Math.Max(
                    1, option.OptionBitmap.Width * scale
                    );
                int newHeight = (int)Math.Max(
                    1,
                    option.OptionBitmap.Height * scale
                    );

                Bitmap newImage = new Bitmap(
                    option.OptionBitmap,
                    new Size( newWidth, newHeight )
                    );

                return new FrameOptionData(
                    option.CenterPixelPosition,
                    newImage
                    );
            }
            else
                return option;
        }
 /// <summary>
 /// Simply returns option.
 /// </summary>
 public FrameOptionData ModifyFrame(
     FrameOptionData option, 
     int frameIndex, 
     int frameCount
     )
 {
     return option;
 }
        /// <summary>
        /// Modifies the frame by fading it in and transitioning it from a 
        /// one-pixel image to its normal size.
        /// </summary>
        public FrameOptionData ModifyFrame(
            FrameOptionData option, 
            int frameIndex, 
            int frameCount
            )
        {
            if( option != null && option.HasBitmap )
            {
                // Scale the image down first.
                float scale = (float)Math.Sqrt(
                    (float)frameIndex / (float)frameCount
                    );

                int newWidth = (int)Math.Max(
                    1, option.OptionBitmap.Width * scale
                    );
                int newHeight = (int)Math.Max(
                    1,
                    option.OptionBitmap.Height * scale
                    );

                Bitmap newImage = new Bitmap(
                    option.OptionBitmap,
                    new Size( newWidth, newHeight )
                    );

                // Now modify its transparency.
                Effects.SetImageOpacity(
                    newImage,
                    (byte)(255 * scale)
                    );

                // All set.
                return new FrameOptionData(
                    option.CenterPixelPosition,
                    newImage
                    );
            }
            else
                return option;
        }
        /// <summary>
        /// Modifies the provided option image, given the current position in
        /// the animation.
        /// </summary>
        public FrameOptionData ModifyFrame(
            FrameOptionData originalOption,
            int frameIndex, 
            int frameCount
            )
        {
            if( originalOption != null && originalOption.HasBitmap )
            {
                // Determine maximum opacity as a function of the current
                // frame.
                byte alpha =
                    (byte)(255.0 *
                    (float)Math.Sqrt( (float)frameIndex / (float)frameCount)
                    );

                // Make the image only so opaque!
                Bitmap option = new Bitmap( originalOption.OptionBitmap );
                Effects.SetImageOpacity( option, alpha );

                // Return the modified image.
                return new FrameOptionData(
                    originalOption.CenterPixelPosition,
                    option
                    );
            }
            else
                return originalOption;
        }