Browse Source

Fixed an issue with new GUILayout code
Fixed modal windows so their resize messages are properly sent
Added OK/Cancel buttons to ColorPicker

Marko Pintera 10 years ago
parent
commit
bf1c1e80c1

+ 3 - 2
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -81,14 +81,15 @@ namespace BansheeEngine
 
 			mSizeRange.optimal.x += childSizeRange.optimal.x + paddingX;
 			mSizeRange.min.x += childSizeRange.min.x + paddingX;
-			mSizeRange.max.x += childSizeRange.max.x + paddingX;
 
 			mSizeRange.optimal.y = std::max((UINT32)mSizeRange.optimal.y, childSizeRange.optimal.y + paddingY);
 			mSizeRange.min.y = std::max((UINT32)mSizeRange.min.y, childSizeRange.min.y + paddingY);
-			mSizeRange.max.y = std::max((UINT32)mSizeRange.max.y, childSizeRange.max.y + paddingY);
 
 			childIdx++;
 		}
+
+		mSizeRange.max.x = 0;
+		mSizeRange.max.y = 0;
 	}
 
 	void GUILayoutX::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const

+ 3 - 2
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -81,14 +81,15 @@ namespace BansheeEngine
 
 			mSizeRange.optimal.y += childSizeRange.optimal.y + paddingY;
 			mSizeRange.min.y += childSizeRange.min.y + paddingY;
-			mSizeRange.max.y += childSizeRange.max.y + paddingY;
 
 			mSizeRange.optimal.x = std::max((UINT32)mSizeRange.optimal.x, childSizeRange.optimal.x + paddingX);
 			mSizeRange.min.x = std::max((UINT32)mSizeRange.min.x, childSizeRange.min.x + paddingX);
-			mSizeRange.max.x = std::max((UINT32)mSizeRange.max.x, childSizeRange.max.x + paddingX);
 
 			childIdx++;
 		}
+
+		mSizeRange.max.x = 0;
+		mSizeRange.max.y = 0;
 	}
 
 	void GUILayoutY::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, 

+ 37 - 2
MBansheeEditor/ColorPicker.cs

@@ -53,6 +53,11 @@ namespace BansheeEditor
         private GUIIntField guiInputB;
         private GUIIntField guiInputA;
 
+        private GUIButton guiOK;
+        private GUIButton guiCancel;
+
+        private Action<bool, Color> closedCallback;
+
         public enum ColorBoxMode
         {
             BG_R,
@@ -77,9 +82,12 @@ namespace BansheeEditor
             }
         }
 
-        public static ColorPicker Show()
+        public static ColorPicker Show(Action<bool, Color> closedCallback = null)
         {
-            return new ColorPicker();
+            ColorPicker picker = new ColorPicker();
+            picker.closedCallback = closedCallback;
+
+            return picker;
         }
 
         protected ColorPicker()
@@ -120,6 +128,9 @@ namespace BansheeEditor
             guiInputB = new GUIIntField();
             guiInputA = new GUIIntField();
 
+            guiOK = new GUIButton("OK");
+            guiCancel = new GUIButton("Cancel");
+
             guiColorBoxBtn.OnClick += OnColorBoxModeChanged;
             guiColorModeBtn.OnClick += OnSliderModeChanged;
 
@@ -134,6 +145,9 @@ namespace BansheeEditor
             guiInputB.OnChanged += OnInputBChanged;
             guiInputA.OnChanged += OnInputAChanged;
 
+            guiOK.OnClick += OnOK;
+            guiCancel.OnClick += OnCancel;
+
             GUILayout v0 = GUI.layout.AddLayoutY();
 
             GUILayout h0 = v0.AddLayoutX();
@@ -186,6 +200,15 @@ namespace BansheeEditor
             h5.AddFlexibleSpace();
             h5.AddElement(guiInputA);
 
+            v0.AddSpace(20);
+
+            GUILayout h6 = v0.AddLayoutX();
+            h6.AddFlexibleSpace();
+            h6.AddElement(guiOK);
+            h6.AddSpace(10);
+            h6.AddElement(guiCancel);
+            h6.AddFlexibleSpace();
+
             GUIArea overlay = GUI.AddArea(0, 0, Width, Height, -1, GUILayoutType.Explicit);
             overlay.layout.AddElement(guiSliderVert);
             overlay.layout.AddElement(guiSliderRHorz);
@@ -526,6 +549,18 @@ namespace BansheeEditor
             guiSliderAHorz.Percent = colAlpha;
         }
 
+        void OnOK()
+        {
+            if (closedCallback != null)
+                closedCallback(true, SelectedColor);
+        }
+
+        void OnCancel()
+        {
+            if (closedCallback != null)
+                closedCallback(false, SelectedColor);
+        }
+
         void UpdateInputBoxValues()
         {
             bool isHSV = sliderMode == SliderMode.HSV;

+ 4 - 1
SBansheeEditor/Source/BsScriptModalWindow.cpp

@@ -308,6 +308,8 @@ namespace BansheeEngine
 			void* params[] = { &width, &height };
 			mOnWindowResizedMethod->invokeVirtual(mManagedInstance, params);
 		}
+
+		ModalWindow::resized();
 	}
 
 	void ManagedModalWindow::close()
@@ -332,6 +334,7 @@ namespace BansheeEngine
 		if (onDestroyMethod != nullptr)
 			mOnDestroyThunk = (OnDestroyThunkDef)onDestroyMethod->getThunk();
 
-		mOnWindowResizedMethod = windowClass->getMethod("OnWindowResized", 2);
+		MonoClass* modalWindowClass = windowClass->getBaseClass();
+		mOnWindowResizedMethod = modalWindowClass->getMethod("OnWindowResized", 2);
 	}
 }

+ 1 - 2
TODO.txt

@@ -11,9 +11,8 @@ C#:
 Dialog.Show(title, text, btn1 text, btn1 callback, btn2 text, btn2 callback, btn3 text, btn3 callback)
 
 ColorPicker
- - Add OK button
- - GUI elements are all cut off and I cannot see the sliders
  - Input range limit on int fields seems broken. As I enter larger values they seem to overflow to other fields?
+ - Need texture for 2D slider handle
 
 Got a crash on shutdown that was caused by locking a mutex in an Event destructor. Event was Platform::onMouseCaptureChanged. 
 Issue happened when I closed the app via the X button (if that's relevant). It doesn't seem to happen always.