35#include "iENCToolbar.h"
40#include "pluginmanager.h"
41#include "OCPNPlatform.h"
44#include "ocpn_frame.h"
46extern s52plib *ps52plib;
54EVT_MENU(wxID_ANY, iENCToolbar::OnToolLeftClick)
55EVT_TIMER(STATE_TIMER, iENCToolbar::StateTimerEvent)
56EVT_MOUSE_EVENTS(iENCToolbar::MouseEvent)
64 wxSize a = m_bmMinimum.GetSize();
65 m_ptoolbar->SetToolBitmapSize(a);
67 m_pbmScratch =
new wxBitmap(a.x, a.y);
69 m_bmTemplate = m_bmRMinus;
72 m_ptoolbar->AddTool(ID_DENSITY, _T(
"Density"), m_bmMinimum, m_bmMinimum);
73 m_ptoolbar->AddTool(ID_RPLUS, _T(
"RangePlus"), m_bmRPlus, m_bmRPlus);
74 m_ptoolbar->AddTool(ID_RMINUS, _T(
"RangeMinus"), m_bmRMinus, m_bmRMinus);
76 SetCanToggleOrientation(
false);
77 EnableRolloverBitmaps(
false);
79 SetGrabberEnable(
false);
82 SetDensityToolBitmap(m_nDensity);
91 m_state_timer.SetOwner(
this, STATE_TIMER);
92 m_state_timer.Start(500, wxTIMER_CONTINUOUS);
95iENCToolbar::~iENCToolbar() {}
97void iENCToolbar::MouseEvent(wxMouseEvent &event) {
98 if (event.IsButton()) gFrame->Raise();
101void iENCToolbar::SetColorScheme(ColorScheme cs) {
105 ocpnFloatingToolbarDialog::SetColorScheme(cs);
108void iENCToolbar::LoadToolBitmaps() {
109 wxString svgDir = g_Platform->GetSharedDataDir() + _T(
"uidata") +
110 wxFileName::GetPathSeparator();
115 if (::wxFileExists(svgDir + _T(
"iENC_All.svg"))) {
116 m_bmAll = LoadSVG(svgDir + _T(
"iENC_All.svg"), w, h);
117 m_bmMinimum = LoadSVG(svgDir + _T(
"iENC_Minimum.svg"), w, h);
118 m_bmStandard = LoadSVG(svgDir + _T(
"iENC_Standard.svg"), w, h);
119 m_bmUStd = LoadSVG(svgDir + _T(
"iENC_UserStd.svg"), w, h);
120 m_bmRPlus = LoadSVG(svgDir + _T(
"iENC_RPlus.svg"), w, h);
121 m_bmRMinus = LoadSVG(svgDir + _T(
"iENC_RMinus.svg"), w, h);
123 wxLogMessage(_T(
"Cannot find iENC icons at: ") + svgDir);
125 m_bmMinimum = wxBitmap(96, 32);
126 m_bmStandard = wxBitmap(96, 32);
128 m_bmAll = wxBitmap(96, 32);
129 m_bmUStd = wxBitmap(96, 32);
131 m_bmRPlus = wxBitmap(96, 32);
132 m_bmRMinus = wxBitmap(96, 32);
136void iENCToolbar::OnToolLeftClick(wxCommandEvent &event) {
137 int itemId =
event.GetId();
141 enum _DisCat nset = STANDARD;
147 if (++m_nDensity > 3) m_nDensity = 0;
149 SetDensityToolBitmap(m_nDensity);
150 m_ptoolbar->Refresh();
152 switch (m_nDensity) {
163 nset = MARINERS_STANDARD;
170 gFrame->SetENCDisplayCategory(cc, nset);
175 range = cc->GetCanvasRangeMeters();
176 range = wxRound(range * 10) / 10.;
178 if (range > 8000.) cc->SetCanvasRangeMeters(8000.);
180 cc->SetCanvasRangeMeters(4000.);
181 else if (range > 2000.)
182 cc->SetCanvasRangeMeters(2000.);
183 else if (range > 1600.)
184 cc->SetCanvasRangeMeters(1600.);
185 else if (range > 1200.)
186 cc->SetCanvasRangeMeters(1200.);
187 else if (range > 800.)
188 cc->SetCanvasRangeMeters(800.);
189 else if (range > 500.)
190 cc->SetCanvasRangeMeters(500.);
191 else if (range > 300.)
192 cc->SetCanvasRangeMeters(300.);
197 range = cc->GetCanvasRangeMeters();
198 range = wxRound(range * 10) / 10.;
201 cc->SetCanvasRangeMeters(300.);
202 else if (range < 500.)
203 cc->SetCanvasRangeMeters(500.);
204 else if (range < 800.)
205 cc->SetCanvasRangeMeters(800.);
206 else if (range < 1200.)
207 cc->SetCanvasRangeMeters(1200.);
208 else if (range < 1600.)
209 cc->SetCanvasRangeMeters(1600.);
210 else if (range < 2000.)
211 cc->SetCanvasRangeMeters(2000.);
212 else if (range < 4000.)
213 cc->SetCanvasRangeMeters(4000.);
214 else if (range < 8000.)
215 cc->SetCanvasRangeMeters(8000.);
224void iENCToolbar::SetDensityToolBitmap(
int nDensity) {
225 int toolID = m_toolDensity->GetId();
228 m_ptoolbar->SetToolBitmaps(ID_DENSITY, &m_bmMinimum, &m_bmMinimum);
229 else if (nDensity == 1)
230 m_ptoolbar->SetToolBitmaps(ID_DENSITY, &m_bmStandard, &m_bmStandard);
231 else if (nDensity == 2)
232 m_ptoolbar->SetToolBitmaps(ID_DENSITY, &m_bmAll, &m_bmAll);
233 else if (nDensity == 3)
234 m_ptoolbar->SetToolBitmaps(ID_DENSITY, &m_bmUStd, &m_bmUStd);
237void iENCToolbar::StateTimerEvent(wxTimerEvent &event) {
245 switch (gFrame->GetPrimaryCanvas()->GetENCDisplayCategory()) {
255 case (MARINERS_STANDARD):
263 if (nset != m_nDensity) {
266 SetDensityToolBitmap(m_nDensity);
268 m_ptoolbar->Refresh();
276 double range = cc->GetCanvasRangeMeters();
278 if (range != m_range) {
289 wxBitmap bmTemplate = m_bmRMinus;
291 wxMask *mask =
new wxMask(bmTemplate, wxColour(wxTRANSPARENT));
292 bmTemplate.SetMask(mask);
294 wxMemoryDC dct(bmTemplate);
298 dc.SelectObject(*m_pbmScratch);
299 dc.SetBackground(wxBrush(GetGlobalColor(_T(
"GREY2"))));
302 dc.Blit(0, 0, m_pbmScratch->GetWidth(), m_pbmScratch->GetHeight(), &dct, 0, 0, wxCOPY,
true);
304 dct.SelectObject(wxNullBitmap);
307 dc.SelectObject(*m_pbmScratch);
308 dc.SetBackground(wxBrush(GetGlobalColor(_T(
"GREY2"))));
310 dc.DrawBitmap(m_bmRMinus, wxPoint(0, 0));
313 m_rangeFont = wxTheFontList->FindOrCreateFont(
314 12, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
316 wxString range_string;
317 range_string.Printf(_T(
"%4.0fm"), range);
319 dc.SetFont(*m_rangeFont);
323 int target_points = 12;
324 while (!good && (target_points > 4)) {
326 dc.GetTextExtent(range_string, &width, &height);
332 m_rangeFont = wxTheFontList->FindOrCreateFont(
333 target_points, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
334 wxFONTWEIGHT_NORMAL);
335 dc.SetFont(*m_rangeFont);
339 dc.SetTextForeground(*wxBLACK);
340 dc.SetBackgroundMode(wxTRANSPARENT);
342 dc.DrawText(range_string, 42, 8);
344 dc.SelectObject(wxNullBitmap);
346 m_ptoolbar->SetToolBitmaps(ID_RMINUS, m_pbmScratch, m_pbmScratch);
348 m_ptoolbar->Refresh();