dlgTextEntry_Keyboard: rename to TouchTextEntry
[xcsoar.git] / src / Input / InputEventsSettings.cpp
blob185c71939412545f9baa219a82d84a661cad64ab
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 "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"
40 void
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"));
55 else
56 Message::AddMessage(_("Vario sounds off"));
57 return;
60 AudioVarioGlue::Configure(settings.vario);
61 Profile::Set(ProfileKeys::SoundAudioVario, settings.vario.enabled);
64 void
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"));
85 break;
87 case TrailSettings::Length::LONG:
88 Message::AddMessage(_("Long snail trail"));
89 break;
91 case TrailSettings::Length::SHORT:
92 Message::AddMessage(_("Short snail trail"));
93 break;
95 case TrailSettings::Length::FULL:
96 Message::AddMessage(_("Full snail trail"));
97 break;
101 ActionInterface::SendMapSettings(true);
104 void
105 InputEvents::eventTerrainTopology(const TCHAR *misc)
107 eventTerrainTopography(misc);
110 // Do JUST Terrain/Topography (toggle any, on/off any, show)
111 void
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
143 void
144 InputEvents::eventAudioDeadband(const TCHAR *misc)
146 SoundSettings &settings = CommonInterface::SetUISettings().sound;
148 if (StringIsEqual(misc, _T("+"))) {
149 if (settings.sound_deadband >= 40)
150 return;
152 ++settings.sound_deadband;
154 if (StringIsEqual(misc, _T("-"))) {
155 if (settings.sound_deadband <= 0)
156 return;
158 --settings.sound_deadband;
161 Profile::Set(ProfileKeys::SoundDeadband, settings.sound_deadband);
163 // TODO feature: send to vario if available
166 // Bugs
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
173 void
174 InputEvents::eventBugs(const TCHAR *misc)
176 if (protected_task_manager == NULL)
177 return;
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;
185 if (BUGS > fixed(1))
186 BUGS = fixed(1);
187 } else if (StringIsEqual(misc, _T("down"))) {
188 BUGS -= fixed(1) / 10;
189 if (BUGS < fixed(0.5))
190 BUGS = fixed(0.5);
191 } else if (StringIsEqual(misc, _T("max")))
192 BUGS = fixed(1);
193 else if (StringIsEqual(misc, _T("min")))
194 BUGS = fixed(0.5);
195 else if (StringIsEqual(misc, _T("show"))) {
196 TCHAR Temp[100];
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);
207 // Ballast
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
214 void
215 InputEvents::eventBallast(const TCHAR *misc)
217 if (protected_task_manager == NULL)
218 return;
220 GlidePolar &polar =
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))
228 BALLAST = fixed(1);
229 } else if (StringIsEqual(misc, _T("down"))) {
230 BALLAST -= fixed(1) / 10;
231 if (BALLAST < fixed(0))
232 BALLAST = fixed(0);
233 } else if (StringIsEqual(misc, _T("max")))
234 BALLAST = fixed(1);
235 else if (StringIsEqual(misc, _T("min")))
236 BALLAST = fixed(0);
237 else if (StringIsEqual(misc, _T("show"))) {
238 TCHAR Temp[100];
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);
250 // ProfileLoad
251 // Loads the profile of the specified filename
252 void
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...
264 Profile::Use();
268 // ProfileSave
269 // Saves the profile to the specified filename
270 void
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
282 void
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"))) {
290 fixed temperature =
291 CommonInterface::GetComputerSettings().forecast_temperature;
292 TCHAR Temp[100];
293 _stprintf(Temp, _T("%f"),
294 (double)Units::ToUserTemperature(temperature));
295 Message::AddMessage(_("Forecast temperature"), Temp);
299 void
300 InputEvents::eventDeclutterLabels(const TCHAR *misc)
302 static const TCHAR *const msg[] = {
303 N_("All"),
304 N_("Task & Landables"),
305 N_("Task"),
306 N_("None"),
307 N_("Task & Airfields"),
309 static constexpr unsigned int n = ARRAY_SIZE(msg);
311 static const TCHAR *const actions[n] = {
312 _T("all"),
313 _T("task+landables"),
314 _T("task"),
315 _T("none")
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"))) {
324 TCHAR tbuf[64];
325 _stprintf(tbuf, _T("%s: %s"), _("Waypoint labels"),
326 gettext(msg[(unsigned)wls]));
327 Message::AddMessage(tbuf);
329 else {
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);
342 void
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;
359 TriggerMapUpdate();
362 void
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
391 0 Show
392 1 Topography = ON
393 2 Topography = OFF
394 3 Terrain = ON
395 4 Terrain = OFF
396 -1 Toggle through 4 stages (off/off, off/on, on/off, on/on)
397 -2 Toggle terrain
398 -3 Toggle topography
401 void
402 InputEvents::sub_TerrainTopography(int vswitch)
404 MapSettings &settings_map = CommonInterface::SetMapSettings();
406 if (vswitch == -1) {
407 // toggle through 4 possible options
408 char val = 0;
410 if (settings_map.topography_enabled)
411 val++;
412 if (settings_map.terrain.enable)
413 val += (char)2;
415 val++;
416 if (val > 3)
417 val = 0;
419 settings_map.topography_enabled = ((val & 0x01) == 0x01);
420 settings_map.terrain.enable = ((val & 0x02) == 0x02);
421 } else if (vswitch == -2)
422 // toggle terrain
423 settings_map.terrain.enable = !settings_map.terrain.enable;
424 else if (vswitch == -3)
425 // toggle topography
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)
434 // Turn on terrain
435 settings_map.terrain.enable = true;
436 else if (vswitch == 4)
437 // Turn off terrain
438 settings_map.terrain.enable = false;
439 else if (vswitch == 0) {
440 // Show terrain/topography
441 // ARH Let user know what's happening
442 TCHAR buf[128];
444 if (settings_map.topography_enabled)
445 _stprintf(buf, _T("\r\n%s / "), _("On"));
446 else
447 _stprintf(buf, _T("\r\n%s / "), _("Off"));
449 _tcscat(buf, settings_map.terrain.enable
450 ? _("On") : _("Off"));
452 Message::AddMessage(_("Topography/Terrain"), buf);
453 return;
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);