From 5550aaa1d71e7fcaa21363ef695dd49f747cfbfb Mon Sep 17 00:00:00 2001 From: John Loehrlein Date: Fri, 23 Jan 2009 01:51:48 +0000 Subject: [PATCH] hooks for binding a "cursormove" event when the cursor moves --- panda/src/pgui/pgEntry.I | 48 ++++++++++++++++++++++++++++++++++++++ panda/src/pgui/pgEntry.cxx | 15 ++++++++++++ panda/src/pgui/pgEntry.h | 7 ++++++ 3 files changed, 70 insertions(+) diff --git a/panda/src/pgui/pgEntry.I b/panda/src/pgui/pgEntry.I index a64ea8ba20..28e4dc5829 100644 --- a/panda/src/pgui/pgEntry.I +++ b/panda/src/pgui/pgEntry.I @@ -155,6 +155,31 @@ get_cursor_position() const { return _cursor_position; } +//////////////////////////////////////////////////////////////////// +// Function: PGEntry::get_cursor_X +// Access: Published +// Description: Returns the node position x of the cursor +//////////////////////////////////////////////////////////////////// + +INLINE float PGEntry:: +get_cursor_X() const { + LightReMutexHolder holder(_lock); + return _cursor_def.get_x(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PGEntry::get_cursor_y +// Access: Published +// Description: Returns the node position y of the cursor +//////////////////////////////////////////////////////////////////// + +INLINE float PGEntry:: +get_cursor_Y() const { + LightReMutexHolder holder(_lock); + return _cursor_def.get_y(); +} + + //////////////////////////////////////////////////////////////////// // Function: PGEntry::set_max_chars // Access: Published @@ -488,6 +513,18 @@ get_erase_prefix() { return "erase-"; } +//////////////////////////////////////////////////////////////////// +// Function: PGEntry::get_cursormove_prefix +// Access: Published, Static +// Description: Returns the prefix that is used to define the cursor +// event for all PGEntries. The cursor event is the +// concatenation of this string followed by get_id(). +//////////////////////////////////////////////////////////////////// +INLINE string PGEntry:: +get_cursormove_prefix() { + return "cursormove-"; +} + //////////////////////////////////////////////////////////////////// // Function: PGEntry::get_accept_event // Access: Published @@ -545,6 +582,17 @@ get_erase_event() const { return get_erase_prefix() + get_id(); } +//////////////////////////////////////////////////////////////////// +// Function: PGEntry::get_cursormove_event +// Access: Published +// Description: Returns the event name that will be thrown whenever +// the cursor moves +//////////////////////////////////////////////////////////////////// +INLINE string PGEntry:: +get_cursormove_event() const { + return get_cursormove_prefix() + get_id(); +} + //////////////////////////////////////////////////////////////////// // Function: PGEntry::set_wtext // Access: Published diff --git a/panda/src/pgui/pgEntry.cxx b/panda/src/pgui/pgEntry.cxx index a2356ae63a..e5a541dd2d 100644 --- a/panda/src/pgui/pgEntry.cxx +++ b/panda/src/pgui/pgEntry.cxx @@ -516,6 +516,19 @@ erase(const MouseWatcherParameter ¶m) { throw_event(event, EventParameter(ep)); } +//////////////////////////////////////////////////////////////////// +// Function: PGEntry::cursormove +// Access: Public, Virtual +// Description: This is a callback hook function, called whenever the +// cursor moves. +//////////////////////////////////////////////////////////////////// +void PGEntry:: +cursormove() { + LightReMutexHolder holder(_lock); + string event = get_cursormove_event(); + throw_event(event, EventParameter(_cursor_def.get_x()), EventParameter(_cursor_def.get_y())); +} + //////////////////////////////////////////////////////////////////// // Function: PGEntry::setup // Access: Published @@ -844,6 +857,8 @@ update_cursor() { _cursor_def.set_pos(xpos, 0.0f, ypos); _cursor_stale = false; + cursormove(); + } // Should the cursor be visible? diff --git a/panda/src/pgui/pgEntry.h b/panda/src/pgui/pgEntry.h index 36a198dc11..ce44e2e44e 100644 --- a/panda/src/pgui/pgEntry.h +++ b/panda/src/pgui/pgEntry.h @@ -61,6 +61,7 @@ public: virtual void overflow(const MouseWatcherParameter ¶m); virtual void type(const MouseWatcherParameter ¶m); virtual void erase(const MouseWatcherParameter ¶m); + virtual void cursormove(); PUBLISHED: enum State { @@ -83,6 +84,9 @@ PUBLISHED: INLINE void set_cursor_position(int position); INLINE int get_cursor_position() const; + + INLINE float get_cursor_X() const; + INLINE float get_cursor_Y() const; INLINE void set_max_chars(int max_chars); INLINE int get_max_chars() const; @@ -120,12 +124,15 @@ PUBLISHED: INLINE static string get_overflow_prefix(); INLINE static string get_type_prefix(); INLINE static string get_erase_prefix(); + INLINE static string get_cursormove_prefix(); INLINE string get_accept_event(const ButtonHandle &button) const; INLINE string get_accept_failed_event(const ButtonHandle &button) const; INLINE string get_overflow_event() const; INLINE string get_type_event() const; INLINE string get_erase_event() const; + INLINE string get_cursormove_event() const; + INLINE bool set_wtext(const wstring &wtext); INLINE wstring get_plain_wtext() const;