4#include <wx/listctrl.h>
13#include "model/cutil.h"
15#include "model/wx28compat.h"
16#include "OCPNPlatform.h"
17#include "RolloverWin.h"
20#include "ocpn_frame.h"
22extern ColorScheme global_color_scheme;
25extern wxString g_locale;
32enum { ID_TCWIN_NX, ID_TCWIN_PR };
34enum { TIDE_PLOT, CURRENT_PLOT };
36#include <wx/listimpl.cpp>
37WX_DEFINE_LIST(SplineList);
39BEGIN_EVENT_TABLE(
TCWin, wxWindow)
40EVT_PAINT(TCWin::OnPaint)
41EVT_SIZE(TCWin::OnSize)
42EVT_MOTION(TCWin::MouseEvent)
43EVT_BUTTON(wxID_OK, TCWin::OKEvent)
44EVT_BUTTON(ID_TCWIN_NX, TCWin::NXEvent)
45EVT_BUTTON(ID_TCWIN_PR, TCWin::PREvent)
46EVT_CLOSE(TCWin::OnCloseWindow)
47EVT_TIMER(TCWININF_TIMER, TCWin::OnTCWinPopupTimerEvent)
48EVT_TIMER(TCWIN_TIME_INDICATOR_TIMER, TCWin::OnTimeIndicatorTimer)
52extern wxDateTime gTimeSource;
58 m_pTCRolloverWin = NULL;
60 long wstyle = wxCLIP_CHILDREN | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER |
61 wxFRAME_FLOAT_ON_PARENT;
71 pConfig->SetPath(_T (
"/Settings/Others" ));
72 pConfig->Read(_T (
"TCWindowTimeZone" ), &m_tzoneDisplay, 0);
75 wxFrame::Create(parent, wxID_ANY, wxString(_T (
"" )), m_position, m_tc_size,
85 if (strchr(
"Tt", pIDX->IDX_type)) {
86 m_plot_type = TIDE_PLOT;
87 SetTitle(wxString(_(
"Tide")));
90 m_plot_type = CURRENT_PLOT;
91 SetTitle(wxString(_(
"Current")));
95 GetClientSize(&sx, &sy);
101 wxString *TClist = NULL;
102 m_tList =
new wxListCtrl(
this, -1, wxPoint(sx * 65 / 100, 11),
103 wxSize((sx * 32 / 100), (sy * 20 / 100)),
104 wxLC_REPORT | wxLC_NO_HEADER);
109 col0.SetText(_T(
""));
110 col0.SetAlign(wxLIST_FORMAT_LEFT);
111 col0.SetWidth(sx * 30 / 100);
112 m_tList->InsertColumn(0, col0);
115 wxButton *test_button =
116 new wxButton(
this, wxID_OK, _(
"OK"), wxPoint(-1, -1), wxDefaultSize);
117 test_button->GetSize(&m_tsx, &m_tsy);
123 if ((m_tsy * 15) > sx) m_tList->Hide();
125 OK_button =
new wxButton(
this, wxID_OK, _(
"OK"),
126 wxPoint(sx - (2 * m_tsy + 10), sy - (m_tsy + 10)),
129 PR_button =
new wxButton(
this, ID_TCWIN_PR, _(
"Prev"),
130 wxPoint(10, sy - (m_tsy + 10)), wxSize(-1, -1));
132 wxSize texc_size = wxSize((sx * 60 / 100), (sy * 29 / 100));
133 if (!m_tList->IsShown()) {
134 texc_size = wxSize((sx * 90 / 100), (sy * 29 / 100));
138 new wxTextCtrl(
this, -1, _T(
""), wxPoint(sx * 3 / 100, 6), texc_size,
139 wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
140 int bsx, bsy, bpx, bpy;
141 PR_button->GetSize(&bsx, &bsy);
142 PR_button->GetPosition(&bpx, &bpy);
145 new wxButton(
this, ID_TCWIN_NX, _(
"Next"),
146 wxPoint(bpx + bsx + 5, sy - (m_tsy + 10)), wxSize(-1, -1));
148 wxString m_choiceTimezoneChoices[] = {_(
"LMT@Station"), _(
"UTC")};
149 int m_choiceTimezoneNChoices =
150 sizeof(m_choiceTimezoneChoices) /
sizeof(wxString);
151 m_choiceTimezone =
new wxChoice(
152 this, wxID_ANY, wxPoint((sx - (bsx * 2)) / 2, sy - (m_tsy * 12 / 10)),
153 wxSize(2 * bsx, bsy), m_choiceTimezoneNChoices, m_choiceTimezoneChoices,
155 m_choiceTimezone->SetToolTip(
156 _(
"Select whether tide times are shown in UTC or "
157 "Local Mean Time (LMT) at the station"));
158 m_choiceSize_x = bsx * 2;
160 m_choiceTimezone->SetSelection(m_tzoneDisplay);
161 m_choiceTimezone->Connect(wxEVT_COMMAND_CHOICE_SELECTED,
162 wxCommandEventHandler(TCWin::TimezoneOnChoice),
165 m_TCWinPopupTimer.SetOwner(
this, TCWININF_TIMER);
168 m_TimeIndicatorTimer.SetOwner(
this, TCWIN_TIME_INDICATOR_TIMER);
169 m_TimeIndicatorTimer.Start(60000,
false);
174 dc.GetTextExtent(_T(
"W"), NULL, &text_height);
175 m_refTextHeight = text_height;
176 m_button_height = m_tsy;
180 wxFont *dlg_font = FontMgr::Get().
GetFont(_(
"Dialog"));
181 int dlg_font_size = dlg_font->GetPointSize();
182#if defined(__WXOSX__) || defined(__WXGTK3__)
184 dlg_font_size /= GetContentScaleFactor();
188 dlg_font_size - 2, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
189 wxFONTWEIGHT_NORMAL, FALSE, wxString(_T (
"Arial" )));
191 dlg_font_size - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
192 wxFONTWEIGHT_NORMAL, FALSE, wxString(_T (
"Arial" )));
194 dlg_font_size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD,
195 FALSE, wxString(_T (
"Arial" )));
197 dlg_font_size + 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
198 wxFONTWEIGHT_BOLD, FALSE, wxString(_T (
"Arial" )));
201 pblack_1 = wxThePenList->FindOrCreatePen(
202 this->GetForegroundColour(), wxMax(1, (
int)(m_tcwin_scaler + 0.5)),
205 pblack_2 = wxThePenList->FindOrCreatePen(
206 this->GetForegroundColour(), wxMax(2, (
int)(2 * m_tcwin_scaler + 0.5)),
209 pblack_3 = wxThePenList->FindOrCreatePen(
210 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW),
211 wxMax(1, (
int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
213 pred_2 = wxThePenList->FindOrCreatePen(
214 wxColor(230, 54, 54), wxMax(4, (
int)(4 * m_tcwin_scaler + 0.5)),
217 pred_time = wxThePenList->FindOrCreatePen(
218 wxColour(0, 100, 255), wxMax(4, (
int)(4 * m_tcwin_scaler + 0.5)),
221 pltgray = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
224 pltgray2 = wxTheBrushList->FindOrCreateBrush(this->GetBackgroundColour(),
226 pgraph = wxThePenList->FindOrCreatePen(
227 wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),
228 wxMax(1, (
int)(m_tcwin_scaler + 0.5)), wxPENSTYLE_SOLID);
235 m_ptextctrl->Clear();
237 wxString locn(pIDX->IDX_station_name, wxConvUTF8);
238 wxString locna, locnb;
239 if (locn.Contains(wxString(_T (
"," )))) {
240 locna = locn.BeforeFirst(
',');
241 locnb = locn.AfterFirst(
',');
249 style.SetFont(*pLFont);
250 m_ptextctrl->SetDefaultStyle(style);
252 m_ptextctrl->AppendText(locna);
253 m_ptextctrl->AppendText(_T(
"\n"));
255 style.SetFont(*pSMFont);
256 m_ptextctrl->SetDefaultStyle(style);
258 if (!locnb.IsEmpty()) m_ptextctrl->AppendText(locnb);
259 m_ptextctrl->AppendText(_T(
"\n"));
262 if ((
't' == pIDX->IDX_type) || (
'c' == pIDX->IDX_type)) {
263 wxString mref(pIDX->IDX_reference_name, wxConvUTF8);
264 mref.Prepend(_T(
" "));
266 m_ptextctrl->AppendText(_(
"Reference Station :"));
267 m_ptextctrl->AppendText(_T(
"\n"));
269 m_ptextctrl->AppendText(mref);
270 m_ptextctrl->AppendText(_T(
"\n"));
273 m_ptextctrl->AppendText(_T(
"\n"));
277 wxString dsource(pIDX->source_ident, wxConvUTF8);
278 dsource.Prepend(_T(
" "));
280 m_ptextctrl->AppendText(_(
"Data Source :"));
281 m_ptextctrl->AppendText(_T(
"\n"));
283 m_ptextctrl->AppendText(dsource);
285 m_ptextctrl->ShowPosition(0);
289 m_TimeIndicatorTimer.Stop();
290 pParent->Refresh(
false);
293void TCWin::SetTimeFactors() {
295 wxDateTime this_now = gTimeSource;
296 bool cur_time = !gTimeSource.IsValid();
299 this_now = wxDateTime::Now();
301 wxDateTime this_gmt = this_now.ToGMT();
303#if wxCHECK_VERSION(2, 6, 2)
304 wxTimeSpan diff = this_now.Subtract(this_gmt);
306 wxTimeSpan diff = this_gmt.Subtract(this_now);
309 m_diff_mins = diff.GetMinutes();
314#if wxCHECK_VERSION(3, 0, 2)
315 if (m_diff_mins == 0 && this_now.IsDST()) m_diff_mins += 60;
318 int station_offset = ptcmgr->GetStationTimeOffset(pIDX);
320 m_stationOffset_mins = station_offset;
321 if (this_now.IsDST()) {
322 m_stationOffset_mins += 60;
328#if wxCHECK_VERSION(3, 0, 2)
335 m_graphday = this_gmt;
337 int day_gmt = this_gmt.GetDayOfYear();
339 time_t ttNow = this_now.GetTicks();
340 time_t tt_at_station =
341 ttNow - (m_diff_mins * 60) + (m_stationOffset_mins * 60);
342 wxDateTime atStation(tt_at_station);
343 int day_at_station = atStation.GetDayOfYear();
345 if (day_gmt > day_at_station) {
346 wxTimeSpan dt(24, 0, 0, 0);
347 m_graphday.Subtract(dt);
348 }
else if (day_gmt < day_at_station) {
349 wxTimeSpan dt(24, 0, 0, 0);
353 wxDateTime graphday_00 = m_graphday;
354 graphday_00.ResetTime();
355 time_t t_graphday_00 = graphday_00.GetTicks();
361 m_t_graphday_GMT = t_graphday_00;
366void TCWin::TimezoneOnChoice(wxCommandEvent &event) {
367 m_tzoneDisplay = m_choiceTimezone->GetSelection();
373void TCWin::RecalculateSize() {
374 wxSize parent_size(2000, 2000);
375 if (pParent) parent_size = pParent->GetClientSize();
377 int unscaledheight = 600;
378 int unscaledwidth = 650;
384 g_tcwin_scale = wxMax(g_tcwin_scale, 10);
385 m_tcwin_scaler = g_Platform->GetDisplayDPmm() * 0.254 * g_tcwin_scale / 100.0;
387 m_tc_size.x = (int)(unscaledwidth * m_tcwin_scaler + 0.5);
388 m_tc_size.y = (int)(unscaledheight * m_tcwin_scaler + 0.5);
390 m_tc_size.x = wxMin(m_tc_size.x, parent_size.x);
391 m_tc_size.y = wxMin(m_tc_size.y, parent_size.y);
398 if ((m_x + 8 + m_tc_size.x) > parent_size.x) xc = xc - m_tc_size.x - 16;
399 if ((m_y + m_tc_size.y) > parent_size.y) yc = yc - m_tc_size.y;
405 if (pParent) pParent->ClientToScreen(&xc, &yc);
406 m_position = wxPoint(xc, yc);
414void TCWin::OKEvent(wxCommandEvent &event) {
416 pParent->pCwin = NULL;
418 delete m_pTCRolloverWin;
420 pParent->Refresh(
false);
424 pConfig->SetPath(_T (
"/Settings/Others" ));
425 pConfig->Write(_T (
"TCWindowTimeZone" ), m_tzoneDisplay);
431void TCWin::OnCloseWindow(wxCloseEvent &event) {
433 pParent->pCwin = NULL;
435 delete m_pTCRolloverWin;
440 pConfig->SetPath(_T (
"/Settings/Others" ));
441 pConfig->Write(_T (
"TCWindowTimeZone" ), m_tzoneDisplay);
447void TCWin::NXEvent(wxCommandEvent &event) {
448 wxTimeSpan dt(24, 0, 0, 0);
450 wxDateTime dm = m_graphday;
452 wxDateTime graphday_00 = dm.ResetTime();
453 time_t t_graphday_00 = graphday_00.GetTicks();
455 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
456 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
458 m_t_graphday_GMT = t_graphday_00;
464void TCWin::PREvent(wxCommandEvent &event) {
465 wxTimeSpan dt(-24, 0, 0, 0);
467 wxDateTime dm = m_graphday;
469 wxDateTime graphday_00 = dm.ResetTime();
470 time_t t_graphday_00 = graphday_00.GetTicks();
472 if (!graphday_00.IsDST() && m_graphday.IsDST()) t_graphday_00 -= 3600;
473 if (graphday_00.IsDST() && !m_graphday.IsDST()) t_graphday_00 += 3600;
475 m_t_graphday_GMT = t_graphday_00;
481void TCWin::RePosition(
void) {
488 pParent->ClientToScreen(&r.x, &r.y);
492void TCWin::OnPaint(wxPaintEvent &event) {
502 if (m_graph_rect.x == 0)
return;
504 GetClientSize(&x, &y);
509 int x_graph = x * 1 / 10;
510 int y_graph = y * 32 / 100;
511 int x_graph_w = x * 8 / 10;
512 int y_graph_h = (y * .7) - (3 * m_button_height);
513 m_graph_rect = wxRect(x_graph, y_graph, x_graph_w, y_graph_h);
515 wxSize texc_size = wxSize( ( x * 60 / 100 ), ( y *29 / 100 ) );
516 if( !m_tList->IsShown()){
517 texc_size = wxSize( ( x * 90 / 100 ), ( y *29 / 100 ) );
520 m_ptextctrl->SetSize(texc_size);
530 pblack_1->SetColour(this->GetForegroundColour());
531 pblack_2->SetColour(this->GetForegroundColour());
532 pltgray->SetColour(this->GetBackgroundColour());
533 pltgray2->SetColour(this->GetBackgroundColour());
534 pred_2->SetColour(GetDimedColor(wxColor(230, 54, 54)));
535 pred_time->SetColour(GetDimedColor(wxColour(0, 100, 255)));
539 int x_textbox = x * 5 / 100;
542 int x_textbox_w = x * 51 / 100;
543 int y_textbox_h = y * 25 / 100;
546 dc.SetPen(*pblack_3);
547 dc.SetBrush(*pltgray2);
548 dc.DrawRoundedRectangle(x_textbox, y_textbox, x_textbox_w, y_textbox_h,
551 if (m_tList->IsShown()) {
552 wxRect tab_rect = m_tList->GetRect();
553 dc.DrawRoundedRectangle(tab_rect.x - 4, y_textbox, tab_rect.width + 8,
558 dc.SetPen(*pblack_1);
559 dc.SetBrush(*pltgray);
560 dc.DrawRectangle(m_graph_rect.x, m_graph_rect.y, m_graph_rect.width,
561 m_graph_rect.height);
566 const int hour_delta = 4;
568 const int hour_delta = 1;
578 for (i = 0; i < 25; i++) {
579 int xd = m_graph_rect.x + ((i)*m_graph_rect.width / 25);
580 if (hour_delta != 1) {
581 if (i % hour_delta == 0) {
582 dc.SetPen(*pblack_2);
583 dc.DrawLine(xd, m_graph_rect.y, xd,
584 m_graph_rect.y + m_graph_rect.height + 5);
586 int hour_show = hour_start + i;
587 if (hour_show >= 24) hour_show -= 24;
588 sprintf(sbuf,
"%02d", hour_show);
590 dc.DrawText(wxString(sbuf, wxConvUTF8),
591 xd + x_shim + (m_graph_rect.width / 25) / 2,
592 m_graph_rect.y + m_graph_rect.height + 8);
594 dc.SetPen(*pblack_1);
595 dc.DrawLine(xd, m_graph_rect.y, xd,
596 m_graph_rect.y + m_graph_rect.height + 5);
599 dc.SetPen(*pblack_1);
600 dc.DrawLine(xd, m_graph_rect.y, xd,
601 m_graph_rect.y + m_graph_rect.height + 5);
603 sst.Printf(_T(
"%02d"), i);
604 dc.DrawRotatedText(sst, xd + (m_graph_rect.width / 25) / 2,
605 m_graph_rect.y + m_graph_rect.height + 8, 270.);
610 wxDateTime system_now = wxDateTime::Now();
612 wxDateTime this_now = gTimeSource;
613 bool cur_time = !gTimeSource.IsValid();
614 if (cur_time) this_now = wxDateTime::Now();
617 time_t t_system_now = system_now.GetTicks();
618 t_system_now -= m_diff_mins * 60;
619 if (m_tzoneDisplay == 0)
620 t_system_now += m_stationOffset_mins * 60;
622 float t_system_ratio =
623 m_graph_rect.width * (t_system_now - m_t_graphday_GMT) / (25 * 3600.0f);
625 int x_system = (t_system_ratio < 0 || t_system_ratio > m_graph_rect.width)
627 : m_graph_rect.x + (int)t_system_ratio;
631 dc.DrawLine(x_system, m_graph_rect.y, x_system,
632 m_graph_rect.y + m_graph_rect.height);
637 if (gTimeSource.IsValid()) {
638 time_t t_selected_time = gTimeSource.GetTicks();
642 if (abs(t_selected_time - t_system_now) > 300) {
643 t_selected_time -= m_diff_mins * 60;
644 if (m_tzoneDisplay == 0)
645 t_selected_time += m_stationOffset_mins * 60;
647 float t_selected_time_ratio = m_graph_rect.width *
648 (t_selected_time - m_t_graphday_GMT) /
651 int x_selected_time = (t_selected_time_ratio < 0 ||
652 t_selected_time_ratio > m_graph_rect.width)
654 : m_graph_rect.x + (int)t_selected_time_ratio;
656 if (x_selected_time >= 0) {
658 dc.SetPen(*pred_time);
659 dc.DrawLine(x_selected_time, m_graph_rect.y, x_selected_time,
660 m_graph_rect.y + m_graph_rect.height);
662 wxLogMessage(
"TCWin::OnPaint: Selected time indicator drawn at %d",
666 dc.SetPen(*pblack_1);
675 m_tList->DeleteAllItems();
683 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
685 if (m_tzoneDisplay == 0)
686 tt_localtz -= m_stationOffset_mins * 60;
689 ptcmgr->GetTideFlowSens(tt_localtz, BACKWARD_TEN_MINUTES_STEP,
692 for (i = 0; i < 26; i++) {
693 int tt = tt_localtz + (i * FORWARD_ONE_HOUR_STEP);
695 ptcmgr->GetTideOrCurrent(tt, pIDX->
IDX_rec_num, tcv[i], dir);
697 if (tcv[i] > tcmax) tcmax = tcv[i];
699 if (tcv[i] < tcmin) tcmin = tcv[i];
700 if (TIDE_PLOT == m_plot_type) {
701 if (!((tcv[i] > val) == wt) && (i > 0))
705 ptcmgr->GetHightOrLowTide(tt, BACKWARD_TEN_MINUTES_STEP,
706 BACKWARD_ONE_MINUTES_STEP, tcv[i], wt,
708 if (tctime > tt_localtz) {
712 tcd.Set(tctime - (m_diff_mins * 60));
713 if (m_tzoneDisplay == 0)
714 tcd.Set(tctime + (m_stationOffset_mins - m_diff_mins) * 60);
716 s.Printf(tcd.Format(_T(
"%H:%M ")));
717 s1.Printf(_T(
"%05.2f "), tcvalue);
720 if (pmsd) s.Append(wxString(pmsd->units_abbrv, wxConvUTF8));
722 (wt) ? s.Append(_(
"HW")) : s.Append(_(
"LW"));
725 li.SetId(list_index);
726 li.SetAlign(wxLIST_FORMAT_LEFT);
729 m_tList->InsertItem(li);
736 if (CURRENT_PLOT == m_plot_type) {
740 thx.Set((time_t)tt - (m_diff_mins * 60));
741 if (m_tzoneDisplay == 0)
742 thx.Set((time_t)tt + (m_stationOffset_mins - m_diff_mins) * 60);
744 s.Printf(thx.Format(_T(
"%H:%M ")));
745 s1.Printf(_T(
"%05.2f "), fabs(tcv[i]));
748 if (pmsd) s.Append(wxString(pmsd->units_abbrv, wxConvUTF8));
749 s1.Printf(_T(
" %03.0f"), dir);
753 li.SetId(list_index);
754 li.SetAlign(wxLIST_FORMAT_LEFT);
757 m_tList->InsertItem(li);
765 if (CURRENT_PLOT == m_plot_type) {
766 it = std::max(abs((
int)tcmin - 1), abs((
int)tcmax + 1));
770 m_plot_y_offset = m_graph_rect.height / 2;
774 if (tcmin < 0) ib -= 1;
778 m_plot_y_offset = (m_graph_rect.height * (it - ib)) / im;
785 dc.GetTextExtent(_T(
"1"), NULL, &height_stext);
786 float available_lines = (float)m_graph_rect.height / height_stext;
787 i_skip = (int)ceil(im / available_lines);
789 if (CURRENT_PLOT == m_plot_type && i_skip != 1) {
798 m_sList.DeleteContents(
true);
801 for (i = 0; i < 26; i++) {
802 wxPoint *pp =
new wxPoint;
803 pp->x = m_graph_rect.x + ((i)*m_graph_rect.width / 25);
804 pp->y = m_graph_rect.y + (m_plot_y_offset) -
805 (
int)((tcv[i] - val_off) * m_graph_rect.height / im);
814 dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
820 int yd = m_graph_rect.y + (m_plot_y_offset) -
821 ((i - val_off) * m_graph_rect.height / im);
823 if ((m_plot_y_offset + m_graph_rect.y) == yd)
824 dc.SetPen(*pblack_2);
826 dc.SetPen(*pblack_1);
828 dc.DrawLine(m_graph_rect.x, yd, m_graph_rect.x + m_graph_rect.width, yd);
829 snprintf(sbuf, 99,
"%d", i);
830 dc.DrawText(wxString(sbuf, wxConvUTF8), m_graph_rect.x - 20, yd - 5);
835#if wxCHECK_VERSION(2, 9, 0)
836 wxPointList *list = (wxPointList *)&m_sList;
838 wxList *list = (wxList *)&m_sList;
849 if (m_tzoneDisplay == 0) {
850 int station_offset = ptcmgr->GetStationTimeOffset(pIDX);
851 int h = station_offset / 60;
852 int m = station_offset - (h * 60);
853 if (m_graphday.IsDST()) h += 1;
854 m_stz.Printf(_T(
"UTC %+03d:%02d"), h, m);
858 double lat = ptcmgr->GetStationLat(pIDX);
862 switch (ptcmgr->GetStationTimeOffset(pIDX)) {
875 if (m_graphday.IsDST()) mtz[1] =
'D';
886 dc.GetTextExtent(m_stz, &w, &h);
887 dc.DrawText(m_stz, x / 2 - w / 2,
888 y - (m_button_height * 15 / 10) - (m_refTextHeight * 2));
891 if (g_locale == _T(
"en_US"))
892 sdate = m_graphday.Format(_T (
"%A %b %d, %Y" ));
894 sdate = m_graphday.Format(_T (
"%A %d %b %Y" ));
897 dc.GetTextExtent(sdate, &w, &h);
898 dc.DrawText(sdate, x / 2 - w / 2,
899 y - (m_button_height * 15 / 10) - (m_refTextHeight * 1));
903 dc.GetTextExtent(wxString(pmsd->units_conv, wxConvUTF8), &w, &h);
904 dc.DrawRotatedText(wxString(pmsd->units_conv, wxConvUTF8), 5,
905 m_graph_rect.y + m_graph_rect.height / 2 + w / 2, 90.);
914 dc.DrawText(fdir, m_graph_rect.x + m_graph_rect.width + 4,
915 m_graph_rect.y + m_graph_rect.height * 1 / 4);
919 dc.DrawText(edir, m_graph_rect.x + m_graph_rect.width + 4,
920 m_graph_rect.y + m_graph_rect.height * 3 / 4);
924 if ((m_button_height * 15) < x && cur_time) {
927 int day = m_graphday.GetDayOfYear();
928 if (m_graphday.GetYear() == this_now.GetYear()) {
929 if (day == this_now.GetDayOfYear())
930 sday.Append(_(
"Today"));
931 else if (day == this_now.GetDayOfYear() + 1)
932 sday.Append(_(
"Tomorrow"));
934 sday.Append(m_graphday.GetWeekDayName(m_graphday.GetWeekDay()));
935 }
else if (m_graphday.GetYear() == this_now.GetYear() + 1 &&
936 day == this_now.Add(wxTimeSpan::Day()).GetDayOfYear())
937 sday.Append(_(
"Tomorrow"));
940 dc.GetTextExtent(sday, &w, &h);
941 dc.DrawText(sday, 55 - w / 2,
942 y - (m_button_height * 15 / 10) - (m_refTextHeight * 1));
946 double spotDim = 4 * g_Platform->GetDisplayDPmm();
948 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(
949 GetGlobalColor(_T (
"YELO1" )), wxBRUSHSTYLE_SOLID));
950 dc.SetPen(wxPen(GetGlobalColor(_T (
"URED" )),
951 wxMax(2, 0.5 * g_Platform->GetDisplayDPmm())));
952 dc.DrawRoundedRectangle(xSpot - spotDim / 2, ySpot - spotDim / 2, spotDim,
953 spotDim, spotDim / 2);
955 dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(
956 GetGlobalColor(_T (
"UBLCK" )), wxBRUSHSTYLE_SOLID));
957 dc.SetPen(wxPen(GetGlobalColor(_T (
"UBLCK" )), 1));
959 double ispotDim = spotDim / 5.;
960 dc.DrawRoundedRectangle(xSpot - ispotDim / 2, ySpot - ispotDim / 2,
961 ispotDim, ispotDim, ispotDim / 2);
965void TCWin::OnSize(wxSizeEvent &event) {
966 if (!m_created)
return;
969 GetClientSize(&x, &y);
972 int x_graph = x * 1 / 10;
973 int y_graph = y * 32 / 100;
974 int x_graph_w = x * 8 / 10;
976 (y * 65 / 100) - (m_button_height * 15 / 10) - (m_refTextHeight * 2);
980 m_graph_rect = wxRect(x_graph, y_graph, x_graph_w, y_graph_h);
985 if ((m_tsy * 15) > x)
988 m_tList->Move(wxPoint(x * 65 / 100, 11));
992 wxSize texc_size = wxSize((x * 60 / 100), (y * 29 / 100));
993 if (!m_tList->IsShown()) {
994 texc_size = wxSize((x * 90 / 100), (y * 29 / 100));
996 m_ptextctrl->SetSize(texc_size);
1000 wxPoint(x - (4 * m_button_height + 10), y - (m_button_height * 12 / 10)));
1003 wxPoint(x - (3 * m_button_height + 10), y - (m_button_height * 12 / 10)));
1005 PR_button->Move(wxPoint(10, y - (m_button_height + 10)));
1007 m_choiceTimezone->Move(
1008 wxPoint(x / 2 - m_choiceSize_x / 2, y - (m_button_height * 12 / 10)));
1010 int bsx, bsy, bpx, bpy;
1011 PR_button->GetSize(&bsx, &bsy);
1012 PR_button->GetPosition(&bpx, &bpy);
1014 NX_button->Move(wxPoint(bpx + bsx + 5, y - (m_button_height + 10)));
1022void TCWin::MouseEvent(wxMouseEvent &event) {
1023 event.GetPosition(&curs_x, &curs_y);
1025 if (!m_TCWinPopupTimer.IsRunning())
1026 m_TCWinPopupTimer.Start(20, wxTIMER_ONE_SHOT);
1029void TCWin::OnTCWinPopupTimerEvent(wxTimerEvent &event) {
1033 GetClientSize(&x, &y);
1034 wxRegion cursorarea(m_graph_rect);
1035 if (cursorarea.Contains(curs_x, curs_y)) {
1036 ShowRollover =
true;
1037 SetCursor(*pParent->pCursorCross);
1038 if (NULL == m_pTCRolloverWin) {
1039 m_pTCRolloverWin =
new RolloverWin(
this, -1,
false);
1043 m_pTCRolloverWin->SetMousePropogation(1);
1044 m_pTCRolloverWin->Hide();
1049 t = (25 / ((float)x * 8 / 10)) * ((
float)curs_x - ((float)x * 1 / 10));
1051 int tt = m_t_graphday_GMT + (int)(t * 3600);
1056 p.Printf(thd.Format(_T(
"%Hh %Mmn")));
1061 int tt_localtz = m_t_graphday_GMT + (m_diff_mins * 60);
1063 int ttv = tt_localtz + (int)(t * 3600);
1064 if (m_tzoneDisplay == 0) {
1065 ttv -= m_stationOffset_mins * 60;
1071 ptcmgr->GetTideOrCurrent(tts, pIDX->
IDX_rec_num, t, d);
1072 s.Printf(_T(
"%3.2f "), (t < 0 && CURRENT_PLOT == m_plot_type)
1079 if (pmsd) p.Append(wxString(pmsd->units_abbrv, wxConvUTF8));
1082 if (CURRENT_PLOT == m_plot_type) {
1083 s.Printf(
"%3.0f%c", d, 0x00B0);
1090 win_size.Set(x * 90 / 100, y * 80 / 100);
1092 m_pTCRolloverWin->SetString(p);
1093 m_pTCRolloverWin->SetBestPosition(curs_x, curs_y, 1, 1, TC_ROLLOVER,
1095 m_pTCRolloverWin->SetBitmap(TC_ROLLOVER);
1096 m_pTCRolloverWin->Refresh();
1097 m_pTCRolloverWin->Show();
1105 for (
int i = 0; i < 26; i++) {
1106 float ppx = m_graph_rect.x + ((i)*m_graph_rect.width / 25.f);
1113 wxPointList *list = (wxPointList *)&m_sList;
1114 wxPoint *a = list->Item(idx - 1)->GetData();
1115 wxPoint *b = list->Item(idx)->GetData();
1117 float pct = (curs_x - a->x) / (
float)((b->x - a->x));
1118 float dy = pct * (b->y - a->y);
1126 SetCursor(*pParent->pCursorArrow);
1127 ShowRollover =
false;
1130 if (m_pTCRolloverWin && m_pTCRolloverWin->IsShown() && !ShowRollover) {
1131 m_pTCRolloverWin->Hide();
1135void TCWin::OnTimeIndicatorTimer(wxTimerEvent &event) {
ChartCanvas - Main chart display and interaction component.
bool GetCanvasPointPix(double rlat, double rlon, wxPoint *r)
Convert latitude/longitude to canvas pixel coordinates (physical pixels) rounded to nearest integer.
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.
wxFont * GetFont(const wxString &TextElement, int requested_font_size=0)
Gets a font object for a UI element.
Represents an index entry for tidal and current data.
char IDX_type
Entry type identifier "TCtcIUu".
int IDX_flood_dir
Flood current direction (in degrees)
char IDX_station_name[MAXNAMELEN]
Name of the tidal or current station.
int IDX_ebb_dir
Ebb current direction (in degrees)
double IDX_lat
Latitude of the station (in degrees, +North)
double IDX_lon
Longitude of the station (in degrees, +East)
Station_Data * pref_sta_data
Pointer to the reference station data.
int IDX_rec_num
Record number for multiple entries with same name.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
General purpose GUI support.