--- /dev/null
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2009 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include "dialog.h"
+
+using namespace Msp;
+
+Dialog::Dialog(const GLtk::Resources &r):
+ GLtk::Widget(r),
+ GLtk::Panel(r),
+ stale(false)
+{
+ add(*(btn_ok=new GLtk::Button(res, "OK")));
+ btn_ok->set_style("green");
+ btn_ok->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
+ btn_ok->signal_clicked.connect(sigc::mem_fun(this, &Dialog::on_ok_clicked));
+ btn_ok->signal_clicked.connect(signal_ok);
+ btn_ok->signal_clicked.connect(sigc::mem_fun(this, &Dialog::dismiss));
+
+ add(*(btn_cancel=new GLtk::Button(res, "Cncl")));
+ btn_cancel->set_style("red");
+ btn_cancel->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
+ btn_cancel->signal_clicked.connect(signal_cancel);
+ btn_cancel->signal_clicked.connect(sigc::mem_fun(this, &Dialog::dismiss));
+}
+
+void Dialog::button_release(int x, int y, unsigned btn)
+{
+ Panel::button_release(x, y, btn);
+ if(stale)
+ delete this;
+}
+
+void Dialog::on_geometry_change()
+{
+ btn_ok->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
+ btn_cancel->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
+}
+
+void Dialog::dismiss()
+{
+ stale = true;
+}
--- /dev/null
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2009 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#ifndef DIALOG_H_
+#define DIALOG_H_
+
+#include <msp/gltk/button.h>
+#include <msp/gltk/panel.h>
+
+class Dialog: public Msp::GLtk::Panel
+{
+public:
+ sigc::signal<void> signal_ok;
+ sigc::signal<void> signal_cancel;
+
+protected:
+ Msp::GLtk::Button *btn_ok;
+ Msp::GLtk::Button *btn_cancel;
+ bool stale;
+
+ Dialog(const Msp::GLtk::Resources &);
+
+ virtual void button_release(int, int, unsigned);
+ virtual void on_geometry_change();
+
+ virtual void on_ok_clicked() { }
+ void dismiss();
+};
+
+#endif
layout(catalogue),
layout_3d(layout),
server(0),
- train_prop(0),
- train_prop_stale(false),
placing_train(0),
placing_block(0),
placing_entry(0),
DataFile::load(layout, args.front());
trfc_mgr = new TrafficManager(control, layout);
- trfc_mgr->signal_block_reserved.connect(sigc::mem_fun(this, &Engineer::block_reserved));
if(FS::exists("engineer.state"))
DataFile::load(*trfc_mgr, "engineer.state");
+ trfc_mgr->signal_train_added.connect(sigc::mem_fun(this, &Engineer::train_added));
+ trfc_mgr->signal_block_reserved.connect(sigc::mem_fun(this, &Engineer::block_reserved));
if(network)
{
delete trfc_mgr;
}
-void Engineer::add_train()
-{
- train_prop = new TrainProperties(*this, ui_res, 0);
- root->add(*train_prop);
- train_prop->signal_ok.connect(sigc::mem_fun(this, &Engineer::dismiss_train_prop));
- train_prop->signal_cancel.connect(sigc::mem_fun(this, &Engineer::dismiss_train_prop));
- train_prop_stale = false;
- train_prop->set_visible(true);
-}
-
-Train *Engineer::add_train(const LocoType &type, unsigned addr)
-{
- Locomotive *loco = new Locomotive(type, control, addr);
- Train *train = new Train(*trfc_mgr, *loco);
- train->set_name(format("Train %d", trfc_mgr->get_trains().size()));
-
- TrainPanel *tpanel = new TrainPanel(*this, ui_res, *train);
- root->add(*tpanel);
- int y = main_panel->get_geometry().y;
- for(list<TrainPanel *>::iterator i=train_panels.begin(); i!=train_panels.end(); ++i)
- y -= (*i)->get_geometry().h;
- tpanel->set_position(0, y-tpanel->get_geometry().h);
- train_panels.push_back(tpanel);
- tpanel->set_visible(true);
-
- place_train(*train);
-
- return train;
-}
-
void Engineer::place_train(Train &train)
{
placing_train = &train;
root->render();
- if(train_prop_stale)
- {
- delete train_prop;
- train_prop = 0;
- }
-
glc->swap_buffers();
}
-void Engineer::key_press(unsigned key, unsigned mod, wchar_t ch)
-{
- if(train_prop)
- train_prop->key_press(key, mod, ch);
-}
-
void Engineer::button_press(int x, int y, unsigned btn, unsigned)
{
if(placing_train)
return layout_3d.pick_track(xx, yy, size);
}
-void Engineer::dismiss_train_prop()
+void Engineer::train_added(Train &train)
{
- train_prop_stale = true;
+ TrainPanel *tpanel = new TrainPanel(*this, ui_res, train);
+ root->add(*tpanel);
+ int y = main_panel->get_geometry().y;
+ for(list<TrainPanel *>::iterator i=train_panels.begin(); i!=train_panels.end(); ++i)
+ y -= (*i)->get_geometry().h;
+ tpanel->set_position(0, y-tpanel->get_geometry().h);
+ train_panels.push_back(tpanel);
+ tpanel->set_visible(true);
+
+ place_train(train);
}
Application::RegApp<Engineer> Engineer::reg;
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
MainPanel *main_panel;
std::list<TrainPanel *> train_panels;
- TrainProperties *train_prop;
- bool train_prop_stale;
Marklin::Train *placing_train;
Marklin::Block *placing_block;
unsigned placing_entry;
Engineer(int argc, char **argv);
~Engineer();
+ const Msp::GLtk::Resources &get_ui_resources() const { return ui_res; }
+ Msp::GLtk::Root &get_root() const { return *root; }
const Marklin::Catalogue &get_catalogue() const { return catalogue; }
Marklin::Control &get_control() { return control; }
- void add_train();
- Marklin::Train *add_train(const Marklin::LocoType &, unsigned);
+ Marklin::TrafficManager &get_traffic_manager() { return *trfc_mgr; }
void place_train(Marklin::Train &);
int main();
void quit() { exit(0); }
private:
void tick();
- void key_press(unsigned, unsigned, wchar_t);
void button_press(int, int, unsigned, unsigned);
void button_release(int, int, unsigned, unsigned);
void pointer_motion(int, int);
void block_reserved(const Marklin::Block &, const Marklin::Train *);
void project_3d();
Marklin::Track3D *pick_track(int, int);
- void dismiss_train_prop();
+ void train_added(Marklin::Train &);
static Msp::Application::RegApp<Engineer> reg;
};
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include <msp/gltk/button.h>
#include "engineer.h"
#include "mainpanel.h"
+#include "trainproperties.h"
using namespace std;
using namespace Msp;
void MainPanel::new_loc()
{
- engineer.add_train();
+ TrainProperties *dialog = new TrainProperties(engineer, res, 0);
+ engineer.get_root().add(*dialog);
+ dialog->set_position(geom.x+geom.w, geom.y+geom.h-dialog->get_geometry().h);
+ dialog->set_visible(true);
}
void MainPanel::quit()
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include "libmarklin/locomotive.h"
#include "engineer.h"
#include "trainpanel.h"
+#include "trainproperties.h"
using namespace std;
using namespace Msp;
add(*(btn=new GLtk::Button(res, "Edit")));
btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24));
+ btn->signal_clicked.connect(sigc::mem_fun(this, &TrainPanel::edit_clicked));
add(*(btn=new GLtk::Button(res, "Place")));
btn->set_geometry(GLtk::Geometry(geom.w-90, 10, 40, 24));
engineer.place_train(train);
}
+void TrainPanel::edit_clicked()
+{
+ TrainProperties *dialog = new TrainProperties(engineer, res, &train);
+ engineer.get_root().add(*dialog);
+ dialog->set_position(geom.x+geom.w, geom.y+geom.h-dialog->get_geometry().h);
+ dialog->set_visible(true);
+}
+
void TrainPanel::forward_toggled(bool value)
{
train.set_reverse(!value);
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
void loco_function_changed(unsigned, bool);
void train_status_changed(const std::string &);
void place_clicked();
+ void edit_clicked();
void forward_toggled(bool);
void func_toggled(bool, unsigned);
};
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include <msp/gltk/button.h>
+#include <msp/gltk/label.h>
#include <msp/strings/formatter.h>
#include <msp/strings/lexicalcast.h>
#include "engineer.h"
using namespace Msp;
using namespace Marklin;
-TrainProperties::TrainProperties(Engineer &e, GLtk::Resources &r, Train *t):
+TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t):
Widget(r),
- Panel(r),
+ Dialog(r),
engineer(e),
train(t)
{
- set_size(200, 95);
+ set_size(200, 120);
+
+ GLtk::Label *label;
+ add(*(label=new GLtk::Label(res, "Train properties")));
+ label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20));
add(*(ent_addr=new GLtk::Entry(res)));
- ent_addr->set_geometry(GLtk::Geometry(10, geom.h-30, 40, 20));
+ ent_addr->set_geometry(GLtk::Geometry(10, geom.h-50, 40, 20));
add(*(drp_type=new GLtk::Dropdown(res)));
- drp_type->set_geometry(GLtk::Geometry(60, geom.h-30, geom.w-70, 20));
+ drp_type->set_geometry(GLtk::Geometry(60, geom.h-50, geom.w-70, 20));
const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
- for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i)
+ unsigned n = 0;
+ for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i, ++n)
+ {
drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name()));
+ if(train && i->second==&train->get_locomotive().get_type())
+ drp_type->set_selected_index(n);
+ }
- add(*(ent_name=new GLtk::Entry(res, "Train")));
- ent_name->set_geometry(GLtk::Geometry(10, geom.h-55, geom.w-20, 20));
-
- GLtk::Button *btn;
-
- add(*(btn=new GLtk::Button(res, "OK")));
- btn->set_style("green");
- btn->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
- btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::ok_clicked));
+ add(*(ent_name=new GLtk::Entry(res)));
+ ent_name->set_geometry(GLtk::Geometry(10, geom.h-75, geom.w-20, 20));
- add(*(btn=new GLtk::Button(res, "Cncl")));
- btn->set_style("red");
- btn->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
- btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::cancel_clicked));
+ if(train)
+ {
+ ent_addr->set_text(lexical_cast(train->get_locomotive().get_address()));
+ ent_name->set_text(train->get_name());
+ }
+ else
+ ent_name->set_text(format("Train %d", engineer.get_traffic_manager().get_trains().size()+1));
}
-void TrainProperties::ok_clicked()
+void TrainProperties::on_ok_clicked()
{
if(!train)
{
const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
map<unsigned, LocoType *>::const_iterator i = locos.begin();
advance(i, drp_type->get_selected_index());
- train = engineer.add_train(*i->second, lexical_cast<unsigned>(ent_addr->get_text()));
+
+ unsigned addr = lexical_cast<unsigned>(ent_addr->get_text());
+ Locomotive *loco = new Locomotive(*i->second, engineer.get_control(), addr);
+ train = new Train(engineer.get_traffic_manager(), *loco);
}
train->set_name(ent_name->get_text());
- signal_ok.emit();
-}
-
-void TrainProperties::cancel_clicked()
-{
- signal_cancel.emit();
}
/* $Id$
This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
Distributed under the GPL
*/
#include <msp/gltk/dropdown.h>
#include <msp/gltk/entry.h>
-#include <msp/gltk/panel.h>
#include <libmarklin/train.h>
+#include "dialog.h"
class Engineer;
-class TrainProperties: public Msp::GLtk::Panel
+class TrainProperties: public Dialog
{
-public:
- sigc::signal<void> signal_ok;
- sigc::signal<void> signal_cancel;
-
private:
Engineer &engineer;
Marklin::Train *train;
Msp::GLtk::Entry *ent_name;
public:
- TrainProperties(Engineer &, Msp::GLtk::Resources &, Marklin::Train *);
+ TrainProperties(Engineer &, const Msp::GLtk::Resources &, Marklin::Train *);
private:
- void ok_clicked();
- void cancel_clicked();
+ virtual void on_ok_clicked();
};
#endif