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 "model/config_vars.h"
35#include "DetailSlider.h"
36#include "chcanv.h"
37#include "OCPNPlatform.h"
38#include "options.h"
39#include "chartdb.h"
40#include "ocpn_frame.h"
41
42extern bool g_bShowDetailSlider;
43extern int g_chart_zoom_modifier_raster;
44extern int g_chart_zoom_modifier_vector;
45extern MyFrame* gFrame;
46
47PopUpDSlide* pPopupDetailSlider;
48
49BEGIN_EVENT_TABLE(PopUpDSlide, wxFrame)
50EVT_KEY_DOWN(PopUpDSlide::OnKeyDown)
51EVT_MOVE(PopUpDSlide::OnMove)
52EVT_COMMAND_SCROLL_THUMBRELEASE(-1, PopUpDSlide::OnChangeValue)
53EVT_COMMAND_SCROLL_LINEUP(-1, PopUpDSlide::OnChangeValue)
54EVT_COMMAND_SCROLL_LINEDOWN(-1, PopUpDSlide::OnChangeValue)
55EVT_COMMAND_SCROLL_PAGEUP(-1, PopUpDSlide::OnChangeValue)
56EVT_COMMAND_SCROLL_PAGEDOWN(-1, PopUpDSlide::OnChangeValue)
57EVT_COMMAND_SCROLL_BOTTOM(-1, PopUpDSlide::OnChangeValue)
58EVT_COMMAND_SCROLL_TOP(-1, PopUpDSlide::OnChangeValue)
59EVT_CLOSE(PopUpDSlide::OnClose)
60END_EVENT_TABLE()
61
62PopUpDSlide::PopUpDSlide(wxWindow* parent, wxWindowID id, ChartTypeEnum ChartT,
63 ChartFamilyEnum ChartF, const wxPoint& pos,
64 const wxSize& size, long style,
65 const wxString& title) {
66 Init();
67 if (Create(parent, ID_CM93ZOOMG, ChartT, ChartF, pos, size, style, title)) {
68 m_p_DetailSlider->Connect(
69 wxEVT_KEY_DOWN, wxKeyEventHandler(PopUpDSlide::OnKeyDown), NULL, this);
70 }
71}
72
73PopUpDSlide::~PopUpDSlide() { delete m_p_DetailSlider; }
74
75void PopUpDSlide::Init(void) { m_p_DetailSlider = NULL; }
76
77bool PopUpDSlide::Create(wxWindow* parent, wxWindowID id, ChartTypeEnum ChartT,
78 ChartFamilyEnum ChartF, const wxPoint& pos,
79 const wxSize& size, long style,
80 const wxString& title) {
81 ChartType = ChartT;
82 ChartFam = ChartF;
83 wxString WindowText;
84 int value;
85 if ((ChartType == CHART_TYPE_CM93COMP) || (ChartType == CHART_TYPE_CM93)) {
86 value = g_cm93_zoom_factor;
87 WindowText = _("CM93 Detail Level");
88 } else if ((ChartType == CHART_TYPE_KAP) || (ChartType == CHART_TYPE_GEO) ||
89 (ChartFam == CHART_FAMILY_RASTER)) {
90 value = g_chart_zoom_modifier_raster;
91 WindowText = _("Rasterchart Zoom/Scale Weighting");
92 } else if ((ChartType == CHART_TYPE_S57) ||
93 (ChartFam == CHART_FAMILY_VECTOR)) {
94 value = g_chart_zoom_modifier_vector;
95 WindowText = _("Vectorchart Zoom/Scale Weighting");
96 } else {
97 pPopupDetailSlider = NULL;
98 return false;
99 }
100
101 long wstyle = wxDEFAULT_DIALOG_STYLE | wxFRAME_FLOAT_ON_PARENT;
102
103 if (!wxFrame::Create(parent, id, WindowText, pos, size, wstyle)) return false;
104
105 m_pparent = parent;
106
107 int minValue = -5;
108 int maxValue = 5;
109 m_p_DetailSlider = new wxSlider(
110 this, id, value, minValue, maxValue, wxPoint(0, 0), wxDefaultSize,
111 wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS, wxDefaultValidator,
112 WindowText);
113
114 m_p_DetailSlider->SetSize(wxSize(350, -1));
115
116 m_p_DetailSlider->InvalidateBestSize();
117 wxSize bs = m_p_DetailSlider->GetBestSize();
118
119 m_p_DetailSlider->SetSize(wxSize(350, bs.y));
120 Fit();
121
122 m_p_DetailSlider->SetValue(value);
123
124 Hide();
125
126 return true;
127}
128
129void PopUpDSlide::OnCancelClick(wxCommandEvent& event) {
130 g_bShowDetailSlider = false;
131 Close();
132}
133
134void PopUpDSlide::OnClose(wxCloseEvent& event) {
135 g_bShowDetailSlider = false;
136
137 if (m_p_DetailSlider)
138 m_p_DetailSlider->Disconnect(
139 wxEVT_KEY_DOWN, wxKeyEventHandler(PopUpDSlide::OnKeyDown), NULL, this);
140 Destroy();
141 pPopupDetailSlider = NULL;
142}
143
144void PopUpDSlide::OnKeyDown(wxKeyEvent& event) {
145 int key_char = event.GetKeyCode();
146 if (key_char == WXK_ESCAPE || key_char == 'D') {
147 g_bShowDetailSlider = false;
148 Close();
149 }
150}
151
152void PopUpDSlide::OnMove(wxMoveEvent& event) {
153 // Record the dialog position
154 wxPoint p = event.GetPosition();
155 g_detailslider_dialog_x = p.x;
156 g_detailslider_dialog_y = p.y;
157
158 event.Skip();
159}
160
161void PopUpDSlide::OnChangeValue(wxScrollEvent& event)
162
163{
164 ::wxBeginBusyCursor();
165
166 if ((ChartType == CHART_TYPE_CM93COMP) || (ChartType == CHART_TYPE_CM93)) {
167 g_cm93_zoom_factor = m_p_DetailSlider->GetValue();
168 ChartCanvas* parentCanvas = dynamic_cast<ChartCanvas*>(GetParent());
169
170 parentCanvas->ReloadVP();
171 parentCanvas->Refresh();
172 ::wxEndBusyCursor();
173 return;
174 }
175
176 if ((ChartType == CHART_TYPE_KAP) || (ChartType == CHART_TYPE_GEO) ||
177 (ChartFam == CHART_FAMILY_RASTER)) {
178 g_chart_zoom_modifier_raster = m_p_DetailSlider->GetValue();
179 }
180
181 if ((ChartType == CHART_TYPE_S57) || (ChartFam == CHART_FAMILY_VECTOR)) {
182 g_chart_zoom_modifier_vector = m_p_DetailSlider->GetValue();
183 }
184
185 gFrame->ProcessOptionsDialog(S52_CHANGED | FORCE_UPDATE, NULL);
186
187 ::wxEndBusyCursor();
188}
Charts database management
Generic Chart canvas base.
ChartCanvas - Main chart display and interaction component.
Definition chcanv.h:151
Main application frame.
Definition ocpn_frame.h:138
A popup frame containing a detail slider for chart display.
Global variables stored in configuration file.