X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fcontrolpanel.cpp;h=cc2fa079fbebc03bd984ee8d74e4b44380f20a9e;hb=15e67d19ed780cc7ebc0e7adb76feb218eb1ab8c;hp=050b37623fb98c472294c75078ea325f39e98312;hpb=77db8741430ca462e3b624dd42d5ead96be7f264;p=r2c2.git diff --git a/source/engineer/controlpanel.cpp b/source/engineer/controlpanel.cpp index 050b376..cc2fa07 100644 --- a/source/engineer/controlpanel.cpp +++ b/source/engineer/controlpanel.cpp @@ -16,7 +16,8 @@ using namespace R2C2; ControlPanel::ControlPanel(Engineer &e, Train &t): engineer(e), train(t), - updating(false) + updating(false), + placing(false) { Loader::WidgetMap widgets; DataFile::load(*this, "data/controlpanel.ui", widgets); @@ -35,6 +36,7 @@ ControlPanel::ControlPanel(Engineer &e, Train &t): for(VehicleType::FunctionMap::const_iterator i=funcs.begin(); i!=funcs.end(); ++i) { GLtk::Toggle *tgl = new GLtk::Toggle(i->second); + tgl->set_value(train.get_function(i->first)); tgl->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &ControlPanel::ui_function_toggled), i->first)); pnl_functions->add(*tgl); tgl_funcs[i->first] = tgl; @@ -75,12 +77,8 @@ void ControlPanel::take_clicked() void ControlPanel::view_clicked() { - GLtk::Container *root = parent; - while(root->get_parent()) - root = root->get_parent(); - TrainView *dlg = new TrainView(engineer, train); - root->add(*dlg); + find_ancestor()->add(*dlg); dlg->autosize(); } @@ -112,12 +110,27 @@ void ControlPanel::pointer_motion(int x, int y) int ry = y; map_coords_to_ancestor(rx, ry, *find_ancestor()); Ray ray = engineer.get_main_view().create_ray(rx, ry); + Vector ground = ray.get_start()-ray.get_direction()*ray.get_start().z/ray.get_direction().z; Track *track = engineer.get_layout().pick(ray); if(track) { - place_location = TrackIter(track, 0).block_iter(); - if(place_location) + const vector &eps = track->get_block().get_endpoints(); + int closest_ep = -1; + float closest_dist = -1; + for(unsigned i=0; iget_snap_node(eps[i].track_ep); + float d = (sn.position-ground).norm(); + if(d=0) { + place_location = BlockIter(&track->get_block(), closest_ep); ghosts.back()->place(place_location.track_iter()); for(unsigned i=ghosts.size()-1; i--; ) ghosts[i]->place_before(*ghosts[i+1]);