Browse Source

hooks for binding a "cursormove" event when the cursor moves

John Loehrlein 17 years ago
parent
commit
5550aaa1d7
3 changed files with 70 additions and 0 deletions
  1. 48 0
      panda/src/pgui/pgEntry.I
  2. 15 0
      panda/src/pgui/pgEntry.cxx
  3. 7 0
      panda/src/pgui/pgEntry.h

+ 48 - 0
panda/src/pgui/pgEntry.I

@@ -155,6 +155,31 @@ get_cursor_position() const {
   return _cursor_position;
   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
 //     Function: PGEntry::set_max_chars
 //       Access: Published
 //       Access: Published
@@ -488,6 +513,18 @@ get_erase_prefix() {
   return "erase-";
   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
 //     Function: PGEntry::get_accept_event
 //       Access: Published
 //       Access: Published
@@ -545,6 +582,17 @@ get_erase_event() const {
   return get_erase_prefix() + get_id();
   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
 //     Function: PGEntry::set_wtext
 //       Access: Published
 //       Access: Published

+ 15 - 0
panda/src/pgui/pgEntry.cxx

@@ -516,6 +516,19 @@ erase(const MouseWatcherParameter &param) {
   throw_event(event, EventParameter(ep));
   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
 //     Function: PGEntry::setup
 //       Access: Published
 //       Access: Published
@@ -844,6 +857,8 @@ update_cursor() {
 
 
     _cursor_def.set_pos(xpos, 0.0f, ypos);
     _cursor_def.set_pos(xpos, 0.0f, ypos);
     _cursor_stale = false;
     _cursor_stale = false;
+    cursormove();
+    
   }
   }
 
 
   // Should the cursor be visible?
   // Should the cursor be visible?

+ 7 - 0
panda/src/pgui/pgEntry.h

@@ -61,6 +61,7 @@ public:
   virtual void overflow(const MouseWatcherParameter &param);
   virtual void overflow(const MouseWatcherParameter &param);
   virtual void type(const MouseWatcherParameter &param);
   virtual void type(const MouseWatcherParameter &param);
   virtual void erase(const MouseWatcherParameter &param);
   virtual void erase(const MouseWatcherParameter &param);
+  virtual void cursormove();
 
 
 PUBLISHED:
 PUBLISHED:
   enum State {
   enum State {
@@ -83,6 +84,9 @@ PUBLISHED:
 
 
   INLINE void set_cursor_position(int position);
   INLINE void set_cursor_position(int position);
   INLINE int get_cursor_position() const;
   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 void set_max_chars(int max_chars);
   INLINE int get_max_chars() const;
   INLINE int get_max_chars() const;
@@ -120,12 +124,15 @@ PUBLISHED:
   INLINE static string get_overflow_prefix();
   INLINE static string get_overflow_prefix();
   INLINE static string get_type_prefix();
   INLINE static string get_type_prefix();
   INLINE static string get_erase_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_event(const ButtonHandle &button) const;
   INLINE string get_accept_failed_event(const ButtonHandle &button) const;
   INLINE string get_accept_failed_event(const ButtonHandle &button) const;
   INLINE string get_overflow_event() const;
   INLINE string get_overflow_event() const;
   INLINE string get_type_event() const;
   INLINE string get_type_event() const;
   INLINE string get_erase_event() const;
   INLINE string get_erase_event() const;
+  INLINE string get_cursormove_event() const;
+  
 
 
   INLINE bool set_wtext(const wstring &wtext);
   INLINE bool set_wtext(const wstring &wtext);
   INLINE wstring get_plain_wtext() const;
   INLINE wstring get_plain_wtext() const;