Просмотр исходного кода

Improved ProjectWindow label look slightly
Fixed a memory corruption issue when deleting objects in ProjectLibrary
Fixed input box so it properly shows caret if the user doesn't select the box with a pointer
Fixed rename input box so it on top of all GUI elements so it properly receives mouse input
Extended managed GUIElement so they can have their focus set programatically

Marko Pintera 10 лет назад
Родитель
Сommit
bc5f01ff6e

+ 25 - 12
BansheeEditor/Source/BsBuiltinEditorResources.cpp

@@ -341,18 +341,6 @@ namespace BansheeEngine
 
 
 		skin->setStyle(GUILabel::getGUITypeName(), labelStyle);
 		skin->setStyle(GUILabel::getGUITypeName(), labelStyle);
 
 
-		// Multi-line label
-		GUIElementStyle multiLinelabelStyle;
-		multiLinelabelStyle.font = font;
-		multiLinelabelStyle.fontSize = DefaultFontSize;
-		multiLinelabelStyle.fixedWidth = false;
-		multiLinelabelStyle.fixedHeight = true;
-		multiLinelabelStyle.height = 11;
-		multiLinelabelStyle.minWidth = 10;
-		multiLinelabelStyle.wordWrap = true;
-
-		skin->setStyle("MultiLineLabel", multiLinelabelStyle);
-
 		// Window frame
 		// Window frame
 		GUIElementStyle windowFrameStyle;
 		GUIElementStyle windowFrameStyle;
 		windowFrameStyle.normal.texture = getGUITexture(WindowFrameNormal);
 		windowFrameStyle.normal.texture = getGUITexture(WindowFrameNormal);
@@ -1243,6 +1231,31 @@ namespace BansheeEngine
 
 
 		skin->setStyle("RightAlignedLabel", rightAlignedLabelStyle);
 		skin->setStyle("RightAlignedLabel", rightAlignedLabelStyle);
 
 
+		// Multi-line label
+		GUIElementStyle multiLinelabelStyle;
+		multiLinelabelStyle.font = font;
+		multiLinelabelStyle.fontSize = DefaultFontSize;
+		multiLinelabelStyle.fixedWidth = false;
+		multiLinelabelStyle.fixedHeight = true;
+		multiLinelabelStyle.height = 11;
+		multiLinelabelStyle.minWidth = 10;
+		multiLinelabelStyle.wordWrap = true;
+
+		skin->setStyle("MultiLineLabel", multiLinelabelStyle);
+
+		// Multi-line centered label
+		GUIElementStyle multiLineCenteredLabelStyle;
+		multiLineCenteredLabelStyle.font = font;
+		multiLineCenteredLabelStyle.fontSize = DefaultFontSize;
+		multiLineCenteredLabelStyle.fixedWidth = false;
+		multiLineCenteredLabelStyle.fixedHeight = true;
+		multiLineCenteredLabelStyle.height = 11;
+		multiLineCenteredLabelStyle.minWidth = 10;
+		multiLineCenteredLabelStyle.wordWrap = true;
+		multiLineCenteredLabelStyle.textHorzAlign = THA_Center;
+
+		skin->setStyle("MultiLineLabelCentered", multiLineCenteredLabelStyle);
+
 		// Selection area
 		// Selection area
 		GUIElementStyle selectionAreaStyle;
 		GUIElementStyle selectionAreaStyle;
 		selectionAreaStyle.normal.texture = getGUITexture(SelectionAreaTex);
 		selectionAreaStyle.normal.texture = getGUITexture(SelectionAreaTex);

+ 2 - 0
BansheeEditor/Source/BsProjectLibrary.cpp

@@ -285,6 +285,8 @@ namespace BansheeEngine
 							else if(child->type == LibraryEntryType::File)
 							else if(child->type == LibraryEntryType::File)
 								deleteResourceInternal(static_cast<ResourceEntry*>(child));
 								deleteResourceInternal(static_cast<ResourceEntry*>(child));
 						}
 						}
+
+						toDelete.clear();
 					}
 					}
 
 
 					for(auto& child : currentDir->mChildren)
 					for(auto& child : currentDir->mChildren)

+ 19 - 2
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -673,6 +673,9 @@ namespace BansheeEngine
 				UINT32 selStart = gGUIManager().getInputSelectionTool()->getSelectionStart();
 				UINT32 selStart = gGUIManager().getInputSelectionTool()->getSelectionStart();
 				clearSelection();
 				clearSelection();
 
 
