2007-05-30 21:56:52 +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.
|
2004-05-09 14:34:47 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-05-09 14:34:47 +00:00
|
|
|
*
|
2006-02-11 12:47:47 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-05-09 14:34:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2004-05-09 14:34:47 +00:00
|
|
|
#include "EventsBuffer.h"
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
namespace CEKEYS {
|
2004-05-09 14:34:47 +00:00
|
|
|
|
2005-07-05 20:27:14 +00:00
|
|
|
bool EventsBuffer::simulateKey(GUI::Key *key, bool pushed) {
|
2004-05-09 14:34:47 +00:00
|
|
|
SDL_Event ev = {0};
|
|
|
|
|
|
|
|
if (!key->keycode())
|
2007-06-23 00:05:32 +00:00
|
|
|
key->setKey(key->ascii(), key->ascii());
|
|
|
|
else if (!key->ascii())
|
|
|
|
key->setKey(key->keycode());
|
2004-05-09 14:34:47 +00:00
|
|
|
|
2005-01-28 23:45:53 +00:00
|
|
|
ev.type = (pushed ? SDL_KEYDOWN : SDL_KEYUP);
|
2004-05-09 14:34:47 +00:00
|
|
|
ev.key.keysym.mod = (SDLMod)key->flags();
|
|
|
|
ev.key.keysym.sym = (SDLKey)key->keycode();
|
|
|
|
ev.key.keysym.unicode = key->keycode();
|
2005-01-28 23:45:53 +00:00
|
|
|
ev.key.keysym.mod = KMOD_RESERVED;
|
2004-05-09 14:34:47 +00:00
|
|
|
return (SDL_PushEvent(&ev) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EventsBuffer::simulateMouseMove(int x, int y) {
|
|
|
|
SDL_Event ev = {0};
|
|
|
|
|
|
|
|
ev.type = SDL_MOUSEMOTION;
|
|
|
|
ev.motion.x = x;
|
|
|
|
ev.motion.y = y;
|
|
|
|
return (SDL_PushEvent(&ev) == 0);
|
|
|
|
}
|
|
|
|
|
2004-12-21 00:31:58 +00:00
|
|
|
bool EventsBuffer::simulateMouseLeftClick(int x, int y, bool pushed) {
|
2004-05-09 14:34:47 +00:00
|
|
|
SDL_Event ev = {0};
|
2006-10-21 11:12:46 +00:00
|
|
|
static bool state = false;
|
2004-05-09 14:34:47 +00:00
|
|
|
|
2006-10-21 11:12:46 +00:00
|
|
|
if (pushed == state) return 0;
|
|
|
|
state = pushed;
|
2004-12-21 00:31:58 +00:00
|
|
|
ev.type = (pushed ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP);
|
2004-05-09 14:34:47 +00:00
|
|
|
ev.button.button = SDL_BUTTON_LEFT;
|
|
|
|
ev.button.x = x;
|
|
|
|
ev.button.y = y;
|
|
|
|
return (SDL_PushEvent(&ev) == 0);
|
|
|
|
}
|
|
|
|
|
2004-12-21 00:31:58 +00:00
|
|
|
bool EventsBuffer::simulateMouseRightClick(int x, int y, bool pushed) {
|
2004-05-09 14:34:47 +00:00
|
|
|
SDL_Event ev = {0};
|
2006-10-21 11:12:46 +00:00
|
|
|
static bool state = false;
|
2004-05-09 14:34:47 +00:00
|
|
|
|
2006-10-21 11:12:46 +00:00
|
|
|
if (pushed == state) return 0;
|
|
|
|
state = pushed;
|
2004-12-21 00:31:58 +00:00
|
|
|
ev.type = (pushed ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP);
|
2004-05-09 14:34:47 +00:00
|
|
|
ev.button.button = SDL_BUTTON_RIGHT;
|
|
|
|
ev.button.x = x;
|
|
|
|
ev.button.y = y;
|
|
|
|
return (SDL_PushEvent(&ev) == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|