summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/include_lua/draw_num.lua
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-04-05 00:38:35 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2024-04-18 13:11:51 -0400
commita6570b7d378b6236c40d2e2bd983f7d53ad479e3 (patch)
tree6e1562a78c07a1fe0e05b36cf10542aff5ca7482 /apps/plugins/lua/include_lua/draw_num.lua
parent7f1b49693cd84b6e03e05d8a980fb99f26a781b1 (diff)
downloadrockbox-a6570b7d378b6236c40d2e2bd983f7d53ad479e3.tar.gz
rockbox-a6570b7d378b6236c40d2e2bd983f7d53ad479e3.zip
lua use lcd_drawline to draw lines inside rliimages
rewrite draw_text to use new viewport buffer set_viewport now accepts rliimage to allowe interfacing with rb. functions fix long standing 2-bit bug with text drawing in lua fix 2-bit img saving bug (i'm guessing just a one off, just enabled clipping) fix font_getstringsize bug fix shape of numbers draw_num.lua also add auto centering add page scrolling to printtable add a new demo script 'stars' Change-Id: I866905cee82ee89ebc0eb020a56a7ecdb101bf5e
Diffstat (limited to 'apps/plugins/lua/include_lua/draw_num.lua')
-rw-r--r--apps/plugins/lua/include_lua/draw_num.lua21
1 files changed, 5 insertions, 16 deletions
diff --git a/apps/plugins/lua/include_lua/draw_num.lua b/apps/plugins/lua/include_lua/draw_num.lua
index 0f42c1f9f5..831e23e71e 100644
--- a/apps/plugins/lua/include_lua/draw_num.lua
+++ b/apps/plugins/lua/include_lua/draw_num.lua
@@ -20,17 +20,13 @@
20 * 20 *
21 ****************************************************************************/ 21 ****************************************************************************/
22]] 22]]
23
24--[[ Exposed Functions 23--[[ Exposed Functions
25 _draw_nums.print; binary (base = 2) , octal (base = 8), hexadecimal (base = 16) 24 _draw_nums.print; binary (base = 2) , octal (base = 8), hexadecimal (base = 16)
26 _draw_nums.nums; table of number characters 25 _draw_nums.nums; table of number characters
27]] 26]]
28
29if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end 27if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end
30
31local _draw_nums = {} do 28local _draw_nums = {} do
32 local _poly = require "draw_poly" 29 local _poly = require "draw_poly"
33
34 -- every 2 elements is an x, y coord pair 30 -- every 2 elements is an x, y coord pair
35 -- n[?] = {x,y,x,y,x,y} 31 -- n[?] = {x,y,x,y,x,y}
36 local nums = { 32 local nums = {
@@ -43,11 +39,11 @@ local _draw_nums = {} do
43 [2] = {1,1,3,1,4,2,4,3,3,4,1,5,1,7,4,7}, 39 [2] = {1,1,3,1,4,2,4,3,3,4,1,5,1,7,4,7},
44 [3] = {1,1,3,1,4,2,4,3,3,4,2,4,3,4,4,5,4,6,3,7,1,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},
45 [4] = {1,1,1,3,2,4,4,4,4,1,4,7}, 41 [4] = {1,1,1,3,2,4,4,4,4,1,4,7},
46 [5] = {1,1,4,1,1,1,1,4,3,4,4,5,4,7,1,7}, 42 [5] = {1,1,4,1,1,1,1,4,3,4,4,5,4,6,3,7,1,7},
47 [6] = {1,2,1,4,1,6,2,7,3,7,4,6,4,4,1,4,1,2,2,1,4,1}, 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},
48 [7] = {1,1,4,1,4,2,1,7}, 44 [7] = {1,1,4,1,4,2,1,7},
49 [8] = {1,2,1,6,2,7,3,7,4,6,4,4,1,4,4,4,4,2,3,1,2,1,1,2}, 45 [8] = {1,2,4,5,4,6,3,7,2,7,1,6,1,5,4,2,3,1,2,1,1,2},
50 [9] = {4,6,4,4,4,2,3,1,2,1,1,2,1,4,4,4,4,6,3,7,1,7}, 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},
51 [10] = {1,7,1,4,4,4,4,7,4,2,3,1,2,1,1,2,1,4}, 47 [10] = {1,7,1,4,4,4,4,7,4,2,3,1,2,1,1,2,1,4},
52 [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}, 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},
53 [12] = {4,2,3,1,2,1,1,2,1,6,2,7,3,7,4,6}, 49 [12] = {4,2,3,1,2,1,1,2,1,6,2,7,3,7,4,6},
@@ -56,8 +52,6 @@ local _draw_nums = {} do
56 [15] = {4,1,1,1,1,4,3,4,1,4,1,7}, 52 [15] = {4,1,1,1,1,4,3,4,1,4,1,7},
57 } 53 }
58 _draw_nums.nums = nums 54 _draw_nums.nums = nums
59
60
61 _draw_nums.print = function(img, num, x, y, chrw, color, base, prefix, bClip, scale_x, scale_y, t_nums) 55 _draw_nums.print = function(img, num, x, y, chrw, color, base, prefix, bClip, scale_x, scale_y, t_nums)
62 scale_x = scale_x or 1 56 scale_x = scale_x or 1
63 scale_y = scale_y or 1 57 scale_y = scale_y or 1
@@ -65,7 +59,6 @@ local _draw_nums = {} do
65 prefix = (prefix == nil or prefix == true) and true or false 59 prefix = (prefix == nil or prefix == true) and true or false
66 t_nums = t_nums or nums 60 t_nums = t_nums or nums
67 local max_x, max_y, digits = 0, 0, {} 61 local max_x, max_y, digits = 0, 0, {}
68
69 if num <= 0 then 62 if num <= 0 then
70 if num < 0 then 63 if num < 0 then
71 digits[-3] = -1 64 digits[-3] = -1
@@ -74,7 +67,6 @@ local _draw_nums = {} do
74 digits[0] = 0 67 digits[0] = 0
75 end 68 end
76 end 69 end
77
78 if not prefix and (base == 2 or base == 8 or base == 16) then 70 if not prefix and (base == 2 or base == 8 or base == 16) then
79 -- no prefix 71 -- no prefix
80 elseif base == 2 then 72 elseif base == 2 then
@@ -92,23 +84,20 @@ local _draw_nums = {} do
92 error("unknown number base: " .. base) 84 error("unknown number base: " .. base)
93 return nil 85 return nil
94 end 86 end
95
96 while num > 0 do -- get each digit (LeastSignificant) 87 while num > 0 do -- get each digit (LeastSignificant)
97 digits[#digits + 1] = num % base; 88 digits[#digits + 1] = num % base;
98 num=num/base; 89 num=num/base;
99 end 90 end
100
101 digits[#digits + 1] = digits[0] -- zero 91 digits[#digits + 1] = digits[0] -- zero
102 digits[#digits + 1] = digits[-1] -- base prefix 92 digits[#digits + 1] = digits[-1] -- base prefix
103 digits[#digits + 1] = digits[-2] -- base prefix (hex) 93 digits[#digits + 1] = digits[-2] -- base prefix (hex)
104 digits[#digits + 1] = digits[-3] -- neg sign 94 digits[#digits + 1] = digits[-3] -- neg sign
105
106 for i = #digits, 1, -1 do 95 for i = #digits, 1, -1 do
107 max_x, max_y = _poly.polyline(img, x, y, t_nums[digits[i]], 96 max_x, max_y = _poly.polyline(img, x, y, t_nums[digits[i]],
108 color, false, bClip, scale_x, scale_y) 97 color, false, bClip, scale_x, scale_y)
98 if chrw == 0 then chrw = max_x end
109 x = x + chrw 99 x = x + chrw
110 end 100 end
111
112 return x, y + max_y, chrw 101 return x, y + max_y, chrw
113 end 102 end
114end 103end