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