Browse Source

Added Menus for the GuiEditors

This adds the menus needed for the GuiEditor. Most of the more important items don't work yet and the lesser items are inconsistent in how they work. I'll be addressing this in the future. The menu items also need to enable/disable based on the events of the editor. But at the very least, this code adds the menu. Baby steps.
Peter Robinson 2 years ago
parent
commit
3ebbe8add2

+ 167 - 0
editor/EditorCore/EditorCore.cs

@@ -91,6 +91,173 @@ function EditorCore::initGui(%this)
 				Command = "quit();";
 			};
 		};
+		new GuiMenuItemCtrl() {
+			Text = "File";
+
+			new GuiMenuItemCtrl() {
+				Text = "New Gui...";
+				Command = "GuiEditor.NewGui();";
+				Accelerator = "Ctrl N";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Open Gui...";
+				Command = "GuiEditor.OpenGui();";
+				Accelerator = "Ctrl O";
+			};
+			new GuiMenuItemCtrl() { Text = "-"; };
+			new GuiMenuItemCtrl() {
+				Text = "Save Gui...";
+				Command = "GuiEditor.SaveGui();";
+				Accelerator = "Ctrl S";
+			};
+		};
+		new GuiMenuItemCtrl() {
+			Text = "Edit";
+
+			new GuiMenuItemCtrl() {
+				Text = "Undo";
+				Command = "GuiEditor.Undo();";
+				Accelerator = "Ctrl Z";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Redo";
+				Command = "GuiEditor.Redo();";
+				Accelerator = "Ctrl-Shift Z";
+			};
+			new GuiMenuItemCtrl() { Text = "-"; };
+			new GuiMenuItemCtrl() {
+				Text = "Cut";
+				Command = "GuiEditor.Cut();";
+				Accelerator = "Ctrl X";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Copy";
+				Command = "GuiEditor.Copy();";
+				Accelerator = "Ctrl C";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Paste";
+				Command = "GuiEditor.Paste();";
+				Accelerator = "Ctrl V";
+			};
+		};
+		new GuiMenuItemCtrl() {
+			Text = "Layout";
+
+			new GuiMenuItemCtrl() {
+				Text = "Nudge Up";
+				Command = "GuiEditor.brain.moveSelection(0,-1);";
+				Accelerator = "Up";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Nudge Down";
+				Command = "GuiEditor.brain.moveSelection(0,1);";
+				Accelerator = "Down";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Nudge Right";
+				Command = "GuiEditor.brain.moveSelection(1,0);";
+				Accelerator = "Right";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Nudge Left";
+				Command = "GuiEditor.brain.moveSelection(-1,0);";
+				Accelerator = "Left";
+			};
+			new GuiMenuItemCtrl() { Text = "-"; };
+			new GuiMenuItemCtrl() {
+				Text = "Expand Height";
+				Command = "GuiEditor.changeExtent(0, 1)";
+				Accelerator = "Ctrl Up";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Shrink Height";
+				Command = "GuiEditor.changeExtent(0,-1);";
+				Accelerator = "Ctrl Down";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Expand Width";
+				Command = "GuiEditor.changeExtent(1,0);";
+				Accelerator = "Ctrl Right";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Shrink Width";
+				Command = "GuiEditor.changeExtent(-1,0);";
+				Accelerator = "Ctrl Left";
+			};
+			new GuiMenuItemCtrl() { Text = "-"; };
+			new GuiMenuItemCtrl() {
+				Text = "Align Left";
+				Command = "GuiEditor.brain.Justify(0);";
+				Accelerator = "Ctrl L";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Align Right";
+				Command = "GuiEditor.brain.Justify(2);";
+				Accelerator = "Ctrl R";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Align Top";
+				Command = "GuiEditor.brain.Justify(3);";
+				Accelerator = "Ctrl T";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Align Bottom";
+				Command = "GuiEditor.brain.Justify(4);";
+				Accelerator = "Ctrl B";
+			};
+			new GuiMenuItemCtrl() { Text = "-"; };
+			new GuiMenuItemCtrl() {
+				Text = "Center Horizontally";
+				Command = "GuiEditor.brain.Justify(1);";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Space Vertically";
+				Command = "GuiEditor.brain.Justify(5);";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Space Horizontally";
+				Command = "GuiEditor.brain.Justify(6);";
+			};
+			new GuiMenuItemCtrl() { Text = "-"; };
+			new GuiMenuItemCtrl() {
+				Text = "Bring to Front";
+				Command = "GuiEditor.brain.BringToFront();";
+				Accelerator = "Ctrl-Shift Up";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Push to Back";
+				Command = "GuiEditor.brain.PushToBack();";
+				Accelerator = "Ctrl-Shift Down";
+			};
+			new GuiMenuItemCtrl() { Text = "-"; };
+			new GuiMenuItemCtrl() {
+				Text = "Set Grid Size...";
+				Command = "GuiEditor.SetGridSize();";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Snap to Grid";
+				Toggle = "1";
+				IsOn = "1";
+				Command = "GuiEditor.SnapToGrid(true);";
+				AltCommand = "GuiEditor.SnapToGrid(false);";
+				Accelerator = "Ctrl G";
+			};
+		};
+		new GuiMenuItemCtrl() {
+			Text = "Select";
+
+			new GuiMenuItemCtrl() {
+				Text = "Select All";
+				Command = "GuiEditor.brain.SelectAll;";
+				Accelerator = "Ctrl A";
+			};
+			new GuiMenuItemCtrl() {
+				Text = "Deselect";
+				Command = "GuiEditor.brain.clearSelection();";
+				Accelerator = "Esc";
+			};
+		};
 		new GuiMenuItemCtrl() {
 			Text = "Theme";
 

+ 77 - 1
editor/GuiEditor/GuiEditor.cs

@@ -164,4 +164,80 @@ function GuiEditor::onNewGui(%this)
     %this.brain.setRoot(%this.blankGui);
     %this.brain.root = %this.blankGui;
     %this.explorerWindow.open(%this.blankGui);
-}
+}
+
+//MENU FUNCTIONS---------------------------------------------------------------
+function GuiEditor::NewGui(%this)
+{
+
+}
+
+function GuiEditor::OpenGui(%this)
+{
+    
+}
+
+function GuiEditor::SaveGui(%this)
+{
+    
+}
+
+function GuiEditor::Undo(%this)
+{
+    %undoManager = %this.brain.getUndoManager();
+    %undoManager.undo();
+}
+
+function GuiEditor::Redo(%this)
+{
+    %undoManager = %this.brain.getUndoManager();
+    %undoManager.redo();
+
+    %count = %undoManager.getRedoCount();
+
+}
+
+function GuiEditor::Cut(%this)
+{
+    
+}
+
+function GuiEditor::Copy(%this)
+{
+    
+}
+
+function GuiEditor::Paste(%this)
+{
+    
+}
+
+function GuiEditor::changeExtent(%this, %x, %y)
+{
+    %set = %this.brain.getSelected();
+    if(%set.getCount() == 1)
+    {
+        %obj = %set.getObject(0);
+        %ext = %obj.getExtent();
+        %obj.setExtent(getWord(%ext, 0) + %x, getWord(%ext, 1) + %y);
+    }
+}
+
+function GuiEditor::SetGridSize(%this)
+{
+    
+}
+
+function GuiEditor::SnapToGrid(%this, %gridOn)
+{
+    if(%gridOn)
+    {
+        %this.brain.setSnapToGrid(10);
+    }
+    else 
+    {
+        %this.brain.setSnapToGrid(0);
+    }
+}
+
+//METHODS-----------------------------------------------------------------

