summaryrefslogtreecommitdiffstats
path: root/apps/plugins/lua/rockaux.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/rockaux.c')
-rw-r--r--apps/plugins/lua/rockaux.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/apps/plugins/lua/rockaux.c b/apps/plugins/lua/rockaux.c
index 734b6a8324..7ed82f616d 100644
--- a/apps/plugins/lua/rockaux.c
+++ b/apps/plugins/lua/rockaux.c
@@ -41,6 +41,122 @@ char *strerror(int errnum)
return NULL;
}
+/* splash string and allow user to scroll around
+ * provides rudimentary text reflow
+ * timeout is disabled on user interaction
+ * returns the action that caused quit
+ * [ACTION_NONE, ACTION_STD_CANCEL, ACTION_STD_OK]
+ * !ACTION_NONE (only on initial timeout)!
+ * TIMEOUT can be TIMEOUT_BLOCK or time in ticks
+*/
+int splash_scroller(int timeout, const char* str)
+{
+ int w, ch_w, ch_h;
+ rb->lcd_getstringsize("W", &ch_w, &ch_h);
+
+ const int max_w = LCD_WIDTH - (ch_w * 2);
+ const int max_lines = LCD_HEIGHT / ch_h - 1;
+ const int wrap_thresh = (LCD_WIDTH / 3);
+ const char *ch;
+ char *brk;
+
+ const int max_ch = (LCD_WIDTH / ch_w - 1) * 2;
+ char line[max_ch + 2]; /* display buffer */
+ const char break_chars[] = "@#$%^&*+-{}[]()/\\|<>:;.,? _\n\r\t";
+
+ int linepos, curline, linesdisp, realline, chars_next_break;
+ int action = ACTION_NONE;
+ int firstline = 0;
+ int cycles = 2; /* get action timeout returns immediately on first call */
+
+ while (cycles > 0)
+ {
+ /* walk whole buffer every refresh, only display relevant portion */
+ rb->lcd_clear_display();
+ curline = 0;
+ linepos = 0;
+ linesdisp = 0;
+ ch = str;
+ for (; *ch && linepos < max_ch; ch++)
+ {
+ if (ch[0] == '\t')
+ {
+ line[linepos++] = ' ';
+ line[linepos] = ' ';
+ }
+ else if (ch[0] == '\b' && timeout > 0)
+ {
+ line[linepos] = ' ';
+ rb->beep_play(1000, HZ, 1000);
+ }
+ else if (ch[0] < ' ') /* Dont copy control characters */
+ line[linepos] = (linepos == 0) ? '\0' : ' ';
+ else
+ line[linepos] = ch[0];
+
+ line[linepos + 1] = '\0'; /* terminate to check text extent */
+ rb->lcd_getstringsize(line, &w, NULL);
+
+ /* try to not split in middle of words */
+ if (w + wrap_thresh >= max_w && strpbrk (&line[linepos], break_chars))
+ {
+ brk = strpbrk(ch+1, break_chars);
+ chars_next_break = (brk - ch);
+ if (chars_next_break < 2 || w + (ch_w * chars_next_break) > max_w)
+ {
+ if (!isprint(line[linepos]))
+ {
+ line[linepos] = '\0';
+ ch--; /* back-up we want it on the next line */
+ }
+ w += max_w;
+ }
+ }
+
+ if (w > max_w ||
+ (ch[0] >= '\n' && iscntrl(ch[0])) ||
+ ch[1] == '\0')
+ {
+ realline = curline - firstline;
+ if (realline >= 0 && realline < max_lines)
+ {
+ rb->lcd_putsxy(0, realline * ch_h, line);
+ linesdisp++;
+ }
+ linepos = 0;
+ curline++;
+ continue;
+ }
+ linepos++;
+ }
+
+ rb->lcd_update();
+
+ action = rb->get_action(CONTEXT_STD, timeout);
+ switch(action)
+ {
+ case ACTION_STD_OK:
+ case ACTION_STD_CANCEL:
+ cycles--;
+ /* Fall Through */
+ case ACTION_NONE:
+ cycles--;
+ break;
+ case ACTION_STD_PREV:
+ timeout = TIMEOUT_BLOCK; /* disable timeout */
+ if(firstline > 0)
+ firstline--;
+ break;
+ case ACTION_STD_NEXT:
+ timeout = TIMEOUT_BLOCK; /* disable timeout */
+ if (linesdisp == max_lines)
+ firstline++;
+ break;
+ }
+ }
+ return action;
+}
+
long rb_pow(long x, long n)
{
long pow = 1;