|
| 1 | +#include <cmoc.h> |
| 2 | +#include <coco.h> |
| 3 | +#include <fujinet-fuji.h> |
| 4 | +#include "../constants.h" |
| 5 | +#include "../globals.h" |
| 6 | +#include "../screen.h" |
| 7 | +#include "scroll.h" |
| 8 | + |
| 9 | +word lastTimer; |
| 10 | +word idleCounter = IDLE_TIMEOUT_COUNT; |
| 11 | +int scrollOffset = 0; |
| 12 | +int scrollDir = 1; // 1 = right, -1 = left |
| 13 | +byte got_scrolltext; |
| 14 | + |
| 15 | + |
| 16 | +// Draw one line of up to 32 chars from given offset (bounce mode) |
| 17 | +void scroll_draw_line_at_y(const char *line, byte y, int offset) |
| 18 | +{ |
| 19 | + char buf[SCREEN_WIDTH + 1]; |
| 20 | + int len = strlen(line); |
| 21 | + |
| 22 | + memset(buf, ' ', SCREEN_WIDTH); |
| 23 | + buf[SCREEN_WIDTH] = 0; |
| 24 | + |
| 25 | + if (offset < len) |
| 26 | + { |
| 27 | + int copyLen = len - offset; |
| 28 | + if (copyLen > SCREEN_WIDTH) |
| 29 | + copyLen = SCREEN_WIDTH; |
| 30 | + memcpy(buf, line + offset, copyLen); |
| 31 | + } |
| 32 | + |
| 33 | + locate(0, y+3); // Need to add offset for file choice screen |
| 34 | + putstr(buf, SCREEN_WIDTH); |
| 35 | + bar_draw(y+3, false); |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | +// Scroll the currently highlighted line by 1 character (bounce mode) |
| 40 | +void scroll_step(void) |
| 41 | +{ |
| 42 | + byte y = (byte) bar_get(); |
| 43 | + if (!got_scrolltext) |
| 44 | + { |
| 45 | + // Get the full text to scroll |
| 46 | + select_get_filename(255); |
| 47 | + got_scrolltext = true; |
| 48 | + } |
| 49 | + |
| 50 | + int len = strlen(response); |
| 51 | + |
| 52 | + if (len <= SCREEN_WIDTH) |
| 53 | + return; // no need to scroll |
| 54 | + |
| 55 | + scrollOffset += scrollDir; |
| 56 | + if (scrollOffset < 0) |
| 57 | + { |
| 58 | + scrollOffset = 0; |
| 59 | + scrollDir = 1; |
| 60 | + } |
| 61 | + else if (scrollOffset > len - SCREEN_WIDTH) |
| 62 | + { |
| 63 | + scrollOffset = len - SCREEN_WIDTH; |
| 64 | + scrollDir = -1; |
| 65 | + } |
| 66 | + |
| 67 | + scroll_draw_line_at_y(response, y, scrollOffset); |
| 68 | +} |
| 69 | + |
| 70 | +// Reset scrolling when user interacts, |
| 71 | +// Or initial zetup |
| 72 | +void scroll_reset(bool init) |
| 73 | +{ |
| 74 | + byte y = (byte)bar_get(); |
| 75 | + scrollOffset = 0; |
| 76 | + scrollDir = 1; |
| 77 | + idleCounter = IDLE_TIMEOUT_COUNT; |
| 78 | + if (init) |
| 79 | + { |
| 80 | + lastTimer = 0; |
| 81 | + } |
| 82 | + else |
| 83 | + { |
| 84 | + if (got_scrolltext && strlen(response) > SCREEN_WIDTH) |
| 85 | + { |
| 86 | + // Get the short version of the text again |
| 87 | + select_get_filename(DIR_MAX_LEN); |
| 88 | + |
| 89 | + screen_select_file_display_entry(y, response, 0); |
| 90 | + } |
| 91 | + } |
| 92 | + got_scrolltext = false; |
| 93 | +} |
0 commit comments