diff --git a/panda/src/pgui/pgItem.I b/panda/src/pgui/pgItem.I index 8d17d44a9b..98d62ce1a0 100644 --- a/panda/src/pgui/pgItem.I +++ b/panda/src/pgui/pgItem.I @@ -202,6 +202,36 @@ get_exit_prefix() { return "exit-"; } +//////////////////////////////////////////////////////////////////// +// Function: PGItem::get_focus_in_prefix +// Access: Published, Static +// Description: Returns the prefix that is used to define the focus_in +// event for all PGItems. The focus_in event is the +// concatenation of this string followed by get_id(). +// +// Unlike most item events, this event is thrown with no +// parameters. +//////////////////////////////////////////////////////////////////// +INLINE string PGItem:: +get_focus_in_prefix() { + return "fin-"; +} + +//////////////////////////////////////////////////////////////////// +// Function: PGItem::get_focus_out_prefix +// Access: Published, Static +// Description: Returns the prefix that is used to define the focus_out +// event for all PGItems. The focus_out event is the +// concatenation of this string followed by get_id(). +// +// Unlike most item events, this event is thrown with no +// parameters. +//////////////////////////////////////////////////////////////////// +INLINE string PGItem:: +get_focus_out_prefix() { + return "fout-"; +} + //////////////////////////////////////////////////////////////////// // Function: PGItem::get_press_prefix // Access: Published, Static @@ -250,6 +280,28 @@ get_exit_event() const { return get_exit_prefix() + get_id(); } +//////////////////////////////////////////////////////////////////// +// Function: PGItem::get_focus_in_event +// Access: Published +// Description: Returns the event name that will be thrown when the +// item gets the keyboard focus. +//////////////////////////////////////////////////////////////////// +INLINE string PGItem:: +get_focus_in_event() const { + return get_focus_in_prefix() + get_id(); +} + +//////////////////////////////////////////////////////////////////// +// Function: PGItem::get_focus_out_event +// Access: Published +// Description: Returns the event name that will be thrown when the +// item loses the keyboard focus. +//////////////////////////////////////////////////////////////////// +INLINE string PGItem:: +get_focus_out_event() const { + return get_focus_out_prefix() + get_id(); +} + //////////////////////////////////////////////////////////////////// // Function: PGItem::get_press_event // Access: Published diff --git a/panda/src/pgui/pgItem.cxx b/panda/src/pgui/pgItem.cxx index c7fa4060a2..e2622d6872 100644 --- a/panda/src/pgui/pgItem.cxx +++ b/panda/src/pgui/pgItem.cxx @@ -166,11 +166,21 @@ xform(const LMatrix4f &mat) { //////////////////////////////////////////////////////////////////// void PGItem:: activate_region(PGTop *, const LMatrix4f &transform, int sort) { + // Transform all four vertices, and get the new bounding box. This + // way the region works (mostly) even if has been rotated. LPoint3f ll(_frame[0], 0.0, _frame[2]); + LPoint3f lr(_frame[1], 0.0, _frame[2]); + LPoint3f ul(_frame[0], 0.0, _frame[3]); LPoint3f ur(_frame[1], 0.0, _frame[3]); ll = ll * transform; + lr = lr * transform; + ul = ul * transform; ur = ur * transform; - _region->set_frame(ll[0], ur[0], ll[2], ur[2]); + _region->set_frame(min(min(ll[0], lr[0]), min(ul[0], ur[0])), + max(max(ll[0], lr[0]), max(ul[0], ur[0])), + min(min(ll[2], lr[2]), min(ul[2], ur[2])), + max(max(ll[2], lr[2]), max(ul[2], ur[2]))); + _region->set_sort(sort); _region->set_active(true); } @@ -223,6 +233,28 @@ exit(const MouseWatcherParameter ¶m) { EventParameter(ep)); } +//////////////////////////////////////////////////////////////////// +// Function: PGItem::focus_in +// Access: Public, Virtual +// Description: This is a callback hook function, called whenever the +// widget gets the keyboard focus. +//////////////////////////////////////////////////////////////////// +void PGItem:: +focus_in() { + throw_event(get_focus_in_event()); +} + +//////////////////////////////////////////////////////////////////// +// Function: PGItem::focus_out +// Access: Public, Virtual +// Description: This is a callback hook function, called whenever the +// widget loses the keyboard focus. +//////////////////////////////////////////////////////////////////// +void PGItem:: +focus_out() { + throw_event(get_focus_out_event()); +} + //////////////////////////////////////////////////////////////////// // Function: PGItem::press // Access: Public, Virtual @@ -302,7 +334,10 @@ set_focus(bool focus) { } _focus_item = this; } - _flags |= F_focus; + if (!get_focus()) { + focus_in(); + _flags |= F_focus; + } } else { if (_focus_item == this) { @@ -310,7 +345,10 @@ set_focus(bool focus) { _focus_item = (PGItem *)NULL; } - _flags &= ~F_focus; + if (get_focus()) { + focus_out(); + _flags &= ~F_focus; + } } _region->set_keyboard(focus); } diff --git a/panda/src/pgui/pgItem.h b/panda/src/pgui/pgItem.h index 7c119ee1f5..99f79ddce4 100644 --- a/panda/src/pgui/pgItem.h +++ b/panda/src/pgui/pgItem.h @@ -73,6 +73,8 @@ public: virtual void enter(const MouseWatcherParameter ¶m); virtual void exit(const MouseWatcherParameter ¶m); + virtual void focus_in(); + virtual void focus_out(); virtual void press(const MouseWatcherParameter ¶m); virtual void release(const MouseWatcherParameter ¶m); @@ -106,11 +108,15 @@ PUBLISHED: INLINE static string get_enter_prefix(); INLINE static string get_exit_prefix(); + INLINE static string get_focus_in_prefix(); + INLINE static string get_focus_out_prefix(); INLINE static string get_press_prefix(); INLINE static string get_release_prefix(); INLINE string get_enter_event() const; INLINE string get_exit_event() const; + INLINE string get_focus_in_event() const; + INLINE string get_focus_out_event() const; INLINE string get_press_event(const ButtonHandle &button) const; INLINE string get_release_event(const ButtonHandle &button) const;