summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/include_lua/printmenus.lua
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/include_lua/printmenus.lua')
-rw-r--r--apps/plugins/lua/include_lua/printmenus.lua249
1 files changed, 249 insertions, 0 deletions
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]]
23if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end
24
25require("printtable")
26
27local _clr = require("color")
28
29local _LCD = rb.lcd_framebuffer()
30
31--[[ -- dpad requires:
32require("actions") -- Contains rb.actions & rb.contexts
33local _timer = require("timer")
34-- Button definitions --
35local CANCEL_BUTTON = rb.actions.PLA_CANCEL
36local DOWN_BUTTON = rb.actions.PLA_DOWN
37local DOWNR_BUTTON = rb.actions.PLA_DOWN_REPEAT
38local EXIT_BUTTON = rb.actions.PLA_EXIT
39local LEFT_BUTTON = rb.actions.PLA_LEFT
40local LEFTR_BUTTON = rb.actions.PLA_LEFT_REPEAT
41local RIGHT_BUTTON = rb.actions.PLA_RIGHT
42local RIGHTR_BUTTON = rb.actions.PLA_RIGHT_REPEAT
43local SEL_BUTTON = rb.actions.PLA_SELECT
44local SELREL_BUTTON = rb.actions.PLA_SELECT_REL
45local SELR_BUTTON = rb.actions.PLA_SELECT_REPEAT
46local UP_BUTTON = rb.actions.PLA_UP
47local UPR_BUTTON = rb.actions.PLA_UP_REPEAT
48]]
49--------------------------------------------------------------------------------
50local 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")
92end
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--[[
105local 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)
167end -- dpad
168]]
169--------------------------------------------------------------------------------
170-- displays text in menu_t calls function in same indice of func_t when selected
171function 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
249end