engineer(e),
train(t)
{
- set_size(200, 172);
+ set_size(200, 145);
add(*(lbl_addr=new GLtk::Label(res, format("%2d", train.get_locomotive().get_address()))));
lbl_addr->set_style("digital");
lbl_name->set_geometry(GLtk::Geometry(45, geom.h-34, geom.w-55, 24));
train.signal_name_changed.connect(sigc::mem_fun(lbl_name, &GLtk::Label::set_text));
+ add(*(lbl_speed=new GLtk::Label(res, format("%2d", train.get_locomotive().get_speed()))));
+ lbl_speed->set_style("digital");
+ lbl_speed->set_geometry(GLtk::Geometry(10, geom.h-58, 35, 24));
+ train.get_locomotive().signal_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_speed_changed));
+
add(*(sld_speed=new GLtk::HSlider(res)));
- sld_speed->set_geometry(GLtk::Geometry(50, geom.h-56, geom.w-60, 10));
+ sld_speed->set_geometry(GLtk::Geometry(50, geom.h-51, geom.w-80, 10));
sld_speed->set_range(0, 14);
sld_speed->set_step(1);
sld_speed->signal_value_changed.connect(sigc::mem_fun(this, &TrainPanel::speed_slider_changed));
- add(*(lbl_speed=new GLtk::Label(res, format("%2d", train.get_locomotive().get_speed()))));
- lbl_speed->set_style("digital");
- lbl_speed->set_geometry(GLtk::Geometry(10, geom.h-63, 35, 24));
- train.get_locomotive().signal_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_speed_changed));
+ add(*(tgl_forward=new GLtk::Toggle(res)));
+ tgl_forward->set_text("Fwd");
+ tgl_forward->set_geometry(GLtk::Geometry(geom.w-30, geom.h-59, 20, 27));
+ tgl_forward->set_value(!train.get_locomotive().get_reverse());
+ tgl_forward->signal_toggled.connect(sigc::mem_fun(this, &TrainPanel::forward_toggled));
- GLtk::Button *btn;
+ add(*(lbl_status=new GLtk::Label(res, train.get_status())));
+ lbl_status->set_style("digital");
+ lbl_status->set_geometry(GLtk::Geometry(10, 34, geom.w-20, 24));
+ train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::train_status_changed));
const map<unsigned, string> &funcs = train.get_locomotive().get_type().get_functions();
unsigned x = 10;
- for(map<unsigned, string>::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=40)
+ for(map<unsigned, string>::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=35)
{
string fname = i->second;
fname[0] = toupper(fname[0]);
- add(*(btn=new GLtk::Button(res, fname)));
- btn->set_geometry(GLtk::Geometry(x, 68, 40, 24));
- btn->signal_clicked.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::func_clicked), i->first));
-
- GLtk::Indicator *ind = new GLtk::Indicator(res);
- add(*ind);
- ind->set_geometry(GLtk::Geometry(x, 92, 40, 12));
- ind->set_active(train.get_locomotive().get_function(i->first));
- ind_funcs[i->first] = ind;
+ GLtk::Toggle *tgl;
+ add(*(tgl=new GLtk::Toggle(res)));
+ tgl->set_text(fname);
+ tgl->set_geometry(GLtk::Geometry(x, geom.h-85, 35, 27));
+ tgl->set_value(train.get_locomotive().get_function(i->first));
+ tgl->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::func_toggled), i->first));
+
+ tgl_funcs[i->first] = tgl;
}
train.get_locomotive().signal_function_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_function_changed));
- add(*(lbl_status=new GLtk::Label(res, train.get_status())));
- lbl_status->set_style("digital");
- lbl_status->set_geometry(GLtk::Geometry(10, 39, geom.w-20, 24));
- train.signal_status_changed.connect(sigc::mem_fun(this, &TrainPanel::train_status_changed));
+ GLtk::Button *btn;
add(*(btn=new GLtk::Button(res, "Edit")));
btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24));
add(*(btn=new GLtk::Button(res, "Place")));
btn->set_geometry(GLtk::Geometry(geom.w-90, 10, 40, 24));
btn->signal_clicked.connect(sigc::mem_fun(this, &TrainPanel::place_clicked));
+
+ add(*(btn=new GLtk::Button(res, "GoTo")));
+ btn->set_geometry(GLtk::Geometry(geom.w-130, 10, 40, 24));
}
void TrainPanel::speed_slider_changed(double v)
void TrainPanel::loco_function_changed(unsigned func, bool value)
{
- map<unsigned, GLtk::Indicator *>::iterator i = ind_funcs.find(func);
- if(i!=ind_funcs.end())
- i->second->set_active(value);
+ map<unsigned, GLtk::Toggle *>::iterator i = tgl_funcs.find(func);
+ if(i!=tgl_funcs.end())
+ i->second->set_value(value);
}
void TrainPanel::train_status_changed(const string &s)
engineer.place_train(train);
}
-void TrainPanel::func_clicked(unsigned func)
+void TrainPanel::forward_toggled(bool value)
+{
+ train.set_reverse(!value);
+}
+
+void TrainPanel::func_toggled(bool value, unsigned func)
{
- train.get_locomotive().set_function(func, !train.get_locomotive().get_function(func));
+ train.get_locomotive().set_function(func, value);
}