Esempio n. 1
0
        static void Main(string[] args)
        {
            Mathematics math = new Mathematics();

            Console.WriteLine(math.Abs(-5));
            Console.WriteLine(math.Abs(-10.052));
            Console.WriteLine(math.Abs(20.01m));
        }
Esempio n. 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 = Resource.GetBitmap(Resource.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 = Mathematics.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, Resource.GetFont(Resource.FontResources.NinaB), Color.White, 10, row, _width - 20, step, TextAlignment.Center, TextTrimming.None);

                // Draw the basic instructions for the menu.
                text = Resource.GetString(Resource.StringResources.MenuScrolling);
                row += (step * 2);
                dc.DrawText(ref text, Resource.GetFont(Resource.FontResources.NinaB), Color.White, 10, row, _width - 20, step, TextAlignment.Center, TextTrimming.None);
                text = Resource.GetString(Resource.StringResources.MenuSelection);
                row += step;
                dc.DrawText(ref text, Resource.GetFont(Resource.FontResources.NinaB), Color.White, 10, row, _width - 20, step, TextAlignment.Center, TextTrimming.None);
                text = Resource.GetString(Resource.StringResources.ReturnToMenu);
                row += step;
                dc.DrawText(ref text, Resource.GetFont(Resource.FontResources.NinaB), 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();
        }