From 68cc677b65c94fa15e8441baab59efec0dcd69a9 Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 26 Oct 2000 23:57:17 +0000 Subject: [PATCH] new file --- panda/src/gui/config_gui.cxx | 0 panda/src/gui/config_gui.h | 4 ++ panda/src/gui/guiManager.cxx | 79 ++++++++++++++++++++++++++++++++++ panda/src/testbed/gui_demo.cxx | 72 +++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 panda/src/gui/config_gui.cxx create mode 100644 panda/src/gui/config_gui.h create mode 100644 panda/src/gui/guiManager.cxx create mode 100644 panda/src/testbed/gui_demo.cxx diff --git a/panda/src/gui/config_gui.cxx b/panda/src/gui/config_gui.cxx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/panda/src/gui/config_gui.h b/panda/src/gui/config_gui.h new file mode 100644 index 0000000000..8b5e8957b8 --- /dev/null +++ b/panda/src/gui/config_gui.h @@ -0,0 +1,4 @@ +// Filename: config_gui.h +// Created by: cary (26Oct00) +// +//////////////////////////////////////////////////////////////////// diff --git a/panda/src/gui/guiManager.cxx b/panda/src/gui/guiManager.cxx new file mode 100644 index 0000000000..dba947f281 --- /dev/null +++ b/panda/src/gui/guiManager.cxx @@ -0,0 +1,79 @@ +// Filename: guiManager.cxx +// Created by: cary (25Oct00) +// +//////////////////////////////////////////////////////////////////// + +#include "guiManager.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +GuiManager::GuiMap* GuiManager::_map = (GuiManager::GuiMap*)0L; + +GuiManager* GuiManager::get_ptr(GraphicsWindow* w, MouseAndKeyboard* mak) { + GuiManager* ret; + if (_map == (GuiMap*)0L) + _map = new GuiMap; + GuiMap::const_iterator gi; + gi = _map->find(w); + if (gi != _map->end()) + ret = (*gi).second; + else { + // going to allocate a new GuiManager for this window + // first see if there is a mouseWatcher already under the MouseAndKeyboard + bool has_watcher = false; + TypeHandle dgt = DataRelation::get_class_type(); + MouseWatcher* watcher; + for (int i=0; iget_num_children(dgt); ++i) + if (mak->get_child(dgt, i)->get_child()->get_type() == + MouseWatcher::get_class_type()) { + has_watcher = true; + watcher = DCAST(MouseWatcher, mak->get_child(dgt, i)->get_child()); + } + if (!has_watcher) { + // there isn't already a mousewatcher in the data graph, so we'll make + // one and re-parent everything to it. + watcher = new MouseWatcher("GUI watcher"); + DataRelation* tmp = new DataRelation(mak, watcher); + for (int j=0; jget_num_children(dgt); ++j) { + NodeRelation* rel = mak->get_child(dgt, j); + if (rel != tmp) + // it's not the node we just created, so reparent it to ours + rel->change_parent(watcher); + } + } + // next, create a 2d layer for the GUI stuff to live in. + Node* root2d_top = new NamedNode("GUI_top"); + Node* root2d = new NamedNode("GUI"); + NodeRelation* root2d_arc = new RenderRelation(root2d_top, root2d); + root2d_arc->set_transition(new DepthTestTransition(DepthTestProperty::M_none), 1); + root2d_arc->set_transition(new DepthWriteTransition(DepthWriteTransition::off()), 1); + root2d_arc->set_transition(new LightTransition(LightTransition::all_off()), 1); + root2d_arc->set_transition(new MaterialTransition(MaterialTransition::off()), 1); + root2d_arc->set_transition(new CullFaceTransition(CullFaceProperty::M_cull_none), 1); + PT(Camera) cam = new Camera("GUI_cam"); + new RenderRelation(root2d, cam); + cam->set_scene(root2d_top); + Frustumf frust2d; + frust2d.make_ortho_2D(); + cam->set_projection(OrthoProjection(frust2d)); + GraphicsChannel *chan = w->get_channel(0); // root/full-window channel + nassertv(chan != (GraphicsChannel*)0L); + GraphicsLayer *layer = chan->make_layer(); + nassertv(layer != (GraphicsLayer*)0L); + DisplayRegion *dr = layer->make_display_region(); + nassertv(dr != (DisplayRegion*)0L); + dr->set_camera(cam); + // now make the manager for this window + ret = new GuiManager(watcher, root2d); + (*_map)[w] = ret; + } + return ret; +} diff --git a/panda/src/testbed/gui_demo.cxx b/panda/src/testbed/gui_demo.cxx new file mode 100644 index 0000000000..f9c10b4932 --- /dev/null +++ b/panda/src/testbed/gui_demo.cxx @@ -0,0 +1,72 @@ +#include "framework.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +//From framework +extern PT(GeomNode) geomnode; +extern RenderRelation* first_arc; + +static void setup_gui(void) { + GuiManager* mgr = GuiManager::get_ptr(main_win, mak); +} + +static void event_2(CPT_Event) { + static bool is_setup = false; + if (!is_setup) { + setup_gui(); + is_setup = true; + } +} + +void demo_keys(EventHandler&) { + new RenderRelation( lights, dlight ); + have_dlight = true; + + event_handler.add_hook("2", event_2); +} + +int main(int argc, char *argv[]) { + define_keys = &demo_keys; + return framework_main(argc, argv); +}