Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / src / Renderer / CuRenderer.cpp
bloba2914fc7609f2a58c2bc4cf946366f4383406aaf
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 "CuRenderer.hpp"
25 #include "ChartRenderer.hpp"
26 #include "Atmosphere/CuSonde.hpp"
27 #include "Units/Units.hpp"
28 #include "Language/Language.hpp"
30 #include <algorithm>
31 #include <stdio.h>
33 using std::min;
34 using std::max;
36 void
37 RenderTemperatureChart(Canvas &canvas, const PixelRect rc,
38 const ChartLook &chart_look,
39 const CuSonde &cu_sonde)
41 ChartRenderer chart(chart_look, canvas, rc);
43 int hmin = 10000;
44 int hmax = -10000;
45 fixed tmin = cu_sonde.maxGroundTemperature;
46 fixed tmax = cu_sonde.maxGroundTemperature;
48 // find range for scaling of graph
49 for (unsigned i = 0; i < cu_sonde.NUM_LEVELS - 1u; i++) {
50 if (cu_sonde.cslevels[i].empty())
51 continue;
53 hmin = min(hmin, (int)i);
54 hmax = max(hmax, (int)i);
56 tmin = min(tmin, min(cu_sonde.cslevels[i].tempDry,
57 min(cu_sonde.cslevels[i].airTemp,
58 cu_sonde.cslevels[i].dewpoint)));
59 tmax = max(tmax, max(cu_sonde.cslevels[i].tempDry,
60 max(cu_sonde.cslevels[i].airTemp,
61 cu_sonde.cslevels[i].dewpoint)));
64 if (hmin >= hmax) {
65 chart.DrawNoData();
66 return;
69 chart.ScaleYFromValue(fixed(hmin));
70 chart.ScaleYFromValue(fixed(hmax));
71 chart.ScaleXFromValue(tmin);
72 chart.ScaleXFromValue(tmax);
74 bool labelDry = false;
75 bool labelAir = false;
76 bool labelDew = false;
78 int ipos = 0;
80 for (unsigned i = 0; i < cu_sonde.NUM_LEVELS - 1u; i++) {
81 if (cu_sonde.cslevels[i].empty() ||
82 cu_sonde.cslevels[i + 1].empty())
83 continue;
85 ipos++;
87 chart.DrawLine(cu_sonde.cslevels[i].tempDry, fixed(i),
88 cu_sonde.cslevels[i + 1].tempDry, fixed(i + 1),
89 ChartLook::STYLE_REDTHICK);
91 chart.DrawLine(cu_sonde.cslevels[i].airTemp, fixed(i),
92 cu_sonde.cslevels[i + 1].airTemp, fixed(i + 1),
93 ChartLook::STYLE_MEDIUMBLACK);
95 chart.DrawLine(cu_sonde.cslevels[i].dewpoint, fixed(i),
96 cu_sonde.cslevels[i + 1].dewpoint, fixed(i + 1),
97 ChartLook::STYLE_BLUETHIN);
99 if (ipos > 2) {
100 if (!labelDry) {
101 chart.DrawLabel(_T("DALR"),
102 cu_sonde.cslevels[i + 1].tempDry, fixed(i));
103 labelDry = true;
104 } else if (!labelAir) {
105 chart.DrawLabel(_T("Air"),
106 cu_sonde.cslevels[i + 1].airTemp, fixed(i));
107 labelAir = true;
108 } else if (!labelDew) {
109 chart.DrawLabel(_T("Dew"),
110 cu_sonde.cslevels[i + 1].dewpoint, fixed(i));
111 labelDew = true;
116 chart.DrawXLabel(_T("T"), _T(DEG "C"));
117 chart.DrawYLabel(_T("h"));
120 void
121 TemperatureChartCaption(TCHAR *sTmp, const CuSonde &cu_sonde)
123 _stprintf(sTmp, _T("%s:\r\n %5.0f %s\r\n\r\n%s:\r\n %5.0f %s\r\n"),
124 _("Thermal height"),
125 (double)Units::ToUserAltitude(cu_sonde.thermalHeight),
126 Units::GetAltitudeName(),
127 _("Cloud base"),
128 (double)Units::ToUserAltitude(cu_sonde.cloudBase),
129 Units::GetAltitudeName());