]> git.tdb.fi Git - r2c2.git/blob - source/engineer/dynamicdialog.cpp
Persist most dialogs across runs
[r2c2.git] / source / engineer / dynamicdialog.cpp
1 #include "dynamicdialog.h"
2 #include "userinterface.h"
3
4 using namespace std;
5 using namespace Msp;
6
7 DynamicDialog::DynamicDialog(UserInterface &u):
8         ui(u)
9 {
10         ui.add_dynamic_dialog(*this);
11 }
12
13 DynamicDialog::~DynamicDialog()
14 {
15         ui.remove_dynamic_dialog(*this);
16 }
17
18 void DynamicDialog::save_position(list<DataFile::Statement> &st) const
19 {
20         GLtk::Root *root = find_ancestor<GLtk::Root>();
21         if(root)
22         {
23                 const GLtk::Geometry &rgeom = root->get_geometry();
24                 float x = static_cast<float>(geom.x)/(rgeom.w-geom.w);
25                 float y = static_cast<float>(geom.y)/(rgeom.h-geom.h);
26                 st.push_back((DataFile::Statement("position"), x, y));
27         }
28 }
29
30
31 DynamicDialog::StateLoader::StateLoader(DynamicDialog &dd):
32         DataFile::ObjectLoader<DynamicDialog>(dd)
33 {
34         add("position", &StateLoader::position);
35 }
36
37 void DynamicDialog::StateLoader::position(float x, float y)
38 {
39         GLtk::Root *root = obj.find_ancestor<GLtk::Root>();
40         if(root)
41         {
42                 const GLtk::Geometry &rgeom = root->get_geometry();
43                 obj.set_position(x*(rgeom.w-obj.geom.w), y*(rgeom.h-obj.geom.h));
44         }
45 }