aboutsummaryrefslogtreecommitdiff
path: root/engines/sword1
diff options
context:
space:
mode:
authorMax Horn2007-06-22 21:34:03 +0000
committerMax Horn2007-06-22 21:34:03 +0000
commitc9030e4653d8dd3a96724681a6423f1b1b296d4d (patch)
tree72233ef1f69f654151e449a1ed9122baf7ec4174 /engines/sword1
parent753eee6d0c25b5b3767c4ab7e7a95488753423a7 (diff)
downloadscummvm-rg350-c9030e4653d8dd3a96724681a6423f1b1b296d4d.tar.gz
scummvm-rg350-c9030e4653d8dd3a96724681a6423f1b1b296d4d.tar.bz2
scummvm-rg350-c9030e4653d8dd3a96724681a6423f1b1b296d4d.zip
Made BS1 track the full KeyState upon KEYDOWN events (this makes it possible to remove to workaround for Mac keyboards)
svn-id: r27627
Diffstat (limited to 'engines/sword1')
-rw-r--r--engines/sword1/control.cpp44
-rw-r--r--engines/sword1/control.h7
2 files changed, 23 insertions, 28 deletions
diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp
index 108773fc23..7479484a06 100644
--- a/engines/sword1/control.cpp
+++ b/engines/sword1/control.cpp
@@ -204,7 +204,7 @@ void Control::askForCd(void) {
_system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
}
delay(300);
- if (_keyPressed) {
+ if (_keyPressed.keycode) {
if (!Common::File::exists(fName)) {
memset(_screenBuf, 0, 640 * 480);
renderText(_lStrings[STR_INCORRECT_CD], 320, 230, TEXT_CENTER);
@@ -224,7 +224,8 @@ void Control::askForCd(void) {
uint8 Control::runPanel(void) {
_mouseDown = false;
_restoreBuf = NULL;
- _keyPressed = _numButtons = 0;
+ _keyPressed.keycode = Common::KEYCODE_INVALID;
+ _numButtons = 0;
_screenBuf = (uint8*)malloc(640 * 480);
memset(_screenBuf, 0, 640 * 480);
_system->copyRectToScreen(_screenBuf, 640, 0, 0, 640, 480);
@@ -283,7 +284,7 @@ uint8 Control::runPanel(void) {
_cursorVisible = false;
_cursorTick = 0;
}
- if (_keyPressed)
+ if (_keyPressed.keycode)
handleSaveKey(_keyPressed);
else if (_cursorVisible != visible)
showSavegameNames();
@@ -328,10 +329,9 @@ uint8 Control::getClicks(uint8 mode, uint8 *retVal) {
}
uint8 flag = 0;
- if (_keyPressed == 27)
+ if (_keyPressed.keycode == Common::KEYCODE_ESCAPE)
flag = kButtonCancel;
- // 3 is num keypad Enter on Macs. See FR #1273746
- else if (_keyPressed == '\r' || _keyPressed == '\n' || _keyPressed == 3)
+ else if (_keyPressed.keycode == Common::KEYCODE_RETURN || _keyPressed.keycode == Common::KEYCODE_KP_ENTER)
flag = kButtonOk;
if (flag) {
@@ -622,9 +622,9 @@ bool Control::getConfirm(const uint8 *title) {
buttons[0]->draw();
buttons[1]->draw();
delay(1000 / 12);
- if (_keyPressed == 27)
+ if (_keyPressed.keycode == Common::KEYCODE_ESCAPE)
retVal = 2;
- else if (_keyPressed == '\r' || _keyPressed == '\n')
+ else if (_keyPressed.keycode == Common::KEYCODE_RETURN || _keyPressed.keycode == Common::KEYCODE_KP_ENTER)
retVal = 1;
if (_mouseState & BS1L_BUTTON_DOWN) {
if (buttons[0]->wasClicked(_mouseX, _mouseY))
@@ -649,7 +649,7 @@ bool Control::getConfirm(const uint8 *title) {
return retVal == 1;
}
-bool Control::keyAccepted(uint8 key) {
+bool Control::keyAccepted(uint16 ascii) {
// this routine needs changes for Czech keys... No idea how to do that, though.
// FIXME: It is not a good idea to put non-ASCII chars into a C source file,
// since there is no way to specify which encoding you are using.
@@ -658,22 +658,22 @@ bool Control::keyAccepted(uint8 key) {
// do not at all specify which encoding keyboard events use, so this
// check here is probably not portable anyway...
static const char allowedSpecials[] = "éèáàúùäöüÄÖÜß,.:-()?! \"\'";
- if (((key >= 'A') && (key <= 'Z')) ||
- ((key >= 'a') && (key <= 'z')) ||
- ((key >= '0') && (key <= '9')) ||
- strchr(allowedSpecials, key))
+ if (((ascii >= 'A') && (ascii <= 'Z')) ||
+ ((ascii >= 'a') && (ascii <= 'z')) ||
+ ((ascii >= '0') && (ascii <= '9')) ||
+ strchr(allowedSpecials, ascii))
return true;
else
return false;
}
-void Control::handleSaveKey(uint8 key) {
+void Control::handleSaveKey(Common::KeyState kbd) {
if (_selectedSavegame < 255) {
uint8 len = strlen((char*)_saveNames[_selectedSavegame]);
- if ((key == 8) && len) // backspace
+ if ((kbd.keycode == Common::KEYCODE_BACKSPACE) && len) // backspace
_saveNames[_selectedSavegame][len - 1] = '\0';
- else if (keyAccepted(key) && (len < 31)) {
- _saveNames[_selectedSavegame][len] = key;
+ else if (keyAccepted(kbd.ascii) && (len < 31)) {
+ _saveNames[_selectedSavegame][len] = kbd.ascii;
_saveNames[_selectedSavegame][len + 1] = '\0';
}
showSavegameNames();
@@ -1037,7 +1037,7 @@ void Control::delay(uint32 msecs) {
uint32 now = _system->getMillis();
uint32 endTime = now + msecs;
- _keyPressed = 0; //reset
+ _keyPressed.keycode = Common::KEYCODE_INVALID; //reset
_mouseState = 0;
do {
@@ -1045,13 +1045,7 @@ void Control::delay(uint32 msecs) {
while (eventMan->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_KEYDOWN:
-
- // Make sure backspace works right (this fixes a small issue on OS X)
- if (event.kbd.keycode == Common::KEYCODE_BACKSPACE) {
-printf("Mac backspace workaround, was %d\n", event.kbd.ascii);
- _keyPressed = 8;
- } else
- _keyPressed = (byte)event.kbd.ascii;
+ _keyPressed = event.kbd;
// we skip the rest of the delay and return immediately
// to handle keyboard input
return;
diff --git a/engines/sword1/control.h b/engines/sword1/control.h
index 89ea7199b6..1825350170 100644
--- a/engines/sword1/control.h
+++ b/engines/sword1/control.h
@@ -27,6 +27,7 @@
#define SWORD1_CONTROL_H
#include "common/scummsys.h"
+#include "common/events.h"
#include "sword1/sworddefs.h"
class OSystem;
@@ -118,8 +119,8 @@ private:
void saveNameSelect(uint8 id, bool saving);
bool saveToFile(void);
bool restoreFromFile(void);
- bool keyAccepted(uint8 key);
- void handleSaveKey(uint8 key);
+ bool keyAccepted(uint16 ascii);
+ void handleSaveKey(Common::KeyState kbd);
void renderVolumeBar(uint8 id, uint8 volL, uint8 volR);
uint16 getTextWidth(const uint8 *str);
@@ -141,7 +142,7 @@ private:
Sound *_sound;
uint8 *_font, *_redFont;
uint8 *_screenBuf;
- uint8 _keyPressed;
+ Common::KeyState _keyPressed;
void delay(uint32 msecs);
uint16 _mouseX, _mouseY, _mouseState;
bool _mouseDown;