From d038acc35d15935a07f33d419d4973cb3c06d2a0 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 16 Nov 2000 00:15:38 +0000 Subject: [PATCH] more toys --- panda/src/gui/guiFrame.cxx | 23 +++++++++++++++ panda/src/gui/guiFrame.h | 1 + panda/src/testbed/deadrec_rec.cxx | 13 ++++++++- panda/src/testbed/deadrec_send.cxx | 47 +++++++++++++++++++++++++++++- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/panda/src/gui/guiFrame.cxx b/panda/src/gui/guiFrame.cxx index abc8c2dcf9..f9ec561eee 100644 --- a/panda/src/gui/guiFrame.cxx +++ b/panda/src/gui/guiFrame.cxx @@ -185,6 +185,29 @@ void GuiFrame::add_item(GuiItem* item) { } } +void GuiFrame::remove_item(GuiItem* item) { + Boxes::iterator i = find_box(item); + if (i == _items.end()) + return; + (*i).erase_all_links(); + // should NEVER link forward in the items, only backward, so it should be + // safe to start here, and go to the end + for (Boxes::iterator j=i+1; j!=_items.end(); ++j) { + bool done; + do { + done = true; + for (int k=0; k<(*j).get_num_links(); ++k) + if ((*j).get_nth_to(k) == item) { + done = false; + (*j).erase_nth_link(k); + break; + } + } while (!done); + } + // now get rid of the thing itself + _items.erase(i); +} + void GuiFrame::pack_item(GuiItem* item, Packing rel, GuiItem* to, float gap) { Boxes::iterator box = find_box(item); if (box == _items.end()) { diff --git a/panda/src/gui/guiFrame.h b/panda/src/gui/guiFrame.h index 0ff8af4a3a..7584b9ec36 100644 --- a/panda/src/gui/guiFrame.h +++ b/panda/src/gui/guiFrame.h @@ -76,6 +76,7 @@ public: ~GuiFrame(void); void add_item(GuiItem*); + void remove_item(GuiItem*); void pack_item(GuiItem*, Packing, GuiItem*, float = 0.); void clear_packing(GuiItem*); void clear_all_packing(void); diff --git a/panda/src/testbed/deadrec_rec.cxx b/panda/src/testbed/deadrec_rec.cxx index d5ea53750c..ff83e479ce 100644 --- a/panda/src/testbed/deadrec_rec.cxx +++ b/panda/src/testbed/deadrec_rec.cxx @@ -5,7 +5,18 @@ #include "framework.h" -void deadrec_keys(EventHandler& eh) { +static void deadrec_setup(void) { + static bool done = false; + if (done) + return; + // load smiley and put it in the scenegraph + smiley = ModelPool::load_model("smiley"); + nassertv(smiley != (Node*)0L); + my_arc = new RenderRelation(render, smiley); +} + +static void deadrec_keys(EventHandler& eh) { + deadrec_setup(); } int main(int argc, char* argv[]) { diff --git a/panda/src/testbed/deadrec_send.cxx b/panda/src/testbed/deadrec_send.cxx index 76dbe66130..68118d1c7b 100644 --- a/panda/src/testbed/deadrec_send.cxx +++ b/panda/src/testbed/deadrec_send.cxx @@ -5,7 +5,52 @@ #include "framework.h" -void deadrec_keys(EventHandler& eh) { +#include + +NotifyCategoryDecl(deadrec, EXPCL_MISC, EXPTP_MISC); +NotifyCategoryDef(deadrec, ""); + +Configure(deadrec); + +ConfigureFn(deadrec) { +} + +static PT_Node smiley; +static RenderRelation* my_arc; +string hostname = deadrec.GetString("deadrec-rec", "localhost"); +int hostport = deadrec.GetInt("deadrec-rec-port", 0xdead); + +static QueuedConnectionManager cm; +PT(Connection) conn; +ConnectionWriter* writer; + +static void deadrec_setup(void) { + static bool done = false; + if (done) + return; + // load smiley and put it in the scenegraph + smiley = ModelPool::load_model("smiley"); + nassertv(smiley != (Node*)0L); + my_arc = new RenderRelation(render, smiley); + // open a connection to the receiver + NetAddress host; + if (!host.set_host(hostname, port)) { + deadrec_cat->fatal() << "Unknown host: " << hostname << endl; + exit(); + } + conn = cm.open_TCP_client_connection(host, 5000); + if (conn.is_null()) { + deadrec_cat->fatal() << "no connection." << endl; + exit(); + } + if (deadrec->is_debug()) + deadrec->debug() << "opened TCP connection to " << hostname << " on port " + << c->get_address().get_port() << " and IP " + << c->get_address() << endl; + writer = new ConnectionWriter(&cm, 0); + +static void deadrec_keys(EventHandler& eh) { + deadrec_setup(); } int main(int argc, char* argv[]) {