Sfoglia il codice sorgente

support rotating widgets

David Rose 24 anni fa
parent
commit
75eb814e05
3 ha cambiato i file con 99 aggiunte e 3 eliminazioni
  1. 52 0
      panda/src/pgui/pgItem.I
  2. 41 3
      panda/src/pgui/pgItem.cxx
  3. 6 0
      panda/src/pgui/pgItem.h

+ 52 - 0
panda/src/pgui/pgItem.I

@@ -202,6 +202,36 @@ get_exit_prefix() {
   return "exit-";
   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
 //     Function: PGItem::get_press_prefix
 //       Access: Published, Static
 //       Access: Published, Static
@@ -250,6 +280,28 @@ get_exit_event() const {
   return get_exit_prefix() + get_id();
   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
 //     Function: PGItem::get_press_event
 //       Access: Published
 //       Access: Published

+ 41 - 3
panda/src/pgui/pgItem.cxx

@@ -166,11 +166,21 @@ xform(const LMatrix4f &mat) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void PGItem::
 void PGItem::
 activate_region(PGTop *, const LMatrix4f &transform, int sort) {
 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 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]);
   LPoint3f ur(_frame[1], 0.0, _frame[3]);
   ll = ll * transform;
   ll = ll * transform;
+  lr = lr * transform;
+  ul = ul * transform;
   ur = ur * 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_sort(sort);
   _region->set_active(true);
   _region->set_active(true);
 }
 }
@@ -223,6 +233,28 @@ exit(const MouseWatcherParameter &param) {
               EventParameter(ep));
               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
 //     Function: PGItem::press
 //       Access: Public, Virtual
 //       Access: Public, Virtual
@@ -302,7 +334,10 @@ set_focus(bool focus) {
       }
       }
       _focus_item = this;
       _focus_item = this;
     }
     }
-    _flags |= F_focus;
+    if (!get_focus()) {
+      focus_in();
+      _flags |= F_focus;
+    }
 
 
   } else {
   } else {
     if (_focus_item == this) {
     if (_focus_item == this) {
@@ -310,7 +345,10 @@ set_focus(bool focus) {
       _focus_item = (PGItem *)NULL;
       _focus_item = (PGItem *)NULL;
     }
     }
 
 
-    _flags &= ~F_focus;
+    if (get_focus()) {
+      focus_out();
+      _flags &= ~F_focus;
+    }
   }
   }
   _region->set_keyboard(focus);
   _region->set_keyboard(focus);
 }
 }

+ 6 - 0
panda/src/pgui/pgItem.h

@@ -73,6 +73,8 @@ public:
 
 
   virtual void enter(const MouseWatcherParameter &param);
   virtual void enter(const MouseWatcherParameter &param);
   virtual void exit(const MouseWatcherParameter &param);
   virtual void exit(const MouseWatcherParameter &param);
+  virtual void focus_in();
+  virtual void focus_out();
   virtual void press(const MouseWatcherParameter &param);
   virtual void press(const MouseWatcherParameter &param);
   virtual void release(const MouseWatcherParameter &param);
   virtual void release(const MouseWatcherParameter &param);
 
 
@@ -106,11 +108,15 @@ PUBLISHED:
 
 
   INLINE static string get_enter_prefix();
   INLINE static string get_enter_prefix();
   INLINE static string get_exit_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_press_prefix();
   INLINE static string get_release_prefix();
   INLINE static string get_release_prefix();
 
 
   INLINE string get_enter_event() const;
   INLINE string get_enter_event() const;
   INLINE string get_exit_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_press_event(const ButtonHandle &button) const;
   INLINE string get_release_event(const ButtonHandle &button) const;
   INLINE string get_release_event(const ButtonHandle &button) const;