OpenCPN Partial API docs
Loading...
Searching...
No Matches
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
33extern OCPNPlatform *g_Platform;
34
35NMEALogWindow *NMEALogWindow::instance = NULL;
36
37NMEALogWindow &NMEALogWindow::Get() {
38 if (instance == NULL) {
39 instance = new NMEALogWindow;
40 }
41 return *instance;
42}
43
44NMEALogWindow::NMEALogWindow()
45 : window(NULL), width(0), height(0), pos_x(0), pos_y(0) {}
46
47void NMEALogWindow::Shutdown() {
48 if (instance) {
49 delete instance;
50 instance = NULL;
51 }
52}
53
54bool NMEALogWindow::Active() const { return window != NULL; }
55
56void NMEALogWindow::Create(wxWindow *parent, int num_lines) {
57 if (window == NULL) {
58 window = new TTYWindow(parent, num_lines, this);
59 window->SetTitle(_("NMEA Debug Window"));
60
61 // Make sure the window is well on the screen
62 pos_x = wxMax(pos_x, 40);
63 pos_y = wxMax(pos_y, 40);
64
65 window->SetSize(pos_x, pos_y, width, height);
66 }
67 window->Show();
68}
69
70void NMEALogWindow::Add(const wxString &s) {
71 if (window) window->Add(s);
72}
73
74void NMEALogWindow::Refresh(bool do_refresh) {
75 if (window) window->Refresh(do_refresh);
76}
77
78void NMEALogWindow::SetSize(const wxSize &size) {
79 width = size.GetWidth();
80 width = wxMax(width, 400 * g_Platform->GetDisplayDensityFactor());
81 width = wxMin(width, g_Platform->getDisplaySize().x - 20);
82 height = size.GetHeight();
83 height = wxMax(height, 300 * g_Platform->GetDisplayDensityFactor());
84 height = wxMin(height, g_Platform->getDisplaySize().y - 20);
85}
86
87void NMEALogWindow::SetPos(const wxPoint &pos) {
88 pos_x = pos.x;
89 pos_y = pos.y;
90}
91
92int NMEALogWindow::GetSizeW() {
93 UpdateGeometry();
94 return width;
95}
96
97int NMEALogWindow::GetSizeH() {
98 UpdateGeometry();
99 return height;
100}
101
102int NMEALogWindow::GetPosX() {
103 UpdateGeometry();
104 return pos_x;
105}
106
107int NMEALogWindow::GetPosY() {
108 UpdateGeometry();
109 return pos_y;
110}
111
112void NMEALogWindow::SetSize(int w, int h) {
113 width = w;
114 width = wxMax(width, 400 * g_Platform->GetDisplayDensityFactor());
115 width = wxMin(width, g_Platform->getDisplaySize().x - 20);
116
117 height = h;
118 height = wxMax(height, 300 * g_Platform->GetDisplayDensityFactor());
119 height = wxMin(height, g_Platform->getDisplaySize().y - 20);
120 // qDebug() << w << h << width << height;
121}
122
123void NMEALogWindow::SetPos(int x, int y) {
124 pos_x = x;
125 pos_y = y;
126}
127
128void NMEALogWindow::CheckPos(int display_width, int display_height) {
129 if ((pos_x < 0) || (pos_x > display_width)) pos_x = 5;
130 if ((pos_y < 0) || (pos_y > display_height)) pos_y = 5;
131}
132
133void NMEALogWindow::DestroyWindow() {
134 if (window) {
135 UpdateGeometry();
136 window->Destroy();
137 window = NULL;
138 }
139}
140
141void NMEALogWindow::Move() {
142 if (window) {
143 window->Move(pos_x, pos_y);
144 window->Raise();
145 }
146}
147
155void NMEALogWindow::UpdateGeometry() {
156 if (window) {
157 SetSize(window->GetSize());
158 SetPos(window->GetPosition());
159 }
160}
This class provides access to the NMEA log/debug window.
Definition: NMEALogWindow.h:47