Beispiel #1
0
        public override bool MousePressed(int button, int x, int y)
        {
            bool childclicked = base.MousePressed(button, x, y);
            int locx, locy;

            // Loop through all children
            foreach (Panel p in children)
            {
                // x, y local to the child panel
                locx = x - p.X;
                locy = y - p.Y;

                // Check if it's in bounds of the child panel
                if (locx > 0 && locy > 0 && locx < p.Width && locy < p.Height)
                {
                    // Change selected panel
                    if (p == this.selected)
                    {
                        this.selected = null;
                    }
                    else
                    {
                        this.selected = p;
                    }

                    // Call event
                    OnChange(this, new EventArgs());
                    return true;
                }
            }

            return childclicked;
        }
Beispiel #2
0
        public override void Initialize()
        {
            // Background
            canvas = new Panel();
            canvas.Color = Color.RoyalBlue;
            canvas.Width = Game1.instance.GraphicsDevice.Viewport.Width;
            canvas.Height = Game1.instance.GraphicsDevice.Viewport.Height;

            // Title text
            title = new Label();
            title.Font = Game1.instance.titlefont;
            title.Text = "Conway's Game of Life";
            title.SizeToContents();
            title.Y = 40;
            canvas.Add(title);
            title.CenterX();

            // Menu area
            menubox = new Panel();
            menubox.Color = Color.CornflowerBlue;
            menubox.Width = 200;
            menubox.Height = 190;
            canvas.Add(menubox);
            menubox.Center();

            // Play button
            TextButton playButton = new TextButton();
            playButton.Font = Game1.instance.titlefont;
            playButton.Color = Color.RoyalBlue;
            playButton.Text = "Play";
            playButton.Width = 180;
            playButton.Height = 80;
            playButton.X = 10;
            playButton.Y = 10;

            // Exit button
            TextButton exitButton = new TextButton();
            exitButton.Font = Game1.instance.titlefont;
            exitButton.Color = Color.RoyalBlue;
            exitButton.Text = "Exit";
            exitButton.Width = 180;
            exitButton.Height = 80;
            exitButton.X = 10;
            exitButton.Y = 100;

            // Add buttons to menu box
            menubox.Add(playButton);
            menubox.Add(exitButton);

            // Button events
            playButton.OnClick += delegate { Play(); };
            exitButton.OnClick += delegate { Game1.instance.Exit(); };
        }
Beispiel #3
0
 // Add a child element
 public virtual void Add(Panel p)
 {
     // Add a new child
     this.children.Add(p);
     p.parent = this;
 }