Skip to content

Commit

Permalink
COMPOSER: Support keyboard shortcuts.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzie committed Nov 5, 2011
1 parent c2cb101 commit 3e98c56
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions engines/composer/composer.cpp
Expand Up @@ -262,6 +262,33 @@ void ComposerEngine::onMouseMove(const Common::Point &pos) {
void ComposerEngine::onKeyDown(uint16 keyCode) {
runEvent(kEventKeyDown, keyCode, 0, 0);
runEvent(kEventChar, keyCode, 0, 0);

for (Common::List<Library>::iterator i = _libraries.begin(); i != _libraries.end(); i++) {
for (Common::List<KeyboardHandler>::iterator j = i->_keyboardHandlers.begin(); j != i->_keyboardHandlers.end(); j++) {
const KeyboardHandler &handler = *j;
if (keyCode != handler.keyId)
continue;

int modifiers = g_system->getEventManager()->getModifierState();
switch (handler.modifierId) {
case 0x10: // shift
if (!(modifiers & Common::KBD_SHIFT))
continue;
break;
case 0x11: // control
if (!(modifiers & Common::KBD_CTRL))
continue;
break;
case 0:
break;
default:
warning("unknown keyb modifier %d", handler.modifierId);
continue;
}

runScript(handler.scriptId);
}
}
}

void ComposerEngine::setCursor(uint16 id, const Common::Point &offset) {
Expand Down Expand Up @@ -406,6 +433,16 @@ void ComposerEngine::loadLibrary(uint id) {
newLib._buttons.insert(newLib._buttons.begin(), button);
}

Common::Array<uint16> accelResources = library._archive->getResourceIDList(ID_ACEL);
for (uint i = 0; i < accelResources.size(); i++) {
Common::SeekableReadStream *stream = library._archive->getResource(ID_ACEL, accelResources[i]);
KeyboardHandler handler;
handler.keyId = stream->readUint16LE();
handler.modifierId = stream->readUint16LE();
handler.scriptId = stream->readUint16LE();
newLib._keyboardHandlers.push_back(handler);
}

// add background sprite, if it exists
if (hasResource(ID_BMAP, 1000))
setBackground(1000);
Expand Down
7 changes: 7 additions & 0 deletions engines/composer/composer.h
Expand Up @@ -95,11 +95,18 @@ enum {
kEventKeyUp = 7
};

struct KeyboardHandler {
uint16 keyId;
uint16 modifierId;
uint16 scriptId;
};

struct Library {
uint _id;
Archive *_archive;

Common::List<Button> _buttons;
Common::List<KeyboardHandler> _keyboardHandlers;
};

struct QueuedScript {
Expand Down
1 change: 1 addition & 0 deletions engines/composer/resource.h
Expand Up @@ -35,6 +35,7 @@ struct Animation;

#define ID_LBRC MKTAG('L','B','R','C') // Main FourCC

#define ID_ACEL MKTAG('A','C','E','L') // Keyboard Accelerator (v1)
#define ID_AMBI MKTAG('A','M','B','I') // Ambient (v1 sprite button)
#define ID_ANIM MKTAG('A','N','I','M') // Animation
#define ID_BMAP MKTAG('B','M','A','P') // Bitmap
Expand Down

0 comments on commit 3e98c56

Please sign in to comment.