]> git.tdb.fi Git - r2c2.git/commitdiff
Add a common base class for dialogs that need to update dynamically
authorMikko Rasa <tdb@tdb.fi>
Thu, 19 Feb 2015 13:31:56 +0000 (15:31 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 19 Feb 2015 13:31:56 +0000 (15:31 +0200)
source/engineer/dynamicdialog.cpp [new file with mode: 0644]
source/engineer/dynamicdialog.h [new file with mode: 0644]
source/engineer/engineer.cpp
source/engineer/engineer.h
source/engineer/trainview.cpp
source/engineer/trainview.h

diff --git a/source/engineer/dynamicdialog.cpp b/source/engineer/dynamicdialog.cpp
new file mode 100644 (file)
index 0000000..87c7437
--- /dev/null
@@ -0,0 +1,13 @@
+#include "dynamicdialog.h"
+#include "engineer.h"
+
+DynamicDialog::DynamicDialog(Engineer &e):
+       engineer(e)
+{
+       engineer.add_dynamic_dialog(*this);
+}
+
+DynamicDialog::~DynamicDialog()
+{
+       engineer.remove_dynamic_dialog(*this);
+}
diff --git a/source/engineer/dynamicdialog.h b/source/engineer/dynamicdialog.h
new file mode 100644 (file)
index 0000000..fc18cbd
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef DYNAMICDIALOG_H_
+#define DYNAMICDIALOG_H_
+
+#include <msp/gltk/dialog.h>
+
+class Engineer;
+
+class DynamicDialog: public Msp::GLtk::Dialog
+{
+protected:
+       Engineer &engineer;
+
+       DynamicDialog(Engineer &);
+public:
+       virtual ~DynamicDialog();
+
+       virtual void update() = 0;
+};
+
+#endif
index 68533bc11520114862acfed734c50cd07c91010b..36412cfeb017f857efd354c30e8e8e85c1f33fcd 100644 (file)
 #include "3d/track.h"
 #include "3d/trackcircuit.h"
 #include "3d/vehicle.h"
+#include "dynamicdialog.h"
 #include "engineer.h"
 #include "mainwindow.h"
 #include "newtraindialog.h"
 #include "traindialog.h"
-#include "trainview.h"
 
 using namespace std;
 using namespace R2C2;
@@ -145,14 +145,14 @@ void Engineer::set_status(const string &text)
        status_timeout = Time::now()+10*Time::sec;
 }
 
-void Engineer::add_train_view(TrainView &tv)
+void Engineer::add_dynamic_dialog(DynamicDialog &tv)
 {
-       train_views.push_back(&tv);
+       dyn_dialogs.push_back(&tv);
 }
 
-void Engineer::remove_train_view(TrainView &tv)
+void Engineer::remove_dynamic_dialog(DynamicDialog &tv)
 {
-       train_views.erase(remove(train_views.begin(), train_views.end(), &tv), train_views.end());
+       dyn_dialogs.erase(remove(dyn_dialogs.begin(), dyn_dialogs.end(), &tv), dyn_dialogs.end());
 }
 
 int Engineer::main()
@@ -174,8 +174,8 @@ void Engineer::tick()
        layout_3d.tick();
        event_disp.tick(Time::zero);
 
-       for(list<TrainView *>::iterator i=train_views.begin(); i!=train_views.end(); ++i)
-               (*i)->prepare();
+       for(list<DynamicDialog *>::iterator i=dyn_dialogs.begin(); i!=dyn_dialogs.end(); ++i)
+               (*i)->update();
 
        Time::TimeStamp t = Time::now();
        if(status_timeout && t>status_timeout)
index 0769473a786e45e639c544c0b7478bf7d9205c94..333af73a871362d698903965b91319aad1d9f760 100644 (file)
@@ -21,7 +21,7 @@
 #include "options.h"
 
 class MainWindow;
-class TrainView;
+class DynamicDialog;
 
 class Engineer: public Msp::RegisteredApplication<Engineer>
 {
@@ -48,7 +48,7 @@ private:
 
        MainWindow *main_wnd;
        std::list<R2C2::Train *> new_trains;
-       std::list<TrainView *> train_views;
+       std::list<DynamicDialog *> dyn_dialogs;
        Msp::Time::TimeStamp status_timeout;
        R2C2::Vector pointer;
        std::list<R2C2::TrackChain3D *> emergencies;
@@ -66,8 +66,8 @@ public:
        R2C2::Layout3D &get_layout_3d() { return layout_3d; }
        R2C2::View3D &get_main_view() { return main_view; }
        void set_status(const std::string &);
-       void add_train_view(TrainView &);
-       void remove_train_view(TrainView &);
+       void add_dynamic_dialog(DynamicDialog &);
+       void remove_dynamic_dialog(DynamicDialog &);
        int main();
        void quit() { exit(0); }
 private:
index 4e43993954ba5fc57c9b6d13df0a9374f6f094eb..aec102705e93960a5f150114009fdc787b9c378e 100644 (file)
@@ -13,7 +13,7 @@ using namespace Msp;
 using namespace R2C2;
 
 TrainView::TrainView(Engineer &e, const Train &t):
-       engineer(e),
+       DynamicDialog(e),
        train(t),
        mode(SIDE),
        forward(true),
@@ -38,13 +38,6 @@ TrainView::TrainView(Engineer &e, const Train &t):
        view.get_camera().set_depth_clip(0.01, 10);
 
        dynamic_cast<GLtk::Image *>(get_item(widgets, "img_view"))->set_image(&tex);
-
-       engineer.add_train_view(*this);
-}
-
-TrainView::~TrainView()
-{
-       engineer.remove_train_view(*this);
 }
 
 void TrainView::set_mode(Mode m)
@@ -63,7 +56,7 @@ void TrainView::set_forward(bool f)
        forward = f;
 }
 
-void TrainView::prepare()
+void TrainView::update()
 {
        const Vehicle &veh = train.get_vehicle(0);
        const Vector &pos = veh.get_position();
index 598b43fab9209bb520228bd886d9961e9f8e5b34..1e484cb3956e920be53c0baedfb1e8713857501d 100644 (file)
@@ -4,13 +4,11 @@
 #include <msp/gl/renderbuffer.h>
 #include <msp/gl/framebuffer.h>
 #include <msp/gl/texture2d.h>
-#include <msp/gltk/dialog.h>
 #include <msp/gltk/toggle.h>
 #include "libr2c2/train.h"
+#include "dynamicdialog.h"
 
-class Engineer;
-
-class TrainView: public Msp::GLtk::Dialog
+class TrainView: public DynamicDialog
 {
 public:
        enum Mode
@@ -21,7 +19,6 @@ public:
        };
 
 private:
-       Engineer &engineer;
        const R2C2::Train &train;
        Msp::GLtk::Toggle *tgl_forward;
        Mode mode;
@@ -33,14 +30,13 @@ private:
 
 public:
        TrainView(Engineer &, const R2C2::Train &);
-       ~TrainView();
 
        void set_mode(Mode);
 private:
        void ui_mode_toggled(bool, Mode);
 public:
        void set_forward(bool);
-       void prepare();
+       virtual void update();
 };
 
 #endif