diff options
Diffstat (limited to 'apps/plugins/lua/include_lua/draw_text.lua')
-rw-r--r-- | apps/plugins/lua/include_lua/draw_text.lua | 85 |
1 files changed, 19 insertions, 66 deletions
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 | ||
25 | if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end | 25 | if not rb.lcd_framebuffer then rb.splash(rb.HZ, "No Support!") return nil end |
26 | |||
27 | do | 26 | do |
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 |