Explorar o código

Added double click to GUIManager
When selection is active and right arrow is pressed move cursor to right end, otherwise move it to left end

Marko Pintera %!s(int64=12) %!d(string=hai) anos
pai
achega
117e97c354

+ 4 - 1
BansheeEngine/Include/BsGUIManager.h

@@ -80,6 +80,8 @@ namespace BansheeEngine
 		boost::signal<void(GUIWidget*, GUIElement*, const GUIMouseEvent&)> mouseEventFilter;
 		boost::signal<void(GUIWidget*, GUIElement*, const GUIMouseEvent&)> mouseEventFilter;
 		boost::signal<void(GUIWidget*, GUIElement*, const GUIKeyEvent&)> keyEventFilter;
 		boost::signal<void(GUIWidget*, GUIElement*, const GUIKeyEvent&)> keyEventFilter;
 	private:
 	private:
+		static float DOUBLE_CLICK_INTERVAL;
+
 		struct SelectiveInputData
 		struct SelectiveInputData
 		{
 		{
 			SelectiveInputData()
 			SelectiveInputData()
@@ -104,7 +106,6 @@ namespace BansheeEngine
 		GUIElement* mActiveElement;
 		GUIElement* mActiveElement;
 		GUIMouseButton mActiveMouseButton;
 		GUIMouseButton mActiveMouseButton;
 
 
-
 		// Element and widget that currently have the keyboard focus
 		// Element and widget that currently have the keyboard focus
 		GUIWidget* mKeyboardFocusWidget;
 		GUIWidget* mKeyboardFocusWidget;
 		GUIElement* mKeyboardFocusElement;
 		GUIElement* mKeyboardFocusElement;
@@ -112,6 +113,8 @@ namespace BansheeEngine
 		GUIInputCaret* mInputCaret;
 		GUIInputCaret* mInputCaret;
 		GUIInputSelection* mInputSelection;
 		GUIInputSelection* mInputSelection;
 
 
+		float mLastClickTime;
+
 		bool mSeparateMeshesByWidget;
 		bool mSeparateMeshesByWidget;
 		CM::Int2 mLastCursorLocalPos;
 		CM::Int2 mLastCursorLocalPos;
 
 

+ 2 - 0
BansheeEngine/Include/BsGUIMouseEvent.h

@@ -11,6 +11,7 @@ namespace BansheeEngine
 		MouseOut,
 		MouseOut,
 		MouseDown,
 		MouseDown,
 		MouseUp,
 		MouseUp,
+		MouseDoubleClick,
 		MouseMove,
 		MouseMove,
 		MouseWheelScroll,
 		MouseWheelScroll,
 		MouseDrag,
 		MouseDrag,
@@ -67,6 +68,7 @@ namespace BansheeEngine
 		void setMouseWheelScrollData(GUIElement* mouseOverElement, float scrollAmount);
 		void setMouseWheelScrollData(GUIElement* mouseOverElement, float scrollAmount);
 		void setMouseUpData(GUIElement* mouseOverElement, const CM::Int2& position, GUIMouseButton button);
 		void setMouseUpData(GUIElement* mouseOverElement, const CM::Int2& position, GUIMouseButton button);
 		void setMouseDownData(GUIElement* mouseOverElement, const CM::Int2& position, GUIMouseButton button);
 		void setMouseDownData(GUIElement* mouseOverElement, const CM::Int2& position, GUIMouseButton button);
+		void setMouseDoubleClickData(GUIElement* mouseOverElement, const CM::Int2& position, GUIMouseButton button);
 
 
 		void setMouseDragData(GUIElement* mouseOverElement, const CM::Int2& position, const CM::Int2& dragAmount);
 		void setMouseDragData(GUIElement* mouseOverElement, const CM::Int2& position, const CM::Int2& dragAmount);
 		void setMouseDragStartData(GUIElement* mouseOverElement, const CM::Int2& position);
 		void setMouseDragStartData(GUIElement* mouseOverElement, const CM::Int2& position);

+ 40 - 10
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -370,6 +370,14 @@ namespace BansheeEngine
 
 
 			return true;
 			return true;
 		}
 		}
