prevent per-window alpha menu from scrolling past 0 or 255:

suppose your alpha was at 3 and then you double-clicked -- IntResMenuItem was
setting the alpha to -2, which in FbWinFrame::setAlpha got cast to an unsigned
char, or 254; then, IntResMenuItem would check if the value was less than 0,
which, of course, it wasn't
now, IntResMenuItem checks if the value will exceed the max/min before setting
This commit is contained in:
markt 2007-01-15 19:00:09 +00:00
parent 2a9e8e2782
commit a2804705db
2 changed files with 18 additions and 14 deletions

View file

@ -1,6 +1,8 @@
(Format: Year/Month/Day)
Changes for 1.0rc3:
*07/01/15:
* Prevent per-window alpha menu from scrolling past 0 or 255 (Mark)
IntResMenuItem.hh
* Fix rootmenu disappearing on reconfigure (Mark)
Screen.cc
*07/01/14:

View file

@ -56,20 +56,22 @@ public:
if (time - last_time <= 200)
inc_val = 5;
last_time = time;
if ((button == 4 || button == 3)&& *m_res < m_max) // scroll up
m_res.get() += inc_val;
else if ((button == 5 || button == 1) && *m_res > m_min) // scroll down
m_res.get() -= inc_val;
// clamp value
if (*m_res > m_max)
m_res.get() = m_max;
else if (*m_res < m_min)
m_res.get() = m_min;
// make sure values stay within bounds _before_ we try to set m_res
// otherwise, this may cause bugs (say, with casting to unsigned char)
if ((button == 4 || button == 3) && *m_res < m_max) { // up
if (*m_res + inc_val < m_max)
m_res.get() += inc_val;
else
m_res.get() = m_max;
} else if ((button == 5 || button == 1) && *m_res > m_min) { // down
if (*m_res - inc_val >= m_min)
m_res.get() -= inc_val;
else
m_res.get() = m_min;
}
// update label
updateLabel();
// call other commands
@ -86,7 +88,7 @@ public:
void updateLabel() {
setLabel(appendIntValue(m_org_label, *m_res));
}
private:
std::string m_org_label; ///< original label
const int m_max; ///< maximum value the integer can have