diff options
author | Max Horn | 2007-03-17 00:07:34 +0000 |
---|---|---|
committer | Max Horn | 2007-03-17 00:07:34 +0000 |
commit | 8fc8c4847df493de85736447c1c8d9528a9b1299 (patch) | |
tree | 597b3d3da0b249ff9dc9ecd510b79a69592c87f0 /common | |
parent | 4951f82c65d31e1f62041c9c07cf74181c035ce7 (diff) | |
download | scummvm-rg350-8fc8c4847df493de85736447c1c8d9528a9b1299.tar.gz scummvm-rg350-8fc8c4847df493de85736447c1c8d9528a9b1299.tar.bz2 scummvm-rg350-8fc8c4847df493de85736447c1c8d9528a9b1299.zip |
Implemented a simple EventManager class
svn-id: r26154
Diffstat (limited to 'common')
-rw-r--r-- | common/events.h | 84 | ||||
-rw-r--r-- | common/system.cpp | 19 | ||||
-rw-r--r-- | common/system.h | 23 |
3 files changed, 120 insertions, 6 deletions
diff --git a/common/events.h b/common/events.h new file mode 100644 index 0000000000..443903896e --- /dev/null +++ b/common/events.h @@ -0,0 +1,84 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2002-2007 The ScummVM project + * + * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef COMMON_EVENTS_H +#define COMMON_EVENTS_H + +#include "common/rect.h" +#include "common/system.h" + +namespace Common { + +/** + * The EventManager provides user input events to the client code. + * In addition, it keeps track of the state of various input devices, + * like keys, mouse position and buttons. + */ +class EventManager { +public: + EventManager() {} + virtual ~EventManager() {} + + enum { + LBUTTON = 1 << 0, + RBUTTON = 1 << 1 + }; + + /** + * Get the next 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. + */ + virtual bool pollEvent(OSystem::Event &event) = 0; + + + /** Return the current key state */ + virtual Common::Point getMousePos() const = 0; + + /** + * Return a bitmask with the button states: + * - bit 0: left button up=1, down=0 + * - bit 1: right button up=1, down=0 + */ + virtual int getButtonState() const = 0; + + /** Get a bitmask with the current modifier state */ + virtual int getModifierState() const = 0; + + /** + * Should the application terminate? Set to true if we + * received an EVENT_QUIT. + */ + virtual int shouldQuit() const = 0; + + // Optional: check whether a given key is currently pressed ???? + //virtual bool isKeyPressed(int keycode) = 0; + + // TODO: Keyboard repeat support? + + // TODO: Consider removing OSystem::getScreenChangeID and + // replacing it by a generic getScreenChangeID method here +}; + +} + +#endif diff --git a/common/system.cpp b/common/system.cpp index 7231338a85..17ecb3f124 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -24,6 +24,7 @@ #include "common/stdafx.h" #include "backends/intern.h" +#include "backends/events/default/default-events.h" #include "gui/message.h" @@ -36,6 +37,12 @@ OSystem *g_system = 0; +OSystem::OSystem() { +} + +OSystem::~OSystem() { +} + bool OSystem::setGraphicsMode(const char *name) { if (!name) return false; @@ -80,3 +87,15 @@ void OSystem::stopCD() { void OSystem::updateCD() { } + +static Common::EventManager *s_eventManager = 0; + +Common::EventManager *OSystem::getEventManager() { + // FIXME/TODO: Eventually this method should be turned into an abstract one, + // to force backends to implement this conciously (even if they + // end up returning the default event manager anyway). + if (!s_eventManager) + s_eventManager = new DefaultEventManager(this); + return s_eventManager; +} + diff --git a/common/system.h b/common/system.h index bd0caf4575..a8aa1198bd 100644 --- a/common/system.h +++ b/common/system.h @@ -1,6 +1,6 @@ /* ScummVM - Scumm Interpreter * Copyright (C) 2001 Ludvig Strigeus - * Copyright (C) 2001-2006 The ScummVM project + * Copyright (C) 2001-2007 The ScummVM project * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -37,6 +37,7 @@ namespace Graphics { } namespace Common { + class EventManager; class SaveFileManager; class TimerManager; } @@ -58,8 +59,8 @@ private: OSystem& operator= (const OSystem&); protected: - OSystem() { } - virtual ~OSystem() { } + OSystem(); + virtual ~OSystem(); public: @@ -68,7 +69,7 @@ public: * config data (including command line params etc.) are fully loaded. * * @note Subclasses should always invoke the implementation of their - * parent class. They should so so near the end of their own + * parent class. They should do so near the end of their own * implementation. */ virtual void initBackend() { } @@ -679,6 +680,9 @@ public: /** @name Events and Time */ //@{ +//protected: + friend class Common::EventManager; + /** * The types of events backends may generate. * @see Event @@ -793,6 +797,7 @@ public: */ virtual bool pollEvent(Event &event) = 0; +public: /** Get the number of milliseconds since the program was started. */ virtual uint32 getMillis() = 0; @@ -800,11 +805,17 @@ public: virtual void delayMillis(uint msecs) = 0; /** - * Returh the timer manager. For more information, refer to the - * TimerManager documentation. + * Return the timer manager singleton. For more information, refer + * to the TimerManager documentation. */ virtual Common::TimerManager *getTimerManager() = 0; + /** + * Return the event manager singleton. For more information, refer + * to the EventManager documentation. + */ + virtual Common::EventManager *getEventManager(); + //@} |