Guiliani  Version 2.6 revision 7293 (documentation build 12)
GUIRange.h
1/*
2* Copyright (C) TES Electronic Solutions GmbH,
3* All Rights Reserved.
4* Contact: info@guiliani.de
5*
6* This file is part of the Guiliani HMI framework
7* for the development of graphical user interfaces on embedded systems.
8*/
9
10#ifndef GUIRANGE__H_
11#define GUIRANGE__H_
12
13#include "GUIStreamableObject.h"
14#include "eC_Math.h"
15
16
18
67{
68public:
69
71 enum Base_t
72 {
73 BASE_AT_MINIMUM,
74 BASE_AT_MAXIMUM
75 };
76
80 m_vPercentValue(eC_FromInt(0)),
81 m_iValue(0),
82 m_uiStepSize(1),
83 m_iMaxValue(1),
84 m_iMinValue(0),
85 m_eBase(BASE_AT_MINIMUM),
86 m_bMaximumLevelIsAlwaysValid(false)
87 {}
88
98 eC_Int iValue,
99 eC_Int iMinValue,
100 eC_Int iMaxValue,
101 eC_UInt uiStepSize = 1,
102 Base_t eBase = BASE_AT_MINIMUM,
103 eC_Bool bExtremeLevelsAreAlwaysValid = false) :
104 m_vPercentValue(eC_FromInt(0)),
105 m_iValue(0),
106 m_uiStepSize(1),
107 m_iMaxValue(1),
108 m_iMinValue(0),
109 m_eBase(BASE_AT_MINIMUM),
110 m_bMaximumLevelIsAlwaysValid(bExtremeLevelsAreAlwaysValid)
111 {
112 SetMinValue(iMinValue);
113 SetMaxValue(iMaxValue);
114 SetStepSize(uiStepSize);
115 SetBase(eBase);
116 SetValue(iValue);
117 }
118
128 eC_Int iLevelPercentage,
129 eC_UInt uiStepSizeLevelPercentage,
130 eC_Int iMinValue,
131 eC_Int iMaxValue,
132 Base_t eBase = BASE_AT_MINIMUM,
133 eC_Bool bExtremeLevelsAreAlwaysValid = false) :
134 m_vPercentValue(eC_FromInt(0)),
135 m_iValue(0),
136 m_uiStepSize(1),
137 m_iMaxValue(1),
138 m_iMinValue(0),
139 m_eBase(BASE_AT_MINIMUM),
140 m_bMaximumLevelIsAlwaysValid(bExtremeLevelsAreAlwaysValid)
141 {
142 SetMinValue(iMinValue);
143 SetMaxValue(iMaxValue);
144 SetStepSizeLevelPercentage(uiStepSizeLevelPercentage);
145 SetBase(eBase);
146 SetLevelPercentage(iLevelPercentage);
147 }
148
158 eC_Value vLevel,
159 eC_Int iMinValue,
160 eC_Int iMaxValue,
161 eC_Value vStepSizeLevel,
162 Base_t eBase = BASE_AT_MINIMUM,
163 eC_Bool bExtremeLevelsAreAlwaysValid = false) :
164 m_vPercentValue(eC_FromInt(0)),
165 m_iValue(0),
166 m_uiStepSize(1),
167 m_iMaxValue(1),
168 m_iMinValue(0),
169 m_eBase(BASE_AT_MINIMUM),
170 m_bMaximumLevelIsAlwaysValid(bExtremeLevelsAreAlwaysValid)
171 {
172 SetMinValue(iMinValue);
173 SetMaxValue(iMaxValue);
174 SetStepSizeLevel(vStepSizeLevel);
175 SetBase(eBase);
176 SetLevel(vLevel);
177 }
178
182 CGUIRange(const CGUIRange& kSource) {CopyAttributes(kSource);}
183
189 {
190 CopyAttributes(kSource);
191 return *this;
192 }
193
205 void SetValue(eC_Int iNewValue);
206
212 inline eC_Int GetValue() const {return m_iValue;}
213
225 inline eC_Value GetLevel() const {return m_vPercentValue;}
226
235 inline eC_UInt GetLevelPercentage() const
236 {
237 return eC_ToInt(eC_Mul(m_vPercentValue, eC_FromInt(100)));
238 }
239
246 void SetLevel(eC_Value vPercent);
247
254 void SetLevelPercentage(eC_UInt uiPercentage);
255
257 inline eC_Int GetMinValue() const {return m_iMinValue;}
258
269 void SetMinValue(eC_Int iMinValue)
270 {
271 SetRange(iMinValue, m_iMaxValue);
272 }
273
275 inline eC_Int GetMaxValue() const {return m_iMaxValue;}
276
288 void SetMaxValue(eC_Int iMaxValue)
289 {
290 SetRange(m_iMinValue, iMaxValue);
291 }
292
301 void SetRange(eC_Int iMinValue, eC_Int iMaxValue);
302
313 void SetStepSizeLevelPercentage(eC_UInt uiPercentage);
314
323 void SetStepSizeLevel(eC_Value vPercent);
324
326 inline eC_UInt GetStepSize() const {return m_uiStepSize;}
327
336 void SetStepSize(eC_UInt uiIntValues);
337
341 eC_Bool Increase();
342
346 eC_Bool Decrease();
347
349 inline const Base_t& GetBase() const {return m_eBase;}
350
364 void SetBase(Base_t eBase);
365
369 inline eC_Bool GetMaximumLevelIsAlwaysValid() const
370 {
371 return m_bMaximumLevelIsAlwaysValid;
372 }
373
378 eC_Bool bNotOnlyMultiplesOfStepSize)
379 {
380 m_bMaximumLevelIsAlwaysValid = bNotOnlyMultiplesOfStepSize;
381 }
382
386 inline void ClipToBounds(eC_Int &iValue) const
387 {
388 if (iValue < m_iMinValue) iValue = m_iMinValue;
389 else if (iValue > m_iMaxValue) iValue = m_iMaxValue;
390 }
391
396 void RoundToNextStep(eC_Int &iRangeValue) const;
397
398#ifdef GUILIANI_STREAM_GUI
399 virtual void ReadFromStream();
400#endif
401
402#ifdef GUILIANI_WRITE_GUI
403 virtual void WriteToStream(const eC_Bool bWriteClassID = false);
404#endif
405
406private:
411 inline void CopyAttributes(const CGUIRange& kSource)
412 {
413 m_vPercentValue = kSource.m_vPercentValue;
414 m_iValue = kSource.m_iValue;
415 m_uiStepSize = kSource.m_uiStepSize;
416 m_iMaxValue = kSource.m_iMaxValue;
417 m_iMinValue = kSource.m_iMinValue;
418 m_eBase = kSource.m_eBase;
419 m_bMaximumLevelIsAlwaysValid = kSource.m_bMaximumLevelIsAlwaysValid;
420 }
421
423 void CalcLevel();
424
426 inline void ClipPercentage(eC_UInt &uiPercentage) const
427 {
428 if (uiPercentage > 100) uiPercentage = 100;
429 }
430
432 inline void ClipLevel(eC_Value& vPercent) const
433 {
434 if (vPercent > eC_FromInt(1)) vPercent = eC_FromInt(1);
435 else if (vPercent < eC_FromInt(0)) vPercent = eC_FromInt(0);
436 }
437
443 inline eC_Int RoundUpToMultiplesOf(eC_Int iValueToRound, eC_Int iStepSize) const
444 {
445 if (iStepSize != 0)
446 // round up to next multiple of step size, steps based at zero
447 return ((iValueToRound + (iStepSize - 1)) / iStepSize)
448 * iStepSize;
449 else
450 return iValueToRound;
451 }
452
458 inline eC_Int RoundDownToMultiplesOf(eC_Int iValueToRound, eC_Int iStepSize) const
459 {
460 if (iStepSize != 0)
461 // round down to next multiple of step size, steps based at zero
462 return (iValueToRound / iStepSize) * iStepSize;
463 else
464 return iValueToRound;
465 }
466
469 eC_Value m_vPercentValue;
470
473 eC_Int m_iValue;
474
482 eC_UInt m_uiStepSize;
483
485 eC_Int m_iMaxValue;
486
488 eC_Int m_iMinValue;
489
491 Base_t m_eBase;
492
495 eC_Bool m_bMaximumLevelIsAlwaysValid;
496};
497#endif
Helper class to supply a platform independent range implementation.
Definition: GUIRange.h:67
void SetValue(eC_Int iNewValue)
eC_UInt GetLevelPercentage() const
Definition: GUIRange.h:235
eC_Int GetMinValue() const
Definition: GUIRange.h:257
void SetStepSizeLevel(eC_Value vPercent)
void SetMaximumLevelIsAlwaysValid(eC_Bool bNotOnlyMultiplesOfStepSize)
Definition: GUIRange.h:377
void SetStepSizeLevelPercentage(eC_UInt uiPercentage)
CGUIRange(eC_Value vLevel, eC_Int iMinValue, eC_Int iMaxValue, eC_Value vStepSizeLevel, Base_t eBase=BASE_AT_MINIMUM, eC_Bool bExtremeLevelsAreAlwaysValid=false)
Definition: GUIRange.h:157
eC_Bool Increase()
CGUIRange()
Definition: GUIRange.h:79
eC_Bool GetMaximumLevelIsAlwaysValid() const
Definition: GUIRange.h:369
CGUIRange(eC_Int iLevelPercentage, eC_UInt uiStepSizeLevelPercentage, eC_Int iMinValue, eC_Int iMaxValue, Base_t eBase=BASE_AT_MINIMUM, eC_Bool bExtremeLevelsAreAlwaysValid=false)
Definition: GUIRange.h:127
virtual void WriteToStream(const eC_Bool bWriteClassID=false)
CGUIRange(eC_Int iValue, eC_Int iMinValue, eC_Int iMaxValue, eC_UInt uiStepSize=1, Base_t eBase=BASE_AT_MINIMUM, eC_Bool bExtremeLevelsAreAlwaysValid=false)
Definition: GUIRange.h:97
CGUIRange(const CGUIRange &kSource)
Definition: GUIRange.h:182
void SetLevelPercentage(eC_UInt uiPercentage)
void SetBase(Base_t eBase)
eC_Int GetMaxValue() const
Definition: GUIRange.h:275
void SetMinValue(eC_Int iMinValue)
Definition: GUIRange.h:269
eC_UInt GetStepSize() const
Definition: GUIRange.h:326
CGUIRange & operator=(const CGUIRange &kSource)
Definition: GUIRange.h:188
void RoundToNextStep(eC_Int &iRangeValue) const
eC_Int GetValue() const
Definition: GUIRange.h:212
void SetRange(eC_Int iMinValue, eC_Int iMaxValue)
eC_Bool Decrease()
eC_Value GetLevel() const
Definition: GUIRange.h:225
void ClipToBounds(eC_Int &iValue) const
Definition: GUIRange.h:386
virtual void ReadFromStream()
void SetLevel(eC_Value vPercent)
void SetStepSize(eC_UInt uiIntValues)
Base_t
Whether base is at minimum or maximum of the range.
Definition: GUIRange.h:72
const Base_t & GetBase() const
Definition: GUIRange.h:349
void SetMaxValue(eC_Int iMaxValue)
Definition: GUIRange.h:288
Base class for streamable objects.
Definition: GUIStreamableObject.h:46