diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-04-09 23:11:31 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2021-04-20 03:30:41 +0000 |
commit | acda37edd13b9c6aca16cd1d1ee9183368d5b40c (patch) | |
tree | e4b500df9ed0c8c18d576c5c7cc6d80a3ce5b28a /apps/plugins/lua/rocklib_img.c | |
parent | c71a47f6496766b80a9e8c965a1603c7223e45ce (diff) | |
download | rockbox-acda37edd13b9c6aca16cd1d1ee9183368d5b40c.tar.gz rockbox-acda37edd13b9c6aca16cd1d1ee9183368d5b40c.zip |
lua print table put_line a do_menu alternative
add stylized lines to lua
the exported do_menu has a severe limitation of 64 items
it also requires double the memory
put_line is the way rockbox builds menus
update printtable
user config from core -- done
code cleanup
fixed for 1-bit screens
changed button behavior
fixed for 2-bit screens
Change-Id: I4de55e42685aa1d2f53a33bc8e980827864e810b
Diffstat (limited to 'apps/plugins/lua/rocklib_img.c')
-rw-r--r-- | apps/plugins/lua/rocklib_img.c | 148 |
1 files changed, 136 insertions, 12 deletions
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), |