event: Expose ButtonEvent to Python

This commit is contained in:
rdb 2021-11-28 14:36:20 +01:00
parent 2abf867203
commit 980399d142
3 changed files with 49 additions and 1 deletions

View File

@ -149,3 +149,35 @@ update_mods(ModifierButtons &mods) const {
return false;
}
}
/**
*
*/
INLINE ButtonHandle ButtonEvent::
get_button() const {
return _button;
}
/**
*
*/
INLINE int ButtonEvent::
get_keycode() const {
return _keycode;
}
/**
*
*/
INLINE ButtonEvent::Type ButtonEvent::
get_type() const {
return _type;
}
/**
*
*/
INLINE double ButtonEvent::
get_time() const {
return _time;
}

View File

@ -44,7 +44,7 @@ class DatagramIterator;
* character set.
*/
class EXPCL_PANDA_EVENT ButtonEvent {
public:
PUBLISHED:
enum Type {
// T_down is sent when a button was just pressed.
T_down,
@ -85,6 +85,7 @@ public:
T_raw_up,
};
public:
INLINE ButtonEvent();
INLINE ButtonEvent(ButtonHandle button, Type type, double time = ClockObject::get_global_clock()->get_frame_time());
INLINE ButtonEvent(int keycode, double time = ClockObject::get_global_clock()->get_frame_time());
@ -93,17 +94,30 @@ public:
INLINE ButtonEvent(const ButtonEvent &copy);
INLINE void operator = (const ButtonEvent &copy);
PUBLISHED:
INLINE bool operator == (const ButtonEvent &other) const;
INLINE bool operator != (const ButtonEvent &other) const;
INLINE bool operator < (const ButtonEvent &other) const;
public:
INLINE bool update_mods(ModifierButtons &mods) const;
INLINE ButtonHandle get_button() const;
INLINE int get_keycode() const;
INLINE Type get_type() const;
INLINE double get_time() const;
void output(std::ostream &out) const;
void write_datagram(Datagram &dg) const;
void read_datagram(DatagramIterator &scan);
PUBLISHED:
MAKE_PROPERTY(button, get_button);
MAKE_PROPERTY(keycode, get_keycode);
MAKE_PROPERTY(type, get_type);
MAKE_PROPERTY(time, get_time);
public:
// _button will be filled in if type is T_down, T_resume_down, or T_up.
ButtonHandle _button;

View File

@ -47,6 +47,8 @@ PUBLISHED:
virtual void output(std::ostream &out) const;
void write(std::ostream &out, int indent_level = 0) const;
MAKE_SEQ_PROPERTY(events, get_num_events, get_event);
private:
typedef pvector<ButtonEvent> Events;
Events _events;