summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/include_lua
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/include_lua')
-rw-r--r--apps/plugins/lua/include_lua/draw_num.lua21
-rw-r--r--apps/plugins/lua/include_lua/draw_text.lua85
-rw-r--r--apps/plugins/lua/include_lua/image_save.lua2
-rw-r--r--apps/plugins/lua/include_lua/printtable.lua9
4 files changed, 33 insertions, 84 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
diff --git a/apps/plugins/lua/include_lua/draw_text.lua b/apps/plugins/lua/include_lua/draw_text.lua
index 3722931c2c..1d44954a5c 100644
--- a/apps/plugins/lua/include_lua/draw_text.lua
+++ b/apps/plugins/lua/include_lua/draw_text.lua
@@ -23,7 +23,6 @@
23-- draw text onto image if width/height are supplied text is centered 23-- draw text onto image if width/height are supplied text is centered
24 24
25if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end 25if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end
26
27do 26do
28 -- Internal Constants 27 -- Internal Constants
29 local rocklib_image = getmetatable(rb.lcd_framebuffer()) 28 local rocklib_image = getmetatable(rb.lcd_framebuffer())
@@ -40,81 +39,35 @@ do
40 return function(img, x, y, width, height, font, color, text) 39 return function(img, x, y, width, height, font, color, text)
41 font = font or rb.FONT_UI 40 font = font or rb.FONT_UI
42 41
43 local opts = {x = 0, y = 0, width = LCD_W - 1, height = LCD_H - 1,
44 font = font, drawmode = 3, fg_pattern = 0x1, bg_pattern = 0}
45
46 if rb.LCD_DEPTH == 2 then -- invert 2-bit screens
47 --vp.drawmode = bit.bxor(vp.drawmode, 4)
48 opts.fg_pattern = 3 - opts.fg_pattern
49 opts.bg_pattern = 3 - opts.bg_pattern
50 end
51 rb.set_viewport(opts)
52 42
53 local res, w, h = rb.font_getstringsize(text, font) 43 if rb.lcd_rgbpack ~= _NIL then -- Color target
54 44 rb.set_viewport(img, {fg_pattern = color, font = font, drawmode = 2})--DRMODE_FG
55 if not width then
56 width = 0
57 else 45 else
58 width = (width - w) / 2 46 if color ~= 0 then color = 3 end--DRMODE_SOLID
47 rb.set_viewport(img, {font = font, drawmode = color})
59 end 48 end
60 49
61 if not height then 50 if width or height then
62 height = 0 51 local res, w, h = rb.font_getstringsize(text, font)
63 else
64 height = (height - h) / 2
65 end
66
67 -- make a copy of the current screen for later
68 --local screen_img = _newimg(LCD_W, LCD_H)
69 local screen_img = _newimg(LCD_W, h * 2)
70 _copy(screen_img, _LCD)
71
72 -- check if the screen buffer is supplied image if so set img to the copy
73 if img == _LCD then
74 img = screen_img
75 end
76 52
77 -- we will be printing the text to the screen then blitting into img 53 if not width then
78 --rb.lcd_clear_display() 54 width = 0
79 _clear(_LCD, opts.bg_pattern or 0, 1, 1, LCD_W, h * 2) 55 else
80 56 width = (width - w) / 2
81 if w > LCD_W then -- text is too long for the screen do it in chunks 57 end
82 local l = 1
83 local resp, wp, hp
84 local lenr = text:len()
85
86 while lenr > 1 do
87 l = lenr
88 resp, wp, hp = rb.font_getstringsize(text:sub(1, l), font)
89
90 while wp >= LCD_W and l > 1 do
91 l = l - 1
92 resp, wp, hp = rb.font_getstringsize(text:sub( 1, l), font)
93 end
94
95 rb.lcd_putsxy(0, 0, text:sub(1, l))
96 text = text:sub(l)
97
98 if x + width > img:width() or y + height > img:height() then
99 break
100 end
101
102 -- using the mask we made blit color into img
103 _copy(img, _LCD, x + width, y + height, _NIL, _NIL, _NIL, _NIL, false, BSAND, color)
104 x = x + wp
105 --rb.lcd_clear_display()
106 _clear(_LCD, opts.bg_pattern or 0, 1, 1, LCD_W, h * 2)
107 58
108 lenr = text:len() 59 if not height then
60 height = 0
61 else
62 height = (height - h) / 2
109 end 63 end
110 else --w <= LCD_W 64 x = width + x
111 rb.lcd_putsxy(0, 0, text) 65 y = height + y
112 66
113 -- using the mask we made blit color into img
114 _copy(img, _LCD, x + width, y + height, _NIL, _NIL, _NIL, _NIL, false, BSAND, color)
115 end 67 end
116 68
117 _copy(_LCD, screen_img) -- restore screen 69 rb.lcd_putsxy(x, y, text)
70
118 rb.set_viewport() -- set viewport default 71 rb.set_viewport() -- set viewport default
119 return res, w, h 72 return res, w, h
120 end 73 end
diff --git a/apps/plugins/lua/include_lua/image_save.lua b/apps/plugins/lua/include_lua/image_save.lua
index 4735af46d7..27e63ca65a 100644
--- a/apps/plugins/lua/include_lua/image_save.lua
+++ b/apps/plugins/lua/include_lua/image_save.lua
@@ -198,7 +198,7 @@ do
198 end 198 end
199 199
200 -- Bitmap lines start at bottom unless biHeight is negative 200 -- Bitmap lines start at bottom unless biHeight is negative
201 for point in _points(img, 1, h, w + bytesleft, 1) do 201 for point in _points(img, 1, h, w + bytesleft, 1, 1, 1, true) do
202 imgdata[#imgdata + 1] = fs_bytes_E(bpp, point or 0) 202 imgdata[#imgdata + 1] = fs_bytes_E(bpp, point or 0)
203 203
204 if #fbuffer >= 31 then -- buffered write, increase # for performance 204 if #fbuffer >= 31 then -- buffered write, increase # for performance
diff --git a/apps/plugins/lua/include_lua/printtable.lua b/apps/plugins/lua/include_lua/printtable.lua
index c70fc1343f..02f3935ae6 100644
--- a/apps/plugins/lua/include_lua/printtable.lua
+++ b/apps/plugins/lua/include_lua/printtable.lua
@@ -145,13 +145,14 @@ function print_table(t, t_count, settings)
145 145
146 local wrap, justify, start, curpos, co_routine, hasheader, m_sel 146 local wrap, justify, start, curpos, co_routine, hasheader, m_sel
147 local header_fgc, header_bgc, item_fgc, item_bgc, item_selc 147 local header_fgc, header_bgc, item_fgc, item_bgc, item_selc
148 local table_linedesc, drawsep, overflow, dpad_fn 148 local table_linedesc, drawsep, overflow, dpad_fn, pagescroll
149 do 149 do
150 local s = settings or _print.get_settings() 150 local s = settings or _print.get_settings()
151 wrap, justify = s.wrap, s.justify 151 wrap, justify = s.wrap, s.justify
152 start, curpos = s.start, s.curpos 152 start, curpos = s.start, s.curpos
153 co_routine = s.co_routine 153 co_routine = s.co_routine
154 hasheader = s.hasheader 154 hasheader = s.hasheader
155 pagescroll = s.pagescroll
155 drawsep = s.drawsep 156 drawsep = s.drawsep
156 sb_width = s.sb_width or sb_width 157 sb_width = s.sb_width or sb_width
157 m_sel = false 158 m_sel = false
@@ -234,8 +235,13 @@ function print_table(t, t_count, settings)
234 dpad_fn(t_p.col, -1, -t_p.col_scrl, t_p.row, -1, -t_p.row_scrl, 235 dpad_fn(t_p.col, -1, -t_p.col_scrl, t_p.row, -1, -t_p.row_scrl,
235 nil, overflow, (t_p.row + t_p.vcursor - 1)) 236 nil, overflow, (t_p.row + t_p.vcursor - 1))
236 237
238
239 if pagescroll == true then
240 t_p.row = t_p.row + y_chg * maxline - 1
241 end
237 t_p.vcursor = t_p.vcursor + y_chg 242 t_p.vcursor = t_p.vcursor + y_chg
238 243
244
239 if t_p.vcursor > maxline or t_p.vcursor < t_p.vcursor_min then 245 if t_p.vcursor > maxline or t_p.vcursor < t_p.vcursor_min then
240 t_p.row = yi 246 t_p.row = yi
241 end 247 end
@@ -268,6 +274,7 @@ function print_table(t, t_count, settings)
268 elseif y_chg ~= 0 then 274 elseif y_chg ~= 0 then
269 --t_p.col = 0 -- reset column to the beginning 275 --t_p.col = 0 -- reset column to the beginning
270 _print.clear() 276 _print.clear()
277
271 _print.opt.sel_line(t_p.vcursor) 278 _print.opt.sel_line(t_p.vcursor)
272 279
273 t_p.row_scrl = set_accel(timeb, t_p.row_scrl, t_p) 280 t_p.row_scrl = set_accel(timeb, t_p.row_scrl, t_p)