3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gltk/button.h>
9 #include <msp/strings/formatter.h>
10 #include <msp/strings/lexicalcast.h>
12 #include "trainproperties.h"
16 using namespace Marklin;
18 TrainProperties::TrainProperties(Engineer &e, GLtk::Resources &r, Train *t):
26 add(*(ent_addr=new GLtk::Entry(res)));
27 ent_addr->set_geometry(GLtk::Geometry(10, geom.h-30, 40, 20));
29 add(*(drp_type=new GLtk::Dropdown(res)));
30 drp_type->set_geometry(GLtk::Geometry(60, geom.h-30, geom.w-70, 20));
32 const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
33 for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i)
34 drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name()));
36 add(*(ent_name=new GLtk::Entry(res, "Train")));
37 ent_name->set_geometry(GLtk::Geometry(10, geom.h-55, geom.w-20, 20));
41 add(*(btn=new GLtk::Button(res, "OK")));
42 btn->set_style("green");
43 btn->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
44 btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::ok_clicked));
46 add(*(btn=new GLtk::Button(res, "Cncl")));
47 btn->set_style("red");
48 btn->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
49 btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::cancel_clicked));
52 void TrainProperties::ok_clicked()
56 const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
57 map<unsigned, LocoType *>::const_iterator i = locos.begin();
58 advance(i, drp_type->get_selected_index());
59 train = engineer.add_train(*i->second, lexical_cast<unsigned>(ent_addr->get_text()));
62 train->set_name(ent_name->get_text());
66 void TrainProperties::cancel_clicked()