35extern int g_iDashDepthUnit;
41DashboardInstrument_Depth::DashboardInstrument_Depth(
42 wxWindow* parent, wxWindowID
id, wxString title,
45 m_cap_flag.set(OCPN_DBP_STC_TMP);
48 m_DepthUnit = getUsrDistanceUnit_Plugin(g_iDashDepthUnit);
50 for (
int idx = 0; idx < DEPTH_RECORD_COUNT; idx++) {
51 m_ArrayDepth[idx] = 0;
55wxSize DashboardInstrument_Depth::GetSize(
int orient, wxSize hint) {
58 InitDataTextHeight(_T(
"15.7 Feet"), w);
64 f = m_Properties->m_LabelFont.GetChosenFont();
65 dc.GetTextExtent(
"20.8 C", &w_label, &h_label, 0, 0, &f);
68 f = g_pFontLabel->GetChosenFont();
69 dc.GetTextExtent(
"20.8 C", &w_label, &h_label, 0, 0, &f);
73 int drawHeight = m_DataTextHeight + 4 * m_DataTextHeight + h_label +
74 m_DataTextHeight * g_TitleVerticalOffset;
75 InitTitleAndDataPosition(drawHeight);
76 int y_total = GetFullHeight(drawHeight);
78 if (orient == wxHORIZONTAL) {
79 return wxSize(wxMax(w + m_DataMargin, DefaultWidth),
80 wxMax(y_total, hint.y));
82 return wxSize(wxMax(hint.x, wxMax(w + m_DataMargin, DefaultWidth)),
87void DashboardInstrument_Depth::SetData(DASH_CAP st,
double data,
89 if (st == OCPN_DBP_STC_DPT) {
90 m_Depth = std::isnan(data) ? 0.0 : data;
92 for (
int idx = 1; idx < DEPTH_RECORD_COUNT; idx++) {
93 m_ArrayDepth[idx - 1] = m_ArrayDepth[idx];
95 m_ArrayDepth[DEPTH_RECORD_COUNT - 1] = m_Depth;
97 }
else if (st == OCPN_DBP_STC_TMP) {
98 if (!std::isnan(data)) {
99 m_Temp = wxString::Format(_T(
"%.1f"), data) + DEGREE_SIGN +
unit;
106void DashboardInstrument_Depth::Draw(wxGCDC* dc) {
111void DashboardInstrument_Depth::DrawBackground(wxGCDC* dc) {
112 wxSize size = GetClientSize();
115 dc->SetTextForeground(
116 GetColourSchemeFont(m_Properties->m_LabelFont.GetColour()));
118 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
119 GetColourSchemeFont(g_pFontLabel->GetColour())) {
120 GetGlobalColor(_T(
"DASHL"), &cl);
121 dc->SetTextForeground(cl);
123 dc->SetTextForeground(GetColourSchemeFont(g_pFontLabel->GetColour()));
126 pen.SetStyle(wxPENSTYLE_SOLID);
128 cl = GetColourSchemeFont(m_Properties->m_SmallFont.GetColour());
131 cl = GetColourSchemeFont(g_pFontSmall->GetColour());
137 int drawHeight = GetDataBottom(size.y) - m_DataTop;
138 InitTitleAndDataPosition(drawHeight);
140 m_plotup = m_DataTop + m_DataTextHeight;
141 m_plotdown = m_DataTop + drawHeight - h_label;
142 m_plotheight = m_plotdown - m_plotup;
144 dc->DrawLine(3, m_plotup, size.x - 3, m_plotup);
145 dc->DrawLine(3, m_plotdown, size.x - 3, m_plotdown);
148 pen.SetStyle(wxPENSTYLE_SHORT_DASH);
150 pen.SetStyle(wxPENSTYLE_DOT);
155 dc->DrawLine(3, m_plotup + m_plotheight / 4, size.x - 3,
156 m_plotup + m_plotheight / 4);
157 dc->DrawLine(3, m_plotup + m_plotheight * 2 / 4, size.x - 3,
158 m_plotup + m_plotheight * 2 / 4);
159 dc->DrawLine(3, m_plotup + m_plotheight * 3 / 4, size.x - 3,
160 m_plotup + m_plotheight * 3 / 4);
162 dc->SetFont(m_Properties->m_SmallFont.GetChosenFont());
163 dc->SetTextForeground(
164 GetColourSchemeFont(m_Properties->m_SmallFont.GetColour()));
166 dc->SetFont(g_pFontSmall->GetChosenFont());
167 dc->SetTextForeground(GetColourSchemeFont(g_pFontSmall->GetColour()));
170 for (
int idx = 0; idx < DEPTH_RECORD_COUNT; idx++) {
171 if (m_ArrayDepth[idx] > m_MaxDepth) m_MaxDepth = m_ArrayDepth[idx];
177 label.Printf(_T(
"%.0f ") + m_DepthUnit, 0.0);
181 f = m_Properties->m_SmallFont.GetChosenFont();
183 f = g_pFontSmall->GetChosenFont();
184 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
185 dc->DrawText(label, size.x - width - 1, m_plotup - height);
187 label.Printf(_T(
"%.0f ") + m_DepthUnit, m_MaxDepth);
189 f = m_Properties->m_SmallFont.GetChosenFont();
191 f = g_pFontSmall->GetChosenFont();
192 dc->GetTextExtent(label, &width, &height, 0, 0, &f);
193 dc->DrawText(label, size.x - width - 1, m_plotdown);
196void DashboardInstrument_Depth::DrawForeground(wxGCDC* dc) {
197 wxSize size = GetClientSize();
200 cl = GetColourSchemeFont(m_Properties->m_LabelFont.GetColour());
202 if (GetColourSchemeFont(g_pFontSmall->GetColour()) ==
203 GetColourSchemeFont(g_pFontLabel->GetColour()))
204 GetGlobalColor(_T(
"DASHL"), &cl);
206 cl = GetColourSchemeFont(g_pFontLabel->GetColour());
209 brush.SetStyle(wxBRUSHSTYLE_SOLID);
212 dc->SetPen(*wxTRANSPARENT_PEN);
214 double ratioH = double(m_plotheight) / m_MaxDepth;
215 double ratioW = double(size.x - 6) / (DEPTH_RECORD_COUNT - 1);
216 wxPoint points[DEPTH_RECORD_COUNT + 2];
218#ifdef __OCPN__ANDROID__
221 points[0].y = m_plotdown;
223 for (
int idx = 0; idx < DEPTH_RECORD_COUNT - 1; idx++) {
224 points[1].x = points[0].x;
225 if (m_ArrayDepth[idx])
226 points[1].y = m_plotup + m_ArrayDepth[idx] * ratioH;
228 points[1].y = m_plotdown;
230 points[2].x = points[1].x + ratioW;
231 if (m_ArrayDepth[idx + 1])
232 points[2].y = m_plotup + m_ArrayDepth[idx + 1] * ratioH;
234 points[2].y = m_plotdown;
236 points[3].x = points[2].x;
237 points[3].y = m_plotdown;
238 dc->DrawPolygon(4, points);
240 points[0].x = points[2].x;
241 points[0].y = m_plotdown;
245 for (
int idx = 0; idx < DEPTH_RECORD_COUNT; idx++) {
246 points[idx].x = idx * ratioW + 3;
247 if (m_ArrayDepth[idx])
248 points[idx].y = m_plotup + m_ArrayDepth[idx] * ratioH;
250 points[idx].y = m_plotdown;
252 points[DEPTH_RECORD_COUNT].x = size.x - 3;
253 points[DEPTH_RECORD_COUNT].y = m_plotdown;
254 points[DEPTH_RECORD_COUNT + 1].x = 3;
255 points[DEPTH_RECORD_COUNT + 1].y = m_plotdown;
256 dc->DrawPolygon(DEPTH_RECORD_COUNT + 2, points);
259 dc->SetFont(m_Properties->m_DataFont.GetChosenFont());
260 dc->SetTextForeground(
261 GetColourSchemeFont(m_Properties->m_DataFont.GetColour()));
264 dc->SetTextForeground(GetColourSchemeFont(g_pFontData->GetColour()));
265 dc->SetFont(g_pFontData->GetChosenFont());
267 if (m_DepthUnit != _T(
"-")) {
268 wxString s_depth = wxString::Format(_T(
"%.2f"), m_Depth);
270 s_depth = s_depth.Mid(0, s_depth.length() - 1);
271 dc->DrawText(s_depth + _T(
" ") + m_DepthUnit, 10, m_DataTop);
273 dc->DrawText(_T(
"---"), 10, m_DataTop);
275 dc->SetFont(m_Properties->m_LabelFont.GetChosenFont());
277 dc->SetFont(g_pFontLabel->GetChosenFont());
278 dc->DrawText(m_Temp, 5, m_plotdown);