A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1--[[ Lua draw number function
2/***************************************************************************
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * $Id$
10 *
11 * Copyright (C) 2019 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--[[ Exposed Functions
24 _draw_nums.print; binary (base = 2) , octal (base = 8), hexadecimal (base = 16)
25 _draw_nums.nums; table of number characters
26]]
27if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end
28local _draw_nums = {} do
29 local _poly = require "draw_poly"
30 -- every 2 elements is an x, y coord pair
31 -- n[?] = {x,y,x,y,x,y}
32 local nums = {
33 ["b"] = {0,1,0,7,0,5,1,4,1,4,2,4,3,5,3,6,2,7,1,7,0,6,0,5},
34 ["o"] = {1,4,0,5,0,6,1,7,2,7,3,6,3,5,2,4,1,4},
35 ["x"] = {0,3,4,7,2,5,4,3,0,7},
36 [-1] = {1,4, 3,4},
37 [0] = {1,2,1,6,2,7,3,7,4,6,4,2,3,1,2,1,1,2},
38 [1] = {3,1,3,7},
39 [2] = {1,1,3,1,4,2,4,3,3,4,1,5,1,7,4,7},
40 [3] = {1,1,3,1,4,2,4,3,3,4,2,4,3,4,4,5,4,6,3,7,1,7},
41 [4] = {1,1,1,3,2,4,4,4,4,1,4,7},
42 [5] = {1,1,4,1,1,1,1,4,3,4,4,5,4,6,3,7,1,7},
43 [6] = {1,2,1,4,1,6,2,7,3,7,4,6,4,5,3,4,1,4,1,2,2,1,3,1,4,2},
44 [7] = {1,1,4,1,4,2,1,7},
45 [8] = {1,2,4,5,4,6,3,7,2,7,1,6,1,5,4,2,3,1,2,1,1,2},
46 [9] = {4,6,4,4,4,2,3,1,2,1,1,2,1,3,2,4,4,4,4,6,3,7,2,7,1,6},
47 [10] = {1,7,1,4,4,4,4,7,4,2,3,1,2,1,1,2,1,4},
48 [11] = {1,1,1,7,3,7,4,6,4,5,3,4,1,4,3,4,4,3,4,2,3,1,1,1},
49 [12] = {4,2,3,1,2,1,1,2,1,6,2,7,3,7,4,6},
50 [13] = {1,1,1,7,3,7,4,6,4,2,3,1,1,1},
51 [14] = {4,1,1,1,1,4,3,4,1,4,1,7,4,7},
52 [15] = {4,1,1,1,1,4,3,4,1,4,1,7},
53 }
54 _draw_nums.nums = nums
55 _draw_nums.print = function(img, num, x, y, chrw, color, base, prefix, bClip, scale_x, scale_y, t_nums)
56 scale_x = scale_x or 1
57 scale_y = scale_y or 1
58 chrw = chrw * scale_x
59 prefix = (prefix == nil or prefix == true) and true or false
60 t_nums = t_nums or nums
61 local max_x, max_y, digits = 0, 0, {}
62 if num <= 0 then
63 if num < 0 then
64 digits[-3] = -1
65 num = -num
66 else
67 digits[0] = 0
68 end
69 end
70 if not prefix and (base == 2 or base == 8 or base == 16) then
71 -- no prefix
72 elseif base == 2 then
73 digits[-1] = "b"
74 elseif base == 8 then
75 digits[-1] = "o"
76 elseif base == 10 then
77 -- no prefix
78 elseif base == 16 then
79 digits[-2] = 0
80 digits[-1] = "x"
81 elseif base == nil then -- default
82 base = 10
83 else
84 error("unknown number base: " .. base)
85 return nil
86 end
87 while num > 0 do -- get each digit (LeastSignificant)
88 digits[#digits + 1] = num % base;
89 num=num/base;
90 end
91 digits[#digits + 1] = digits[0] -- zero
92 digits[#digits + 1] = digits[-1] -- base prefix
93 digits[#digits + 1] = digits[-2] -- base prefix (hex)
94 digits[#digits + 1] = digits[-3] -- neg sign
95 for i = #digits, 1, -1 do
96 max_x, max_y = _poly.polyline(img, x, y, t_nums[digits[i]],
97 color, false, bClip, scale_x, scale_y)
98 if chrw == 0 then chrw = max_x end
99 x = x + chrw
100 end
101 return x, y + max_y, chrw
102 end
103end
104return _draw_nums