X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fremote%2Ftrainpanel.cpp;h=58dcd676a86d2d7af0c8e90a26abce6cba6706f7;hb=9b8a32cf7371bc5fae8ce239a212469511c459e6;hp=e3db1badb3cfcd0c5451216c5497daf09ef7110c;hpb=010d8321e982d1684fcbff5bf6fc2bdec7cb7bae;p=r2c2.git diff --git a/source/remote/trainpanel.cpp b/source/remote/trainpanel.cpp index e3db1ba..58dcd67 100644 --- a/source/remote/trainpanel.cpp +++ b/source/remote/trainpanel.cpp @@ -1,83 +1,98 @@ -/* $Id$ - -This file is part of the MSP Märklin suite -Copyright © 2009 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - -#include -#include "libmarklin/locotype.h" +#include +#include +#include +#include +#include +#include +#include +#include "network/client.h" #include "trainpanel.h" using namespace std; +using namespace Msp; +using namespace R2C2; -TrainPanel::TrainPanel(Marklin::NetTrain &t): - train(t) +TrainPanel::TrainPanel(NetTrain &t): + train(t), + updating(false) { - train.signal_name_changed.connect(sigc::mem_fun(this, &TrainPanel::name_changed)); - train.signal_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::speed_changed)); - train.signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::function_changed)); - train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::status_changed)); + Loader::WidgetMap widgets; + DataFile::load(*this, "data/remote/trainpanel.ui", widgets); - set_label(train.get_name()); + Msp::GLtk::Button *btn = dynamic_cast(get_item(widgets, "btn_forward")); + btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(&train, &NetTrain::set_reverse), false)); + btn = dynamic_cast(get_item(widgets, "btn_reverse")); + btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(&train, &NetTrain::set_reverse), true)); - Gtk::VBox *vbox = new Gtk::VBox(false, 5); - add(*manage(vbox)); - vbox->set_border_width(5); + ind_forward = dynamic_cast(get_item(widgets, "ind_forward")); + ind_reverse = dynamic_cast(get_item(widgets, "ind_reverse")); - vbox->add(*manage(scl_speed = new Gtk::HScale)); - scl_speed->set_digits(0); - scl_speed->set_range(0, 14); - scl_speed->set_increments(1, 1); - scl_speed->set_size_request(280, -1); - scl_speed->signal_value_changed().connect(sigc::mem_fun(this, &TrainPanel::ui_speed_changed)); + sld_speed = dynamic_cast(get_item(widgets, "sld_speed")); + sld_speed->set_range(0, train.get_loco_type().get_maximum_speed()/train.get_client().get_catalogue().get_scale()*3.6); + sld_speed->signal_value_changed.connect(sigc::mem_fun(this, &TrainPanel::ui_speed_changed)); - Gtk::HBox *func_box = new Gtk::HBox(false, 5); - vbox->add(*manage(func_box)); - const std::map &funcs = train.get_loco_type().get_functions(); - for(std::map::const_iterator i=funcs.begin(); i!=funcs.end(); ++i) + lbl_speed = dynamic_cast(get_item(widgets, "lbl_speed")); + + lbl_status = dynamic_cast(get_item(widgets, "lbl_status")); + train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::status_changed)); + lbl_status->set_text(train.get_status()); + + GLtk::Panel *pnl_functions = dynamic_cast(get_item(widgets, "pnl_functions")); + const VehicleType::FunctionMap &functions = train.get_loco_type().get_functions(); + GLtk::Column column(*pnl_functions->get_layout()); + for(VehicleType::FunctionMap::const_iterator i=functions.begin(); i!=functions.end(); ++i) { - Gtk::CheckButton *&chk = chk_funcs[i->first]; - chk = new Gtk::CheckButton(i->second); - func_box->pack_start(*manage(chk), false, true); - chk->signal_toggled().connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::ui_function_changed), i->first)); + GLtk::Toggle *tgl = new GLtk::Toggle(i->second); + pnl_functions->add(*tgl); + tgl->set_value(train.get_function(i->first)); + tgl->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::ui_function_toggled), i->first)); + tgl_functions[i->first] = tgl; } - vbox->add(*manage(lbl_status = new Gtk::Label)); - - show_all(); + train.signal_target_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::update_speed)); + update_speed(train.get_target_speed()); + train.signal_reverse_changed.connect(sigc::mem_fun(this, &TrainPanel::update_reverse)); + update_reverse(train.get_reverse()); } -void TrainPanel::name_changed(const string &name) +void TrainPanel::update_reverse(bool r) { - set_label(name); + ind_forward->set_active(!r); + ind_reverse->set_active(r); } -void TrainPanel::status_changed(const string &status) +void TrainPanel::update_speed(float s) { - lbl_status->set_text(status); + SetFlag setf(updating); + float scale_speed = s/train.get_client().get_catalogue().get_scale()*3.6; + sld_speed->set_value(scale_speed); + lbl_speed->set_text(format("%3.0f", scale_speed)); } -void TrainPanel::speed_changed(unsigned speed) +void TrainPanel::ui_speed_changed(float s) { - scl_speed->set_value(speed); + if(!updating) + { + float real_speed = s*train.get_client().get_catalogue().get_scale()/3.6; + train.set_target_speed(real_speed); + } } -void TrainPanel::function_changed(unsigned func, bool set) +void TrainPanel::function_changed(unsigned f, bool a) { - std::map::iterator i = chk_funcs.find(func); - if(i!=chk_funcs.end()) - i->second->set_active(set); + SetFlag setf(updating); + map::iterator i = tgl_functions.find(f); + if(i!=tgl_functions.end()) + get_item(tgl_functions, f)->set_value(a); } -void TrainPanel::ui_speed_changed() +void TrainPanel::ui_function_toggled(bool a, unsigned f) { - train.set_speed(static_cast(scl_speed->get_value())); + if(!updating) + train.set_function(f, a); } -void TrainPanel::ui_function_changed(unsigned func) +void TrainPanel::status_changed(const string &s) { - std::map::iterator i = chk_funcs.find(func); - if(i!=chk_funcs.end()) - train.set_function(func, i->second->get_active()); + lbl_status->set_text(s); }