+		else if(ev.getType() == GUIMouseEventType::MouseDoubleClick && ev.getButton() == GUIMouseButton::Left)
+		{
+			showSelection(0);
+			gGUIManager().getInputSelectionTool()->selectAll();
+
+			markContentAsDirty();
+			return true;
+		}
 		else if(ev.getType() == GUIMouseEventType::MouseDown && ev.getButton() == GUIMouseButton::Left)
 		else if(ev.getType() == GUIMouseEventType::MouseDown && ev.getButton() == GUIMouseButton::Left)
 		{
 		{
 			if(mHasFocus)
 			if(mHasFocus)
@@ -529,14 +537,25 @@ namespace BansheeEngine
 				{
 				{
 					if(!mSelectionShown)
 					if(!mSelectionShown)
 						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
 						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
+
+					gGUIManager().getInputCaretTool()->moveCaretLeft();
+					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
 				}
 				}
 				else
 				else
-					clearSelection();
-
-				gGUIManager().getInputCaretTool()->moveCaretLeft();
+				{
+					if(mSelectionShown)
+					{
+						UINT32 selStart = gGUIManager().getInputSelectionTool()->getSelectionStart();
+						clearSelection();
 
 
-				if(ev.isShiftDown())
-					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
+						if(selStart > 0)
+							gGUIManager().getInputCaretTool()->moveCaretToChar(selStart - 1, CARET_AFTER);
+						else
+							gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
+					}
+					else
+						gGUIManager().getInputCaretTool()->moveCaretLeft();
+				}
 
 
 				scrollTextToCaret();
 				scrollTextToCaret();
 				markContentAsDirty();
 				markContentAsDirty();
@@ -549,14 +568,25 @@ namespace BansheeEngine
 				{
 				{
 					if(!mSelectionShown)
 					if(!mSelectionShown)
 						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
 						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
+
+					gGUIManager().getInputCaretTool()->moveCaretRight();
+					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
 				}
 				}
 				else
 				else
-					clearSelection();
-
-				gGUIManager().getInputCaretTool()->moveCaretRight();
+				{
+					if(mSelectionShown)
+					{
+						UINT32 selEnd = gGUIManager().getInputSelectionTool()->getSelectionEnd();
+						clearSelection();
 
 
-				if(ev.isShiftDown())
-					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
+						if(selEnd > 0)
+							gGUIManager().getInputCaretTool()->moveCaretToChar(selEnd - 1, CARET_AFTER);
+						else
+							gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
+					}
+					else
+						gGUIManager().getInputCaretTool()->moveCaretRight();
+				}
 
 
 				scrollTextToCaret();
 				scrollTextToCaret();
 				markContentAsDirty();
 				markContentAsDirty();

+ 17 - 4
BansheeEngine/Source/BsGUIManager.cpp

@@ -31,6 +31,8 @@
 using namespace CamelotFramework;
 using namespace CamelotFramework;
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	float GUIManager::DOUBLE_CLICK_INTERVAL = 0.5f;
+
 	struct GUIGroupElement
 	struct GUIGroupElement
 	{
 	{
 		GUIGroupElement()
 		GUIGroupElement()
@@ -57,7 +59,7 @@ namespace BansheeEngine
 		:mMouseOverElement(nullptr), mMouseOverWidget(nullptr), mSeparateMeshesByWidget(true), mActiveElement(nullptr), 
 		:mMouseOverElement(nullptr), mMouseOverWidget(nullptr), mSeparateMeshesByWidget(true), mActiveElement(nullptr), 
 		mActiveWidget(nullptr), mActiveMouseButton(GUIMouseButton::Left), mKeyboardFocusElement(nullptr), mKeyboardFocusWidget(nullptr),
 		mActiveWidget(nullptr), mActiveMouseButton(GUIMouseButton::Left), mKeyboardFocusElement(nullptr), mKeyboardFocusWidget(nullptr),
 		mCaretTexture(nullptr), mCaretBlinkInterval(0.5f), mCaretLastBlinkTime(0.0f), mCaretColor(1.0f, 0.6588f, 0.0f), mIsCaretOn(false),
 		mCaretTexture(nullptr), mCaretBlinkInterval(0.5f), mCaretLastBlinkTime(0.0f), mCaretColor(1.0f, 0.6588f, 0.0f), mIsCaretOn(false),
-		mTextSelectionColor(1.0f, 0.6588f, 0.0f), mInputCaret(nullptr), mInputSelection(nullptr), mSelectiveInputActive(false)
+		mTextSelectionColor(1.0f, 0.6588f, 0.0f), mInputCaret(nullptr), mInputSelection(nullptr), mSelectiveInputActive(false), mLastClickTime(0.0f)
 	{
 	{
 		mOnButtonDownConn = gInput().onButtonDown.connect(boost::bind(&GUIManager::onButtonDown, this, _1));
 		mOnButtonDownConn = gInput().onButtonDown.connect(boost::bind(&GUIManager::onButtonDown, this, _1));
 		mOnButtonUpConn = gInput().onButtonUp.connect(boost::bind(&GUIManager::onButtonUp, this, _1));
 		mOnButtonUpConn = gInput().onButtonUp.connect(boost::bind(&GUIManager::onButtonUp, this, _1));
@@ -582,9 +584,20 @@ namespace BansheeEngine
 			{
 			{
 				Int2 localPos = getWidgetRelativePos(*mMouseOverWidget, gInput().getMousePosition());
 				Int2 localPos = getWidgetRelativePos(*mMouseOverWidget, gInput().getMousePosition());
 
 
-				mMouseEvent.setMouseDownData(mMouseOverElement, localPos, guiButton);
-				if(sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent))
-					event.markAsUsed();
+				if((mLastClickTime + DOUBLE_CLICK_INTERVAL) > gTime().getTime())
+				{
+					mMouseEvent.setMouseDoubleClickData(mMouseOverElement, localPos, guiButton);
+					if(sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent))
+						event.markAsUsed();
+				}
+				else
+				{
+					mMouseEvent.setMouseDownData(mMouseOverElement, localPos, guiButton);
+					if(sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent))
+						event.markAsUsed();
+
+					mLastClickTime = gTime().getTime();
+				}
 
 
 				if(guiButton == GUIMouseButton::Left)
 				if(guiButton == GUIMouseButton::Left)
 				{
 				{

+ 10 - 0
BansheeEngine/Source/BsGUIMouseEvent.cpp

@@ -78,6 +78,16 @@ namespace BansheeEngine
 		mWheelScrollAmount = 0.0f;
 		mWheelScrollAmount = 0.0f;
 	}
 	}
 
 
+	void GUIMouseEvent::setMouseDoubleClickData(GUIElement* mouseOverElement, const Int2& position, GUIMouseButton button)
+	{
+		mType = GUIMouseEventType::MouseDoubleClick;
+		mPosition = position;
+		mMouseOverElement = mouseOverElement;
+		mButton = button;
+		mDragAmount = Int2();
+		mWheelScrollAmount = 0.0f;
+	}
+
 	void GUIMouseEvent::setMouseDragData(GUIElement* mouseOverElement, const Int2& position, const Int2& dragAmount)
 	void GUIMouseEvent::setMouseDragData(GUIElement* mouseOverElement, const Int2& position, const Int2& dragAmount)
 	{
 	{
 		mType = GUIMouseEventType::MouseDrag;
 		mType = GUIMouseEventType::MouseDrag;

+ 3 - 3
TODO.txt

@@ -12,10 +12,10 @@ GUIWidget::updateMeshes leaks. If I leave the game running I can see memory cont
 GUI SYSTEM WRAP UP:
 GUI SYSTEM WRAP UP:
  Key repeat
  Key repeat
  Double click (Input box select all)
  Double click (Input box select all)
- Copy/Cut/Paste shortcut keys
- Copy/Cut/Past context menu
- Clipboard
  Windows drag and drop detect
  Windows drag and drop detect
+  - http://www.codeguru.com/cpp/misc/misc/draganddrop/article.php/c349/Drag-And-Drop-between-Window-Controls.htm
+  - http://www.catch22.net/tuts/drop-target
+  - http://msdn.microsoft.com/en-us/library/windows/desktop/bb776902(v=vs.85).aspx
  Click when unfocused actually effects the elements in that window/widget
  Click when unfocused actually effects the elements in that window/widget
 
 
 IMMEDIATE:
 IMMEDIATE: