コード例 #1
0
        /// <summary>
        /// This constructor gets all the pieces at once.
        /// </summary>
        /// <param name="rBitmapSmall"></param>
        /// <param name="rBitmap"></param>
        /// <param name="description"></param>
        /// <param name="rLargeSizeBitmap"></param>
        public MenuItem(Resources.BitmapResources rBitmapSmall,
                        Resources.BitmapResources rBitmap, string description,
                        Resources.BitmapResources rLargeSizeBitmap)
        {
            // Get the images from the resource manager.
            _imageSmall = Resources.GetBitmap(rBitmapSmall);
            _image      = Resources.GetBitmap(rBitmap);

            // Set the description.
            _description = description;

            // Create the step arrays for zooming in and out.
            _widthSteps  = new int[MenuItemPanel.maxStep];
            _heightSteps = new int[MenuItemPanel.maxStep];

            // Get the difference in size between the large and small images.
            int wDiff = _image.Width - _imageSmall.Width;
            int hDiff = _image.Height - _imageSmall.Height;

            // Pre-calculate the width and height values for scaling the image.
            for (int i = 1; i < MenuItemPanel.maxStep; i++)
            {
                _widthSteps[i]  = (wDiff / MenuItemPanel.maxStep) * i;
                _heightSteps[i] = (hDiff / MenuItemPanel.maxStep) * i;
            }

            // Set the large width and height based on one of the main icons.
            Bitmap bmp = Resources.GetBitmap(rLargeSizeBitmap);

            _largeWidth  = bmp.Width;
            _largeHeight = bmp.Height;
        }
コード例 #2
0
        /// <summary>
        /// Override the OnRender method to do the actual drawing of the menu.
        /// </summary>
        /// <param name="dc">The drawing context to render.</param>
        public override void OnRender(DrawingContext dc)
        {
            // Call the base class in case this control contains other controls.
            // Depending on where those controls are placed, this call might not
            // be optimal.
            base.OnRender(dc);

            // Calculate some initial values for positioning and drawing the
            // MenuItems.

            // Set the width of each MenuItem.
            int largeX = Resources.GetBitmap(
                Resources.BitmapResources.Canvas_Panel_Icon).Width +
                         xOffsetSeparation;

            // Set the starting x position.
            int x = (_width / 2) - ((largeX * 2) + (largeX / 2));

            // Set the starting y position.
            int y = 6;

            // Set the scaling of the current MenuItem.
            int scale = 0;

            // Set the scaling offset based on the animation step.
            int scaleOffset = System.Math.Abs(_animationStep);

            // Adjust the x based on the animation step.
            x += _animationStep * 5;

            // Iterate through the children, limiting them to 2 in front and 2
            // behind the current child.  This places the current MenuItem in the
            // middle of the menu.
            for (int i = _currentChild - 2; i < _currentChild + 3; i++)
            {
                // If we are on the current child...
                if (i == _currentChild)
                {
                    // Scale the current child based on the current animation step
                    // value.  The current child is getting smaller, so take the
                    // largest value (maxStep) and subtract the current scaling
                    // offset.
                    scale = maxStep - scaleOffset;
                }
                else
                {
                    // If we are moving left and are drawing the child to the left,
                    // or we are moving right and are drawing the child to the
                    // right, then that child needs to be growing in size.  Else the
                    // child is drawn without any scaling.
                    if ((_animationStep < 0 && i == _currentChild + 1) ||
                        (_animationStep > 0 && i == _currentChild - 1))
                    {
                        scale = scaleOffset;
                    }
                    else
                    {
                        scale = 0;
                    }
                }

                // Variable to point to the current MenuItem we want to draw.
                MenuItem menuItem = null;

                // Get the correct MenuItem from the array based on the value of i.
                // Because we are looking 2 left and 2 right, if the current child
                // is near the beginning or end of the array, we have to watch for
                // wrapping around the ends.
                if (i < 0)
                {
                    menuItem = (MenuItem)MenuItemList[MenuItemList.Count + i];
                }
                else if (i > MenuItemList.Count - 1)
                {
                    menuItem = (MenuItem)MenuItemList[i - MenuItemList.Count];
                }
                else
                {
                    menuItem = (MenuItem)MenuItemList[i];
                }

                // Have the MenuItem render itself based on the position and scaling
                // calculated.
                menuItem.Render(dc, x, y, scale);

                // Increment the x position by the size of the MenuItems
                x += largeX;
            }

            // Draw the current menuItem's text.
            if (_width > 0)
            {
                // Check the window size for displaying instructions.
                int step = 20;
                int row  = 120;

                // Check for portrait display.
                if (_width < _height)
                {
                    step = 40;
                }

                // Draw the description of the current MenuItem.
                string text = ((MenuItem)MenuItemList[_currentChild]).Description;
                dc.DrawText(ref text,
                            Resources.GetFont(Resources.FontResources.NinaBFont),
                            Color.White, 10, row, _width - 20, step, TextAlignment.Center,
                            TextTrimming.None);

                // Draw the basic instructions for the menu.
                text = Resources.GetString(Resources.StringResources.MenuScrolling);
                row += (step * 2);
                dc.DrawText(ref text,
                            Resources.GetFont(Resources.FontResources.NinaBFont),
                            Color.White, 10, row, _width - 20, step, TextAlignment.Center,
                            TextTrimming.None);
                text = Resources.GetString(Resources.StringResources.MenuSelection);
                row += step;
                dc.DrawText(ref text,
                            Resources.GetFont(Resources.FontResources.NinaBFont),
                            Color.White, 10, row, _width - 20, step, TextAlignment.Center,
                            TextTrimming.None);
                text = Resources.GetString(Resources.StringResources.ReturnToMenu);
                row += step;
                dc.DrawText(ref text,
                            Resources.GetFont(Resources.FontResources.NinaBFont),
                            Color.White, 10, row, _width - 20, step, TextAlignment.Center,
                            TextTrimming.None);
            }

            // Start the animation timer.  The animation timer is called every time
            // the menu is rendered.  The animation timer will handle decrementing
            // the _animationStep member and stopping the timer when _animationStep
            // reaches 0.
            StartAnimationTimer();
        }