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 "InfoBoxes/Content/Weather.hpp"
25 #include "InfoBoxes/Panel/Panel.hpp"
26 #include "InfoBoxes/Panel/WindEdit.hpp"
27 #include "InfoBoxes/Data.hpp"
28 #include "Interface.hpp"
29 #include "Dialogs/dlgInfoBoxAccess.hpp"
30 #include "Util/Macros.hpp"
31 #include "Units/Units.hpp"
32 #include "Language/Language.hpp"
33 #include "Formatter/UserUnits.hpp"
34 #include "Formatter/AngleFormatter.hpp"
35 #include "Screen/Layout.hpp"
36 #include "Renderer/WindArrowRenderer.hpp"
37 #include "UIGlobals.hpp"
38 #include "Look/Look.hpp"
44 UpdateInfoBoxHumidity(InfoBoxData
&data
)
46 const NMEAInfo
&basic
= CommonInterface::Basic();
47 if (!basic
.humidity_available
) {
53 data
.UnsafeFormatValue( _T("%d"), (int)basic
.humidity
);
57 UpdateInfoBoxTemperature(InfoBoxData
&data
)
59 const NMEAInfo
&basic
= CommonInterface::Basic();
60 if (!basic
.temperature_available
) {
66 data
.SetValue(_T("%2.1f"),
67 Units::ToUserTemperature(basic
.temperature
));
69 data
.SetValueUnit(Units::current
.temperature_unit
);
73 InfoBoxContentTemperatureForecast::Update(InfoBoxData
&data
)
75 fixed temperature
= CommonInterface::GetComputerSettings().forecast_temperature
;
76 data
.SetValue(_T("%2.1f"),
77 Units::ToUserTemperature(temperature
));
79 data
.SetValueUnit(Units::current
.temperature_unit
);
83 InfoBoxContentTemperatureForecast::HandleKey(const InfoBoxKeyCodes keycode
)
87 CommonInterface::SetComputerSettings().forecast_temperature
+= fixed(0.5);
91 CommonInterface::SetComputerSettings().forecast_temperature
-= fixed(0.5);
102 * Subpart callback function pointers
106 /* gcc gives "redeclaration differs in 'constexpr'" */
109 const InfoBoxPanel wind_infobox_panels
[] = {
110 { N_("Edit"), LoadWindEditPanel
},
115 InfoBoxContentWindArrow::GetDialogContent()
117 return wind_infobox_panels
;
121 UpdateInfoBoxWindSpeed(InfoBoxData
&data
)
123 const DerivedInfo
&info
= CommonInterface::Calculated();
124 if (!info
.wind_available
) {
130 data
.SetValue(_T("%2.0f"),
131 Units::ToUserWindSpeed(info
.wind
.norm
));
134 data
.SetValueUnit(Units::current
.wind_speed_unit
);
137 data
.SetComment(info
.wind
.bearing
);
141 UpdateInfoBoxWindBearing(InfoBoxData
&data
)
143 const DerivedInfo
&info
= CommonInterface::Calculated();
144 if (!info
.wind_available
) {
149 data
.SetValue(info
.wind
.bearing
);
152 FormatUserWindSpeed(info
.wind
.norm
, buffer
, true, false);
153 data
.SetComment(buffer
);
157 UpdateInfoBoxHeadWind(InfoBoxData
&data
)
159 const DerivedInfo
&info
= CommonInterface::Calculated();
160 if (!info
.head_wind_available
) {
166 data
.SetValue(_T("%2.0f"),
167 Units::ToUserWindSpeed(info
.head_wind
));
170 data
.SetValueUnit(Units::current
.wind_speed_unit
);
174 UpdateInfoBoxHeadWindSimplified(InfoBoxData
&data
)
176 const NMEAInfo
&basic
= CommonInterface::Basic();
177 if (!basic
.ground_speed_available
|| !basic
.airspeed_available
) {
182 fixed value
= basic
.true_airspeed
- basic
.ground_speed
;
185 data
.SetValue(_T("%2.0f"), Units::ToUserWindSpeed(value
));
188 data
.SetValueUnit(Units::current
.wind_speed_unit
);
192 InfoBoxContentWindArrow::Update(InfoBoxData
&data
)
194 const DerivedInfo
&info
= CommonInterface::Calculated();
195 if (!info
.wind_available
|| info
.wind
.IsZero()) {
202 TCHAR speed_buffer
[16], bearing_buffer
[16];
203 FormatUserWindSpeed(info
.wind
.norm
, speed_buffer
, true, false);
204 FormatBearing(bearing_buffer
, ARRAY_SIZE(bearing_buffer
), info
.wind
.bearing
);
206 StaticString
<32> buffer
;
207 buffer
.Format(_T("%s / %s"), bearing_buffer
, speed_buffer
);
208 data
.SetComment(buffer
);
212 InfoBoxContentWindArrow::OnCustomPaint(Canvas
&canvas
, const PixelRect
&rc
)
214 const auto &info
= CommonInterface::Calculated();
216 const RasterPoint pt
= rc
.GetCenter();
218 UPixelScalar padding
= Layout::FastScale(10);
219 UPixelScalar size
= std::min(rc
.right
- rc
.left
, rc
.bottom
- rc
.top
);
224 // Normalize the size because the Layout::Scale is applied
225 // by the DrawArrow() function again
226 size
= size
* 100 / Layout::Scale(100);
228 auto angle
= info
.wind
.bearing
- CommonInterface::Basic().attitude
.heading
;
231 std::min(size
, (UPixelScalar
)std::max(10, iround(info
.wind
.norm
* 4)));
233 PixelScalar offset
= -length
/ 2;
235 auto style
= CommonInterface::GetMapSettings().wind_arrow_style
;
237 WindArrowRenderer
renderer(UIGlobals::GetLook().wind_arrow_info_box
);
238 renderer
.DrawArrow(canvas
, pt
, angle
, length
, style
, offset
);