+				if (!mCaretShown)
+					showCaret();
+
 				if(selStart > 0)
 				if(selStart > 0)
 					gGUIManager().getInputCaretTool()->moveCaretToChar(selStart - 1, CARET_AFTER);
 					gGUIManager().getInputCaretTool()->moveCaretToChar(selStart - 1, CARET_AFTER);
 				else
 				else
@@ -706,6 +709,9 @@ namespace BansheeEngine
 				UINT32 selEnd = gGUIManager().getInputSelectionTool()->getSelectionEnd();
 				UINT32 selEnd = gGUIManager().getInputSelectionTool()->getSelectionEnd();
 				clearSelection();
 				clearSelection();
 
 
+				if (!mCaretShown)
+					showCaret();
+
 				if(selEnd > 0)
 				if(selEnd > 0)
 					gGUIManager().getInputCaretTool()->moveCaretToChar(selEnd - 1, CARET_AFTER);
 					gGUIManager().getInputCaretTool()->moveCaretToChar(selEnd - 1, CARET_AFTER);
 				else
 				else
@@ -734,7 +740,11 @@ namespace BansheeEngine
 
 
 		if(ev.getType() == GUICommandEventType::MoveUp)
 		if(ev.getType() == GUICommandEventType::MoveUp)
 		{
 		{
-			clearSelection();
+			if (mSelectionShown)
+				clearSelection();
+
+			if (!mCaretShown)
+				showCaret();
 
 
 			gGUIManager().getInputCaretTool()->moveCaretUp();
 			gGUIManager().getInputCaretTool()->moveCaretUp();
 
 
@@ -758,7 +768,11 @@ namespace BansheeEngine
 
 
 		if(ev.getType() == GUICommandEventType::MoveDown)
 		if(ev.getType() == GUICommandEventType::MoveDown)
 		{
 		{
-			clearSelection();
+			if (mSelectionShown)
+				clearSelection();
+
+			if (!mCaretShown)
+				showCaret();
 
 
 			gGUIManager().getInputCaretTool()->moveCaretDown();
 			gGUIManager().getInputCaretTool()->moveCaretDown();
 
 
@@ -1001,6 +1015,9 @@ namespace BansheeEngine
 			filterOkay = mFilter(newText);
 			filterOkay = mFilter(newText);
 		}
 		}
 
 
+		if (!mCaretShown)
+			showCaret();
+
 		if(filterOkay)
 		if(filterOkay)
 		{
 		{
 			mText.erase(mText.begin() + selStart, mText.begin() + selEnd);
 			mText.erase(mText.begin() + selStart, mText.begin() + selEnd);

+ 1 - 0
MBansheeEditor/EditorStyles.cs

@@ -11,6 +11,7 @@ namespace BansheeEditor
         public const string Blank = "Blank";
         public const string Blank = "Blank";
         public const string Label = "Label";
         public const string Label = "Label";
         public const string MultiLineLabel = "MultiLineLabel";
         public const string MultiLineLabel = "MultiLineLabel";
+        public const string MultiLineLabelCentered = "MultiLineLabelCentered";
         public const string Button = "Button";
         public const string Button = "Button";
         public const string Toggle = "Toggle";
         public const string Toggle = "Toggle";
         public const string InputBox = "InputBox";
         public const string InputBox = "InputBox";

+ 12 - 11
MBansheeEditor/ProjectWindow.cs

@@ -21,6 +21,7 @@ namespace BansheeEditor
                 GUIPanel contentPanel = parentPanel.AddPanel(1);
                 GUIPanel contentPanel = parentPanel.AddPanel(1);
                 overlay = parentPanel.AddPanel(0);
                 overlay = parentPanel.AddPanel(0);
                 underlay = parentPanel.AddPanel(2);
                 underlay = parentPanel.AddPanel(2);
+                inputOverlay = parentPanel.AddPanel(-1);
 
 
                 main = contentPanel.AddLayoutY();
                 main = contentPanel.AddLayoutY();
 
 
@@ -71,6 +72,7 @@ namespace BansheeEditor
             public GUILayout main;
             public GUILayout main;
             public GUIPanel overlay;
             public GUIPanel overlay;
             public GUIPanel underlay;
             public GUIPanel underlay;
+            public GUIPanel inputOverlay;
 
 
             public ProjectWindow window;
             public ProjectWindow window;
             public int tileSize;
             public int tileSize;
@@ -117,7 +119,7 @@ namespace BansheeEditor
 
 
                 if (info.gridLayout)
                 if (info.gridLayout)
                 {
                 {
-                    label = new GUILabel(entry.Name, EditorStyles.MultiLineLabel,
+                    label = new GUILabel(entry.Name, EditorStyles.MultiLineLabelCentered,
                         GUIOption.FixedWidth(info.labelWidth), GUIOption.FlexibleHeight(0, MAX_LABEL_HEIGHT));
                         GUIOption.FixedWidth(info.labelWidth), GUIOption.FlexibleHeight(0, MAX_LABEL_HEIGHT));
                 }
                 }
                 else
                 else
@@ -140,10 +142,10 @@ namespace BansheeEditor
                 bounds = icon.Bounds;
                 bounds = icon.Bounds;
                 Rect2I labelBounds = label.Bounds;
                 Rect2I labelBounds = label.Bounds;
 
 
-                bounds.x = MathEx.Min(bounds.x, labelBounds.x);
+                bounds.x = MathEx.Min(bounds.x, labelBounds.x - SELECTION_EXTRA_WIDTH);
                 bounds.y = MathEx.Min(bounds.y, labelBounds.y) - 5; // 5 - Just padding for better look
                 bounds.y = MathEx.Min(bounds.y, labelBounds.y) - 5; // 5 - Just padding for better look
                 bounds.width = MathEx.Max(bounds.x + bounds.width,
                 bounds.width = MathEx.Max(bounds.x + bounds.width,
-                    labelBounds.x + labelBounds.width) - bounds.x;
+                    labelBounds.x + labelBounds.width) - bounds.x + SELECTION_EXTRA_WIDTH;
                 bounds.height = MathEx.Max(bounds.y + bounds.height,
                 bounds.height = MathEx.Max(bounds.y + bounds.height,
                     labelBounds.y + labelBounds.height) - bounds.y;
                     labelBounds.y + labelBounds.height) - bounds.y;
 
 
@@ -227,10 +229,11 @@ namespace BansheeEditor
 
 
                 renameTextBox = new GUITextBox(false);
                 renameTextBox = new GUITextBox(false);
                 renameTextBox.Bounds = label.Bounds;
                 renameTextBox.Bounds = label.Bounds;
-                info.overlay.AddElement(renameTextBox);
+                info.inputOverlay.AddElement(renameTextBox);
 
 
                 string name = Path.GetFileNameWithoutExtension(PathEx.GetTail(path));
                 string name = Path.GetFileNameWithoutExtension(PathEx.GetTail(path));
                 renameTextBox.Text = name;
                 renameTextBox.Text = name;
+                renameTextBox.Focus = true;
 
 
                 label.Visible = false;
                 label.Visible = false;
             }
             }
@@ -318,11 +321,12 @@ namespace BansheeEditor
         private const int GRID_ENTRY_SPACING = 15;
         private const int GRID_ENTRY_SPACING = 15;
         private const int LIST_ENTRY_SPACING = 7;
         private const int LIST_ENTRY_SPACING = 7;
         private const int MAX_LABEL_HEIGHT = 50;
         private const int MAX_LABEL_HEIGHT = 50;
-        private const int MIN_HORZ_SPACING = 5;
+        private const int MIN_HORZ_SPACING = 8;
         private const int DRAG_SCROLL_HEIGHT = 20;
         private const int DRAG_SCROLL_HEIGHT = 20;
         private const int DRAG_SCROLL_AMOUNT_PER_SECOND = 100;
         private const int DRAG_SCROLL_AMOUNT_PER_SECOND = 100;
         private const int FOLDER_BUTTON_WIDTH = 20;
         private const int FOLDER_BUTTON_WIDTH = 20;
         private const int FOLDER_SEPARATOR_WIDTH = 7;
         private const int FOLDER_SEPARATOR_WIDTH = 7;
+        private const int SELECTION_EXTRA_WIDTH = 3;
         private static readonly Color PING_COLOR = Color.BansheeOrange;
         private static readonly Color PING_COLOR = Color.BansheeOrange;
         private static readonly Color SELECTION_COLOR = Color.DarkCyan;
         private static readonly Color SELECTION_COLOR = Color.DarkCyan;
         private static readonly Color HOVER_COLOR = new Color(Color.DarkCyan.r, Color.DarkCyan.g, Color.DarkCyan.b, 0.5f);
         private static readonly Color HOVER_COLOR = new Color(Color.DarkCyan.r, Color.DarkCyan.g, Color.DarkCyan.b, 0.5f);
@@ -699,13 +703,10 @@ namespace BansheeEditor
             }
             }
             else
             else
             {
             {
-                if (!selectionPaths.Contains(path))
-                {
-                    SetSelection(new List<string>() {path});
+                SetSelection(new List<string>() {path});
 
 
-                    selectionAnchorStart = entry.index;
-                    selectionAnchorEnd = entry.index;
-                }
+                selectionAnchorStart = entry.index;
+                selectionAnchorEnd = entry.index;
             }
             }
         }
         }
 
 

