X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fremote%2Fremote.cpp;fp=source%2Fremote%2Fremote.cpp;h=f6e8692b3319e8b2c36d480071b98820c75203fd;hb=f8873062b146028c07f55ad625d2767e45133c27;hp=0000000000000000000000000000000000000000;hpb=a9bbf8d37a2f94a720897fe4f0ab06a016779c69;p=r2c2.git diff --git a/source/remote/remote.cpp b/source/remote/remote.cpp new file mode 100644 index 0000000..f6e8692 --- /dev/null +++ b/source/remote/remote.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +#include "connectdialog.h" +#include "remote.h" + +using namespace std; +using namespace Msp; +using namespace R2C2; + +Remote::Remote(int, char **): + window(1024, 768), + client(catalogue), + ui_resources("data/r2c2.res"), + root(ui_resources, window), + root_layout(new GLtk::Layout), + status_bar(client) +{ + window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Remote::exit), 0)); + + root.set_size(window.get_width()/2, window.get_height()/2); + root.set_layout(root_layout); + root_layout->set_margin(GLtk::Sides()); + root_layout->set_spacing(0); + + for(unsigned i=0; i<2; ++i) + { + selectors[i] = new TrainSelector(client); + root.add(*selectors[i]); + root_layout->set_gravity(*selectors[i], i*2-1, 1); + root_layout->set_expand(*selectors[i], true, false); + selectors[i]->signal_train_selected.connect(sigc::bind(sigc::mem_fun(this, &Remote::train_selected), i)); + + if(i>0) + { + root_layout->add_constraint(*selectors[i], GLtk::Layout::RIGHT_OF, *selectors[i-1]); + root_layout->add_constraint(*selectors[i], GLtk::Layout::COPY_WIDTH, *selectors[i-1]); + } + + panels[i] = 0; + } + + root.add(status_bar); + root_layout->set_gravity(status_bar, -1, -1); + root_layout->set_expand(status_bar, true, false); + + catalogue.add_source("data/Märklin/H0"); + + client.use_event_dispatcher(ev_disp); +} + +int Remote::main() +{ + ConnectDialog *dlg = new ConnectDialog(client); + root.add(*dlg); + root_layout->set_gravity(*dlg, 0, 0); + + window.show(); + + return Application::main(); +} + +void Remote::tick() +{ + for(unsigned i=0;; ++i) + { + Time::TimeStamp t = Time::now(); + if(i>0 && t>=next_frame) + { + next_frame = t+Time::sec/30; + break; + } + ev_disp.tick(max(next_frame-t, Time::zero)); + } + + window.tick(); + + GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT); + root.render(); + window.swap_buffers(); +} + +void Remote::train_selected(NetTrain *train, unsigned index) +{ + delete panels[index]; + panels[index] = 0; + + if(train) + { + panels[index] = new TrainPanel(*train); + root.add(*panels[index]); + root_layout->set_expand(*panels[index], true, true); + root_layout->add_constraint(*panels[index], GLtk::Layout::BELOW, *selectors[index]); + root_layout->add_constraint(*panels[index], GLtk::Layout::ALIGN_LEFT, *selectors[index]); + root_layout->add_constraint(*panels[index], GLtk::Layout::ALIGN_RIGHT, *selectors[index]); + root_layout->add_constraint(*panels[index], GLtk::Layout::ABOVE, status_bar); + } +}