diff options
| -rw-r--r-- | saga/input.cpp | 3 | ||||
| -rw-r--r-- | saga/interface.cpp | 148 | ||||
| -rw-r--r-- | saga/interface.h | 11 | 
3 files changed, 107 insertions, 55 deletions
diff --git a/saga/input.cpp b/saga/input.cpp index 1a3ad11db0..e383ca2a3f 100644 --- a/saga/input.cpp +++ b/saga/input.cpp @@ -108,6 +108,9 @@ int SagaEngine::processInput() {  				break;  			}  			break; +		case OSystem::EVENT_KEYUP: +			_interface->processKeyUp(event.kbd.ascii); +			break;  		case OSystem::EVENT_LBUTTONUP:  			_leftMouseButtonPressed = false;  			break; diff --git a/saga/interface.cpp b/saga/interface.cpp index ee4a9a39a4..881c4b2c53 100644 --- a/saga/interface.cpp +++ b/saga/interface.cpp @@ -38,6 +38,8 @@  #include "saga/interface.h" +#include "common/timer.h" +  namespace Saga {  static int verbTypeToTextStringsIdLUT[kVerbTypesMax] = { @@ -199,6 +201,8 @@ Interface::Interface(SagaEngine *vm) : _vm(vm), _initialized(false) {  		error("Interface::Interface(): not enough memory");  	} +	_textInputRepeatPhase = 0; +  	_initialized = true;  } @@ -305,6 +309,7 @@ void Interface::setMode(int mode, bool force) {  			strcpy(_textInputString, "test1");  			_textInputStringLength = strlen(_textInputString);  			_textInputPos = _textInputStringLength + 1; +			_textInputRepeatPhase = 0;  			break;  	} @@ -432,6 +437,39 @@ bool Interface::processAscii(uint16 ascii) {  	return false;  } +#define KEYBOARD_REPEAT_DELAY1 300000L +#define KEYBOARD_REPEAT_DELAY2 50000L + +void Interface::textInputRepeatCallback(void *refCon) { +	((Interface *)refCon)->textInputRepeat(); +}                                                                                + +void Interface::textInputStartRepeat(uint16 ascii) { +	if (!_textInputRepeatPhase) { +		_textInputRepeatPhase = 1; +		Common::g_timer->installTimerProc(&textInputRepeatCallback, KEYBOARD_REPEAT_DELAY1, this); +	} + +	_textInputRepeatChar = ascii; +} + +void Interface::textInputRepeat() { +	if (_textInputRepeatPhase == 1) { +		_textInputRepeatPhase = 2; +		Common::g_timer->removeTimerProc(&textInputRepeatCallback); +		Common::g_timer->installTimerProc(&textInputRepeatCallback, KEYBOARD_REPEAT_DELAY2, this); +	} else if (_textInputRepeatPhase == 2) { +		processAscii(_textInputRepeatChar); +	} +} + +void Interface::processKeyUp(uint16 ascii) { +	if (_textInputRepeatPhase) { +		Common::g_timer->removeTimerProc(&textInputRepeatCallback); +		_textInputRepeatPhase = 0; +	} +} +  void Interface::setStatusText(const char *text, int statusColor) {  	assert(text != NULL);  	assert(strlen(text) < STATUS_TEXT_LEN); @@ -786,62 +824,64 @@ void Interface::processTextInput(uint16 ascii) {  	memset(tempString, 0, SAVE_TITLE_SIZE);  	ch[1] = 0; +	textInputStartRepeat(ascii); +  	switch (ascii) { -				case(8): // backspace -					if (_textInputPos <= 1) { -						break; -					} -					_textInputPos--; -				case(127): // del -					if (_textInputPos <= _textInputStringLength) { -						if (_textInputPos != 1) { -							strncpy(tempString, _textInputString, _textInputPos - 1);							 -						} -						if (_textInputPos != _textInputStringLength) { -							strncat(tempString, &_textInputString[_textInputPos], _textInputStringLength - _textInputPos); -						} -						strcpy(_textInputString, tempString); -						_textInputStringLength = strlen(_textInputString); -					} -					break; -				case(276): // left -					if (_textInputPos > 1) { -						_textInputPos--; -					} -					break; -				case(275): // right -					if (_textInputPos <= _textInputStringLength) { -						_textInputPos++; -					} -					break; -				default: -					if (((ascii >= 'a') && (ascii <='z')) ||  -						((ascii >= '0') && (ascii <='9')) || -						((ascii >= 'A') && (ascii <='Z'))) { -							if (_textInputStringLength < SAVE_TITLE_SIZE - 1) { -								ch[0] = ascii; -								tempWidth = _vm->_font->getStringWidth(SMALL_FONT_ID, ch, 0, 0); -								tempWidth += _vm->_font->getStringWidth(SMALL_FONT_ID, _textInputString, 0, 0); -								if (tempWidth > _textInputMaxWidth) { +	case(8): // backspace +		if (_textInputPos <= 1) { +			break; +		} +		_textInputPos--; +	case(127): // del +		if (_textInputPos <= _textInputStringLength) { +			if (_textInputPos != 1) { +				strncpy(tempString, _textInputString, _textInputPos - 1);							 +			} +			if (_textInputPos != _textInputStringLength) { +				strncat(tempString, &_textInputString[_textInputPos], _textInputStringLength - _textInputPos); +			} +			strcpy(_textInputString, tempString); +			_textInputStringLength = strlen(_textInputString); +		} +		break; +	case(276): // left +		if (_textInputPos > 1) { +			_textInputPos--; +		} +		break; +	case(275): // right +		if (_textInputPos <= _textInputStringLength) { +			_textInputPos++; +		} +		break; +	default: +		if (((ascii >= 'a') && (ascii <='z')) ||  +			((ascii >= '0') && (ascii <='9')) || +			((ascii >= 'A') && (ascii <='Z'))) { +			if (_textInputStringLength < SAVE_TITLE_SIZE - 1) { +				ch[0] = ascii; +				tempWidth = _vm->_font->getStringWidth(SMALL_FONT_ID, ch, 0, 0); +				tempWidth += _vm->_font->getStringWidth(SMALL_FONT_ID, _textInputString, 0, 0); +				if (tempWidth > _textInputMaxWidth) {  									break; -								} -								if (_textInputPos != 1) { -									strncpy(tempString, _textInputString, _textInputPos - 1); -									strcat(tempString, ch); -								} -								if ((_textInputStringLength == 0) || (_textInputPos == 1)) { -									strcpy(tempString, ch); -								} -								if ((_textInputStringLength != 0) && (_textInputPos != _textInputStringLength)) { -									strncat(tempString, &_textInputString[_textInputPos - 1], _textInputStringLength - _textInputPos + 1); -								} - -								strcpy(_textInputString, tempString); -								_textInputStringLength = strlen(_textInputString); -								_textInputPos++; -							} -						} -						break; +				} +				if (_textInputPos != 1) { +					strncpy(tempString, _textInputString, _textInputPos - 1); +					strcat(tempString, ch); +				} +				if ((_textInputStringLength == 0) || (_textInputPos == 1)) { +					strcpy(tempString, ch); +				} +				if ((_textInputStringLength != 0) && (_textInputPos != _textInputStringLength)) { +					strncat(tempString, &_textInputString[_textInputPos - 1], _textInputStringLength - _textInputPos + 1); +				} +				 +				strcpy(_textInputString, tempString); +				_textInputStringLength = strlen(_textInputString); +				_textInputPos++; +			} +		} +		break;  	}  } diff --git a/saga/interface.h b/saga/interface.h index d9a914df16..7b6330bc39 100644 --- a/saga/interface.h +++ b/saga/interface.h @@ -210,8 +210,11 @@ public:  	void setVerbState(int verb, int state);  	bool processAscii(uint16 ascii); -	 +	void processKeyUp(uint16 ascii); +  private: +	static void textInputRepeatCallback(void *refCon); +  	void drawInventory(SURFACE *backBuffer);  	void updateInventory(int pos);  	void inventoryChangePos(int chg); @@ -298,6 +301,9 @@ private:  	void drawVerbPanel(SURFACE *backBuffer, PanelButton* panelButton);  	void calcOptionSaveSlider();  	void processTextInput(uint16 ascii); +	void textInputStartRepeat(uint16 ascii); +	void textInputRepeat(void); +  public:  	void converseInit(void);  	void converseClear(void); @@ -378,6 +384,9 @@ private:  	uint _textInputStringLength;  	uint _textInputPos;  	uint _textInputMaxWidth; + +	int _textInputRepeatPhase; +	uint16 _textInputRepeatChar;  };  } // End of namespace Saga  | 
