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):
25 add(*(ent_addr=new GLtk::Entry(res)));
26 ent_addr->set_geometry(GLtk::Geometry(10, geom.h-30, 40, 20));
28 add(*(drp_type=new GLtk::Dropdown(res)));
29 drp_type->set_geometry(GLtk::Geometry(60, geom.h-30, geom.w-70, 20));
31 const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
32 for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i)
33 drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name()));
35 add(*(ent_name=new GLtk::Entry(res, "Train")));
36 ent_name->set_geometry(GLtk::Geometry(10, geom.h-55, geom.w-20, 20));
40 add(*(btn=new GLtk::Button(res, "OK")));
41 btn->set_style("green");
42 btn->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
43 btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::ok_clicked));
45 add(*(btn=new GLtk::Button(res, "Cncl")));
46 btn->set_style("red");
47 btn->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
48 btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::cancel_clicked));
51 void TrainProperties::ok_clicked()
55 const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
56 map<unsigned, LocoType *>::const_iterator i = locos.begin();
57 advance(i, drp_type->get_selected_index());
58 train = engineer.add_train(*i->second, lexical_cast<unsigned>(ent_addr->get_text()));
61 train->set_name(ent_name->get_text());
65 void TrainProperties::cancel_clicked()