Explorar o código

Extract startTextInput & stopTextInput
(*) these functions do nothing with SDL1 - this is by design - less ifdef`s

AlexVinS %!s(int64=11) %!d(string=hai) anos
pai
achega
e57dbbde15

+ 2 - 13
client/GUIClasses.cpp

@@ -4028,13 +4028,7 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event)
 
 void CInGameConsole::startEnteringText()
 {
-	#ifndef VCMI_SDL1
-	if (SDL_IsTextInputActive() == SDL_FALSE)		
-	{		
-		SDL_StartTextInput();		
-	}		
-	SDL_SetTextInputRect(&pos);
-	#endif
+	CSDL_Ext::startTextInput(&pos);
 
 	enteredText = "_";
 	if(GH.topInt() == adventureInt)
@@ -4053,12 +4047,7 @@ void CInGameConsole::startEnteringText()
 
 void CInGameConsole::endEnteringText(bool printEnteredText)
 {
-	#ifndef VCMI_SDL1
-	if (SDL_IsTextInputActive() == SDL_TRUE)
-	{		
-		SDL_StopTextInput();			
-	}		
-	#endif
+	CSDL_Ext::stopTextInput();
 	
 	prevEntDisp = -1;
 	if(printEnteredText)

+ 2 - 13
client/gui/CIntObjectClasses.cpp

@@ -1583,23 +1583,12 @@ CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf)
 
 void CTextInput::focusGot()
 {
-	#ifndef VCMI_SDL1
-	if (SDL_IsTextInputActive() == SDL_FALSE)		
-	{		
-		SDL_StartTextInput();		
-	}		
-	SDL_SetTextInputRect(&pos);
-	#endif	
+	CSDL_Ext::startTextInput(&pos);	
 }
 
 void CTextInput::focusLost()
 {
-	#ifndef VCMI_SDL1
-	if (SDL_IsTextInputActive() == SDL_TRUE)
-	{		
-		SDL_StopTextInput();			
-	}		
-	#endif	
+	CSDL_Ext::stopTextInput();
 }
 
 

+ 23 - 0
client/gui/SDL_Extensions.cpp

@@ -983,6 +983,29 @@ SDL_Color CSDL_Ext::makeColor(ui8 r, ui8 g, ui8 b, ui8 a)
 	return ret;
 }
 
+void CSDL_Ext::startTextInput(SDL_Rect * where)
+{
+	#ifndef VCMI_SDL1
+	if (SDL_IsTextInputActive() == SDL_FALSE)		
+	{		
+		SDL_StartTextInput();		
+	}		
+	SDL_SetTextInputRect(where);
+	#endif
+}
+
+void CSDL_Ext::stopTextInput()
+{
+	#ifndef VCMI_SDL1
+	if (SDL_IsTextInputActive() == SDL_TRUE)
+	{		
+		SDL_StopTextInput();			
+	}		
+	#endif	
+}
+
+
+
 template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<2>(int, int);
 template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<3>(int, int);
 template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<4>(int, int);

+ 3 - 0
client/gui/SDL_Extensions.h

@@ -263,4 +263,7 @@ namespace CSDL_Ext
 	template<int bpp>
 	void applyEffectBpp( SDL_Surface * surf, const SDL_Rect * rect, int mode );
 	void applyEffect(SDL_Surface * surf, const SDL_Rect * rect, int mode); //mode: 0 - sepia, 1 - grayscale
+	
+	void startTextInput(SDL_Rect * where);
+	void stopTextInput();
 }