28#include <wx/statline.h>
29#include <wx/textwrapper.h>
31#include "notification_manager_gui.h"
34#include "observable_globvar.h"
35#include "color_handler.h"
37#include "OCPNPlatform.h"
39#include "glChartCanvas.h"
42#include "model/datetime.h"
52 Wrap(win, text, widthMax);
54 wxString
const& GetWrapped()
const {
return m_wrapped; }
55 int const GetLineCount()
const {
return m_lineCount; }
56 wxArrayString GetLineArray() {
return m_array; }
59 virtual void OnOutputLine(
const wxString& line) {
63 virtual void OnNewLine() {
71 wxArrayString m_array;
76EVT_PAINT(NotificationPanel::OnPaint)
80 wxPanel* parent, wxWindowID
id, const wxPoint& pos, const wxSize& size,
81 std::shared_ptr<
Notification> _notification,
int _repeat_count)
82 : wxPanel(parent,
id, pos, size, wxBORDER_NONE),
83 repeat_count(_repeat_count) {
84 notification = _notification;
86 wxBoxSizer* topSizer =
new wxBoxSizer(wxVERTICAL);
89 wxBoxSizer* itemBoxSizer01 =
new wxBoxSizer(wxHORIZONTAL);
90 topSizer->Add(itemBoxSizer01, 0, wxEXPAND);
92 double iconSize = GetCharWidth() * 3;
94 int icon_scale = iconSize * dpi_mult;
96 wxImage notification_icon;
100 if (notification->GetSeverity() == NotificationSeverity::kInformational) {
102 wxFileName(g_Platform->GetSharedDataDir(),
"notification-info-2.svg");
103 }
else if (notification->GetSeverity() == NotificationSeverity::kWarning) {
104 path = wxFileName(g_Platform->GetSharedDataDir(),
105 "notification-warning-2.svg");
107 path = wxFileName(g_Platform->GetSharedDataDir(),
108 "notification-critical-2.svg");
110 path.AppendDir(
"uidata");
111 path.AppendDir(
"MUI_flat");
112 bitmap = LoadSVG(path.GetFullPath(), icon_scale, icon_scale);
113 m_itemStaticBitmap =
new wxStaticBitmap(
this, wxID_ANY, bitmap);
115 itemBoxSizer01->Add(m_itemStaticBitmap, 0, wxEXPAND | wxALL, 10);
118 wxString rp = _(
"Repeat:");
119 wxString sCount = rp + wxString::Format(
"\n %d", repeat_count);
120 auto counttextbox =
new wxStaticText(
this, wxID_ANY, sCount);
121 itemBoxSizer01->Add(counttextbox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
124 wxDateTime act_time = wxDateTime(notification->GetActivateTime());
125 wxString stime = wxString::Format(
128 .SetFormatString(
"$short_date")
129 .SetShowTimezone(
false)));
130 stime = stime.BeforeFirst(
' ');
131 wxString stime1 = wxString::Format(
132 "%s", ocpn::toUsrDateTimeFormat(act_time,
134 "$24_hour_minutes_seconds")));
138 auto timetextbox =
new wxStaticText(
this, wxID_ANY, stime);
139 itemBoxSizer01->Add(timetextbox, 0,
140 wxALL | wxALIGN_CENTER_VERTICAL, 5);
143 GetSize().x * 60 / 100);
145 auto textbox =
new wxStaticText(
this, wxID_ANY, wrapper.GetWrapped());
146 itemBoxSizer01->Add(textbox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 10);
148 itemBoxSizer01->AddStretchSpacer(1);
151 m_ack_button =
new wxButton(
this, wxID_OK);
152 itemBoxSizer01->Add(m_ack_button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 10);
153 m_ack_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
154 &NotificationPanel::OnAckButton,
this);
156 DimeControl(m_ack_button);
159NotificationPanel::~NotificationPanel() {}
161void NotificationPanel::OnAckButton(wxCommandEvent& event) {
166void NotificationPanel::OnPaint(wxPaintEvent& event) {
168 wxColor back_color = GetDialogColor(DLG_UNSELECTED_BACKGROUND);
169 wxBrush bg(back_color, wxBRUSHSTYLE_SOLID);
170 dc.SetBackground(bg);
174 wxColour box_color = GetDialogColor(DLG_UNSELECTED_BACKGROUND);
175 wxColour box_border = GetGlobalColor(
"GREY3");
177 wxBrush b(box_color, wxBRUSHSTYLE_SOLID);
179 dc.SetPen(wxPen(box_border, penWidth));
181 dc.DrawRoundedRectangle(5, 5, GetSize().x - 10, GetSize().y - 10, 5);
184NotificationListPanel::NotificationListPanel(wxWindow* parent, wxWindowID
id,
187 : wxScrolledWindow(parent, id, pos, size,
188 wxTAB_TRAVERSAL | wxVSCROLL | wxHSCROLL) {
189 SetSizer(
new wxBoxSizer(wxVERTICAL));
191 ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_DEFAULT);
193 ShowScrollbars(wxSHOW_SB_NEVER, wxSHOW_SB_NEVER);
196 ReloadNotificationPanels();
200NotificationListPanel::~NotificationListPanel() {}
202void NotificationListPanel::ReloadNotificationPanels() {
203 wxWindowList kids = GetChildren();
204 for (
unsigned int i = 0; i < kids.GetCount(); i++) {
205 wxWindowListNode* node = kids.Item(i);
206 wxWindow* win = node->GetData();
208 if (pp) win->Destroy();
217 int panel_size_x = 60 * GetCharWidth();
218 panel_size_x = wxMax(panel_size_x, GetParent()->GetClientSize().x);
219 wxSize panel_size = wxSize(panel_size_x, -1);
221 for (
auto notification : notifications) {
222 size_t this_hash = notification->GetStringHash();
223 int repeat_count = 0;
224 for (
auto hash_test : notifications) {
225 if (hash_test->GetStringHash() == this_hash) {
232 for (
auto tpanel : panels) {
233 auto note = tpanel->GetNotification();
235 if ((note->GetStringHash() == this_hash) && (repeat_count > 1)) {
243 notification, repeat_count);
244 panels.push_back(panel);
247 for (
auto panel : panels) {
248 AddNotificationPanel(panel);
259 GetSizer()->Add(_panel, 0);
267EVT_CLOSE(NotificationsList::OnClose)
274 long mstyle = wxRESIZE_BORDER | wxCAPTION | wxCLOSE_BOX | wxFRAME_NO_TASKBAR;
276 mstyle |= wxSTAY_ON_TOP;
279 wxDialog::Create(parent, wxID_ANY, _(
"OpenCPN Notifications"),
280 wxDefaultPosition, wxDefaultSize, mstyle);
282 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
286 int group_item_spacing = 0;
287 int interGroupSpace = border_size * 2;
289 auto acksizer =
new wxBoxSizer(wxHORIZONTAL);
290 topsizer->Add(acksizer, 0, wxEXPAND);
293 acksizer->AddStretchSpacer(1);
295 m_ackall_button =
new wxButton(
this, wxID_ANY, _(
"Acknowledge All"));
296 acksizer->Add(m_ackall_button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
297 m_ackall_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
298 &NotificationsList::OnAckAllButton,
this);
299 acksizer->AddSpacer(10);
302 topsizer->Add(0, interGroupSpace);
305 this, wxID_ANY, wxDefaultPosition, wxSize(-1, parent->GetSize().y));
306 topsizer->Add(m_notifications_list_panel, 0, wxALL | wxEXPAND, border_size);
310void NotificationsList::SetColorScheme() { DimeControl(
this); }
312void NotificationsList::ReloadNotificationList() {
313 m_notifications_list_panel->ReloadNotificationPanels();
314 if (!m_notifications_list_panel->GetPanels().size()) {
316 GetParent()->Refresh();
320void NotificationsList::OnAckAllButton(wxCommandEvent& event) {
322 noteman.AcknowledgeAllNotifications();
325void NotificationsList::RecalculateSize() {
327 wxSize parent_size = GetParent()->GetSize();
328 wxPoint ClientUpperRight =
329 GetParent()->ClientToScreen(wxPoint(parent_size.x, 0));
330 wxPoint list_bottom =
331 GetParent()->ClientToScreen(wxPoint(0, parent_size.y / 3));
332 int size_y = list_bottom.y - (ClientUpperRight.y + 5);
333 size_y -= GetParent()->GetCharHeight();
335 wxMax(size_y, 8 * GetCharHeight());
337 wxSize target_size = wxSize(GetCharWidth() * 80, size_y);
339 wxPoint targetNLPos = GetParent()->ClientToScreen(
340 wxPoint(parent_size.x / 2, 3 * GetParent()->GetCharHeight()));
344 if (target_size.x * 2 > display_size.x) {
346 display_size.x * 85 / 100 - (2 * GetParent()->GetCharWidth());
348 GetParent()->ClientToScreen(wxPoint(display_size.x * 15 / 100, 0)).x;
351 SetSize(target_size);
356void NotificationsList::OnClose(wxCloseEvent& event) { Hide(); }
363extern bool g_bSatValid;
364extern int g_SatsInView;
365extern bool g_bopengl;
366extern bool g_btenhertz;
369#define GL_RGBA8 0x8058
372NotificationButton::NotificationButton(
ChartCanvas* parent) {
376 _img_gpsRed = style->GetIcon(_T(
"gpsRed"));
378 m_pStatBoxToolStaticBmp = NULL;
380 m_rect = wxRect(style->GetCompassXOffset(), style->GetCompassYOffset(),
381 _img_gpsRed.GetWidth() + style->GetCompassLeftMargin() * 2 +
382 style->GetToolSeparation(),
383 _img_gpsRed.GetHeight() + style->GetCompassTopMargin() +
384 style->GetCompassBottomMargin());
392 m_cs = GLOBAL_COLOR_SCHEME_RGB;
393 m_NoteIconName =
"notification-info-2";
396NotificationButton::~NotificationButton() {
399 glDeleteTextures(1, &m_texobj);
404 delete m_pStatBoxToolStaticBmp;
407void NotificationButton::SetIconSeverity(NotificationSeverity _severity) {
409 if (_severity == NotificationSeverity::kInformational) {
410 icon_name =
"notification-info-2";
411 }
else if (_severity == NotificationSeverity::kWarning) {
412 icon_name =
"notification-warning-2";
414 icon_name =
"notification-critical-2";
417 SetIconName(icon_name);
420void NotificationButton::Paint(
ocpnDC& dc) {
421 if (m_shown && m_StatBmp.IsOk()) {
422#if defined(ocpnUSE_GLES) || defined(ocpnUSE_GL)
423 if (g_bopengl && !m_texobj) {
426 glGenTextures(1, &m_texobj);
430 if (g_bopengl && m_texobj ) {
431 glBindTexture(GL_TEXTURE_2D, m_texobj);
432 glEnable(GL_TEXTURE_2D);
434#if defined(USE_ANDROID_GLES2) || defined(ocpnUSE_GLSL)
441 uv[2] = (float)m_image_width / m_tex_w;
443 uv[4] = (float)m_image_width / m_tex_w;
444 uv[5] = (float)m_image_height / m_tex_h;
446 uv[7] = (float)m_image_height / m_tex_h;
449 coords[0] = m_rect.x;
450 coords[1] = m_rect.y;
451 coords[2] = m_rect.x + m_rect.width;
452 coords[3] = m_rect.y;
453 coords[4] = m_rect.x + m_rect.width;
454 coords[5] = m_rect.y + m_rect.height;
455 coords[6] = m_rect.x;
456 coords[7] = m_rect.y + m_rect.height;
458 m_parent->GetglCanvas()->RenderTextures(dc, coords, uv, 4,
465 glVertex2i(m_rect.x, m_rect.y);
466 glTexCoord2f((
float)m_image_width / m_tex_w, 0);
467 glVertex2i(m_rect.x + m_rect.width, m_rect.y);
468 glTexCoord2f((
float)m_image_width / m_tex_w,
469 (
float)m_image_height / m_tex_h);
470 glVertex2i(m_rect.x + m_rect.width, m_rect.y + m_rect.height);
471 glTexCoord2f(0, (
float)m_image_height / m_tex_h);
472 glVertex2i(m_rect.x, m_rect.y + m_rect.height);
477 glDisable(GL_TEXTURE_2D);
483 double scale = m_parent->GetContentScaleFactor();
485 wxImage image = m_StatBmp.ConvertToImage();
486 image.Rescale(image.GetWidth() *
scale, image.GetHeight() *
scale);
488 dc.DrawBitmap(bmp, m_rect.x, m_rect.y,
true);
490 dc.DrawBitmap(m_StatBmp, m_rect.x, m_rect.y,
true);
492 dc.DrawBitmap(m_StatBmp, m_rect.x, m_rect.y,
true);
494 dc.DrawBitmap(m_StatBmp, m_rect.x, m_rect.y,
true);
499 dc.DrawBitmap(m_StatBmp, m_rect.x, m_rect.y,
true);
504void NotificationButton::SetColorScheme(ColorScheme cs) {
510#ifdef wxHAS_DPI_INDEPENDENT_PIXELS
511#if wxCHECK_VERSION(3, 1, 6)
512 wxRect logicalRect = wxRect(m_parent->FromPhys(m_rect.GetPosition()),
513 m_parent->FromPhys(m_rect.GetSize()));
515 double scaleFactor = m_parent->GetContentScaleFactor();
517 wxPoint(m_rect.GetX() / scaleFactor, m_rect.GetY() / scaleFactor),
518 wxSize(m_rect.GetWidth() / scaleFactor,
519 m_rect.GetHeight() / scaleFactor));
523 wxRect logicalRect = m_rect;
528bool NotificationButton::UpdateStatus(
bool bnew) {
530 if (bnew) m_lastNoteIconName.Clear();
531 if (m_lastNoteIconName != m_NoteIconName) {
537 if (g_bopengl && m_texobj) CreateTexture();
542void NotificationButton::SetScaleFactor(
float factor) {
552 int orient = style->GetOrientation();
553 style->SetOrientation(wxTB_HORIZONTAL);
554 if (style->HasBackground()) {
555 noteBg = style->GetNormalBG();
556 style->DrawToolbarLineEnd(noteBg);
557 noteBg = style->SetBitmapBrightness(noteBg, m_cs);
560 if (fabs(m_scale - 1.0) > 0.1) {
567 int width = noteBg.GetWidth() + style->GetCompassLeftMargin();
568 if (!style->marginsInvisible)
569 width += style->GetCompassLeftMargin() + style->GetToolSeparation();
571 m_rect = wxRect(style->GetCompassXOffset(), style->GetCompassYOffset(), width,
572 noteBg.GetHeight() + style->GetCompassTopMargin() +
573 style->GetCompassBottomMargin());
576void NotificationButton::CreateBmp(
bool newColorScheme) {
584 static wxBitmap noteBg;
585 static wxSize toolsize;
586 static int topmargin, leftmargin, radius;
588 if (!noteBg.IsOk() || newColorScheme) {
589 int orient = style->GetOrientation();
590 style->SetOrientation(wxTB_HORIZONTAL);
591 if (style->HasBackground()) {
592 noteBg = style->GetNormalBG();
593 style->DrawToolbarLineEnd(noteBg);
594 noteBg = style->SetBitmapBrightness(noteBg, m_cs);
597 if (fabs(m_scale - 1.0) > 0.1) {
598 wxImage bg_img = noteBg.ConvertToImage();
599 bg_img.Rescale(noteBg.GetWidth() * m_scale, noteBg.GetHeight() * m_scale,
600 wxIMAGE_QUALITY_NORMAL);
601 noteBg = wxBitmap(bg_img);
604 leftmargin = style->GetCompassLeftMargin();
605 topmargin = style->GetCompassTopMargin();
606 radius = style->GetCompassCornerRadius();
608 if (orient == wxTB_VERTICAL) style->SetOrientation(wxTB_VERTICAL);
612 int height = noteBg.GetHeight() + topmargin + style->GetCompassBottomMargin();
617 m_StatBmp.Create(width, height);
619 m_rect.width = m_StatBmp.GetWidth();
620 m_rect.height = m_StatBmp.GetHeight();
622 m_MaskBmp = wxBitmap(m_StatBmp.GetWidth(), m_StatBmp.GetHeight());
623 if (style->marginsInvisible) {
624 wxMemoryDC sdc(m_MaskBmp);
625 sdc.SetBackground(*wxWHITE_BRUSH);
627 sdc.SetBrush(*wxBLACK_BRUSH);
628 sdc.SetPen(*wxBLACK_PEN);
629 wxSize maskSize = wxSize(m_MaskBmp.GetWidth() - leftmargin,
630 m_MaskBmp.GetHeight() - (2 * topmargin));
631 sdc.DrawRoundedRectangle(wxPoint(leftmargin, topmargin), maskSize, radius);
632 sdc.SelectObject(wxNullBitmap);
634 wxMemoryDC sdc(m_MaskBmp);
635 sdc.SetBackground(*wxWHITE_BRUSH);
637 sdc.SetBrush(*wxBLACK_BRUSH);
638 sdc.SetPen(*wxBLACK_PEN);
639 sdc.DrawRoundedRectangle(0, 0, m_MaskBmp.GetWidth(), m_MaskBmp.GetHeight(),
641 sdc.SelectObject(wxNullBitmap);
643#if !defined(USE_ANDROID_GLES2) && !defined(ocpnUSE_GLSL)
644 m_StatBmp.SetMask(
new wxMask(m_MaskBmp, *wxWHITE));
648 mdc.SelectObject(m_StatBmp);
649 mdc.SetBackground(wxBrush(GetGlobalColor(_T(
"COMP1")), wxBRUSHSTYLE_SOLID));
652 mdc.SetPen(wxPen(GetGlobalColor(_T(
"UITX1")), 1));
653 mdc.SetBrush(wxBrush(GetGlobalColor(_T(
"UITX1")), wxBRUSHSTYLE_TRANSPARENT));
655 if (!style->marginsInvisible)
656 mdc.DrawRoundedRectangle(0, 0, m_StatBmp.GetWidth(), m_StatBmp.GetHeight(),
658 wxPoint offset(leftmargin, topmargin);
661 int twidth = style->GetToolSize().x * m_scale;
662 int theight = style->GetToolSize().y * m_scale;
663 int swidth = wxMax(twidth, theight);
664 int sheight = wxMin(twidth, theight);
666 swidth = swidth * 45 / 50;
667 sheight = sheight * 45 / 50;
669 offset.x = ((m_StatBmp.GetWidth() - swidth) / 2);
670 offset.y = ((m_StatBmp.GetHeight() - sheight) / 2);
672 wxFileName icon_path;
673 wxString file_name = m_NoteIconName +
".svg";
674 icon_path = wxFileName(g_Platform->GetSharedDataDir(), file_name);
675 icon_path.AppendDir(
"uidata");
676 icon_path.AppendDir(
"MUI_flat");
677 wxBitmap gicon = LoadSVG(icon_path.GetFullPath(), swidth, sheight);
682 mdc.DrawBitmap(iconBm, offset);
683 mdc.SelectObject(wxNullBitmap);
685 m_lastNoteIconName = m_NoteIconName;
688void NotificationButton::CreateTexture() {
689#if defined(USE_ANDROID_GLES2) || defined(ocpnUSE_GLSL)
693 wxImage image = m_StatBmp.ConvertToImage();
694 unsigned char* imgdata = image.GetData();
695 unsigned char* imgalpha = image.GetAlpha();
696 m_tex_w = image.GetWidth();
697 m_tex_h = image.GetHeight();
698 m_image_width = m_tex_w;
699 m_image_height = m_tex_h;
702 int width_pot = m_tex_w;
703 int height_pot = m_tex_h;
705 int xp = image.GetWidth();
706 if (((xp != 0) && !(xp & (xp - 1))))
717 xp = image.GetHeight();
718 if (((xp != 0) && !(xp & (xp - 1))))
730 m_tex_h = height_pot;
732 GLuint format = GL_RGBA;
733 GLuint internalformat = GL_RGBA8;
737 unsigned char* teximage =
738 (
unsigned char*)malloc(stride * m_tex_w * m_tex_h);
740 for (
int i = 0; i < m_image_height; i++) {
741 for (
int j = 0; j < m_image_width; j++) {
742 int s = (i * 3 * m_image_width) + (j * 3);
743 int d = (i * stride * m_tex_w) + (j * stride);
745 teximage[d + 0] = imgdata[s + 0];
746 teximage[d + 1] = imgdata[s + 1];
747 teximage[d + 2] = imgdata[s + 2];
748 teximage[d + 3] = 255;
752 glBindTexture(GL_TEXTURE_2D, m_texobj);
754 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
755 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
756 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
758 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
760 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, m_tex_w, m_tex_h, 0,
761 format, GL_UNSIGNED_BYTE, teximage);
764 glBindTexture(GL_TEXTURE_2D, 0);
771void NotificationButton::UpdateTexture() {
772#if defined(USE_ANDROID_GLES2) || defined(ocpnUSE_GLSL)
776 wxImage image = m_StatBmp.ConvertToImage();
777 unsigned char* imgdata = image.GetData();
778 unsigned char* imgalpha = image.GetAlpha();
779 m_tex_w = image.GetWidth();
780 m_tex_h = image.GetHeight();
781 m_image_width = m_tex_w;
782 m_image_height = m_tex_h;
785 int width_pot = m_tex_w;
786 int height_pot = m_tex_h;
788 int xp = image.GetWidth();
789 if (((xp != 0) && !(xp & (xp - 1))))
800 xp = image.GetHeight();
801 if (((xp != 0) && !(xp & (xp - 1))))
813 m_tex_h = height_pot;
815 GLuint format = GL_RGBA;
816 GLuint internalformat = GL_RGBA8;
820 unsigned char* teximage =
821 (
unsigned char*)malloc(stride * m_tex_w * m_tex_h);
823 for (
int i = 0; i < m_image_height; i++) {
824 for (
int j = 0; j < m_image_width; j++) {
825 int s = (i * 3 * m_image_width) + (j * 3);
826 int d = (i * stride * m_tex_w) + (j * stride);
828 teximage[d + 0] = imgdata[s + 0];
829 teximage[d + 1] = imgdata[s + 1];
830 teximage[d + 2] = imgdata[s + 2];
831 teximage[d + 3] = 255;
835 glBindTexture(GL_TEXTURE_2D, m_texobj);
836 glEnable(GL_TEXTURE_2D);
838 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_tex_w, m_tex_h, format,
839 GL_UNSIGNED_BYTE, teximage);
842 glBindTexture(GL_TEXTURE_2D, 0);
ChartCanvas - Main chart display and interaction component.
The global list of user notifications, a singleton.
const std::vector< std::shared_ptr< Notification > > & GetNotifications() const
Return current active notifications.
bool AcknowledgeNotification(const std::string &guid)
User ack on a notification which eventually will remove it.
User visible notification.
Device context class that can use either wxDC or OpenGL for drawing.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
General purpose GUI support.
Class NotificationManager.