[Scummvm-cvs-logs] SF.net SVN: scummvm: [26154] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Mar 17 01:07:35 CET 2007


Revision: 26154
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26154&view=rev
Author:   fingolfin
Date:     2007-03-16 17:07:34 -0700 (Fri, 16 Mar 2007)

Log Message:
-----------
Implemented a simple EventManager class

Modified Paths:
--------------
    scummvm/trunk/backends/module.mk
    scummvm/trunk/common/system.cpp
    scummvm/trunk/common/system.h

Added Paths:
-----------
    scummvm/trunk/backends/events/
    scummvm/trunk/backends/events/default/
    scummvm/trunk/backends/events/default/default-events.cpp
    scummvm/trunk/backends/events/default/default-events.h
    scummvm/trunk/common/events.h


Property changes on: scummvm/trunk/backends/events
___________________________________________________________________
Name: svn:ignore
   + .deps
*.o
lib*.a



Property changes on: scummvm/trunk/backends/events/default
___________________________________________________________________
Name: svn:ignore
   + .deps
*.o
lib*.a


Added: scummvm/trunk/backends/events/default/default-events.cpp
===================================================================
--- scummvm/trunk/backends/events/default/default-events.cpp	                        (rev 0)
+++ scummvm/trunk/backends/events/default/default-events.cpp	2007-03-17 00:07:34 UTC (rev 26154)
@@ -0,0 +1,87 @@
+/* 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$
+ *
+ */
+
+#if !defined(DISABLE_DEFAULT_EVENTMANAGER)
+
+#include "common/stdafx.h"
+#include "common/system.h"
+#include "backends/events/default/default-events.h"
+
+DefaultEventManager::DefaultEventManager(OSystem *boss) :
+	_boss(boss),
+	_buttonState(0),
+	_modifierState(0),
+	_shouldQuit(false) {
+
+ 	assert(_boss);
+}
+
+DefaultEventManager::~DefaultEventManager() {
+
+}
+
+bool DefaultEventManager::pollEvent(OSystem::Event &event) {
+	bool result;
+	
+	result = _boss->pollEvent(event);
+	
+	if (result) {
+		switch (event.type) {
+		case OSystem::EVENT_KEYDOWN:
+		case OSystem::EVENT_KEYUP:
+			_modifierState = event.kbd.flags;
+			break;
+		case OSystem::EVENT_MOUSEMOVE:
+			_mousePos = event.mouse;
+			break;
+
+		case OSystem::EVENT_LBUTTONDOWN:
+			_mousePos = event.mouse;
+			_buttonState |= LBUTTON;
+			break;
+		case OSystem::EVENT_LBUTTONUP:
+			_mousePos = event.mouse;
+			_buttonState &= ~LBUTTON;
+			break;
+
+		case OSystem::EVENT_RBUTTONDOWN:
+			_mousePos = event.mouse;
+			_buttonState |= RBUTTON;
+			break;
+		case OSystem::EVENT_RBUTTONUP:
+			_mousePos = event.mouse;
+			_buttonState &= ~RBUTTON;
+			break;
+
+		case OSystem::EVENT_QUIT:
+			_shouldQuit = true;
+			break;
+
+		default:
+			break;
+		}
+	}
+	
+	return result;
+}
+
+#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)


Property changes on: scummvm/trunk/backends/events/default/default-events.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: scummvm/trunk/backends/events/default/default-events.h
===================================================================
--- scummvm/trunk/backends/events/default/default-events.h	                        (rev 0)
+++ scummvm/trunk/backends/events/default/default-events.h	2007-03-17 00:07:34 UTC (rev 26154)
@@ -0,0 +1,61 @@
+/* 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$
+ *
+ */
+
+#if !defined(BACKEND_SAVES_DEFAULT_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER)
+#define BACKEND_SAVES_DEFAULT_H
+
+#include "common/stdafx.h"
+#include "common/events.h"
+
+/*
+At some point we will remove pollEvent from OSystem and change
+DefaultEventManager to use a "boss" derived from this class:
+class EventProvider {
+public
+	virtual bool pollEvent(Common::Event &event) = 0;
+};
+
+Backends which wish to use the DefaultEventManager then simply can
+use a subclass of EventProvider.
+*/
+
+class DefaultEventManager : public Common::EventManager {
+	OSystem *_boss;
+
+	Common::Point _mousePos;
+	int _buttonState;
+	int _modifierState;
+	bool _shouldQuit;
+
+public:
+	DefaultEventManager(OSystem *boss);
+	~DefaultEventManager();
+
+	virtual bool pollEvent(OSystem::Event &event);
+
+	virtual Common::Point getMousePos() const { return _mousePos; }
+	virtual int getButtonState() const { return _buttonState; }
+	virtual int getModifierState() const { return _modifierState; }
+	virtual int shouldQuit() const { return _shouldQuit; }
+};
+
+#endif


Property changes on: scummvm/trunk/backends/events/default/default-events.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Modified: scummvm/trunk/backends/module.mk
===================================================================
--- scummvm/trunk/backends/module.mk	2007-03-16 23:08:59 UTC (rev 26153)
+++ scummvm/trunk/backends/module.mk	2007-03-17 00:07:34 UTC (rev 26154)
@@ -1,6 +1,7 @@
 MODULE := backends
 
 MODULE_OBJS := \
+	events/default/default-events.o \
 	fs/posix/posix-fs.o \
 	fs/morphos/abox-fs.o \
 	fs/windows/windows-fs.o \

Added: scummvm/trunk/common/events.h
===================================================================
--- scummvm/trunk/common/events.h	                        (rev 0)
+++ scummvm/trunk/common/events.h	2007-03-17 00:07:34 UTC (rev 26154)
@@ -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


Property changes on: scummvm/trunk/common/events.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Modified: scummvm/trunk/common/system.cpp
===================================================================
--- scummvm/trunk/common/system.cpp	2007-03-16 23:08:59 UTC (rev 26153)
+++ scummvm/trunk/common/system.cpp	2007-03-17 00:07:34 UTC (rev 26154)
@@ -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::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;
+}
+

Modified: scummvm/trunk/common/system.h
===================================================================
--- scummvm/trunk/common/system.h	2007-03-16 23:08:59 UTC (rev 26153)
+++ scummvm/trunk/common/system.h	2007-03-17 00:07:34 UTC (rev 26154)
@@ -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 Common {
+	class EventManager;
 	class SaveFileManager;
 	class TimerManager;
 }
@@ -58,8 +59,8 @@
 	OSystem& operator= (const OSystem&);
 
 protected:
-	OSystem() { }
-	virtual ~OSystem() { }
+	OSystem();
+	virtual ~OSystem();
 
 public:
 
@@ -68,7 +69,7 @@
 	 * 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 @@
 	/** @name Events and Time */
 	//@{
 
+//protected:
+	friend class Common::EventManager;
+
 	/**
 	 * The types of events backends may generate.
 	 * @see Event
@@ -793,6 +797,7 @@
 	 */
 	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 @@
 	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();
+
 	//@}
 
 


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