diff --git a/panda/src/gui/guiLabel.I b/panda/src/gui/guiLabel.I index 8b5c23edfe..5c81732ee4 100644 --- a/panda/src/gui/guiLabel.I +++ b/panda/src/gui/guiLabel.I @@ -7,7 +7,8 @@ INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE), _arc((RenderRelation*)0L), _tex((Texture*)0L), _internal((RenderRelation*)0L), - _gset((Geom*)0L), _scale(1.), + _gset((Geom*)0L), _model_width(1.), + _model_height(1.), _scale(1.), _pos(0., 0., 0.), _foreground(1., 1., 1., 1.), _have_background(false), diff --git a/panda/src/gui/guiLabel.cxx b/panda/src/gui/guiLabel.cxx index 54331c040d..02f84a12fc 100644 --- a/panda/src/gui/guiLabel.cxx +++ b/panda/src/gui/guiLabel.cxx @@ -226,10 +226,12 @@ GuiLabel* GuiLabel::make_simple_card_label(void) { return ret; } -GuiLabel* GuiLabel::make_model_label(Node* geom) { +GuiLabel* GuiLabel::make_model_label(Node* geom, float w, float h) { GuiLabel* ret = new GuiLabel(); ret->_type = MODEL; ret->_geom = new NamedNode("GUI label"); + ret->_model_width = w; + ret->_model_height = h; ret->_internal = new RenderRelation(ret->_geom, geom); ret->_internal->set_transition( new ColorTransition(Colorf(ret->_foreground))); @@ -320,10 +322,7 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) { } break; case SIMPLE_CARD: - case MODEL: { - // this really isn't correct for model, but will do until there is time - // or need for more float x = _pos.dot(LVector3f::rfu(1., 0., 0.)); float y = _pos.dot(LVector3f::rfu(0., 0., 1.)); l = _have_width?-(_width*0.5):-0.5; @@ -336,6 +335,20 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) { t += y; } break; + case MODEL: + { + float x = _pos.dot(LVector3f::rfu(1., 0., 0.)); + float y = _pos.dot(LVector3f::rfu(0., 0., 1.)); + l = _have_width?-(_width*_model_width*0.5):-(_model_width*0.5); + r = _have_width?(_width*_model_width*0.5):(_model_width*0.5); + l += x; + r += x; + b = _have_height?-(_height*_model_height*0.5):-(_model_height*0.5); + t = _have_height?(_height*_model_height*0.5):(_model_height*0.5); + b += y; + t += y; + } + break; default: gui_cat->warning() << "trying to get extents from something I don't know how to" << endl; diff --git a/panda/src/gui/guiLabel.h b/panda/src/gui/guiLabel.h index 0f863ad130..0b9ea1bbf7 100644 --- a/panda/src/gui/guiLabel.h +++ b/panda/src/gui/guiLabel.h @@ -33,6 +33,7 @@ private: PT(Texture) _tex; RenderRelation* _internal; Geom* _gset; + float _model_width, _model_height; float _scale; LVector3f _pos; @@ -65,7 +66,7 @@ PUBLISHED: static GuiLabel* make_simple_text_label(const string&, Node*, Texture* = (Texture*)0L); static GuiLabel* make_simple_card_label(void); - static GuiLabel* make_model_label(Node*); + static GuiLabel* make_model_label(Node*, float, float); int freeze(); int thaw(); diff --git a/panda/src/gui/guiRegion.I b/panda/src/gui/guiRegion.I index 805df2316d..27e13a324a 100644 --- a/panda/src/gui/guiRegion.I +++ b/panda/src/gui/guiRegion.I @@ -10,6 +10,8 @@ INLINE GuiRegion::GuiRegion(const string& name, float l, float r, float b, float t, bool buttons) : Namable(name), _left(l), _right(r), _bottom(b), _top(t) { + gui_cat->spam() << "region '" << name << "' constructed with (" << l + << ", " << r << ", " << b << ", " << t << ")" << endl; _region = new MouseWatcherRegion(name, l, r, b, t); _region->set_suppress_below(buttons); } @@ -35,6 +37,9 @@ INLINE void GuiRegion::set_region(float left, float right, float bottom, _right = right; _bottom = bottom; _top = top; + gui_cat->spam() << "reset region '" << this->get_name() << " to (" << left + << ", " << right << ", " << bottom << ", " << top << ")" + << endl; } INLINE LVector4f GuiRegion::get_frame(void) const { diff --git a/panda/src/gui/guiRegion.h b/panda/src/gui/guiRegion.h index 3b5957e689..5859aa8467 100644 --- a/panda/src/gui/guiRegion.h +++ b/panda/src/gui/guiRegion.h @@ -11,6 +11,8 @@ #include #include +#include "config_gui.h" + // container for active regions of a GUI class GuiManager; diff --git a/panda/src/testbed/gui_demo.cxx b/panda/src/testbed/gui_demo.cxx index f1899f6465..a09e54028b 100644 --- a/panda/src/testbed/gui_demo.cxx +++ b/panda/src/testbed/gui_demo.cxx @@ -661,11 +661,11 @@ static void test12(GuiManager* mgr, Node* font) { GuiLabel* l5 = GuiLabel::make_simple_text_label("none", font); */ PT_Node smile = ModelPool::load_model("smiley"); - GuiLabel* l1 = GuiLabel::make_model_label(smile); - GuiLabel* l2 = GuiLabel::make_model_label(smile); - GuiLabel* l3 = GuiLabel::make_model_label(smile); - GuiLabel* l4 = GuiLabel::make_model_label(smile); - GuiLabel* l5 = GuiLabel::make_model_label(smile); + GuiLabel* l1 = GuiLabel::make_model_label(smile, 0.25, 0.25); + GuiLabel* l2 = GuiLabel::make_model_label(smile, 0.25, 0.25); + GuiLabel* l3 = GuiLabel::make_model_label(smile, 0.25, 0.25); + GuiLabel* l4 = GuiLabel::make_model_label(smile, 0.25, 0.25); + GuiLabel* l5 = GuiLabel::make_model_label(smile, 0.25, 0.25); gb1 = new GuiButton("test12", l1, l2, l3, l4, l5); gb1->set_scale(0.1); gb1->set_pos(LVector3f::rfu(-0.25, 0., 0.25)); @@ -1034,7 +1034,7 @@ static void test17(GuiManager* mgr, Node* font) { ch1->add_item(s4); ch1->add_item(s5); PT_Node panel = ModelPool::load_model("phase_3/models/props/panel"); - GuiLabel* bgl = GuiLabel::make_model_label(panel); + GuiLabel* bgl = GuiLabel::make_model_label(panel, 0.1, 0.1); GuiBackground *bg = new GuiBackground("bg", ch1, bgl); bg->set_color(1., 0., 1., 1.); bg->thaw();