From 675a62e6cffa9f52aea464e7b1098e81723e3ecb Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 2 Nov 2000 21:46:51 +0000 Subject: [PATCH] fix frame packing calculation --- panda/src/gui/guiButton.cxx | 18 ++++++++++++++ panda/src/gui/guiButton.h | 2 ++ panda/src/gui/guiFrame.cxx | 45 ++++++++++++++++++++++++---------- panda/src/gui/guiFrame.h | 2 ++ panda/src/gui/guiItem.I | 5 ++++ panda/src/gui/guiItem.cxx | 15 +++++++++++- panda/src/gui/guiItem.h | 2 ++ panda/src/gui/guiLabel.I | 3 ++- panda/src/gui/guiLabel.cxx | 3 +++ panda/src/gui/guiRegion.I | 8 ++++++ panda/src/gui/guiRegion.h | 1 + panda/src/gui/guiRollover.cxx | 10 ++++++++ panda/src/gui/guiRollover.h | 2 ++ panda/src/testbed/gui_demo.cxx | 1 + 14 files changed, 102 insertions(+), 15 deletions(-) diff --git a/panda/src/gui/guiButton.cxx b/panda/src/gui/guiButton.cxx index b6790767c5..8e2f318832 100644 --- a/panda/src/gui/guiButton.cxx +++ b/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; +} diff --git a/panda/src/gui/guiButton.h b/panda/src/gui/guiButton.h index 624897d562..7e285ed09f 100644 --- a/panda/src/gui/guiButton.h +++ b/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" diff --git a/panda/src/gui/guiFrame.cxx b/panda/src/gui/guiFrame.cxx index 507a0b788b..14c74ec520 100644 --- a/panda/src/gui/guiFrame.cxx +++ b/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; jget_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; jset_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; } diff --git a/panda/src/gui/guiRegion.I b/panda/src/gui/guiRegion.I index e99da5db93..34e015eca3 100644 --- a/panda/src/gui/guiRegion.I +++ b/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); } diff --git a/panda/src/gui/guiRegion.h b/panda/src/gui/guiRegion.h index 8c0baaeb1b..2a02ba0be5 100644 --- a/panda/src/gui/guiRegion.h +++ b/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" diff --git a/panda/src/gui/guiRollover.cxx b/panda/src/gui/guiRollover.cxx index 25a30e392c..581ddd8f3c 100644 --- a/panda/src/gui/guiRollover.cxx +++ b/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; +} diff --git a/panda/src/gui/guiRollover.h b/panda/src/gui/guiRollover.h index e8e7cb9381..3c5ec1119d 100644 --- a/panda/src/gui/guiRollover.h +++ b/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" diff --git a/panda/src/testbed/gui_demo.cxx b/panda/src/testbed/gui_demo.cxx index 8da4e7e281..d1fcc7efbf 100644 --- a/panda/src/testbed/gui_demo.cxx +++ b/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) {