AModule::getScrollDir: convert if-else chain into switch statement
This commit is contained in:
parent
7c85aec8e0
commit
86d6668ed4
|
@ -53,41 +53,41 @@ bool AModule::handleToggle(GdkEventButton* const& e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
|
AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
|
||||||
if (e->direction == GDK_SCROLL_UP) {
|
switch (e -> direction) {
|
||||||
return SCROLL_DIR::UP;
|
case GDK_SCROLL_UP: return SCROLL_DIR::UP;
|
||||||
} else if (e->direction == GDK_SCROLL_DOWN) {
|
case GDK_SCROLL_DOWN: return SCROLL_DIR::DOWN;
|
||||||
return SCROLL_DIR::DOWN;
|
case GDK_SCROLL_LEFT: return SCROLL_DIR::LEFT;
|
||||||
} else if (e->direction == GDK_SCROLL_LEFT) {
|
case GDK_SCROLL_RIGHT: return SCROLL_DIR::RIGHT;
|
||||||
return SCROLL_DIR::LEFT;
|
case GDK_SCROLL_SMOOTH: {
|
||||||
} else if (e->direction == GDK_SCROLL_RIGHT) {
|
SCROLL_DIR dir{SCROLL_DIR::NONE};
|
||||||
return SCROLL_DIR::RIGHT;
|
|
||||||
} else if (e->direction == GDK_SCROLL_SMOOTH) {
|
|
||||||
SCROLL_DIR dir{SCROLL_DIR::NONE};
|
|
||||||
|
|
||||||
distance_scrolled_y_ += e->delta_y;
|
distance_scrolled_y_ += e->delta_y;
|
||||||
distance_scrolled_x_ += e->delta_x;
|
distance_scrolled_x_ += e->delta_x;
|
||||||
|
|
||||||
gdouble threshold = 0;
|
gdouble threshold = 0;
|
||||||
if (config_["smooth-scrolling-threshold"].isNumeric()) {
|
if (config_["smooth-scrolling-threshold"].isNumeric()) {
|
||||||
threshold = config_["smooth-scrolling-threshold"].asDouble();
|
threshold = config_["smooth-scrolling-threshold"].asDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (distance_scrolled_y_ < -threshold) {
|
||||||
|
dir = SCROLL_DIR::UP;
|
||||||
|
} else if (distance_scrolled_y_ > threshold) {
|
||||||
|
dir = SCROLL_DIR::DOWN;
|
||||||
|
} else if (distance_scrolled_x_ > threshold) {
|
||||||
|
dir = SCROLL_DIR::RIGHT;
|
||||||
|
} else if (distance_scrolled_x_ < -threshold) {
|
||||||
|
dir = SCROLL_DIR::LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::DOWN) {
|
||||||
|
distance_scrolled_y_ = 0;
|
||||||
|
} else if (dir == SCROLL_DIR::LEFT || dir == SCROLL_DIR::RIGHT) {
|
||||||
|
distance_scrolled_x_ = 0;
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
}
|
}
|
||||||
|
// Silence -Wreturn-type:
|
||||||
if (distance_scrolled_y_ < -threshold) {
|
default: return SCROLL_DIR::NONE;
|
||||||
dir = SCROLL_DIR::UP;
|
|
||||||
} else if (distance_scrolled_y_ > threshold) {
|
|
||||||
dir = SCROLL_DIR::DOWN;
|
|
||||||
} else if (distance_scrolled_x_ > threshold) {
|
|
||||||
dir = SCROLL_DIR::RIGHT;
|
|
||||||
} else if (distance_scrolled_x_ < -threshold) {
|
|
||||||
dir = SCROLL_DIR::LEFT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::DOWN) {
|
|
||||||
distance_scrolled_y_ = 0;
|
|
||||||
} else if (dir == SCROLL_DIR::LEFT || dir == SCROLL_DIR::RIGHT) {
|
|
||||||
distance_scrolled_x_ = 0;
|
|
||||||
}
|
|
||||||
return dir;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue