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