35#include "iENCToolbar.h"
40#include "pluginmanager.h"
41#include "OCPNPlatform.h"
44#include "ocpn_frame.h"
46extern s52plib *ps52plib;
54iENCToolbar::iENCToolbar(wxWindow *parent, wxPoint position,
long orient,
59 wxSize a = m_bmMinimum.GetSize();
60 m_ptoolbar->SetToolBitmapSize(a);
62 m_pbmScratch =
new wxBitmap(a.x, a.y);
64 m_bmTemplate = m_bmRMinus;
67 m_ptoolbar->AddTool(ID_DENSITY, _T(
"Density"), m_bmMinimum, m_bmMinimum);
68 m_ptoolbar->AddTool(ID_RPLUS, _T(
"RangePlus"), m_bmRPlus, m_bmRPlus);
69 m_ptoolbar->AddTool(ID_RMINUS, _T(
"RangeMinus"), m_bmRMinus, m_bmRMinus);
71 SetCanToggleOrientation(
false);
72 EnableRolloverBitmaps(
false);
76 SetDensityToolBitmap(m_nDensity);
79 m_ptoolbar->SetBackgroundColour(GetGlobalColor(
"DILG0"));
85 m_state_timer.SetOwner(
this, STATE_TIMER);
86 m_state_timer.Start(100, wxTIMER_CONTINUOUS);
87 this->Connect(wxEVT_TIMER, wxTimerEventHandler(iENCToolbar::StateTimerEvent),
91iENCToolbar::~iENCToolbar() {}
93void iENCToolbar::SetColorScheme(ColorScheme cs) {
95 m_ptoolbar->SetBackgroundColour(GetGlobalColor(
"DILG0"));
97 ocpnFloatingToolbarDialog::SetColorScheme(cs);
98 m_ptoolbar->InvalidateBitmaps();
103void iENCToolbar::LoadToolBitmaps() {
104 wxString svgDir = g_Platform->GetSharedDataDir() + _T(
"uidata") +
105 wxFileName::GetPathSeparator();
110 if (::wxFileExists(svgDir + _T(
"iENC_All.svg"))) {
111 m_bmAll = LoadSVG(svgDir + _T(
"iENC_All.svg"), w, h);
112 m_bmMinimum = LoadSVG(svgDir + _T(
"iENC_Minimum.svg"), w, h);
113 m_bmStandard = LoadSVG(svgDir + _T(
"iENC_Standard.svg"), w, h);
114 m_bmUStd = LoadSVG(svgDir + _T(
"iENC_UserStd.svg"), w, h);
115 m_bmRPlus = LoadSVG(svgDir + _T(
"iENC_RPlus.svg"), w, h);
116 m_bmRMinus = LoadSVG(svgDir + _T(
"iENC_RMinus.svg"), w, h);
118 wxLogMessage(_T(
"Cannot find iENC icons at: ") + svgDir);
120 m_bmMinimum = wxBitmap(96, 32);
121 m_bmStandard = wxBitmap(96, 32);
122 m_bmAll = wxBitmap(96, 32);
123 m_bmUStd = wxBitmap(96, 32);
124 m_bmRPlus = wxBitmap(96, 32);
125 m_bmRMinus = wxBitmap(96, 32);
129void iENCToolbar::OnToolLeftClick(wxCommandEvent &event) {
130 int itemId =
event.GetId();
134 enum _DisCat nset = STANDARD;
140 if (++m_nDensity > 3) m_nDensity = 0;
142 SetDensityToolBitmap(m_nDensity);
144 switch (m_nDensity) {
155 nset = MARINERS_STANDARD;
162 gFrame->SetENCDisplayCategory(cc, nset);
167 range = cc->GetCanvasRangeMeters();
168 range = wxRound(range * 10) / 10.;
170 if (range > 8000.) cc->SetCanvasRangeMeters(8000.);
172 cc->SetCanvasRangeMeters(4000.);
173 else if (range > 2000.)
174 cc->SetCanvasRangeMeters(2000.);
175 else if (range > 1600.)
176 cc->SetCanvasRangeMeters(1600.);
177 else if (range > 1200.)
178 cc->SetCanvasRangeMeters(1200.);
179 else if (range > 800.)
180 cc->SetCanvasRangeMeters(800.);
181 else if (range > 500.)
182 cc->SetCanvasRangeMeters(500.);
183 else if (range > 300.)
184 cc->SetCanvasRangeMeters(300.);
189 range = cc->GetCanvasRangeMeters();
190 range = wxRound(range * 10) / 10.;
193 cc->SetCanvasRangeMeters(300.);
194 else if (range < 500.)
195 cc->SetCanvasRangeMeters(500.);
196 else if (range < 800.)
197 cc->SetCanvasRangeMeters(800.);
198 else if (range < 1200.)
199 cc->SetCanvasRangeMeters(1200.);
200 else if (range < 1600.)
201 cc->SetCanvasRangeMeters(1600.);
202 else if (range < 2000.)
203 cc->SetCanvasRangeMeters(2000.);
204 else if (range < 4000.)
205 cc->SetCanvasRangeMeters(4000.);
206 else if (range < 8000.)
207 cc->SetCanvasRangeMeters(8000.);
214 m_ptoolbar->InvalidateBitmaps();
218void iENCToolbar::SetDensityToolBitmap(
int nDensity) {
219 int toolID = m_toolDensity->GetId();
222 m_ptoolbar->SetToolBitmaps(ID_DENSITY, &m_bmMinimum, &m_bmMinimum);
223 else if (nDensity == 1)
224 m_ptoolbar->SetToolBitmaps(ID_DENSITY, &m_bmStandard, &m_bmStandard);
225 else if (nDensity == 2)
226 m_ptoolbar->SetToolBitmaps(ID_DENSITY, &m_bmAll, &m_bmAll);
227 else if (nDensity == 3)
228 m_ptoolbar->SetToolBitmaps(ID_DENSITY, &m_bmUStd, &m_bmUStd);
231void iENCToolbar::SetRangeToolBitmap() {
233 dc.SelectObject(*m_pbmScratch);
234 dc.SetBackground(wxBrush(GetGlobalColor(
"DILG0")));
236 dc.DrawBitmap(m_bmRMinus, wxPoint(0, 0));
239 m_rangeFont = wxTheFontList->FindOrCreateFont(
240 12, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
242 wxString range_string;
243 range_string.Printf(_T(
"%4.0fm"), m_range);
245 dc.SetFont(*m_rangeFont);
249 int target_points = 12;
250 while (!good && (target_points > 4)) {
252 dc.GetTextExtent(range_string, &width, &height);
258 m_rangeFont = wxTheFontList->FindOrCreateFont(
259 target_points, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
260 wxFONTWEIGHT_NORMAL);
261 dc.SetFont(*m_rangeFont);
265 dc.SetTextForeground(*wxBLACK);
266 dc.SetBackgroundMode(wxTRANSPARENT);
268 dc.DrawText(range_string, 42, 8);
270 dc.SelectObject(wxNullBitmap);
272 m_ptoolbar->SetToolBitmaps(ID_RMINUS, m_pbmScratch, m_pbmScratch);
275void iENCToolbar::StateTimerEvent(wxTimerEvent &event) {
279 bool bRefresh =
false;
284 switch (gFrame->GetPrimaryCanvas()->GetENCDisplayCategory()) {
294 case (MARINERS_STANDARD):
302 if (nset != m_nDensity) {
305 SetDensityToolBitmap(m_nDensity);
315 double range = cc->GetCanvasRangeMeters();
317 if (range != m_range) {
319 SetRangeToolBitmap();
325 m_ptoolbar->InvalidateBitmaps();
330 m_state_timer.Start(500, wxTIMER_CONTINUOUS);
ChartCanvas - Main chart display and interaction component.