Cary Sandvig 25 лет назад
Родитель
Сommit
675a62e6cf

+ 18 - 0
panda/src/gui/guiButton.cxx

@@ -231,3 +231,21 @@ void GuiButton::set_pos(const LVector3f& p) {
   GuiItem::set_pos(p);
   this->recompute_frame();
 }
+
+void GuiButton::output(ostream& os) const {
+  GuiItem::output(os);
+  os << "  Button data:" << endl;
+  os << "    up - 0x" << (void*)_up << endl;
+  os << "    up_rollover - 0x" << (void*)_up_rollover << endl;
+  os << "    down - 0x" << (void*)_down << endl;
+  os << "    down_rollover - 0x" << (void*)_down_rollover << endl;
+  os << "    inactive - 0x" << (void*)_inactive << endl;
+  os << "    up event - '" << _up_event << "'" << endl;
+  os << "    up_rollover event - '" << _up_rollover_event << "'" << endl;
+  os << "    down event - '" << _down_event << "'" << endl;
+  os << "    down_rollover event - '" << _down_rollover_event << "'" << endl;
+  os << "    inactive event - '" << _inactive_event << "'" << endl;
+  os << "    rgn - 0x" << (void*)_rgn << endl;
+  os << "      frame - " << _rgn->get_frame() << endl;
+  os << "    state - " << _state << endl;
+}

+ 2 - 0
panda/src/gui/guiButton.h

@@ -61,6 +61,8 @@ public:
 
   virtual void set_scale(float);
   virtual void set_pos(const LVector3f&);
+
+  virtual void output(ostream&) const;
 };
 
 #include "guiButton.I"

+ 32 - 13
panda/src/gui/guiFrame.cxx

