25#include <wx/artprov.h>
28#include <wx/statbmp.h>
33#include "OCPNPlatform.h"
38#include "androidUTIL.h"
44extern int g_GUIScaleFactor;
46CopyableText::CopyableText(wxWindow* parent,
const char* text)
47 : wxTextCtrl(parent, wxID_ANY, text, wxDefaultPosition, wxDefaultSize,
50 wxStaticText tmp(parent, wxID_ANY, text);
51 SetBackgroundColour(tmp.GetBackgroundColour());
55 wxFont* dFont = FontMgr::Get().
GetFont(item, default_size);
56 int req_size = dFont->GetPointSize();
60 double scaled_font_size = dFont->GetPointSize();
63 double points_per_mm =
64 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
65 double min_scaled_font_size =
67 int nscaled_font_size =
68 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
70 if (req_size >= nscaled_font_size)
74 nscaled_font_size, dFont->GetFamily(), dFont->GetStyle(),
84 wxFont* dFont = FontMgr::Get().
GetFont(item, 0);
85 int req_size = dFont->GetPointSize();
86 wxFont qFont = *dFont;
89 double postmult = exp(g_GUIScaleFactor * (0.693 / 5.0));
90 double scaled_font_size = dFont->GetPointSize() * postmult;
92 double points_per_mm =
93 g_Platform->getFontPointsperPixel() * g_Platform->GetDisplayDPmm();
94 double min_scaled_font_size =
96 int nscaled_font_size =
97 wxMax(wxRound(scaled_font_size), min_scaled_font_size);
104 qFont.SetPointSize(nscaled_font_size);
110int OCPNMessageBox(wxWindow* parent,
const wxString& message,
111 const wxString& caption,
int style,
int timeout_sec,
int x,
113#ifdef __OCPN__ANDROID__
114 androidDisableRotation();
115 int style_mod = style;
117 auto dlg =
new wxMessageDialog(parent, message, caption, style_mod);
118 int ret = dlg->ShowModal();
119 qDebug() <<
"OCPNMB-1 ret" << ret;
124 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
128 androidEnableRotation();
129 qDebug() <<
"OCPNMB-2 ret" << ret;
137 ret = tbox.GetRetVal();
144EVT_BUTTON(wxID_YES, OCPNMessageDialog::OnYes)
145EVT_BUTTON(wxID_NO, OCPNMessageDialog::OnNo)
146EVT_BUTTON(wxID_CANCEL, OCPNMessageDialog::OnCancel)
147EVT_CLOSE(OCPNMessageDialog::OnClose)
151 const wxString& caption,
long style,
153 : wxDialog(parent, wxID_ANY, caption, pos, wxDefaultSize,
154 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP) {
159 wxBoxSizer* topsizer =
new wxBoxSizer(wxVERTICAL);
161 wxBoxSizer* icon_text =
new wxBoxSizer(wxHORIZONTAL);
165 if (style & wxICON_MASK) {
167 switch (style & wxICON_MASK) {
169 wxFAIL_MSG(_T(
"incorrect log style"));
173 bitmap = wxArtProvider::GetIcon(wxART_ERROR, wxART_MESSAGE_BOX);
176 case wxICON_INFORMATION:
177 bitmap = wxArtProvider::GetIcon(wxART_INFORMATION, wxART_MESSAGE_BOX);
181 bitmap = wxArtProvider::GetIcon(wxART_WARNING, wxART_MESSAGE_BOX);
184 case wxICON_QUESTION:
185 bitmap = wxArtProvider::GetIcon(wxART_QUESTION, wxART_MESSAGE_BOX);
188 wxStaticBitmap* icon =
new wxStaticBitmap(
this, wxID_ANY, bitmap);
189 icon_text->Add(icon, 0, wxCENTER);
195 icon_text->Add(CreateTextSizer(message), 0, wxALIGN_CENTER | wxLEFT, 10);
197 topsizer->Add(icon_text, 1, wxCENTER | wxLEFT | wxRIGHT | wxTOP, 10);
201 int AllButtonSizerFlags =
202 wxOK | wxCANCEL | wxYES | wxNO | wxHELP | wxNO_DEFAULT;
203 int center_flag = wxEXPAND;
204 if (style & wxYES_NO) center_flag = wxALIGN_CENTRE;
205 wxSizer* sizerBtn = CreateSeparatedButtonSizer(style & AllButtonSizerFlags);
206 if (sizerBtn) topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10);
211 topsizer->SetSizeHints(
this);
213 wxSize size(GetSize());
214 if (size.x < size.y * 3 / 2) {
215 size.x = size.y * 3 / 2;
219 Centre(wxBOTH | wxCENTER_FRAME);
222void OCPNMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) {
223 SetReturnCode(wxID_YES);
227void OCPNMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) {
228 SetReturnCode(wxID_NO);
232void OCPNMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) {
235 if ((m_style & wxYES_NO) != wxYES_NO || (m_style & wxCANCEL)) {
236 SetReturnCode(wxID_CANCEL);
237 EndModal(wxID_CANCEL);
241void OCPNMessageDialog::OnClose(wxCloseEvent& event) {
242 SetReturnCode(wxID_CANCEL);
243 EndModal(wxID_CANCEL);
247EVT_TIMER(-1, TimedMessageBox::OnTimer)
251 const wxString& caption,
long style,
252 int timeout_sec, const wxPoint& pos) {
254 m_timer.SetOwner(
this, -1);
256 if (timeout_sec > 0) m_timer.Start(timeout_sec * 1000, wxTIMER_ONE_SHOT);
261 int ret = dlg->GetReturnCode();
264 if (((style & wxYES_NO) == wxYES_NO) && (ret == wxID_OK)) ret = wxID_YES;
272TimedMessageBox::~TimedMessageBox() {}
274void TimedMessageBox::OnTimer(wxTimerEvent& evt) {
275 if (dlg) dlg->EndModal(wxID_CANCEL);
280EVT_PAINT(TimedPopupWin::OnPaint)
281EVT_TIMER(POPUP_TIMER, TimedPopupWin::OnTimer)
287 : wxWindow(parent, wxID_ANY, wxPoint(0, 0), wxSize(1, 1), wxNO_BORDER) {
290 m_timer_timeout.SetOwner(
this, POPUP_TIMER);
291 m_timeout_sec = timeout;
296TimedPopupWin::~TimedPopupWin() {
delete m_pbm; }
297void TimedPopupWin::OnTimer(wxTimerEvent& event) {
298 if (IsShown()) Hide();
301void TimedPopupWin::SetBitmap(wxBitmap& bmp) {
303 m_pbm =
new wxBitmap(bmp);
306 if (m_timeout_sec > 0)
307 m_timer_timeout.Start(m_timeout_sec * 1000, wxTIMER_ONE_SHOT);
310void TimedPopupWin::OnPaint(wxPaintEvent& event) {
312 GetClientSize(&width, &height);
316 mdc.SelectObject(*m_pbm);
317 dc.Blit(0, 0, width, height, &mdc, 0, 0);
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.
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.