view engine/core/eventchannel/mouse/ec_mouseevent.h @ 695:47d58c7a95d7

Fixed a bug in VFSDirectory that prevented absolute paths from being resolved. * Modified the VFSDirectory constructor so that it now adds the drive root as the VFS root by default, instead of the current working directory. * Added the current working directory to the VFS in Engine::preInit in addition to the default drive root. * Reverted a change to EventManager::processMouseEvent which prevents GUIChan from grabbing mouse input. The fact that GUIChan grabs all mouse input will need to be addressed once the GUI code is modularized.
author M. George Hansen <technopolitica@gmail.com>
date Fri, 10 Jun 2011 23:36:14 -1000
parents 010da1d1ee1c
children
line wrap: on
line source

/***************************************************************************
 *   Copyright (C) 2005-2008 by the FIFE team                              *
 *   http://www.fifengine.de                                               *
 *   This file is part of FIFE.                                            *
 *                                                                         *
 *   FIFE is free software; you can redistribute it and/or                 *
 *   modify it under the terms of the GNU Lesser General Public            *
 *   License as published by the Free Software Foundation; either          *
 *   version 2.1 of the License, or (at your option) any later version.    *
 *                                                                         *
 *   This library 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     *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU Lesser General Public      *
 *   License along with this library; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

#ifndef FIFE_EVENTCHANNEL_MOUSEEVENT_H
#define FIFE_EVENTCHANNEL_MOUSEEVENT_H

// Standard C++ library includes
//

// 3rd party library includes
//

// FIFE includes
// These includes are split up in two parts, separated by one empty line
// First block: files included from the FIFE root src directory
// Second block: files included from the same folder
//
#include "eventchannel/base/ec_inputevent.h"

namespace FIFE {

	/**  Class for mouse events
	 */
	class MouseEvent: public InputEvent {
	public:
		/**
		 * Mouse event types.
		 */
		enum MouseEventType
		{
			UNKNOWN_EVENT = -1,
			MOVED = 0,
			PRESSED,
			RELEASED,
			WHEEL_MOVED_DOWN,
			WHEEL_MOVED_UP,
			CLICKED,
			ENTERED,
			EXITED,
			DRAGGED
		};

		/**
		 * Mouse button types.
		 */
		enum MouseButtonType
		{
			EMPTY = 0,
			LEFT = 1,
			RIGHT = 2,
			MIDDLE = 4,
			UNKNOWN_BUTTON = 8
		};


		/** Constructor.
		*/
		MouseEvent():
			InputEvent(),
			m_eventtype(UNKNOWN_EVENT),
			m_buttontype(UNKNOWN_BUTTON),
			m_x(-1),
			m_y(-1) {}

		/** Destructor.
		*/
		virtual ~MouseEvent() {}

		/**
		 * Gets the button of the mouse event.
		 * @return the button of the mouse event.
		 */
		MouseButtonType getButton() const { return m_buttontype; }
		void setButton(MouseButtonType type) { m_buttontype = type; }

		/**
		 * Gets the type of the event.
		 * @return the type of the event.
		 */
		MouseEventType getType() const { return m_eventtype; }
		void setType(MouseEventType type) { m_eventtype = type; }

		/**
		 * Gets the x coordinate of the mouse event. The coordinate is relative to
		 * the source event source.
		 * @return the x coordinate of the mouse event.
		 */
		int getX() const { return m_x; }
		void setX(int x) { m_x = x; }

		/**
		 * Gets the y coordinate of the mouse event. The coordinate is relative to
		 * the source event source.
		 * @return the y coordinate of the mouse event.
		 */
		int getY() const { return m_y; }
		void setY(int y) { m_y = y; }

		virtual bool isAltPressed() const { return InputEvent::isAltPressed(); }
		virtual void setAltPressed(bool pressed) { InputEvent::setAltPressed(pressed); }
		virtual bool isControlPressed() const { return InputEvent::isControlPressed(); }
		virtual void setControlPressed(bool pressed) { InputEvent::setControlPressed(pressed); }
		virtual bool isMetaPressed() const { return InputEvent::isMetaPressed(); }
		virtual void setMetaPressed(bool pressed) { InputEvent::setMetaPressed(pressed); }
		virtual bool isShiftPressed() const { return InputEvent::isShiftPressed(); }
		virtual void setShiftPressed(bool pressed) { InputEvent::setShiftPressed(pressed); }

		virtual void consume() { InputEvent::consume(); }
		virtual bool isConsumed() const { return InputEvent::isConsumed(); }
		virtual void consumedByWidgets() { InputEvent::consumedByWidgets(); }
		virtual bool isConsumedByWidgets() const { return InputEvent::isConsumedByWidgets(); }
		virtual IEventSource* getSource() { return InputEvent::getSource(); }
		virtual void setSource(IEventSource* source) { InputEvent::setSource(source); }
		virtual int getTimeStamp() const { return InputEvent::getTimeStamp(); }
		virtual void setTimeStamp(int timestamp ) { InputEvent::setTimeStamp(timestamp); }

		virtual const std::string& getName() const {
			const static std::string eventName("MouseEvent");
			return eventName;
		}
		virtual std::string getDebugString() const { return InputEvent::getDebugString(); }
		virtual std::string getAttrStr() const {
			std::stringstream ss;
			ss << InputEvent::getAttrStr() << std::endl;
			ss << "event = " << mouseEventType2str(m_eventtype) << ", ";
			ss << "button = " << mouseButtonType2str(m_buttontype) << ", ";
			ss << "x = " << m_x << ", ";
			ss << "y = " << m_y;
			return  ss.str();
		}

		/** Returns string representation of given event type
		*/
		inline static std::string mouseEventType2str(MouseEventType t)  {
			std::string s("unknown");
			switch (t) {
				case MouseEvent::MOVED:
					s = "moved";
					break;
				case MouseEvent::PRESSED:
					s = "pressed";
					break;
				case MouseEvent::RELEASED:
					s = "released";
					break;
				case MouseEvent::WHEEL_MOVED_DOWN:
					s = "wheel_moved_down";
					break;
				case MouseEvent::WHEEL_MOVED_UP:
					s = "wheel_moved_up";
					break;
				case MouseEvent::CLICKED:
					s = "clicked";
					break;
				case MouseEvent::ENTERED:
					s = "entered";
					break;
				case MouseEvent::EXITED:
					s = "excited";
					break;
				case MouseEvent::DRAGGED:
					s = "dragged";
					break;
				default:
					break;
			}
			return s;
		}

		/** Returns string representation of given button type
		*/
		inline static std::string mouseButtonType2str(MouseButtonType t) {
			std::string s("unknown");
			switch (t) {
				case MouseEvent::EMPTY:
					s = "empty";
					break;
				case MouseEvent::LEFT:
					s = "left";
					break;
				case MouseEvent::RIGHT:
					s = "right";
					break;
				case MouseEvent::MIDDLE:
					s = "middle";
					break;
				default:
					break;
			}
			return s;
		}



	private:
		MouseEventType m_eventtype;
		MouseButtonType m_buttontype;
		int m_x;
 		int m_y;

	};

} //FIFE

#endif