Dialogs/Replay: use RowFormWidget
[xcsoar.git] / src / Dialogs / ReplayDialog.cpp
blob05cb8f438fee43ca613bae24e50814de3e28e59f
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "ReplayDialog.hpp"
25 #include "Dialogs/Message.hpp"
26 #include "Dialogs/WidgetDialog.hpp"
27 #include "Widget/RowFormWidget.hpp"
28 #include "Form/ActionListener.hpp"
29 #include "Form/DataField/Listener.hpp"
30 #include "UIGlobals.hpp"
31 #include "Components.hpp"
32 #include "Replay/Replay.hpp"
33 #include "Form/DataField/FileReader.hpp"
34 #include "Form/DataField/Float.hpp"
35 #include "Language/Language.hpp"
37 enum Buttons {
38 START,
39 STOP,
42 class ReplayControlWidget final
43 : public RowFormWidget, public ActionListener, DataFieldListener {
44 enum Controls {
45 FILE,
46 RATE,
49 public:
50 ReplayControlWidget(const DialogLook &look)
51 :RowFormWidget(look) {}
53 private:
54 void OnStopClicked();
55 void OnStartClicked();
57 public:
58 /* virtual methods from class Widget */
59 virtual void Prepare(ContainerWindow &parent,
60 const PixelRect &rc) override;
62 /* virtual methods from ActionListener */
63 virtual void OnAction(int id) override;
65 private:
66 /* methods from DataFieldListener */
67 virtual void OnModified(DataField &df) override;
70 void
71 ReplayControlWidget::Prepare(ContainerWindow &parent, const PixelRect &rc)
73 auto *file =
74 AddFileReader(_("File"),
75 _("Name of file to replay. Can be an IGC file (.igc), a raw NMEA log file (.nmea), or if blank, runs the demo."),
76 nullptr,
77 _T("*.nmea\0*.igc\0"),
78 true);
79 ((DataFieldFileReader *)file->GetDataField())->Lookup(replay->GetFilename());
80 file->RefreshDisplay();
82 AddFloat(_("Rate"),
83 _("Time acceleration of replay. Set to 0 for pause, 1 for normal real-time replay."),
84 _("%.0f x"), _T("%.0f"),
85 fixed(0), fixed(10), fixed(1), false,
86 replay->GetTimeScale(),
87 this);
90 inline void
91 ReplayControlWidget::OnStopClicked()
93 replay->Stop();
96 inline void
97 ReplayControlWidget::OnStartClicked()
99 const DataFieldFileReader &df = (const DataFieldFileReader &)
100 GetDataField(FILE);
101 const TCHAR *path = df.GetPathFile();
102 if (!replay->Start(path))
103 ShowMessageBox(_("Could not open IGC file!"),
104 _("Replay"), MB_OK | MB_ICONINFORMATION);
107 void
108 ReplayControlWidget::OnAction(int id)
110 switch (id) {
111 case START:
112 OnStartClicked();
113 break;
115 case STOP:
116 OnStopClicked();
117 break;
121 void
122 ReplayControlWidget::OnModified(DataField &_df)
124 const DataFieldFloat &df = (const DataFieldFloat &)_df;
126 replay->SetTimeScale(df.GetAsFixed());
129 void
130 ShowReplayDialog()
132 const DialogLook &look = UIGlobals::GetDialogLook();
133 ReplayControlWidget *widget = new ReplayControlWidget(look);
134 WidgetDialog dialog(look);
135 dialog.CreateAuto(UIGlobals::GetMainWindow(), _("Replay"), widget);
136 dialog.AddButton(_("Start"), *widget, START);
137 dialog.AddButton(_("Stop"), *widget, STOP);
138 dialog.AddButton(_("Close"), mrOK);
140 dialog.ShowModal();