+ 16 - 1
engine/source/gui/editor/guiEditCtrl.cc

@@ -173,7 +173,14 @@ ConsoleMethod( GuiEditCtrl, moveSelection, void, 4, 4, "(int deltax, int deltay)
               "@param deltax,deltay The change in coordinates.\n"
               "@return No return value.")
 {
-   object->moveAndSnapSelection(Point2I(dAtoi(argv[2]), dAtoi(argv[3])));
+	if(object->hasSnapToGrid())
+	{
+		object->moveAndSnapSelection(Point2I(dAtoi(argv[2]), dAtoi(argv[3])));
+	}
+	else
+	{
+		object->moveSelection(Point2I(dAtoi(argv[2]), dAtoi(argv[3])));
+	}
 }
 
 ConsoleMethod( GuiEditCtrl, saveSelection, void, 3, 3, "(string fileName) Saves the current selection to given filename\n"
@@ -1145,6 +1152,11 @@ void GuiEditCtrl::moveAndSnapSelection(const Point2I &delta)
 
 void GuiEditCtrl::moveSelection(const Point2I &delta)
 {
+	// move / nudge gets a special callback so that multiple small moves can be
+   // coalesced into one large undo action.
+   // undo
+   Con::executef(this, 2, "onPreSelectionNudged", Con::getIntArg(getSelectedSet().getId()));
+
    Vector<GuiControl *>::iterator i;
    for(i = mSelectedControls.begin(); i != mSelectedControls.end(); i++)
    {
@@ -1155,6 +1167,9 @@ void GuiEditCtrl::moveSelection(const Point2I &delta)
       (*i)->resize((*i)->mBounds.point + delta, (*i)->mBounds.extent);
    }
 
+   // undo
+   Con::executef(this, 2, "onPostSelectionNudged", Con::getIntArg(getSelectedSet().getId()));
+
    // allow script to update the inspector
    if (mSelectedControls.size() == 1)
       Con::executef(this, 2, "onSelectionMoved", Con::getIntArg(mSelectedControls[0]->getId()));

+ 1 - 0
engine/source/gui/editor/guiEditCtrl.h

@@ -134,6 +134,7 @@ class GuiEditCtrl : public GuiControl
    void bringToFront();
    void pushToBack();
    void setSnapToGrid(U32 gridsize);
+   bool hasSnapToGrid() { return mGridSnap.x && mGridSnap.y; }
    void moveSelectionToCtrl(GuiControl*);
 };