@@ -30,51 +30,52 @@ void GuiFrame::recompute_frame(void) {
     if (n > 0) {
       GuiItem* here = (*i).get_item();
       LVector4f ext_h = here->get_frame();
-      float x_h = (ext_h[0] + ext_h[1]) / 2.;
-      float y_h = (ext_h[2] + ext_h[3]) / 2.;
+      LVector3f pos_h = here->get_pos();
       for (int j=0; j<n; ++j) {
 	Packing pack = (*i).get_nth_packing(j);
 	if (pack == NONE)
 	  continue;
 	GuiItem* to = (*i).get_nth_to(j);
 	LVector4f ext_t = to->get_frame();
-	float x_t = (ext_t[0] + ext_h[1]) / 2.;
-	float y_t = (ext_t[2] + ext_h[3]) / 2.;
 	switch (pack) {
 	case ABOVE:
 	  {
 	    // to(top) - here(bottom)
 	    float diff = ext_t[3] - ext_h[2];
-	    y_h += diff;
-	    here->set_pos(LVector3f::rfu(x_h, 0., y_h));
+	    LVector3f move = LVector3f::rfu(0., 0., diff);
+	    here->set_pos(pos_h + move);
 	    ext_h = here->get_frame();
+	    pos_h = here->get_pos();
 	  }
 	  break;
 	case UNDER:
 	  {
 	    // to(bottom) - here(top)
 	    float diff = ext_t[2] - ext_h[3];
-	    y_h += diff;
-	    here->set_pos(LVector3f::rfu(x_h, 0., y_h));
+	    LVector3f move = LVector3f::rfu(0., 0., diff);
+	    here->set_pos(pos_h + move);
 	    ext_h = here->get_frame();
+	    pos_h = here->get_pos();
 	  }
 	  break;
 	case LEFT:
 	  {
 	    // to(left) - here(right)
 	    float diff = ext_t[0] - ext_h[1];
-	    x_h += diff;
-	    here->set_pos(LVector3f::rfu(x_h, 0., y_h));
+	    LVector3f move = LVector3f::rfu(diff, 0., 0.);
+	    here->set_pos(pos_h + move);
 	    ext_h = here->get_frame();
+	    pos_h = here->get_pos();
 	  }
 	  break;
 	case RIGHT:
 	  {
 	    // to(right) - here(left)
 	    float diff = ext_t[1] - ext_h[0];
-	    x_h += diff;
-	    here->set_pos(LVector3f::rfu(x_h, 0., y_h));
+	    LVector3f move = LVector3f::rfu(diff, 0., 0.);
+	    here->set_pos(pos_h + move);
 	    ext_h = here->get_frame();
+	    pos_h = here->get_pos();
 	  }
 	  break;
 	default:
@@ -151,7 +152,7 @@ void GuiFrame::pack_item(GuiItem* item, Packing rel, GuiItem* to) {
       << "tried to pack an item relative to something we don't have" << endl;
     return;
   }
-  (*box).add_link(Connection(rel, (*tobox).get_item()));
+  (*box).add_link(Connection(rel, to));
   this->recompute_frame();
 }
 
@@ -187,3 +188,21 @@ void GuiFrame::set_pos(const LVector3f& p) {
   GuiItem::set_pos(p);
   this->recompute_frame();
 }
+
+void GuiFrame::output(ostream& os) const {
+  GuiItem::output(os);
+  os << "  Frame data:" << endl;
+  Boxes::const_iterator i;
+  for (i=_items.begin(); i!=_items.end(); ++i) {
+    os << "    box - 0x" << (void*)((*i).get_item()) << endl;
+    int n = (*i).get_num_links();
+    if (n > 0) {
+      for (int j=0; j<n; ++j)
+	os << "      linked by " << (*i).get_nth_packing(j) << " to 0x"
+	   << (void*)((*i).get_nth_to(j)) << endl;
+    }
+  }
+  for (i=_items.begin(); i!=_items.end(); ++i) {
+    os << *((*i).get_item());
+  }
+}

+ 2 - 0
panda/src/gui/guiFrame.h

@@ -68,6 +68,8 @@ public:
 
   virtual void set_scale(float);
   virtual void set_pos(const LVector3f&);
+
+  virtual void output(ostream&) const;
 };
 
 #include "guiFrame.I"

+ 5 - 0
panda/src/gui/guiItem.I

@@ -33,3 +33,8 @@ INLINE float GuiItem::get_top(void) const {
 INLINE LVector4f GuiItem::get_frame(void) const {
   return LVector4f(_left, _right, _bottom, _top);
 }
+
+INLINE ostream& operator<<(ostream& os, GuiItem& item) {
+  item.output(os);
+  return os;
+}

+ 14 - 1
panda/src/gui/guiItem.cxx

@@ -9,7 +9,9 @@ void GuiItem::recompute_frame(void) {
 }
 
 GuiItem::GuiItem(const string& name) : Namable(name), _added_hooks(false),
-				       _mgr((GuiManager*)0L) {
+				       _mgr((GuiManager*)0L), _scale(1.),
+				       _pos(0., 0., 0.), _left(-1.),
+				       _right(1.), _bottom(-1.), _top(1.) {
 }
 
 GuiItem::~GuiItem(void) {
@@ -30,3 +32,14 @@ void GuiItem::set_scale(float f) {
 void GuiItem::set_pos(const LVector3f& p) {
   _pos = p;
 }
+
+void GuiItem::output(ostream& os) const {
+  os << "GuiItem (0x" << (void*)this << ")" << endl;
+  os << "  name - '" << get_name() << "'" << endl;
+  os << "  hooks have" << (_added_hooks?" ":" not ") << "been added" << endl;
+  os << "  scale - " << _scale << endl;
+  os << "  pos - " << _pos << endl;
+  os << "  mgr - 0x" << (void*)_mgr << endl;
+  os << "  frame - (" << _left << ", " << _right << ", " << _bottom << ", "
+     << _top << ")" << endl;
+}

+ 2 - 0
panda/src/gui/guiItem.h

@@ -36,6 +36,8 @@ public:
   INLINE float get_bottom(void) const;
   INLINE float get_top(void) const;
   INLINE LVector4f get_frame(void) const;
+
+  virtual void output(ostream&) const = 0;
 };
 
 #include "guiItem.I"

+ 2 - 1
panda/src/gui/guiLabel.I

@@ -3,7 +3,8 @@
 // 
 ////////////////////////////////////////////////////////////////////
 
-INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE) {
+INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE), _scale(1.),
+				  _pos(0., 0., 0.) {
 }
 
 INLINE Node* GuiLabel::get_geometry(void) const {

+ 3 - 0
panda/src/gui/guiLabel.cxx

@@ -39,6 +39,9 @@ GuiLabel* GuiLabel::make_simple_text_label(const string& text, Node* font) {
   n->set_align(TM_ALIGN_CENTER);
   n->set_text_color(1., 1., 1., 1.);
   n->set_text(text);
+  ret->set_scale(1.);
+  ret->set_pos(LVector3f(0., 0., 0.));
+  ret->recompute_transform();
   return ret;
 }
 

+ 8 - 0
panda/src/gui/guiRegion.I

@@ -25,4 +25,12 @@ INLINE void GuiRegion::trap_clicks(bool t) {
 INLINE void GuiRegion::set_region(float left, float right, float bottom,
 				  float top) {
   _region->set_frame(left, right, bottom, top);
+  _left = left;
+  _right = right;
+  _bottom = bottom;
+  _top = top;
+}
+
+INLINE LVector4f GuiRegion::get_frame(void) const {
+  return LVector4f(_left, _right, _bottom, _top);
 }

+ 1 - 0
panda/src/gui/guiRegion.h

@@ -31,6 +31,7 @@ public:
   INLINE void trap_clicks(bool);
 
   INLINE void set_region(float, float, float, float);
+  INLINE LVector4f get_frame(void) const;
 };
 
 #include "guiRegion.I"

+ 10 - 0
panda/src/gui/guiRollover.cxx

@@ -86,3 +86,13 @@ void GuiRollover::set_pos(const LVector3f& p) {
   GuiItem::set_pos(p);
   recompute_frame();
 }
+
+void GuiRollover::output(ostream& os) const {
+  GuiItem::output(os);
+  os << "  Rollover data:" << endl;
+  os << "    off - 0x" << (void*)_off << endl;
+  os << "    on - 0x" << (void*)_on << endl;
+  os << "    region - 0x" << (void*)_rgn << endl;
+  os << "      frame - " << _rgn->get_frame() << endl;
+  os << "    state - " << _state << endl;
+}

+ 2 - 0
panda/src/gui/guiRollover.h

@@ -34,6 +34,8 @@ public:
 
   virtual void set_scale(float);
   virtual void set_pos(const LVector3f&);
+
+  virtual void output(ostream&) const;
 };
 
 #include "guiRollover.I"

+ 1 - 0
panda/src/testbed/gui_demo.cxx

@@ -157,6 +157,7 @@ static void setup_gui(void) {
   f1->set_scale(0.1);
   f1->set_pos(LVector3f::rfu(0., 0., -0.25));
   f1->manage(mgr, event_handler);
+  cerr << *f1;
 }
 
 static void event_2(CPT_Event) {