Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/putil/buttonEvent.h

Go to the documentation of this file.
00001 // Filename: buttonEvent.h
00002 // Created by:  drose (01Mar00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef BUTTONEVENT_H
00020 #define BUTTONEVENT_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "buttonHandle.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : ButtonEvent
00028 // Description : Records a button event of some kind.  This is either
00029 //               a keyboard or mouse button (or some other kind of
00030 //               button) changing state from up to down, or
00031 //               vice-versa, or it is a single "keystroke".
00032 //
00033 //               A keystroke is different than a button event in that
00034 //               (a) it does not necessarily correspond to a physical
00035 //               button on a keyboard, but might be the result of a
00036 //               combination of buttons (e.g. "A" is the result of
00037 //               shift + "a"); and (b) it does not manage separate
00038 //               "up" and "down" events, but is itself an
00039 //               instantaneous event.  
00040 //
00041 //               Normal up/down button events can be used to track the
00042 //               state of a particular button on the keyboard, while
00043 //               keystroke events are best used to monitor what a user
00044 //               is attempting to type.
00045 //
00046 //               Button up/down events are defined across all the
00047 //               physical keys on the keyboard (and other buttons for
00048 //               which there is a corresponding ButtonHandle object),
00049 //               while keystroke events are defined across the entire
00050 //               Unicode character set.
00051 ////////////////////////////////////////////////////////////////////
00052 class EXPCL_PANDA ButtonEvent {
00053 public:
00054   enum Type {
00055     // T_down and T_up represent a button changing state
00056     // correspondingly.  T_resume_down is a special event that is only
00057     // thrown when focus is returned to a window and a button is
00058     // detected as being held down at that point; it indicates that
00059     // the button should be considered down now (if it wasn't
00060     // already), but it didn't just get pressed down at this moment,
00061     // it was depressed some time ago.  It's mainly used for correct
00062     // tracking of modifier keys like shift and control, and can be
00063     // ignored for other keys.
00064     T_down,
00065     T_resume_down,
00066     T_up,
00067 
00068     // T_keystroke is a special keystroke event, and is sent along
00069     // with a Unicode keycode value, not a ButtonHandle.
00070     T_keystroke
00071   };
00072 
00073   INLINE ButtonEvent();
00074   INLINE ButtonEvent(ButtonHandle button, Type type);
00075   INLINE ButtonEvent(short keycode);
00076   INLINE ButtonEvent(const ButtonEvent &copy);
00077   INLINE void operator = (const ButtonEvent &copy);
00078 
00079   INLINE bool operator == (const ButtonEvent &other) const;
00080   INLINE bool operator != (const ButtonEvent &other) const;
00081   INLINE bool operator < (const ButtonEvent &other) const;
00082 
00083   void output(ostream &out) const;
00084 
00085   // _button will be filled in if type is T_down, T_resume_down, or
00086   // T_up.
00087   ButtonHandle _button;
00088 
00089   // _keycode will be filled in if type is T_keystroke.  It will be
00090   // the Unicode character that was typed.
00091   short _keycode;
00092 
00093   Type _type;
00094 };
00095 
00096 INLINE ostream &operator << (ostream &out, const ButtonEvent &be) {
00097   be.output(out);
00098   return out;
00099 }
00100 
00101 #include "buttonEvent.I"
00102 
00103 #endif
00104 

Generated on Fri May 2 00:43:32 2003 for Panda by doxygen1.3