+ 8 - 0
MBansheeEngine/GUI/GUIElement.cs

@@ -24,6 +24,11 @@ namespace BansheeEngine
             set { Internal_SetVisible(mCachedPtr, value); }
             set { Internal_SetVisible(mCachedPtr, value); }
         }
         }
 
 
+        public bool Focus
+        {
+            set { Internal_SetFocus(mCachedPtr, value); }
+        }
+
         private void InternalOnFocusChanged(bool focus)
         private void InternalOnFocusChanged(bool focus)
         {
         {
             if (OnFocusChanged != null)
             if (OnFocusChanged != null)
@@ -77,6 +82,9 @@ namespace BansheeEngine
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
         private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
 
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetFocus(IntPtr nativeInstance, bool focus);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetPosition(IntPtr nativeInstance, int x, int y);
         private static extern void Internal_SetPosition(IntPtr nativeInstance, int x, int y);
 
 

+ 1 - 0
SBansheeEngine/Include/BsScriptGUIElement.h

@@ -101,6 +101,7 @@ namespace BansheeEngine
 	private:
 	private:
 		static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
 		static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
 		static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
 		static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
+		static void internal_setFocus(ScriptGUIElementBaseTBase* nativeInstance, bool focus);
 		static Rect2I internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance);
 		static Rect2I internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance);
 		static void internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I bounds);
 		static void internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I bounds);
 		static Rect2I internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance);
 		static Rect2I internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance);

+ 11 - 0
SBansheeEngine/Source/BsScriptGUIElement.cpp

@@ -77,6 +77,7 @@ namespace BansheeEngine
 	{
 	{
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIElement::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIElement::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIElement::internal_setVisible);
 		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIElement::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetFocus", &ScriptGUIElement::internal_setFocus);
 		metaData.scriptClass->addInternalCall("Internal_GetBounds", &ScriptGUIElement::internal_getBounds);
 		metaData.scriptClass->addInternalCall("Internal_GetBounds", &ScriptGUIElement::internal_getBounds);
 		metaData.scriptClass->addInternalCall("Internal_SetBounds", &ScriptGUIElement::internal_setBounds);
 		metaData.scriptClass->addInternalCall("Internal_SetBounds", &ScriptGUIElement::internal_setBounds);
 		metaData.scriptClass->addInternalCall("Internal_GetVisibleBounds", &ScriptGUIElement::internal_getVisibleBounds);
 		metaData.scriptClass->addInternalCall("Internal_GetVisibleBounds", &ScriptGUIElement::internal_getVisibleBounds);
@@ -104,6 +105,16 @@ namespace BansheeEngine
 			nativeInstance->getGUIElement()->disableRecursively();
 			nativeInstance->getGUIElement()->disableRecursively();
 	}
 	}
 
 
+	void ScriptGUIElement::internal_setFocus(ScriptGUIElementBaseTBase* nativeInstance, bool focus)
+	{
+		GUIElementBase* guiElemBase = nativeInstance->getGUIElement();
+		if (guiElemBase->_getType() == GUIElementBase::Type::Element)
+		{
+			GUIElement* guiElem = static_cast<GUIElement*>(guiElemBase);
+			guiElem->setFocus(focus);
+		}		
+	}
+
 	Rect2I ScriptGUIElement::internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance)
 	Rect2I ScriptGUIElement::internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance)
 	{
 	{
 		return nativeInstance->getGUIElement()->getBounds();
 		return nativeInstance->getGUIElement()->getBounds();

+ 0 - 3
TODO.txt

@@ -27,14 +27,11 @@ return them in checkForModifications?
 ----------------------------------------------------------------------
 ----------------------------------------------------------------------
 Project window
 Project window
 
 
-Test rename
-
 Later:
 Later:
  - Hook up ping effect so it triggers when I select a resource or sceneobject
  - Hook up ping effect so it triggers when I select a resource or sceneobject
   - Add ping to SceneTreeView
   - Add ping to SceneTreeView
  - Consider delaying search until user stops pressing keys (so not to have thousands of search results in the initial stages)
  - Consider delaying search until user stops pressing keys (so not to have thousands of search results in the initial stages)
  - Save & restore scroll position when Refresh happens
  - Save & restore scroll position when Refresh happens
- - Center labels and add a couple of pixels border from the selection rectangle (add special style since MultiLineLabel is used by other code)
 
 
 ----------------------------------------------------------------------
 ----------------------------------------------------------------------
 Resources
 Resources