Esempio n. 1
0
        internal void ExitApplication()
        {
            GridBox gridBox = GetGridBox();

            if (gridBox.GridModified)
            {
                // Grid was modified. Save changes?
                DialogResult saveChanges = MessageBox.Show("Save changes?", "Save Changes", MessageBoxButtons.YesNoCancel);
                if (saveChanges == DialogResult.Yes)
                {
                    gridBox.SaveMap(CurrentWorkingFile);
                }
                else if (saveChanges == DialogResult.Cancel)
                {
                    // Do not quit.
                    return;
                }
            }
            // Actually close the form.
            Close();
        }
Esempio n. 2
0
        private void PopulateMenubar()
        {
            // Populates the main menu bar.
            GridBox gridBox = GetGridBox();
            // Top menus
            ToolStripMenuItem fileMenu = new ToolStripMenuItem("File");
            ToolStripMenuItem viewMenu = new ToolStripMenuItem("View");
            ToolStripMenuItem helpMenu = new ToolStripMenuItem("Help");
            // Sub menus.
            // File menu first.
            var loadMap = new ToolStripMenuItem("&Load", null, (sender, e) => { gridBox.LoadMap(); });                   // Load map
            var saveMap = new ToolStripMenuItem("&Save", null, (sender, e) => { gridBox.SaveMap(CurrentWorkingFile); }); // Save map
            // We call SaveMap with null to indicate that we want to select a new file to save into.
            var saveMapAs    = new ToolStripMenuItem("&Save as", null, (sender, e) => { gridBox.SaveMap(null); });       // Save map as
            var exportBitmap = new ToolStripMenuItem("&Export bitmap", null, (sender, e) => { gridBox.ExportBitmap(); });
            var exitApp      = new ToolStripMenuItem("&Quit", null, (sender, e) => { ExitApplication(); });              // Exit app

            ToolStripMenuItem[] items = new ToolStripMenuItem[] { loadMap, saveMap, saveMapAs, exportBitmap, exitApp };
            fileMenu.DropDownItems.AddRange(items);
            MainMenuStrip.Items.Add(fileMenu);

            // Now the View menu
            // Square sizes
            ToolStripMenuItem[] squareSizes = new ToolStripMenuItem[] {
                new ToolStripMenuItem("5px", null, (sender, e) => {
                    gridBox.SquareSideLength = 5;
                    gridBox.ResizeGridBox();
                }),
                new ToolStripMenuItem("10px", null, (sender, e) => {
                    gridBox.SquareSideLength = 10;
                    gridBox.ResizeGridBox();
                }),
                new ToolStripMenuItem("20px", null, (sender, e) => {
                    gridBox.SquareSideLength = 20;
                    gridBox.ResizeGridBox();
                }),
                new ToolStripMenuItem("25px", null, (sender, e) => {
                    gridBox.SquareSideLength = 25;
                    gridBox.ResizeGridBox();
                }),
            };
            var squareSizeItem = new ToolStripMenuItem("Square Size");

            squareSizeItem.DropDownItems.AddRange(squareSizes);
            viewMenu.DropDownItems.Add(squareSizeItem);

            // Background clearing functionality
            viewMenu.DropDownItems.Add(
                new ToolStripMenuItem("Clear grid", null, (sender, e) => {
                // Sets all the squares' background colour to the default colour.
                gridBox.SetBackgroundColor(gridBox.DefaultBackgroundColor);
            })
                );

            // Set background colour, which does NOT affect the already painted squares.
            viewMenu.DropDownItems.Add(
                new ToolStripMenuItem("Set background colour", null, (sender, e) => {
                if (colorDialog.ShowDialog() == DialogResult.OK)
                {
                    // A "false" boolean parameter indicates that we don't want to set it for all squares,
                    // only for the non painted ones.
                    gridBox.SetBackgroundColor(colorDialog.Color, false);
                }
            })
                );

            // ColorDialog for custom colours
            viewMenu.DropDownItems.Add(
                // FIXME: "Select color to draw" is a f*****g HORRIBLE way to describe this item's functionality.
                new ToolStripMenuItem("Select color to draw", null, (sender, e) => {
                if (colorDialog.ShowDialog() == DialogResult.OK)
                {
                    gridBox.SelectedColor = colorDialog.Color;
                    this.Controls.Find("BigBox", true).FirstOrDefault().BackColor = colorDialog.Color;
                }
            })
                );
            MainMenuStrip.Items.Add(viewMenu);
            MainMenuStrip.Items.Add(helpMenu); // TODO: Make documentation and display it via the help menu
        }