Przeglądaj źródła

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 12 lat temu
rodzic
commit
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 GUIKeyEvent&)> keyEventFilter;
 	private:
+		static float DOUBLE_CLICK_INTERVAL;
+
 		struct SelectiveInputData
 		{
 			SelectiveInputData()
@@ -104,7 +106,6 @@ namespace BansheeEngine
 		GUIElement* mActiveElement;
 		GUIMouseButton mActiveMouseButton;
 
-
 		// Element and widget that currently have the keyboard focus
 		GUIWidget* mKeyboardFocusWidget;
 		GUIElement* mKeyboardFocusElement;
@@ -112,6 +113,8 @@ namespace BansheeEngine
 		GUIInputCaret* mInputCaret;
 		GUIInputSelection* mInputSelection;
 
+		float mLastClickTime;
+
 		bool mSeparateMeshesByWidget;
 		CM::Int2 mLastCursorLocalPos;
 

+ 2 - 0
BansheeEngine/Include/BsGUIMouseEvent.h

@@ -11,6 +11,7 @@ namespace BansheeEngine
 		MouseOut,
 		MouseDown,
 		MouseUp,
+		MouseDoubleClick,
 		MouseMove,
 		MouseWheelScroll,
 		MouseDrag,
@@ -67,6 +68,7 @@ namespace BansheeEngine
 		void setMouseWheelScrollData(GUIElement* mouseOverElement, float scrollAmount);
 		void setMouseUpData(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 setMouseDragStartData(GUIElement* mouseOverElement, const CM::Int2& position);

+ 40 - 10
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -370,6 +370,14 @@ namespace BansheeEngine
 
 			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)
 		{
 			if(mHasFocus)
@@ -529,14 +537,25 @@ namespace BansheeEngine
 				{
 					if(!mSelectionShown)
 						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
+
+					gGUIManager().getInputCaretTool()->moveCaretLeft();
+					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
 				}
 				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();
 				markContentAsDirty();
@@ -549,14 +568,25 @@ namespace BansheeEngine
 				{
 					if(!mSelectionShown)
 						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
+
+					gGUIManager().getInputCaretTool()->moveCaretRight();
+					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
 				}
 				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();
 				markContentAsDirty();

+ 17 - 4
BansheeEngine/Source/BsGUIManager.cpp

@@ -31,6 +31,8 @@
 using namespace CamelotFramework;
 namespace BansheeEngine
 {
+	float GUIManager::DOUBLE_CLICK_INTERVAL = 0.5f;
+
 	struct GUIGroupElement
 	{
 		GUIGroupElement()
@@ -57,7 +59,7 @@ namespace BansheeEngine
 		:mMouseOverElement(nullptr), mMouseOverWidget(nullptr), mSeparateMeshesByWidget(true), mActiveElement(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),
-		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));
 		mOnButtonUpConn = gInput().onButtonUp.connect(boost::bind(&GUIManager::onButtonUp, this, _1));
@@ -582,9 +584,20 @@ namespace BansheeEngine
 			{
 				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)
 				{

+ 10 - 0
BansheeEngine/Source/BsGUIMouseEvent.cpp

@@ -78,6 +78,16 @@ namespace BansheeEngine
 		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)
 	{
 		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:
  Key repeat
  Double click (Input box select all)
- Copy/Cut/Paste shortcut keys
- Copy/Cut/Past context menu
- Clipboard
  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
 
 IMMEDIATE: