view engine/core/eventchannel/mouse/ec_mouseevent.h @ 697:ecaa4d98f05f tip

Abstracted the GUI code and refactored the GUIChan-specific code into its own module. * Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring. * GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass. * The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class. * The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged. * Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author M. George Hansen <technopolitica@gmail.com>
date Sat, 18 Jun 2011 00:28:40 -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