📄 wg_message.h
字号:
// wg_message.h//// CMessage interface////// Copyright (c) 2002 Rob Wiskow// rob-dev@boxedchaos.com//// This library 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//#ifndef _WG_MESSAGE_H_#define _WG_MESSAGE_H_#include "wg_point.h"#include "wg_rect.h"#include "SDL.h"#include <string>namespace wGui{// Forward declarationsclass CMessageClient;//! The base message class//! wGui uses Message object to inform other objects of events.//! \sa CMessageServer CMessageClientclass CMessage{public: //! The various message types enum EMessageType { UNKNOWN = 0, //!< An unknown message, this is not a valid type KEYBOARD_KEYDOWN, //!< CKeyboardMessage generated when a keyboard key is pressed KEYBOARD_KEYUP, //!< CKeyboardMessage generated when a keyboard key is released MOUSE_BUTTONDOWN, //!< CMouseMessage generated when a mouse button is pressed MOUSE_BUTTONUP, //!< CMouseMessage generated when a mouse button is released MOUSE_MOVE, //!< CMouseMessage generated when a mouse is moved CTRL_LCLICK, //!< TIntMessage generated when a control is clicked on with the left mouse button CTRL_RCLICK, //!< TIntMessage generated when a control is clicked on with the right mouse button CTRL_MCLICK, //!< TIntMessage generated when a control is clicked on with the middle mouse button CTRL_VALUECHANGE, //!< CValueMessage generated when a control's text or value is changed via user input CTRL_VALUECHANGING, //!< CValueMessage generated when a control's text or value is in the process of changing via user input CTRL_RESIZE, //!< TPointMessage used to tell the app that the view has been resized CTRL_TIMER, //!< TIntMessage used to tell when a timer has expired, where Value() is the count of times fired APP_PAINT, //!< CMessage used to tell controls or windows to redraw themselves APP_EXIT, //!< CMessage used to tell controls or windows that the application is closing USER //!< Any user defined messages of type CUserMessage }; //! Construct a new message //! \param MessageType The type of message being created //! \param pDestination A pointer to the window that the message is destined for (0 for no specific destination, or to broadcast to all) //! \param pSource A pointer to the source of the message CMessage(const EMessageType MessageType, const CMessageClient* pDestination, const CMessageClient* pSource); //! Standard destructor virtual ~CMessage(void) { } //! \return The message type of the message const EMessageType MessageType(void) { return m_MessageType; } //! \return A pointer to the destination of the message (0 for no specific destination, or to broadcast to all) const CMessageClient* Destination(void) { return m_pDestination; } //! \return A pointer to the source of the message const CMessageClient* Source(void) { return m_pSource; }protected: //! The message type const EMessageType m_MessageType; //! A pointer to the message destination (0 for no specific destination, or to broadcast to all) const CMessageClient* m_pDestination; //! A pointer to the control that generated the message const CMessageClient* m_pSource;private: void operator=(CMessage) { } //!< The assignment operator is not allowed for CMessage objects};//! Any messages generated from keyboard inputclass CKeyboardMessage : public CMessage{public: //! Construct a new Keyboard message //! \param MessageType The type of message being created //! \param pDestination A pointer to the window that the message is destined for (0 for no specific destination, or to broadcast to all) //! \param pSource A pointer to the window that created the message //! \param ScanCode The scan code of the key pressed //! \param Modifiers Any modifier keys that are being pressed (alt, ctrl, shift, etc) //! \param Key The SDLKey that defines the key pressed //! \param Unicode The unicode character the keypress corresponds to CKeyboardMessage(const EMessageType MessageType, const CMessageClient* pDestination, const CMessageClient* pSource, unsigned char ScanCode, SDLMod Modifiers, SDLKey Key, Uint16 Unicode); unsigned char ScanCode; //!< \param ScanCode The scan code of the key pressed SDLMod Modifiers; //!< \param Modifiers Any modifier keys that are being pressed (alt, ctrl, shift, etc) SDLKey Key; //!< \param Key The SDLKey that defines the key pressed Uint16 Unicode; //!< The unicode character the keypress corresponds to};//! Any messages generated from mouse inputclass CMouseMessage : public CMessage{public: //! Constants for all the mouse buttons, these values can be ORed together for more than one button enum EMouseButton { NONE = 0, //!< No mouse button LEFT = 1, //!< The left mouse button RIGHT = 2, //!< The right mouse button MIDDLE = 4, //!< The middle mouse button WHEELUP = 8, //!< The mouse wheel moved up WHEELDOWN = 16 //!< The mouse wheel moved down }; //! Construct a new mouse message //! \param MessageType The type of message being created //! \param pDestination A pointer to the window that the message is destined for (0 for no specific destination, or to broadcast to all) //! \param pSource A pointer to the window that created the message //! \param Point The location of the mouse cursor //! \param Relative The relative movement of the cursor (only valid for MOUSE_MOVE messages) //! \param Button An OR of all the EMouseButton values indicating which mouse buttons are pressed CMouseMessage(const EMessageType MessageType, const CMessageClient* pDestination, const CMessageClient* pSource, CPoint Point, CPoint Relative, unsigned int Button); //! Converst an SDLButton value into an EMouseButton value static unsigned int TranslateSDLButton(Uint8 SDLButton); //! Converts an SDLButtonState value into an ORing of EMouseButton values static unsigned int TranslateSDLButtonState(Uint8 SDLButtonState); CPoint Point; //!< The point where the mouse cursor was at the time of the message CPoint Relative; //!< The relative movement of the cursor (only valid for MOUSE_MOVE messages) unsigned int Button; //!< Any mouse buttons pressed};//! A template for messages that contain values//! Type T must have a valid copy constructor and assignment operatortemplate<typename T>class CValueMessage : public CMessage{public: //! Construct a new template based Value message //! \param MessageType The type of message being created //! \param pDestination A pointer to the window that the message is destined for (0 for no specific destination, or to broadcast to all) //! \param pSource A pointer to the control that triggered the message //! \param Value A template type data the user has CValueMessage(const EMessageType MessageType, const CMessageClient* pDestination, const CMessageClient* pSource, const T& Value ) : CMessage(MessageType, pDestination, pSource), m_Value(Value) { } //! Returns the value of the message //! \return A constant reference to the internal value const T& Value(void) { return m_Value; } //! Sets the value of the message //! \param Value The value void SetValue(const T& Value) { m_Value = Value; }protected: //! The internal value T m_Value;};//! Some predefined value messagestypedef CValueMessage<int> TIntMessage;typedef CValueMessage<float> TFloatMessage;typedef CValueMessage<std::string> TStringMessage;typedef CValueMessage<CPoint> TPointMessage;typedef CValueMessage<CRect> TRectMessage;}#endif // _WG_MESSAGE_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -