コード例 #1
0
        } // ViewportArea

        #endregion

        #region Add Main Window Controls

        /// <summary>
        /// Add the editor's main window controls.
        /// </summary>
        public static void AddMainControls()
        {
            #region Canvas

            // The canvas cover the whole window. I will place the static controls there.
            // I don’t place the controls directly to the manager to allow having some functionality
            // provided by the canvas like the automatic placing of menu items, status bar, etc.
            Container canvas = new Container
            {
                Top             = 0,
                Left            = 0,
                Width           = Screen.Width,
                Height          = Screen.Height,
                Anchor          = Anchors.All,
                AutoScroll      = false,
                BackgroundColor = Color.Transparent,
                StayOnBack      = true,
                Passive         = true,
                CanFocus        = false,
            };

            #endregion

            #region Main Menu

            canvas.MainMenu = new MainMenu
            {
                Width    = Screen.Width,
                Anchor   = Anchors.Left | Anchors.Top,
                CanFocus = false
            };

            #region File

            MenuItem menuItemFile = new MenuItem("File", true);
            canvas.MainMenu.Items.Add(menuItemFile);
            menuItemFile.Items.AddRange(new[]
            {
                new MenuItem("New Scene")
                {
                    RightSideText = "Ctrl+N"
                },
                new MenuItem("Open Scene")
                {
                    RightSideText = "Ctrl+O"
                },
                new MenuItem("Save Scene")
                {
                    RightSideText = "Ctrl+S", SeparationLine = true
                },
                new MenuItem("Save Scene as...")
                {
                    RightSideText = "Ctrl+Shift+S"
                },
                new MenuItem("Exit", true)
                {
                    SeparationLine = true
                },
            });
            menuItemFile.Items[0].Click += delegate { StorageManager.ClearScene(); };
            menuItemFile.Items[1].Click += delegate { StorageManager.LoadScene(); };
            menuItemFile.Items[2].Click += delegate { StorageManager.SaveScene(); };

            #endregion

            #region Edit

            MenuItem menuItemEdit = new MenuItem("Edit", true);
            canvas.MainMenu.Items.Add(menuItemEdit);
            menuItemEdit.Items.AddRange(new[]
            {
                new MenuItem("Undo")
                {
                    RightSideText = "Ctrl+Z"
                },
                new MenuItem("Redo")
                {
                    RightSideText = "Ctrl+Y"
                },
                new MenuItem("Frame Selected (All 3D Views)")
                {
                    RightSideText = "Shift+F", SeparationLine = true
                },
                new MenuItem("Frame All (All 3D Views)")
                {
                    RightSideText = "Shift+A"
                },
                new MenuItem("Reset (All 3D Views)")
                {
                    RightSideText = "Shift+R"
                },
            });
            menuItemEdit.Items[0].Click += delegate { ActionManager.Undo(); };
            menuItemEdit.Items[1].Click += delegate { ActionManager.Redo(); };
            menuItemEdit.Items[2].Click += delegate
            {
                foreach (var editorViewport in EditorManager.EditorViewports)
                {
                    editorViewport.FrameObjects(EditorManager.SelectedObjects);
                }
            };
            menuItemEdit.Items[3].Click += delegate
            {
                foreach (var editorViewport in EditorManager.EditorViewports)
                {
                    editorViewport.FrameObjects(GameObject.GameObjects);
                }
            };
            menuItemEdit.Items[4].Click += delegate
            {
                foreach (var editorViewport in EditorManager.EditorViewports)
                {
                    editorViewport.Reset();
                }
            };

            #endregion

            #region Game Object

            MenuItem menuItemGameObject = new MenuItem("Game Object", true);
            canvas.MainMenu.Items.Add(menuItemGameObject);
            menuItemGameObject.Items.AddRange(new[]
            {
                new MenuItem("Create Empty 3D Game Object")
                {
                    RightSideText = "Ctrl+Shift+N"
                },
                new MenuItem("Create Empty 2D Game Object")
                {
                    RightSideText = "Ctrl+Shift+M"
                },
                new MenuItem("Create Other"),
            });
            menuItemGameObject.Items[2].Items.AddRange(new[]
            {
                new MenuItem("Camera"),
                new MenuItem("Particle System"),
                new MenuItem("HUD Texture"),
                new MenuItem("HUD Text"),
                new MenuItem("Directional Light")
                {
                    SeparationLine = true
                },
                new MenuItem("Point Light"),
                new MenuItem("Spot Light"),
                new MenuItem("Sphere")
                {
                    SeparationLine = true
                },
                new MenuItem("Box"),
                new MenuItem("Plane"),
                new MenuItem("Cylinder"),
                new MenuItem("Cone"),
                new MenuItem("Empty Model"),
            });
            // Create Empty 3D Game Object
            menuItemGameObject.Items[0].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Camera
            menuItemGameObject.Items[2].Items[0].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <Camera>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Particle System
            menuItemGameObject.Items[2].Items[1].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <ParticleEmitter>();
                gameObject3D.AddComponent <ParticleRenderer>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // HUD Texture
            menuItemGameObject.Items[2].Items[2].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <HudTexture>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // HUD Text
            menuItemGameObject.Items[2].Items[3].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <HudText>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Directional Light
            menuItemGameObject.Items[2].Items[4].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <DirectionalLight>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Point Light
            menuItemGameObject.Items[2].Items[5].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <PointLight>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Spot Light
            menuItemGameObject.Items[2].Items[6].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D();
                gameObject3D.AddComponent <SpotLight>();
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Sphere
            menuItemGameObject.Items[2].Items[7].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Sphere(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Box
            menuItemGameObject.Items[2].Items[8].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Box(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Plane
            menuItemGameObject.Items[2].Items[9].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Plane(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Cylinder
            menuItemGameObject.Items[2].Items[10].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Cylinder(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Cone
            menuItemGameObject.Items[2].Items[11].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(new Cone(), Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };
            // Empty Model
            menuItemGameObject.Items[2].Items[12].Click += delegate
            {
                GameObject3D gameObject3D = new GameObject3D(null, Material.DefaultMaterial);
                EditorManager.RemoveAllObjectFromSelection();
                EditorManager.AddObjectToSelection(gameObject3D);
            };

            #endregion

            #region Component

            MenuItem menuItemComponent = new MenuItem("Component", true);
            canvas.MainMenu.Items.Add(menuItemComponent);
            menuItemComponent.Items.AddRange(new[]
            {
                new MenuItem("Model"),
                new MenuItem("Particles"),
                new MenuItem("Physics"),
                new MenuItem("Audio"),
                new MenuItem("Rendering"),
            });

            #endregion

            #region Window

            MenuItem menuItemWindow = new MenuItem("Window", true);
            canvas.MainMenu.Items.Add(menuItemWindow);
            menuItemWindow.Items.AddRange(new[]
            {
                new MenuItem("Layouts"),
                new MenuItem("Hierarchy")
                {
                    RightSideText = "Ctrl+6", SeparationLine = true,
                },
                new MenuItem("Heads Up Display Editor")
                {
                    RightSideText = "Ctrl+7"
                },
            });
            menuItemWindow.Items[0].Items.AddRange(new []
            {
                new MenuItem("4 Split"),
                new MenuItem("3 Split"),
                new MenuItem("Wide"),
                new MenuItem("Toggle")
                {
                    RightSideText = "F12", SeparationLine = true,
                },
            });
            menuItemWindow.Items[0].Items[0].Click += delegate { EditorManager.Layout = EditorManager.LayoutOptions.FourSplit; };
            menuItemWindow.Items[0].Items[1].Click += delegate { EditorManager.Layout = EditorManager.LayoutOptions.ThreeSplit; };
            menuItemWindow.Items[0].Items[2].Click += delegate { EditorManager.Layout = EditorManager.LayoutOptions.Wide; };
            menuItemWindow.Items[0].Items[3].Click += delegate { EditorManager.ToggleLayout(); };

            #endregion

            #region Help

            MenuItem menuItemHelp = new MenuItem("Help", true);
            canvas.MainMenu.Items.Add(menuItemHelp);
            menuItemHelp.Items.AddRange(new[]
            {
                new MenuItem("About"),
                new MenuItem("Documentation")
                {
                    RightSideText = "F1", SeparationLine = true,
                },
            });
            menuItemHelp.Items[1].Click += delegate { System.Diagnostics.Process.Start("http://xnafinalengine.codeplex.com/documentation"); };

            #endregion

            #endregion

            #region Top Panel

            ToolBarPanel topPanel = new ToolBarPanel();
            canvas.ToolBarPanel = topPanel;
            ToolBar toolBarTopPanel = new ToolBar
            {
                Parent  = topPanel,
                Movable = true,
                FullRow = true
            };

            #region Button Space

            Button buttonSpace = new Button
            {
                Text     = "Global",
                Left     = 10,
                Top      = 10,
                Height   = 15,
                Parent   = toolBarTopPanel,
                CanFocus = false,
            };
            buttonSpace.Click += delegate
            {
                if (Gizmo.Space == Gizmo.SpaceMode.Local)
                {
                    Gizmo.Space      = Gizmo.SpaceMode.Global;
                    buttonSpace.Text = "Global";
                }
                else
                {
                    Gizmo.Space      = Gizmo.SpaceMode.Local;
                    buttonSpace.Text = "Local";
                }
                buttonSpace.Focused = false;
            };

            #endregion

            #region Buttons Play, Pause and Stop

            Texture playTexture        = new Texture("Editor\\PlayIconNotPressed");
            Texture playPressedTexture = new Texture("Editor\\PlayIcon");
            Button  buttonPlay         = new Button
            {
                Left   = Screen.Width / 2 - 50,
                Top    = 2,
                Height = 32,
                Width  = 32,
                Glyph  = new Glyph(playTexture)
                {
                    SizeMode = SizeMode.Normal
                },
                Parent   = toolBarTopPanel,
                CanFocus = false,
            };
            buttonPlay.Click += delegate { buttonPlay.Glyph.Texture = buttonPlay.Glyph.Texture == playTexture ? playPressedTexture : playTexture; };
            Texture pauseTexture        = new Texture("Editor\\PauseIconNotPressed");
            Texture pausePressedTexture = new Texture("Editor\\PauseIcon");
            Button  buttonPause         = new Button
            {
                Left   = buttonPlay.Left + 34,
                Top    = 2,
                Height = 32,
                Width  = 32,
                Glyph  = new Glyph(pauseTexture)
                {
                    SizeMode = SizeMode.Normal
                },
                Parent   = toolBarTopPanel,
                CanFocus = false,
            };
            buttonPause.Click += delegate { buttonPause.Glyph.Texture = buttonPause.Glyph.Texture == pauseTexture ? pausePressedTexture : pauseTexture; };
            Texture stopTexture        = new Texture("Editor\\StopIconNotPressed");
            Texture stopPressedTexture = new Texture("Editor\\StopIcon");
            Button  buttonStop         = new Button
            {
                Left   = buttonPlay.Left + 68,
                Top    = 2,
                Height = 32,
                Width  = 32,
                Glyph  = new Glyph(stopTexture)
                {
                    SizeMode = SizeMode.Normal
                },
                Parent   = toolBarTopPanel,
                CanFocus = false,
            };
            buttonStop.Click += delegate { buttonStop.Glyph.Texture = buttonStop.Glyph.Texture == stopTexture ? stopPressedTexture : stopTexture; };

            #endregion

            // Adjust top panel height.
            topPanel.Height        = buttonStop.Top + buttonStop.Height + 2;
            toolBarTopPanel.Height = buttonStop.Top + buttonStop.Height + 2;

            #endregion

            #region Viewport Space

            // The canvas cover the whole window. I will place the static controls there.
            // I don’t place the controls directly to the manager to allow having some functionality
            // provided by the canvas like the automatic placing of menu items, status bar, etc.
            ViewportsSpace = new Container
            {
                Top             = 0,
                Left            = 0,
                Width           = canvas.ClientWidth - 420,
                Height          = canvas.ClientHeight,
                Anchor          = Anchors.All,
                AutoScroll      = false,
                BackgroundColor = Color.Transparent,
                StayOnBack      = true,
                Passive         = false,
                CanFocus        = false,
                Parent          = canvas,
            };

            #endregion

            #region Right Panel

            Panel rightPanel = new Panel
            {
                StayOnBack = true,
                Passive    = true,
                Parent     = canvas,
                Width      = 420,
                Left       = canvas.ClientWidth - 420,
                Height     = canvas.ClientHeight,
                Anchor     = Anchors.Right | Anchors.Top | Anchors.Bottom,
                Color      = new Color(64, 64, 64),
            };

            TabControl rightPanelTabControl = new TabControl
            {
                Parent = rightPanel,
                Left   = 2,
                Top    = 2,
                Width  = rightPanel.ClientWidth - 2,
                Height = rightPanel.ClientHeight - 2,
                Anchor = Anchors.All
            };
            rightPanelTabControl.AddPage();
            rightPanelTabControl.TabPages[0].Text = "Inspector";
            inspector = rightPanelTabControl.TabPages[0];
            rightPanelTabControl.AddPage();
            rightPanelTabControl.TabPages[1].Text = "Layers";
            var label = new Label
            {
                Parent = rightPanelTabControl.TabPages[1],
                Width  = 50,
                Top    = 15,
                Left   = rightPanelTabControl.TabPages[1].ClientWidth - 132,
                Text   = "Active",
                Height = 10,
            };
            label.ToolTip.Text = "Active layers are updated.";
            label = new Label
            {
                Parent = rightPanelTabControl.TabPages[1],
                Width  = 50,
                Top    = 15,
                Left   = rightPanelTabControl.TabPages[1].ClientWidth - 72,
                Text   = "Visible",
                Height = 10,
            };
            label.ToolTip.Text = "Visible layers are rendered.";
            for (int i = 0; i < 30; i++)
            {
                CommonControls.LayerBox(i, rightPanelTabControl.TabPages[1]);
            }

            #endregion
        } // AddMainControls