mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-24 11:36:22 +00:00
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
This commit is contained in:
parent
950b68be7b
commit
98f999f8e0
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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__)
|
||||
|
@ -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() {
|
||||
|
||||
while (_displaying) {
|
||||
|
||||
}
|
||||
void VirtualKeyboard::hide() {
|
||||
_displaying = false;
|
||||
}
|
||||
|
||||
void VirtualKeyboard::draw() {
|
||||
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::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
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user