2008-07-03 22:38:19 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-07-07 15:06:43 +00:00
|
|
|
#include "backends/common/virtual-keyboard.h"
|
|
|
|
#include "backends/common/virtual-keyboard-parser.h"
|
2008-07-03 22:38:19 +00:00
|
|
|
#include "common/config-manager.h"
|
2008-07-07 14:30:11 +00:00
|
|
|
#include "common/events.h"
|
2008-07-11 20:10:14 +00:00
|
|
|
#include "common/unzip.h"
|
|
|
|
#include "graphics/cursorman.h"
|
2008-07-03 22:38:19 +00:00
|
|
|
#include "graphics/imageman.h"
|
2008-07-07 21:10:58 +00:00
|
|
|
#include "graphics/surface-keycolored.h"
|
2008-07-11 20:10:14 +00:00
|
|
|
#include "gui/newgui.h"
|
2008-07-03 22:38:19 +00:00
|
|
|
|
2008-07-07 15:42:26 +00:00
|
|
|
namespace Common {
|
2008-07-03 22:38:19 +00:00
|
|
|
|
2008-07-07 14:30:11 +00:00
|
|
|
VirtualKeyboard::VirtualKeyboard() : _currentMode(0), _keyDown(0) {
|
2008-07-03 22:38:19 +00:00
|
|
|
assert(g_system);
|
|
|
|
_system = g_system;
|
|
|
|
|
|
|
|
_parser = new VirtualKeyboardParser(this);
|
2008-07-08 15:03:39 +00:00
|
|
|
_loaded = _displaying = _drag = false;
|
2008-07-09 13:33:36 +00:00
|
|
|
_lastScreenChanged = _system->getScreenChangeID();
|
2008-07-11 20:10:14 +00:00
|
|
|
|
|
|
|
memset(_cursor, 0xFF, sizeof(_cursor));
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VirtualKeyboard::~VirtualKeyboard() {
|
2008-07-04 17:55:19 +00:00
|
|
|
// TODO: clean up event data pointers
|
2008-07-09 13:33:36 +00:00
|
|
|
deleteEventData();
|
2008-07-04 17:55:19 +00:00
|
|
|
delete _parser;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::reset() {
|
|
|
|
// TODO: clean up event data pointers
|
2008-07-09 13:33:36 +00:00
|
|
|
deleteEventData();
|
2008-07-04 17:55:19 +00:00
|
|
|
_modes.clear();
|
|
|
|
_initialMode = _currentMode = 0;
|
2008-07-08 15:03:39 +00:00
|
|
|
_kbdBound.left = _kbdBound.top
|
|
|
|
= _kbdBound.right = _kbdBound.bottom = 0;
|
2008-07-04 17:55:19 +00:00
|
|
|
_hAlignment = kAlignCentre;
|
|
|
|
_vAlignment = kAlignBottom;
|
|
|
|
_keyQueue.clear();
|
2008-07-07 14:30:11 +00:00
|
|
|
_keyDown = 0;
|
2008-07-26 20:35:46 +00:00
|
|
|
_keyFlags = 0;
|
2008-07-08 15:03:39 +00:00
|
|
|
_displaying = _drag = false;
|
|
|
|
_firstRun = true;
|
2008-07-09 13:33:36 +00:00
|
|
|
_lastScreenChanged = _system->getScreenChangeID();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::deleteEventData() {
|
|
|
|
ModeMap::iterator it_m;
|
|
|
|
EventMap::iterator it_e;
|
|
|
|
for (it_m = _modes.begin(); it_m != _modes.end(); it_m++) {
|
|
|
|
EventMap *evt = &(it_m->_value.events);
|
|
|
|
for (it_e = evt->begin(); it_e != evt->end(); it_e++)
|
|
|
|
delete it_e->_value.data;
|
|
|
|
}
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VirtualKeyboard::loadKeyboardPack(Common::String packName) {
|
2008-07-04 17:55:19 +00:00
|
|
|
|
2008-07-03 22:38:19 +00:00
|
|
|
if (Common::File::exists(packName + ".xml")) {
|
|
|
|
// uncompressed keyboard pack
|
|
|
|
if (!_parser->loadFile(packName + ".xml"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else if (Common::File::exists(packName + ".zip")) {
|
|
|
|
// compressed keyboard pack
|
|
|
|
#ifdef USE_ZLIB
|
|
|
|
unzFile zipFile = unzOpen((packName + ".zip").c_str());
|
|
|
|
if (zipFile && unzLocateFile(zipFile, (packName + ".xml").c_str(), 2) == UNZ_OK) {
|
|
|
|
unz_file_info fileInfo;
|
|
|
|
unzOpenCurrentFile(zipFile);
|
|
|
|
unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
|
|
|
|
byte *buffer = new byte[fileInfo.uncompressed_size+1];
|
|
|
|
assert(buffer);
|
2008-07-04 11:38:15 +00:00
|
|
|
memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(byte));
|
2008-07-03 22:38:19 +00:00
|
|
|
unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size);
|
|
|
|
unzCloseCurrentFile(zipFile);
|
2008-07-04 11:38:15 +00:00
|
|
|
if (!_parser->loadBuffer(buffer, fileInfo.uncompressed_size+1, true)) {
|
2008-07-03 22:38:19 +00:00
|
|
|
unzClose(zipFile);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2008-07-24 10:00:56 +00:00
|
|
|
warning("Could not find %s.xml file in %s.zip keyboard pack", packName.c_str(), packName.c_str());
|
2008-07-03 22:38:19 +00:00
|
|
|
unzClose(zipFile);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
unzClose(zipFile);
|
|
|
|
|
|
|
|
ImageMan.addArchive(packName + ".zip");
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
warning("Keyboard pack not found");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-09 11:30:49 +00:00
|
|
|
_parser->setParseMode(kParseFull);
|
2008-07-07 21:10:58 +00:00
|
|
|
_loaded = _parser->parse();
|
|
|
|
if (_loaded)
|
|
|
|
printf("Keyboard pack '%s' loaded successfully!\n", packName.c_str());
|
2008-07-08 15:03:39 +00:00
|
|
|
|
2008-07-07 21:10:58 +00:00
|
|
|
return _loaded;
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-08 15:03:39 +00:00
|
|
|
void VirtualKeyboard::setDefaultPosition()
|
2008-07-04 17:55:19 +00:00
|
|
|
{
|
2008-07-09 13:33:36 +00:00
|
|
|
int16 scrW = _system->getOverlayWidth(), scrH = _system->getOverlayHeight();
|
2008-07-08 15:03:39 +00:00
|
|
|
int16 kbdW = _kbdBound.width(), kbdH = _kbdBound.height();
|
|
|
|
int16 posX = 0, posY = 0;
|
2008-07-09 13:33:36 +00:00
|
|
|
if (scrW != kbdW) {
|
2008-07-04 17:55:19 +00:00
|
|
|
switch (_hAlignment) {
|
2008-07-08 15:03:39 +00:00
|
|
|
case kAlignLeft:
|
|
|
|
posX = 0;
|
|
|
|
break;
|
2008-07-04 17:55:19 +00:00
|
|
|
case kAlignCentre:
|
2008-07-09 13:33:36 +00:00
|
|
|
posX = (scrW - kbdW) / 2;
|
2008-07-04 17:55:19 +00:00
|
|
|
break;
|
|
|
|
case kAlignRight:
|
2008-07-09 13:33:36 +00:00
|
|
|
posX = scrW - kbdW;
|
2008-07-07 15:45:48 +00:00
|
|
|
break;
|
2008-07-04 17:55:19 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-09 13:33:36 +00:00
|
|
|
if (scrH != kbdH) {
|
2008-07-04 17:55:19 +00:00
|
|
|
switch (_vAlignment) {
|
2008-07-08 15:03:39 +00:00
|
|
|
case kAlignTop:
|
|
|
|
posY = 0;
|
|
|
|
break;
|
2008-07-04 17:55:19 +00:00
|
|
|
case kAlignMiddle:
|
2008-07-09 13:33:36 +00:00
|
|
|
posY = (scrH - kbdH) / 2;
|
2008-07-04 17:55:19 +00:00
|
|
|
break;
|
|
|
|
case kAlignBottom:
|
2008-07-09 13:33:36 +00:00
|
|
|
posY = scrH - kbdH;
|
2008-07-07 15:45:48 +00:00
|
|
|
break;
|
2008-07-04 17:55:19 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-08 15:03:39 +00:00
|
|
|
_kbdBound.moveTo(posX, posY);
|
2008-07-04 17:55:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-09 11:30:49 +00:00
|
|
|
bool VirtualKeyboard::checkModeResolutions()
|
2008-07-04 17:55:19 +00:00
|
|
|
{
|
2008-07-09 11:30:49 +00:00
|
|
|
_parser->setParseMode(kParseCheckResolutions);
|
|
|
|
_loaded = _parser->parse();
|
|
|
|
return _loaded;
|
2008-07-08 15:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::move(int16 x, int16 y) {
|
|
|
|
// snap to edge of screen
|
|
|
|
if (ABS(x) < SNAP_WIDTH)
|
|
|
|
x = 0;
|
|
|
|
int16 x2 = _system->getOverlayWidth() - _kbdBound.width();
|
|
|
|
if (ABS(x - x2) < SNAP_WIDTH)
|
|
|
|
x = x2;
|
|
|
|
if (ABS(y) < SNAP_WIDTH)
|
|
|
|
y = 0;
|
|
|
|
int16 y2 = _system->getOverlayHeight() - _kbdBound.height();
|
|
|
|
if (ABS(y - y2) < SNAP_WIDTH)
|
|
|
|
y = y2;
|
|
|
|
|
|
|
|
_kbdBound.moveTo(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String VirtualKeyboard::findArea(int16 x, int16 y) {
|
|
|
|
x -= _kbdBound.left;
|
|
|
|
y -= _kbdBound.top;
|
|
|
|
if (x < 0 || x > _kbdBound.width()) return "";
|
|
|
|
if (y < 0 || y > _kbdBound.height()) return "";
|
|
|
|
return _currentMode->imageMap.findMapArea(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::processClick(const Common::String& area) {
|
2008-07-07 21:10:58 +00:00
|
|
|
if (!_currentMode->events.contains(area)) return;
|
|
|
|
Event evt = _currentMode->events[area];
|
2008-07-08 15:03:39 +00:00
|
|
|
|
2008-07-04 17:55:19 +00:00
|
|
|
switch (evt.type) {
|
2008-07-26 20:35:46 +00:00
|
|
|
case kEventKey: {
|
2008-07-04 17:55:19 +00:00
|
|
|
// add virtual keypress to queue
|
2008-07-26 20:35:46 +00:00
|
|
|
Common::KeyState key = *(Common::KeyState*)evt.data;
|
|
|
|
key.flags ^= _keyFlags;
|
|
|
|
if ((key.keycode >= Common::KEYCODE_a) && (key.keycode <= Common::KEYCODE_z))
|
|
|
|
key.ascii = (key.flags & Common::KBD_SHIFT) ? key.keycode - 32 : key.keycode;
|
|
|
|
_keyQueue.insertKey(key);
|
|
|
|
_keyFlags = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kEventModifier:
|
|
|
|
_keyFlags ^= *(byte*)(evt.data);
|
2008-07-04 17:55:19 +00:00
|
|
|
break;
|
|
|
|
case kEventSwitchMode:
|
|
|
|
// switch to new mode
|
|
|
|
switchMode(*(Common::String *)evt.data);
|
2008-07-26 20:35:46 +00:00
|
|
|
_keyFlags = 0;
|
2008-07-04 17:55:19 +00:00
|
|
|
break;
|
|
|
|
case kEventClose:
|
|
|
|
// close virtual keyboard
|
|
|
|
_displaying = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 22:38:19 +00:00
|
|
|
|
2008-07-07 14:30:11 +00:00
|
|
|
void VirtualKeyboard::switchMode(Mode *newMode) {
|
2008-07-11 20:10:14 +00:00
|
|
|
_kbdBound.setWidth(newMode->image->w);
|
|
|
|
_kbdBound.setHeight(newMode->image->h);
|
2008-07-07 14:30:11 +00:00
|
|
|
_currentMode = newMode;
|
|
|
|
_needRedraw = true;
|
|
|
|
}
|
|
|
|
|
2008-07-04 17:55:19 +00:00
|
|
|
void VirtualKeyboard::switchMode(const Common::String& newMode) {
|
2008-07-07 14:30:11 +00:00
|
|
|
if (!_modes.contains(newMode)) {
|
|
|
|
warning("Keyboard mode '%s' unknown", newMode.c_str());
|
|
|
|
return;
|
|
|
|
}
|
2008-07-08 15:03:39 +00:00
|
|
|
switchMode(&_modes[newMode]);
|
2008-07-04 17:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::show() {
|
2008-07-09 11:30:49 +00:00
|
|
|
if (!_loaded) {
|
2008-07-11 20:10:14 +00:00
|
|
|
// if not loaded then load default "vkeybd" pack
|
|
|
|
if (!loadKeyboardPack("vkeybd")) {
|
|
|
|
warning("Keyboard not loaded therefore can't be shown");
|
|
|
|
return;
|
|
|
|
}
|
2008-07-09 11:30:49 +00:00
|
|
|
}
|
2008-07-09 13:33:36 +00:00
|
|
|
if (_lastScreenChanged != _system->getScreenChangeID())
|
|
|
|
screenChanged();
|
2008-07-07 14:30:11 +00:00
|
|
|
switchMode(_initialMode);
|
2008-07-04 17:55:19 +00:00
|
|
|
_displaying = true;
|
2008-07-08 15:03:39 +00:00
|
|
|
if (_firstRun) {
|
|
|
|
_firstRun = false;
|
|
|
|
setDefaultPosition();
|
|
|
|
}
|
2008-07-11 20:10:14 +00:00
|
|
|
|
|
|
|
if (!g_gui.isActive()) {
|
|
|
|
_system->showOverlay();
|
|
|
|
_system->clearOverlay();
|
|
|
|
}
|
|
|
|
_overlayBackup.create(_system->getOverlayWidth(), _system->getOverlayHeight(), sizeof(OverlayColor));
|
|
|
|
_system->grabOverlay((OverlayColor*)_overlayBackup.pixels, _overlayBackup.w);
|
|
|
|
setupCursor();
|
|
|
|
|
2008-07-04 17:55:19 +00:00
|
|
|
runLoop();
|
2008-07-11 20:10:14 +00:00
|
|
|
|
|
|
|
removeCursor();
|
|
|
|
_system->copyRectToOverlay((OverlayColor*)_overlayBackup.pixels, _overlayBackup.w, 0, 0, _overlayBackup.w, _overlayBackup.h);
|
|
|
|
if (!g_gui.isActive()) _system->hideOverlay();
|
|
|
|
_overlayBackup.free();
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-07 14:30:11 +00:00
|
|
|
void VirtualKeyboard::hide() {
|
|
|
|
_displaying = false;
|
|
|
|
}
|
2008-07-03 22:38:19 +00:00
|
|
|
|
2008-07-09 13:33:36 +00:00
|
|
|
void VirtualKeyboard::screenChanged() {
|
|
|
|
_lastScreenChanged = _system->getScreenChangeID();
|
|
|
|
if (!checkModeResolutions())
|
|
|
|
_displaying = false;
|
|
|
|
}
|
|
|
|
|
2008-07-07 14:30:11 +00:00
|
|
|
void VirtualKeyboard::runLoop() {
|
|
|
|
Common::EventManager *eventMan = _system->getEventManager();
|
2008-07-08 15:03:39 +00:00
|
|
|
|
2008-07-04 17:55:19 +00:00
|
|
|
while (_displaying) {
|
2008-07-07 14:30:11 +00:00
|
|
|
if (_needRedraw) redraw();
|
2008-07-04 17:55:19 +00:00
|
|
|
|
2008-07-11 20:10:14 +00:00
|
|
|
animateCursor();
|
2008-07-07 21:10:58 +00:00
|
|
|
_system->updateScreen();
|
2008-07-07 14:30:11 +00:00
|
|
|
Common::Event event;
|
|
|
|
while (eventMan->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2008-07-08 15:03:39 +00:00
|
|
|
if (_kbdBound.contains(event.mouse)) {
|
|
|
|
_areaDown = findArea(event.mouse.x, event.mouse.y);
|
|
|
|
if (_areaDown.empty()) {
|
|
|
|
_drag = true;
|
|
|
|
_dragPoint.x = event.mouse.x - _kbdBound.left;
|
|
|
|
_dragPoint.y = event.mouse.y - _kbdBound.top;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
_areaDown.clear();
|
2008-07-07 14:30:11 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
2008-07-08 15:03:39 +00:00
|
|
|
if (_drag) _drag = false;
|
|
|
|
if (!_areaDown.empty() && _areaDown == findArea(event.mouse.x, event.mouse.y)) {
|
|
|
|
processClick(_areaDown);
|
|
|
|
_areaDown.clear();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
if (_drag) {
|
|
|
|
move(event.mouse.x - _dragPoint.x,
|
|
|
|
event.mouse.y - _dragPoint.y);
|
|
|
|
_needRedraw = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Common::EVENT_SCREEN_CHANGED:
|
2008-07-09 13:33:36 +00:00
|
|
|
screenChanged();
|
2008-07-07 14:30:11 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
_system->quit();
|
|
|
|
return;
|
2008-07-07 15:45:48 +00:00
|
|
|
default:
|
|
|
|
break;
|
2008-07-07 14:30:11 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-09 23:05:47 +00:00
|
|
|
// Delay for a moment
|
|
|
|
_system->delayMillis(10);
|
2008-07-04 17:55:19 +00:00
|
|
|
}
|
2008-07-09 13:33:36 +00:00
|
|
|
|
|
|
|
// push keydown & keyup events into the event manager
|
|
|
|
Common::Event evt;
|
|
|
|
evt.synthetic = false;
|
|
|
|
while (!_keyQueue.empty()) {
|
|
|
|
evt.kbd = _keyQueue.pop();
|
|
|
|
evt.type = Common::EVENT_KEYDOWN;
|
|
|
|
eventMan->pushEvent(evt);
|
|
|
|
evt.type = Common::EVENT_KEYUP;
|
|
|
|
eventMan->pushEvent(evt);
|
|
|
|
}
|
2008-07-03 22:38:19 +00:00
|
|
|
}
|
|
|
|
|
2008-07-07 14:30:11 +00:00
|
|
|
void VirtualKeyboard::redraw() {
|
2008-07-07 21:10:58 +00:00
|
|
|
Graphics::SurfaceKeyColored surf;
|
|
|
|
|
|
|
|
surf.create(_system->getOverlayWidth(), _system->getOverlayHeight(), sizeof(OverlayColor));
|
2008-07-11 20:10:14 +00:00
|
|
|
|
|
|
|
memcpy(surf.pixels, _overlayBackup.pixels, surf.w * surf.h * sizeof(OverlayColor));
|
|
|
|
surf.blit(_currentMode->image, _kbdBound.left, _kbdBound.top, _currentMode->transparentColor);
|
2008-07-09 13:33:36 +00:00
|
|
|
|
2008-07-07 21:10:58 +00:00
|
|
|
_system->copyRectToOverlay((OverlayColor*)surf.pixels, surf.w, 0, 0, surf.w, surf.h);
|
|
|
|
|
|
|
|
surf.free();
|
|
|
|
|
2008-07-07 14:30:11 +00:00
|
|
|
_needRedraw = false;
|
|
|
|
}
|
|
|
|
|
2008-07-11 20:10:14 +00:00
|
|
|
void VirtualKeyboard::setupCursor() {
|
|
|
|
const byte palette[] = {
|
|
|
|
255, 255, 255, 0,
|
|
|
|
255, 255, 255, 0,
|
|
|
|
171, 171, 171, 0,
|
|
|
|
87, 87, 87, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
CursorMan.pushCursorPalette(palette, 0, 4);
|
|
|
|
CursorMan.pushCursor(NULL, 0, 0, 0, 0);
|
|
|
|
CursorMan.showMouse(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::animateCursor() {
|
|
|
|
int time = _system->getMillis();
|
|
|
|
if (time > _cursorAnimateTimer + kCursorAnimateDelay) {
|
|
|
|
for (int i = 0; i < 15; i++) {
|
|
|
|
if ((i < 6) || (i > 8)) {
|
|
|
|
_cursor[16 * 7 + i] = _cursorAnimateCounter;
|
|
|
|
_cursor[16 * i + 7] = _cursorAnimateCounter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CursorMan.replaceCursor(_cursor, 16, 16, 7, 7);
|
|
|
|
|
|
|
|
_cursorAnimateTimer = time;
|
|
|
|
_cursorAnimateCounter = (_cursorAnimateCounter + 1) % 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::removeCursor() {
|
|
|
|
CursorMan.popCursor();
|
|
|
|
CursorMan.popCursorPalette();
|
|
|
|
}
|
|
|
|
|
2008-07-26 20:35:46 +00:00
|
|
|
VirtualKeyboard::Queue::Queue() {
|
|
|
|
_keyPos = _keys.begin();
|
|
|
|
_strPos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::Queue::insertKey(KeyState key) {
|
|
|
|
switch (key.keycode) {
|
|
|
|
case KEYCODE_LEFT:
|
|
|
|
moveLeft();
|
|
|
|
return;
|
|
|
|
case KEYCODE_RIGHT:
|
|
|
|
moveRight();
|
|
|
|
return;
|
|
|
|
case KEYCODE_BACKSPACE:
|
|
|
|
deleteKey();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String keyStr;
|
|
|
|
if (key.keycode >= 32 && key.keycode <= 126) {
|
|
|
|
if (key.flags & KBD_CTRL)
|
|
|
|
keyStr += "Ctrl+";
|
|
|
|
if (key.flags & KBD_ALT)
|
|
|
|
keyStr += "Alt+";
|
|
|
|
if (key.flags & KBD_SHIFT && (key.ascii < 65 || key.ascii > 90))
|
|
|
|
keyStr += "Shift+";
|
|
|
|
keyStr += (char)key.ascii;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *k = keyStr.c_str();
|
|
|
|
while (char ch = *k++)
|
|
|
|
_str.insertChar(ch, _strPos++);
|
|
|
|
|
|
|
|
VirtualKeyPress kp;
|
|
|
|
kp.key = key;
|
|
|
|
kp.strLen = keyStr.size();
|
|
|
|
_keys.insert(_keyPos, kp);
|
|
|
|
_keyPos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::Queue::deleteKey() {
|
|
|
|
if (_keyPos == _keys.begin())
|
|
|
|
return;
|
|
|
|
List<VirtualKeyPress>::iterator it = _keyPos;
|
|
|
|
it--;
|
|
|
|
_strPos -= it->strLen;
|
|
|
|
while((it->strLen)-- > 0)
|
|
|
|
_str.deleteChar(_strPos);
|
|
|
|
_keys.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::Queue::moveLeft() {
|
|
|
|
if (_keyPos == _keys.begin())
|
|
|
|
return;
|
|
|
|
_keyPos--;
|
|
|
|
_strPos -= _keyPos->strLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::Queue::moveRight() {
|
|
|
|
List<VirtualKeyPress>::iterator it = _keyPos;
|
|
|
|
it++;
|
|
|
|
if (it == _keys.end())
|
|
|
|
return;
|
|
|
|
_strPos += _keyPos->strLen;
|
|
|
|
_keyPos = it;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyState VirtualKeyboard::Queue::pop() {
|
|
|
|
KeyState ret = _keys.begin()->key;
|
|
|
|
_keys.pop_front();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboard::Queue::clear() {
|
|
|
|
_keys.clear();
|
|
|
|
_keyPos = _keys.begin();
|
|
|
|
_str.clear();
|
|
|
|
_strPos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VirtualKeyboard::Queue::empty()
|
|
|
|
{
|
|
|
|
return _keys.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
String VirtualKeyboard::Queue::getString()
|
|
|
|
{
|
|
|
|
return _str;
|
|
|
|
}
|
|
|
|
|
2008-07-11 20:10:14 +00:00
|
|
|
} // end of namespace Common
|