// Copyright (C) 2002-2006 Nikolaus Gebhardt // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h #pragma once #pragma unmanaged #include "..\\..\\include\\irrlicht.h" #pragma managed #using using namespace System; #include "IGUIElement.h" #include "Position2D.h" #include "KeyCodes.h" namespace Irrlicht { /// /// An enum for all event types /// __value public enum EventType { /// An event of the graphical user interface. GUIEvent = 0, /// A mouse input event. MouseInput, //! A key input evant. KeyInput, //! A log event LogText }; namespace GUI { /// //! Enumeration for all events which are sendable by the gui system /// __value public enum GUIEvent { //! A gui element has lost its focus. ELEMENT_FOCUS_LOST = 0, //! A gui element has got the focus. ELEMENT_FOCUSED, //! A gui element was hovered. ELEMENT_HOVERED, //! A hovered gui element was left ELEMENT_LEFT, //! A button was clicked. BUTTON_CLICKED, //! A scrollbar has changed its position. SCROLL_BAR_CHANGED, //! A checkbox has changed its check state. CHECKBOX_CHANGED, //! A new item in a listbox was seleted. LISTBOX_CHANGED, //! An item in the listbox was selected, which was already selected. LISTBOX_SELECTED_AGAIN, //! A file has been selected in the file open dialog FILE_SELECTED, //! A file open dialog has been closed without choosing a file FILE_CHOOSE_DIALOG_CANCELLED, //! 'Yes' was clicked on a messagebox MESSAGEBOX_YES, //! 'No' was clicked on a messagebox MESSAGEBOX_NO, //! 'OK' was clicked on a messagebox MESSAGEBOX_OK, //! 'Cancel' was clicked on a messagebox MESSAGEBOX_CANCEL, //! In an editbox was pressed 'ENTER' EDITBOX_ENTER, //! The tab was changed in an tab control TAB_CHANGED, //! A menu item was selected in a (context) menu MENU_ITEM_SELECTED, //! The selection in a combo box has been changed COMBO_BOX_CHANGED }; }// end namespace GUI //! Enumeration for all mouse input events __value public enum MouseInputEvent { /// Left mouse button was pressed down. PressedDownLeft = 0, /// Right mouse button was pressed down. PressedDownRight, /// Middle mouse button was pressed down. PressedDownMiddle, /// Left mouse button was left up. LeftUpLeft, /// Right mouse button was left up. LeftUpRight, /// Middle mouse button was left up. LeftUpMiddle, /// The mouse cursor changed its position. MouseMoved, /// The mouse wheel was moved. Use Wheel value in event data to find out /// in what direction and how fast. MouseWheel }; /// /// Struct for holding event data. An event can be a gui, mouse or keyboard event. /// Use the Type property to find out what type of event this is. /// Please note that the properties of this class are not typesafe, for example if you read /// the MouseInputEvent property although the event type is KeyInput, the result /// will be undefined. /// This may look a little bit strange, but this interface was created in /// this way to reflect the original C++ Irrlicht interface and to increase speed. /// public __value class Event { public: /// /// Constructs a Irrlicht.NET event from a native C++ Irrlicht event. /// Event(irr::SEvent e) : NativeEvent(e) { } /// /// Returns type of event. Based of this type, you can call further methods to /// find out more about that event. For example if it was a mouse input event /// (MouseInput), use the MouseInputType property. /// Please note that this system is not very typesafe, for example if you read /// the MouseInputEvent property although the event type is KeyInput, the result /// will be undefined. /// This may look a little bit strange, but this interface was created in /// this way to reflect the original C++ Irrlicht interface and to increase speed. /// __property EventType get_Type() { return (EventType)NativeEvent.EventType; } /// /// Returns type of mouse event, if Type of this event is MouseInput, otherwise undefined. /// __property MouseInputEvent get_MouseInputType() { return (MouseInputEvent)NativeEvent.MouseInput.Event; } /// /// Returns mouse wheel delta, usually 1.0 or -1.0. Only valid if // Type of this event is MouseInput and MouseInputType is /// MouseWheel, otherwise undefined. /// __property float get_MouseWheelDelta() { return NativeEvent.MouseInput.Wheel; } /// /// Returns position of mouse. Only valid if Type of this event is MouseInput, /// otherwise undefined. /// __property Core::Position2D get_MousePos() { return Core::Position2D(NativeEvent.MouseInput.X, NativeEvent.MouseInput.Y); } /// /// Returns character corresponding to the key (0, if not a character). /// Only valid if Type of this event is KeyInput, otherwise undefined. /// __property __wchar_t get_KeyCharacter() { return NativeEvent.KeyInput.Char; } /// /// Returns key code of the pressed key. /// Only valid if Type of this event is KeyInput, otherwise undefined. /// __property KeyCode get_Key() { return (KeyCode)NativeEvent.KeyInput.Key; } /// /// Returns true if the key was pressed down, and false if it was left up. /// Only valid if Type of this event is KeyInput, otherwise undefined. /// __property bool get_KeyPressedDown() { return (bool)NativeEvent.KeyInput.PressedDown; } /// /// Returns true if shift was pressed also. /// Only valid if Type of this event is KeyInput, otherwise undefined. /// __property bool get_KeyShift() { return (bool)NativeEvent.KeyInput.Shift; } /// /// Returns true if control was pressed also. /// Only valid if Type of this event is KeyInput, otherwise undefined. /// __property bool get_KeyControl() { return (bool)NativeEvent.KeyInput.Control; } /// /// Returns the text if this was a log event. /// Only valid if Type of this event is LogText, otherwise undefined. /// __property System::String* get_LogText() { // for this, we'll add a type check at least. if (NativeEvent.EventType != irr::EET_LOG_TEXT_EVENT) throw new System::Exception("Irrlicht Event problem: The event is not a log text, but you're trying to get the log text. Don't do that."); return new System::String(NativeEvent.LogEvent.Text); } /// /// Returns the text if this was a log event. /// Only valid if Type of this event is GUIEvent, otherwise undefined. /// __property GUI::GUIEvent get_GUIEventType() { return (GUI::GUIEvent)NativeEvent.GUIEvent.EventType; } /// /// Returns caller of a gui event. /// Only valid if Type of this event is GUIEvent, otherwise undefined. /// __property GUI::IGUIElement* get_GUIEventCaller(); protected: irr::SEvent NativeEvent; }; /// /// Interface of an object wich can receive events. /// public __gc __interface IEventReceiver { /// /// called if an event happened. Should return true if event was processed /// bool OnEvent(Event e); }; }