diff --git a/include/Headers.hpp b/include/Headers.hpp index 1da2c0f..7f48a2e 100644 --- a/include/Headers.hpp +++ b/include/Headers.hpp @@ -7,5 +7,6 @@ #include #include #include +#include #include "Log.hpp" diff --git a/include/Roster.hpp b/include/Roster.hpp index 14cc283..7393069 100644 --- a/include/Roster.hpp +++ b/include/Roster.hpp @@ -90,13 +90,14 @@ class Roster: public Window { std::string get_active_name(); private: - void mute_current(int&); + void mute_current(int current); void mute_all(); RosterItem& get_roster(int); void draw_user(int i, RosterItem &user); - void scroll_down(int ¤t_active); - void scroll_up(int ¤t_active); - void scroll_helper(int dir, int &pos); + void draw_users(int start, int num); + void scroll_down(int lines); + void scroll_up(int lines); + void scroll_helper(int dir); int active = -1; int delta = 0; diff --git a/src/Roster.cpp b/src/Roster.cpp index 64ecbd9..bc32fac 100644 --- a/src/Roster.cpp +++ b/src/Roster.cpp @@ -85,21 +85,25 @@ int Roster::wait(Session &sess) { #endif c = wgetch(win); - switch (c) { + switch (tolower(c)) { case KEY_UP: - scroll_up(current_active); + scroll_up(1); break; case KEY_DOWN: - scroll_down(current_active); + scroll_down(1); break; case KEY_ESC: return c; // value to return in case of ESC + case KEY_PPAGE: + scroll_up(current_active); + break; + case KEY_NPAGE: + scroll_down(users.size() - current_active - 1); + break; case 'm': - case 'M': mute_current(current_active); break; case 'n': - case 'N': mute_all(); break; case KEY_ENT: @@ -119,9 +123,9 @@ int Roster::wait(Session &sess) { /* scroll up and down events associated with mouse wheel */ #if NCURSES_MOUSE_VERSION > 1 else if (event.bstate & BUTTON4_PRESSED) { - scroll_up(current_active); + scroll_up(1); } else if (event.bstate & BUTTON5_PRESSED) { - scroll_down(current_active); + scroll_down(1); } #endif } @@ -145,37 +149,57 @@ void Roster::set_current_active() { current_active = active; } -void Roster::scroll_down(int ¤t_active) { - if (current_active < users.size() - 1) { +void Roster::scroll_down(int lines) { + if (current_active < users.size() - lines) { mvwprintw(win, current_active + 1 - delta, 1, " "); - current_active++; - if (current_active - get_real_rows() >= delta) { - scroll_helper(1, current_active); + int old_delta = delta; + while (lines > 0) { + current_active++; + if (current_active - get_real_rows() >= delta) { + delta++; + } + lines--; + } + if (delta != old_delta) { + scroll_helper(delta - old_delta); + draw_users(current_active + 1 - (delta - old_delta), delta - old_delta); } mvwprintw(win, current_active + 1 - delta, 1, "*"); } } -void Roster::scroll_up(int ¤t_active) { +void Roster::scroll_up(int lines) { if (current_active > 0) { mvwprintw(win, current_active + 1 - delta, 1, " "); - current_active--; - if (current_active < delta) { - scroll_helper(-1, current_active); + int old_delta = delta; + while (lines > 0) { + current_active--; + if (current_active < delta) { + delta--; + } + lines--; + } + if (delta != old_delta) { + scroll_helper(delta - old_delta); + draw_users(delta, old_delta - delta); } mvwprintw(win, current_active + 1 - delta, 1, "*"); } } -void Roster::scroll_helper(int dir, int &pos) { +void Roster::scroll_helper(int dir) { wborder(win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); wscrl(win, dir); wattroff(win, A_BOLD); draw_borders(); wattron(win, A_BOLD); - delta += dir; - RosterItem &user = get_roster(pos); - draw_user(pos, user); +} + +void Roster::draw_users(int start, int num) { + for (int i = 0; i < num && start + i < users.size(); i++) { + RosterItem &user = get_roster(start + i); + draw_user(start + i, user); + } } void Roster::remove_highlight() { @@ -199,7 +223,7 @@ RosterItem& Roster::get_roster(int x) { return it->second; } -void Roster::mute_current(int& current) { +void Roster::mute_current(int current) { RosterItem &x = get_roster(current); x.muted = !x.muted; if (current - delta < get_real_rows() && current >= delta) { diff --git a/src/SlackUI.cpp b/src/SlackUI.cpp index 187cafb..d5775ce 100644 --- a/src/SlackUI.cpp +++ b/src/SlackUI.cpp @@ -102,7 +102,7 @@ void SlackUI::main_ui_cycle() { case KEY_TAB: change_context(); active_win = roster.get(); - break; + break; case KEY_UP: scroll_up(); break;