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 "InputEvents.hpp"
25 #include "Language/Language.hpp"
26 #include "Interface.hpp"
27 #include "ActionInterface.hpp"
28 #include "Message.hpp"
29 #include "Profile/Profile.hpp"
30 #include "Profile/ProfileKeys.hpp"
31 #include "Util/Macros.hpp"
32 #include "Util/EnumCast.hpp"
33 #include "Units/Units.hpp"
34 #include "Protection.hpp"
35 #include "UtilsSettings.hpp"
36 #include "Components.hpp"
37 #include "Task/ProtectedTaskManager.hpp"
38 #include "Audio/VarioGlue.hpp"
41 InputEvents::eventSounds(const TCHAR
*misc
)
43 SoundSettings
&settings
= CommonInterface::SetUISettings().sound
;
44 // bool OldEnableSoundVario = EnableSoundVario;
46 if (StringIsEqual(misc
, _T("toggle")))
47 settings
.vario
.enabled
= !settings
.vario
.enabled
;
48 else if (StringIsEqual(misc
, _T("on")))
49 settings
.vario
.enabled
= true;
50 else if (StringIsEqual(misc
, _T("off")))
51 settings
.vario
.enabled
= false;
52 else if (StringIsEqual(misc
, _T("show"))) {
53 if (settings
.vario
.enabled
)
54 Message::AddMessage(_("Vario sounds on"));
56 Message::AddMessage(_("Vario sounds off"));
60 AudioVarioGlue::Configure(settings
.vario
);
61 Profile::Set(ProfileKeys::SoundAudioVario
, settings
.vario
.enabled
);
65 InputEvents::eventSnailTrail(const TCHAR
*misc
)
67 MapSettings
&settings_map
= CommonInterface::SetMapSettings();
69 if (StringIsEqual(misc
, _T("toggle"))) {
70 unsigned trail_length
= (int)settings_map
.trail
.length
;
71 trail_length
= (trail_length
+ 1u) % 4u;
72 settings_map
.trail
.length
= (TrailSettings::Length
)trail_length
;
73 } else if (StringIsEqual(misc
, _T("off")))
74 settings_map
.trail
.length
= TrailSettings::Length::OFF
;
75 else if (StringIsEqual(misc
, _T("long")))
76 settings_map
.trail
.length
= TrailSettings::Length::LONG
;
77 else if (StringIsEqual(misc
, _T("short")))
78 settings_map
.trail
.length
= TrailSettings::Length::SHORT
;
79 else if (StringIsEqual(misc
, _T("full")))
80 settings_map
.trail
.length
= TrailSettings::Length::FULL
;
81 else if (StringIsEqual(misc
, _T("show"))) {
82 switch (settings_map
.trail
.length
) {
83 case TrailSettings::Length::OFF
:
84 Message::AddMessage(_("Snail trail off"));
87 case TrailSettings::Length::LONG
:
88 Message::AddMessage(_("Long snail trail"));
91 case TrailSettings::Length::SHORT
:
92 Message::AddMessage(_("Short snail trail"));
95 case TrailSettings::Length::FULL
:
96 Message::AddMessage(_("Full snail trail"));
101 ActionInterface::SendMapSettings(true);
105 InputEvents::eventTerrainTopology(const TCHAR
*misc
)
107 eventTerrainTopography(misc
);
110 // Do JUST Terrain/Topography (toggle any, on/off any, show)
112 InputEvents::eventTerrainTopography(const TCHAR
*misc
)
114 if (StringIsEqual(misc
, _T("terrain toggle")))
115 sub_TerrainTopography(-2);
116 else if (StringIsEqual(misc
, _T("topography toggle")))
117 sub_TerrainTopography(-3);
118 else if (StringIsEqual(misc
, _T("topology toggle")))
119 sub_TerrainTopography(-3);
120 else if (StringIsEqual(misc
, _T("terrain on")))
121 sub_TerrainTopography(3);
122 else if (StringIsEqual(misc
, _T("terrain off")))
123 sub_TerrainTopography(4);
124 else if (StringIsEqual(misc
, _T("topography on")))
125 sub_TerrainTopography(1);
126 else if (StringIsEqual(misc
, _T("topography off")))
127 sub_TerrainTopography(2);
128 else if (StringIsEqual(misc
, _T("topology on")))
129 sub_TerrainTopography(1);
130 else if (StringIsEqual(misc
, _T("topology off")))
131 sub_TerrainTopography(2);
132 else if (StringIsEqual(misc
, _T("show")))
133 sub_TerrainTopography(0);
134 else if (StringIsEqual(misc
, _T("toggle")))
135 sub_TerrainTopography(-1);
137 XCSoarInterface::SendMapSettings(true);
140 // Adjust audio deadband of internal vario sounds
141 // +: increases deadband
142 // -: decreases deadband
144 InputEvents::eventAudioDeadband(const TCHAR
*misc
)
146 SoundSettings
&settings
= CommonInterface::SetUISettings().sound
;
148 if (StringIsEqual(misc
, _T("+"))) {
149 if (settings
.sound_deadband
>= 40)
152 ++settings
.sound_deadband
;
154 if (StringIsEqual(misc
, _T("-"))) {
155 if (settings
.sound_deadband
<= 0)
158 --settings
.sound_deadband
;
161 Profile::Set(ProfileKeys::SoundDeadband
, settings
.sound_deadband
);
163 // TODO feature: send to vario if available
167 // Adjusts the degradation of glider performance due to bugs
168 // up: increases the performance by 10%
169 // down: decreases the performance by 10%
170 // max: cleans the aircraft of bugs
171 // min: selects the worst performance (50%)
172 // show: shows the current bug degradation
174 InputEvents::eventBugs(const TCHAR
*misc
)
176 if (protected_task_manager
== NULL
)
179 PolarSettings
&settings
= CommonInterface::SetComputerSettings().polar
;
180 fixed BUGS
= settings
.bugs
;
181 fixed oldBugs
= BUGS
;
183 if (StringIsEqual(misc
, _T("up"))) {
184 BUGS
+= fixed(1) / 10;
187 } else if (StringIsEqual(misc
, _T("down"))) {
188 BUGS
-= fixed(1) / 10;
189 if (BUGS
< fixed(0.5))
191 } else if (StringIsEqual(misc
, _T("max")))
193 else if (StringIsEqual(misc
, _T("min")))
195 else if (StringIsEqual(misc
, _T("show"))) {
197 _stprintf(Temp
, _T("%d"), (int)(BUGS
* 100));
198 Message::AddMessage(_("Bugs performance"), Temp
);
201 if (BUGS
!= oldBugs
) {
202 settings
.SetBugs(BUGS
);
203 protected_task_manager
->SetGlidePolar(settings
.glide_polar_task
);
208 // Adjusts the ballast setting of the glider
209 // up: increases ballast by 10%
210 // down: decreases ballast by 10%
211 // max: selects 100% ballast
212 // min: selects 0% ballast
213 // show: displays a status message indicating the ballast percentage
215 InputEvents::eventBallast(const TCHAR
*misc
)
217 if (protected_task_manager
== NULL
)
221 CommonInterface::SetComputerSettings().polar
.glide_polar_task
;
222 fixed BALLAST
= polar
.GetBallast();
223 fixed oldBallast
= BALLAST
;
225 if (StringIsEqual(misc
, _T("up"))) {
226 BALLAST
+= fixed(1) / 10;
227 if (BALLAST
>= fixed(1))
229 } else if (StringIsEqual(misc
, _T("down"))) {
230 BALLAST
-= fixed(1) / 10;
231 if (BALLAST
< fixed(0))
233 } else if (StringIsEqual(misc
, _T("max")))
235 else if (StringIsEqual(misc
, _T("min")))
237 else if (StringIsEqual(misc
, _T("show"))) {
239 _stprintf(Temp
, _T("%d"), (int)(BALLAST
* 100));
240 /* xgettext:no-c-format */
241 Message::AddMessage(_("Ballast %"), Temp
);
244 if (BALLAST
!= oldBallast
) {
245 polar
.SetBallast(fixed(BALLAST
));
246 protected_task_manager
->SetGlidePolar(polar
);
251 // Loads the profile of the specified filename
253 InputEvents::eventProfileLoad(const TCHAR
*misc
)
255 if (!StringIsEmpty(misc
)) {
256 Profile::LoadFile(misc
);
258 MapFileChanged
= true;
259 WaypointFileChanged
= true;
260 AirspaceFileChanged
= true;
261 AirfieldFileChanged
= true;
263 // assuming all is ok, we can...
269 // Saves the profile to the specified filename
271 InputEvents::eventProfileSave(const TCHAR
*misc
)
273 if (!StringIsEmpty(misc
))
274 Profile::SaveFile(misc
);
277 // AdjustForecastTemperature
278 // Adjusts the maximum ground temperature used by the convection forecast
279 // +: increases temperature by one degree celsius
280 // -: decreases temperature by one degree celsius
281 // show: Shows a status message with the current forecast temperature
283 InputEvents::eventAdjustForecastTemperature(const TCHAR
*misc
)
285 if (StringIsEqual(misc
, _T("+")))
286 CommonInterface::SetComputerSettings().forecast_temperature
+= fixed(1);
287 else if (StringIsEqual(misc
, _T("-")))
288 CommonInterface::SetComputerSettings().forecast_temperature
-= fixed(1);
289 else if (StringIsEqual(misc
, _T("show"))) {
291 CommonInterface::GetComputerSettings().forecast_temperature
;
293 _stprintf(Temp
, _T("%f"),
294 (double)Units::ToUserTemperature(temperature
));
295 Message::AddMessage(_("Forecast temperature"), Temp
);
300 InputEvents::eventDeclutterLabels(const TCHAR
*misc
)
302 static const TCHAR
*const msg
[] = {
304 N_("Task & Landables"),
307 N_("Task & Airfields"),
309 static constexpr unsigned int n
= ARRAY_SIZE(msg
);
311 static const TCHAR
*const actions
[n
] = {
313 _T("task+landables"),
316 _T("task+airfields"),
319 WaypointRendererSettings::LabelSelection
&wls
=
320 CommonInterface::SetMapSettings().waypoint
.label_selection
;
321 if (StringIsEqual(misc
, _T("toggle")))
322 wls
= WaypointRendererSettings::LabelSelection(((unsigned)wls
+ 1) % n
);
323 else if (StringIsEqual(misc
, _T("show"))) {
325 _stprintf(tbuf
, _T("%s: %s"), _("Waypoint labels"),
326 gettext(msg
[(unsigned)wls
]));
327 Message::AddMessage(tbuf
);
330 for (unsigned int i
=0; i
<n
; i
++)
331 if (StringIsEqual(misc
, actions
[i
]))
332 wls
= (WaypointRendererSettings::LabelSelection
)i
;
335 /* save new values to profile */
336 Profile::Set(ProfileKeys::WaypointLabelSelection
,
337 EnumCast
<WaypointRendererSettings::LabelSelection
>()(wls
));
339 ActionInterface::SendMapSettings(true);
343 InputEvents::eventAirspaceDisplayMode(const TCHAR
*misc
)
345 AirspaceRendererSettings
&settings
=
346 CommonInterface::SetMapSettings().airspace
;
348 if (StringIsEqual(misc
, _T("all")))
349 settings
.altitude_mode
= AirspaceDisplayMode::ALLON
;
350 else if (StringIsEqual(misc
, _T("clip")))
351 settings
.altitude_mode
= AirspaceDisplayMode::CLIP
;
352 else if (StringIsEqual(misc
, _T("auto")))
353 settings
.altitude_mode
= AirspaceDisplayMode::AUTO
;
354 else if (StringIsEqual(misc
, _T("below")))
355 settings
.altitude_mode
= AirspaceDisplayMode::ALLBELOW
;
356 else if (StringIsEqual(misc
, _T("off")))
357 settings
.altitude_mode
= AirspaceDisplayMode::ALLOFF
;
363 InputEvents::eventOrientation(const TCHAR
*misc
)
365 MapSettings
&settings_map
= CommonInterface::SetMapSettings();
367 if (StringIsEqual(misc
, _T("northup"))) {
368 settings_map
.cruise_orientation
= DisplayOrientation::NORTH_UP
;
369 settings_map
.circling_orientation
= DisplayOrientation::NORTH_UP
;
370 } else if (StringIsEqual(misc
, _T("northcircle"))) {
371 settings_map
.cruise_orientation
= DisplayOrientation::TRACK_UP
;
372 settings_map
.circling_orientation
= DisplayOrientation::NORTH_UP
;
373 } else if (StringIsEqual(misc
, _T("trackcircle"))) {
374 settings_map
.cruise_orientation
= DisplayOrientation::NORTH_UP
;
375 settings_map
.circling_orientation
= DisplayOrientation::TRACK_UP
;
376 } else if (StringIsEqual(misc
, _T("trackup"))) {
377 settings_map
.cruise_orientation
= DisplayOrientation::TRACK_UP
;
378 settings_map
.circling_orientation
= DisplayOrientation::TRACK_UP
;
379 } else if (StringIsEqual(misc
, _T("northtrack"))) {
380 settings_map
.cruise_orientation
= DisplayOrientation::TRACK_UP
;
381 settings_map
.circling_orientation
= DisplayOrientation::TARGET_UP
;
382 } else if (StringIsEqual(misc
, _T("targetup"))) {
383 settings_map
.cruise_orientation
= DisplayOrientation::TARGET_UP
;
384 settings_map
.circling_orientation
= DisplayOrientation::TARGET_UP
;
387 ActionInterface::SendMapSettings(true);
390 /* Event_TerrainToplogy Changes
396 -1 Toggle through 4 stages (off/off, off/on, on/off, on/on)
402 InputEvents::sub_TerrainTopography(int vswitch
)
404 MapSettings
&settings_map
= CommonInterface::SetMapSettings();
407 // toggle through 4 possible options
410 if (settings_map
.topography_enabled
)
412 if (settings_map
.terrain
.enable
)
419 settings_map
.topography_enabled
= ((val
& 0x01) == 0x01);
420 settings_map
.terrain
.enable
= ((val
& 0x02) == 0x02);
421 } else if (vswitch
== -2)
423 settings_map
.terrain
.enable
= !settings_map
.terrain
.enable
;
424 else if (vswitch
== -3)
426 settings_map
.topography_enabled
= !settings_map
.topography_enabled
;
427 else if (vswitch
== 1)
428 // Turn on topography
429 settings_map
.topography_enabled
= true;
430 else if (vswitch
== 2)
431 // Turn off topography
432 settings_map
.topography_enabled
= false;
433 else if (vswitch
== 3)
435 settings_map
.terrain
.enable
= true;
436 else if (vswitch
== 4)
438 settings_map
.terrain
.enable
= false;
439 else if (vswitch
== 0) {
440 // Show terrain/topography
441 // ARH Let user know what's happening
444 if (settings_map
.topography_enabled
)
445 _stprintf(buf
, _T("\r\n%s / "), _("On"));
447 _stprintf(buf
, _T("\r\n%s / "), _("Off"));
449 _tcscat(buf
, settings_map
.terrain
.enable
450 ? _("On") : _("Off"));
452 Message::AddMessage(_("Topography/Terrain"), buf
);
456 /* save new values to profile */
457 Profile::Set(ProfileKeys::DrawTopography
,
458 settings_map
.topography_enabled
);
459 Profile::Set(ProfileKeys::DrawTerrain
,
460 settings_map
.terrain
.enable
);
462 XCSoarInterface::SendMapSettings(true);