25#include <wx/artprov.h>
28#include <wx/statbmp.h>
29#include <wx/statline.h>
35#include "OCPNPlatform.h"
40#include "androidUTIL.h"
46extern int g_GUIScaleFactor;
48CopyableText::CopyableText(wxWindow* parent,
const char* text)
49 : wxTextCtrl(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize,
52 wxStaticText tmp(parent, wxID_ANY, text);
53 SetBackgroundColour(tmp.GetBackgroundColour());
57 wxFont* dFont = FontMgr::Get().
GetFont(item, default_size);
58 int req_size = dFont->GetPointSize();
62 double scaled_font_size = dFont->GetPointSize();
65 double points_per_mm =
66 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
67 double min_scaled_font_size =
69 int nscaled_font_size =
70 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
72 if (req_size >= nscaled_font_size)
76 nscaled_font_size, dFont->GetFamily(), dFont->GetStyle(),
86 wxFont* dFont = FontMgr::Get().
GetFont(item, 0);
87 int req_size = dFont->GetPointSize();
88 wxFont qFont = *dFont;
91 double postmult = exp(g_GUIScaleFactor * (0.693 / 5.0));
92 double scaled_font_size = dFont->GetPointSize() * postmult;
94 double points_per_mm =
95 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
96 double min_scaled_font_size =
98 int nscaled_font_size =
99 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
106 qFont.SetPointSize(nscaled_font_size);
112int OCPNMessageBox(wxWindow* parent,
const wxString& message,
113 const wxString& caption,
int style,
int timeout_sec,
int x,
115#ifdef __OCPN__ANDROID__
116 androidDisableRotation();
117 int style_mod = style;
119 auto dlg =
new wxMessageDialog(parent, message, caption, style_mod);
120 int ret = dlg->ShowModal();
121 qDebug() <<
"OCPNMB-1 ret" << ret;
126 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
130 androidEnableRotation();
131 qDebug() <<
"OCPNMB-2 ret" << ret;
139 ret = tbox.GetRetVal();
146EVT_BUTTON(wxID_YES, OCPNMessageDialog::OnYes)
147EVT_BUTTON(wxID_NO, OCPNMessageDialog::OnNo)
148EVT_BUTTON(wxID_CANCEL, OCPNMessageDialog::OnCancel)
149EVT_CLOSE(OCPNMessageDialog::OnClose)
153 const wxString& caption,
long style,
155 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
156 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) {
161 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
163 wxBoxSizer* icon_text =
new wxBoxSizer(wxHORIZONTAL);
167 if (style & wxICON_MASK) {
169 switch (style & wxICON_MASK) {
171 wxFAIL_MSG(_T(
"incorrect log style"));
175 bitmap = wxArtProvider::GetIcon(wxART_ERROR, wxART_MESSAGE_BOX);
178 case wxICON_INFORMATION:
179 bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_MESSAGE_BOX);
183 bitmap = wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX);
186 case wxICON_QUESTION:
187 bitmap = wxArtProvider::GetIcon(wxART_QUESTION, wxART_MESSAGE_BOX);
190 wxStaticBitmap* icon =
new wxStaticBitmap(
this, wxID_ANY, bitmap);
191 icon_text->Add(icon, 0, wxCENTER);
197 icon_text->Add(CreateTextSizer(message), 0, wxALIGN_CENTER | wxLEFT, 10);
199 topsizer->Add(icon_text, 1, wxCENTER | wxLEFT | wxRIGHT | wxTOP, 10);
203 int AllButtonSizerFlags =
204 wxOK | wxCANCEL | wxYES | wxNO | wxHELP | wxNO_DEFAULT;
205 int center_flag = wxEXPAND;
206 if (style & wxYES_NO) center_flag = wxALIGN_CENTRE;
207 wxSizer* sizerBtn = CreateSeparatedButtonSizer(style & AllButtonSizerFlags);
208 if (sizerBtn) topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10);
213 topsizer->SetSizeHints(
this);
215 wxSize size(GetSize());
216 if (size.x < size.y * 3 / 2) {
217 size.x = size.y * 3 / 2;
221 Centre(wxBOTH | wxCENTER_FRAME);
224void OCPNMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) {
225 SetReturnCode(wxID_YES);
229void OCPNMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) {
230 SetReturnCode(wxID_NO);
234void OCPNMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) {
237 if ((m_style & wxYES_NO) != wxYES_NO || (m_style & wxCANCEL)) {
238 SetReturnCode(wxID_CANCEL);
239 EndModal(wxID_CANCEL);
243void OCPNMessageDialog::OnClose(wxCloseEvent& event) {
244 SetReturnCode(wxID_CANCEL);
245 EndModal(wxID_CANCEL);
249EVT_TIMER(-1, TimedMessageBox::OnTimer)
253 const wxString& caption,
long style,
254 int timeout_sec, const wxPoint& pos) {
256 m_timer.SetOwner(
this, -1);
258 if (timeout_sec > 0) m_timer.Start(timeout_sec * 1000, wxTIMER_ONE_SHOT);
263 int ret = dlg->GetReturnCode();
266 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
274TimedMessageBox::~TimedMessageBox() {}
276void TimedMessageBox::OnTimer(wxTimerEvent& evt) {
277 if (dlg) dlg->EndModal(wxID_CANCEL);
282EVT_PAINT(TimedPopupWin::OnPaint)
283EVT_TIMER(POPUP_TIMER, TimedPopupWin::OnTimer)
289 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER) {
292 m_timer_timeout.SetOwner(
this, POPUP_TIMER);
293 m_timeout_sec = timeout;
298TimedPopupWin::~TimedPopupWin() {
delete m_pbm; }
299void TimedPopupWin::OnTimer(wxTimerEvent& event) {
300 if (IsShown()) Hide();
303void TimedPopupWin::SetBitmap(wxBitmap& bmp) {
305 m_pbm =
new wxBitmap(bmp);
308 if (m_timeout_sec > 0)
309 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
312void TimedPopupWin::OnPaint(wxPaintEvent& event) {
314 GetClientSize(&width, &height);
318 mdc.SelectObject(*m_pbm);
319 dc.Blit(0, 0, width, height, &mdc, 0, 0);
324 explicit InfoFrame(wxWindow* parent,
const char* header,
const char* info)
325 : wxFrame(parent, wxID_ANY, info) {
326 auto flags = wxSizerFlags().Expand();
327 auto vbox =
new wxBoxSizer(wxVERTICAL);
328 vbox->Add(
new wxStaticText(
this, wxID_ANY, info), flags.Border());
329 vbox->Add(
new wxStaticLine(
this, wxID_ANY), flags);
330 auto button_sizer =
new wxStdDialogButtonSizer();
331 auto ok_btn =
new wxButton(
this, wxID_OK);
332 ok_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED,
333 [&](wxCommandEvent&) { Hide(); });
334 button_sizer->SetAffirmativeButton(ok_btn);
335 vbox->Add(button_sizer, flags.Border());
336 button_sizer->Realize();
343InfoButton::InfoButton(wxWindow* parent,
bool touch,
const char* header,
345 : wxButton(parent, wxID_ANY,
"", wxDefaultPosition, wxDefaultSize,
346 wxBU_EXACTFIT | wxBORDER_NONE),
347 m_icon(parent,
"help-info.svg",
348 GuiEvents::GetInstance().color_scheme_change, touch),
349 m_info_frame(new
InfoFrame(parent, header, info)) {
350 SetBitmap(m_icon.GetBitmap());
351 Bind(wxEVT_COMMAND_BUTTON_CLICKED, [&](wxCommandEvent&) {
353 m_info_frame->Show();
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.
EventVar exchange point, a singleton.
Misc GUI event vars, a singleton.
bool g_bresponsive
Flag to control adaptive UI scaling.
wxFont * GetOCPNScaledFont(wxString item, int default_size)
Retrieves a font from FontMgr, optionally scaled for physical readability.
wxFont GetOCPNGUIScaledFont(wxString item)
Retrieves a font optimized for touch and high-resolution interfaces.
General purpose GUI support.
PlugIn Object Definition/API.