aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/IntResMenuItem.hh30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/IntResMenuItem.hh b/src/IntResMenuItem.hh
index 0be2775..768870e 100644
--- a/src/IntResMenuItem.hh
+++ b/src/IntResMenuItem.hh
@@ -56,20 +56,22 @@ public:
56 if (time - last_time <= 200) 56 if (time - last_time <= 200)
57 inc_val = 5; 57 inc_val = 5;
58 58
59
60 last_time = time; 59 last_time = time;
61 60
62 if ((button == 4 || button == 3)&& *m_res < m_max) // scroll up 61 // make sure values stay within bounds _before_ we try to set m_res
63 m_res.get() += inc_val; 62 // otherwise, this may cause bugs (say, with casting to unsigned char)
64 else if ((button == 5 || button == 1) && *m_res > m_min) // scroll down 63 if ((button == 4 || button == 3) && *m_res < m_max) { // up
65 m_res.get() -= inc_val; 64 if (*m_res + inc_val < m_max)
66 65 m_res.get() += inc_val;
67 // clamp value 66 else
68 if (*m_res > m_max) 67 m_res.get() = m_max;
69 m_res.get() = m_max; 68 } else if ((button == 5 || button == 1) && *m_res > m_min) { // down
70 else if (*m_res < m_min) 69 if (*m_res - inc_val >= m_min)
71 m_res.get() = m_min; 70 m_res.get() -= inc_val;
72 71 else
72 m_res.get() = m_min;
73 }
74
73 // update label 75 // update label
74 updateLabel(); 76 updateLabel();
75 // call other commands 77 // call other commands
@@ -86,7 +88,7 @@ public:
86 void updateLabel() { 88 void updateLabel() {
87 setLabel(appendIntValue(m_org_label, *m_res)); 89 setLabel(appendIntValue(m_org_label, *m_res));
88 } 90 }
89 91
90private: 92private:
91 std::string m_org_label; ///< original label 93 std::string m_org_label; ///< original label
92 const int m_max; ///< maximum value the integer can have 94 const int m_max; ///< maximum value the integer can have