Makefile: remove spurious tab
[xcsoar.git] / src / MapWindow / MapWindowTraffic.cpp
blob9b0563d78e94c2a8de07cdb0845880b663bdbba7
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 "MapWindow.hpp"
25 #include "Math/Screen.hpp"
26 #include "Screen/Icon.hpp"
27 #include "Screen/Layout.hpp"
28 #include "Util/StringUtil.hpp"
29 #include "GlideSolvers/GlidePolar.hpp"
30 #include "Formatter/UserUnits.hpp"
31 #include "Look/TrafficLook.hpp"
32 #include "Renderer/TextInBox.hpp"
33 #include "Renderer/TrafficRenderer.hpp"
34 #include "FLARM/Friends.hpp"
35 #include "Look/Fonts.hpp"
36 #include "Tracking/SkyLines/Data.hpp"
38 #include <stdio.h>
40 /**
41 * Draws the FLARM traffic icons onto the given canvas
42 * @param canvas Canvas for drawing
44 void
45 MapWindow::DrawFLARMTraffic(Canvas &canvas,
46 const RasterPoint aircraft_pos) const
48 // Return if FLARM icons on moving map are disabled
49 if (!GetMapSettings().show_flarm_on_map)
50 return;
52 // Return if FLARM data is not available
53 const TrafficList &flarm = Basic().flarm.traffic;
54 if (flarm.IsEmpty())
55 return;
57 const WindowProjection &projection = render_projection;
59 // if zoomed in too far out, dont draw traffic since it will be too close to
60 // the glider and so will be meaningless (serves only to clutter, cant help
61 // the pilot)
62 if (projection.GetMapScale() > fixed(7300))
63 return;
65 canvas.Select(Fonts::map);
67 // Circle through the FLARM targets
68 for (auto it = flarm.list.begin(), end = flarm.list.end();
69 it != end; ++it) {
70 const FlarmTraffic &traffic = *it;
72 if (!traffic.location_available)
73 continue;
75 // Save the location of the FLARM target
76 GeoPoint target_loc = traffic.location;
78 // Points for the screen coordinates for the icon, name and average climb
79 RasterPoint sc, sc_name, sc_av;
81 // If FLARM target not on the screen, move to the next one
82 if (!projection.GeoToScreenIfVisible(target_loc, sc))
83 continue;
85 // Draw the name 16 points below the icon
86 sc_name = sc;
87 sc_name.y -= Layout::Scale(20);
89 // Draw the average climb value above the icon
90 sc_av = sc;
91 sc_av.y += Layout::Scale(5);
93 TextInBoxMode mode;
94 mode.shape = LabelShape::OUTLINED;
96 // JMW TODO enhancement: decluttering of FLARM altitudes (sort by max lift)
98 int dx = sc_av.x - aircraft_pos.x;
99 int dy = sc_av.y - aircraft_pos.y;
101 // only draw labels if not close to aircraft
102 if (dx * dx + dy * dy > Layout::Scale(30 * 30)) {
103 // If FLARM callsign/name available draw it to the canvas
104 if (traffic.HasName() && !StringIsEmpty(traffic.name))
105 TextInBox(canvas, traffic.name, sc_name.x, sc_name.y,
106 mode, GetClientRect());
108 if (traffic.climb_rate_avg30s >= fixed(0.1)) {
109 // If average climb data available draw it to the canvas
110 TCHAR label_avg[100];
111 FormatUserVerticalSpeed(traffic.climb_rate_avg30s,
112 label_avg, false);
113 TextInBox(canvas, label_avg, sc_av.x, sc_av.y, mode, GetClientRect());
117 auto color = FlarmFriends::GetFriendColor(traffic.id);
118 TrafficRenderer::Draw(canvas, traffic_look, traffic,
119 traffic.track - projection.GetScreenAngle(),
120 color, sc);
125 * Draws the teammate icon to the given canvas
126 * @param canvas Canvas for drawing
128 void
129 MapWindow::DrawTeammate(Canvas &canvas) const
131 const TeamInfo &teamcode_info = Calculated();
133 if (teamcode_info.teammate_available) {
134 RasterPoint sc;
135 if (render_projection.GeoToScreenIfVisible(teamcode_info.teammate_location,
136 sc))
137 traffic_look.teammate_icon.Draw(canvas, sc);
141 #ifdef HAVE_SKYLINES_TRACKING_HANDLER
143 void
144 MapWindow::DrawSkyLinesTraffic(Canvas &canvas) const
146 if (skylines_data == nullptr)
147 return;
149 canvas.Select(Fonts::map);
151 ScopeLock protect(skylines_data->mutex);
152 for (auto &i : skylines_data->traffic) {
153 RasterPoint pt;
154 if (render_projection.GeoToScreenIfVisible(i.second.location, pt)) {
155 traffic_look.teammate_icon.Draw(canvas, pt);
160 #endif