OpenCPN Partial API docs
Loading...
Searching...
No Matches
instrument.h
1/***************************************************************************
2 * $Id: instrument.h, v1.0 2010/08/30 SethDart Exp $
3 *
4 * Project: OpenCPN
5 * Purpose: Dashboard Plugin
6 * Author: Jean-Eudes Onfray
7 *
8 ***************************************************************************
9 * Copyright (C) 2010 by David S. Register *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program; if not, write to the *
23 * Free Software Foundation, Inc., *
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
25 ***************************************************************************
26 */
27
28#ifndef _INSTRUMENT_H_
29#define _INSTRUMENT_H_
30
31#include "wx/wxprec.h"
32
33#ifndef WX_PRECOMP
34#include "wx/wx.h"
35#endif // precompiled headers
36
37#if !wxUSE_GRAPHICS_CONTEXT
38#define wxGCDC wxDC
39#endif
40
41// Required GetGlobalColor
42#include "../../../include/ocpn_plugin.h"
43#include <wx/dcbuffer.h>
44#include <wx/dcgraph.h> // supplemental, for Mac
45
46#include <bitset>
47#include <wx/fontdata.h>
48
49const wxString DEGREE_SIGN = wxString::Format(
50 _T("%c"), 0x00B0); // This is the degree sign in UTF8. It should be
51 // correctly handled on both Win & Unix
52#define DefaultWidth 150
53
54extern wxFontData *g_pFontTitle;
55extern wxFontData *g_pFontData;
56extern wxFontData *g_pFontLabel;
57extern wxFontData *g_pFontSmall;
58
59extern wxFontData *g_pUSFontTitle;
60extern wxFontData *g_pUSFontData;
61extern wxFontData *g_pUSFontLabel;
62extern wxFontData *g_pUSFontSmall;
63
64extern wxAlignment g_TitleAlignment;
65extern double g_TitleVerticalOffset;
66extern int g_iTitleMargin;
67extern bool g_bShowUnit;
68extern wxAlignment g_DataAlignment;
69extern int g_iDataMargin;
70extern int g_iInstrumentSpacing;
71
72wxString toSDMM(int NEflag, double a);
73
78
79enum DASH_CAP {
80 OCPN_DBP_STC_LAT = 0,
81 OCPN_DBP_STC_LON,
82 OCPN_DBP_STC_SOG,
83 OCPN_DBP_STC_COG,
84 OCPN_DBP_STC_STW,
85 OCPN_DBP_STC_HDM,
86 OCPN_DBP_STC_HDT,
87 OCPN_DBP_STC_HMV,
89 OCPN_DBP_STC_BRG,
90 OCPN_DBP_STC_AWA,
91 OCPN_DBP_STC_AWS,
92 OCPN_DBP_STC_TWA,
93 OCPN_DBP_STC_TWS,
94 OCPN_DBP_STC_DPT,
95 OCPN_DBP_STC_TMP,
96 OCPN_DBP_STC_VMG,
97 OCPN_DBP_STC_VMGW,
98 OCPN_DBP_STC_RSA,
99 OCPN_DBP_STC_SAT,
100 OCPN_DBP_STC_GPS,
101 OCPN_DBP_STC_PLA,
102 OCPN_DBP_STC_PLO,
103 OCPN_DBP_STC_CLK,
104 OCPN_DBP_STC_MON, // Does not seem to be used anywhere
105 OCPN_DBP_STC_ATMP,
106 OCPN_DBP_STC_TWD,
108 OCPN_DBP_STC_TWS2,
109 OCPN_DBP_STC_VLW1,
110 OCPN_DBP_STC_VLW2,
111 OCPN_DBP_STC_MDA,
112 OCPN_DBP_STC_MCOG,
113 OCPN_DBP_STC_PITCH,
114 OCPN_DBP_STC_HEEL,
115 OCPN_DBP_STC_ALTI,
116 OCPN_DBP_STC_HUM,
117 OCPN_DBP_STC_WCC,
118 // Insert new instrument capability flags here
119 OCPN_DBP_STC_LAST // This should always be the last enum in this list
120};
121
122#define N_INSTRUMENTS \
123 ((int)OCPN_DBP_STC_LAST) // Number of instrument capability flags
124using CapType = std::bitset<N_INSTRUMENTS>;
125
126wxColour GetColourSchemeBackgroundColour(wxColour co);
127wxColour GetColourSchemeFont(wxColour co);
128
130public:
131 InstrumentProperties() { SetDefault(); }
132 InstrumentProperties(int aInstrument, int Listplace) {
133 m_aInstrument = aInstrument;
134 m_Listplace = Listplace;
135 m_ShowUnit = -1;
136 m_DataAlignment = wxALIGN_INVALID;
137 m_DataMargin = -1;
138 m_InstrumentSpacing = -1;
139 m_Format = "";
140 m_Title = "";
141 m_TitleFont = *(g_pFontTitle);
142 m_USTitleFont = *(g_pUSFontTitle);
143 m_DataFont = *(g_pFontData);
144 m_USDataFont = *(g_pUSFontData);
145 m_LabelFont = *(g_pFontLabel);
146 m_USLabelFont = *(g_pUSFontLabel);
147 m_SmallFont = *(g_pFontSmall);
148 m_USSmallFont = *(g_pUSFontSmall);
149 GetGlobalColor(_T("DASHL"), &m_TitleBackgroundColour);
150 GetGlobalColor(_T("DASHB"), &m_DataBackgroundColour);
151 GetGlobalColor(_T("DASHN"), &m_Arrow_First_Colour);
152 GetGlobalColor(_T("BLUE3"), &m_Arrow_Second_Colour);
153 }
155 void SetDefault() {
156 m_aInstrument = -1;
157 m_Listplace = -1;
158 m_ShowUnit = -1;
159 m_DataAlignment = wxALIGN_INVALID;
160 m_DataMargin = -1;
161 m_InstrumentSpacing = -1;
162 m_Format = "";
163 m_Title = "";
164 m_TitleFont = *(g_pFontTitle);
165 m_USTitleFont = *(g_pUSFontTitle);
166 m_DataFont = *(g_pFontData);
167 m_USDataFont = *(g_pUSFontData);
168 m_LabelFont = *(g_pFontLabel);
169 m_USLabelFont = *(g_pUSFontLabel);
170 m_SmallFont = *(g_pFontSmall);
171 m_USSmallFont = *(g_pUSFontSmall);
172 GetGlobalColor(_T("DASHL"), &m_TitleBackgroundColour);
173 GetGlobalColor(_T("DASHB"), &m_DataBackgroundColour);
174 GetGlobalColor(_T("DASHN"), &m_Arrow_First_Colour);
175 GetGlobalColor(_T("BLUE3"), &m_Arrow_Second_Colour);
176 };
177 int m_aInstrument;
178 int m_Listplace;
179 int m_ShowUnit;
180 wxAlignment m_DataAlignment;
181 int m_DataMargin;
182 int m_InstrumentSpacing;
183 wxString m_Format;
184 wxString m_Title;
185 wxFontData m_TitleFont;
186 wxFontData m_USTitleFont;
187 wxColour m_TitleBackgroundColour;
188 wxFontData m_DataFont;
189 wxFontData m_USDataFont;
190 wxColour m_DataBackgroundColour;
191 wxFontData m_LabelFont;
192 wxFontData m_USLabelFont;
193 wxFontData m_SmallFont;
194 wxFontData m_USSmallFont;
195 wxColour m_Arrow_First_Colour;
196 wxColour m_Arrow_Second_Colour;
197};
198
199class DashboardInstrument : public wxControl {
200public:
201 DashboardInstrument(wxWindow *pparent, wxWindowID id, wxString title,
202 DASH_CAP cap_flag,
203 InstrumentProperties *Properties = NULL);
205
206 CapType GetCapacity();
207 void OnEraseBackground(wxEraseEvent &WXUNUSED(evt));
208 virtual wxSize GetSize(int orient, wxSize hint) = 0;
209 void OnPaint(wxPaintEvent &WXUNUSED(event));
210 virtual void SetData(DASH_CAP st, double data, wxString unit) = 0;
211 void SetDrawSoloInPane(bool value);
212 void MouseEvent(wxMouseEvent &event);
213#ifdef HAVE_WX_GESTURE_EVENTS
214 void OnLongPress(wxLongPressEvent &event);
215#endif
216 void OnLeftUp(wxMouseEvent &event);
217 void SetCapFlag(DASH_CAP val) { m_cap_flag.set(val); }
218 bool HasCapFlag(DASH_CAP val) { return m_cap_flag.test(val); }
219 int instrumentTypeId;
220 InstrumentProperties *m_Properties;
221
222protected:
223 CapType m_cap_flag;
224 int m_InstrumentSpacing;
225 int m_DataTextHeight;
226 int m_DataMargin;
227 int m_TitleWidth;
228 int m_TitleHeight;
229 int m_DataTop;
230 int m_TitleTop;
231 bool m_DataRightAlign;
232 bool m_TitleRightAlign;
233 wxString m_title;
234 virtual void Draw(wxGCDC *dc) = 0;
235 virtual void InitDataTextHeight(const wxString &sampleText, int &sampleWidth);
236 virtual void InitTitleSize();
237 virtual void InitTitleAndDataPosition(int drawHeight);
238 virtual int GetFullHeight(int drawHeight);
239 virtual int GetDataBottom(int clientHeight);
240 virtual void SetDataFont(wxGCDC *dc);
241
242private:
243 bool m_drawSoloInPane;
244 bool m_popupWanted;
245};
246
248public:
249 DashboardInstrument_Single(wxWindow *pparent, wxWindowID id, wxString title,
250 InstrumentProperties *Properties, DASH_CAP cap,
251 wxString format);
253
254 wxSize GetSize(int orient, wxSize hint);
255 void SetData(DASH_CAP st, double data, wxString unit);
256
257protected:
258 wxString m_data;
259 wxString m_format;
260 // int m_DataHeight;
261 // InstrumentProperties* m_Properties;
262
263 void Draw(wxGCDC *dc);
264};
265
267public:
268 DashboardInstrument_Position(wxWindow *pparent, wxWindowID id, wxString title,
269 InstrumentProperties *Properties = NULL,
270 DASH_CAP cap_flag1 = OCPN_DBP_STC_LAT,
271 DASH_CAP cap_flag2 = OCPN_DBP_STC_LON);
273
274 wxSize GetSize(int orient, wxSize hint);
275 void SetData(DASH_CAP st, double data, wxString unit);
276
277protected:
278 wxString m_data1;
279 wxString m_data2;
280 DASH_CAP m_cap_flag1;
281 DASH_CAP m_cap_flag2;
282 // int m_DataHeight;
283
284 void Draw(wxGCDC *dc);
285};
286
287#endif
A dashboard instrument that displays sunrise and sunset times.
Definition clock.h:103