Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Step.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_UI_MIXIN_SNAP_H_
21 #define OMNI_UI_MIXIN_SNAP_H_
22 
23 #include <math.h>
24 #include <cmath>
25 
26 namespace omni {
27  namespace ui {
28  namespace mixin {
29  /**@brief Mixin Stepping value class template
30  @detail Singla and page step
31  **/
32  template<typename VALUE>
33  struct Step
34  {
35  typedef VALUE value_type;
36 
37  /// Construct with a single step, page step value
39  value_type _singleStep = 1.0,
40  value_type _pageStep = 10.0,
41  bool _snap = false) :
42  singleStep_(_singleStep),
43  pageStep_(_pageStep),
44  snap_(_snap)
45  {}
46 
47  /// Return snapped value
48  qreal snapped(value_type _v) const
49  {
50  return value_type(round(qreal(_v) / singleStep())) *
51  singleStep();
52  }
53 
54  /// Snap value (align to single step value)
55  bool snap() const
56  {
57  return snap_;
58  }
59 
60  /// Set boolean if value is to be snapped
61  void setSnap(bool _snap)
62  {
63  snap_ = _snap;
64  }
65 
66  /// Return value for single step
68  {
69  return singleStep_;
70  }
71 
72  /// Return value for page step
74  {
75  return pageStep_;
76  }
77 
78  /// Set new single step value
79  void setSingleStep(value_type _singleStep)
80  {
81  singleStep_ = _singleStep;
82  }
83 
84  /// Set new value for page step
85  void setPageStep(value_type _pageStep)
86  {
87  pageStep_ = _pageStep;
88  }
89 
90  protected:
91  /// Functor to be applied for each step between min and maximum
92  template<typename MIN, typename MAX, typename F>
93  void for_each_step(MIN _min, MAX _max, F f)
94  {
95  int _step = 0;
96 
97  for (value_type i = _min; i <= _max; i += singleStep())
98  {
99  int _rI = int(std::round(double(i) / singleStep()));
100 
101  bool _isPage = int(pageStep()) == 0 ? false :
102  abs(_rI) %
103  int(std::round(double(pageStep()) /
104  singleStep())) == 0;
105  f(_step, i, _isPage);
106  ++_step;
107  }
108  }
109 
110  private:
113  bool snap_;
114  };
115  }
116  }
117 }
118 
119 #endif /* OMNI_UI_MIXIN_SNAP_H_ */
value_type pageStep() const
Return value for page step.
Definition: Step.h:73
VALUE value_type
Definition: Step.h:35
void setSnap(bool _snap)
Set boolean if value is to be snapped.
Definition: Step.h:61
qreal snapped(value_type _v) const
Return snapped value.
Definition: Step.h:48
bool snap_
Definition: Step.h:113
Step(value_type _singleStep=1.0, value_type _pageStep=10.0, bool _snap=false)
Construct with a single step, page step value.
Definition: Step.h:38
void setPageStep(value_type _pageStep)
Set new value for page step.
Definition: Step.h:85
value_type singleStep() const
Return value for single step.
Definition: Step.h:67
bool snap() const
Snap value (align to single step value)
Definition: Step.h:55
value_type singleStep_
Definition: Step.h:111
value_type pageStep_
Definition: Step.h:112
void for_each_step(MIN _min, MAX _max, F f)
Functor to be applied for each step between min and maximum.
Definition: Step.h:93
void setSingleStep(value_type _singleStep)
Set new single step value.
Definition: Step.h:79
Mixin Stepping value class template Singla and page step.
Definition: Step.h:33