about summary refs log tree commit diff
path: root/src/game
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2010-06-19 13:48:01 +0200
committeroy <Tom_Adams@web.de>2010-06-19 13:48:01 +0200
commitb790634a2dc273a506d3373a85e8b11ae9b043da (patch)
tree27c5dcae6f290ca6fc05677842a3fd0eeb2c8651 /src/game
parentea64b0d7b361308d3b3737ecbac724856bfddda4 (diff)
downloadzcatch-b790634a2dc273a506d3373a85e8b11ae9b043da.tar.gz
zcatch-b790634a2dc273a506d3373a85e8b11ae9b043da.zip
scroll the possible commands in the console's tab completion if the wanted one is out of sight. Closes #105
Diffstat (limited to 'src/game')
-rw-r--r--src/game/client/components/console.cpp14
-rw-r--r--src/game/client/components/console.h1
2 files changed, 14 insertions, 1 deletions
diff --git a/src/game/client/components/console.cpp b/src/game/client/components/console.cpp
index 9e09e6a2..2916606b 100644
--- a/src/game/client/components/console.cpp
+++ b/src/game/client/components/console.cpp
@@ -51,6 +51,7 @@ CGameConsole::CInstance::CInstance(int Type)
 
 	m_aCompletionBuffer[0] = 0;
 	m_CompletionChosen = -1;
+	m_CompletionRenderOffset = 0.0f;
 	
 	m_pCommand = 0x0;
 }
@@ -241,6 +242,8 @@ struct CRenderInfo
 	const char *m_pCurrentCmd;
 	int m_WantedCompletion;
 	int m_EnumCount;
+	float m_Offset;
+	float m_Width;
 };
 
 void CGameConsole::PossibleCommandsRenderCallback(const char *pStr, void *pUser)
@@ -256,6 +259,12 @@ void CGameConsole::PossibleCommandsRenderCallback(const char *pStr, void *pUser)
 			pInfo->m_pSelf->RenderTools()->DrawRoundRect(pInfo->m_Cursor.m_X-3, pInfo->m_Cursor.m_Y, tw+5, pInfo->m_Cursor.m_FontSize+4, pInfo->m_Cursor.m_FontSize/3);
 		pInfo->m_pSelf->Graphics()->QuadsEnd();
 		
+		// scroll when out of sight
+		if(pInfo->m_Cursor.m_X < 3.0f)
+			pInfo->m_Offset = 0.0f;
+		else if(pInfo->m_Cursor.m_X+tw > pInfo->m_Width)
+			pInfo->m_Offset -= pInfo->m_Width/2;
+
 		pInfo->m_pSelf->TextRender()->TextColor(0.05f, 0.05f, 0.05f,1);
 		pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, -1);
 	}
@@ -386,8 +395,10 @@ void CGameConsole::OnRender()
 		Info.m_pSelf = this;
 		Info.m_WantedCompletion = pConsole->m_CompletionChosen;
 		Info.m_EnumCount = 0;
+		Info.m_Offset = pConsole->m_CompletionRenderOffset;
+		Info.m_Width = Screen.w;
 		Info.m_pCurrentCmd = pConsole->m_aCompletionBuffer;
-		TextRender()->SetCursor(&Info.m_Cursor, x, y+12.0f, FontSize, TEXTFLAG_RENDER);
+		TextRender()->SetCursor(&Info.m_Cursor, x+Info.m_Offset, y+12.0f, FontSize, TEXTFLAG_RENDER);
 
 		const char *pPrompt = "> ";
 		if(m_ConsoleType)
@@ -438,6 +449,7 @@ void CGameConsole::OnRender()
 			if(pConsole->m_Input.GetString()[0] != 0)
 			{
 				m_pConsole->PossibleCommands(pConsole->m_aCompletionBuffer, pConsole->m_CompletionFlagmask, PossibleCommandsRenderCallback, &Info);
+				pConsole->m_CompletionRenderOffset = Info.m_Offset;
 				
 				if(Info.m_EnumCount <= 0)
 				{
diff --git a/src/game/client/components/console.h b/src/game/client/components/console.h
index d146307f..6d644001 100644
--- a/src/game/client/components/console.h
+++ b/src/game/client/components/console.h
@@ -24,6 +24,7 @@ class CGameConsole : public CComponent
 		char m_aCompletionBuffer[128];
 		int m_CompletionChosen;
 		int m_CompletionFlagmask;
+		float m_CompletionRenderOffset;
 		
 		IConsole::CCommandInfo *m_pCommand;