dlgTextEntry_Keyboard: rename to TouchTextEntry
[xcsoar.git] / src / Input / InputEventsMap.cpp
blob045672716e57d3715f8fc76444b45f0c82733660
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 "Message.hpp"
27 #include "Interface.hpp"
28 #include "ActionInterface.hpp"
29 #include "Profile/Profile.hpp"
30 #include "Profile/ProfileKeys.hpp"
31 #include "UIGlobals.hpp"
32 #include "MapWindow/GlueMapWindow.hpp"
33 #include "Units/Units.hpp"
34 #include "UIState.hpp"
35 #include "Asset.hpp"
36 #include "Pan.hpp"
37 #include "PageActions.hpp"
38 #include "Util/Clamp.hpp"
40 // eventAutoZoom - Turn on|off|toggle AutoZoom
41 // misc:
42 // auto on - Turn on if not already
43 // auto off - Turn off if not already
44 // auto toggle - Toggle current full screen status
45 // auto show - Shows autozoom status
46 // + - Zoom in
47 // ++ - Zoom in near
48 // - - Zoom out
49 // -- - Zoom out far
50 // n.n - Zoom to a set scale
51 // show - Show current zoom scale
52 void
53 InputEvents::eventZoom(const TCHAR* misc)
55 // JMW pass through to handler in MapWindow
56 // here:
57 // -1 means toggle
58 // 0 means off
59 // 1 means on
61 MapSettings &settings_map = CommonInterface::SetMapSettings();
63 if (StringIsEqual(misc, _T("auto toggle")))
64 sub_AutoZoom(-1);
65 else if (StringIsEqual(misc, _T("auto on")))
66 sub_AutoZoom(1);
67 else if (StringIsEqual(misc, _T("auto off")))
68 sub_AutoZoom(0);
69 else if (StringIsEqual(misc, _T("auto show"))) {
70 if (settings_map.auto_zoom_enabled)
71 Message::AddMessage(_("Auto. zoom on"));
72 else
73 Message::AddMessage(_("Auto. zoom off"));
74 } else if (StringIsEqual(misc, _T("slowout")))
75 sub_ScaleZoom(-1);
76 else if (StringIsEqual(misc, _T("slowin")))
77 sub_ScaleZoom(1);
78 else if (StringIsEqual(misc, _T("out")))
79 sub_ScaleZoom(-1);
80 else if (StringIsEqual(misc, _T("in")))
81 sub_ScaleZoom(1);
82 else if (StringIsEqual(misc, _T("-")))
83 sub_ScaleZoom(-1);
84 else if (StringIsEqual(misc, _T("+")))
85 sub_ScaleZoom(1);
86 else if (StringIsEqual(misc, _T("--")))
87 sub_ScaleZoom(-2);
88 else if (StringIsEqual(misc, _T("++")))
89 sub_ScaleZoom(2);
90 else if (StringIsEqual(misc, _T("circlezoom toggle"))) {
91 settings_map.circle_zoom_enabled = !settings_map.circle_zoom_enabled;
92 } else if (StringIsEqual(misc, _T("circlezoom on"))) {
93 settings_map.circle_zoom_enabled = true;
94 } else if (StringIsEqual(misc, _T("circlezoom off"))) {
95 settings_map.circle_zoom_enabled = false;
96 } else if (StringIsEqual(misc, _T("circlezoom show"))) {
97 if (settings_map.circle_zoom_enabled)
98 Message::AddMessage(_("Circling zoom on"));
99 else
100 Message::AddMessage(_("Circling zoom off"));
101 } else {
102 TCHAR *endptr;
103 double zoom = _tcstod(misc, &endptr);
104 if (endptr == misc)
105 return;
107 sub_SetZoom(Units::ToSysDistance(fixed(zoom)));
110 XCSoarInterface::SendMapSettings(true);
114 * This function handles all "pan" input events
115 * @param misc A string describing the desired pan action.
116 * on Turn pan on
117 * off Turn pan off
118 * toogle Toogles pan mode
119 * up Pan up
120 * down Pan down
121 * left Pan left
122 * right Pan right
123 * @todo feature: n,n Go that direction - +/-
124 * @todo feature: ??? Go to particular point
125 * @todo feature: ??? Go to waypoint (eg: next, named)
127 void
128 InputEvents::eventPan(const TCHAR *misc)
130 if (StringIsEqual(misc, _T("toggle")))
131 TogglePan();
133 else if (StringIsEqual(misc, _T("on")))
134 EnterPan();
136 else if (StringIsEqual(misc, _T("off")))
137 LeavePan();
139 else if (StringIsEqual(misc, _T("up")))
140 if (IsHP31X())
141 // Scroll wheel on the HP31x series should zoom in pan mode
142 sub_ScaleZoom(1);
143 else
144 sub_PanCursor(0, 1);
146 else if (StringIsEqual(misc, _T("down")))
147 if (IsHP31X())
148 // Scroll wheel on the HP31x series should zoom in pan mode
149 sub_ScaleZoom(-1);
150 else
151 sub_PanCursor(0, -1);
153 else if (StringIsEqual(misc, _T("left")))
154 sub_PanCursor(1, 0);
156 else if (StringIsEqual(misc, _T("right")))
157 sub_PanCursor(-1, 0);
159 XCSoarInterface::SendMapSettings(true);
162 void
163 InputEvents::sub_PanCursor(int dx, int dy)
165 GlueMapWindow *map_window = UIGlobals::GetMapIfActive();
166 if (map_window == NULL || !map_window->IsPanning())
167 return;
169 const WindowProjection &projection = map_window->VisibleProjection();
170 if (!projection.IsValid())
171 return;
173 RasterPoint pt = projection.GetScreenOrigin();
174 pt.x -= dx * projection.GetScreenWidth() / 4;
175 pt.y -= dy * projection.GetScreenHeight() / 4;
176 map_window->SetLocation(projection.ScreenToGeo(pt));
178 map_window->QuickRedraw();
181 // called from UI or input event handler (same thread)
182 void
183 InputEvents::sub_AutoZoom(int vswitch)
185 MapSettings &settings_map = CommonInterface::SetMapSettings();
187 if (vswitch == -1)
188 settings_map.auto_zoom_enabled = !settings_map.auto_zoom_enabled;
189 else
190 settings_map.auto_zoom_enabled = (vswitch != 0); // 0 off, 1 on
192 Profile::Set(ProfileKeys::AutoZoom, settings_map.auto_zoom_enabled);
194 if (settings_map.auto_zoom_enabled &&
195 UIGlobals::GetMap() != NULL)
196 UIGlobals::GetMap()->SetPan(false);
198 ActionInterface::SendMapSettings(true);
201 void
202 InputEvents::sub_SetZoom(fixed value)
204 MapSettings &settings_map = CommonInterface::SetMapSettings();
205 GlueMapWindow *map_window = PageActions::ShowMap();
206 if (map_window == NULL)
207 return;
209 const DisplayMode displayMode = CommonInterface::GetUIState().display_mode;
210 if (settings_map.auto_zoom_enabled &&
211 !(displayMode == DisplayMode::CIRCLING && settings_map.circle_zoom_enabled) &&
212 !IsPanning()) {
213 settings_map.auto_zoom_enabled = false; // disable autozoom if user manually changes zoom
214 Profile::Set(ProfileKeys::AutoZoom, false);
215 Message::AddMessage(_("Auto. zoom off"));
218 fixed vmin = CommonInterface::GetComputerSettings().polar.glide_polar_task.GetVMin();
219 fixed scale_2min_distance = vmin * 12;
220 const fixed scale_100m = fixed(10);
221 const fixed scale_1600km = fixed(1600*100);
222 fixed minreasonable = displayMode == DisplayMode::CIRCLING
223 ? scale_100m
224 : std::max(scale_100m, scale_2min_distance);
226 value = Clamp(value, minreasonable, scale_1600km);
227 map_window->SetMapScale(value);
228 map_window->QuickRedraw();
231 void
232 InputEvents::sub_ScaleZoom(int vswitch)
234 const GlueMapWindow *map_window = PageActions::ShowMap();
235 if (map_window == NULL)
236 return;
238 const MapWindowProjection &projection =
239 map_window->VisibleProjection();
240 if (!projection.IsValid())
241 return;
243 fixed value = projection.GetMapScale();
245 if (projection.HaveScaleList()) {
246 value = projection.StepMapScale(value, -vswitch);
247 } else {
248 if (vswitch == 1)
249 // zoom in a little
250 value /= fixed_sqrt_two;
251 else if (vswitch == -1)
252 // zoom out a little
253 value *= fixed_sqrt_two;
254 else if (vswitch == 2)
255 // zoom in a lot
256 value /= 2;
257 else if (vswitch == -2)
258 // zoom out a lot
259 value *= 2;
262 sub_SetZoom(value);