Browse Source

whee! functionality

Cary Sandvig 25 years ago
parent
commit
2c9655669b

+ 12 - 0
panda/src/gui/guiButton.I

@@ -157,3 +157,15 @@ INLINE const string& GuiButton::get_down_rollover_event(void) const {
 INLINE const string& GuiButton::get_inactive_event(void) const {
   return _inactive_event;
 }
+
+INLINE void GuiButton::set_up_rollover(GuiLabel* upr) {
+  _up_rollover = upr;
+  if (_up_rollover_event.empty())
+    _up_rollover_event = this->get_name() + "-up-rollover";
+}
+
+INLINE void GuiButton::set_down_rollover(GuiLabel* downr) {
+  _down_rollover = downr;
+  if (_down_rollover_event.empty())
+    _down_rollover_event = this->get_name() + "-down-rollover";
+}

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

@@ -159,6 +159,14 @@ void GuiButton::switch_state(GuiButton::States nstate) {
 
 void GuiButton::recompute_frame(void) {
   GuiItem::recompute_frame();
+  _up->recompute();
+  _down->recompute();
+  if (_up_rollover != (GuiLabel*)0L)
+    _up_rollover->recompute();
+  if (_down_rollover != (GuiLabel*)0L)
+    _down_rollover->recompute();
+  if (_inactive != (GuiLabel*)0L)
+    _inactive->recompute();
   GetExtents(_up, _down, _up_rollover, _down_rollover, _inactive, _left,
 	     _right, _bottom, _top);
   _rgn->set_region(_left, _right, _bottom, _top);

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

@@ -67,6 +67,9 @@ public:
   INLINE const string& get_down_rollover_event(void) const;
   INLINE const string& get_inactive_event(void) const;
 
+  INLINE void set_up_rollover(GuiLabel*);
+  INLINE void set_down_rollover(GuiLabel*);
+
   virtual void set_scale(float);
   virtual void set_pos(const LVector3f&);
 

+ 47 - 5
panda/src/gui/guiFrame.cxx

@@ -28,9 +28,10 @@ void GuiFrame::recompute_frame(void) {
   // and brute-force algorithm.  Hopefully it will be replaced with something
   // more ellegant later
   for (i=_items.begin(); i!=_items.end(); ++i) {
+    GuiItem* here = (*i).get_item();
+    here->recompute();
     int n = (*i).get_num_links();
     if (n > 0) {
-      GuiItem* here = (*i).get_item();
       LVector4f ext_h = here->get_frame();
       LVector3f pos_h = here->get_pos();
       for (int j=0; j<n; ++j) {
@@ -38,12 +39,13 @@ void GuiFrame::recompute_frame(void) {
 	if (pack == NONE)
 	  continue;
 	GuiItem* to = (*i).get_nth_to(j);
+	float gap = (*i).get_nth_gap(j);
 	LVector4f ext_t = to->get_frame();
 	switch (pack) {
 	case ABOVE:
 	  {
 	    // to(top) - here(bottom)
-	    float diff = ext_t[3] - ext_h[2];
+	    float diff = ext_t[3] - ext_h[2] + gap;
 	    LVector3f move = LVector3f::rfu(0., 0., diff);
 	    here->set_pos(pos_h + move);
 	    ext_h = here->get_frame();
@@ -53,7 +55,7 @@ void GuiFrame::recompute_frame(void) {
 	case UNDER:
 	  {
 	    // to(bottom) - here(top)
-	    float diff = ext_t[2] - ext_h[3];
+	    float diff = ext_t[2] - ext_h[3] - gap;
 	    LVector3f move = LVector3f::rfu(0., 0., diff);
 	    here->set_pos(pos_h + move);
 	    ext_h = here->get_frame();
@@ -63,7 +65,7 @@ void GuiFrame::recompute_frame(void) {
 	case LEFT:
 	  {
 	    // to(left) - here(right)
-	    float diff = ext_t[0] - ext_h[1];
+	    float diff = ext_t[0] - ext_h[1] - gap;
 	    LVector3f move = LVector3f::rfu(diff, 0., 0.);
 	    here->set_pos(pos_h + move);
 	    ext_h = here->get_frame();
@@ -73,7 +75,47 @@ void GuiFrame::recompute_frame(void) {
 	case RIGHT:
 	  {
 	    // to(right) - here(left)
-	    float diff = ext_t[1] - ext_h[0];
+	    float diff = ext_t[1] - ext_h[0] + gap;
+	    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 ALIGN_ABOVE:
+	  {
+	    // to(top) - here(top)
+	    float diff = ext_t[3] - ext_h[3];
+	    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 ALIGN_UNDER:
+	  {
+	    // to(bottom) - here(bottom)
+	    float diff = ext_t[2] - ext_h[2];
+	    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 ALIGN_LEFT:
+	  {
+	    // to(left) - here(left)
+	    float diff = ext_t[0] - ext_h[0];
+	    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 ALIGN_RIGHT:
+	  {
+	    // to(right) - here(right)
+	    float diff = ext_t[1] - ext_h[1];
 	    LVector3f move = LVector3f::rfu(diff, 0., 0.);
 	    here->set_pos(pos_h + move);
 	    ext_h = here->get_frame();

+ 3 - 1
panda/src/gui/guiFrame.h

@@ -12,7 +12,8 @@
 
 class EXPCL_PANDA GuiFrame : public GuiItem {
 public:
-  enum Packing { NONE, ABOVE, UNDER, LEFT, RIGHT };
+  enum Packing { NONE, ABOVE, UNDER, LEFT, RIGHT, ALIGN_ABOVE, ALIGN_UNDER,
+		 ALIGN_LEFT, ALIGN_RIGHT };
 private:
   class Connection {
   private:
@@ -58,6 +59,7 @@ private:
     inline int get_num_links(void) const { return _links.size(); }
     inline Packing get_nth_packing(int n) const { return _links[n].get_how(); }
     inline GuiItem* get_nth_to(int n) const { return _links[n].get_who(); }
+    inline float get_nth_gap(int n) const { return _links[n].get_gap(); }
 
     inline void erase_nth_link(int n) { _links.erase(_links.begin() + n); }
     inline void erase_all_links(void) { _links.clear(); }

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

@@ -34,6 +34,10 @@ INLINE LVector4f GuiItem::get_frame(void) const {
   return LVector4f(_left, _right, _bottom, _top);
 }
 
+INLINE void GuiItem::recompute(void) {
+  this->recompute_frame();
+}
+
 INLINE ostream& operator<<(ostream& os, GuiItem& item) {
   item.output(os);
   return os;

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

@@ -37,6 +37,8 @@ public:
   INLINE float get_top(void) const;
   INLINE LVector4f get_frame(void) const;
 
+  INLINE void recompute(void);
+
   virtual void output(ostream&) const = 0;
 public:
   // type interface

+ 4 - 0
panda/src/gui/guiLabel.I

@@ -88,3 +88,7 @@ INLINE Colorf GuiLabel::get_foreground_color(void) const {
 INLINE Colorf GuiLabel::get_background_color(void) const {
   return _background;
 }
+
+INLINE void GuiLabel::recompute(void) {
+  this->recompute_transform();
+}

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

@@ -43,8 +43,6 @@ void GuiLabel::set_properties(void) {
       n->set_text_color(_foreground);
       if (!_have_background) {
 	n->clear_card();
-	if (gui_cat->is_debug())
-	  gui_cat->debug() << "cleared card" << endl;
       } else {
 	n->set_card_color(_background);
 	if (_have_width || _have_height) {
@@ -52,35 +50,20 @@ void GuiLabel::set_properties(void) {
 	  float w = v[1] - v[0];
 	  float h = v[3] - v[2];
 	  if (_have_width) {
-	    gui_cat->debug() << "adjusting width: before = " << w;
 	    w = _width - w;
-	    gui_cat->debug(false) << "  diff = " << w;
 	    w *= 0.5;
 	    v[1] += w;
 	    v[0] -= w;
-	    gui_cat->debug(false) << "  after = " << (v[1] - v[0])
-				  << "  want = " << _width << endl;
 	  }
 	  if (_have_height) {
-	    gui_cat->debug() << "adjusting height: before = " << h;
 	    h = _height - h;
-	    gui_cat->debug(false) << "  diff = " << h;
 	    h *= 0.5;
 	    v[3] += h;
 	    v[2] -= h;
-	    gui_cat->debug(false) << "  after = " << (v[3] - v[2])
-				  << "  want = " << _height << endl;
 	  }
 	  n->set_card_actual(v[0], v[1], v[2], v[3]);
 	} else
 	  n->set_card_as_margin(0., 0., 0., 0.);
-	if (gui_cat->is_debug()) {
-	  gui_cat->debug() << "set card color" << endl;
-	  if (n->has_card())
-	    gui_cat->debug() << ".. and a card was made" << endl;
-	  else
-	    gui_cat->debug() << ".. but there is no card" << endl;
-	}
       }
     }
     break;
@@ -257,11 +240,5 @@ void GuiLabel::set_background_color(const Colorf& color) {
 
   _background = color;
   _have_background = (color != zero);
-  if (gui_cat->is_debug()) {
-    if (_have_background)
-      gui_cat->debug() << "setting background" << endl;
-    else
-      gui_cat->debug() << "setting no background" << endl;
-  }
   set_properties();
 }

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

@@ -74,6 +74,8 @@ public:
 
   INLINE Colorf get_foreground_color(void) const;
   INLINE Colorf get_background_color(void) const;
+
+  INLINE void recompute(void);
 public:
   // type interface
   static TypeHandle get_class_type(void) {

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

@@ -36,6 +36,8 @@ static void exit_rollover(CPT_Event e) {
 
 void GuiRollover::recompute_frame(void) {
   GuiItem::recompute_frame();
+  _off->recompute();
+  _on->recompute();
   GetExtents(_off, _on, _left, _right, _bottom, _top);
   _rgn->set_region(_left, _right, _bottom, _top);
 }

+ 1 - 0
panda/src/gui/guiSign.cxx

@@ -10,6 +10,7 @@ TypeHandle GuiSign::_type_handle;
 
 void GuiSign::recompute_frame(void) {
   GuiItem::recompute_frame();
+  _sign->recompute();
   _sign->get_extents(_left, _right, _bottom, _top);
 }
 

+ 121 - 34
panda/src/testbed/gui_demo.cxx

@@ -51,7 +51,7 @@
 extern PT(GeomNode) geomnode;
 extern RenderRelation* first_arc;
 
-static PT(GuiFrame) global_frame;
+// static PT(GuiFrame) global_frame;
 
 static void setup_gui(void) {
   GuiManager* mgr = GuiManager::get_ptr(main_win, mak);
@@ -165,35 +165,127 @@ static void setup_gui(void) {
   //  f1->manage(mgr, event_handler);
   //  cerr << *f1;
   // test 5
-  GuiLabel* l1 = GuiLabel::make_simple_text_label("on", font);
-  GuiLabel* l2 = GuiLabel::make_simple_text_label("off", font);
-  GuiLabel* l3 = GuiLabel::make_simple_text_label("over", font);
-  GuiLabel* l4 = GuiLabel::make_simple_text_label("easy", font);
-  l1->set_background_color(1., 1., 1., 0.3);
-  l2->set_background_color(1., 1., 1., 0.3);
-  l3->set_background_color(1., 1., 1., 0.3);
-  l4->set_background_color(1., 1., 1., 0.3);
-  GuiRollover* r1 = new GuiRollover("r1", l1, l2);
-  GuiRollover* r2 = new GuiRollover("r2", l3, l4);
-  GuiFrame* f1 = new GuiFrame("test5");
-  f1->add_item(r1);
-  f1->add_item(r2);
-  f1->pack_item(r2, GuiFrame::UNDER, r1);
-  f1->set_scale(0.1);
-  f1->manage(mgr, event_handler);
-  float w1, w2, w3, w4, w;
-  w1 = l1->get_width();
-  w2 = l2->get_width();
-  w3 = l3->get_width();
-  w4 = l4->get_width();
+  //  GuiLabel* l1 = GuiLabel::make_simple_text_label("on", font);
+  //  GuiLabel* l2 = GuiLabel::make_simple_text_label("off", font);
+  //  GuiLabel* l3 = GuiLabel::make_simple_text_label("over", font);
+  //  GuiLabel* l4 = GuiLabel::make_simple_text_label("easy", font);
+  //  l1->set_background_color(1., 1., 1., 0.3);
+  //  l2->set_background_color(1., 1., 1., 0.3);
+  //  l3->set_background_color(1., 1., 1., 0.3);
+  //  l4->set_background_color(1., 1., 1., 0.3);
+  //  GuiRollover* r1 = new GuiRollover("r1", l1, l2);
+  //  GuiRollover* r2 = new GuiRollover("r2", l3, l4);
+  //  GuiFrame* f1 = new GuiFrame("test5");
+  //  f1->add_item(r1);
+  //  f1->add_item(r2);
+  //  f1->pack_item(r2, GuiFrame::UNDER, r1);
+  //  f1->set_scale(0.1);
+  //  f1->manage(mgr, event_handler);
+  //  float w1, w2, w3, w4, w;
+  //  w1 = l1->get_width();
+  //  w2 = l2->get_width();
+  //  w3 = l3->get_width();
+  //  w4 = l4->get_width();
+  //  w = (w1>w2)?w1:w2;
+  //  w = (w>w3)?w:w3;
+  //  w = (w>w4)?w:w4;
+  //  l1->set_width(w);
+  //  l2->set_width(w);
+  //  l3->set_width(w);
+  //  l4->set_width(w);
+  //  global_frame = f1;
+  // test 6  (the greg test)
+  GuiFrame* f1 = new GuiFrame("canids");
+  GuiLabel* b1l1 = GuiLabel::make_simple_text_label("dingo", font);
+  b1l1->set_foreground_color(0., 0., 0., 1.);
+  b1l1->set_background_color(1., 1., 1., 1.);
+  GuiLabel* b1l2 = GuiLabel::make_simple_text_label("dingo", font);
+  b1l2->set_foreground_color(0., 0., 0., 1.);
+  b1l2->set_background_color(1., 1., 0., 1.);
+  GuiLabel* b1l3 = GuiLabel::make_simple_text_label("dingo", font);
+  b1l3->set_foreground_color(1., 1., 1., 1.);
+  b1l3->set_background_color(0., 0., 0., 1.);
+  GuiButton* b1 = new GuiButton("dingo", b1l1, b1l2, b1l3, b1l3, b1l1);
+  b1->set_scale(0.1);
+  f1->add_item(b1);
+  GuiLabel* b2l1 = GuiLabel::make_simple_text_label("jackel", font);
+  b2l1->set_foreground_color(0., 0., 0., 1.);
+  b2l1->set_background_color(1., 1., 1., 1.);
+  GuiLabel* b2l2 = GuiLabel::make_simple_text_label("jackel", font);
+  b2l2->set_foreground_color(0., 0., 0., 1.);
+  b2l2->set_background_color(1., 1., 0., 1.);
+  GuiLabel* b2l3 = GuiLabel::make_simple_text_label("jackel", font);
+  b2l3->set_foreground_color(1., 1., 1., 1.);
+  b2l3->set_background_color(0., 0., 0., 1.);
+  GuiButton* b2 = new GuiButton("jackel", b2l1, b2l2, b2l3, b2l3, b2l1);
+  b2->set_scale(0.1);
+  f1->add_item(b2);
+  GuiLabel* b3l1 = GuiLabel::make_simple_text_label("hyena", font);
+  b3l1->set_foreground_color(0., 0., 0., 1.);
+  b3l1->set_background_color(1., 1., 1., 1.);
+  GuiLabel* b3l2 = GuiLabel::make_simple_text_label("hyena", font);
+  b3l2->set_foreground_color(0., 0., 0., 1.);
+  b3l2->set_background_color(1., 1., 0., 1.);
+  GuiLabel* b3l3 = GuiLabel::make_simple_text_label("hyena", font);
+  b3l3->set_foreground_color(1., 1., 1., 1.);
+  b3l3->set_background_color(0., 0., 0., 1.);
+  GuiButton* b3 = new GuiButton("hyena", b3l1, b3l2, b3l3, b3l3, b3l1);
+  b3->set_scale(0.1);
+  f1->add_item(b3);
+  GuiLabel* b4l1 = GuiLabel::make_simple_text_label("wolf", font);
+  b4l1->set_foreground_color(0., 0., 0., 1.);
+  b4l1->set_background_color(1., 1., 1., 1.);
+  GuiLabel* b4l2 = GuiLabel::make_simple_text_label("wolf", font);
+  b4l2->set_foreground_color(0., 0., 0., 1.);
+  b4l2->set_background_color(1., 1., 0., 1.);
+  GuiLabel* b4l3 = GuiLabel::make_simple_text_label("wolf", font);
+  b4l3->set_foreground_color(1., 1., 1., 1.);
+  b4l3->set_background_color(0., 0., 0., 1.);
+  GuiButton* b4 = new GuiButton("wolf", b4l1, b4l2, b4l3, b4l3, b4l1);
+  b4->set_scale(0.1);
+  f1->add_item(b4);
+  GuiLabel* b5l1 = GuiLabel::make_simple_text_label("fox", font);
+  b5l1->set_foreground_color(0., 0., 0., 1.);
+  b5l1->set_background_color(1., 1., 1., 1.);
+  GuiLabel* b5l2 = GuiLabel::make_simple_text_label("fox", font);
+  b5l2->set_foreground_color(0., 0., 0., 1.);
+  b5l2->set_background_color(1., 1., 0., 1.);
+  GuiLabel* b5l3 = GuiLabel::make_simple_text_label("fox", font);
+  b5l3->set_foreground_color(1., 1., 1., 1.);
+  b5l3->set_background_color(0., 0., 0., 1.);
+  GuiButton* b5 = new GuiButton("fox", b5l1, b5l2, b5l3, b5l3, b5l1);
+  b5->set_scale(0.1);
+  f1->add_item(b5);
+  f1->pack_item(b2, GuiFrame::UNDER, b1);
+  f1->pack_item(b3, GuiFrame::UNDER, b2);
+  f1->pack_item(b4, GuiFrame::UNDER, b3);
+  f1->pack_item(b5, GuiFrame::UNDER, b4);
+  float w, w1, w2;
+  w1 = b1l1->get_width();
+  w2 = b2l1->get_width();
   w = (w1>w2)?w1:w2;
-  w = (w>w3)?w:w3;
-  w = (w>w4)?w:w4;
-  l1->set_width(w);
-  l2->set_width(w);
-  l3->set_width(w);
-  l4->set_width(w);
-  global_frame = f1;
+  w2 = b3l1->get_width();
+  w = (w>w2)?w:w2;
+  w2 = b4l1->get_width();
+  w = (w>w2)?w:w2;
+  w2 = b5l1->get_width();
+  w = (w>w2)?w:w2;
+  b1l1->set_width(w);
+  b1l2->set_width(w);
+  b1l3->set_width(w);
+  b2l1->set_width(w);
+  b2l2->set_width(w);
+  b2l3->set_width(w);
+  b3l1->set_width(w);
+  b3l2->set_width(w);
+  b3l3->set_width(w);
+  b4l1->set_width(w);
+  b4l2->set_width(w);
+  b4l3->set_width(w);
+  b5l1->set_width(w);
+  b5l2->set_width(w);
+  b5l3->set_width(w);
+  f1->manage(mgr, event_handler);
 }
 
 static void event_2(CPT_Event) {
@@ -204,16 +296,11 @@ static void event_2(CPT_Event) {
   }
 }
 
-static void event_3(CPT_Event) {
-  global_frame = (GuiFrame*)0L;
-}
-
 void demo_keys(EventHandler&) {
   new RenderRelation( lights, dlight );
   have_dlight = true;
 
   event_handler.add_hook("2", event_2);
-  event_handler.add_hook("3", event_3);
 }
 
 int main(int argc, char *argv[]) {