aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorStephen Kennedy2008-07-07 14:30:11 +0000
committerStephen Kennedy2008-07-07 14:30:11 +0000
commit98f999f8e01c4752a771f1a8c6aec77b6efe3fb5 (patch)
treeb56a61b845e25225491aea6a82180ae5903c32e4 /gui
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
Diffstat (limited to 'gui')
-rw-r--r--gui/virtualKeyboard.cpp74
-rw-r--r--gui/virtualKeyboard.h21
-rw-r--r--gui/virtualKeyboardParser.cpp4
3 files changed, 86 insertions, 13 deletions
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;