00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 #include "sim_view_box.hpp"
00035 #include "main_window.hpp"
00036 
00037 #include "framework/application.hpp"
00038 #include "scenegraph/node.hpp"
00039 #include "space/galaxy.hpp"
00040 #include "space/solar_system.hpp"
00041 #include "space/star.hpp"
00042 #include "space/planet_system.hpp"
00043 #include "space/large_rocky_body.hpp"
00044 
00045 
00046 using namespace gsgl;
00047 using namespace gsgl::data;
00048 using namespace gsgl::platform;
00049 using namespace gsgl::framework;
00050 
00051 
00052 namespace periapsis
00053 {
00054 
00055     using namespace space;
00056 
00057 
00058 
00059     sim_view_box::sim_view_box(gsgl::framework::widget *parent, 
00060                                int x, int y, int w, int h, 
00061                                const color & fg, const color & bg)
00062         : widget(parent, x, y, w, h, fg, bg), title_box(0), scenery_box(0)
00063     {
00064         int title_height = 4 + main_window::FONT_SIZE * 3 / 2;
00065 
00066         title_box = new textbox(this, 
00067                                 0, h - title_height, 
00068                                 w, title_height,
00069                                 fg, bg, main_window::FONT_FACE, main_window::FONT_SIZE * 4 / 3);
00070         title_box->get_text() = L"Viewpoint";
00071 
00072         scenery_box = new treebox(this,
00073                                   0, 0,
00074                                   w, h - (title_height + 4),
00075                                   fg, bg, main_window::FONT_FACE, main_window::FONT_SIZE);
00076 
00077     } 
00078 
00079     sim_view_box::~sim_view_box()
00080     {
00081     } 
00082 
00083 
00084     
00085 
00086     void sim_view_box::load_scenery_info()
00087     {
00088         scenery_box->clear_tree_nodes();
00089 
00090         scenegraph::node *scenery_root = application::global_instance()->get_global_scenery();
00091         if (scenery_root)
00092         {
00093             load_scenery_info(scenery_root, scenery_box, 0);
00094         }
00095     } 
00096 
00097 
00098     treebox_node *sim_view_box::load_scenery_info(scenegraph::node *n, treebox *box, treebox_node *parent_node)
00099     {
00100         treebox_node *new_node = 0;
00101 
00102         if (dynamic_cast<space::solar_system *>(n))
00103         {
00104             new_node = new treebox_node(box, parent_node, main_window::FOREGROUND, main_window::BACKGROUND, n->get_name(), n);
00105             new_node->get_expanded() = true;
00106             parent_node = new_node;
00107         }
00108         else if (dynamic_cast<space::gas_body *>(n) || dynamic_cast<space::large_rocky_body *>(n))
00109         {
00110             new_node = new treebox_node(box, parent_node, main_window::FOREGROUND, main_window::BACKGROUND, n->get_name(), n);
00111         }
00112 
00113         
00114         treebox_node *system_primary = 0;
00115         for (simple_array<scenegraph::node *>::iterator i = n->get_children().iter(); i.is_valid(); ++i)
00116         {
00117             treebox_node *child_node = load_scenery_info(*i, box, system_primary ? system_primary : parent_node);
00118 
00119             if (dynamic_cast<space::planet_system *>(n) && !system_primary)
00120                 system_primary = child_node;
00121         }
00122 
00123         return new_node;
00124     } 
00125 
00126 }