From 7e08feb402d53654abf8b385128b7438b0ecc277 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Tue, 28 Nov 2000 19:07:02 +0000 Subject: [PATCH] ability to change label text --- panda/src/gui/guiLabel.cxx | 18 +++++++++ panda/src/gui/guiLabel.h | 2 + panda/src/testbed/gui_demo.cxx | 72 +++++++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/panda/src/gui/guiLabel.cxx b/panda/src/gui/guiLabel.cxx index 27b8f8926e..ffad146ea2 100644 --- a/panda/src/gui/guiLabel.cxx +++ b/panda/src/gui/guiLabel.cxx @@ -269,3 +269,21 @@ void GuiLabel::set_background_color(const Colorf& color) { _have_background = (color != zero); set_properties(); } + +void GuiLabel::set_text(const string& val) { + switch (_type) { + case SIMPLE_TEXT: + { + TextNode* n = DCAST(TextNode, _geom); + n->set_text(val); + } + break; + case SIMPLE_TEXTURE: + gui_cat->warning() << "tried to set text on a texture label" << endl; + break; + default: + gui_cat->warning() << "trying to set text on an unknown label type (" + << (int)_type << ")" << endl; + } + recompute(); +} diff --git a/panda/src/gui/guiLabel.h b/panda/src/gui/guiLabel.h index 7f359d579a..9de2d5ddff 100644 --- a/panda/src/gui/guiLabel.h +++ b/panda/src/gui/guiLabel.h @@ -77,6 +77,8 @@ PUBLISHED: INLINE Colorf get_foreground_color(void) const; INLINE Colorf get_background_color(void) const; + void set_text(const string&); + INLINE void recompute(void); public: diff --git a/panda/src/testbed/gui_demo.cxx b/panda/src/testbed/gui_demo.cxx index e7aa66b9bd..f6ff203ee5 100644 --- a/panda/src/testbed/gui_demo.cxx +++ b/panda/src/testbed/gui_demo.cxx @@ -409,6 +409,7 @@ static void test7(GuiManager* mgr, Node* font) { } */ +/* GuiManager* g_mgr; PT(GuiSign) s1; PT(GuiSign) s4; @@ -471,6 +472,60 @@ static void test8(GuiManager* mgr, Node* font) { f1->recompute(); f1->manage(mgr, event_handler); } +*/ + +GuiManager* g_mgr; +PT(GuiLabel) l4; +PT(GuiFrame) f1; +static bool frame_state = true; + +static void test9(GuiManager* mgr, Node* font) { + f1 = new GuiFrame("canids"); + GuiLabel* l1 = GuiLabel::make_simple_text_label("dingo", font); + l1->set_foreground_color(0., 0., 0., 1.); + l1->set_background_color(1., 1., 1., 1.); + GuiSign* s1 = new GuiSign("dingo", l1); + s1->set_scale(0.1); + f1->add_item(s1); + GuiLabel* l2 = GuiLabel::make_simple_text_label("jackel", font); + l2->set_foreground_color(0., 0., 0., 1.); + l2->set_background_color(1., 1., 1., 1.); + GuiSign* s2 = new GuiSign("jackel", l2); + s2->set_scale(0.1); + f1->add_item(s2); + GuiLabel* l3 = GuiLabel::make_simple_text_label("hyena", font); + l3->set_foreground_color(0., 0., 0., 1.); + l3->set_background_color(1., 1., 1., 1.); + GuiSign* s3 = new GuiSign("jackel", l3); + s3->set_scale(0.1); + f1->add_item(s3); + l4 = GuiLabel::make_simple_text_label("wolf", font); + l4->set_foreground_color(0., 0., 0., 1.); + l4->set_background_color(1., 1., 1., 1.); + GuiSign* s4 = new GuiSign("wolf", l4); + s4->set_scale(0.1); + f1->add_item(s4); + f1->pack_item(s2, GuiFrame::UNDER, s1); + f1->pack_item(s2, GuiFrame::LEFT, s1); + f1->pack_item(s3, GuiFrame::UNDER, s1); + f1->pack_item(s3, GuiFrame::RIGHT, s1); + f1->pack_item(s4, GuiFrame::UNDER, s1); + f1->pack_item(s4, GuiFrame::ALIGN_LEFT, s1); + float w, w1, w2; + w1 = l1->get_width(); + w2 = l2->get_width(); + w = (w1>w2)?w1:w2; + w2 = l3->get_width(); + w = (w>w2)?w:w2; + w2 = l4->get_width(); + w = (w>w2)?w:w2; + l1->set_width(w); + l2->set_width(w); + l3->set_width(w); + l4->set_width(w); + f1->recompute(); + f1->manage(mgr, event_handler); +} static void setup_gui(void) { GuiManager* mgr = GuiManager::get_ptr(main_win, mak); @@ -491,7 +546,9 @@ static void setup_gui(void) { // test7(mgr, font); // g_mgr = mgr; // test 8 - test8(mgr, font); + // test8(mgr, font); + // test 9 + test9(mgr, font); g_mgr = mgr; } @@ -524,6 +581,7 @@ static void event_3(CPT_Event) { } */ +/* // for test 8 static void event_3(CPT_Event) { if (frame_state) { @@ -542,6 +600,18 @@ static void event_3(CPT_Event) { f1->recompute(); frame_state = !frame_state; } +*/ + +// for test 9 +static void event_3(CPT_Event) { + if (frame_state) { + l4->set_text("fox"); + } else { + l4->set_text("wolf"); + } + f1->recompute(); + frame_state = !frame_state; +} void gui_keys(EventHandler&) { new RenderRelation( lights, dlight );