28 #include <wx/wxprec.h>
35 #include "iENCToolbar.h"
40 #include "pluginmanager.h"
41 #include "OCPNPlatform.h"
43 #include "svg_utils.h"
44 #include "ocpn_frame.h"
46 extern s52plib *ps52plib;
54 iENCToolbar::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 ), NULL,
this );
90 iENCToolbar::~iENCToolbar() {}
92 void iENCToolbar::SetColorScheme(ColorScheme cs) {
94 m_ptoolbar->SetBackgroundColour(GetGlobalColor(
"DILG0"));
96 ocpnFloatingToolbarDialog::SetColorScheme(cs);
97 m_ptoolbar->InvalidateBitmaps();
102 void iENCToolbar::LoadToolBitmaps() {
103 wxString svgDir = g_Platform->GetSharedDataDir() + _T(
"uidata") +
104 wxFileName::GetPathSeparator();
109 if (::wxFileExists(svgDir + _T(
"iENC_All.svg"))) {
110 m_bmAll = LoadSVG(svgDir + _T(
"iENC_All.svg"), w, h);
111 m_bmMinimum = LoadSVG(svgDir + _T(
"iENC_Minimum.svg"), w, h);
112 m_bmStandard = LoadSVG(svgDir + _T(
"iENC_Standard.svg"), w, h);
113 m_bmUStd = LoadSVG(svgDir + _T(
"iENC_UserStd.svg"), w, h);
114 m_bmRPlus = LoadSVG(svgDir + _T(
"iENC_RPlus.svg"), w, h);
115 m_bmRMinus = LoadSVG(svgDir + _T(
"iENC_RMinus.svg"), w, h);
117 wxLogMessage(_T(
"Cannot find iENC icons at: ") + svgDir);
119 m_bmMinimum = wxBitmap(96, 32);
120 m_bmStandard = wxBitmap(96, 32);
121 m_bmAll = wxBitmap(96, 32);
122 m_bmUStd = wxBitmap(96, 32);
123 m_bmRPlus = wxBitmap(96, 32);
124 m_bmRMinus = wxBitmap(96, 32);
128 void iENCToolbar::OnToolLeftClick(wxCommandEvent &event) {
129 int itemId =
event.GetId();
133 enum _DisCat nset = STANDARD;
139 if (++m_nDensity > 3) m_nDensity = 0;
141 SetDensityToolBitmap(m_nDensity);
143 switch (m_nDensity) {
154 nset = MARINERS_STANDARD;
161 gFrame->SetENCDisplayCategory(cc, nset);
166 range = cc->GetCanvasRangeMeters();
167 range = wxRound(range * 10) / 10.;
169 if (range > 8000.) cc->SetCanvasRangeMeters(8000.);
171 cc->SetCanvasRangeMeters(4000.);
172 else if (range > 2000.)
173 cc->SetCanvasRangeMeters(2000.);
174 else if (range > 1600.)
175 cc->SetCanvasRangeMeters(1600.);
176 else if (range > 1200.)
177 cc->SetCanvasRangeMeters(1200.);
178 else if (range > 800.)
179 cc->SetCanvasRangeMeters(800.);
180 else if (range > 500.)
181 cc->SetCanvasRangeMeters(500.);
182 else if (range > 300.)
183 cc->SetCanvasRangeMeters(300.);
188 range = cc->GetCanvasRangeMeters();
189 range = wxRound(range * 10) / 10.;
192 cc->SetCanvasRangeMeters(300.);
193 else if (range < 500.)
194 cc->SetCanvasRangeMeters(500.);
195 else if (range < 800.)
196 cc->SetCanvasRangeMeters(800.);
197 else if (range < 1200.)
198 cc->SetCanvasRangeMeters(1200.);
199 else if (range < 1600.)
200 cc->SetCanvasRangeMeters(1600.);
201 else if (range < 2000.)
202 cc->SetCanvasRangeMeters(2000.);
203 else if (range < 4000.)
204 cc->SetCanvasRangeMeters(4000.);
205 else if (range < 8000.)
206 cc->SetCanvasRangeMeters(8000.);
213 m_ptoolbar->InvalidateBitmaps();
218 void 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);
231 void 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);
276 void iENCToolbar::StateTimerEvent(wxTimerEvent &event) {
280 bool bRefresh =
false;
285 switch (gFrame->GetPrimaryCanvas()->GetENCDisplayCategory()) {
295 case (MARINERS_STANDARD):
303 if (nset != m_nDensity) {
306 SetDensityToolBitmap(m_nDensity);
316 double range = cc->GetCanvasRangeMeters();
318 if (range != m_range) {
320 SetRangeToolBitmap();
326 m_ptoolbar->InvalidateBitmaps();
331 m_state_timer.Start(500, wxTIMER_CONTINUOUS);