]> git.tdb.fi Git - r2c2.git/commitdiff
Load UI resources with constructor
authorMikko Rasa <tdb@tdb.fi>
Thu, 4 Nov 2010 07:30:41 +0000 (07:30 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Nov 2010 07:30:41 +0000 (07:30 +0000)
Make root and camera_ctl direct members

source/designer/designer.cpp
source/designer/designer.h

index 83164b5da169ba05aaf98876754208deec54b5b6..c071b5b4612d46d47d331d6545fd07da008e7483 100644 (file)
@@ -44,11 +44,14 @@ Application::RegApp<Designer> Designer::reg;
 
 Designer::Designer(int argc, char **argv):
        window(1280, 960),
+       ui_res("marklin.res"),
+       root(ui_res, window),
        base_object(0),
        cur_route(0),
        mode(SELECT),
        manipulator(*this, selection),
        measure(*this),
+       camera_ctl(*this, root, camera),
        track_wrap(*this, selection)
 {
        window.set_title("Railway Designer");
@@ -115,20 +118,18 @@ Designer::Designer(int argc, char **argv):
        camera.set_look_direction(GL::Vector3(0, 0.5, -0.866));
 
        // Setup UI
-       DataFile::load(ui_res, "marklin.res");
-       root = new GLtk::Root(ui_res, window);
-       root->signal_key_press.connect(sigc::mem_fun(this, &Designer::key_press));
-       root->signal_button_press.connect(sigc::mem_fun(this, &Designer::button_press));
-       root->signal_pointer_motion.connect(sigc::mem_fun(this, &Designer::pointer_motion));
-       root->signal_tooltip.connect(sigc::mem_fun(this, &Designer::tooltip));
+       root.signal_key_press.connect(sigc::mem_fun(this, &Designer::key_press));
+       root.signal_button_press.connect(sigc::mem_fun(this, &Designer::button_press));
+       root.signal_pointer_motion.connect(sigc::mem_fun(this, &Designer::pointer_motion));
+       root.signal_tooltip.connect(sigc::mem_fun(this, &Designer::tooltip));
 
        toolbar = new Toolbar(*this);
-       root->add(*toolbar);
+       root.add(*toolbar);
        toolbar->set_position(0, window.get_height()-toolbar->get_geometry().h);
        toolbar->set_focusable(false);
 
        GLtk::Panel *statusbar = new GLtk::Panel(ui_res);
-       root->add(*statusbar);
+       root.add(*statusbar);
        statusbar->set_size(window.get_width(), 20);
        statusbar->set_focusable(false);
 
@@ -138,8 +139,7 @@ Designer::Designer(int argc, char **argv):
 
        overlay = new Overlay3D(window, camera, ui_res.get_default_font());
 
-       camera_ctl = new CameraController(*this, *root, camera);
-       camera_ctl->view_all();
+       camera_ctl.view_all();
 
        const Layout3D::TrackMap &tracks = layout_3d->get_tracks();
        for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
@@ -148,9 +148,7 @@ Designer::Designer(int argc, char **argv):
 
 Designer::~Designer()
 {
-       delete camera_ctl;
        delete overlay;
-       delete root;
        delete pipeline;
        delete base_object;
        delete layout_3d;
@@ -266,9 +264,9 @@ void Designer::tick()
        float dt = (t-last_tick)/Msp::Time::sec;
        last_tick = t;
 
-       window.get_display().tick();
-       root->tick();
-       camera_ctl->tick(dt);
+       window.tick();
+       root.tick();
+       camera_ctl.tick(dt);
 
        for(list<Track *>::iterator i=new_tracks.begin(); i!=new_tracks.end(); ++i)
                layout_3d->get_track(**i).get_path().set_mask(0);
@@ -425,7 +423,7 @@ void Designer::pointer_motion(int x, int y)
 {
        y = window.get_height()-y-1;
 
-       if(!root->get_child_at(x, y))
+       if(!root.get_child_at(x, y))
        {
                Point ground = map_pointer_coords(x, y);
                manipulator.pointer_motion(x, y, ground.x, ground.y);
@@ -480,7 +478,7 @@ void Designer::render()
        GL::disable(GL::DEPTH_TEST);
 
        GL::Bind bind_blend(GL::Blend::alpha());
-       root->render();
+       root.render();
        GL::Texture::unbind();
 }
 
index 7ab3d1dc3a03cd3bad7a5fb7ee49875d50ecbbde..dbbd1923ca1b47a9fb6c42a0cac464253c574618 100644 (file)
@@ -47,7 +47,7 @@ private:
 
        Msp::Graphics::SimpleGLWindow window;
        Msp::GLtk::Resources ui_res;
-       Msp::GLtk::Root *root;
+       Msp::GLtk::Root root;
 
        Toolbar *toolbar;
        Msp::GLtk::Label *lbl_status;
@@ -70,7 +70,7 @@ private:
        Selection selection;
        Manipulator manipulator;
        Measure measure;
-       CameraController *camera_ctl;
+       CameraController camera_ctl;
        TrackWrap track_wrap;
 
        Msp::Time::TimeStamp last_tick;
@@ -90,7 +90,7 @@ public:
        Marklin::Layout3D &get_layout_3d() { return *layout_3d; }
        const Msp::GL::Camera &get_camera() const { return camera; }
        const Msp::GLtk::Resources &get_ui_resources() const { return ui_res; }
-       Msp::GLtk::Root &get_root() const { return *root; }
+       Msp::GLtk::Root &get_root() { return root; }
 
        void new_track();
        void set_turnout_id();