[Scummvm-cvs-logs] CVS: scummvm/saga input.cpp,1.43,1.44 interface.cpp,1.96,1.97 interface.h,1.53,1.54
Eugene Sandulenko
sev at users.sourceforge.net
Sun May 29 13:59:33 CEST 2005
Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv445
Modified Files:
input.cpp interface.cpp interface.h
Log Message:
Implement key auto-repeat used in savegame dialog.
Index: input.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/input.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- input.cpp 29 May 2005 15:39:34 -0000 1.43
+++ input.cpp 29 May 2005 20:57:45 -0000 1.44
@@ -108,6 +108,9 @@
break;
}
break;
+ case OSystem::EVENT_KEYUP:
+ _interface->processKeyUp(event.kbd.ascii);
+ break;
case OSystem::EVENT_LBUTTONUP:
_leftMouseButtonPressed = false;
break;
Index: interface.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/interface.cpp,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- interface.cpp 29 May 2005 15:39:34 -0000 1.96
+++ interface.cpp 29 May 2005 20:57:45 -0000 1.97
@@ -38,6 +38,8 @@
#include "saga/interface.h"
+#include "common/timer.h"
+
namespace Saga {
static int verbTypeToTextStringsIdLUT[kVerbTypesMax] = {
@@ -199,6 +201,8 @@
error("Interface::Interface(): not enough memory");
}
+ _textInputRepeatPhase = 0;
+
_initialized = true;
}
@@ -305,6 +309,7 @@
strcpy(_textInputString, "test1");
_textInputStringLength = strlen(_textInputString);
_textInputPos = _textInputStringLength + 1;
+ _textInputRepeatPhase = 0;
break;
}
@@ -432,6 +437,39 @@
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 @@
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;
}
}
Index: interface.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/interface.h,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- interface.h 29 May 2005 15:39:35 -0000 1.53
+++ interface.h 29 May 2005 20:57:45 -0000 1.54
@@ -210,8 +210,11 @@
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 @@
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 @@
uint _textInputStringLength;
uint _textInputPos;
uint _textInputMaxWidth;
+
+ int _textInputRepeatPhase;
+ uint16 _textInputRepeatChar;
};
} // End of namespace Saga
More information about the Scummvm-git-logs
mailing list