aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Kennedy2008-07-07 14:30:11 +0000
committerStephen Kennedy2008-07-07 14:30:11 +0000
commit98f999f8e01c4752a771f1a8c6aec77b6efe3fb5 (patch)
treeb56a61b845e25225491aea6a82180ae5903c32e4
parent950b68be7b0e228addf92150abf0fbca1091e57e (diff)
downloadscummvm-rg350-98f999f8e01c4752a771f1a8c6aec77b6efe3fb5.tar.gz
scummvm-rg350-98f999f8e01c4752a771f1a8c6aec77b6efe3fb5.tar.bz2
scummvm-rg350-98f999f8e01c4752a771f1a8c6aec77b6efe3fb5.zip
WIP: VirtualKeyboard updates:
- got keyboard bitmap displaying (no transparency as yet) - simple event loop for VK to capture mouse clicks done (and untested code to process the clicks) - pollEvent() method to deliver the virtual key press events to EventManager svn-id: r32939
-rw-r--r--backends/events/default/default-events.cpp21
-rw-r--r--backends/events/default/default-events.h3
-rw-r--r--base/main.cpp13
-rw-r--r--gui/virtualKeyboard.cpp74
-rw-r--r--gui/virtualKeyboard.h21
-rw-r--r--gui/virtualKeyboardParser.cpp4
6 files changed, 109 insertions, 27 deletions
diff --git a/backends/events/default/default-events.cpp b/backends/events/default/default-events.cpp
index 0caba25792..601e292ad0 100644
--- a/backends/events/default/default-events.cpp
+++ b/backends/events/default/default-events.cpp
@@ -191,6 +191,9 @@ DefaultEventManager::DefaultEventManager(OSystem *boss) :
_hasPlaybackEvent = false;
}
+
+ _vk = new GUI::VirtualKeyboard();
+ _vk->loadKeyboardPack("test");
}
DefaultEventManager::~DefaultEventManager() {
@@ -349,7 +352,10 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
uint32 time = _boss->getMillis();
bool result;
- result = _boss->pollEvent(event);
+ // poll virtual keyboard
+ result = _vk->pollEvent(event);
+ // if no vk event, then poll backend
+ if (!result) result = _boss->pollEvent(event);
if (_recordMode != kPassthrough) {
@@ -384,6 +390,19 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
_currentKeyDown.flags = event.kbd.flags;
_keyRepeatTime = time + kKeyRepeatInitialDelay;
#endif
+
+ // quick hack to show/hide keyboard
+ if (event.kbd.keycode == Common::KEYCODE_F6 && event.kbd.flags == 0) {
+ if (_vk->isDisplaying()) {
+ _vk->hide();
+ } else {
+ bool isPaused = (g_engine) ? g_engine->isPaused() : true;
+ if (!isPaused) g_engine->pauseEngine(true);
+ _vk->show();
+ if (!isPaused) g_engine->pauseEngine(false);
+ }
+ }
+
break;
case Common::EVENT_KEYUP:
_modifierState = event.kbd.flags;
diff --git a/backends/events/default/default-events.h b/backends/events/default/default-events.h
index 98dcd4b3de..db054b4d26 100644
--- a/backends/events/default/default-events.h
+++ b/backends/events/default/default-events.h
@@ -28,6 +28,7 @@
#include "common/events.h"
#include "common/savefile.h"
+#include "gui/virtualKeyboard.h"
/*
At some point we will remove pollEvent from OSystem and change
@@ -44,6 +45,8 @@ use a subclass of EventProvider.
class DefaultEventManager : public Common::EventManager {
OSystem *_boss;
+ GUI::VirtualKeyboard *_vk;
+
Common::Point _mousePos;
int _buttonState;
int _modifierState;
diff --git a/base/main.cpp b/base/main.cpp
index 4ab486ee9b..88d9f3bab5 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -52,12 +52,6 @@
#include "gui/launcher.h"
#endif
-#define ___VK_TEST
-
-#if defined(___VK_TEST)
-#include "gui/virtualKeyboard.h"
-#endif
-
static bool launcherDialog(OSystem &system) {
@@ -74,13 +68,6 @@ static bool launcherDialog(OSystem &system) {
// Clear the main screen
system.clearScreen();
-#if defined(___VK_TEST)
- GUI::VirtualKeyboard *vk = new GUI::VirtualKeyboard();
- if (vk->loadKeyboardPack("test"))
- printf("Successfully parsed test keyboard pack\n");
-
-#endif
-
#if defined(_WIN32_WCE)
CELauncherDialog dlg;
#elif defined(__DC__)
diff --git a/gui/virtualKeyboard.cpp b/gui/virtualKeyboard.cpp
index 02c28bf4a2..c0e9c0fb47 100644
--- a/gui/virtualKeyboard.cpp
+++ b/gui/virtualKeyboard.cpp
@@ -26,12 +26,13 @@
#include "gui/virtualKeyboard.h"
#include "gui/virtualKeyboardParser.h"
#include "common/config-manager.h"
+#include "common/events.h"
#include "graphics/imageman.h"
#include "common/unzip.h"
namespace GUI {
-VirtualKeyboard::VirtualKeyboard() : _currentMode(0) {
+VirtualKeyboard::VirtualKeyboard() : _currentMode(0), _keyDown(0) {
assert(g_system);
_system = g_system;
@@ -51,8 +52,8 @@ void VirtualKeyboard::reset() {
_hAlignment = kAlignCentre;
_vAlignment = kAlignBottom;
_keyQueue.clear();
+ _keyDown = 0;
_displaying = false;
-
}
bool VirtualKeyboard::loadKeyboardPack(Common::String packName) {
@@ -115,8 +116,6 @@ bool VirtualKeyboard::loadKeyboardPack(Common::String packName) {
}
}
- reposition();
-
return true;
}
@@ -175,29 +174,86 @@ void VirtualKeyboard::processClick(int16 x, int16 y)
}
}
+void VirtualKeyboard::switchMode(Mode *newMode) {
+ _currentMode = newMode;
+ reposition();
+ _needRedraw = true;
+}
+
void VirtualKeyboard::switchMode(const Common::String& newMode) {
- if (!_modes.contains(newMode)) return;
+ if (!_modes.contains(newMode)) {
+ warning("Keyboard mode '%s' unknown", newMode.c_str());
+ return;
+ }
_currentMode = &_modes[newMode];
reposition();
- draw();
+ _needRedraw = true;
}
void VirtualKeyboard::show() {
+ switchMode(_initialMode);
_displaying = true;
runLoop();
}
-void VirtualKeyboard::runLoop() {
+void VirtualKeyboard::hide() {
+ _displaying = false;
+}
+void VirtualKeyboard::runLoop() {
+ Common::EventManager *eventMan = _system->getEventManager();
+
+ _system->showOverlay();
+ // capture mouse clicks
while (_displaying) {
+ if (_needRedraw) redraw();
+ Common::Event event;
+ while (eventMan->pollEvent(event)) {
+ switch (event.type) {
+ case Common::EVENT_LBUTTONDOWN:
+ _mouseDown = event.mouse;
+ break;
+ case Common::EVENT_LBUTTONUP:
+ if (ABS(_mouseDown.x - event.mouse.x) < 5
+ && ABS(_mouseDown.y - event.mouse.y) < 5)
+ processClick(event.mouse.x, event.mouse.y);
+ break;
+ case Common::EVENT_QUIT:
+ _system->quit();
+ return;
+ }
+ }
}
+ // clear keyboard from overlay
+ _system->hideOverlay();
}
-void VirtualKeyboard::draw() {
+void VirtualKeyboard::redraw() {
+ _needRedraw = false;
+ _system->clearOverlay();
_system->copyRectToOverlay((OverlayColor*)_currentMode->image->pixels,
- _currentMode->image->pitch, _pos.x, _pos.y,
+ _currentMode->image->w, _pos.x, _pos.y,
_currentMode->image->w, _currentMode->image->h);
+ _system->updateScreen();
+}
+
+bool VirtualKeyboard::pollEvent(Common::Event &event) {
+ if (_displaying || (_keyQueue.empty() && !_keyDown))
+ return false;
+
+ event.synthetic = false; // ???
+ if (_keyDown) {
+ event.type = Common::EVENT_KEYUP;
+ event.kbd = *_keyDown;
+ _keyQueue.remove_at(0);
+ _keyDown = 0;
+ } else {
+ _keyDown = _keyQueue.begin();
+ event.type = Common::EVENT_KEYDOWN;
+ event.kbd = *_keyDown;
+ }
+ return true;
}
} // end of namespace GUI
diff --git a/gui/virtualKeyboard.h b/gui/virtualKeyboard.h
index 914949aad3..2d4c32e420 100644
--- a/gui/virtualKeyboard.h
+++ b/gui/virtualKeyboard.h
@@ -28,6 +28,7 @@
class OSystem;
+#include "common/events.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
#include "common/imagemap.h"
@@ -42,7 +43,7 @@ class VirtualKeyboardParser;
class VirtualKeyboard {
-private:
+
/** Type of key event */
enum EventType {
kEventKey,
@@ -90,6 +91,17 @@ public:
bool loadKeyboardPack(Common::String packName);
void show();
+ void hide();
+ bool isDisplaying() {
+ return _displaying;
+ }
+
+ /**
+ * Get the next virtual key event in the event queue.
+ * @param event point to an Event struct, which will be filled with the event data.
+ * @return true if an event was retrieved.
+ */
+ bool pollEvent(Common::Event &event);
private:
OSystem *_system;
@@ -100,12 +112,14 @@ private:
// TODO : sort order of all this stuff
void reset();
void reposition();
+ void switchMode(Mode *newMode);
void switchMode(const Common::String& newMode);
void processClick(int16 x, int16 y);
void runLoop();
- void draw();
+ void redraw();
bool _displaying;
+ bool _needRedraw;
ModeMap _modes;
Mode *_initialMode;
@@ -115,7 +129,10 @@ private:
HorizontalAlignment _hAlignment;
VerticalAlignment _vAlignment;
+ Common::Point _mouseDown;
+
Common::Array<Common::KeyState> _keyQueue;
+ Common::KeyState *_keyDown;
};
diff --git a/gui/virtualKeyboardParser.cpp b/gui/virtualKeyboardParser.cpp
index 93b670e7c9..5d8a28e7e9 100644
--- a/gui/virtualKeyboardParser.cpp
+++ b/gui/virtualKeyboardParser.cpp
@@ -130,8 +130,8 @@ bool VirtualKeyboardParser::parserCallback_Mode() {
if (resX == scrX && resY == scrY) {
_mode->resolution = res;
break;
- } else if (resX < scrX && resY < scrY) {
- uint16 newDiff = (scrX - resX) + (scrY - resY);
+ } else {
+ uint16 newDiff = ABS(scrX - resX) + ABS(scrY - resY);
if (newDiff < diff) {
diff = newDiff;
_mode->resolution = res;