[Scummvm-cvs-logs] SF.net SVN: scummvm: [32939] scummvm/branches/gsoc2008-vkeybd
sk4425 at users.sourceforge.net
sk4425 at users.sourceforge.net
Mon Jul 7 16:30:13 CEST 2008
Revision: 32939
http://scummvm.svn.sourceforge.net/scummvm/?rev=32939&view=rev
Author: sk4425
Date: 2008-07-07 07:30:11 -0700 (Mon, 07 Jul 2008)
Log Message:
-----------
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
Modified Paths:
--------------
scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp
scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.h
scummvm/branches/gsoc2008-vkeybd/base/main.cpp
scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboard.cpp
scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboard.h
scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboardParser.cpp
Modified: scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp 2008-07-07 13:01:54 UTC (rev 32938)
+++ scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp 2008-07-07 14:30:11 UTC (rev 32939)
@@ -191,6 +191,9 @@
_hasPlaybackEvent = false;
}
+
+ _vk = new GUI::VirtualKeyboard();
+ _vk->loadKeyboardPack("test");
}
DefaultEventManager::~DefaultEventManager() {
@@ -349,7 +352,10 @@
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 @@
_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;
Modified: scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.h 2008-07-07 13:01:54 UTC (rev 32938)
+++ scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.h 2008-07-07 14:30:11 UTC (rev 32939)
@@ -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 @@
class DefaultEventManager : public Common::EventManager {
OSystem *_boss;
+ GUI::VirtualKeyboard *_vk;
+
Common::Point _mousePos;
int _buttonState;
int _modifierState;
Modified: scummvm/branches/gsoc2008-vkeybd/base/main.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/base/main.cpp 2008-07-07 13:01:54 UTC (rev 32938)
+++ scummvm/branches/gsoc2008-vkeybd/base/main.cpp 2008-07-07 14:30:11 UTC (rev 32939)
@@ -52,13 +52,7 @@
#include "gui/launcher.h"
#endif
-#define ___VK_TEST
-#if defined(___VK_TEST)
-#include "gui/virtualKeyboard.h"
-#endif
-
-
static bool launcherDialog(OSystem &system) {
system.beginGFXTransaction();
@@ -74,13 +68,6 @@
// 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__)
Modified: scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboard.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboard.cpp 2008-07-07 13:01:54 UTC (rev 32938)
+++ scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboard.cpp 2008-07-07 14:30:11 UTC (rev 32939)
@@ -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 @@
_hAlignment = kAlignCentre;
_vAlignment = kAlignBottom;
_keyQueue.clear();
+ _keyDown = 0;
_displaying = false;
-
}
bool VirtualKeyboard::loadKeyboardPack(Common::String packName) {
@@ -115,8 +116,6 @@
}
}
- reposition();
-
return true;
}
@@ -175,29 +174,86 @@
}
}
+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::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
Modified: scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboard.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboard.h 2008-07-07 13:01:54 UTC (rev 32938)
+++ scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboard.h 2008-07-07 14:30:11 UTC (rev 32939)
@@ -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 VirtualKeyboard {
-private:
+
/** Type of key event */
enum EventType {
kEventKey,
@@ -90,7 +91,18 @@
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 @@
// 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 @@
HorizontalAlignment _hAlignment;
VerticalAlignment _vAlignment;
+ Common::Point _mouseDown;
+
Common::Array<Common::KeyState> _keyQueue;
+ Common::KeyState *_keyDown;
};
Modified: scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboardParser.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboardParser.cpp 2008-07-07 13:01:54 UTC (rev 32938)
+++ scummvm/branches/gsoc2008-vkeybd/gui/virtualKeyboardParser.cpp 2008-07-07 14:30:11 UTC (rev 32939)
@@ -130,8 +130,8 @@
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;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list