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"
41#include "model/datetime.h"
50 Wrap(win, text, widthMax);
52 wxString
const& GetWrapped()
const {
return m_wrapped; }
53 int const GetLineCount()
const {
return m_lineCount; }
54 wxArrayString GetLineArray() {
return m_array; }
57 virtual void OnOutputLine(
const wxString& line) {
61 virtual void OnNewLine() {
69 wxArrayString m_array;
74EVT_PAINT(NotificationPanel::OnPaint)
78 wxPanel* parent, wxWindowID
id, const wxPoint& pos, const wxSize& size,
79 std::shared_ptr<
Notification> _notification,
int _repeat_count)
80 : wxPanel(parent,
id, pos, size, wxBORDER_NONE),
81 repeat_count(_repeat_count) {
82 notification = _notification;
84 wxBoxSizer* topSizer =
new wxBoxSizer(wxVERTICAL);
87 wxBoxSizer* itemBoxSizer01 =
new wxBoxSizer(wxHORIZONTAL);
88 topSizer->Add(itemBoxSizer01, 0, wxEXPAND);
90 double iconSize = GetCharWidth() * 3;
92 int icon_scale = iconSize * dpi_mult;
94 wxImage notification_icon;
98 if (notification->GetSeverity() == NotificationSeverity::kInformational) {
99 path = wxFileName(g_Platform->GetSharedDataDir(),
"notification-info.svg");
100 }
else if (notification->GetSeverity() == NotificationSeverity::kWarning) {
102 wxFileName(g_Platform->GetSharedDataDir(),
"notification-warning.svg");
105 wxFileName(g_Platform->GetSharedDataDir(),
"notification-critical.svg");
107 path.AppendDir(
"uidata");
108 path.AppendDir(
"MUI_flat");
109 bitmap = LoadSVG(path.GetFullPath(), icon_scale, icon_scale);
110 m_itemStaticBitmap =
new wxStaticBitmap(
this, wxID_ANY, bitmap);
112 itemBoxSizer01->Add(m_itemStaticBitmap, 0, wxEXPAND | wxALL, 10);
115 wxString rp = _(
"Repeat:");
116 wxString sCount = rp + wxString::Format(
"\n %d", repeat_count);
117 auto counttextbox =
new wxStaticText(
this, wxID_ANY, sCount);
118 itemBoxSizer01->Add(counttextbox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
121 wxDateTime act_time = wxDateTime(notification->GetActivateTime());
122 wxString stime = wxString::Format(
123 "%s", ocpn::toUsrDateTimeFormat(
125 "$short_date\n$hour_minutes_seconds")));
126 auto timetextbox =
new wxStaticText(
this, wxID_ANY, stime);
127 itemBoxSizer01->Add(timetextbox, 0,
128 wxALL | wxALIGN_CENTER_VERTICAL, 5);
131 GetSize().x * 5 / 10);
133 auto textbox =
new wxStaticText(
this, wxID_ANY, wrapper.GetWrapped());
134 itemBoxSizer01->Add(textbox, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
136 itemBoxSizer01->AddStretchSpacer(1);
139 m_ack_button =
new wxButton(
this, wxID_ANY,
"ACK");
140 itemBoxSizer01->Add(m_ack_button, 0, wxALIGN_CENTER_VERTICAL | wxALL, 10);
141 m_ack_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
142 &NotificationPanel::OnAckButton,
this);
148NotificationPanel::~NotificationPanel() {}
150void NotificationPanel::OnAckButton(wxCommandEvent& event) {
155void NotificationPanel::OnPaint(wxPaintEvent& event) {
159 wxColour color = GetDialogColor(DLG_UNSELECTED_BACKGROUND);
160 wxColour border = GetDialogColor(DLG_UNSELECTED_ACCENT);
162 wxBrush b(color, wxBRUSHSTYLE_SOLID);
164 dc.SetPen(wxPen(border, penWidth));
166 dc.DrawRoundedRectangle(5, 5, GetSize().x - 10, GetSize().y - 10, 5);
169NotificationListPanel::NotificationListPanel(wxWindow* parent, wxWindowID
id,
172 : wxScrolledWindow(parent, id, pos, size, wxTAB_TRAVERSAL | wxVSCROLL) {
173 SetSizer(
new wxBoxSizer(wxVERTICAL));
175 ReloadNotificationPanels();
178NotificationListPanel::~NotificationListPanel() {}
180void NotificationListPanel::ReloadNotificationPanels() {
181 wxWindowList kids = GetChildren();
182 for (
unsigned int i = 0; i < kids.GetCount(); i++) {
183 wxWindowListNode* node = kids.Item(i);
184 wxWindow* win = node->GetData();
186 if (pp) win->Destroy();
195 wxSize panel_size = GetParent()->GetClientSize();
198 for (
auto notification : notifications) {
199 size_t this_hash = notification->GetStringHash();
200 int repeat_count = 0;
201 for (
auto hash_test : notifications) {
202 if (hash_test->GetStringHash() == this_hash) {
209 for (
auto tpanel : panels) {
210 auto note = tpanel->GetNotification();
212 if ((note->GetStringHash() == this_hash) && (repeat_count > 1)) {
220 notification, repeat_count);
221 panels.push_back(panel);
224 for (
auto panel : panels) {
225 AddNotificationPanel(panel);
228 GetSizer()->FitInside(
this);
237 GetSizer()->Add(_panel, 0, wxEXPAND);
245EVT_CLOSE(NotificationsList::OnClose)
255 long mstyle = wxNO_BORDER | wxFRAME_NO_TASKBAR;
257 mstyle |= wxSTAY_ON_TOP;
260 wxDialog::Create(parent, wxID_ANY, _T(
""), wxDefaultPosition, wxDefaultSize,
263 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
274 int group_item_spacing = 0;
275 int interGroupSpace = border_size * 2;
277 wxSizerFlags verticalInputFlags = wxSizerFlags(0)
280 .Border(wxALL, group_item_spacing);
281 wxSizerFlags inputFlags =
282 wxSizerFlags(0).Align(wxALIGN_LEFT).Border(wxALL, group_item_spacing);
290 wxStaticText* optionsLabelBox =
291 new wxStaticText(
this, wxID_ANY, _(
"OpenCPN Notifications"));
292 topsizer->Add(optionsLabelBox, 0, wxALL | wxEXPAND, 4);
293 wxStaticLine* m_staticLine121 =
new wxStaticLine(
294 this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL);
295 topsizer->Add(m_staticLine121, 0, wxALL | wxEXPAND, 4);
298 topsizer->Add(0, interGroupSpace);
301 this, wxID_ANY, wxDefaultPosition, wxSize(-1, 300));
302 topsizer->Add(m_notifications_list_panel, 0, wxALL | wxEXPAND, border_size);
309void NotificationsList::ReloadNotificationList() {
310 m_notifications_list_panel->ReloadNotificationPanels();
311 if (!m_notifications_list_panel->GetPanels().size()) {
313 GetParent()->Refresh();
317void NotificationsList::OnClose(wxCloseEvent& event) {}
324extern bool g_bSatValid;
325extern int g_SatsInView;
326extern bool g_bopengl;
327extern bool g_btenhertz;
330#define GL_RGBA8 0x8058
333NotificationButton::NotificationButton(
ChartCanvas* parent) {
337 _img_gpsRed = style->GetIcon(_T(
"gpsRed"));
339 m_pStatBoxToolStaticBmp = NULL;
341 m_rect = wxRect(style->GetCompassXOffset(), style->GetCompassYOffset(),
342 _img_gpsRed.GetWidth() + style->GetCompassLeftMargin() * 2 +
343 style->GetToolSeparation(),
344 _img_gpsRed.GetHeight() + style->GetCompassTopMargin() +
345 style->GetCompassBottomMargin());
353 m_cs = GLOBAL_COLOR_SCHEME_RGB;
354 m_NoteIconName =
"notification-info";
357NotificationButton::~NotificationButton() {
360 glDeleteTextures(1, &m_texobj);
365 delete m_pStatBoxToolStaticBmp;
368void NotificationButton::SetIconSeverity(NotificationSeverity _severity) {
370 if (_severity == NotificationSeverity::kInformational) {
371 icon_name =
"notification-info";
372 }
else if (_severity == NotificationSeverity::kWarning) {
373 icon_name =
"notification-warning";
375 icon_name =
"notification-critical";
378 SetIconName(icon_name);
381void NotificationButton::Paint(
ocpnDC& dc) {
382 if (m_shown && m_StatBmp.IsOk()) {
383#if defined(ocpnUSE_GLES) || defined(ocpnUSE_GL)
384 if (g_bopengl && !m_texobj) {
387 glGenTextures(1, &m_texobj);
391 if (g_bopengl && m_texobj ) {
392 glBindTexture(GL_TEXTURE_2D, m_texobj);
393 glEnable(GL_TEXTURE_2D);
395#if defined(USE_ANDROID_GLES2) || defined(ocpnUSE_GLSL)
402 uv[2] = (float)m_image_width / m_tex_w;
404 uv[4] = (float)m_image_width / m_tex_w;
405 uv[5] = (float)m_image_height / m_tex_h;
407 uv[7] = (float)m_image_height / m_tex_h;
410 coords[0] = m_rect.x;
411 coords[1] = m_rect.y;
412 coords[2] = m_rect.x + m_rect.width;
413 coords[3] = m_rect.y;
414 coords[4] = m_rect.x + m_rect.width;
415 coords[5] = m_rect.y + m_rect.height;
416 coords[6] = m_rect.x;
417 coords[7] = m_rect.y + m_rect.height;
419 m_parent->GetglCanvas()->RenderTextures(dc, coords, uv, 4,
426 glVertex2i(m_rect.x, m_rect.y);
427 glTexCoord2f((
float)m_image_width / m_tex_w, 0);
428 glVertex2i(m_rect.x + m_rect.width, m_rect.y);
429 glTexCoord2f((
float)m_image_width / m_tex_w,
430 (
float)m_image_height / m_tex_h);
431 glVertex2i(m_rect.x + m_rect.width, m_rect.y + m_rect.height);
432 glTexCoord2f(0, (
float)m_image_height / m_tex_h);
433 glVertex2i(m_rect.x, m_rect.y + m_rect.height);
438 glDisable(GL_TEXTURE_2D);
444 double scale = m_parent->GetContentScaleFactor();
446 wxImage image = m_StatBmp.ConvertToImage();
447 image.Rescale(image.GetWidth() *
scale, image.GetHeight() *
scale);
449 dc.DrawBitmap(bmp, m_rect.x, m_rect.y,
true);
451 dc.DrawBitmap(m_StatBmp, m_rect.x, m_rect.y,
true);
453 dc.DrawBitmap(m_StatBmp, m_rect.x, m_rect.y,
true);
455 dc.DrawBitmap(m_StatBmp, m_rect.x, m_rect.y,
true);
460 dc.DrawBitmap(m_StatBmp, m_rect.x, m_rect.y,
true);
465void NotificationButton::SetColorScheme(ColorScheme cs) {
471#ifdef wxHAS_DPI_INDEPENDENT_PIXELS
472#if wxCHECK_VERSION(3, 1, 6)
473 wxRect logicalRect = wxRect(m_parent->FromPhys(m_rect.GetPosition()),
474 m_parent->FromPhys(m_rect.GetSize()));
476 double scaleFactor = m_parent->GetContentScaleFactor();
478 wxPoint(m_rect.GetX() / scaleFactor, m_rect.GetY() / scaleFactor),
479 wxSize(m_rect.GetWidth() / scaleFactor,
480 m_rect.GetHeight() / scaleFactor));
484 wxRect logicalRect = m_rect;
489bool NotificationButton::UpdateStatus(
bool bnew) {
491 if (bnew) m_lastNoteIconName.Clear();
492 if (m_lastNoteIconName != m_NoteIconName) {
498 if (g_bopengl && m_texobj) CreateTexture();
503void NotificationButton::SetScaleFactor(
float factor) {
513 int orient = style->GetOrientation();
514 style->SetOrientation(wxTB_HORIZONTAL);
515 if (style->HasBackground()) {
516 noteBg = style->GetNormalBG();
517 style->DrawToolbarLineEnd(noteBg);
518 noteBg = style->SetBitmapBrightness(noteBg, m_cs);
521 if (fabs(m_scale - 1.0) > 0.1) {
528 int width = noteBg.GetWidth() + style->GetCompassLeftMargin();
529 if (!style->marginsInvisible)
530 width += style->GetCompassLeftMargin() + style->GetToolSeparation();
532 m_rect = wxRect(style->GetCompassXOffset(), style->GetCompassYOffset(), width,
533 noteBg.GetHeight() + style->GetCompassTopMargin() +
534 style->GetCompassBottomMargin());
537void NotificationButton::CreateBmp(
bool newColorScheme) {
545 static wxBitmap noteBg;
546 static wxSize toolsize;
547 static int topmargin, leftmargin, radius;
549 if (!noteBg.IsOk() || newColorScheme) {
550 int orient = style->GetOrientation();
551 style->SetOrientation(wxTB_HORIZONTAL);
552 if (style->HasBackground()) {
553 noteBg = style->GetNormalBG();
554 style->DrawToolbarLineEnd(noteBg);
555 noteBg = style->SetBitmapBrightness(noteBg, m_cs);
558 if (fabs(m_scale - 1.0) > 0.1) {
559 wxImage bg_img = noteBg.ConvertToImage();
560 bg_img.Rescale(noteBg.GetWidth() * m_scale, noteBg.GetHeight() * m_scale,
561 wxIMAGE_QUALITY_NORMAL);
562 noteBg = wxBitmap(bg_img);
565 leftmargin = style->GetCompassLeftMargin();
566 topmargin = style->GetCompassTopMargin();
567 radius = style->GetCompassCornerRadius();
569 if (orient == wxTB_VERTICAL) style->SetOrientation(wxTB_VERTICAL);
572 int width = noteBg.GetWidth() + leftmargin;
574 if (!style->marginsInvisible)
575 width += leftmargin + style->GetToolSeparation();
578 width, noteBg.GetHeight() + topmargin + style->GetCompassBottomMargin());
580 m_rect.width = m_StatBmp.GetWidth();
581 m_rect.height = m_StatBmp.GetHeight();
583 m_MaskBmp = wxBitmap(m_StatBmp.GetWidth(), m_StatBmp.GetHeight());
584 if (style->marginsInvisible) {
585 wxMemoryDC sdc(m_MaskBmp);
586 sdc.SetBackground(*wxWHITE_BRUSH);
588 sdc.SetBrush(*wxBLACK_BRUSH);
589 sdc.SetPen(*wxBLACK_PEN);
590 wxSize maskSize = wxSize(m_MaskBmp.GetWidth() - leftmargin,
591 m_MaskBmp.GetHeight() - (2 * topmargin));
592 sdc.DrawRoundedRectangle(wxPoint(leftmargin, topmargin), maskSize, radius);
593 sdc.SelectObject(wxNullBitmap);
595 wxMemoryDC sdc(m_MaskBmp);
596 sdc.SetBackground(*wxWHITE_BRUSH);
598 sdc.SetBrush(*wxBLACK_BRUSH);
599 sdc.SetPen(*wxBLACK_PEN);
600 sdc.DrawRoundedRectangle(0, 0, m_MaskBmp.GetWidth(), m_MaskBmp.GetHeight(),
602 sdc.SelectObject(wxNullBitmap);
604#if !defined(USE_ANDROID_GLES2) && !defined(ocpnUSE_GLSL)
605 m_StatBmp.SetMask(
new wxMask(m_MaskBmp, *wxWHITE));
609 mdc.SelectObject(m_StatBmp);
610 mdc.SetBackground(wxBrush(GetGlobalColor(_T(
"COMP1")), wxBRUSHSTYLE_SOLID));
613 mdc.SetPen(wxPen(GetGlobalColor(_T(
"UITX1")), 1));
614 mdc.SetBrush(wxBrush(GetGlobalColor(_T(
"UITX1")), wxBRUSHSTYLE_TRANSPARENT));
616 if (!style->marginsInvisible)
617 mdc.DrawRoundedRectangle(0, 0, m_StatBmp.GetWidth(), m_StatBmp.GetHeight(),
619 wxPoint offset(leftmargin, topmargin);
621 offset.x += style->GetToolSeparation();
624 int twidth = style->GetToolSize().x * m_scale;
625 int theight = style->GetToolSize().y * m_scale;
626 int swidth = wxMax(twidth, theight);
627 int sheight = wxMin(twidth, theight);
629 wxFileName icon_path;
630 wxString file_name = m_NoteIconName +
".svg";
631 icon_path = wxFileName(g_Platform->GetSharedDataDir(), file_name);
632 icon_path.AppendDir(
"uidata");
633 icon_path.AppendDir(
"MUI_flat");
634 wxBitmap gicon = LoadSVG(icon_path.GetFullPath(), swidth, sheight);
637 if (style->HasBackground()) {
638 iconBm = MergeBitmaps(noteBg, gicon, wxSize(0, 0));
643 iconBm = ConvertTo24Bit(wxColor(0, 0, 0), iconBm);
644 mdc.DrawBitmap(iconBm, offset);
645 mdc.SelectObject(wxNullBitmap);
647 m_lastNoteIconName = m_NoteIconName;
650void NotificationButton::CreateTexture() {
651#if defined(USE_ANDROID_GLES2) || defined(ocpnUSE_GLSL)
655 wxImage image = m_StatBmp.ConvertToImage();
656 unsigned char* imgdata = image.GetData();
657 unsigned char* imgalpha = image.GetAlpha();
658 m_tex_w = image.GetWidth();
659 m_tex_h = image.GetHeight();
660 m_image_width = m_tex_w;
661 m_image_height = m_tex_h;
664 int width_pot = m_tex_w;
665 int height_pot = m_tex_h;
667 int xp = image.GetWidth();
668 if (((xp != 0) && !(xp & (xp - 1))))
679 xp = image.GetHeight();
680 if (((xp != 0) && !(xp & (xp - 1))))
692 m_tex_h = height_pot;
694 GLuint format = GL_RGBA;
695 GLuint internalformat = GL_RGBA8;
699 unsigned char* teximage =
700 (
unsigned char*)malloc(stride * m_tex_w * m_tex_h);
702 for (
int i = 0; i < m_image_height; i++) {
703 for (
int j = 0; j < m_image_width; j++) {
704 int s = (i * 3 * m_image_width) + (j * 3);
705 int d = (i * stride * m_tex_w) + (j * stride);
707 teximage[d + 0] = imgdata[s + 0];
708 teximage[d + 1] = imgdata[s + 1];
709 teximage[d + 2] = imgdata[s + 2];
710 teximage[d + 3] = 255;
714 glBindTexture(GL_TEXTURE_2D, m_texobj);
716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
720 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
722 glTexImage2D(GL_TEXTURE_2D, 0, internalformat, m_tex_w, m_tex_h, 0,
723 format, GL_UNSIGNED_BYTE, teximage);
726 glBindTexture(GL_TEXTURE_2D, 0);
733void NotificationButton::UpdateTexture() {
734#if defined(USE_ANDROID_GLES2) || defined(ocpnUSE_GLSL)
738 wxImage image = m_StatBmp.ConvertToImage();
739 unsigned char* imgdata = image.GetData();
740 unsigned char* imgalpha = image.GetAlpha();
741 m_tex_w = image.GetWidth();
742 m_tex_h = image.GetHeight();
743 m_image_width = m_tex_w;
744 m_image_height = m_tex_h;
747 int width_pot = m_tex_w;
748 int height_pot = m_tex_h;
750 int xp = image.GetWidth();
751 if (((xp != 0) && !(xp & (xp - 1))))
762 xp = image.GetHeight();
763 if (((xp != 0) && !(xp & (xp - 1))))
775 m_tex_h = height_pot;
777 GLuint format = GL_RGBA;
778 GLuint internalformat = GL_RGBA8;
782 unsigned char* teximage =
783 (
unsigned char*)malloc(stride * m_tex_w * m_tex_h);
785 for (
int i = 0; i < m_image_height; i++) {
786 for (
int j = 0; j < m_image_width; j++) {
787 int s = (i * 3 * m_image_width) + (j * 3);
788 int d = (i * stride * m_tex_w) + (j * stride);
790 teximage[d + 0] = imgdata[s + 0];
791 teximage[d + 1] = imgdata[s + 1];
792 teximage[d + 2] = imgdata[s + 2];
793 teximage[d + 3] = 255;
797 glBindTexture(GL_TEXTURE_2D, m_texobj);
798 glEnable(GL_TEXTURE_2D);
800 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_tex_w, m_tex_h, format,
801 GL_UNSIGNED_BYTE, teximage);
804 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.
Class NotificationManager.