]> git.tdb.fi Git - r2c2.git/blob - source/remote/remote.cpp
Put TrainPanels in a ScrolledWindow so the UI is usable on small screens
[r2c2.git] / source / remote / remote.cpp
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2009-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <gtkmm/scrolledwindow.h>
9 #include <gtkmm/separator.h>
10 #include <msp/net/resolve.h>
11 #include <msp/time/units.h>
12 #include "remote.h"
13 #include "trainpanel.h"
14
15 using namespace std;
16 using namespace Msp;
17
18 Application::RegApp<Remote> Remote::reg;
19
20 Remote::Remote(int argc, char **argv):
21         client(catalogue),
22         gtk(argc, argv)
23 {
24         if(argc<2)
25                 throw UsageError("No address given");
26
27         DataFile::load(catalogue, "locos.dat");
28
29         client.use_event_dispatcher(event_disp);
30         client.signal_train_added.connect(sigc::mem_fun(this, &Remote::train_added));
31         string addr_str = argv[1];
32         if(addr_str.find(':')==string::npos)
33                 addr_str += ":8315";
34         Net::SockAddr *addr = Net::resolve(addr_str);
35         client.connect(*addr);
36         delete addr;
37
38         window.signal_hide().connect(sigc::bind(sigc::mem_fun(this, &Remote::exit), 0));
39         window.set_default_size(300, 200);
40         window.set_border_width(5);
41
42         Gtk::ScrolledWindow *scroll = new Gtk::ScrolledWindow;
43         window.add(*manage(scroll));
44         scroll->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
45
46         train_box = new Gtk::VBox(false, 5);
47         scroll->add(*manage(train_box));
48
49         window.show_all();
50 }
51
52 void Remote::tick()
53 {
54         event_disp.tick(Time::zero);
55         gtk.iteration(false);
56 }
57
58 void Remote::train_added(R2C2::NetTrain &t)
59 {
60         TrainPanel *panel = new TrainPanel(*this, client, t);
61         if(!train_panels.empty())
62         {
63                 Gtk::HSeparator *sep = new Gtk::HSeparator;
64                 train_box->pack_start(*manage(sep), false, true);
65                 sep->show();
66         }
67         train_box->pack_start(*manage(panel), false, true);
68         train_panels.push_back(panel);
69 }