Example #1
0
        /// <summary>
        /// The executable entry point.
        /// </summary>
        public static void Main()
        {
            MySimpleWPFApplication myApplication = new MySimpleWPFApplication();

            mainWindow = new MainMenuWindow(myApplication);

            // Create the object that configures the GPIO pins to buttons.
            GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null);

            // Load the fonts.
            NinaBFont = Resources.GetFont(Resources.FontResources.NinaBFont);
            SmallFont = Resources.GetFont(Resources.FontResources.SmallFont);

            // Start the application.
            myApplication.Run(mainWindow);
        }
        /// <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();
        }
        /// <summary>
        /// Override the OnRender and draw using the DrawingContext that is passed
        /// in.
        /// </summary>
        /// <param name="dc"></param>
        public override void OnRender(DrawingContext dc)
        {
            // Paint the background.
            dc.DrawRectangle(
                new SolidColorBrush(ColorUtility.ColorFromRGB(128, 0, 255)),
                new Pen(ColorUtility.ColorFromRGB(128, 0, 255)),
                0, 0, Width, Height);

            // Draw some circles.
            for (int i = 0; i < 3; i++)
            {
                dc.DrawEllipse(
                    new SolidColorBrush(ColorUtility.ColorFromRGB((byte)(64 * i),
                                                                  128, 128)),
                    new Pen(ColorUtility.ColorFromRGB(255, (byte)(64 * i), 255)),
                    Width / 5, Height / 5, i * (Width / 10 - (i * 2)),
                    i * (Height / 10 - (i * 2)));
            }

            // Draw some lines.
            for (int i = 0; i < 20; i++)
            {
                dc.DrawLine(new Pen(ColorUtility.ColorFromRGB((byte)(16 * i),
                                                              (byte)(16 * (20 - i)), (byte)(16 * (2 * i)))),
#if MF_FRAMEWORK_VERSION_V3_0
                            Microsoft.SPOT.Math.Random(Width / 2) + Width / 3,
                            Microsoft.SPOT.Math.Random(Height / 3) + Height / 3,
                            Microsoft.SPOT.Math.Random(Width / 4) + Width / 2,
                            Microsoft.SPOT.Math.Random(Height / 4) + Height / 2);
            }
#else
                            _random.Next(Width / 2) + Width / 3,
                            _random.Next(Height / 3) + Height / 3,
                            _random.Next(Width / 4) + Width / 2,
                            _random.Next(Height / 4) + Height / 2);
#endif

            // Draw a rectangle.
            dc.DrawRectangle(new SolidColorBrush(ColorUtility.ColorFromRGB(
                                                     255, 0, 0)),
                             new Pen(ColorUtility.ColorFromRGB(0, 0, 255)), Width - 40, 0, 30,
                             100);

            // Draw a polyline.
            int[] points = { 10, 230, 30, 210, 0, 180, 30, 130, 50, 130, 80, 180,
                             50, 210, 70, 230 };
            if (Width > Height)
            {
                for (int i = 1; i < points.Length; i += 2)
                {
                    points[i] -= 20;
                }
            }
            dc.DrawPolygon(new SolidColorBrush(ColorUtility.ColorFromRGB(
                                                   32, 0, 128)),
                           new Pen(ColorUtility.ColorFromRGB(0, 0, 0)), points);

            // Draw some text.
            dc.DrawText(Resources.GetString(
                            Resources.StringResources.DrawTextSample),
                        Resources.GetFont(Resources.FontResources.NinaBFont),
                        ColorUtility.ColorFromRGB(255, 255, 255),
#if MF_FRAMEWORK_VERSION_V3_0
                        Microsoft.SPOT.Math.Random(Width / 4), Height - 20);
#else
                        _random.Next(Width / 4), Height - 20);
#endif
        }