diff options
Diffstat (limited to 'gui/virtualKeyboard.cpp')
-rw-r--r-- | gui/virtualKeyboard.cpp | 111 |
1 files changed, 106 insertions, 5 deletions
diff --git a/gui/virtualKeyboard.cpp b/gui/virtualKeyboard.cpp index a47f890ce5..02c28bf4a2 100644 --- a/gui/virtualKeyboard.cpp +++ b/gui/virtualKeyboard.cpp @@ -31,19 +31,34 @@ namespace GUI { -VirtualKeyboard::VirtualKeyboard() { +VirtualKeyboard::VirtualKeyboard() : _currentMode(0) { assert(g_system); _system = g_system; _parser = new VirtualKeyboardParser(this); - } VirtualKeyboard::~VirtualKeyboard() { + // TODO: clean up event data pointers + delete _parser; +} + +void VirtualKeyboard::reset() { + // TODO: clean up event data pointers + _modes.clear(); + _initialMode = _currentMode = 0; + _pos.x = _pos.y = 0; + _hAlignment = kAlignCentre; + _vAlignment = kAlignBottom; + _keyQueue.clear(); + _displaying = false; } bool VirtualKeyboard::loadKeyboardPack(Common::String packName) { + // reset to default settings + reset(); + if (ConfMan.hasKey("extrapath")) Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath")); @@ -84,19 +99,105 @@ bool VirtualKeyboard::loadKeyboardPack(Common::String packName) { return false; } - return _parser->parse(); + if (!_parser->parse()) + return false; + + if (!_initialMode) + warning("Initial mode of keyboard pack not defined"); + + ModeMap::iterator it; + for (it = _modes.begin(); it != _modes.end(); it++) { + // if no image then it means layout tag for the + // required resolution was missing from the mode tag. + if (!it->_value.image) { + warning("'%s' layout missing from '%s' mode", it->_value.resolution, it->_value.name); + return false; + } + } + + reposition(); + + return true; } -void VirtualKeyboard::show() { +void VirtualKeyboard::reposition() +{ + // calculate keyboard co-ordinates + int16 scrW = _system->getOverlayWidth(), scrH = _system->getOverlayHeight(); + int16 keyW = _currentMode->image->w, keyH = _currentMode->image->h; + if (scrW != keyW) { + switch (_hAlignment) { + case kAlignCentre: + _pos.x = (scrW - keyW) / 2; + break; + case kAlignRight: + _pos.x = scrW - keyW; + break; + } + } + if (scrH != keyH) { + switch (_vAlignment) { + case kAlignMiddle: + _pos.y = (scrH - keyH) / 2; + break; + case kAlignBottom: + _pos.y = scrH - keyH; + break; + } + } +} + +void VirtualKeyboard::processClick(int16 x, int16 y) +{ + x -= _pos.x; + y -= _pos.y; + if (x < 0 || x > _currentMode->image->w) return; + if (y < 0 || y > _currentMode->image->h) return; + + Common::MapArea *area = _currentMode->imageMap.findMapArea(x, y); + if (!area) return; + if (!_currentMode->events.contains(area->getTarget())) return; + Event evt = _currentMode->events[area->getTarget()]; + + switch (evt.type) { + case kEventKey: + // add virtual keypress to queue + _keyQueue.push_back(*(Common::KeyState*)evt.data); + break; + case kEventSwitchMode: + // switch to new mode + switchMode(*(Common::String *)evt.data); + break; + case kEventClose: + // close virtual keyboard + _displaying = false; + break; + } +} +void VirtualKeyboard::switchMode(const Common::String& newMode) { + if (!_modes.contains(newMode)) return; + _currentMode = &_modes[newMode]; + reposition(); + draw(); +} + +void VirtualKeyboard::show() { + _displaying = true; + runLoop(); } void VirtualKeyboard::runLoop() { + while (_displaying) { + + } } void VirtualKeyboard::draw() { - + _system->copyRectToOverlay((OverlayColor*)_currentMode->image->pixels, + _currentMode->image->pitch, _pos.x, _pos.y, + _currentMode->image->w, _currentMode->image->h); } } // end of namespace GUI |