1
2 ///////////////////////////////////////////////////////////
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_GDI //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // sgdi_controls.cpp //
15 // //
16 // Copyright (C) 2020 by //
17 // Olaf Conrad //
18 // //
19 //-------------------------------------------------------//
20 // //
21 // This file is part of 'SAGA - System for Automated //
22 // Geoscientific Analyses'. SAGA is free software; you //
23 // can redistribute it and/or modify it under the terms //
24 // of the GNU General Public License as published by the //
25 // Free Software Foundation, either version 2 of the //
26 // License, or (at your option) any later version. //
27 // //
28 // SAGA is distributed in the hope that it will be //
29 // useful, but WITHOUT ANY WARRANTY; without even the //
30 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
31 // PARTICULAR PURPOSE. See the GNU General Public //
32 // License for more details. //
33 // //
34 // You should have received a copy of the GNU General //
35 // Public License along with this program; if not, see //
36 // <http://www.gnu.org/licenses/>. //
37 // //
38 //-------------------------------------------------------//
39 // //
40 // e-mail: oconrad@saga-gis.org //
41 // //
42 // contact: Olaf Conrad //
43 // Institute of Geography //
44 // University of Hamburg //
45 // Germany //
46 // //
47 ///////////////////////////////////////////////////////////
48
49 //---------------------------------------------------------
50 #include <wx/wxprec.h>
51 #include <wx/dc.h>
52
53 //---------------------------------------------------------
54 #include "sgdi_controls.h"
55
56
57 ///////////////////////////////////////////////////////////
58 // //
59 // //
60 // //
61 ///////////////////////////////////////////////////////////
62
63 //---------------------------------------------------------
64 #define SLIDER_RANGE 100
65
66 //---------------------------------------------------------
CSGDI_Slider(wxWindow * pParent,int ID,double Value,double minValue,double maxValue,const wxPoint & Point,const wxSize & Size,long Style)67 CSGDI_Slider::CSGDI_Slider(wxWindow *pParent, int ID, double Value, double minValue, double maxValue, const wxPoint &Point, const wxSize &Size, long Style)
68 : wxSlider(pParent, ID, 0, 0, SLIDER_RANGE, Point, Size, Style)
69 {
70 Set_Range(minValue, maxValue);
71
72 Set_Value(Value);
73
74 SetTickFreq(SLIDER_RANGE / 10);
75 }
76
77 //---------------------------------------------------------
~CSGDI_Slider(void)78 CSGDI_Slider::~CSGDI_Slider(void)
79 {}
80
81 //---------------------------------------------------------
Set_Value(double Value)82 bool CSGDI_Slider::Set_Value(double Value)
83 {
84 int Position = (int)((double)SLIDER_RANGE * (Value - m_Min) / (m_Max - m_Min));
85
86 if( Position <= 0 )
87 {
88 SetValue(0);
89 }
90 else if( Position >= SLIDER_RANGE )
91 {
92 SetValue(SLIDER_RANGE);
93 }
94 else
95 {
96 SetValue(Position);
97 }
98
99 return( true );
100 }
101
102 //---------------------------------------------------------
Get_Value(void)103 double CSGDI_Slider::Get_Value(void)
104 {
105 return( m_Min + GetValue() * (m_Max - m_Min) / (double)SLIDER_RANGE );
106 }
107
108 //---------------------------------------------------------
Set_Range(double minValue,double maxValue)109 bool CSGDI_Slider::Set_Range(double minValue, double maxValue)
110 {
111 if( maxValue == minValue )
112 {
113 minValue = 0.;
114 maxValue = 1.;
115 }
116
117 m_Min = minValue;
118 m_Max = maxValue;
119
120 return( true );
121 }
122
123
124 ///////////////////////////////////////////////////////////
125 // //
126 // //
127 // //
128 ///////////////////////////////////////////////////////////
129
130 //---------------------------------------------------------
CSGDI_SpinCtrl(wxWindow * pParent,int ID,double Value,double minValue,double maxValue,bool bPercent,const wxPoint & Point,const wxSize & Size,long Style)131 CSGDI_SpinCtrl::CSGDI_SpinCtrl(wxWindow *pParent, int ID, double Value, double minValue, double maxValue, bool bPercent, const wxPoint &Point, const wxSize &Size, long Style)
132 : wxSpinCtrl(pParent, ID, wxEmptyString, Point, Size, Style, bPercent ? 0 : (int)minValue, bPercent ? 100 : (int)maxValue)
133 {
134 m_bPercent = bPercent;
135
136 Set_Range(minValue, maxValue);
137
138 Set_Value(Value);
139 }
140
141 //---------------------------------------------------------
~CSGDI_SpinCtrl(void)142 CSGDI_SpinCtrl::~CSGDI_SpinCtrl(void)
143 {}
144
145 //---------------------------------------------------------
Set_Value(double Value)146 bool CSGDI_SpinCtrl::Set_Value(double Value)
147 {
148 if( m_bPercent )
149 {
150 int Position = (int)((double)SLIDER_RANGE * (Value - m_Min) / (m_Max - m_Min));
151
152 if( Position <= 0 )
153 {
154 SetValue(0);
155 }
156 else if( Position >= SLIDER_RANGE )
157 {
158 SetValue(SLIDER_RANGE);
159 }
160 else
161 {
162 SetValue(Position);
163 }
164 }
165 else
166 {
167 if( Value <= m_Min )
168 {
169 SetValue((int)m_Min);
170 }
171 else if( Value >= m_Max )
172 {
173 SetValue((int)m_Max);
174 }
175 else
176 {
177 SetValue((int)Value);
178 }
179 }
180
181 return( true );
182 }
183
184 //---------------------------------------------------------
Get_Value(void)185 double CSGDI_SpinCtrl::Get_Value(void)
186 {
187 if( m_bPercent )
188 {
189 return( m_Min + GetValue() * (m_Max - m_Min) / (double)SLIDER_RANGE );
190 }
191
192 return( GetValue() );
193 }
194
195 //---------------------------------------------------------
Set_Range(double minValue,double maxValue)196 bool CSGDI_SpinCtrl::Set_Range(double minValue, double maxValue)
197 {
198 if( maxValue == minValue )
199 {
200 minValue = 0.;
201 maxValue = 1.;
202 }
203
204 m_Min = minValue;
205 m_Max = maxValue;
206
207 return( true );
208 }
209
210
211 ///////////////////////////////////////////////////////////
212 // //
213 // //
214 // //
215 ///////////////////////////////////////////////////////////
216
217 //---------------------------------------------------------
218