OpenCPN Partial API docs
Loading...
Searching...
No Matches
concanv.cpp
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose: Console Canvas
5 * Author: David Register
6 *
7 ***************************************************************************
8 * Copyright (C) 2010 by David S. Register *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 ***************************************************************************
25 *
26 *
27 *
28 */
29
30#include <wx/wxprec.h>
31
32#ifndef WX_PRECOMP
33#include <wx/wx.h>
34#endif // precompiled headers
35
36#include <stdlib.h>
37#include <math.h>
38#include <time.h>
39#include <wx/datetime.h>
40
41#include "model/navutil_base.h"
42#include "model/own_ship.h"
43#include "model/route.h"
44#include "model/routeman.h"
45#include "model/wx28compat.h"
46
47#include "concanv.h"
48#include "FontMgr.h"
49#include "gui_lib.h"
50#include "navutil.h"
51#include "ocpn_frame.h"
52#include "OCPNPlatform.h"
53#include "ocpn_plugin.h"
54#include "styles.h"
55
56extern Routeman* g_pRouteMan;
57extern MyFrame* gFrame;
58extern bool g_bShowActiveRouteHighway;
59extern BasePlatform* g_BasePlatform;
60
61bool g_bShowRouteTotal;
62
63extern ocpnStyle::StyleManager* g_StyleManager;
64
65enum eMenuItems { ID_NAVLEG = 1, ID_NAVROUTE, ID_NAVHIGHWAY } menuItems;
66
67//------------------------------------------------------------------------------
68// ConsoleCanvas Implementation
69//------------------------------------------------------------------------------
70BEGIN_EVENT_TABLE(ConsoleCanvas, wxWindow)
71EVT_PAINT(ConsoleCanvas::OnPaint)
72EVT_SHOW(ConsoleCanvas::OnShow)
73EVT_CONTEXT_MENU(ConsoleCanvas::OnContextMenu)
74EVT_MENU(ID_NAVLEG, ConsoleCanvas::OnContextMenuSelection)
75EVT_MENU(ID_NAVROUTE, ConsoleCanvas::OnContextMenuSelection)
76EVT_MENU(ID_NAVHIGHWAY, ConsoleCanvas::OnContextMenuSelection)
77
78END_EVENT_TABLE()
79
80// Define a constructor for my canvas
81ConsoleCanvas::ConsoleCanvas(wxWindow* frame) {
82 m_speedUsed = SPEED_VMG;
83 pbackBrush = NULL;
84 m_bNeedClear = false;
85
86 long style = wxSIMPLE_BORDER | wxCLIP_CHILDREN | wxFRAME_FLOAT_ON_PARENT;
87
88#ifdef __WXMSW__
89 style |= wxFRAME_NO_TASKBAR;
90#endif
91
92 wxFrame::Create(frame, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize,
93 style);
94
95 m_pParent = frame;
96
97 m_pitemBoxSizerLeg = new wxBoxSizer(wxVERTICAL);
98
99 pThisLegText = new wxStaticText(this, -1, _("This Leg"));
100 pThisLegText->Fit();
101 m_pitemBoxSizerLeg->Add(pThisLegText, 0, wxALIGN_CENTER_HORIZONTAL, 2);
102
103 wxFont* qFont = GetOCPNScaledFont(_("Dialog"));
104
105 wxFont* pThisLegFont = FontMgr::Get().FindOrCreateFont(
106 10, wxFONTFAMILY_DEFAULT, qFont->GetStyle(), wxFONTWEIGHT_BOLD, false,
107 qFont->GetFaceName());
108 pThisLegText->SetFont(*pThisLegFont);
109
110 pXTE = new AnnunText(this, -1, _("Console Legend"), _("Console Value"));
111 pXTE->SetALabel(_T("XTE"));
112 m_pitemBoxSizerLeg->Add(pXTE, 1, wxALIGN_LEFT | wxALL, 2);
113
114 pBRG = new AnnunText(this, -1, _("Console Legend"), _("Console Value"));
115 pBRG->SetALabel(_T("BRG"));
116 m_pitemBoxSizerLeg->Add(pBRG, 1, wxALIGN_LEFT | wxALL, 2);
117
118 pVMG = new AnnunText(this, -1, _("Console Legend"), _("Console Value"));
119 pVMG->SetALabel(_T("VMG"));
120 m_pitemBoxSizerLeg->Add(pVMG, 1, wxALIGN_LEFT | wxALL, 2);
121
122 pRNG = new AnnunText(this, -1, _("Console Legend"), _("Console Value"));
123 pRNG->SetALabel(_T("RNG"));
124 m_pitemBoxSizerLeg->Add(pRNG, 1, wxALIGN_LEFT | wxALL, 2);
125
126 pTTG = new AnnunText(this, -1, _("Console Legend"), _("Console Value"));
127 pTTG->SetALabel(_T("TTG @VMG"));
128 m_pitemBoxSizerLeg->Add(pTTG, 1, wxALIGN_LEFT | wxALL, 2);
129
130 // Create CDI Display Window
131
132 pCDI = new CDI(this, -1, wxSIMPLE_BORDER, _T("CDI"));
133 m_pitemBoxSizerLeg->AddSpacer(5);
134 m_pitemBoxSizerLeg->Add(pCDI, 0, wxALL | wxEXPAND, 2);
135
136 SetSizer(m_pitemBoxSizerLeg); // use the sizer for layout
137 m_pitemBoxSizerLeg->SetSizeHints(this);
138 Layout();
139 Fit();
140
141 if (g_bShowRouteTotal)
142 pThisLegText->SetLabel(_("Route"));
143 else
144 pThisLegText->SetLabel(_("This Leg"));
145
146 Hide();
147}
148
149ConsoleCanvas::~ConsoleCanvas() { delete pCDI; }
150
151void ConsoleCanvas::SetColorScheme(ColorScheme cs) {
152 pbackBrush = wxTheBrushList->FindOrCreateBrush(
153 GetGlobalColor(_T("DILG1" /*UIBDR*/)), wxBRUSHSTYLE_SOLID);
154 SetBackgroundColour(GetGlobalColor(_T("DILG1" /*"UIBDR"*/)));
155
156 if (g_bShowRouteTotal)
157 pThisLegText->SetLabel(_("Route"));
158 else
159 pThisLegText->SetLabel(_("This Leg"));
160
161 // Also apply color scheme to all known children
162
163 pThisLegText->SetBackgroundColour(GetGlobalColor(_T("DILG1" /*"UIBDR"*/)));
164
165 pXTE->SetColorScheme(cs);
166 pBRG->SetColorScheme(cs);
167 pRNG->SetColorScheme(cs);
168 pTTG->SetColorScheme(cs);
169 pVMG->SetColorScheme(cs);
170
171 pCDI->SetColorScheme(cs);
172}
173
174void ConsoleCanvas::OnPaint(wxPaintEvent& event) {
175 wxPaintDC dc(this);
176
177 if (g_pRouteMan->GetpActiveRoute()) {
178 if (m_bNeedClear) {
179 pThisLegText->Refresh();
180 m_bNeedClear = false;
181 }
182
184 }
185
186 if (!g_bShowActiveRouteHighway) pCDI->Hide();
187}
188
189void ConsoleCanvas::OnShow(wxShowEvent& event) {
190 pCDI->Show(g_bShowActiveRouteHighway);
191 m_pitemBoxSizerLeg->SetSizeHints(this);
192}
193
194void ConsoleCanvas::LegRoute() {
195 if (g_bShowRouteTotal)
196 pThisLegText->SetLabel(_("Route"));
197 else
198 pThisLegText->SetLabel(_("This Leg"));
199
200 pThisLegText->Refresh(true);
201 RefreshConsoleData();
202}
203
204void ConsoleCanvas::OnContextMenu(wxContextMenuEvent& event) {
205 wxMenu* contextMenu = new wxMenu();
206 wxMenuItem* btnLeg = new wxMenuItem(contextMenu, ID_NAVLEG, _("This Leg"),
207 _T(""), wxITEM_RADIO);
208 wxMenuItem* btnRoute = new wxMenuItem(contextMenu, ID_NAVROUTE,
209 _("Full Route"), _T(""), wxITEM_RADIO);
210 wxMenuItem* btnHighw = new wxMenuItem(
211 contextMenu, ID_NAVHIGHWAY, _("Show Highway"), _T(""), wxITEM_CHECK);
212 contextMenu->Append(btnLeg);
213 contextMenu->Append(btnRoute);
214 contextMenu->AppendSeparator();
215 contextMenu->Append(btnHighw);
216
217 btnLeg->Check(!g_bShowRouteTotal);
218 btnRoute->Check(g_bShowRouteTotal);
219 btnHighw->Check(g_bShowActiveRouteHighway);
220
221 PopupMenu(contextMenu);
222
223 delete contextMenu;
224}
225
226void ConsoleCanvas::OnContextMenuSelection(wxCommandEvent& event) {
227 switch (event.GetId()) {
228 case ID_NAVLEG: {
229 g_bShowRouteTotal = false;
230 LegRoute();
231 break;
232 }
233 case ID_NAVROUTE: {
234 g_bShowRouteTotal = true;
235 LegRoute();
236 break;
237 }
238 case ID_NAVHIGHWAY: {
239 g_bShowActiveRouteHighway = !g_bShowActiveRouteHighway;
240 if (g_bShowActiveRouteHighway) {
241 pCDI->Show();
242 } else {
243 pCDI->Hide();
244 }
245 m_pitemBoxSizerLeg->SetSizeHints(this);
246 break;
247 }
248 }
249}
250
252 m_speedUsed = m_speedUsed == SPEED_VMG ? SPEED_SOG : SPEED_VMG;
253 LegRoute();
254}
255
257 wxString str_buf;
258
259 if (g_pRouteMan->GetpActiveRoute()) {
260 if (g_pRouteMan->m_bDataValid) {
261 // Range to the next waypoint is needed always
262 float rng = g_pRouteMan->GetCurrentRngToActivePoint();
263
264 // Brg to the next waypoint
265 float dcog = g_pRouteMan->GetCurrentBrgToActivePoint();
266 if (dcog >= 359.5) dcog = 0;
267
268 wxString cogstr;
269 if (g_bShowTrue)
270 cogstr << wxString::Format(wxString("%6.0f", wxConvUTF8), dcog);
271 if (g_bShowMag)
272 cogstr << wxString::Format(wxString("%6.0f(M)", wxConvUTF8),
273 toMagnetic(dcog));
274
275 pBRG->SetAValue(cogstr);
276
277 double speed = 0.;
278 if (!std::isnan(gCog) && !std::isnan(gSog)) {
279 double BRG;
280 BRG = g_pRouteMan->GetCurrentBrgToActivePoint();
281 double vmg = gSog * cos((BRG - gCog) * PI / 180.);
282 str_buf.Printf(_T("%6.2f"), toUsrSpeed(vmg));
283
284 if (m_speedUsed == SPEED_VMG) {
285 // VMG
286 // VMG is always to next waypoint, not to end of route
287 // VMG is SOG x cosine (difference between COG and BRG to Waypoint)
288 speed = vmg;
289 } else {
290 speed = gSog;
291 }
292 } else
293 str_buf = _T("---");
294
295 pVMG->SetAValue(str_buf);
296
297 if (!g_bShowRouteTotal) {
298 float nrng = g_pRouteMan->GetCurrentRngToActiveNormalArrival();
299 wxString srng;
300 double deltarng = fabs(rng - nrng);
301 if ((deltarng > .01) && ((deltarng / rng) > .10) &&
302 (rng < 10.0)) // show if there is more than 10% difference in
303 // ranges, etc...
304 {
305 if (nrng < 10.0)
306 srng.Printf(_T("%5.2f/%5.2f"), toUsrDistance(rng),
307 toUsrDistance(nrng));
308 else
309 srng.Printf(_T("%5.1f/%5.1f"), toUsrDistance(rng),
310 toUsrDistance(nrng));
311 } else {
312 if (rng < 10.0)
313 srng.Printf(_T("%6.2f"), toUsrDistance(rng));
314 else
315 srng.Printf(_T("%6.1f"), toUsrDistance(rng));
316 }
317
318 // RNG to the next WPT
319 pRNG->SetAValue(srng);
320 // XTE
321 str_buf.Printf(
322 _T("%6.2f"),
323 toUsrDistance(g_pRouteMan->GetCurrentXTEToActivePoint()));
324 pXTE->SetAValue(str_buf);
325 if (g_pRouteMan->GetXTEDir() < 0)
326 pXTE->SetALabel(wxString(_("XTE L")));
327 else
328 pXTE->SetALabel(wxString(_("XTE R")));
329 // TTG
330 // In all cases, ttg/eta are declared invalid if VMG <= 0.
331 // If showing only "this leg", use VMG for calculation of ttg
332 wxString ttg_s;
333 if ((speed > 0.) && !std::isnan(gCog) && !std::isnan(gSog)) {
334 float ttg_sec = (rng / speed) * 3600.;
335 wxTimeSpan ttg_span(0, 0, long(ttg_sec), 0);
336 ttg_s = ttg_span.Format();
337 } else
338 ttg_s = _T("---");
339
340 pTTG->SetAValue(ttg_s);
341 if (m_speedUsed == SPEED_VMG) {
342 pTTG->SetALabel(wxString(_("TTG @VMG")));
343 } else {
344 pTTG->SetALabel(wxString(_("TTG @SOG")));
345 }
346 } else {
347 // Remainder of route
348 float trng = rng;
349
350 Route* prt = g_pRouteMan->GetpActiveRoute();
351 wxRoutePointListNode* node = (prt->pRoutePointList)->GetFirst();
352 RoutePoint* prp;
353
354 int n_addflag = 0;
355 while (node) {
356 prp = node->GetData();
357 if (n_addflag) trng += prp->m_seg_len;
358
359 if (prp == prt->m_pRouteActivePoint) n_addflag++;
360
361 node = node->GetNext();
362 }
363
364 // total rng
365 wxString strng;
366 if (trng < 10.0)
367 strng.Printf(_T("%6.2f"), toUsrDistance(trng));
368 else
369 strng.Printf(_T("%6.1f"), toUsrDistance(trng));
370
371 pRNG->SetAValue(strng);
372
373 // total TTG
374 // If showing total route TTG/ETA, use gSog for calculation
375
376 wxString tttg_s;
377 wxTimeSpan tttg_span;
378 float tttg_sec = 0.0;
379 if (speed > 0.) {
380 tttg_sec = (trng / gSog) * 3600.;
381 tttg_span = wxTimeSpan::Seconds((long)tttg_sec);
382 // Show also #days if TTG > 24 h
383 tttg_s = tttg_sec > SECONDS_PER_DAY ? tttg_span.Format(_("%Dd %H:%M"))
384 : tttg_span.Format("%H:%M:%S");
385 } else {
386 tttg_span = wxTimeSpan::Seconds(0);
387 tttg_s = _T("---");
388 }
389
390 pTTG->SetAValue(tttg_s);
391
392 // total ETA to be shown on XTE panel
393 wxDateTime dtnow, eta;
394 dtnow.SetToCurrent();
395 eta = dtnow.Add(tttg_span);
396 wxString seta;
397
398 if (speed > 0.) {
399 // Show date, e.g. Feb 15, if TTG > 24 h
400 seta = tttg_sec > SECONDS_PER_DAY ? eta.Format(_T("%d/%m %H:%M"))
401 : eta.Format(_T("%H:%M"));
402 } else {
403 seta = _T("---");
404 }
405 pXTE->SetAValue(seta);
406 if (m_speedUsed == SPEED_VMG) {
407 pTTG->SetALabel(wxString(_("TTG @VMG")));
408 pXTE->SetALabel(wxString(_("ETA @VMG")));
409 } else {
410 pTTG->SetALabel(wxString(_("TTG @SOG")));
411 pXTE->SetALabel(wxString(_("ETA @SOG")));
412 }
413 }
414
415 pRNG->Refresh();
416 pBRG->Refresh();
417 pVMG->Refresh();
418 pTTG->Refresh();
419 pXTE->Refresh();
420 }
421 }
422}
423
424void ConsoleCanvas::RefreshConsoleData(void) {
426
427 pRNG->Refresh();
428 pBRG->Refresh();
429 pVMG->Refresh();
430 pTTG->Refresh();
431 pXTE->Refresh();
432 pCDI->Refresh();
433}
434
436 Hide();
437 Move(0, 0);
438
439 UpdateFonts();
440 gFrame->PositionConsole();
441 Show();
442}
443
444void ConsoleCanvas::UpdateFonts(void) {
445 pBRG->RefreshFonts();
446 pXTE->RefreshFonts();
447 pTTG->RefreshFonts();
448 pRNG->RefreshFonts();
449 pVMG->RefreshFonts();
450
451 m_pitemBoxSizerLeg->SetSizeHints(this);
452 Layout();
453 Fit();
454
455 Refresh();
456}
457
458//------------------------------------------------------------------------------
459// AnnunText Implementation
460//------------------------------------------------------------------------------
461BEGIN_EVENT_TABLE(AnnunText, wxWindow)
462EVT_PAINT(AnnunText::OnPaint)
463EVT_MOUSE_EVENTS(AnnunText::MouseEvent)
464END_EVENT_TABLE()
465
466AnnunText::AnnunText(wxWindow* parent, wxWindowID id,
467 const wxString& LegendElement,
468 const wxString& ValueElement)
469 : wxWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxNO_BORDER) {
470 m_label = _T("Label");
471 m_value = _T("-----");
472
473 m_plabelFont = FontMgr::Get().FindOrCreateFont(
474 14, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, FALSE,
475 wxString(_T("Arial Bold")));
476 m_pvalueFont = FontMgr::Get().FindOrCreateFont(
477 24, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, FALSE,
478 wxString(_T("helvetica")), wxFONTENCODING_ISO8859_1);
479
480 m_LegendTextElement = LegendElement;
481 m_ValueTextElement = ValueElement;
482
483 RefreshFonts();
484}
485
486AnnunText::~AnnunText() {}
487void AnnunText::MouseEvent(wxMouseEvent& event) {
488 if (event.RightDown()) {
489 wxContextMenuEvent cevt;
490 cevt.SetPosition(event.GetPosition());
491
492 ConsoleCanvas* ccp = dynamic_cast<ConsoleCanvas*>(GetParent());
493 if (ccp) ccp->OnContextMenu(cevt);
494
495 } else if (event.LeftDown()) {
496 ConsoleCanvas* ccp = dynamic_cast<ConsoleCanvas*>(GetParent());
497 if (ccp) {
499 }
500 }
501}
502
503void AnnunText::CalculateMinSize(void) {
504 // Calculate the minimum required size of the window based on text size
505
506 int wl = 50; // reasonable defaults?
507 int hl = 20;
508 int wv = 50;
509 int hv = 20;
510
511 if (m_plabelFont)
512 GetTextExtent(_T("1234"), &wl, &hl, NULL, NULL, m_plabelFont);
513
514 if (m_pvalueFont)
515 GetTextExtent(_T("123.4567"), &wv, &hv, NULL, NULL, m_pvalueFont);
516
517 double pdifactor = g_BasePlatform->GetDisplayDIPMult(gFrame);
518 wl *= pdifactor;
519 hl *= pdifactor;
520 wv *= pdifactor;
521 hv *= pdifactor;
522
523 wxSize min;
524 min.x = wl + wv;
525
526 // Space is tight on Android....
527#ifdef __ANDROID__
528 min.x = wv * 1.2;
529#endif
530
531 min.y = (int)((hl + hv) * 1.2);
532
533 SetMinSize(min);
534
535 // resize background to the necessary size
536 ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
537 if (style->consoleTextBackground.IsOk()) {
538 wxImage img = style->consoleTextBackground.ConvertToImage();
539 style->consoleTextBackground = wxBitmap(img.Rescale(min.x, min.y));
540 }
541}
542
543void AnnunText::SetColorScheme(ColorScheme cs) {
544 ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
545 m_backBrush = *wxTheBrushList->FindOrCreateBrush(GetGlobalColor(_T("UBLCK")),
546 wxBRUSHSTYLE_SOLID);
547
548 m_default_text_color = style->consoleFontColor;
549 RefreshFonts();
550}
551
552void AnnunText::RefreshFonts() {
553 wxFont* pl = FontMgr::Get().GetFont(m_LegendTextElement);
554 m_plabelFont = FontMgr::Get().FindOrCreateFont(
555 pl->GetPointSize() / OCPN_GetWinDIPScaleFactor(), pl->GetFamily(),
556 pl->GetStyle(), pl->GetWeight(), FALSE, pl->GetFaceName());
557
558 wxFont* pv = FontMgr::Get().GetFont(m_ValueTextElement);
559 m_pvalueFont = FontMgr::Get().FindOrCreateFont(
560 pv->GetPointSize() / OCPN_GetWinDIPScaleFactor(), pv->GetFamily(),
561 pv->GetStyle(), pv->GetWeight(), FALSE, pv->GetFaceName());
562
563 m_legend_color = FontMgr::Get().GetFontColor(_("Console Legend"));
564 m_val_color = FontMgr::Get().GetFontColor(_("Console Value"));
565
566 CalculateMinSize();
567
568 // Make sure that the background color and the text colors are not too close,
569 // for contrast
570 if (m_backBrush.IsOk()) {
571 wxColour back_color = m_backBrush.GetColour();
572
573 wxColour legend_color = m_legend_color;
574 if ((abs(legend_color.Red() - back_color.Red()) < 5) &&
575 (abs(legend_color.Green() - back_color.Blue()) < 5) &&
576 (abs(legend_color.Blue() - back_color.Blue()) < 5))
577 m_legend_color = m_default_text_color;
578
579 wxColour value_color = m_val_color;
580 if ((abs(value_color.Red() - back_color.Red()) < 5) &&
581 (abs(value_color.Green() - back_color.Blue()) < 5) &&
582 (abs(value_color.Blue() - back_color.Blue()) < 5))
583 m_val_color = m_default_text_color;
584 }
585}
586
587void AnnunText::SetLegendElement(const wxString& element) {
588 m_LegendTextElement = element;
589}
590
591void AnnunText::SetValueElement(const wxString& element) {
592 m_ValueTextElement = element;
593}
594
595void AnnunText::SetALabel(const wxString& l) { m_label = l; }
596
597void AnnunText::SetAValue(const wxString& v) { m_value = v; }
598
599void AnnunText::OnPaint(wxPaintEvent& event) {
600 int sx, sy;
601 GetClientSize(&sx, &sy);
602 ocpnStyle::Style* style = g_StyleManager->GetCurrentStyle();
603
604 // Do the drawing on an off-screen memory DC, and blit into place
605 // to avoid objectionable flashing
606 wxMemoryDC mdc;
607
608 wxBitmap m_bitmap(sx, sy, -1);
609 mdc.SelectObject(m_bitmap);
610 mdc.SetBackground(m_backBrush);
611 mdc.Clear();
612
613 if (style->consoleTextBackground.IsOk())
614 mdc.DrawBitmap(style->consoleTextBackground, 0, 0);
615
616 mdc.SetTextForeground(m_default_text_color);
617
618 if (m_plabelFont) {
619 mdc.SetFont(*m_plabelFont);
620 mdc.SetTextForeground(m_legend_color);
621 mdc.DrawText(m_label, 5, 2);
622 }
623
624 if (m_pvalueFont) {
625 mdc.SetFont(*m_pvalueFont);
626 mdc.SetTextForeground(m_val_color);
627
628 int w, h;
629 mdc.GetTextExtent(m_value, &w, &h);
630 int cw, ch;
631 mdc.GetSize(&cw, &ch);
632
633 mdc.DrawText(m_value, cw - w - 2, ch - h - 2);
634 }
635
636 wxPaintDC dc(this);
637 dc.Blit(0, 0, sx, sy, &mdc, 0, 0);
638}
639//------------------------------------------------------------------------------
640// CDI Implementation
641//------------------------------------------------------------------------------
642BEGIN_EVENT_TABLE(CDI, wxWindow)
643EVT_PAINT(CDI::OnPaint)
644EVT_MOUSE_EVENTS(CDI::MouseEvent)
645END_EVENT_TABLE()
646
647CDI::CDI(wxWindow* parent, wxWindowID id, long style, const wxString& name)
648 : wxWindow(parent, id, wxDefaultPosition, wxDefaultSize, style, name)
649
650{
651 SetMinSize(wxSize(10, 150));
652}
653
654void CDI::MouseEvent(wxMouseEvent& event) {
655#ifdef __ANDROID__
656 if (event.RightDown()) {
657 qDebug() << "right down";
658
659 wxContextMenuEvent cevt;
660 cevt.SetPosition(event.GetPosition());
661
662 ConsoleCanvas* ccp = dynamic_cast<ConsoleCanvas*>(GetParent());
663 if (ccp) ccp->OnContextMenu(cevt);
664 }
665#endif
666}
667
668void CDI::SetColorScheme(ColorScheme cs) {
669 m_pbackBrush = wxTheBrushList->FindOrCreateBrush(GetGlobalColor(_T("DILG2")),
670 wxBRUSHSTYLE_SOLID);
671 m_proadBrush = wxTheBrushList->FindOrCreateBrush(GetGlobalColor(_T("DILG1")),
672 wxBRUSHSTYLE_SOLID);
673 m_proadPen = wxThePenList->FindOrCreatePen(GetGlobalColor(_T("CHBLK")), 1,
674 wxPENSTYLE_SOLID);
675}
676
677void CDI::OnPaint(wxPaintEvent& event) {
678 int sx, sy;
679 GetClientSize(&sx, &sy);
680
681 // Do the drawing on an off-screen memory DC, and blit into place
682 // to avoid objectionable flashing
683 wxMemoryDC mdc;
684
685 wxBitmap m_bitmap(sx, sy, -1);
686 mdc.SelectObject(m_bitmap);
687 mdc.SetBackground(*m_pbackBrush);
688 mdc.Clear();
689
690 int xp = sx / 2;
691 int yp = sy * 9 / 10;
692
693 int path_length = sy * 3;
694 int pix_per_xte = 120;
695
696 if (g_pRouteMan->GetpActiveRoute()) {
697 double angle = 90 - (g_pRouteMan->GetCurrentSegmentCourse() - gCog);
698
699 double dy = path_length * sin(angle * PI / 180.);
700 double dx = path_length * cos(angle * PI / 180.);
701
702 int xtedir;
703 xtedir = g_pRouteMan->GetXTEDir();
704 double xte = g_pRouteMan->GetCurrentXTEToActivePoint();
705
706 double ddy = xtedir * pix_per_xte * xte * sin((90 - angle) * PI / 180.);
707 double ddx = xtedir * pix_per_xte * xte * cos((90 - angle) * PI / 180.);
708
709 int ddxi = (int)ddx;
710 int ddyi = (int)ddy;
711
712 int xc1 = xp - (int)(dx / 2) + ddxi;
713 int yc1 = yp + (int)(dy / 2) + ddyi;
714 int xc2 = xp + (int)(dx / 2) + ddxi;
715 int yc2 = yp - (int)(dy / 2) + ddyi;
716
717 wxPoint road[4];
718
719 int road_top_width = 10;
720 int road_bot_width = 40;
721
722 road[0].x = xc1 - (int)(road_bot_width * cos((90 - angle) * PI / 180.));
723 road[0].y = yc1 - (int)(road_bot_width * sin((90 - angle) * PI / 180.));
724
725 road[1].x = xc2 - (int)(road_top_width * cos((90 - angle) * PI / 180.));
726 road[1].y = yc2 - (int)(road_top_width * sin((90 - angle) * PI / 180.));
727
728 road[2].x = xc2 + (int)(road_top_width * cos((90 - angle) * PI / 180.));
729 road[2].y = yc2 + (int)(road_top_width * sin((90 - angle) * PI / 180.));
730
731 road[3].x = xc1 + (int)(road_bot_width * cos((90 - angle) * PI / 180.));
732 road[3].y = yc1 + (int)(road_bot_width * sin((90 - angle) * PI / 180.));
733
734 mdc.SetBrush(*m_proadBrush);
735 mdc.SetPen(*m_proadPen);
736 mdc.DrawPolygon(4, road, 0, 0, wxODDEVEN_RULE);
737
739
740 mdc.DrawLine(0, yp, sx, yp);
741 mdc.DrawCircle(xp, yp, 6);
742 mdc.DrawLine(xp, yp + 5, xp, yp - 5);
743 }
744
745 wxPaintDC dc(this);
746 dc.Blit(0, 0, sx, sy, &mdc, 0, 0);
747}
double GetDisplayDIPMult(wxWindow *win)
Get the display scaling factor for DPI-aware rendering.
Annunciator Text display.
Definition concanv.h:69
Course Deviation Indicator display.
Definition concanv.h:50
void OnPaint(wxPaintEvent &event)
Definition concanv.cpp:677
Primary navigation console display for route and vessel tracking.
Definition concanv.h:127
void ShowWithFreshFonts(void)
Recomputes and applies new fonts to console elements.
Definition concanv.cpp:435
void UpdateRouteData()
Updates route-related data displays.
Definition concanv.cpp:256
void ToggleRouteTotalDisplay()
Toggles between route total and current leg display modes.
Definition concanv.cpp:251
wxFont * FindOrCreateFont(int point_size, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &facename=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
Creates or finds a matching font in the font cache.
Definition FontMgr.cpp:450
wxColour GetFontColor(const wxString &TextElement) const
Gets the text color for a UI element.
Definition FontMgr.cpp:117
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Gets a font object for a UI element.
Definition FontMgr.cpp:186
Main application frame.
Definition ocpn_frame.h:136
Represents a waypoint or mark within the navigation system.
Definition route_point.h:70
double m_seg_len
Length of the leg from previous waypoint to this waypoint in nautical miles.
Represents a navigational route in the navigation system.
Definition route.h:98
RoutePointList * pRoutePointList
Ordered list of waypoints (RoutePoints) that make up this route.
Definition route.h:335
RoutePoint * m_pRouteActivePoint
Pointer to the currently active waypoint within this route.
Definition route.h:213
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
Definition gui_lib.cpp:54
General purpose GUI support.
PlugIn Object Definition/API.
double OCPN_GetWinDIPScaleFactor()
Gets Windows-specific DPI scaling factor.