From 67faa460e785c6b06b3c303dc012859af8ba3116 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Wed, 8 Nov 2000 19:50:33 +0000 Subject: [PATCH] add label color setting --- panda/src/gui/guiLabel.I | 27 ++++- panda/src/gui/guiLabel.cxx | 55 +++++++++- panda/src/gui/guiLabel.h | 13 +++ panda/src/testbed/gui_demo.cxx | 186 +++++++++++++++++---------------- 4 files changed, 188 insertions(+), 93 deletions(-) diff --git a/panda/src/gui/guiLabel.I b/panda/src/gui/guiLabel.I index a2b0a738a0..f1b7304544 100644 --- a/panda/src/gui/guiLabel.I +++ b/panda/src/gui/guiLabel.I @@ -6,7 +6,10 @@ INLINE GuiLabel::GuiLabel(void) : _type(GuiLabel::NONE), _scale(1.), _pos(0., 0., 0.), _tex((Texture*)0L), _arc((RenderRelation*)0L), - _internal((RenderRelation*)0L) { + _internal((RenderRelation*)0L), + _foreground(1., 1., 1., 1.), + _background(0., 0., 0., 0.), + _have_background(false) { } INLINE Node* GuiLabel::get_geometry(void) const { @@ -26,6 +29,10 @@ INLINE void GuiLabel::set_scale(float f) { recompute_transform(); } +INLINE void GuiLabel::set_pos(float x, float y, float z) { + this->set_pos(LVector3f(x, y, z)); +} + INLINE void GuiLabel::set_pos(const LVector3f& p) { _pos = p; recompute_transform(); @@ -38,3 +45,21 @@ INLINE float GuiLabel::get_scale(void) const { INLINE LVector3f GuiLabel::get_pos(void) const { return _pos; } + +INLINE void GuiLabel::set_foreground_color(float r, float g, float b, + float a) { + this->set_foreground_color(Colorf(r, g, b, a)); +} + +INLINE void GuiLabel::set_background_color(float r, float g, float b, + float a) { + this->set_background_color(Colorf(r, g, b, a)); +} + +INLINE Colorf GuiLabel::get_foreground_color(void) const { + return _foreground; +} + +INLINE Colorf GuiLabel::get_background_color(void) const { + return _background; +} diff --git a/panda/src/gui/guiLabel.cxx b/panda/src/gui/guiLabel.cxx index a679c20ebc..b126097e11 100644 --- a/panda/src/gui/guiLabel.cxx +++ b/panda/src/gui/guiLabel.cxx @@ -7,6 +7,7 @@ #include #include +#include void GuiLabel::recompute_transform(void) { switch (_type) { @@ -29,6 +30,39 @@ void GuiLabel::recompute_transform(void) { gui_cat->warning() << "recompute_transform on invalid label type (" << _type << ")" << endl; } + set_properties(); +} + +void GuiLabel::set_properties(void) { + switch (_type) { + case SIMPLE_TEXT: + { + TextNode* n = DCAST(TextNode, _geom); + 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); + 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; + case SIMPLE_TEXTURE: + _internal->set_transition(new ColorTransition(_foreground)); + break; + default: + gui_cat->warning() << "recompute_transform on invalid label type (" + << _type << ")" << endl; + } } GuiLabel::~GuiLabel(void) { @@ -98,7 +132,7 @@ GuiLabel* GuiLabel::make_simple_text_label(const string& text, Node* font) { ret->_geom = n; n->set_font(font); n->set_align(TM_ALIGN_CENTER); - n->set_text_color(1., 1., 1., 1.); + n->set_text_color(ret->get_foreground_color()); n->set_text(text); ret->set_scale(1.); ret->set_pos(LVector3f(0., 0., 0.)); @@ -158,3 +192,22 @@ void GuiLabel::get_extents(float& l, float& r, float& b, float& t) { r = t = 1.; } } + +void GuiLabel::set_foreground_color(const Colorf& color) { + _foreground = color; + set_properties(); +} + +void GuiLabel::set_background_color(const Colorf& color) { + static Colorf zero(0., 0., 0., 0.); + + _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(); +} diff --git a/panda/src/gui/guiLabel.h b/panda/src/gui/guiLabel.h index 828654ef6d..8bc83367ee 100644 --- a/panda/src/gui/guiLabel.h +++ b/panda/src/gui/guiLabel.h @@ -29,6 +29,9 @@ private: float _scale; LVector3f _pos; + Colorf _foreground; + bool _have_background; + Colorf _background; INLINE Node* get_geometry(void) const; INLINE void set_arc(RenderRelation*); @@ -37,6 +40,7 @@ private: friend GuiManager; void recompute_transform(void); + void set_properties(void); public: INLINE GuiLabel(void); virtual ~GuiLabel(void); @@ -47,10 +51,19 @@ public: void get_extents(float&, float&, float&, float&); INLINE void set_scale(float); + INLINE void set_pos(float, float, float); INLINE void set_pos(const LVector3f&); INLINE float get_scale(void) const; INLINE LVector3f get_pos(void) const; + + INLINE void set_foreground_color(float, float, float, float); + void set_foreground_color(const Colorf&); + INLINE void set_background_color(float, float, float, float); + void set_background_color(const Colorf&); + + INLINE Colorf get_foreground_color(void) const; + INLINE Colorf get_background_color(void) const; }; #include "guiLabel.I" diff --git a/panda/src/testbed/gui_demo.cxx b/panda/src/testbed/gui_demo.cxx index 3885f5ef9f..40966a8f81 100644 --- a/panda/src/testbed/gui_demo.cxx +++ b/panda/src/testbed/gui_demo.cxx @@ -65,98 +65,102 @@ static void setup_gui(void) { // r1->set_pos(LVector3f::rfu(0.25, 0., 0.25)); // r1->manage(mgr, event_handler); // test 3 - // GuiLabel* l1 = GuiLabel::make_simple_text_label("up", font); - // GuiLabel* l2 = GuiLabel::make_simple_text_label("upr", font); - // GuiLabel* l3 = GuiLabel::make_simple_text_label("down", font); - // GuiLabel* l4 = GuiLabel::make_simple_text_label("downr", font); - // GuiLabel* l5 = GuiLabel::make_simple_text_label("none", font); - // GuiButton* b1 = new GuiButton("test3", l1, l2, l3, l4, l5); - // b1->set_scale(0.1); - // b1->set_pos(LVector3f::rfu(-0.25, 0., 0.25)); - // b1->manage(mgr, event_handler); + GuiLabel* l1 = GuiLabel::make_simple_text_label("up", font); + GuiLabel* l2 = GuiLabel::make_simple_text_label("upr", font); + GuiLabel* l3 = GuiLabel::make_simple_text_label("down", font); + GuiLabel* l4 = GuiLabel::make_simple_text_label("downr", font); + GuiLabel* l5 = GuiLabel::make_simple_text_label("none", font); + GuiButton* b1 = new GuiButton("test3", l1, l2, l3, l4, l5); + b1->set_scale(0.1); + b1->set_pos(LVector3f::rfu(-0.25, 0., 0.25)); + l2->set_foreground_color(1., 1., 0., 1.); + l4->set_foreground_color(1., 1., 0., 1.); + l3->set_background_color(1., 1., 1., 0.5); + l4->set_background_color(1., 1., 1., 0.5); + b1->manage(mgr, event_handler); // test 4 - GuiRollover* r1 = new GuiRollover("r1", - GuiLabel::make_simple_text_label("1", - font), - GuiLabel::make_simple_text_label("!", - font)); - GuiRollover* r2 = new GuiRollover("r2", - GuiLabel::make_simple_text_label("2", - font), - GuiLabel::make_simple_text_label("@", - font)); - GuiRollover* r3 = new GuiRollover("r3", - GuiLabel::make_simple_text_label("3", - font), - GuiLabel::make_simple_text_label("#", - font)); - GuiRollover* r4 = new GuiRollover("r4", - GuiLabel::make_simple_text_label("4", - font), - GuiLabel::make_simple_text_label("$", - font)); - GuiRollover* r5 = new GuiRollover("r5", - GuiLabel::make_simple_text_label("5", - font), - GuiLabel::make_simple_text_label("%", - font)); - GuiRollover* r6 = new GuiRollover("r6", - GuiLabel::make_simple_text_label("6", - font), - GuiLabel::make_simple_text_label("^", - font)); - GuiRollover* r7 = new GuiRollover("r7", - GuiLabel::make_simple_text_label("7", - font), - GuiLabel::make_simple_text_label("&", - font)); - GuiRollover* r8 = new GuiRollover("r8", - GuiLabel::make_simple_text_label("8", - font), - GuiLabel::make_simple_text_label("*", - font)); - GuiRollover* r9 = new GuiRollover("r9", - GuiLabel::make_simple_text_label("9", - font), - GuiLabel::make_simple_text_label("(", - font)); - GuiRollover* r0 = new GuiRollover("r0", - GuiLabel::make_simple_text_label("0", - font), - GuiLabel::make_simple_text_label(")", - font)); - GuiFrame* f1 = new GuiFrame("test4"); - f1->add_item(r1); - f1->add_item(r2); - f1->pack_item(r2, GuiFrame::UNDER, r1); - f1->pack_item(r2, GuiFrame::RIGHT, r1); - f1->add_item(r3); - f1->pack_item(r3, GuiFrame::UNDER, r2); - f1->pack_item(r3, GuiFrame::RIGHT, r2); - f1->add_item(r4); - f1->pack_item(r4, GuiFrame::UNDER, r3); - f1->pack_item(r4, GuiFrame::RIGHT, r2); - f1->add_item(r5); - f1->pack_item(r5, GuiFrame::UNDER, r4); - f1->pack_item(r5, GuiFrame::LEFT, r4); - f1->add_item(r6); - f1->pack_item(r6, GuiFrame::UNDER, r5); - f1->pack_item(r6, GuiFrame::LEFT, r5); - f1->add_item(r7); - f1->pack_item(r7, GuiFrame::ABOVE, r6); - f1->pack_item(r7, GuiFrame::LEFT, r6); - f1->add_item(r8); - f1->pack_item(r8, GuiFrame::ABOVE, r7); - f1->pack_item(r8, GuiFrame::LEFT, r7); - f1->add_item(r9); - f1->pack_item(r9, GuiFrame::ABOVE, r8); - f1->pack_item(r9, GuiFrame::LEFT, r7); - f1->add_item(r0); - f1->pack_item(r0, GuiFrame::ABOVE, r9); - f1->pack_item(r0, GuiFrame::RIGHT, r9); - f1->set_scale(0.1); - f1->set_pos(LVector3f::rfu(0., 0., -0.25)); - f1->manage(mgr, event_handler); + // GuiRollover* r1 = new GuiRollover("r1", + // GuiLabel::make_simple_text_label("1", + // font), + // GuiLabel::make_simple_text_label("!", + // font)); + // GuiRollover* r2 = new GuiRollover("r2", + // GuiLabel::make_simple_text_label("2", + // font), + // GuiLabel::make_simple_text_label("@", + // font)); + // GuiRollover* r3 = new GuiRollover("r3", + // GuiLabel::make_simple_text_label("3", + // font), + // GuiLabel::make_simple_text_label("#", + // font)); + // GuiRollover* r4 = new GuiRollover("r4", + // GuiLabel::make_simple_text_label("4", + // font), + // GuiLabel::make_simple_text_label("$", + // font)); + // GuiRollover* r5 = new GuiRollover("r5", + // GuiLabel::make_simple_text_label("5", + // font), + // GuiLabel::make_simple_text_label("%", + // font)); + // GuiRollover* r6 = new GuiRollover("r6", + // GuiLabel::make_simple_text_label("6", + // font), + // GuiLabel::make_simple_text_label("^", + // font)); + // GuiRollover* r7 = new GuiRollover("r7", + // GuiLabel::make_simple_text_label("7", + // font), + // GuiLabel::make_simple_text_label("&", + // font)); + // GuiRollover* r8 = new GuiRollover("r8", + // GuiLabel::make_simple_text_label("8", + // font), + // GuiLabel::make_simple_text_label("*", + // font)); + // GuiRollover* r9 = new GuiRollover("r9", + // GuiLabel::make_simple_text_label("9", + // font), + // GuiLabel::make_simple_text_label("(", + // font)); + // GuiRollover* r0 = new GuiRollover("r0", + // GuiLabel::make_simple_text_label("0", + // font), + // GuiLabel::make_simple_text_label(")", + // font)); + // GuiFrame* f1 = new GuiFrame("test4"); + // f1->add_item(r1); + // f1->add_item(r2); + // f1->pack_item(r2, GuiFrame::UNDER, r1); + // f1->pack_item(r2, GuiFrame::RIGHT, r1); + // f1->add_item(r3); + // f1->pack_item(r3, GuiFrame::UNDER, r2); + // f1->pack_item(r3, GuiFrame::RIGHT, r2); + // f1->add_item(r4); + // f1->pack_item(r4, GuiFrame::UNDER, r3); + // f1->pack_item(r4, GuiFrame::RIGHT, r2); + // f1->add_item(r5); + // f1->pack_item(r5, GuiFrame::UNDER, r4); + // f1->pack_item(r5, GuiFrame::LEFT, r4); + // f1->add_item(r6); + // f1->pack_item(r6, GuiFrame::UNDER, r5); + // f1->pack_item(r6, GuiFrame::LEFT, r5); + // f1->add_item(r7); + // f1->pack_item(r7, GuiFrame::ABOVE, r6); + // f1->pack_item(r7, GuiFrame::LEFT, r6); + // f1->add_item(r8); + // f1->pack_item(r8, GuiFrame::ABOVE, r7); + // f1->pack_item(r8, GuiFrame::LEFT, r7); + // f1->add_item(r9); + // f1->pack_item(r9, GuiFrame::ABOVE, r8); + // f1->pack_item(r9, GuiFrame::LEFT, r7); + // f1->add_item(r0); + // f1->pack_item(r0, GuiFrame::ABOVE, r9); + // f1->pack_item(r0, GuiFrame::RIGHT, r9); + // f1->set_scale(0.1); + // f1->set_pos(LVector3f::rfu(0., 0., -0.25)); + // f1->manage(mgr, event_handler); // cerr << *f1; }