OpenCPN Partial API docs
Loading...
Searching...
No Matches
instrument.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2010 by Jean-Eudes Onfray *
3 * Copyright (C) 2010 by David S. Register *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#ifndef InSTRUMENT_H_
26#define InSTRUMENT_H_
27
28#include <bitset>
29
30#include <wx/wxprec.h>
31
32#ifndef WX_PRECOMP
33#include <wx/wx.h>
34#endif
35
36#if !wxUSE_GRAPHICS_CONTEXT
37#define wxGCDC wxDC
38#endif
39
40// Required GetGlobalColor
41#include <wx/dcbuffer.h>
42#include <wx/dcgraph.h> // supplemental, for Mac
43#include <wx/fontdata.h>
44
45#include "ocpn_plugin.h"
46
47#define DefaultWidth 150
48
49// The degree sign in UTF8, should be correctly handled on both Win & Unix.
50const wxString DEGREE_SIGN = wxString::Format("%c", 0x00B0);
51
52extern wxFontData *g_pFontTitle;
53extern wxFontData *g_pFontData;
54extern wxFontData *g_pFontLabel;
55extern wxFontData *g_pFontSmall;
56
57extern wxFontData *g_pUSFontTitle;
58extern wxFontData *g_pUSFontData;
59extern wxFontData *g_pUSFontLabel;
60extern wxFontData *g_pUSFontSmall;
61
62extern wxAlignment g_TitleAlignment;
63extern double g_TitleVerticalOffset;
64extern int g_iTitleMargin;
65extern bool g_bShowUnit;
66extern wxAlignment g_DataAlignment;
67extern int g_iDataMargin;
68extern int g_iInstrumentSpacing;
69
70wxString toSDMM(int NEflag, double a);
71
76
119
120#define N_INSTRUMENTS \
121 ((int)OCPN_DBP_STC_LAST) // Number of instrument capability flags
122
123using CapType = std::bitset<N_INSTRUMENTS>;
124
125wxColour GetColourSchemeBackgroundColour(wxColour co);
126wxColour GetColourSchemeFont(wxColour co);
127
129public:
130 InstrumentProperties() { SetDefault(); }
131 InstrumentProperties(int aInstrument, int Listplace) {
132 m_aInstrument = aInstrument;
133 m_Listplace = Listplace;
134 m_ShowUnit = -1;
135 m_DataAlignment = wxALIGN_INVALID;
136 m_DataMargin = -1;
137 m_InstrumentSpacing = -1;
138 m_Format = "";
139 m_Title = "";
140 m_TitleFont = *(g_pFontTitle);
141 m_USTitleFont = *(g_pUSFontTitle);
142 m_DataFont = *(g_pFontData);
143 m_USDataFont = *(g_pUSFontData);
144 m_LabelFont = *(g_pFontLabel);
145 m_USLabelFont = *(g_pUSFontLabel);
146 m_SmallFont = *(g_pFontSmall);
147 m_USSmallFont = *(g_pUSFontSmall);
148 GetGlobalColor("DASHL", &m_TitleBackgroundColour);
149 GetGlobalColor("DASHB", &m_DataBackgroundColour);
150 GetGlobalColor("DASHN", &m_Arrow_First_Colour);
151 GetGlobalColor("BLUE3", &m_Arrow_Second_Colour);
152 }
153
154 ~InstrumentProperties() = default;
155
156 void SetDefault() {
157 m_aInstrument = -1;
158 m_Listplace = -1;
159 m_ShowUnit = -1;
160 m_DataAlignment = wxALIGN_INVALID;
161 m_DataMargin = -1;
162 m_InstrumentSpacing = -1;
163 m_Format = "";
164 m_Title = "";
165 m_TitleFont = *(g_pFontTitle);
166 m_USTitleFont = *(g_pUSFontTitle);
167 m_DataFont = *(g_pFontData);
168 m_USDataFont = *(g_pUSFontData);
169 m_LabelFont = *(g_pFontLabel);
170 m_USLabelFont = *(g_pUSFontLabel);
171 m_SmallFont = *(g_pFontSmall);
172 m_USSmallFont = *(g_pUSFontSmall);
173 GetGlobalColor("DASHL", &m_TitleBackgroundColour);
174 GetGlobalColor("DASHB", &m_DataBackgroundColour);
175 GetGlobalColor("DASHN", &m_Arrow_First_Colour);
176 GetGlobalColor("BLUE3", &m_Arrow_Second_Colour);
177 };
178 int m_aInstrument;
179 int m_Listplace;
180 int m_ShowUnit;
181 wxAlignment m_DataAlignment;
182 int m_DataMargin;
183 int m_InstrumentSpacing;
184 wxString m_Format;
185 wxString m_Title;
186 wxFontData m_TitleFont;
187 wxFontData m_USTitleFont;
188 wxColour m_TitleBackgroundColour;
189 wxFontData m_DataFont;
190 wxFontData m_USDataFont;
191 wxColour m_DataBackgroundColour;
192 wxFontData m_LabelFont;
193 wxFontData m_USLabelFont;
194 wxFontData m_SmallFont;
195 wxFontData m_USSmallFont;
196 wxColour m_Arrow_First_Colour;
197 wxColour m_Arrow_Second_Colour;
198};
199
200class DashboardInstrument : public wxControl {
201public:
202 DashboardInstrument(wxWindow *pparent, wxWindowID id, wxString title,
203 DASH_CAP cap_flag,
204 InstrumentProperties *Properties = nullptr);
205 ~DashboardInstrument() override = default;
206
207 CapType GetCapacity();
208 void OnEraseBackground(wxEraseEvent &WXUNUSED(evt));
209 virtual wxSize GetSize(int orient, wxSize hint) = 0;
210 void OnPaint(wxPaintEvent &WXUNUSED(event));
211 virtual void SetData(DASH_CAP st, double data, wxString unit) = 0;
212 void SetDrawSoloInPane(bool value);
213 void MouseEvent(wxMouseEvent &event);
214#ifdef HAVE_WX_GESTURE_EVENTS
215 void OnLongPress(wxLongPressEvent &event);
216#endif
217 void OnLeftUp(wxMouseEvent &event);
218 void SetCapFlag(DASH_CAP val) { m_cap_flag.set(val); }
219 bool HasCapFlag(DASH_CAP val) { return m_cap_flag.test(val); }
220 int instrumentTypeId;
221 InstrumentProperties *m_Properties;
222
223protected:
224 CapType m_cap_flag;
225 int m_InstrumentSpacing;
226 int m_DataTextHeight;
227 int m_DataMargin;
228 int m_TitleWidth;
229 int m_TitleHeight;
230 int m_DataTop;
231 int m_TitleTop;
232 bool m_DataRightAlign;
233 bool m_TitleRightAlign;
234 wxString m_title;
235 virtual void Draw(wxGCDC *dc) = 0;
236 virtual void InitDataTextHeight(const wxString &sampleText, int &sampleWidth);
237 virtual void InitTitleSize();
238 virtual void InitTitleAndDataPosition(int drawHeight);
239 virtual int GetFullHeight(int drawHeight);
240 virtual int GetDataBottom(int clientHeight);
241 virtual void SetDataFont(wxGCDC *dc);
242
243private:
244 bool m_drawSoloInPane;
245 bool m_popupWanted;
246};
247
249public:
250 DashboardInstrument_Single(wxWindow *pparent, wxWindowID id, wxString title,
251 InstrumentProperties *Properties, DASH_CAP cap,
252 wxString format);
253 ~DashboardInstrument_Single() override = default;
254
255 wxSize GetSize(int orient, wxSize hint) override;
256 void SetData(DASH_CAP st, double data, wxString unit) override;
257
258protected:
259 wxString m_data;
260 wxString m_format;
261 // int m_DataHeight;
262 // InstrumentProperties* m_Properties;
263
264 void Draw(wxGCDC *dc) override;
265};
266
268public:
269 DashboardInstrument_Position(wxWindow *pparent, wxWindowID id, wxString title,
270 InstrumentProperties *Properties = nullptr,
271 DASH_CAP cap_flag1 = OCPN_DBP_STC_LAT,
272 DASH_CAP cap_flag2 = OCPN_DBP_STC_LON);
273 ~DashboardInstrument_Position() override = default;
274
275 wxSize GetSize(int orient, wxSize hint) override;
276 void SetData(DASH_CAP st, double data, wxString unit) override;
277
278protected:
279 wxString m_data1;
280 wxString m_data2;
281 DASH_CAP m_cap_flag1;
282 DASH_CAP m_cap_flag2;
283 // int m_DataHeight;
284
285 void Draw(wxGCDC *dc) override;
286};
287
288#endif // InSTRUMENT_H_
A dashboard instrument that displays sunrise and sunset times.
Definition clock.h:99
DASH_CAP
Definition instrument.h:77
@ OCPN_DBP_STC_VLW1
Trip Log.
Definition instrument.h:107
@ OCPN_DBP_STC_AWA
Apparent wind angle.
Definition instrument.h:88
@ OCPN_DBP_STC_PITCH
Pitch.
Definition instrument.h:111
@ OCPN_DBP_STC_RSA
Rudder angle.
Definition instrument.h:96
@ OCPN_DBP_STC_AWS
Apparent wind speed.
Definition instrument.h:89
@ OCPN_DBP_STC_STW
Speed through water.
Definition instrument.h:82
@ OCPN_DBP_STC_HEEL
Heel.
Definition instrument.h:112
@ OCPN_DBP_STC_VMGW
Velocity made good to windward.
Definition instrument.h:95
@ OCPN_DBP_STC_PLA
Cursor latitude.
Definition instrument.h:99
@ OCPN_DBP_STC_SAT
Satellite count in use.
Definition instrument.h:97
@ OCPN_DBP_STC_BRG
Bearing.
Definition instrument.h:87
@ OCPN_DBP_STC_HDT
Heading true North.
Definition instrument.h:84
@ OCPN_DBP_STC_VMG
Velocity made good.
Definition instrument.h:94
@ OCPN_DBP_STC_TWS2
True Wind Speed, same calculation as TWS.
Definition instrument.h:106
@ OCPN_DBP_STC_ALTI
Altitude.
Definition instrument.h:113
@ OCPN_DBP_STC_GPS
GPS status.
Definition instrument.h:98
@ OCPN_DBP_STC_HDM
Heading magnetic North.
Definition instrument.h:83
@ OCPN_DBP_STC_TWA
True wind angle.
Definition instrument.h:90
@ OCPN_DBP_STC_SOG
Speed over ground.
Definition instrument.h:80
@ OCPN_DBP_STC_VLW2
Sum Log.
Definition instrument.h:108
@ OCPN_DBP_STC_LON
Longitude.
Definition instrument.h:79
@ OCPN_DBP_STC_MCOG
Magnetic Course over Ground.
Definition instrument.h:110
@ OCPN_DBP_STC_PLO
Cursor longitude.
Definition instrument.h:100
@ OCPN_DBP_STC_HMV
Magnetic variation from NMEA device if available (not from WMM)
Definition instrument.h:85
@ OCPN_DBP_STC_ATMP
Air Temperature.
Definition instrument.h:103
@ OCPN_DBP_STC_MDA
Barometic pressure.
Definition instrument.h:109
@ OCPN_DBP_STC_DPT
Depth.
Definition instrument.h:92
@ OCPN_DBP_STC_COG
Course over ground.
Definition instrument.h:81
@ OCPN_DBP_STC_TWD
True Wind Direction (from NMEA device if available, otherwise TWA + magnetic variation)
Definition instrument.h:104
@ OCPN_DBP_STC_TWS
True wind speed.
Definition instrument.h:91
@ OCPN_DBP_STC_TMP
Water temperature.
Definition instrument.h:93
@ OCPN_DBP_STC_CLK
Clock.
Definition instrument.h:101
@ OCPN_DBP_STC_HUM
Humidity.
Definition instrument.h:114
@ OCPN_DBP_STC_WCC
Windlass.
Definition instrument.h:115
@ OCPN_DBP_STC_LAT
Latitude.
Definition instrument.h:78
PlugIn Object Definition/API.