]> git.tdb.fi Git - r2c2.git/commitdiff
Only pick once per rendered frame
authorMikko Rasa <tdb@tdb.fi>
Fri, 23 Apr 2010 16:31:59 +0000 (16:31 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 23 Apr 2010 16:31:59 +0000 (16:31 +0000)
Don't add new routes to layout manually

source/designer/toolbar.cpp
source/engineer/engineer.cpp
source/engineer/engineer.h

index 36b4882a00a7878730ff850589b2e695333d0683..ee990ddb6d56bdd8569c2c2fcc9970fe1bd8baaa 100644 (file)
@@ -80,7 +80,6 @@ void Toolbar::route_selected(unsigned index, const string &)
        {
                Layout &layout = *designer.get_layout();
                Route *route = new Route(layout, format("Route %d", layout.get_routes().size()+1));
-               designer.get_layout()->add_route(*route);
                designer.edit_route(*route);
 
                const map<string, Route *> &routes = designer.get_layout()->get_routes();
index 897c7ca1ea8121f21d205a26d007b4ec35e26f8a..c8092872c4dc0e0b3314115329fabd8562d6b017 100644 (file)
@@ -50,7 +50,10 @@ Engineer::Engineer(int argc, char **argv):
        picking(false),
        picking_track(0),
        picking_entry(0),
-       picking_path(0)
+       picking_path(0),
+       pointer_x(0),
+       pointer_y(0),
+       pointer_moved(false)
 {
        // Setup GUI
        window.set_title("Railroad Engineer");
@@ -173,6 +176,31 @@ void Engineer::tick()
                overlay->render(0);
        }
 
+       if(pointer_moved)
+       {
+               pointer_moved = false;
+
+               if(picking)
+               {
+                       Track3D *track = pick_track(pointer_x, window.get_height()-pointer_y-1);
+                       if(track && &track->get_track()!=picking_track)
+                       {
+                               picking_track = &track->get_track();
+                               if(picking_entry>=0)
+                                       picking_entry = 0;
+
+                               delete picking_path;
+                               picking_path = new Path3D(*track);
+                               if(picking_entry>=0)
+                                       picking_path->set_mask(picking_track->get_type().get_endpoints()[picking_entry].paths);
+                               else
+                                       picking_path->set_mask(picking_track->get_type().get_paths());
+                               picking_path->set_color(GL::Color(0));
+                               picking_path->set_layer(1);
+                       }
+               }
+       }
+
        if(picking && picking_track && picking_entry>=0)
        {
                GL::PushMatrix push_mat;
@@ -255,25 +283,9 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned)
 
 void Engineer::pointer_motion(int x, int y)
 {
-       if(picking)
-       {
-               Track3D *track = pick_track(x, window.get_height()-y-1);
-               if(track && &track->get_track()!=picking_track)
-               {
-                       picking_track = &track->get_track();
-                       if(picking_entry>=0)
-                               picking_entry = 0;
-
-                       delete picking_path;
-                       picking_path = new Path3D(*track);
-                       if(picking_entry>=0)
-                               picking_path->set_mask(picking_track->get_type().get_endpoints()[picking_entry].paths);
-                       else
-                               picking_path->set_mask(picking_track->get_type().get_paths());
-                       picking_path->set_color(GL::Color(0));
-                       picking_path->set_layer(1);
-               }
-       }
+       pointer_x = x;
+       pointer_y = y;
+       pointer_moved = true;
 }
 
 void Engineer::view_all()
index 8ce848e8779f971f408c077729b032e1f298d6ef..dc7a7a02dddf64ca6712bc2986236961972aa70a 100644 (file)
@@ -61,6 +61,9 @@ private:
        Marklin::Track *picking_track;
        int picking_entry;
        Marklin::Path3D *picking_path;
+       int pointer_x;
+       int pointer_y;
+       bool pointer_moved;
 
 public:
        Engineer(int argc, char **argv);