diff options
-rw-r--r-- | crawl-ref/source/command.cc | 8 | ||||
-rw-r--r-- | crawl-ref/source/menu.cc | 61 | ||||
-rw-r--r-- | crawl-ref/source/menu.h | 5 |
3 files changed, 74 insertions, 0 deletions
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc index 771012383a..fd38e95970 100644 --- a/crawl-ref/source/command.cc +++ b/crawl-ref/source/command.cc @@ -629,6 +629,14 @@ static void add_file_to_scroller(FILE* fp, formatted_scroller& m, bool next_is_hotkey = false; bool is_first = true; char buf[200]; + + // bracket with MEL_TITLES, so that you won't scroll + // into it or above it + m.add_entry(new MenuEntry(std::string(), MEL_TITLE)); + for ( int i = 0; i < get_number_of_lines(); ++i ) + m.add_entry(new MenuEntry(std::string())); + m.add_entry(new MenuEntry(std::string(), MEL_TITLE)); + while (fgets(buf, sizeof buf, fp)) { MenuEntry* me = new MenuEntry(buf); diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 7d35711662..4531e35766 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -1161,6 +1161,67 @@ bool formatted_scroller::jump_to( int i ) return true; } +// Don't scroll past MEL_TITLE entries +bool formatted_scroller::page_down() +{ + const int old_first = first_entry; + + if ( (int)items.size() <= first_entry + pagesize ) + return false; + + // If, when scrolling forward, we encounter a MEL_TITLE + // somewhere in the newly displayed page, stop scrolling + // just before it becomes visible + int target; + for (target = first_entry; target < first_entry + pagesize; ++target ) + { + const int offset = target + pagesize - 1; + if (offset < (int)items.size() && items[offset]->level == MEL_TITLE) + break; + } + first_entry = target; + return (old_first != first_entry); +} + +bool formatted_scroller::page_up() +{ + int old_first = first_entry; + + // If, when scrolling backward, we encounter a MEL_TITLE + // somewhere in the newly displayed page, stop scrolling + // just before it becomes visible + + + for ( int i = 0; i < pagesize; ++i ) + { + if (first_entry == 0 || items[first_entry-1]->level == MEL_TITLE) + break; + --first_entry; + } + return (old_first != first_entry); +} + +bool formatted_scroller::line_down() +{ + if (first_entry + pagesize < (int) items.size() && + items[first_entry + pagesize]->level != MEL_TITLE ) + { + ++first_entry; + return true; + } + return false; +} + +bool formatted_scroller::line_up() +{ + if (first_entry > 0 && items[first_entry-1]->level != MEL_TITLE) + { + --first_entry; + return true; + } + return false; +} + bool formatted_scroller::process_key( int keyin ) { diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index 9d58fa4158..84e0d44df4 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -360,6 +360,11 @@ public: virtual void add_text(const std::string& s); virtual ~formatted_scroller(); protected: + virtual bool page_down(); + virtual bool line_down(); + virtual bool page_up(); + virtual bool line_up(); + virtual void draw_index_item(int index, const MenuEntry* me) const; virtual bool process_key( int keyin ); bool jump_to( int linenum ); |