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"
37 #include "PageActions.hpp"
38 #include "Util/Clamp.hpp"
40 // eventAutoZoom - Turn on|off|toggle AutoZoom
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
50 // n.n - Zoom to a set scale
51 // show - Show current zoom scale
53 InputEvents::eventZoom(const TCHAR
* misc
)
55 // JMW pass through to handler in MapWindow
61 MapSettings
&settings_map
= CommonInterface::SetMapSettings();
63 if (StringIsEqual(misc
, _T("auto toggle")))
65 else if (StringIsEqual(misc
, _T("auto on")))
67 else if (StringIsEqual(misc
, _T("auto off")))
69 else if (StringIsEqual(misc
, _T("auto show"))) {
70 if (settings_map
.auto_zoom_enabled
)
71 Message::AddMessage(_("Auto. zoom on"));
73 Message::AddMessage(_("Auto. zoom off"));
74 } else if (StringIsEqual(misc
, _T("slowout")))
76 else if (StringIsEqual(misc
, _T("slowin")))
78 else if (StringIsEqual(misc
, _T("out")))
80 else if (StringIsEqual(misc
, _T("in")))
82 else if (StringIsEqual(misc
, _T("-")))
84 else if (StringIsEqual(misc
, _T("+")))
86 else if (StringIsEqual(misc
, _T("--")))
88 else if (StringIsEqual(misc
, _T("++")))
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"));
100 Message::AddMessage(_("Circling zoom off"));
103 double zoom
= _tcstod(misc
, &endptr
);
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.
118 * toogle Toogles pan mode
123 * @todo feature: n,n Go that direction - +/-
124 * @todo feature: ??? Go to particular point
125 * @todo feature: ??? Go to waypoint (eg: next, named)
128 InputEvents::eventPan(const TCHAR
*misc
)
130 if (StringIsEqual(misc
, _T("toggle")))
133 else if (StringIsEqual(misc
, _T("on")))
136 else if (StringIsEqual(misc
, _T("off")))
139 else if (StringIsEqual(misc
, _T("up")))
141 // Scroll wheel on the HP31x series should zoom in pan mode
146 else if (StringIsEqual(misc
, _T("down")))
148 // Scroll wheel on the HP31x series should zoom in pan mode
151 sub_PanCursor(0, -1);
153 else if (StringIsEqual(misc
, _T("left")))
156 else if (StringIsEqual(misc
, _T("right")))
157 sub_PanCursor(-1, 0);
159 XCSoarInterface::SendMapSettings(true);
163 InputEvents::sub_PanCursor(int dx
, int dy
)
165 GlueMapWindow
*map_window
= UIGlobals::GetMapIfActive();
166 if (map_window
== NULL
|| !map_window
->IsPanning())
169 const WindowProjection
&projection
= map_window
->VisibleProjection();
170 if (!projection
.IsValid())
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)
183 InputEvents::sub_AutoZoom(int vswitch
)
185 MapSettings
&settings_map
= CommonInterface::SetMapSettings();
188 settings_map
.auto_zoom_enabled
= !settings_map
.auto_zoom_enabled
;
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);
202 InputEvents::sub_SetZoom(fixed value
)
204 MapSettings
&settings_map
= CommonInterface::SetMapSettings();
205 GlueMapWindow
*map_window
= PageActions::ShowMap();
206 if (map_window
== NULL
)
209 const DisplayMode displayMode
= CommonInterface::GetUIState().display_mode
;
210 if (settings_map
.auto_zoom_enabled
&&
211 !(displayMode
== DisplayMode::CIRCLING
&& settings_map
.circle_zoom_enabled
) &&
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
224 : std::max(scale_100m
, scale_2min_distance
);
226 value
= Clamp(value
, minreasonable
, scale_1600km
);
227 map_window
->SetMapScale(value
);
228 map_window
->QuickRedraw();
232 InputEvents::sub_ScaleZoom(int vswitch
)
234 const GlueMapWindow
*map_window
= PageActions::ShowMap();
235 if (map_window
== NULL
)
238 const MapWindowProjection
&projection
=
239 map_window
->VisibleProjection();
240 if (!projection
.IsValid())
243 fixed value
= projection
.GetMapScale();
245 if (projection
.HaveScaleList()) {
246 value
= projection
.StepMapScale(value
, -vswitch
);
250 value
/= fixed_sqrt_two
;
251 else if (vswitch
== -1)
253 value
*= fixed_sqrt_two
;
254 else if (vswitch
== 2)
257 else if (vswitch
== -2)