diff --git a/direct/src/gui/Button.py b/direct/src/gui/Button.py index d10a8feee9..9578dedd90 100644 --- a/direct/src/gui/Button.py +++ b/direct/src/gui/Button.py @@ -20,18 +20,22 @@ class Button(DirectObject): # up self.l1 = GuiLabel.GuiLabel.makeSimpleTextLabel(self.label, font) self.l1.setForegroundColor(0., 0., 0., 1.) + self.l1.thaw() # roll-over up self.l2 = GuiLabel.GuiLabel.makeSimpleTextLabel(self.label, font) self.l2.setForegroundColor(0., 0., 0., 1.) - self.l2.setBackgroundColor(1., 1., 0., 1.) + self.l2.setBackgroundColor(1., 1., 0., 1.) + self.l2.thaw() # roll-over down self.l3 = GuiLabel.GuiLabel.makeSimpleTextLabel(self.label, font) self.l3.setForegroundColor(1., 1., 1., 1.) self.l3.setBackgroundColor(0., 0., 0., 1.) + self.l3.thaw() self.button = GuiButton.GuiButton(self.name, self.l1, self.l2, self.l3, self.l3, self.l1) self.setScale(0.1) self.managed = 0 + return None def cleanup(self): @@ -44,6 +48,7 @@ class Button(DirectObject): def __str__(self): return "Button: %s" % self.name + def getName(self): return self.name @@ -62,6 +67,18 @@ class Button(DirectObject): self.l1.setWidth(width) self.l2.setWidth(width) self.l3.setWidth(width) + + def freeze(self): + self.l1.freeze() + self.l2.freeze() + self.l3.freeze() + self.button.freeze() + + def thaw(self): + self.l1.thaw() + self.l2.thaw() + self.l3.thaw() + self.button.thaw() def manage(self): self.button.manage(guiMgr, base.eventMgr.eventHandler) diff --git a/direct/src/gui/ForceAcknowledge.py b/direct/src/gui/ForceAcknowledge.py index ca8424871a..d021352127 100644 --- a/direct/src/gui/ForceAcknowledge.py +++ b/direct/src/gui/ForceAcknowledge.py @@ -52,10 +52,12 @@ class ForceAcknowledge(StateData.StateData): # create a message self.text = OnscreenText.OnscreenText("", 0.0, 0.25) + self.text.freeze() self.text.node().setAlign(0) self.text.node().setTextColor(0.0, 0.0, 0.0, 1.0) self.text.node().setFrameColor(1.0, 1.0, 1.0, 1.0) self.text.setScale(0.08) + self.text.thaw() # create a button self.okButton = Button.Button("ForceAcknowledge", "OK") diff --git a/direct/src/gui/Frame.py b/direct/src/gui/Frame.py index d778145206..8fc5b56d83 100644 --- a/direct/src/gui/Frame.py +++ b/direct/src/gui/Frame.py @@ -47,6 +47,12 @@ class Frame(DirectObject): self.offset = offset # actions + def freeze(self): + self.frame.freeze() + + def thaw(self): + self.frame.thaw() + def manage(self): self.frame.manage(guiMgr, base.eventMgr.eventHandler) self.managed = 1 diff --git a/direct/src/gui/OnscreenText.py b/direct/src/gui/OnscreenText.py index 2e5df5ab94..20dee6e96d 100644 --- a/direct/src/gui/OnscreenText.py +++ b/direct/src/gui/OnscreenText.py @@ -53,6 +53,12 @@ class OnscreenText(PandaObject, NodePath): self.isClean = 1 NodePath.__del__(self) return None + + def freeze(self): + self.textNode.freeze() + + def thaw(self): + self.textNode.thaw() def setText(self, string): """setText(self, string) diff --git a/direct/src/gui/ScrollingLabel.py b/direct/src/gui/ScrollingLabel.py index 57c363e557..087f3c6589 100644 --- a/direct/src/gui/ScrollingLabel.py +++ b/direct/src/gui/ScrollingLabel.py @@ -25,6 +25,7 @@ class ScrollingLabel(PandaObject.PandaObject): label = GuiLabel.GuiLabel.makeSimpleTextLabel(self.name, font) label.setForegroundColor(1., 0., 0., 1.) label.setBackgroundColor(1., 1., 1., 0.) + label.thaw() self.title = Sign.Sign(self.name, label) self.frame.addItem(self.title) @@ -36,6 +37,7 @@ class ScrollingLabel(PandaObject.PandaObject): label = GuiLabel.GuiLabel.makeSimpleTextLabel(longest, font) label.setForegroundColor(0., 0., 0., 1.) label.setBackgroundColor(1., 1., 1., 1.) + label.thaw() self.itemSign = Sign.Sign(longest, label) self.frame.addItem(self.itemSign) diff --git a/panda/src/gui/guiButton.cxx b/panda/src/gui/guiButton.cxx index 0e1a062c38..31e7b429ef 100644 --- a/panda/src/gui/guiButton.cxx +++ b/panda/src/gui/guiButton.cxx @@ -303,6 +303,32 @@ void GuiButton::unmanage(void) { GuiItem::unmanage(); } +int GuiButton::freeze() { + _up->freeze(); + _down->freeze(); + if (_up_rollover != (GuiLabel*)0L) + _up_rollover->freeze(); + if (_down_rollover != (GuiLabel*)0L) + _down_rollover->freeze(); + if (_inactive != (GuiLabel*)0L) + _inactive->freeze(); + + return 0; +} + +int GuiButton::thaw() { + _up->thaw(); + _down->thaw(); + if (_up_rollover != (GuiLabel*)0L) + _up_rollover->thaw(); + if (_down_rollover != (GuiLabel*)0L) + _down_rollover->thaw(); + if (_inactive != (GuiLabel*)0L) + _inactive->thaw(); + + return 0; +} + void GuiButton::set_scale(float f) { _up->set_scale(f * _up_scale); _down->set_scale(f * _down_scale); diff --git a/panda/src/gui/guiButton.h b/panda/src/gui/guiButton.h index 7890af2dea..e5f1e96110 100644 --- a/panda/src/gui/guiButton.h +++ b/panda/src/gui/guiButton.h @@ -48,6 +48,9 @@ public: virtual void unmanage(void); PUBLISHED: + virtual int freeze(); + virtual int thaw(); + INLINE void enter(void); INLINE void exit(void); INLINE void up(void); diff --git a/panda/src/gui/guiFrame.cxx b/panda/src/gui/guiFrame.cxx index e47b283f0c..717c944644 100644 --- a/panda/src/gui/guiFrame.cxx +++ b/panda/src/gui/guiFrame.cxx @@ -23,7 +23,11 @@ GuiFrame::Boxes::iterator GuiFrame::find_box(GuiItem* item) { void GuiFrame::recompute_frame(void) { GuiItem::recompute_frame(); + + freeze(); + Boxes::iterator i; + // go thru and make sure everything is packed correctly. This is a stupid // and brute-force algorithm. Hopefully it will be replaced with something // more ellegant later @@ -202,6 +206,8 @@ void GuiFrame::recompute_frame(void) { tmp = (*i).get_item()->get_top(); _top = (_topunmanage(); } +int GuiFrame::freeze() { + int result = 0; + Boxes::iterator i; + + for (i=_items.begin(); i!=_items.end(); ++i) { + GuiItem* here = (*i).get_item(); + int count = here->freeze(); + result = max(result, count); + } + + return result; +} + +int GuiFrame::thaw() { + int result = 0; + Boxes::iterator i; + + for (i=_items.begin(); i!=_items.end(); ++i) { + GuiItem* here = (*i).get_item(); + int count = here->thaw(); + result = max(result, count); + } + + return result; +} + void GuiFrame::add_item(GuiItem* item) { bool found = false; for (Boxes::iterator i=_items.begin(); (!found)&&(i!=_items.end()); ++i) diff --git a/panda/src/gui/guiFrame.h b/panda/src/gui/guiFrame.h index a8f154c010..0ee70f404a 100644 --- a/panda/src/gui/guiFrame.h +++ b/panda/src/gui/guiFrame.h @@ -84,6 +84,9 @@ PUBLISHED: GuiFrame(const string&); ~GuiFrame(void); + virtual int freeze(); + virtual int thaw(); + void add_item(GuiItem*); void remove_item(GuiItem*); void pack_item(GuiItem*, Packing, GuiItem*, float = 0.); diff --git a/panda/src/gui/guiItem.cxx b/panda/src/gui/guiItem.cxx index 7db6bd1eac..24d2f601b5 100644 --- a/panda/src/gui/guiItem.cxx +++ b/panda/src/gui/guiItem.cxx @@ -24,6 +24,14 @@ GuiItem::~GuiItem(void) { this->unmanage(); } +int GuiItem::freeze() { + return 0; +} + +int GuiItem::thaw() { + return 0; +} + void GuiItem::manage(GuiManager* mgr, EventHandler&) { test_ref_count_integrity(); _mgr = mgr; diff --git a/panda/src/gui/guiItem.h b/panda/src/gui/guiItem.h index 9a5585d817..00780fdc57 100644 --- a/panda/src/gui/guiItem.h +++ b/panda/src/gui/guiItem.h @@ -31,6 +31,9 @@ PUBLISHED: virtual void manage(GuiManager*, EventHandler&) = 0; virtual void unmanage(void) = 0; + virtual int freeze(); + virtual int thaw(); + virtual void set_scale(float) = 0; virtual void set_pos(const LVector3f&) = 0; INLINE void set_priority(const Priority); diff --git a/panda/src/gui/guiLabel.cxx b/panda/src/gui/guiLabel.cxx index ffad146ea2..ecdc4529f1 100644 --- a/panda/src/gui/guiLabel.cxx +++ b/panda/src/gui/guiLabel.cxx @@ -160,6 +160,10 @@ GuiLabel* GuiLabel::make_simple_text_label(const string& text, Node* font, TextNode* n = new TextNode("GUI label"); ret->_geom = n; ret->_tex = tex; + + // The GuiLabel is initially frozen at the time it is created. + n->freeze(); + n->set_font(font); n->set_align(TM_ALIGN_CENTER); n->set_text_color(ret->get_foreground_color()); @@ -172,6 +176,32 @@ GuiLabel* GuiLabel::make_simple_text_label(const string& text, Node* font, return ret; } +int GuiLabel::freeze() { + switch (_type) { + case SIMPLE_TEXT: + { + TextNode* n = DCAST(TextNode, _geom); + return n->freeze(); + } + + default: + return 0; + } +} + +int GuiLabel::thaw() { + switch (_type) { + case SIMPLE_TEXT: + { + TextNode* n = DCAST(TextNode, _geom); + return n->thaw(); + } + + default: + return 0; + } +} + void GuiLabel::get_extents(float& l, float& r, float& b, float& t) { switch (_type) { case SIMPLE_TEXT: diff --git a/panda/src/gui/guiLabel.h b/panda/src/gui/guiLabel.h index 9de2d5ddff..a810b94212 100644 --- a/panda/src/gui/guiLabel.h +++ b/panda/src/gui/guiLabel.h @@ -55,6 +55,9 @@ PUBLISHED: static GuiLabel* make_simple_text_label(const string&, Node*, Texture* = (Texture*)0L); + int freeze(); + int thaw(); + void get_extents(float&, float&, float&, float&); float get_width(void); float get_height(void); diff --git a/panda/src/gui/guiSign.cxx b/panda/src/gui/guiSign.cxx index 0f24cc9376..aa8d5ac7fc 100644 --- a/panda/src/gui/guiSign.cxx +++ b/panda/src/gui/guiSign.cxx @@ -40,6 +40,14 @@ void GuiSign::unmanage(void) { GuiItem::unmanage(); } +int GuiSign::freeze() { + return _sign->freeze(); +} + +int GuiSign::thaw() { + return _sign->thaw(); +} + void GuiSign::set_scale(float f) { _sign->set_scale(f * _sign_scale); GuiItem::set_scale(f); diff --git a/panda/src/gui/guiSign.h b/panda/src/gui/guiSign.h index d26a7b54ef..347badbf79 100644 --- a/panda/src/gui/guiSign.h +++ b/panda/src/gui/guiSign.h @@ -25,6 +25,9 @@ PUBLISHED: virtual void manage(GuiManager*, EventHandler&); virtual void unmanage(void); + virtual int freeze(); + virtual int thaw(); + virtual void set_scale(float); virtual void set_pos(const LVector3f&); diff --git a/panda/src/text/Sources.pp b/panda/src/text/Sources.pp index 6315338ff9..1c854ef376 100644 --- a/panda/src/text/Sources.pp +++ b/panda/src/text/Sources.pp @@ -10,7 +10,7 @@ config_text.cxx config_text.h textNode.I textNode.cxx textNode.h #define INSTALL_HEADERS \ - textNode.I textNode.h + config_text.h textNode.I textNode.h #define IGATESCAN all diff --git a/panda/src/text/textNode.I b/panda/src/text/textNode.I index 0348c439d3..f7789ad39d 100644 --- a/panda/src/text/textNode.I +++ b/panda/src/text/textNode.I @@ -26,6 +26,11 @@ //////////////////////////////////////////////////////////////////// INLINE int TextNode:: freeze() { + if (text_cat.is_debug()) { + text_cat.debug() + << "Freezing " << this->get_name() << ", level = " + << _freeze_level << "\n"; + } return _freeze_level++; } @@ -52,6 +57,11 @@ get_freeze_level() const { //////////////////////////////////////////////////////////////////// INLINE int TextNode:: thaw() { + if (text_cat.is_debug()) { + text_cat.debug() + << "Thawing " << this->get_name() << ", level = " + << _freeze_level-1 << "\n"; + } nassertr(_freeze_level > 0, _freeze_level); _freeze_level--; diff --git a/panda/src/text/textNode.h b/panda/src/text/textNode.h index 2e29a6a8dc..f4f1e51680 100644 --- a/panda/src/text/textNode.h +++ b/panda/src/text/textNode.h @@ -11,6 +11,8 @@ //////////////////////////////////////////////////////////////////// #include +#include "config_text.h" + #include #include #include