33extern int g_iDashDepthUnit;
35DashboardInstrument_Depth::DashboardInstrument_Depth(
36 wxWindow* parent, wxWindowID
id, wxString title,
44 for (
int idx = 0; idx < DEPTH_RECORD_COUNT; idx++) {
45 m_array_depth[idx] = 0;
49wxSize DashboardInstrument_Depth::GetSize(
int orient, wxSize hint) {
52 InitDataTextHeight(
"15.7 Feet", w);
58 f = m_Properties->m_LabelFont.GetChosenFont();
59 dc.GetTextExtent(
"20.8 C", &w_label, &h_label,
nullptr,
nullptr, &f);
62 f = g_pFontLabel->GetChosenFont();
63 dc.GetTextExtent(
"20.8 C", &w_label, &h_label,
nullptr,
nullptr, &f);
68 static_cast<int>(m_DataTextHeight + 4 * m_DataTextHeight + h_label +
69 m_DataTextHeight * g_TitleVerticalOffset);
70 InitTitleAndDataPosition(drawHeight);
71 int y_total = GetFullHeight(drawHeight);
73 if (orient == wxHORIZONTAL) {
74 return wxSize(wxMax(w + m_DataMargin, DefaultWidth),
75 wxMax(y_total, hint.y));
77 return wxSize(wxMax(hint.x, wxMax(w + m_DataMargin, DefaultWidth)),
82void DashboardInstrument_Depth::SetData(
DASH_CAP st,
double data,
85 m_depth = std::isnan(data) ? 0.0 : data;
87 for (
int idx = 1; idx < DEPTH_RECORD_COUNT; idx++) {
88 m_array_depth[idx - 1] = m_array_depth[idx];
90 m_array_depth[DEPTH_RECORD_COUNT - 1] = m_depth;
93 if (!std::isnan(data)) {
94 m_temp = wxString::Format(
"%.1f", data) + DEGREE_SIGN +
unit;
101void DashboardInstrument_Depth::Draw(wxGCDC* dc) {
106void DashboardInstrument_Depth::DrawBackground(wxGCDC* dc) {
107 wxSize size = GetClientSize();
110 dc->SetTextForeground(
111 GetColourSchemeFont(m_Properties->m_LabelFont.GetColour()));
113 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
114 GetColourSchemeFont(g_pFontLabel->GetColour())) {
115 GetGlobalColor(
"DASHL", &cl);
116 dc->SetTextForeground(cl);
118 dc->SetTextForeground(GetColourSchemeFont(g_pFontLabel->GetColour()));
121 pen.SetStyle(wxPENSTYLE_SOLID);
123 cl = GetColourSchemeFont(m_Properties->m_SmallFont.GetColour());
126 cl = GetColourSchemeFont(g_pFontSmall->GetColour());
132 int drawHeight = GetDataBottom(size.y) - m_DataTop;
133 InitTitleAndDataPosition(drawHeight);
135 m_plotup = m_DataTop + m_DataTextHeight;
136 m_plotdown = m_DataTop + drawHeight - h_label;
137 m_plotheight = m_plotdown - m_plotup;
139 dc->DrawLine(3, m_plotup, size.x - 3, m_plotup);
140 dc->DrawLine(3, m_plotdown, size.x - 3, m_plotdown);
143 pen.SetStyle(wxPENSTYLE_SHORT_DASH);
145 pen.SetStyle(wxPENSTYLE_DOT);
150 dc->DrawLine(3, m_plotup + m_plotheight / 4, size.x - 3,
151 m_plotup + m_plotheight / 4);
152 dc->DrawLine(3, m_plotup + m_plotheight * 2 / 4, size.x - 3,
153 m_plotup + m_plotheight * 2 / 4);
154 dc->DrawLine(3, m_plotup + m_plotheight * 3 / 4, size.x - 3,
155 m_plotup + m_plotheight * 3 / 4);
157 dc->SetFont(m_Properties->m_SmallFont.GetChosenFont());
158 dc->SetTextForeground(
159 GetColourSchemeFont(m_Properties->m_SmallFont.GetColour()));
161 dc->SetFont(g_pFontSmall->GetChosenFont());
162 dc->SetTextForeground(GetColourSchemeFont(g_pFontSmall->GetColour()));
165 for (
int idx = 0; idx < DEPTH_RECORD_COUNT; idx++) {
166 if (m_array_depth[idx] > m_max_depth) m_max_depth = m_array_depth[idx];
172 label.Printf(
"%.0f " + m_depth_unit, 0.0);
176 f = m_Properties->m_SmallFont.GetChosenFont();
178 f = g_pFontSmall->GetChosenFont();
179 dc->GetTextExtent(label, &width, &height,
nullptr,
nullptr, &f);
180 dc->DrawText(label, size.x - width - 1, m_plotup - height);
182 label.Printf(
"%.0f " + m_depth_unit, m_max_depth);
184 f = m_Properties->m_SmallFont.GetChosenFont();
186 f = g_pFontSmall->GetChosenFont();
187 dc->GetTextExtent(label, &width, &height,
nullptr,
nullptr, &f);
188 dc->DrawText(label, size.x - width - 1, m_plotdown);
191void DashboardInstrument_Depth::DrawForeground(wxGCDC* dc) {
192 wxSize size = GetClientSize();
195 cl = GetColourSchemeFont(m_Properties->m_LabelFont.GetColour());
197 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
198 GetColourSchemeFont(g_pFontLabel->GetColour()))
199 GetGlobalColor(
"DASHL", &cl);
201 cl = GetColourSchemeFont(g_pFontLabel->GetColour());
204 brush.SetStyle(wxBRUSHSTYLE_SOLID);
207 dc->SetPen(*wxTRANSPARENT_PEN);
209 double ratioH = double(m_plotheight) / m_max_depth;
210 double ratioW = double(size.x - 6) / (DEPTH_RECORD_COUNT - 1);
211 wxPoint points[DEPTH_RECORD_COUNT + 2];
216 points[0].y = m_plotdown;
218 for (
int idx = 0; idx < DEPTH_RECORD_COUNT - 1; idx++) {
219 points[1].x = points[0].x;
220 if (m_array_depth[idx])
221 points[1].y = m_plotup + m_array_depth[idx] * ratioH;
223 points[1].y = m_plotdown;
225 points[2].x = points[1].x + ratioW;
226 if (m_array_depth[idx + 1])
227 points[2].y = m_plotup + m_array_depth[idx + 1] * ratioH;
229 points[2].y = m_plotdown;
231 points[3].x = points[2].x;
232 points[3].y = m_plotdown;
233 dc->DrawPolygon(4, points);
235 points[0].x = points[2].x;
236 points[0].y = m_plotdown;
240 for (
int idx = 0; idx < DEPTH_RECORD_COUNT; idx++) {
241 points[idx].x =
static_cast<int>(idx * ratioW + 3);
242 if (m_array_depth[idx])
243 points[idx].y =
static_cast<int>(m_plotup + m_array_depth[idx] * ratioH);
245 points[idx].y = m_plotdown;
247 points[DEPTH_RECORD_COUNT].x = size.x - 3;
248 points[DEPTH_RECORD_COUNT].y = m_plotdown;
249 points[DEPTH_RECORD_COUNT + 1].x = 3;
250 points[DEPTH_RECORD_COUNT + 1].y = m_plotdown;
251 dc->DrawPolygon(DEPTH_RECORD_COUNT + 2, points);
254 dc->SetFont(m_Properties->m_DataFont.GetChosenFont());
255 dc->SetTextForeground(
256 GetColourSchemeFont(m_Properties->m_DataFont.GetColour()));
259 dc->SetTextForeground(GetColourSchemeFont(g_pFontData->GetColour()));
260 dc->SetFont(g_pFontData->GetChosenFont());
262 if (m_depth_unit !=
"-") {
263 wxString s_depth = wxString::Format(
"%.2f", m_depth);
265 s_depth = s_depth.Mid(0, s_depth.length() - 1);
266 dc->DrawText(s_depth +
" " + m_depth_unit, 10, m_DataTop);
268 dc->DrawText(
"---", 10, m_DataTop);
270 dc->SetFont(m_Properties->m_LabelFont.GetChosenFont());
272 dc->SetFont(g_pFontLabel->GetChosenFont());
273 dc->DrawText(m_temp, 5, m_plotdown);
Dashboard depth instrument.
@ OCPN_DBP_STC_TMP
Water temperature.
wxString getUsrDistanceUnit_Plugin(int unit)
Gets display string for user's preferred distance unit.