summaryrefslogtreecommitdiff
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)
41 return NULL; 41 return NULL;
42} 42}
43 43
44/* splash string and allow user to scroll around
45 * provides rudimentary text reflow
46 * timeout is disabled on user interaction
47 * returns the action that caused quit
48 * [ACTION_NONE, ACTION_STD_CANCEL, ACTION_STD_OK]
49 * !ACTION_NONE (only on initial timeout)!
50 * TIMEOUT can be TIMEOUT_BLOCK or time in ticks
51*/
52int splash_scroller(int timeout, const char* str)
53{
54 int w, ch_w, ch_h;
55 rb->lcd_getstringsize("W", &ch_w, &ch_h);
56
57 const int max_w = LCD_WIDTH - (ch_w * 2);
58 const int max_lines = LCD_HEIGHT / ch_h - 1;
59 const int wrap_thresh = (LCD_WIDTH / 3);
60 const char *ch;
61 char *brk;
62
63 const int max_ch = (LCD_WIDTH / ch_w - 1) * 2;
64 char line[max_ch + 2]; /* display buffer */
65 const char break_chars[] = "@#$%^&*+-{}[]()/\\|<>:;.,? _\n\r\t";
66
67 int linepos, curline, linesdisp, realline, chars_next_break;
68 int action = ACTION_NONE;
69 int firstline = 0;
70 int cycles = 2; /* get action timeout returns immediately on first call */
71
72 while (cycles > 0)
73 {
74 /* walk whole buffer every refresh, only display relevant portion */
75 rb->lcd_clear_display();
76 curline = 0;
77 linepos = 0;
78 linesdisp = 0;
79 ch = str;
80 for (; *ch && linepos < max_ch; ch++)
81 {
82 if (ch[0] == '\t')
83 {
84 line[linepos++] = ' ';
85 line[linepos] = ' ';
86 }
87 else if (ch[0] == '\b' && timeout > 0)
88 {
89 line[linepos] = ' ';
90 rb->beep_play(1000, HZ, 1000);
91 }
92 else if (ch[0] < ' ') /* Dont copy control characters */
93 line[linepos] = (linepos == 0) ? '\0' : ' ';
94 else
95 line[linepos] = ch[0];
96
97 line[linepos + 1] = '\0'; /* terminate to check text extent */
98 rb->lcd_getstringsize(line, &w, NULL);
99
100 /* try to not split in middle of words */
101 if (w + wrap_thresh >= max_w && strpbrk (&line[linepos], break_chars))
102 {
103 brk = strpbrk(ch+1, break_chars);
104 chars_next_break = (brk - ch);
105 if (chars_next_break < 2 || w + (ch_w * chars_next_break) > max_w)
106 {
107 if (!isprint(line[linepos]))
108 {
109 line[linepos] = '\0';
110 ch--; /* back-up we want it on the next line */
111 }
112 w += max_w;
113 }
114 }
115
116 if (w > max_w ||
117 (ch[0] >= '\n' && iscntrl(ch[0])) ||
118 ch[1] == '\0')
119 {
120 realline = curline - firstline;
121 if (realline >= 0 && realline < max_lines)
122 {
123 rb->lcd_putsxy(0, realline * ch_h, line);
124 linesdisp++;
125 }
126 linepos = 0;
127 curline++;
128 continue;
129 }
130 linepos++;
131 }
132
133 rb->lcd_update();
134
135 action = rb->get_action(CONTEXT_STD, timeout);
136 switch(action)
137 {
138 case ACTION_STD_OK:
139 case ACTION_STD_CANCEL:
140 cycles--;
141 /* Fall Through */
142 case ACTION_NONE:
143 cycles--;
144 break;
145 case ACTION_STD_PREV:
146 timeout = TIMEOUT_BLOCK; /* disable timeout */
147 if(firstline > 0)
148 firstline--;
149 break;
150 case ACTION_STD_NEXT:
151 timeout = TIMEOUT_BLOCK; /* disable timeout */
152 if (linesdisp == max_lines)
153 firstline++;
154 break;
155 }
156 }
157 return action;
158}
159
44long rb_pow(long x, long n) 160long rb_pow(long x, long n)
45{ 161{
46 long pow = 1; 162 long pow = 1;