Skip to content

Commit 5550aaa

Browse files
author
John Loehrlein
committed
hooks for binding a "cursormove" event when the cursor moves
1 parent 2c71002 commit 5550aaa

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

panda/src/pgui/pgEntry.I

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,31 @@ get_cursor_position() const {
155155
return _cursor_position;
156156
}
157157

158+
////////////////////////////////////////////////////////////////////
159+
// Function: PGEntry::get_cursor_X
160+
// Access: Published
161+
// Description: Returns the node position x of the cursor
162+
////////////////////////////////////////////////////////////////////
163+
164+
INLINE float PGEntry::
165+
get_cursor_X() const {
166+
LightReMutexHolder holder(_lock);
167+
return _cursor_def.get_x();
168+
}
169+
170+
////////////////////////////////////////////////////////////////////
171+
// Function: PGEntry::get_cursor_y
172+
// Access: Published
173+
// Description: Returns the node position y of the cursor
174+
////////////////////////////////////////////////////////////////////
175+
176+
INLINE float PGEntry::
177+
get_cursor_Y() const {
178+
LightReMutexHolder holder(_lock);
179+
return _cursor_def.get_y();
180+
}
181+
182+
158183
////////////////////////////////////////////////////////////////////
159184
// Function: PGEntry::set_max_chars
160185
// Access: Published
@@ -488,6 +513,18 @@ get_erase_prefix() {
488513
return "erase-";
489514
}
490515

516+
////////////////////////////////////////////////////////////////////
517+
// Function: PGEntry::get_cursormove_prefix
518+
// Access: Published, Static
519+
// Description: Returns the prefix that is used to define the cursor
520+
// event for all PGEntries. The cursor event is the
521+
// concatenation of this string followed by get_id().
522+
////////////////////////////////////////////////////////////////////
523+
INLINE string PGEntry::
524+
get_cursormove_prefix() {
525+
return "cursormove-";
526+
}
527+
491528
////////////////////////////////////////////////////////////////////
492529
// Function: PGEntry::get_accept_event
493530
// Access: Published
@@ -545,6 +582,17 @@ get_erase_event() const {
545582
return get_erase_prefix() + get_id();
546583
}
547584

585+
////////////////////////////////////////////////////////////////////
586+
// Function: PGEntry::get_cursormove_event
587+
// Access: Published
588+
// Description: Returns the event name that will be thrown whenever
589+
// the cursor moves
590+
////////////////////////////////////////////////////////////////////
591+
INLINE string PGEntry::
592+
get_cursormove_event() const {
593+
return get_cursormove_prefix() + get_id();
594+
}
595+
548596
////////////////////////////////////////////////////////////////////
549597
// Function: PGEntry::set_wtext
550598
// Access: Published

panda/src/pgui/pgEntry.cxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,19 @@ erase(const MouseWatcherParameter &param) {
516516
throw_event(event, EventParameter(ep));
517517
}
518518

519+
////////////////////////////////////////////////////////////////////
520+
// Function: PGEntry::cursormove
521+
// Access: Public, Virtual
522+
// Description: This is a callback hook function, called whenever the
523+
// cursor moves.
524+
////////////////////////////////////////////////////////////////////
525+
void PGEntry::
526+
cursormove() {
527+
LightReMutexHolder holder(_lock);
528+
string event = get_cursormove_event();
529+
throw_event(event, EventParameter(_cursor_def.get_x()), EventParameter(_cursor_def.get_y()));
530+
}
531+
519532
////////////////////////////////////////////////////////////////////
520533
// Function: PGEntry::setup
521534
// Access: Published
@@ -844,6 +857,8 @@ update_cursor() {
844857

845858
_cursor_def.set_pos(xpos, 0.0f, ypos);
846859
_cursor_stale = false;
860+
cursormove();
861+
847862
}
848863

849864
// Should the cursor be visible?

panda/src/pgui/pgEntry.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class EXPCL_PANDA_PGUI PGEntry : public PGItem {
6161
virtual void overflow(const MouseWatcherParameter &param);
6262
virtual void type(const MouseWatcherParameter &param);
6363
virtual void erase(const MouseWatcherParameter &param);
64+
virtual void cursormove();
6465

6566
PUBLISHED:
6667
enum State {
@@ -83,6 +84,9 @@ class EXPCL_PANDA_PGUI PGEntry : public PGItem {
8384

8485
INLINE void set_cursor_position(int position);
8586
INLINE int get_cursor_position() const;
87+
88+
INLINE float get_cursor_X() const;
89+
INLINE float get_cursor_Y() const;
8690

8791
INLINE void set_max_chars(int max_chars);
8892
INLINE int get_max_chars() const;
@@ -120,12 +124,15 @@ class EXPCL_PANDA_PGUI PGEntry : public PGItem {
120124
INLINE static string get_overflow_prefix();
121125
INLINE static string get_type_prefix();
122126
INLINE static string get_erase_prefix();
127+
INLINE static string get_cursormove_prefix();
123128

124129
INLINE string get_accept_event(const ButtonHandle &button) const;
125130
INLINE string get_accept_failed_event(const ButtonHandle &button) const;
126131
INLINE string get_overflow_event() const;
127132
INLINE string get_type_event() const;
128133
INLINE string get_erase_event() const;
134+
INLINE string get_cursormove_event() const;
135+
129136

130137
INLINE bool set_wtext(const wstring &wtext);
131138
INLINE wstring get_plain_wtext() const;

0 commit comments

Comments
 (0)