105 lines
3.7 KiB
C++
105 lines
3.7 KiB
C++
// Filename: buttonEvent.h
|
|
// Created by: drose (01Mar00)
|
|
//
|
|
////////////////////////////////////////////////////////////////////
|
|
//
|
|
// PANDA 3D SOFTWARE
|
|
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
|
|
//
|
|
// All use of this software is subject to the terms of the Panda 3d
|
|
// Software license. You should have received a copy of this license
|
|
// along with this source code; you will also find a current copy of
|
|
// the license at http://www.panda3d.org/license.txt .
|
|
//
|
|
// To contact the maintainers of this program write to
|
|
// panda3d@yahoogroups.com .
|
|
//
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef BUTTONEVENT_H
|
|
#define BUTTONEVENT_H
|
|
|
|
#include "pandabase.h"
|
|
|
|
#include "buttonHandle.h"
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
// Class : ButtonEvent
|
|
// Description : Records a button event of some kind. This is either
|
|
// a keyboard or mouse button (or some other kind of
|
|
// button) changing state from up to down, or
|
|
// vice-versa, or it is a single "keystroke".
|
|
//
|
|
// A keystroke is different than a button event in that
|
|
// (a) it does not necessarily correspond to a physical
|
|
// button on a keyboard, but might be the result of a
|
|
// combination of buttons (e.g. "A" is the result of
|
|
// shift + "a"); and (b) it does not manage separate
|
|
// "up" and "down" events, but is itself an
|
|
// instantaneous event.
|
|
//
|
|
// Normal up/down button events can be used to track the
|
|
// state of a particular button on the keyboard, while
|
|
// keystroke events are best used to monitor what a user
|
|
// is attempting to type.
|
|
//
|
|
// Button up/down events are defined across all the
|
|
// physical keys on the keyboard (and other buttons for
|
|
// which there is a corresponding ButtonHandle object),
|
|
// while keystroke events are defined across the entire
|
|
// Unicode character set.
|
|
////////////////////////////////////////////////////////////////////
|
|
class EXPCL_PANDA ButtonEvent {
|
|
public:
|
|
enum Type {
|
|
// T_down and T_up represent a button changing state
|
|
// correspondingly. T_resume_down is a special event that is only
|
|
// thrown when focus is returned to a window and a button is
|
|
// detected as being held down at that point; it indicates that
|
|
// the button should be considered down now (if it wasn't
|
|
// already), but it didn't just get pressed down at this moment,
|
|
// it was depressed some time ago. It's mainly used for correct
|
|
// tracking of modifier keys like shift and control, and can be
|
|
// ignored for other keys.
|
|
T_down,
|
|
T_resume_down,
|
|
T_up,
|
|
|
|
// T_keystroke is a special keystroke event, and is sent along
|
|
// with a Unicode keycode value, not a ButtonHandle.
|
|
T_keystroke
|
|
};
|
|
|
|
INLINE ButtonEvent();
|
|
INLINE ButtonEvent(ButtonHandle button, Type type);
|
|
INLINE ButtonEvent(short keycode);
|
|
INLINE ButtonEvent(const ButtonEvent ©);
|
|
INLINE void operator = (const ButtonEvent ©);
|
|
|
|
INLINE bool operator == (const ButtonEvent &other) const;
|
|
INLINE bool operator != (const ButtonEvent &other) const;
|
|
INLINE bool operator < (const ButtonEvent &other) const;
|
|
|
|
void output(ostream &out) const;
|
|
|
|
// _button will be filled in if type is T_down, T_resume_down, or
|
|
// T_up.
|
|
ButtonHandle _button;
|
|
|
|
// _keycode will be filled in if type is T_keystroke. It will be
|
|
// the Unicode character that was typed.
|
|
short _keycode;
|
|
|
|
Type _type;
|
|
};
|
|
|
|
INLINE ostream &operator << (ostream &out, const ButtonEvent &be) {
|
|
be.output(out);
|
|
return out;
|
|
}
|
|
|
|
#include "buttonEvent.I"
|
|
|
|
#endif
|
|
|