diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/lua/include_lua/print.lua | 165 | ||||
-rw-r--r-- | apps/plugins/lua/include_lua/printmenus.lua | 249 | ||||
-rw-r--r-- | apps/plugins/lua/include_lua/printtable.lua | 63 | ||||
-rw-r--r-- | apps/plugins/lua/lua.make | 2 | ||||
-rwxr-xr-x | apps/plugins/lua/rbdefines_helper.pl | 1 | ||||
-rw-r--r-- | apps/plugins/lua/rocklib_img.c | 148 | ||||
-rw-r--r-- | apps/plugins/lua_scripts.lua | 22 | ||||
-rw-r--r-- | apps/plugins/lua_scripts/file_browser.lua | 2 | ||||
-rwxr-xr-x | apps/plugins/lua_scripts/fileview.lua | 2 | ||||
-rwxr-xr-x | apps/plugins/lua_scripts/fileviewers.lua | 3 | ||||
-rwxr-xr-x | apps/plugins/lua_scripts/printmenu.lua | 83 | ||||
-rwxr-xr-x | apps/plugins/lua_scripts/rlimg.lua | 2 | ||||
-rw-r--r-- | apps/plugins/lua_scripts/tagnav.lua | 2 |
13 files changed, 581 insertions, 163 deletions
diff --git a/apps/plugins/lua/include_lua/print.lua b/apps/plugins/lua/include_lua/print.lua index 3fb19bef1f..3b4c389848 100644 --- a/apps/plugins/lua/include_lua/print.lua +++ b/apps/plugins/lua/include_lua/print.lua | |||
@@ -123,6 +123,49 @@ local _print = {} do | |||
123 | return w, h, msg | 123 | return w, h, msg |
124 | end | 124 | end |
125 | -------------------------------------------------------------------------------- | 125 | -------------------------------------------------------------------------------- |
126 | local function set_linedesc(t_linedesc, opts) | ||
127 | local o = opts or _print.opt.get(true) | ||
128 | --local out = function() local t = {} for k, v in pairs(o) do t[#t + 1] = tostring(k) t[#t + 1] = tostring(v) end return table.concat(t, "\n") end | ||
129 | --rb.splash_scroller(1000, out()) | ||
130 | local linedesc ={ | ||
131 | --These are the defaults - changes will be made below if you supplied t_linedesc | ||
132 | indent = 0, -- internal indent text | ||
133 | line = 0, -- line index within group | ||
134 | nlines = 1, -- selection grouping | ||
135 | offset = 0, -- internal item offset | ||
136 | scroll = true, | ||
137 | selected = false, --internal | ||
138 | separator_height = 0, | ||
139 | line_separator = false, | ||
140 | show_cursor = false, | ||
141 | show_icons = false, | ||
142 | icon = -1, | ||
143 | icon_fn = function() return -1 end, | ||
144 | style = rb.STYLE_COLORBAR, | ||
145 | text_color = o.fg_pattern or WHITE, | ||
146 | line_color = o.bg_pattern or BLACK, | ||
147 | line_end_color= o.bg_pattern or BLACK, | ||
148 | } | ||
149 | if type(t_linedesc) == "table" then | ||
150 | |||
151 | if not o.linedesc then | ||
152 | o.linedesc = {} | ||
153 | for k, v in pairs(linedesc) do | ||
154 | o.linedesc[k] = v | ||
155 | end | ||
156 | end | ||
157 | |||
158 | for k, v in pairs(t_linedesc) do | ||
159 | o.linedesc[k] = v | ||
160 | end | ||
161 | if o.linedesc.separator_height > 0 then | ||
162 | o.linedesc.line_separator = true | ||
163 | end | ||
164 | return | ||
165 | end | ||
166 | o.linedesc = linedesc | ||
167 | return o.linedesc | ||
168 | end | ||
126 | 169 | ||
127 | -- set defaults for print view | 170 | -- set defaults for print view |
128 | local function set_defaults() | 171 | local function set_defaults() |
@@ -138,11 +181,13 @@ local _print = {} do | |||
138 | line = 1, | 181 | line = 1, |
139 | max_line = _NIL, | 182 | max_line = _NIL, |
140 | col = 0, | 183 | col = 0, |
141 | ovfl = "auto", | 184 | header = false, --Internal use - treats first entry as header |
142 | justify = "left", | 185 | ovfl = "auto", -- auto, manual, none |
143 | autoupdate = true, | 186 | justify = "left", --left, center, right |
144 | drawsep = false, | 187 | autoupdate = true, --updates screen as items are added |
188 | drawsep = false, -- separator between items | ||
145 | } | 189 | } |
190 | set_linedesc(nil, _p_opts) -- default line display | ||
146 | _p_opts.max_line = max_lines(_p_opts) | 191 | _p_opts.max_line = max_lines(_p_opts) |
147 | 192 | ||
148 | s_lines, col_buf = {}, {} | 193 | s_lines, col_buf = {}, {} |
@@ -187,29 +232,16 @@ local _print = {} do | |||
187 | 232 | ||
188 | -- helper function sets up colors/marker for selected items | 233 | -- helper function sets up colors/marker for selected items |
189 | local function show_selected(iLine, msg) | 234 | local function show_selected(iLine, msg) |
190 | local o = get_settings() -- using a copy of opts so changes revert | ||
191 | |||
192 | if s_lines[iLine] == true then | ||
193 | if not rb.lcd_set_background then | ||
194 | o.drawmode = bit.bxor(o.drawmode, 4) | ||
195 | else | ||
196 | o.fg_pattern = o.bg_pattern | ||
197 | o.bg_pattern = o.sel_pattern | ||
198 | end | ||
199 | -- alternative selection method | ||
200 | --msg = "> " .. msg | ||
201 | end | ||
202 | |||
203 | if not o then rb.set_viewport() return end | ||
204 | |||
205 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens | 235 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens |
236 | local o = get_settings() -- using a copy of opts so changes revert | ||
237 | if not o then rb.set_viewport() return end | ||
206 | o.fg_pattern = 3 - o.fg_pattern | 238 | o.fg_pattern = 3 - o.fg_pattern |
207 | o.bg_pattern = 3 - o.bg_pattern | 239 | o.bg_pattern = 3 - o.bg_pattern |
240 | rb.set_viewport(o) | ||
241 | o = _NIL | ||
242 | else | ||
243 | show_selected = function() end -- no need to check again | ||
208 | end | 244 | end |
209 | |||
210 | rb.set_viewport(o) | ||
211 | |||
212 | o = _NIL | ||
213 | end | 245 | end |
214 | 246 | ||
215 | -- sets line explicitly or increments line if line is _NIL | 247 | -- sets line explicitly or increments line if line is _NIL |
@@ -274,31 +306,82 @@ local _print = {} do | |||
274 | s_lines[iLine] = true | 306 | s_lines[iLine] = true |
275 | end | 307 | end |
276 | 308 | ||
277 | -- Internal print function | 309 | -- Internal print function |
278 | local function print_internal(t_opts, x, w, h, msg) | 310 | local function print_internal(t_opts, x, w, h, msg) |
279 | 311 | ||
312 | local linedesc | ||
313 | local line_separator = false | ||
280 | local o = t_opts | 314 | local o = t_opts |
281 | if o.justify == "center" then | 315 | local ld = o.linedesc or set_linedesc() |
282 | x = x + (o.width - w) / 2 | 316 | local show_cursor = ld.show_cursor or 0 |
283 | elseif o.justify == "right" then | 317 | local line_indent = 0 |
284 | x = x + (o.width - w) | 318 | |
319 | local linestyle = ld.style or rb.STYLE_COLORBAR | ||
320 | |||
321 | if o.justify ~= "left" then | ||
322 | line_indent = (o.width - w) --"right" | ||
323 | if o.justify == "center" then | ||
324 | line_indent = line_indent / 2 | ||
325 | end | ||
285 | end | 326 | end |
286 | 327 | ||
287 | local line = o.line - 1 -- rb is 0-based lua is 1-based | 328 | local line = o.line - 1 -- rb is 0-based lua is 1-based |
288 | if(o.ovfl == "auto" and w >= o.width) then -- -o.x | 329 | |
289 | rb.lcd_puts_scroll(0, line, msg) | 330 | if o.ovfl == "manual" then --save msg for later side scroll |
331 | col_buf_insert(msg, o.line, o) | ||
332 | end | ||
333 | |||
334 | -- bit of a pain to set the fields this way but its much more efficient than iterating a table to set them | ||
335 | local function set_desc(tld, scroll, separator_height, selected, style, indent, text_color, line_color, line_end_color) | ||
336 | tld.scroll = scroll | ||
337 | tld.separator_height = separator_height | ||
338 | tld.selected = selected | ||
339 | tld.style = style | ||
340 | tld.indent = indent | ||
341 | tld.text_color = text_color | ||
342 | tld.line_color = line_color | ||
343 | tld.line_end_color = line_end_color | ||
344 | end | ||
345 | |||
346 | line_separator = ld.line_separator | ||
347 | |||
348 | if o.line == 1 and o.header then | ||
349 | --rb scroller doesn't like negative offset! | ||
350 | local indent = line_indent < 0 and 0 or line_indent | ||
351 | set_desc(ld, true, 1, false, rb.STYLE_DEFAULT, | ||
352 | indent, o.fg_pattern, o.bg_pattern, o.bg_pattern) | ||
353 | ld.show_cursor = false | ||
354 | elseif s_lines[o.line] then | ||
355 | --/* Display line selector */ | ||
356 | local style = show_cursor == true and rb.STYLE_DEFAULT or linestyle | ||
357 | |||
358 | local indent = line_indent < 0 and 0 or line_indent | ||
359 | --rb scroller doesn't like negative offset! | ||
360 | local ovfl = (o.ovfl == "auto" and w >= o.width and x == 0) | ||
361 | set_desc(ld, ovfl, 0, true, style, indent, | ||
362 | o.bg_pattern, o.sel_pattern, o.sel_pattern) | ||
290 | else | 363 | else |
291 | rb.lcd_putsxy(x, line * h, msg) | 364 | set_desc(ld, false, 0, false, rb.STYLE_DEFAULT,line_indent, |
292 | if o.ovfl == "manual" then --save msg for later side scroll | 365 | o.fg_pattern, o.bg_pattern, o.bg_pattern) |
293 | col_buf_insert(msg, o.line, o) | ||
294 | end | ||
295 | end | 366 | end |
296 | if o.drawsep == true then | 367 | |
297 | if s_lines[o.line] == true then | 368 | if ld.show_icons then |
298 | rb.set_viewport(o) --nned to revert drawmode if selected | 369 | ld.icon = ld.icon_fn(line, ld.icon or -1) |
370 | end | ||
371 | |||
372 | rb.lcd_put_line(x, line *h, msg, ld) | ||
373 | |||
374 | ld.show_cursor = show_cursor | ||
375 | ld.style = linestyle | ||
376 | if line_separator then | ||
377 | if ld.selected == true then | ||
378 | rb.set_viewport(o) -- revert drawmode if selected | ||
299 | end | 379 | end |
300 | rb.lcd_drawline(0, line * h, o.width, line * h) | 380 | rb.lcd_drawline(0, line * h, o.width, line * h) |
381 | rb.lcd_drawline(0, line * h + h, o.width, line * h + h) --only to add the last line | ||
382 | -- but we don't have an idea which line is the last line here so every line is the last line! | ||
301 | end | 383 | end |
384 | |||
302 | --only update the line we changed | 385 | --only update the line we changed |
303 | update_line(o.autoupdate, o, line, h) | 386 | update_line(o.autoupdate, o, line, h) |
304 | 387 | ||
@@ -308,7 +391,7 @@ local _print = {} do | |||
308 | -- Helper function that acts mostly like a normal printf() would | 391 | -- Helper function that acts mostly like a normal printf() would |
309 | local function printf(fmt, v1, ...) | 392 | local function printf(fmt, v1, ...) |
310 | local o = get_settings(true) | 393 | local o = get_settings(true) |
311 | local w, h, msg | 394 | local w, h, msg, rep |
312 | local line = o.line - 1 -- rb is 0-based lua is 1-based | 395 | local line = o.line - 1 -- rb is 0-based lua is 1-based |
313 | 396 | ||
314 | if not (fmt) or (fmt) == "\n" then -- handles blank line / single '\n' | 397 | if not (fmt) or (fmt) == "\n" then -- handles blank line / single '\n' |
@@ -322,6 +405,9 @@ local _print = {} do | |||
322 | return o.line, o.max_line, o.width, h | 405 | return o.line, o.max_line, o.width, h |
323 | end | 406 | end |
324 | 407 | ||
408 | fmt, rep = fmt.gsub(fmt or "", "%%h", "%%s") | ||
409 | o.header = (rep == 1) | ||
410 | |||
325 | msg = string.format(fmt, v1, ...) | 411 | msg = string.format(fmt, v1, ...) |
326 | 412 | ||
327 | show_selected(o.line, msg) | 413 | show_selected(o.line, msg) |
@@ -337,6 +423,8 @@ local _print = {} do | |||
337 | local function set_column(x) | 423 | local function set_column(x) |
338 | local o = get_settings() | 424 | local o = get_settings() |
339 | if o.ovfl ~= "manual" then return end -- no buffer stored to scroll | 425 | if o.ovfl ~= "manual" then return end -- no buffer stored to scroll |
426 | rb.lcd_scroll_stop() | ||
427 | |||
340 | local res, w, h, str, line | 428 | local res, w, h, str, line |
341 | 429 | ||
342 | for key, value in pairs(col_buf) do | 430 | for key, value in pairs(col_buf) do |
@@ -367,6 +455,7 @@ local _print = {} do | |||
367 | _print.opt.justify = set_justify | 455 | _print.opt.justify = set_justify |
368 | _print.opt.sel_line = select_line | 456 | _print.opt.sel_line = select_line |
369 | _print.opt.line = set_line | 457 | _print.opt.line = set_line |
458 | _print.opt.linedesc = set_linedesc | ||
370 | _print.opt.autoupdate = set_update | 459 | _print.opt.autoupdate = set_update |
371 | _print.clear = clear | 460 | _print.clear = clear |
372 | _print.f = printf | 461 | _print.f = printf |
diff --git a/apps/plugins/lua/include_lua/printmenus.lua b/apps/plugins/lua/include_lua/printmenus.lua new file mode 100644 index 0000000000..3e8f870104 --- /dev/null +++ b/apps/plugins/lua/include_lua/printmenus.lua | |||
@@ -0,0 +1,249 @@ | |||
1 | --[[ | ||
2 | /*************************************************************************** | ||
3 | * __________ __ ___. | ||
4 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
5 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
8 | * \/ \/ \/ \/ \/ | ||
9 | * $Id$ | ||
10 | * | ||
11 | * Copyright (C) 2017 William Wilgus | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | ]] | ||
23 | if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end | ||
24 | |||
25 | require("printtable") | ||
26 | |||
27 | local _clr = require("color") | ||
28 | |||
29 | local _LCD = rb.lcd_framebuffer() | ||
30 | |||
31 | --[[ -- dpad requires: | ||
32 | require("actions") -- Contains rb.actions & rb.contexts | ||
33 | local _timer = require("timer") | ||
34 | -- Button definitions -- | ||
35 | local CANCEL_BUTTON = rb.actions.PLA_CANCEL | ||
36 | local DOWN_BUTTON = rb.actions.PLA_DOWN | ||
37 | local DOWNR_BUTTON = rb.actions.PLA_DOWN_REPEAT | ||
38 | local EXIT_BUTTON = rb.actions.PLA_EXIT | ||
39 | local LEFT_BUTTON = rb.actions.PLA_LEFT | ||
40 | local LEFTR_BUTTON = rb.actions.PLA_LEFT_REPEAT | ||
41 | local RIGHT_BUTTON = rb.actions.PLA_RIGHT | ||
42 | local RIGHTR_BUTTON = rb.actions.PLA_RIGHT_REPEAT | ||
43 | local SEL_BUTTON = rb.actions.PLA_SELECT | ||
44 | local SELREL_BUTTON = rb.actions.PLA_SELECT_REL | ||
45 | local SELR_BUTTON = rb.actions.PLA_SELECT_REPEAT | ||
46 | local UP_BUTTON = rb.actions.PLA_UP | ||
47 | local UPR_BUTTON = rb.actions.PLA_UP_REPEAT | ||
48 | ]] | ||
49 | -------------------------------------------------------------------------------- | ||
50 | local function get_core_settings() | ||
51 | if rb.core_color_table ~= nil and rb.core_talk_table ~= nil and | ||
52 | rb.core_list_settings_table ~= nil then return end | ||
53 | |||
54 | local rbs_is_loaded = (package.loaded.rbsettings ~= nil) | ||
55 | local s_is_loaded = (package.loaded.settings ~= nil) | ||
56 | |||
57 | require("rbsettings") | ||
58 | require("settings") | ||
59 | rb.metadata = nil -- remove track metadata settings | ||
60 | |||
61 | local rb_settings = rb.settings.dump('global_settings', "system") | ||
62 | local color_table = {} | ||
63 | local talk_table = {} | ||
64 | local list_settings_table = {} | ||
65 | local list_settings = "cursor_style|show_icons|statusbar|scrollbar|scrollbar_width|list_separator_height|backdrop_file|" | ||
66 | for key, value in pairs(rb_settings) do | ||
67 | key = key or "" | ||
68 | if (key:find("color")) then | ||
69 | color_table[key]=value | ||
70 | elseif (key:find("talk")) then | ||
71 | talk_table[key]=value | ||
72 | elseif (list_settings:find(key)) then | ||
73 | list_settings_table[key]=value | ||
74 | end | ||
75 | end | ||
76 | |||
77 | if not s_is_loaded then | ||
78 | rb.settings = nil | ||
79 | package.loaded.settings = nil | ||
80 | end | ||
81 | |||
82 | if not rbs_is_loaded then | ||
83 | rb.system = nil | ||
84 | rb.metadata = nil | ||
85 | package.loaded.rbsettings = nil | ||
86 | end | ||
87 | |||
88 | rb.core_color_table = color_table | ||
89 | rb.core_talk_table = talk_table | ||
90 | rb.core_list_settings_table = list_settings_table | ||
91 | collectgarbage("collect") | ||
92 | end | ||
93 | |||
94 | --[[ cursor style button routine | ||
95 | -- left / right are x, xi is increment xir is increment when repeat | ||
96 | -- up / down are y, yi is increment yir is increment when repeat | ||
97 | -- cancel is returned as 0,1 | ||
98 | -- select as 0, 1, 2, 3 (none, pressed, repeat, relesed) | ||
99 | -- x_chg and y_chg are the amount x or y changed | ||
100 | -- timeout == nil or -1 loop waits indefinitely till button is pressed | ||
101 | -- time since last button press is returned in ticks.. | ||
102 | -- make xi, xir, yi, yir negative to flip direction... | ||
103 | ]] | ||
104 | --[[ | ||
105 | local function dpad(x, xi, xir, y, yi, yir, timeout, overflow) | ||
106 | local scroll_is_fixed = overflow ~= "manual" | ||
107 | _timer("dpad") -- start a persistant timer; keeps time between button events | ||
108 | if timeout == nil then timeout = -1 end | ||
109 | local cancel, select = 0, 0 | ||
110 | local x_chg, y_chg = 0, 0 | ||
111 | local button | ||
112 | while true do | ||
113 | button = rb.get_plugin_action(timeout) | ||
114 | |||
115 | if button == CANCEL_BUTTON then | ||
116 | cancel = 1 | ||
117 | break; | ||
118 | elseif button == EXIT_BUTTON then | ||
119 | cancel = 1 | ||
120 | break; | ||
121 | elseif button == SEL_BUTTON then | ||
122 | select = 1 | ||
123 | timeout = timeout + 1 | ||
124 | elseif button == SELR_BUTTON then | ||
125 | select = 2 | ||
126 | timeout = timeout + 1 | ||
127 | elseif button == SELREL_BUTTON then | ||
128 | select = -1 | ||
129 | timeout = timeout + 1 | ||
130 | elseif button == LEFT_BUTTON then | ||
131 | x_chg = x_chg - xi | ||
132 | if scroll_is_fixed then | ||
133 | cancel = 1 | ||
134 | break; | ||
135 | end | ||
136 | elseif button == LEFTR_BUTTON then | ||
137 | x_chg = x_chg - xir | ||
138 | elseif button == RIGHT_BUTTON then | ||
139 | x_chg = x_chg + xi | ||
140 | if scroll_is_fixed then | ||
141 | select = 1 | ||
142 | timeout = timeout + 1 | ||
143 | end | ||
144 | elseif button == RIGHTR_BUTTON then | ||
145 | x_chg = x_chg + xir | ||
146 | elseif button == UP_BUTTON then | ||
147 | y_chg = y_chg + yi | ||
148 | elseif button == UPR_BUTTON then | ||
149 | y_chg = y_chg + yir | ||
150 | elseif button == DOWN_BUTTON then | ||
151 | y_chg = y_chg - yi | ||
152 | elseif button == DOWNR_BUTTON then | ||
153 | y_chg = y_chg - yir | ||
154 | elseif timeout >= 0 then--and rb.button_queue_count() < 1 then | ||
155 | break; | ||
156 | end | ||
157 | |||
158 | if x_chg ~= 0 or y_chg ~= 0 then | ||
159 | timeout = timeout + 1 | ||
160 | end | ||
161 | end | ||
162 | |||
163 | x = x + x_chg | ||
164 | y = y + y_chg | ||
165 | |||
166 | return cancel, select, x_chg, x, y_chg, y, _timer.check("dpad", true) | ||
167 | end -- dpad | ||
168 | ]] | ||
169 | -------------------------------------------------------------------------------- | ||
170 | -- displays text in menu_t calls function in same indice of func_t when selected | ||
171 | function print_menu(menu_t, func_t, selected, settings, copy_screen) | ||
172 | |||
173 | local i, start, vcur, screen_img | ||
174 | |||
175 | if selected then vcur = selected + 1 end | ||
176 | if vcur and vcur <= 1 then vcur = 2 end | ||
177 | |||
178 | get_core_settings() | ||
179 | local c_table = rb.core_color_table or {} | ||
180 | |||
181 | if not settings then | ||
182 | settings = {} | ||
183 | settings.default = true | ||
184 | end | ||
185 | |||
186 | settings.justify = settings.justify or "center" | ||
187 | settings.wrap = settings.wrap or true | ||
188 | settings.hfgc = settings.hfgc or c_table.lst_color or _clr.set( 0, 000, 000, 000) | ||
189 | settings.hbgc = settings.hbgc or c_table.bg_color or _clr.set(-1, 255, 255, 255) | ||
190 | settings.ifgc = settings.ifgc or c_table.fg_color or _clr.set(-1, 000, 255, 060) | ||
191 | settings.ibgc = settings.ibgc or c_table.bg_color or _clr.set( 0, 000, 000, 000) | ||
192 | settings.iselc = settings.iselc or c_table.lss_color or _clr.set( 1, 000, 200, 100) | ||
193 | |||
194 | if not settings.linedesc or rb.core_list_settings_table then | ||
195 | settings.linedesc = settings.linedesc or {} | ||
196 | local t_l = rb.core_list_settings_table | ||
197 | local linedesc = { | ||
198 | separator_height = t_l.list_separator_height or 0, | ||
199 | show_cursor = (t_l.cursor_style or 0) == 0, | ||
200 | style = t_l.cursor_style or 0xFFFF, --just a random non used index | ||
201 | show_icons = t_l.show_icons or false, | ||
202 | text_color = c_table.fg_color or _clr.set(-1, 000, 255, 060), | ||
203 | line_color = c_table.bg_color or _clr.set( 0, 000, 000, 000), | ||
204 | line_end_color= c_table.bg_color or _clr.set( 0, 000, 000, 000), | ||
205 | } | ||
206 | local styles = {rb.STYLE_NONE, rb.STYLE_INVERT, rb.STYLE_GRADIENT, rb.STYLE_COLORBAR, rb.STYLE_DEFAULT} | ||
207 | linedesc.style = styles[linedesc.style + 1] or rb.STYLE_COLORBAR | ||
208 | |||
209 | for k, v in pairs(linedesc) do | ||
210 | --dont overwrite supplied settings | ||
211 | settings.linedesc[k] = settings.linedesc[k] or v | ||
212 | end | ||
213 | end | ||
214 | |||
215 | settings.hasheader = true | ||
216 | settings.co_routine = nil | ||
217 | settings.msel = false | ||
218 | settings.start = start | ||
219 | settings.curpos = vcur | ||
220 | --settings.dpad_fn = dpad | ||
221 | |||
222 | while not i or i > 0 do | ||
223 | if copy_screen == true then | ||
224 | --make a copy of screen for restoration | ||
225 | screen_img = screen_img or rb.new_image() | ||
226 | screen_img:copy(_LCD) | ||
227 | else | ||
228 | screen_img = nil | ||
229 | end | ||
230 | |||
231 | _LCD:clear(settings.ibgc) | ||
232 | |||
233 | settings.start = start | ||
234 | settings.curpos = vcur | ||
235 | |||
236 | i, start, vcur = print_table(menu_t, #menu_t, settings) | ||
237 | --vcur = vcur + 1 | ||
238 | collectgarbage("collect") | ||
239 | if copy_screen == true then _LCD:copy(screen_img) end | ||
240 | |||
241 | if func_t and func_t[i] then | ||
242 | if func_t[i](i, menu_t) == true then break end | ||
243 | else | ||
244 | break | ||
245 | end | ||
246 | end | ||
247 | if settings.default == true then settings = nil end | ||
248 | return screen_img, i | ||
249 | end | ||
diff --git a/apps/plugins/lua/include_lua/printtable.lua b/apps/plugins/lua/include_lua/printtable.lua index b289beeb0e..c23d801f83 100644 --- a/apps/plugins/lua/include_lua/printtable.lua +++ b/apps/plugins/lua/include_lua/printtable.lua | |||
@@ -27,9 +27,9 @@ require("actions") -- Contains rb.actions & rb.contexts | |||
27 | local _clr = require("color") | 27 | local _clr = require("color") |
28 | local _print = require("print") | 28 | local _print = require("print") |
29 | local _timer = require("timer") | 29 | local _timer = require("timer") |
30 | local sb_width = 5 | ||
30 | 31 | ||
31 | -- Button definitions -- | 32 | -- Button definitions -- |
32 | local EXIT_BUTTON = rb.PLA_EXIT | ||
33 | local CANCEL_BUTTON = rb.actions.PLA_CANCEL | 33 | local CANCEL_BUTTON = rb.actions.PLA_CANCEL |
34 | local DOWN_BUTTON = rb.actions.PLA_DOWN | 34 | local DOWN_BUTTON = rb.actions.PLA_DOWN |
35 | local DOWNR_BUTTON = rb.actions.PLA_DOWN_REPEAT | 35 | local DOWNR_BUTTON = rb.actions.PLA_DOWN_REPEAT |
@@ -71,8 +71,8 @@ end | |||
71 | -- time since last button press is returned in ticks.. | 71 | -- time since last button press is returned in ticks.. |
72 | -- make xi, xir, yi, yir negative to flip direction... | 72 | -- make xi, xir, yi, yir negative to flip direction... |
73 | ]] | 73 | ]] |
74 | 74 | local function dpad(x, xi, xir, y, yi, yir, timeout, overflow) | |
75 | local function dpad(x, xi, xir, y, yi, yir, timeout) | 75 | local scroll_is_fixed = overflow ~= "manual" |
76 | _timer("dpad") -- start a persistant timer; keeps time between button events | 76 | _timer("dpad") -- start a persistant timer; keeps time between button events |
77 | if timeout == nil then timeout = -1 end | 77 | if timeout == nil then timeout = -1 end |
78 | local cancel, select = 0, 0 | 78 | local cancel, select = 0, 0 |
@@ -98,10 +98,18 @@ local function dpad(x, xi, xir, y, yi, yir, timeout) | |||
98 | timeout = timeout + 1 | 98 | timeout = timeout + 1 |
99 | elseif button == LEFT_BUTTON then | 99 | elseif button == LEFT_BUTTON then |
100 | x_chg = x_chg - xi | 100 | x_chg = x_chg - xi |
101 | if scroll_is_fixed then | ||
102 | cancel = 1 | ||
103 | break; | ||
104 | end | ||
101 | elseif button == LEFTR_BUTTON then | 105 | elseif button == LEFTR_BUTTON then |
102 | x_chg = x_chg - xir | 106 | x_chg = x_chg - xir |
103 | elseif button == RIGHT_BUTTON then | 107 | elseif button == RIGHT_BUTTON then |
104 | x_chg = x_chg + xi | 108 | x_chg = x_chg + xi |
109 | if scroll_is_fixed then | ||
110 | select = 1 | ||
111 | timeout = timeout + 1 | ||
112 | end | ||
105 | elseif button == RIGHTR_BUTTON then | 113 | elseif button == RIGHTR_BUTTON then |
106 | x_chg = x_chg + xir | 114 | x_chg = x_chg + xir |
107 | elseif button == UP_BUTTON then | 115 | elseif button == UP_BUTTON then |
@@ -152,19 +160,26 @@ function print_table(t, t_count, settings) | |||
152 | end | 160 | end |
153 | 161 | ||
154 | local wrap, justify, start, curpos, co_routine, hasheader, m_sel | 162 | local wrap, justify, start, curpos, co_routine, hasheader, m_sel |
155 | local header_fgc, header_bgc, item_fgc, item_bgc, item_selc, drawsep | 163 | local header_fgc, header_bgc, item_fgc, item_bgc, item_selc |
164 | local table_linedesc, drawsep, overflow, dpad_fn | ||
156 | do | 165 | do |
157 | local s = settings or _print.get_settings() | 166 | local s = settings or _print.get_settings() |
158 | wrap, justify = s.wrap, s.justify | 167 | wrap, justify = s.wrap, s.justify |
159 | start, curpos = s.start, s.curpos | 168 | start, curpos = s.start, s.curpos |
160 | co_routine = s.co_routine | 169 | co_routine = s.co_routine |
161 | hasheader = s.hasheader | 170 | hasheader = s.hasheader |
162 | drawsep = s.drawsep | 171 | drawsep = s.drawsep |
163 | m_sel = false | 172 | sb_width = s.sb_width or sb_width |
173 | m_sel = false | ||
174 | table_linedesc = s.linedesc | ||
175 | dpad_fn = s.dpad_fn | ||
176 | if type(dpad_fn) ~= "function" then dpad_fn = dpad end | ||
177 | |||
164 | if co_routine == nil then | 178 | if co_routine == nil then |
165 | --no multi select in incremental mode | 179 | --no multi select in incremental mode |
166 | m_sel = s.msel | 180 | m_sel = s.msel |
167 | end | 181 | end |
182 | overflow = s.ovfl or "auto" | ||
168 | header_fgc = s.hfgc or _clr.set( 0, 000, 000, 000) | 183 | header_fgc = s.hfgc or _clr.set( 0, 000, 000, 000) |
169 | header_bgc = s.hbgc or _clr.set(-1, 255, 255, 255) | 184 | header_bgc = s.hbgc or _clr.set(-1, 255, 255, 255) |
170 | item_fgc = s.ifgc or _clr.set(-1, 000, 255, 060) | 185 | item_fgc = s.ifgc or _clr.set(-1, 000, 255, 060) |
@@ -210,16 +225,19 @@ function print_table(t, t_count, settings) | |||
210 | -- displays header text at top | 225 | -- displays header text at top |
211 | local function disp_header(hstr) | 226 | local function disp_header(hstr) |
212 | local header = header or hstr | 227 | local header = header or hstr |
213 | local opts = _print.opt.get() | 228 | local opts = _print.opt.get() -- save to restore settings |
214 | _print.opt.overflow("none") -- don't scroll header; colors change | 229 | _print.opt.overflow("auto") -- don't scroll header; colors change |
215 | _print.opt.color(header_fgc, header_bgc) | 230 | _print.opt.color(header_fgc, header_bgc) |
216 | _print.opt.line(1) | 231 | _print.opt.line(1) |
217 | 232 | ||
233 | rb.set_viewport(_print.opt.get(true)) | ||
218 | _print.f() | 234 | _print.f() |
219 | local line = _print.f(header) | 235 | _print.f("%h", tostring(header)) --hack to signal header |
220 | 236 | ||
221 | _print.opt.set(opts) | 237 | _print.opt.set(opts) -- restore settings |
222 | _print.opt.line(2) | 238 | _print.opt.line(2) |
239 | rb.set_viewport(opts) | ||
240 | opts = nil | ||
223 | return 2 | 241 | return 2 |
224 | end | 242 | end |
225 | 243 | ||
@@ -229,7 +247,7 @@ function print_table(t, t_count, settings) | |||
229 | rb.lcd_update() | 247 | rb.lcd_update() |
230 | 248 | ||
231 | local quit, select, x_chg, xi, y_chg, yi, timeb = | 249 | local quit, select, x_chg, xi, y_chg, yi, timeb = |
232 | dpad(t_p.col, -1, -t_p.col_scrl, t_p.row, -1, -t_p.row_scrl) | 250 | dpad_fn(t_p.col, -1, -t_p.col_scrl, t_p.row, -1, -t_p.row_scrl, nil, overflow) |
233 | 251 | ||
234 | t_p.vcursor = t_p.vcursor + y_chg | 252 | t_p.vcursor = t_p.vcursor + y_chg |
235 | 253 | ||
@@ -322,6 +340,7 @@ function print_table(t, t_count, settings) | |||
322 | 340 | ||
323 | rb.button_clear_queue() -- keep the button queue from overflowing | 341 | rb.button_clear_queue() -- keep the button queue from overflowing |
324 | end | 342 | end |
343 | rb.lcd_scroll_stop() | ||
325 | return sel | 344 | return sel |
326 | end -- display_table | 345 | end -- display_table |
327 | --============================================================================-- | 346 | --============================================================================-- |
@@ -331,7 +350,7 @@ function print_table(t, t_count, settings) | |||
331 | _print.opt.color(item_fgc, item_bgc, item_selc) | 350 | _print.opt.color(item_fgc, item_bgc, item_selc) |
332 | 351 | ||
333 | table_p = init_position(15, 5) | 352 | table_p = init_position(15, 5) |
334 | line, maxline = _print.opt.area(5, 1, rb.LCD_WIDTH - 10, rb.LCD_HEIGHT - 2) | 353 | line, maxline = _print.opt.area(5, 1, rb.LCD_WIDTH - 10 - sb_width, rb.LCD_HEIGHT - 2) |
335 | maxline = math.min(maxline, t_count) | 354 | maxline = math.min(maxline, t_count) |
336 | 355 | ||
337 | -- allow user to start at a position other than the beginning | 356 | -- allow user to start at a position other than the beginning |
@@ -349,9 +368,11 @@ function print_table(t, t_count, settings) | |||
349 | end | 368 | end |
350 | 369 | ||
351 | _print.opt.sel_line(table_p.vcursor) | 370 | _print.opt.sel_line(table_p.vcursor) |
352 | _print.opt.overflow("manual") | 371 | _print.opt.overflow(overflow) |
353 | _print.opt.justify(justify) | 372 | _print.opt.justify(justify) |
354 | 373 | ||
374 | _print.opt.linedesc(table_linedesc) | ||
375 | |||
355 | local opts = _print.opt.get() | 376 | local opts = _print.opt.get() |
356 | opts.drawsep = drawsep | 377 | opts.drawsep = drawsep |
357 | _print.opt.set(opts) | 378 | _print.opt.set(opts) |
@@ -360,17 +381,19 @@ function print_table(t, t_count, settings) | |||
360 | -- initialize vertical scrollbar | 381 | -- initialize vertical scrollbar |
361 | set_vsb(); do | 382 | set_vsb(); do |
362 | local vsb =_print.opt.get() | 383 | local vsb =_print.opt.get() |
384 | vsb.width = vsb.width + sb_width | ||
385 | |||
363 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens | 386 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens |
364 | vsb.fg_pattern = 3 - vsb.fg_pattern | 387 | vsb.fg_pattern = 3 - vsb.fg_pattern |
365 | vsb.bg_pattern = 3 - vsb.bg_pattern | 388 | vsb.bg_pattern = 3 - vsb.bg_pattern |
366 | end | 389 | end |
367 | 390 | ||
368 | set_vsb = function (item) | 391 | set_vsb = function (item) |
369 | if t_count > (maxline or t_count) then | 392 | if sb_width > 0 and t_count > (maxline or t_count) then |
370 | rb.set_viewport(vsb) | 393 | rb.set_viewport(vsb) |
371 | item = item or 0 | 394 | item = item or 0 |
372 | local m = maxline / 2 + 1 | 395 | local m = maxline / 2 + 1 |
373 | rb.gui_scrollbar_draw(vsb.width - 5, vsb.y, 5, vsb.height, | 396 | rb.gui_scrollbar_draw(vsb.width - sb_width, vsb.y, sb_width, vsb.height, |
374 | t_count, math.max(0, item - m), | 397 | t_count, math.max(0, item - m), |
375 | math.min(item + m, t_count), 0) | 398 | math.min(item + m, t_count), 0) |
376 | end | 399 | end |
@@ -378,7 +401,7 @@ function print_table(t, t_count, settings) | |||
378 | end -- set_vsb | 401 | end -- set_vsb |
379 | local selected = display_table(table_p, 0, 1, 0) | 402 | local selected = display_table(table_p, 0, 1, 0) |
380 | 403 | ||
381 | _print.opt.defaults() | 404 | _print.opt.defaults() --restore settings |
382 | 405 | ||
383 | if m_sel == true then -- walk the table to get selected items | 406 | if m_sel == true then -- walk the table to get selected items |
384 | selected = {} | 407 | selected = {} |
diff --git a/apps/plugins/lua/lua.make b/apps/plugins/lua/lua.make index daa8a05384..1e74277549 100644 --- a/apps/plugins/lua/lua.make +++ b/apps/plugins/lua/lua.make | |||
@@ -18,7 +18,7 @@ OTHER_SRC += $(LUA_SRC) | |||
18 | LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua | 18 | LUA_INCLUDEDIR := $(LUA_SRCDIR)/include_lua |
19 | LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,audio.lua blit.lua color.lua draw.lua draw_floodfill.lua draw_poly.lua \ | 19 | LUA_INCLUDELIST := $(addprefix $(LUA_BUILDDIR)/,audio.lua blit.lua color.lua draw.lua draw_floodfill.lua draw_poly.lua \ |
20 | draw_num.lua draw_text.lua files.lua image.lua image_save.lua lcd.lua math_ex.lua \ | 20 | draw_num.lua draw_text.lua files.lua image.lua image_save.lua lcd.lua math_ex.lua \ |
21 | print.lua timer.lua playlist.lua pcm.lua sound.lua \ | 21 | print.lua timer.lua playlist.lua pcm.lua sound.lua printmenus.lua\ |
22 | rbcompat.lua rbsettings.lua poly_points.lua printtable.lua) | 22 | rbcompat.lua rbsettings.lua poly_points.lua printtable.lua) |
23 | 23 | ||
24 | 24 | ||
diff --git a/apps/plugins/lua/rbdefines_helper.pl b/apps/plugins/lua/rbdefines_helper.pl index b55609077d..eca09187fa 100755 --- a/apps/plugins/lua/rbdefines_helper.pl +++ b/apps/plugins/lua/rbdefines_helper.pl | |||
@@ -53,6 +53,7 @@ if ($def_type eq "rb_defines") { | |||
53 | '^PLUGIN_DIR$', | 53 | '^PLUGIN_DIR$', |
54 | '^PLUGIN(_APPS_|_GAMES_|_)DATA_DIR$', | 54 | '^PLUGIN(_APPS_|_GAMES_|_)DATA_DIR$', |
55 | '^ROCKBOX_DIR$', | 55 | '^ROCKBOX_DIR$', |
56 | '^STYLE_(NONE|DEFAULT|INVERT|COLORBAR|GRADIENT|COLORED)', | ||
56 | '^VIEWERS_DATA_DIR$'); | 57 | '^VIEWERS_DATA_DIR$'); |
57 | } | 58 | } |
58 | elsif ($def_type eq "sound_defines") { | 59 | elsif ($def_type eq "sound_defines") { |
diff --git a/apps/plugins/lua/rocklib_img.c b/apps/plugins/lua/rocklib_img.c index 13e5503f75..b0ca769ca4 100644 --- a/apps/plugins/lua/rocklib_img.c +++ b/apps/plugins/lua/rocklib_img.c | |||
@@ -23,6 +23,9 @@ | |||
23 | 23 | ||
24 | #define lrockimg_c | 24 | #define lrockimg_c |
25 | #define LUA_LIB | 25 | #define LUA_LIB |
26 | #define ICON_PADDING_S "1" | ||
27 | |||
28 | |||
26 | 29 | ||
27 | #include "lua.h" | 30 | #include "lua.h" |
28 | #include "lauxlib.h" | 31 | #include "lauxlib.h" |
@@ -1292,6 +1295,137 @@ RB_WRAP(lcd_puts) | |||
1292 | return 0; | 1295 | return 0; |
1293 | } | 1296 | } |
1294 | 1297 | ||
1298 | /* Helper function for opt_viewport lcd_put_line */ | ||
1299 | static int check_tablevalue_def(lua_State *L, const char* key, int tablepos, int def) | ||
1300 | { | ||
1301 | lua_getfield(L, tablepos, key); /* Find table[key] */ | ||
1302 | |||
1303 | int val; | ||
1304 | |||
1305 | if (lua_isboolean(L, -1)) | ||
1306 | val = lua_toboolean (L, -1); /*True = 1 and False = 0*/ | ||
1307 | else | ||
1308 | val = luaL_optinteger(L, -1, def); | ||
1309 | |||
1310 | lua_pop(L, 1); /* Pop the value off the stack */ | ||
1311 | return val; | ||
1312 | } | ||
1313 | |||
1314 | /* Helper function for opt_viewport lcd_put_line */ | ||
1315 | static int check_tablevalue(lua_State *L, const char* key, int tablepos) | ||
1316 | { | ||
1317 | /* returns 0 if key doesn't exist */ | ||
1318 | return check_tablevalue_def(L, key, tablepos, 0); | ||
1319 | } | ||
1320 | |||
1321 | RB_WRAP(lcd_put_line) | ||
1322 | { | ||
1323 | /*x, y, text, t_linedesc, [screen = MAIN]*/ | ||
1324 | |||
1325 | #if 0 | ||
1326 | /* height of the line (in pixels). -1 to inherit the height | ||
1327 | * from the font. The text will be centered if the height is larger, | ||
1328 | * but the decorations will span the entire height */ | ||
1329 | int height; | ||
1330 | /* multiline support: For some decorations (e.g. gradient) to work | ||
1331 | * across multiple lines (e.g. to draw a line selector across 2 lines) | ||
1332 | * the line index and line count must be known. For normal, single | ||
1333 | * lines specify nlines=1 and line=0 */ | ||
1334 | /* line count of a group */ | ||
1335 | int16_t nlines; | ||
1336 | /* index of the line in the group */ | ||
1337 | int16_t line; | ||
1338 | /* line text color if STYLE_COLORED is specified, in native | ||
1339 | * lcd format (convert with LCD_RGBPACK() if necessary) */ | ||
1340 | unsigned text_color; | ||
1341 | /* line color if STYLE_COLORBAR or STYLE_GRADIENT is specified, in native | ||
1342 | * lcd format (convert with LCD_RGBPACK() if necessary) */ | ||
1343 | unsigned line_color, line_end_color; | ||
1344 | /* line decorations, see STYLE_DEFAULT etc. */ | ||
1345 | enum line_styles style; | ||
1346 | /* whether the line can scroll */ | ||
1347 | bool scroll; | ||
1348 | /* height of the line separator (in pixels). 0 to disable drawing | ||
1349 | * of the separator */ | ||
1350 | int8_t separator_height; | ||
1351 | #endif | ||
1352 | |||
1353 | /*LINE_DESC_DEFINIT { .style = STYLE_DEFAULT, .height = -1, .separator_height = 0, .line = 0, .nlines = 1, .scroll = false }*/ | ||
1354 | |||
1355 | struct line_desc linedes = LINE_DESC_DEFINIT; | ||
1356 | |||
1357 | bool is_selected = false; | ||
1358 | bool show_icons = false; | ||
1359 | bool show_cursor = false; | ||
1360 | |||
1361 | int line_indent = 0; | ||
1362 | int item_offset = 0; | ||
1363 | |||
1364 | int x = (int) luaL_checkint(L, 1); | ||
1365 | int y = (int) luaL_checkint(L, 2); | ||
1366 | |||
1367 | const unsigned char * string = luaL_checkstring(L, 3); | ||
1368 | int icon = Icon_NOICON; | ||
1369 | const int narg = 4; | ||
1370 | |||
1371 | if(lua_type(L, narg) == LUA_TTABLE) | ||
1372 | { | ||
1373 | /* check_tablevalue only returns INTS */ | ||
1374 | linedes.line = check_tablevalue(L, "line", narg); | ||
1375 | linedes.height = check_tablevalue_def(L, "height", narg, -1); | ||
1376 | linedes.nlines = check_tablevalue_def(L, "nlines", narg, 1); | ||
1377 | linedes.style = check_tablevalue_def(L, "style", narg, STYLE_DEFAULT); | ||
1378 | linedes.separator_height = check_tablevalue(L, "separator_height", narg); | ||
1379 | linedes.scroll = check_tablevalue(L, "scroll", narg) > 0; | ||
1380 | |||
1381 | linedes.text_color = check_tablevalue(L, "text_color", narg); | ||
1382 | linedes.line_color = check_tablevalue(L, "line_color", narg); | ||
1383 | linedes.line_end_color = check_tablevalue(L, "line_end_color", narg); | ||
1384 | |||
1385 | icon = check_tablevalue_def(L, "icon", narg, Icon_NOICON); | ||
1386 | show_icons = check_tablevalue(L, "show_icons", narg) > 0 && icon > Icon_NOICON; | ||
1387 | show_cursor = check_tablevalue(L, "show_cursor", narg) > 0; | ||
1388 | is_selected = check_tablevalue(L, "selected", narg) > 0; | ||
1389 | |||
1390 | line_indent = check_tablevalue(L, "indent", narg); | ||
1391 | item_offset = check_tablevalue(L, "offset", narg); | ||
1392 | |||
1393 | } | ||
1394 | |||
1395 | while (*string == '\t') | ||
1396 | { | ||
1397 | line_indent++; | ||
1398 | string++; | ||
1399 | } | ||
1400 | |||
1401 | /* mask out gradient and colorbar styles for non-color displays */ | ||
1402 | if (RB_SCREEN_STRUCT(L, 5)->depth < 16) | ||
1403 | { | ||
1404 | if (linedes.style & (STYLE_COLORBAR|STYLE_GRADIENT)) | ||
1405 | { | ||
1406 | linedes.style &= ~(STYLE_COLORBAR|STYLE_GRADIENT); | ||
1407 | linedes.style |= STYLE_INVERT; | ||
1408 | } | ||
1409 | linedes.style &= ~STYLE_COLORED; | ||
1410 | } | ||
1411 | |||
1412 | if (show_cursor && (show_icons && icon > Icon_NOICON)) | ||
1413 | RB_SCREENS(L, 5, put_line, x, y, &linedes, | ||
1414 | "$*s$"ICON_PADDING_S"I$i$"ICON_PADDING_S"s$*t", | ||
1415 | line_indent, is_selected ? Icon_Cursor : Icon_NOICON, | ||
1416 | icon, item_offset, string); | ||
1417 | else if (show_cursor || (show_icons && icon > Icon_NOICON)) | ||
1418 | RB_SCREENS(L, 5, put_line, x, y, &linedes, | ||
1419 | "$*s$"ICON_PADDING_S"I$*t", line_indent, | ||
1420 | show_cursor ? (is_selected ? Icon_Cursor:Icon_NOICON):icon, | ||
1421 | item_offset, string); | ||
1422 | else | ||
1423 | RB_SCREENS(L, 5, put_line, x, y, &linedes, "$*s$*t", line_indent, item_offset, string); | ||
1424 | |||
1425 | |||
1426 | return 0; | ||
1427 | } | ||
1428 | |||
1295 | RB_WRAP(lcd_puts_scroll) | 1429 | RB_WRAP(lcd_puts_scroll) |
1296 | { | 1430 | { |
1297 | int x, y; | 1431 | int x, y; |
@@ -1307,17 +1441,6 @@ RB_WRAP(lcd_scroll_stop) | |||
1307 | return 0; | 1441 | return 0; |
1308 | } | 1442 | } |
1309 | 1443 | ||
1310 | /* Helper function for opt_viewport */ | ||
1311 | static int check_tablevalue(lua_State *L, const char* key, int tablepos) | ||
1312 | { | ||
1313 | lua_getfield(L, tablepos, key); /* Find table[key] */ | ||
1314 | |||
1315 | int val = lua_tointeger(L, -1); | ||
1316 | |||
1317 | lua_pop(L, 1); /* Pop the value off the stack */ | ||
1318 | return val; | ||
1319 | } | ||
1320 | |||
1321 | static inline struct viewport* opt_viewport(lua_State *L, | 1444 | static inline struct viewport* opt_viewport(lua_State *L, |
1322 | int narg, | 1445 | int narg, |
1323 | struct viewport* vp, | 1446 | struct viewport* vp, |
@@ -1333,7 +1456,7 @@ static inline struct viewport* opt_viewport(lua_State *L, | |||
1333 | vp->width = check_tablevalue(L, "width", narg); | 1456 | vp->width = check_tablevalue(L, "width", narg); |
1334 | vp->height = check_tablevalue(L, "height", narg); | 1457 | vp->height = check_tablevalue(L, "height", narg); |
1335 | vp->font = check_tablevalue(L, "font", narg); | 1458 | vp->font = check_tablevalue(L, "font", narg); |
1336 | vp->drawmode = check_tablevalue(L, "drawmode", narg); | 1459 | vp->drawmode = check_tablevalue_def(L, "drawmode", narg, DRMODE_SOLID); |
1337 | #if LCD_DEPTH > 1 | 1460 | #if LCD_DEPTH > 1 |
1338 | vp->fg_pattern = (unsigned int) check_tablevalue(L, "fg_pattern", narg); | 1461 | vp->fg_pattern = (unsigned int) check_tablevalue(L, "fg_pattern", narg); |
1339 | vp->bg_pattern = (unsigned int) check_tablevalue(L, "bg_pattern", narg); | 1462 | vp->bg_pattern = (unsigned int) check_tablevalue(L, "bg_pattern", narg); |
@@ -1686,6 +1809,7 @@ static const luaL_Reg rocklib_img[] = | |||
1686 | R(lcd_set_drawmode), | 1809 | R(lcd_set_drawmode), |
1687 | R(lcd_putsxy), | 1810 | R(lcd_putsxy), |
1688 | R(lcd_puts), | 1811 | R(lcd_puts), |
1812 | R(lcd_put_line), | ||
1689 | R(lcd_puts_scroll), | 1813 | R(lcd_puts_scroll), |
1690 | R(lcd_scroll_stop), | 1814 | R(lcd_scroll_stop), |
1691 | R(set_viewport), | 1815 | R(set_viewport), |
diff --git a/apps/plugins/lua_scripts.lua b/apps/plugins/lua_scripts.lua index 02fe50b327..43593d96b0 100644 --- a/apps/plugins/lua_scripts.lua +++ b/apps/plugins/lua_scripts.lua | |||
@@ -24,13 +24,15 @@ | |||
24 | local scrpath = rb.current_path() .. "/lua_scripts/" | 24 | local scrpath = rb.current_path() .. "/lua_scripts/" |
25 | 25 | ||
26 | package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path | 26 | package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path |
27 | require("printtable") | 27 | require("printmenus") |
28 | 28 | ||
29 | rb.actions = nil | 29 | rb.actions = nil |
30 | package.loaded["actions"] = nil | 30 | package.loaded["actions"] = nil |
31 | 31 | ||
32 | local excludedsrc = ";filebrowse.lua;fileviewers.lua;printmenu.lua;dbgettags.lua;" | 32 | local excludedsrc = ";filebrowse.lua;fileviewers.lua;printmenu.lua;dbgettags.lua;" |
33 | -------------------------------------------------------------------------------- | 33 | -------------------------------------------------------------------------------- |
34 | local Icon_Plugin = 0x9 | ||
35 | |||
34 | 36 | ||
35 | local function get_files(path, norecurse, finddir, findfile, f_t, d_t) | 37 | local function get_files(path, norecurse, finddir, findfile, f_t, d_t) |
36 | 38 | ||
@@ -120,6 +122,15 @@ local function get_files(path, norecurse, finddir, findfile, f_t, d_t) | |||
120 | end -- get_files | 122 | end -- get_files |
121 | -------------------------------------------------------------------------------- | 123 | -------------------------------------------------------------------------------- |
122 | 124 | ||
125 | function icon_fn(item, icon) | ||
126 | if item ~= 0 then | ||
127 | icon = Icon_Plugin | ||
128 | else | ||
129 | icon = -1 | ||
130 | end | ||
131 | return icon | ||
132 | end | ||
133 | |||
123 | -- uses print_table and get_files to display simple file browser | 134 | -- uses print_table and get_files to display simple file browser |
124 | function script_choose(dir, title) | 135 | function script_choose(dir, title) |
125 | local dstr | 136 | local dstr |
@@ -128,8 +139,8 @@ function script_choose(dir, title) | |||
128 | local norecurse = true | 139 | local norecurse = true |
129 | local f_finddir = false -- function to match directories; nil all, false none | 140 | local f_finddir = false -- function to match directories; nil all, false none |
130 | local f_findfile = nil -- function to match files; nil all, false none | 141 | local f_findfile = nil -- function to match files; nil all, false none |
131 | 142 | local t_linedesc = {show_icons = true, icon_fn = icon_fn} | |
132 | local p_settings = {wrap = true, hasheader = true} | 143 | local p_settings = {wrap = true, hasheader = true, justify = "left", linedesc = t_linedesc} |
133 | local files = {} | 144 | local files = {} |
134 | local dirs = {} | 145 | local dirs = {} |
135 | local item = 1 | 146 | local item = 1 |
@@ -142,10 +153,11 @@ function script_choose(dir, title) | |||
142 | for i = 1, #files do | 153 | for i = 1, #files do |
143 | table.insert(dirs, "\t" .. string.gsub(files[i], ".*/","")) | 154 | table.insert(dirs, "\t" .. string.gsub(files[i], ".*/","")) |
144 | end | 155 | end |
145 | 156 | --print_menu(menu_t, func_t, selected, settings, copy_screen) | |
146 | item = print_table(dirs, #dirs, p_settings) | 157 | _, item = print_menu(dirs, nil, 0, p_settings) |
147 | 158 | ||
148 | -- If item was selected follow directory or return filename | 159 | -- If item was selected follow directory or return filename |
160 | item = item or -1 | ||
149 | if item > 0 then | 161 | if item > 0 then |
150 | dir = files[item - 1] | 162 | dir = files[item - 1] |
151 | if not rb.dir_exists("/" .. dir) then | 163 | if not rb.dir_exists("/" .. dir) then |
diff --git a/apps/plugins/lua_scripts/file_browser.lua b/apps/plugins/lua_scripts/file_browser.lua index 19f475acf3..ab246a2a7e 100644 --- a/apps/plugins/lua_scripts/file_browser.lua +++ b/apps/plugins/lua_scripts/file_browser.lua | |||
@@ -33,7 +33,7 @@ local scrpath = rb.current_path()--rb.PLUGIN_DIR .. "/demos/lua_scripts/" | |||
33 | 33 | ||
34 | package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path | 34 | package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path |
35 | 35 | ||
36 | require("printmenu") --menu | 36 | require("printmenus") --menu |
37 | require("filebrowse") -- file browser | 37 | require("filebrowse") -- file browser |
38 | 38 | ||
39 | rb.actions = nil | 39 | rb.actions = nil |
diff --git a/apps/plugins/lua_scripts/fileview.lua b/apps/plugins/lua_scripts/fileview.lua index 920281bbef..08eea0337c 100755 --- a/apps/plugins/lua_scripts/fileview.lua +++ b/apps/plugins/lua_scripts/fileview.lua | |||
@@ -33,7 +33,7 @@ local scrpath = rb.current_path()--rb.PLUGIN_DIR .. "/demos/lua_scripts/" | |||
33 | 33 | ||
34 | package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path | 34 | package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path |
35 | 35 | ||
36 | require("printmenu") --menu | 36 | require("printmenus") --menu |
37 | require("filebrowse") -- file browser | 37 | require("filebrowse") -- file browser |
38 | require("fileviewers") -- fileviewer, hexviewer | 38 | require("fileviewers") -- fileviewer, hexviewer |
39 | 39 | ||
diff --git a/apps/plugins/lua_scripts/fileviewers.lua b/apps/plugins/lua_scripts/fileviewers.lua index 5a9c417d36..c686f3eeda 100755 --- a/apps/plugins/lua_scripts/fileviewers.lua +++ b/apps/plugins/lua_scripts/fileviewers.lua | |||
@@ -205,6 +205,7 @@ function print_file(filename, maxlinelen, settings) | |||
205 | end | 205 | end |
206 | settings.hasheader = true | 206 | settings.hasheader = true |
207 | settings.co_routine = nil | 207 | settings.co_routine = nil |
208 | settings.ovfl = "manual" | ||
208 | 209 | ||
209 | local sel = | 210 | local sel = |
210 | print_table(ftable, #ftable, settings) | 211 | print_table(ftable, #ftable, settings) |
@@ -309,6 +310,7 @@ function print_file_increment(filename, settings) | |||
309 | settings.hasheader = true | 310 | settings.hasheader = true |
310 | settings.co_routine = co | 311 | settings.co_routine = co |
311 | settings.msel = false | 312 | settings.msel = false |
313 | settings.ovfl = "manual" | ||
312 | 314 | ||
313 | table.insert(file_t, 1, hstr) --position 1 is header/title | 315 | table.insert(file_t, 1, hstr) --position 1 is header/title |
314 | local sel = | 316 | local sel = |
@@ -437,6 +439,7 @@ function print_file_hex(filename, bytesperline, settings) | |||
437 | settings.co_routine = co | 439 | settings.co_routine = co |
438 | settings.start = start | 440 | settings.start = start |
439 | settings.curpos = vcur | 441 | settings.curpos = vcur |
442 | settings.ovfl = "manual" | ||
440 | 443 | ||
441 | while sel > 0 do | 444 | while sel > 0 do |
442 | settings.start = start | 445 | settings.start = start |
diff --git a/apps/plugins/lua_scripts/printmenu.lua b/apps/plugins/lua_scripts/printmenu.lua deleted file mode 100755 index 3cb17d8026..0000000000 --- a/apps/plugins/lua_scripts/printmenu.lua +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | --[[ | ||
2 | /*************************************************************************** | ||
3 | * __________ __ ___. | ||
4 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
5 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
8 | * \/ \/ \/ \/ \/ | ||
9 | * $Id$ | ||
10 | * | ||
11 | * Copyright (C) 2017 William Wilgus | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | ]] | ||
23 | if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end | ||
24 | |||
25 | require("printtable") | ||
26 | local _clr = require("color") | ||
27 | |||
28 | local _LCD = rb.lcd_framebuffer() | ||
29 | -------------------------------------------------------------------------------- | ||
30 | -- displays text in menu_t calls function in same indice of func_t when selected | ||
31 | function print_menu(menu_t, func_t, selected, settings, copy_screen) | ||
32 | |||
33 | local i, start, vcur, screen_img | ||
34 | |||
35 | if selected then vcur = selected + 1 end | ||
36 | if vcur and vcur <= 1 then vcur = 2 end | ||
37 | |||
38 | if not settings then | ||
39 | settings = {} | ||
40 | settings.justify = "center" | ||
41 | settings.wrap = true | ||
42 | settings.hfgc = _clr.set( 0, 000, 000, 000) | ||
43 | settings.hbgc = _clr.set(-1, 255, 255, 255) | ||
44 | settings.ifgc = _clr.set(-1, 000, 255, 060) | ||
45 | settings.ibgc = _clr.set( 0, 000, 000, 000) | ||
46 | settings.iselc = _clr.set( 1, 000, 200, 100) | ||
47 | settings.default = true | ||
48 | end | ||
49 | |||
50 | settings.hasheader = true | ||
51 | settings.co_routine = nil | ||
52 | settings.msel = false | ||
53 | settings.start = start | ||
54 | settings.curpos = vcur | ||
55 | |||
56 | while not i or i > 0 do | ||
57 | if copy_screen == true then | ||
58 | --make a copy of screen for restoration | ||
59 | screen_img = screen_img or rb.new_image() | ||
60 | screen_img:copy(_LCD) | ||
61 | else | ||
62 | screen_img = nil | ||
63 | end | ||
64 | |||
65 | _LCD:clear(settings.ibgc) | ||
66 | |||
67 | settings.start = start | ||
68 | settings.curpos = vcur | ||
69 | |||
70 | i, start, vcur = print_table(menu_t, #menu_t, settings) | ||
71 | --vcur = vcur + 1 | ||
72 | collectgarbage("collect") | ||
73 | if copy_screen == true then _LCD:copy(screen_img) end | ||
74 | |||
75 | if func_t and func_t[i] then | ||
76 | if func_t[i](i, menu_t) == true then break end | ||
77 | else | ||
78 | break | ||
79 | end | ||
80 | end | ||
81 | if settings.default == true then settings = nil end | ||
82 | return screen_img | ||
83 | end | ||
diff --git a/apps/plugins/lua_scripts/rlimg.lua b/apps/plugins/lua_scripts/rlimg.lua index 801d0c5fac..c9dde65ed4 100755 --- a/apps/plugins/lua_scripts/rlimg.lua +++ b/apps/plugins/lua_scripts/rlimg.lua | |||
@@ -36,7 +36,7 @@ local _draw_text = require("draw_text") | |||
36 | 36 | ||
37 | --package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path | 37 | --package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path |
38 | 38 | ||
39 | require("printmenu") --menu | 39 | require("printmenus") --menu |
40 | 40 | ||
41 | --[[ RBIMAGE library functions | 41 | --[[ RBIMAGE library functions |
42 | NOTE!! on x, y coordinates + width & height | 42 | NOTE!! on x, y coordinates + width & height |
diff --git a/apps/plugins/lua_scripts/tagnav.lua b/apps/plugins/lua_scripts/tagnav.lua index f62f27973b..9646f359e3 100644 --- a/apps/plugins/lua_scripts/tagnav.lua +++ b/apps/plugins/lua_scripts/tagnav.lua | |||
@@ -25,7 +25,7 @@ | |||
25 | --local scrpath = rb.current_path()" | 25 | --local scrpath = rb.current_path()" |
26 | 26 | ||
27 | --package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path | 27 | --package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to path |
28 | require("printmenu") | 28 | require("printmenus") |
29 | require("printtable") | 29 | require("printtable") |
30 | require("dbgettags") | 30 | require("dbgettags") |
31 | 31 | ||