43wxColour GetColourSchemeBackgroundColour(wxColour co) {
44 wxColour ret_val = co;
45#if wxCHECK_VERSION(3, 1, 6)
46 unsigned int red = co.GetRed();
47 unsigned int Green = co.GetGreen();
48 unsigned int Blue = co.GetBlue();
50 unsigned int red = co.Red();
51 unsigned int Green = co.Green();
52 unsigned int Blue = co.Blue();
54 switch (aktuellColorScheme) {
63 ret_val = wxColour(red, Green, Blue);
69 ret_val = wxColour(red, Green, Blue);
77wxColour GetColourSchemeFont(wxColour co) {
78 wxColour ret_val = co;
79#if wxCHECK_VERSION(3, 1, 6)
80 unsigned int red = co.GetRed();
81 unsigned int Green = co.GetGreen();
82 unsigned int Blue = co.GetBlue();
84 unsigned int red = co.Red();
85 unsigned int Green = co.Green();
86 unsigned int Blue = co.Blue();
88 switch (aktuellColorScheme) {
100 ret_val = wxColour(red, Green, Blue);
106 if (red + Green + Blue < 10) {
107 red = Green = Blue = 50;
109 ret_val = wxColour(red, Green, Blue);
123DashboardInstrument::DashboardInstrument(wxWindow* pparent, wxWindowID
id,
126 : wxControl(pparent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE) {
127 m_InstrumentSpacing = 0;
128 m_DataTextHeight = 0;
132 m_DataRightAlign =
false;
133 m_TitleRightAlign =
false;
135 m_Properties = Properties;
136 m_cap_flag.set(cap_flag);
137 m_popupWanted =
false;
139 wxWindow::SetBackgroundStyle(wxBG_STYLE_CUSTOM);
140 SetDrawSoloInPane(
false);
143 wxEVT_ERASE_BACKGROUND,
144 wxEraseEventHandler(DashboardInstrument::OnEraseBackground));
145 wxWindow::Connect(wxEVT_PAINT,
146 wxPaintEventHandler(DashboardInstrument::OnPaint));
155#if defined(__WXOSX__) || defined(__WXQT__)
156 Connect(wxEVT_RIGHT_DOWN,
157 wxMouseEventHandler(DashboardInstrument::MouseEvent), NULL,
this);
160#ifdef HAVE_WX_GESTURE_EVENTS
161 if (!EnableTouchEvents(wxTOUCH_PRESS_GESTURES)) {
162 wxLogError(
"Failed to enable touch events on dashboard Instrument");
165 Bind(wxEVT_LONG_PRESS, &DashboardInstrument::OnLongPress,
this);
166 Bind(wxEVT_LEFT_UP, &DashboardInstrument::OnLeftUp,
this);
170#ifdef HAVE_WX_GESTURE_EVENTS
171void DashboardInstrument::OnLongPress(wxLongPressEvent& event) {
175 m_popupWanted =
true;
179void DashboardInstrument::OnLeftUp(wxMouseEvent& event) {
180 wxPoint pos =
event.GetPosition();
182 if (!m_popupWanted) {
183 wxMouseEvent ev(wxEVT_LEFT_UP);
186 GetParent()->GetEventHandler()->AddPendingEvent(ev);
190 m_popupWanted =
false;
191 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, this->GetId(),
192 this->ClientToScreen(event.GetPosition()));
193 evtCtx.SetEventObject(
this);
194 GetParent()->GetEventHandler()->AddPendingEvent(evtCtx);
197void DashboardInstrument::MouseEvent(wxMouseEvent& event) {
198 if (event.GetEventType() == wxEVT_RIGHT_DOWN) {
199 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, this->GetId(),
200 this->ClientToScreen(event.GetPosition()));
201 evtCtx.SetEventObject(
this);
202 GetParent()->GetEventHandler()->AddPendingEvent(evtCtx);
206CapType DashboardInstrument::GetCapacity() {
return m_cap_flag; }
207void DashboardInstrument::SetDrawSoloInPane(
bool value) {
208 m_drawSoloInPane = value;
210void DashboardInstrument::OnEraseBackground(wxEraseEvent& WXUNUSED(evt)) {
214void DashboardInstrument::InitDataTextHeight(
const wxString& sampleText,
220 f = m_Properties->m_DataFont.GetChosenFont();
222 f = g_pFontData->GetChosenFont();
224 dc.GetTextExtent(sampleText, &sampleWidth, &m_DataTextHeight,
nullptr,
228void DashboardInstrument::InitTitleSize() {
231 m_InstrumentSpacing = g_iInstrumentSpacing;
234 if (!m_Properties->m_Title.IsEmpty()) m_title = m_Properties->m_Title;
235 f = m_Properties->m_TitleFont.GetChosenFont();
236 if (m_Properties->m_InstrumentSpacing >= 0)
237 m_InstrumentSpacing = m_Properties->m_InstrumentSpacing;
239 f = g_pFontTitle->GetChosenFont();
241 dc.GetTextExtent(m_title, &m_TitleWidth, &m_TitleHeight,
nullptr,
nullptr,
245void DashboardInstrument::InitTitleAndDataPosition(
int drawHeight) {
246 m_DataRightAlign = (g_DataAlignment & wxALIGN_RIGHT) != 0;
247 m_DataMargin = g_iDataMargin;
250 if (m_Properties->m_DataAlignment != wxALIGN_INVALID)
251 m_DataRightAlign = (m_Properties->m_DataAlignment & wxALIGN_RIGHT) != 0;
252 if (m_Properties->m_DataMargin >= 0)
253 m_DataMargin = m_Properties->m_DataMargin;
256 m_TitleRightAlign = (g_TitleAlignment & wxALIGN_RIGHT) != 0;
257 m_TitleTop =
static_cast<int>(m_DataTextHeight * g_TitleVerticalOffset);
258 m_DataTop = m_TitleHeight;
259 if ((g_TitleAlignment & wxALIGN_BOTTOM) != 0) {
260 m_TitleTop = drawHeight + (m_DataTextHeight * g_TitleVerticalOffset);
265int DashboardInstrument::GetFullHeight(
int drawHeight) {
266 int h = m_TitleTop + m_TitleHeight + drawHeight + m_InstrumentSpacing;
267 if ((g_TitleAlignment & wxALIGN_BOTTOM) != 0) {
268 h = m_TitleTop + m_TitleHeight + m_InstrumentSpacing;
274int DashboardInstrument::GetDataBottom(
int clientHeight) {
275 if ((g_TitleAlignment & wxALIGN_BOTTOM) != 0) {
276 return clientHeight - m_TitleHeight - m_InstrumentSpacing - 3;
278 return clientHeight - m_InstrumentSpacing;
281void DashboardInstrument::SetDataFont(wxGCDC* dc) {
285 f = m_Properties->m_DataFont.GetChosenFont();
287 dc->SetTextForeground(
288 GetColourSchemeFont(m_Properties->m_DataFont.GetColour()));
290 f = g_pFontData->GetChosenFont();
292 dc->SetTextForeground(GetColourSchemeFont(g_pFontData->GetColour()));
296void DashboardInstrument::OnPaint(wxPaintEvent& WXUNUSED(event)) {
297 wxAutoBufferedPaintDC pdc(
this);
300 "DashboardInstrument::OnPaint() fatal: "
301 "wxAutoBufferedPaintDC.IsOk() false.");
305 wxSize size = GetClientSize();
306 if (size.x == 0 || size.y == 0) {
307 wxLogMessage(
"DashboardInstrument::OnPaint() fatal: Zero size DC.");
311#if wxUSE_GRAPHICS_CONTEXT
319 GetColourSchemeBackgroundColour(m_Properties->m_DataBackgroundColour));
321 GetGlobalColor(
"DASHB", &cl);
322 dc.SetBackground(cl);
326 dc.SetPen(*wxTRANSPARENT_PEN);
327 dc.DrawRectangle(0, 0, size.x, size.y);
333 if (!m_drawSoloInPane) {
335 pen.SetStyle(wxPENSTYLE_SOLID);
337 pen.SetColour(GetColourSchemeBackgroundColour(
338 m_Properties->m_TitleBackgroundColour));
340 dc.SetBrush(GetColourSchemeBackgroundColour(
341 m_Properties->m_TitleBackgroundColour));
343 GetGlobalColor(
"DASHL", &cl);
349 dc.DrawRoundedRectangle(0, m_TitleTop, size.x, m_TitleHeight, 3);
352 f = m_Properties->m_TitleFont.GetChosenFont();
354 dc.SetTextForeground(
355 GetColourSchemeFont(m_Properties->m_TitleFont.GetColour()));
356 dc.SetTextBackground(GetColourSchemeBackgroundColour(
357 m_Properties->m_TitleBackgroundColour));
359 f = g_pFontTitle->GetChosenFont();
361 dc.SetTextForeground(GetColourSchemeFont(g_pFontTitle->GetColour()));
362 GetGlobalColor(
"DASHL", &cl);
363 dc.SetTextBackground(cl);
367 if (m_TitleRightAlign) {
369 GetClientSize().GetWidth() - m_TitleWidth - g_iTitleMargin,
372 dc.DrawText(m_title, g_iTitleMargin, m_TitleTop);
383DashboardInstrument_Single::DashboardInstrument_Single(
384 wxWindow* pparent, wxWindowID
id, wxString title,
391wxSize DashboardInstrument_Single::GetSize(
int orient, wxSize hint) {
394 InitDataTextHeight(
"000", w);
397 static_cast<int>(m_DataTextHeight * (1 + g_TitleVerticalOffset));
398 InitTitleAndDataPosition(drawHeight);
399 int h = GetFullHeight(drawHeight);
401 if (orient == wxHORIZONTAL) {
402 return wxSize(wxMax(w + m_DataMargin, DefaultWidth), wxMax(hint.y, h));
404 return wxSize(wxMax(hint.x, wxMax(w + m_DataMargin, DefaultWidth)), h);
408void DashboardInstrument_Single::Draw(wxGCDC* dc) {
412 if (m_DataMargin < 0)
413 m_DataMargin = m_TitleHeight;
416 if (m_DataRightAlign) {
418 dc->GetTextExtent(m_data, &w, &h,
nullptr,
nullptr);
419 x1 = GetClientSize().GetWidth() - w - m_DataMargin;
422 dc->DrawText(m_data, x1, m_DataTop);
425void DashboardInstrument_Single::SetData(
DASH_CAP st,
double data,
427 if (m_cap_flag.test(st)) {
428 if (!std::isnan(data)) {
430 (m_Properties ? (m_Properties->m_ShowUnit == 1) : g_bShowUnit);
432 (m_Properties && m_Properties->m_Format !=
"" ? m_Properties->m_Format
435 m_data = wxString::Format(format, data) +
436 (showUnit ? DEGREE_SIGN +
"C" :
"");
437 else if (
unit ==
"\u00B0")
438 m_data = wxString::Format(format, data) + (showUnit ? DEGREE_SIGN :
"");
439 else if (
unit ==
"\u00B0T")
440 m_data = wxString::Format(format, data) +
441 (showUnit ? DEGREE_SIGN + _(
" true") :
"");
442 else if (
unit ==
"\u00B0M")
443 m_data = wxString::Format(format, data) +
444 (showUnit ? DEGREE_SIGN + _(
" mag") :
"");
445 else if (
unit ==
"\u00B0L")
446 m_data =
">" + wxString::Format(format, data) +
447 (showUnit ? DEGREE_SIGN :
"");
448 else if (
unit ==
"\u00B0R")
449 m_data = wxString::Format(format, data) +
450 (showUnit ? DEGREE_SIGN +
"<" :
"");
451 else if (
unit ==
"N")
452 m_data = wxString::Format(format, data) + (showUnit ?
" Kts" :
"");
461 m_data = wxString::Format(format, data) + (showUnit ?
" " +
unit :
"");
475DashboardInstrument_Position::DashboardInstrument_Position(
476 wxWindow* pparent, wxWindowID
id, wxString title,
479 m_cap_flag.set(cap_flag2);
483 m_cap_flag1 = cap_flag1;
484 m_cap_flag2 = cap_flag2;
487wxSize DashboardInstrument_Position::GetSize(
int orient, wxSize hint) {
490 InitDataTextHeight(
"000 00.0000 W", w);
492 int drawHeight =
static_cast<int>(m_DataTextHeight * 2 +
493 m_DataTextHeight * g_TitleVerticalOffset);
494 InitTitleAndDataPosition(drawHeight);
495 int h = GetFullHeight(drawHeight);
497 if (orient == wxHORIZONTAL) {
498 return wxSize(wxMax(w + m_DataMargin, DefaultWidth), wxMax(hint.y, h));
500 return wxSize(wxMax(hint.x, wxMax(w + m_DataMargin, DefaultWidth)), h);
504void DashboardInstrument_Position::Draw(wxGCDC* dc) {
508 x1 = x2 = m_DataMargin;
510 if (m_DataRightAlign) {
512 dc->GetTextExtent(m_data1, &w, &h,
nullptr,
nullptr);
513 x1 = GetClientSize().GetWidth() - w - m_DataMargin;
514 dc->GetTextExtent(m_data2, &w, &h,
nullptr,
nullptr);
515 x2 = GetClientSize().GetWidth() - w - m_DataMargin;
518 dc->DrawText(m_data1, x1, m_DataTop);
519 dc->DrawText(m_data2, x2, m_DataTop + m_DataTextHeight);
522void DashboardInstrument_Position::SetData(
DASH_CAP st,
double data,
524 if (std::isnan(data))
return;
525 if (st == m_cap_flag1) {
526 m_data1 = toSDMM(1, data);
528 }
else if (st == m_cap_flag2) {
529 m_data2 = toSDMM(2, data);
539wxString toSDMM(
int NEflag,
double a) {
549 m = (long)((a - (
double)d) * 60000.0);
556 s.Printf(
"%d %02ld.%03ld'", d, m / 1000, m % 1000);
566 s.Printf(
"%03d %02ld.%03ld %c", d, m / 1000, (m % 1000), c);
567 }
else if (NEflag == 2) {
574 s.Printf(
"%03d %02ld.%03ld %c", d, m / 1000, (m % 1000), c);
Dashboard instrument base class.
PI_ColorScheme
Color schemes for different lighting conditions.
@ PI_GLOBAL_COLOR_SCHEME_DAY
Day color scheme, optimized for bright ambient light.
@ PI_GLOBAL_COLOR_SCHEME_NIGHT
Night/dark color scheme, optimized for dark conditions with minimal impact on night vision.
@ PI_GLOBAL_COLOR_SCHEME_RGB
RGB color scheme, unmodified colors.
@ PI_GLOBAL_COLOR_SCHEME_DUSK
Dusk color scheme, optimized for low ambient light.