OpenCPN Partial API docs
Loading...
Searching...
No Matches
DetailSlider.cpp
1/******************************************************************************
2 *
3 * Project: OpenCPN
4 *
5 ***************************************************************************
6 * Copyright (C) 2013 by David S. Register *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22 ***************************************************************************
23 */
24
25#ifdef __MINGW32__
26#undef IPV6STRICT // mingw FTBS fix: missing struct ip_mreq
27#include <windows.h>
28#endif
29
30#include <wx/wxprec.h>
31
32#include <wx/slider.h>
33
34#include "DetailSlider.h"
35#include "chcanv.h"
36#include "OCPNPlatform.h"
37#include "options.h"
38#include "chartdb.h"
39#include "ocpn_frame.h"
40
41extern bool g_bShowDetailSlider;
42extern PopUpDSlide* pPopupDetailSlider;
43extern int g_cm93_zoom_factor;
44extern int g_chart_zoom_modifier_raster;
45extern int g_chart_zoom_modifier_vector;
46extern int g_detailslider_dialog_x;
47extern int g_detailslider_dialog_y;
48extern MyFrame* gFrame;
49
50BEGIN_EVENT_TABLE(PopUpDSlide, wxFrame)
51EVT_KEY_DOWN(PopUpDSlide::OnKeyDown)
52EVT_MOVE(PopUpDSlide::OnMove)
53EVT_COMMAND_SCROLL_THUMBRELEASE(-1, PopUpDSlide::OnChangeValue)
54EVT_COMMAND_SCROLL_LINEUP(-1, PopUpDSlide::OnChangeValue)
55EVT_COMMAND_SCROLL_LINEDOWN(-1, PopUpDSlide::OnChangeValue)
56EVT_COMMAND_SCROLL_PAGEUP(-1, PopUpDSlide::OnChangeValue)
57EVT_COMMAND_SCROLL_PAGEDOWN(-1, PopUpDSlide::OnChangeValue)
58EVT_COMMAND_SCROLL_BOTTOM(-1, PopUpDSlide::OnChangeValue)
59EVT_COMMAND_SCROLL_TOP(-1, PopUpDSlide::OnChangeValue)
60EVT_CLOSE(PopUpDSlide::OnClose)
61END_EVENT_TABLE()
62
63PopUpDSlide::PopUpDSlide(wxWindow* parent, wxWindowID id, ChartTypeEnum ChartT,
64 ChartFamilyEnum ChartF, const wxPoint& pos,
65 const wxSize& size, long style,
66 const wxString& title) {
67 Init();
68 if (Create(parent, ID_CM93ZOOMG, ChartT, ChartF, pos, size, style, title)) {
69 m_p_DetailSlider->Connect(
70 wxEVT_KEY_DOWN, wxKeyEventHandler(PopUpDSlide::OnKeyDown), NULL, this);
71 }
72}
73
74PopUpDSlide::~PopUpDSlide() { delete m_p_DetailSlider; }
75
76void PopUpDSlide::Init(void) { m_p_DetailSlider = NULL; }
77
78bool PopUpDSlide::Create(wxWindow* parent, wxWindowID id, ChartTypeEnum ChartT,
79 ChartFamilyEnum ChartF, const wxPoint& pos,
80 const wxSize& size, long style,
81 const wxString& title) {
82 ChartType = ChartT;
83 ChartFam = ChartF;
84 wxString WindowText;
85 int value;
86 if ((ChartType == CHART_TYPE_CM93COMP) || (ChartType == CHART_TYPE_CM93)) {
87 value = g_cm93_zoom_factor;
88 WindowText = _("CM93 Detail Level");
89 } else if ((ChartType == CHART_TYPE_KAP) || (ChartType == CHART_TYPE_GEO) ||
90 (ChartFam == CHART_FAMILY_RASTER)) {
91 value = g_chart_zoom_modifier_raster;
92 WindowText = _("Rasterchart Zoom/Scale Weighting");
93 } else if ((ChartType == CHART_TYPE_S57) ||
94 (ChartFam == CHART_FAMILY_VECTOR)) {
95 value = g_chart_zoom_modifier_vector;
96 WindowText = _("Vectorchart Zoom/Scale Weighting");
97 } else {
98 pPopupDetailSlider = NULL;
99 return false;
100 }
101
102 long wstyle = wxDEFAULT_DIALOG_STYLE | wxFRAME_FLOAT_ON_PARENT;
103
104 if (!wxFrame::Create(parent, id, WindowText, pos, size, wstyle)) return false;
105
106 m_pparent = parent;
107
108 int minValue = -5;
109 int maxValue = 5;
110 m_p_DetailSlider = new wxSlider(
111 this, id, value, minValue, maxValue, wxPoint(0, 0), wxDefaultSize,
112 wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator,
113 WindowText);
114
115 m_p_DetailSlider->SetSize(wxSize(350, -1));
116
117 m_p_DetailSlider->InvalidateBestSize();
118 wxSize bs = m_p_DetailSlider->GetBestSize();
119
120 m_p_DetailSlider->SetSize(wxSize(350, bs.y));
121 Fit();
122
123 m_p_DetailSlider->SetValue(value);
124
125 Hide();
126
127 return true;
128}
129
130void PopUpDSlide::OnCancelClick(wxCommandEvent& event) {
131 g_bShowDetailSlider = false;
132 Close();
133}
134
135void PopUpDSlide::OnClose(wxCloseEvent& event) {
136 g_bShowDetailSlider = false;
137
138 if (m_p_DetailSlider)
139 m_p_DetailSlider->Disconnect(
140 wxEVT_KEY_DOWN, wxKeyEventHandler(PopUpDSlide::OnKeyDown), NULL, this);
141 Destroy();
142 pPopupDetailSlider = NULL;
143}
144
145void PopUpDSlide::OnKeyDown(wxKeyEvent& event) {
146 int key_char = event.GetKeyCode();
147 if (key_char == WXK_ESCAPE || key_char == 'D') {
148 g_bShowDetailSlider = false;
149 Close();
150 }
151}
152
153void PopUpDSlide::OnMove(wxMoveEvent& event) {
154 // Record the dialog position
155 wxPoint p = event.GetPosition();
156 g_detailslider_dialog_x = p.x;
157 g_detailslider_dialog_y = p.y;
158
159 event.Skip();
160}
161
162void PopUpDSlide::OnChangeValue(wxScrollEvent& event)
163
164{
165 ::wxBeginBusyCursor();
166
167 if ((ChartType == CHART_TYPE_CM93COMP) || (ChartType == CHART_TYPE_CM93)) {
168 g_cm93_zoom_factor = m_p_DetailSlider->GetValue();
169 ChartCanvas* parentCanvas = dynamic_cast<ChartCanvas*>(GetParent());
170
171 parentCanvas->ReloadVP();
172 parentCanvas->Refresh();
173 ::wxEndBusyCursor();
174 return;
175 }
176
177 if ((ChartType == CHART_TYPE_KAP) || (ChartType == CHART_TYPE_GEO) ||
178 (ChartFam == CHART_FAMILY_RASTER)) {
179 g_chart_zoom_modifier_raster = m_p_DetailSlider->GetValue();
180 }
181
182 if ((ChartType == CHART_TYPE_S57) || (ChartFam == CHART_FAMILY_VECTOR)) {
183 g_chart_zoom_modifier_vector = m_p_DetailSlider->GetValue();
184 }
185
186 gFrame->ProcessOptionsDialog(S52_CHANGED | FORCE_UPDATE, NULL);
187
188 ::wxEndBusyCursor();
189}