OpenCPN Partial API docs
NMEALogWindow.cpp
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  *
5  ***************************************************************************
6  * Copyright (C) 2013 by David S. Register *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22  ***************************************************************************
23  */
24 
25 #include "NMEALogWindow.h"
26 #include "TTYWindow.h"
27 #include "OCPNPlatform.h"
28 
29 #ifdef __OCPN__ANDROID__
30 #include "qdebug.h"
31 #endif
32 
33 extern OCPNPlatform *g_Platform;
34 
35 NMEALogWindow *NMEALogWindow::instance = NULL;
36 
37 NMEALogWindow &NMEALogWindow::GetInstance() {
38  if (instance == NULL) {
39  instance = new NMEALogWindow;
40  }
41  return *instance;
42 }
43 
44 NMEALogWindow::NMEALogWindow()
45  : m_window(NULL), m_width(0), m_height(0), m_pos_x(0), m_pos_y(0) {}
46 
47 void NMEALogWindow::Shutdown() {
48  if (instance) {
49  delete instance;
50  instance = NULL;
51  }
52 }
53 
54 bool NMEALogWindow::Active() const { return m_window != NULL; }
55 
56 void NMEALogWindow::Create(wxWindow *parent, int num_lines) {
57  if (m_window == NULL) {
58  m_window = new TTYWindow(parent, num_lines, this);
59  m_window->SetTitle(_("NMEA Debug Window"));
60 
61  // Make sure the window is well on the screen
62  m_pos_x = wxMax(m_pos_x, 40);
63  m_pos_y = wxMax(m_pos_y, 40);
64 
65  m_window->SetSize(m_pos_x, m_pos_y, m_width, m_height);
66  }
67  m_window->Show();
68 }
69 
70 void NMEALogWindow::Add(const wxString &s) {
71  if (m_window) m_window->Add(s);
72 }
73 
74 void NMEALogWindow::Refresh(bool do_refresh) {
75  if (m_window) m_window->Refresh(do_refresh);
76 }
77 
78 void NMEALogWindow::SetSize(const wxSize &size) {
79  m_width = size.GetWidth();
80  m_width = wxMax(m_width, 400 * g_Platform->GetDisplayDensityFactor());
81  m_width = wxMin(m_width, g_Platform->getDisplaySize().x - 20);
82  m_height = size.GetHeight();
83  m_height = wxMax(m_height, 300 * g_Platform->GetDisplayDensityFactor());
84  m_height = wxMin(m_height, g_Platform->getDisplaySize().y - 20);
85 }
86 
87 void NMEALogWindow::SetPos(const wxPoint &pos) {
88  m_pos_x = pos.x;
89  m_pos_y = pos.y;
90 }
91 
92 int NMEALogWindow::GetSizeW() {
93  UpdateGeometry();
94  return m_width;
95 }
96 
97 int NMEALogWindow::GetSizeH() {
98  UpdateGeometry();
99  return m_height;
100 }
101 
102 int NMEALogWindow::GetPosX() {
103  UpdateGeometry();
104  return m_pos_x;
105 }
106 
107 int NMEALogWindow::GetPosY() {
108  UpdateGeometry();
109  return m_pos_y;
110 }
111 
112 void NMEALogWindow::SetSize(int w, int h) {
113  m_width = w;
114  m_width = wxMax(m_width, 400 * g_Platform->GetDisplayDensityFactor());
115  m_width = wxMin(m_width, g_Platform->getDisplaySize().x - 20);
116 
117  m_height = h;
118  m_height = wxMax(m_height, 300 * g_Platform->GetDisplayDensityFactor());
119  m_height = wxMin(m_height, g_Platform->getDisplaySize().y - 20);
120  // qDebug() << w << h << width << height;
121 }
122 
123 void NMEALogWindow::SetPos(int x, int y) {
124  m_pos_x = x;
125  m_pos_y = y;
126 }
127 
128 void NMEALogWindow::CheckPos(int display_width, int display_height) {
129  if ((m_pos_x < 0) || (m_pos_x > display_width)) m_pos_x = 5;
130  if ((m_pos_y < 0) || (m_pos_y > display_height)) m_pos_y = 5;
131 }
132 
133 void NMEALogWindow::DestroyWindow() {
134  if (m_window) {
135  UpdateGeometry();
136  m_window->Destroy();
137  m_window = NULL;
138  }
139 }
140 
141 void NMEALogWindow::Move() {
142  if (m_window) {
143  m_window->Move(m_pos_x, m_pos_y);
144  m_window->Raise();
145  }
146 }
147 
155 void NMEALogWindow::UpdateGeometry() {
156  if (m_window) {
157  SetSize(m_window->GetSize());
158  SetPos(m_window->GetPosition());
159  }
160 }
This class provides access to the NMEA log/debug window.
Definition: NMEALogWindow.h:48
bool Active() const
Return true if log is visible i.
void Add(const wxString &s)
Add an formatted string to log output.