Browse Source

A few remaining input caret fixes

Marko Pintera 12 years ago
parent
commit
22fb8ea488

+ 1 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -154,6 +154,7 @@
     <ClInclude Include="Include\BsGUICommandEvent.h" />
     <ClInclude Include="Include\BsGUIInputBox.h" />
     <ClInclude Include="Include\BsGUIButtonEvent.h" />
+    <ClInclude Include="Include\BsGUIInputCaret.h" />
     <ClInclude Include="Include\BsGUILayoutOptions.h" />
     <ClInclude Include="Include\BsGUILayoutX.h" />
     <ClInclude Include="Include\BsGUILayout.h" />

+ 28 - 0
BansheeEngine/Include/BsGUIInputCaret.h

@@ -0,0 +1,28 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+
+namespace BansheeEngine
+{
+
+	class BS_EXPORT GUIInputCaret
+	{
+	public:
+		GUIInputCaret(TextSprite& sprite);
+		~GUIInputCaret();
+
+		ImageSprite& getSprite();
+		void updateSprite();
+
+		void moveCaretToStart();
+		void moveCaretLeft();
+		void moveCaretRight();
+		void moveCaretUp();
+		void moveCaretRight();
+		void moveCaretToPos();
+
+	private:
+		CM::UINT32 mCaretPos;
+		ImageSprite* mCaretSprite;
+	};
+}

+ 3 - 4
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -679,10 +679,9 @@ namespace BansheeEngine
 
 	void GUIInputBox::moveCaretRight()
 	{
-		//if(isCaretAtLineStart())
-		//	mCaretPos = mCaretPos + 2; // Skip line start char as well
-		//else
-			mCaretPos = mCaretPos + 1; // TODO - Limit this
+		UINT32 maxCaretPos = mText.size(); // One extra because beginning of first line has an extra "fake" char
+
+		mCaretPos = std::min(maxCaretPos, mCaretPos + 1);
 	}
 
 	void GUIInputBox::moveCaretToChar(UINT32 charIdx, CaretPos caretPos)

+ 6 - 2
BansheeEngine/Source/BsTextSprite.cpp

@@ -228,6 +228,7 @@ namespace BansheeEngine
 		UINT32 lineStartChar = 0;
 		UINT32 lineEndChar = 0;
 		UINT32 newlineChars = 0;
+		UINT32 lineIdx = 0;
 		for(auto& line : mLineDescs)
 		{
 			if(pos.y >= line.lineYStart && pos.y < (line.lineYStart + (INT32)line.lineHeight))
@@ -239,10 +240,13 @@ namespace BansheeEngine
 
 			newlineChars++; // Newline chars count in the startChar/endChar variables, but don't actually exist in the buffers
 			// so we need to filter them out
+			lineIdx++;
 		}
 
+		bool hasNewlineChar = lineIdx < (mLineDescs.size() - 1);
+
 		UINT32 lineStartQuad = lineStartChar - newlineChars;
-		UINT32 lineEndQuad = lineEndChar - newlineChars;
+		UINT32 lineEndQuad = lineEndChar - newlineChars - (hasNewlineChar ? 1 : 0);
 
 		float nearestDist = std::numeric_limits<float>::max();
 		UINT32 nearestChar = 0;
@@ -269,7 +273,7 @@ namespace BansheeEngine
 				float dist = Math::Abs(centerX - vecPos.x);
 				if(dist < nearestDist)
 				{
-					nearestChar = quadIdx;
+					nearestChar = quadIdx + newlineChars;
 					nearestDist = dist;
 					foundChar = true;
 				}

+ 5 - 5
TODO.txt

@@ -15,9 +15,6 @@ IMMEDIATE:
  - Clicking on a window to focus and immediately trying to drag/resize it, doesn't work. I first need to click, then click again to drag/resize.
  - OpenGL rendering slows to extremely with time (seems to be related to rendering, possibly GUI, possibly in general Pass/Material/Shader/PassParams)
  - Update debug camera so it uses callbacks
- - Add support for diacritical marks
- - onMovedOrResized is still used by Viewport
- - Replace list of windows in WIndowEventUtilities with WindowManagers list. No need to keep two lists I think
 
  - I have disabled linear filtering because it doesn't look good on scale9grid textures. (Add another material so it works with stretched textures?)
  - Enable alpha test so I don't render completely transparent pixels.
@@ -28,7 +25,6 @@ IMMEDIATE:
 TextBox needed elements:
  - Up/Down arrow keys should move cursor up/down
  - Drag mouse to update selection
- - Need to figure out how do I place a cursor on an empty first line?
  - Text scroll. Typing outside of textbox should scroll the text so caret is visible.
  - Get DebugCamera to ignore input if GUI has already processed it
  - Cut/Copy/Paste
@@ -184,6 +180,9 @@ Low priority TODO
  - Shared GPU buffers
    - wouldn't work atm due to the way I update the buffers (and the way I mark them dirty)
    - Material::setParamBlock is commented out
+ - Add support for diacritical marks to the input system (in WindowEventUtilities)
+ - onMovedOrResized is still used by Viewport while that same callback is offered by RenderWindowManager. There is no need to have them in both places.
+ - Replace list of windows in WIndowEventUtilities with RenderWindowManager list. No need to keep two lists I think
 ----------------------------------------------------------------------------------------------
 Optional:
  - Need better handling for shader techniques. Some Materials are able to run on all renderers yet I can only specify one. This is problematic
@@ -223,4 +222,5 @@ After polish and ideas:
    - Since I probably can't compile them, try adding them to VS and see what intellisense says?
  - Textures and all other buffers keep a copy of their data in system memory. If there are memory constraints we might need a way to avoid this.
  - Move all multiplatform files (window creation, cursor, etc.) into a separate PlatformSpecific folder. So anyone porting it to a new platform
-   knows that he only needs to change those files.
+   knows that he only needs to change those files.
+ - Make sure my Log system uses XML + HTML