Ejemplo n.º 1
0
        public MyList(int x, int y, int width, int height)
            : base(null, x, y, true)
        {
            Panel     = new MyPanel(0, 0, width, height); base.AddChild(Panel);
            Scrollbar = new MyScrollbar(Panel);

            SelectionBackground = new MyPanel(0, 0, width, 1).WithOptionalParameters(true, true, false);
            base.AddChild(SelectionBackground);
        }
Ejemplo n.º 2
0
        /**
         * The initializationMonitoringFunction is run once per frame by the Cycle method of the POST page.
         * When it returns TRUE, the application switches to the first page that comes after the POST page.
         * If There is no other page than the POST page, then nothing will happen.
         */
        public MyOnScreenApplication WithDefaultPostPage(Func <MyOnScreenApplication, bool> initializationMonitoringFunction)
        {
            // Make sure the POST page is the first one added
            if (Pages.Count() > 0)
            {
                throw new InvalidOperationException("The POST page must be the first page ever added to the application");
            }

            // Enforce the order of builder operations to avoid null pointer exceptions
            if (Canvas == null)
            {
                throw new InvalidOperationException("Please call WithCanvas() before calling WithDefaultPostPage()");
            }

            // Make sure the initialization function is set
            if (initializationMonitoringFunction == null)
            {
                throw new ArgumentException("The initialization monitoring function must be a lambda taking in a MyOnScreenObject and returning a bool");
            }

            // Create the POST page and give it the functionality of switching to the next page once
            // the initialization monitoring function returns true
            MyPage POSTPage = (MyPage) new MyPage()
                              .WithInvertedColors()
                              .WithClientPreDrawMethod((MyCanvas TargetCanvas, int iterationIndex) => {
                TargetCanvas.Clear();
            })
                              .WithClientCycleMethod((MyOnScreenObject obj, int iterationIndex) => {
                if (initializationMonitoringFunction(this))
                {
                    SwitchToPage(1);     // will do nothing if the page does not exist
                }
            });

            // Add the POST page to the application
            this.AddPage(POSTPage);

            // Add another filled panel to the POST page, to serve as background for the INITIALIZING text
            MyPanel TextBackgroundPanel = new MyPanel(0, 0, 2, 2).WithOptionalParameters(true, true, false);

            POSTPage.AddChild(TextBackgroundPanel);

            // Add the INIIALIZING text label to the POST page
            MyTextLabel TextLabel = new MyTextLabel("INITIALIZING", 1, 1).WithOptionalParameters(true, true, true);

            POSTPage.AddChild(TextLabel);

            // Compute the location and dimensions of the text and that of its back panel based on
            // the resolution of the Canvas
            int textLabelWidth  = TextLabel.GetWidth();
            int textLabelHeight = TextLabel.GetHeight();

            // Update the label coordinates
            TextLabel.x = (Canvas.GetResX() - textLabelWidth) / 2;
            TextLabel.y = (Canvas.GetResY() - textLabelHeight) / 2 - 3;

            // Update the panel coordinates (the drawing framework handles overflows)
            TextBackgroundPanel.x = TextLabel.x - 3;
            TextBackgroundPanel.y = TextLabel.y - 2;
            TextBackgroundPanel.SetWidth(textLabelWidth + 6);
            TextBackgroundPanel.SetHeight(textLabelHeight + 3);

            // Add the moving square (a panel with some simple animation logic)
            POSTPage.AddChild(
                new MyPanel(TextBackgroundPanel.x, TextBackgroundPanel.y + TextBackgroundPanel.GetHeight() + 2, 7, 4)
                .WithOptionalParameters(true, true, false)
                .WithClientCycleMethod((MyOnScreenObject obj, int iterationIndex) => {
                obj.x++;
                if (obj.x > TextBackgroundPanel.x + TextBackgroundPanel.GetWidth() - 7)
                {
                    obj.x = TextBackgroundPanel.x;
                }
            })
                );

            return(this);
        }