diff options
Diffstat (limited to 'apps/plugins/lua/include_lua/lcd.lua')
-rw-r--r-- | apps/plugins/lua/include_lua/lcd.lua | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/apps/plugins/lua/include_lua/lcd.lua b/apps/plugins/lua/include_lua/lcd.lua index e0a3c5895a..f4bb0db695 100644 --- a/apps/plugins/lua/include_lua/lcd.lua +++ b/apps/plugins/lua/include_lua/lcd.lua | |||
@@ -51,7 +51,6 @@ local _lcd = {} do | |||
51 | 51 | ||
52 | --internal constants | 52 | --internal constants |
53 | local _NIL = nil -- _NIL placeholder | 53 | local _NIL = nil -- _NIL placeholder |
54 | local LCD_W, LCD_H = rb.LCD_WIDTH, rb.LCD_HEIGHT | ||
55 | 54 | ||
56 | -- clamps value to >= min and <= max | 55 | -- clamps value to >= min and <= max |
57 | local function clamp(val, min, max) | 56 | local function clamp(val, min, max) |
@@ -65,21 +64,21 @@ local _lcd = {} do | |||
65 | end | 64 | end |
66 | 65 | ||
67 | -- return a copy of lcd screen | 66 | -- return a copy of lcd screen |
68 | local function duplicate(t, screen_img) | 67 | _lcd.duplicate = function(t, screen_img) |
69 | screen_img = screen_img or rb.new_image() | 68 | screen_img = screen_img or rb.new_image() |
70 | screen_img:copy(rb.lcd_framebuffer()) | 69 | screen_img:copy(rb.lcd_framebuffer()) |
71 | return screen_img | 70 | return screen_img |
72 | end | 71 | end |
73 | 72 | ||
74 | -- updates screen in specified rectangle | 73 | -- updates screen in specified rectangle |
75 | local function update_rect(t, x, y, w, h) | 74 | _lcd.update_rect = function(t, x, y, w, h) |
76 | rb.lcd_update_rect(x - 1, y - 1, | 75 | rb.lcd_update_rect(x - 1, y - 1, |
77 | clamp(x + w, 1, LCD_W) - 1, | 76 | clamp(x + w, 1, rb.LCD_WIDTH) - 1, |
78 | clamp(y + h, 1, LCD_H) - 1) | 77 | clamp(y + h, 1, rb.LCD_HEIGHT) - 1) |
79 | end | 78 | end |
80 | 79 | ||
81 | -- clears lcd, optional.. ([color, x1, y1, x2, y2, clip]) | 80 | -- clears lcd, optional.. ([color, x1, y1, x2, y2, clip]) |
82 | local function clear(t, clr, ...) | 81 | _lcd.clear = function(t, clr, ...) |
83 | rb.lcd_scroll_stop() --rb really doesn't like bg change while scroll | 82 | rb.lcd_scroll_stop() --rb really doesn't like bg change while scroll |
84 | if clr == _NIL and ... == _NIL then | 83 | if clr == _NIL and ... == _NIL then |
85 | rb.lcd_clear_display() | 84 | rb.lcd_clear_display() |
@@ -89,7 +88,7 @@ local _lcd = {} do | |||
89 | end | 88 | end |
90 | 89 | ||
91 | -- loads an image to the screen | 90 | -- loads an image to the screen |
92 | local function image(t, src, x, y) | 91 | _lcd.image = function(t, src, x, y) |
93 | if not src then --make sure an image was passed, otherwise bail | 92 | if not src then --make sure an image was passed, otherwise bail |
94 | rb.splash(rb.HZ, "No Image!") | 93 | rb.splash(rb.HZ, "No Image!") |
95 | return _NIL | 94 | return _NIL |
@@ -98,19 +97,19 @@ local _lcd = {} do | |||
98 | end | 97 | end |
99 | 98 | ||
100 | -- Formattable version of splash | 99 | -- Formattable version of splash |
101 | local function splashf(t, timeout, ...) | 100 | _lcd.splashf = function(t, timeout, ...) |
102 | rb.splash(timeout, string.format(...)) | 101 | rb.splash(timeout, string.format(...)) |
103 | end | 102 | end |
104 | 103 | ||
105 | -- Gets size of text | 104 | -- Gets size of text |
106 | local function text_extent(t, msg, font) | 105 | _lcd.text_extent = function(t, msg, font) |
107 | font = font or rb.FONT_UI | 106 | font = font or rb.FONT_UI |
108 | 107 | ||
109 | return rb.font_getstringsize(msg, font) | 108 | return rb.font_getstringsize(msg, font) |
110 | end | 109 | end |
111 | 110 | ||
112 | -- Sets viewport size | 111 | -- Sets viewport size |
113 | local function set_viewport(t, vp) | 112 | _lcd.set_viewport = function(t, vp) |
114 | if not vp then rb.set_viewport() return end | 113 | if not vp then rb.set_viewport() return end |
115 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens | 114 | if rb.LCD_DEPTH == 2 then -- invert 2-bit screens |
116 | --vp.drawmode = bit.bxor(vp.drawmode, 4) | 115 | --vp.drawmode = bit.bxor(vp.drawmode, 4) |
@@ -133,14 +132,17 @@ local _lcd = {} do | |||
133 | end | 132 | end |
134 | 133 | ||
135 | --expose functions to the outside through _lcd table | 134 | --expose functions to the outside through _lcd table |
135 | --[[ | ||
136 | _lcd.text_extent = text_extent | 136 | _lcd.text_extent = text_extent |
137 | _lcd.set_viewport = set_viewport | 137 | _lcd.set_viewport = set_viewport |
138 | _lcd.duplicate = duplicate | 138 | _lcd.duplicate = duplicate |
139 | _lcd.update = rb.lcd_update | 139 | _lcd.update = _update |
140 | _lcd.update_rect = update_rect | 140 | _lcd.update_rect = update_rect |
141 | _lcd.clear = clear | 141 | _lcd.clear = clear |
142 | _lcd.splashf = splashf | 142 | _lcd.splashf = splashf |
143 | _lcd.image = image | 143 | _lcd.image = image |
144 | ]] | ||
145 | _lcd.update = rb.lcd_update | ||
144 | _lcd.DEPTH = rb.LCD_DEPTH | 146 | _lcd.DEPTH = rb.LCD_DEPTH |
145 | _lcd.W = rb.LCD_WIDTH | 147 | _lcd.W = rb.LCD_WIDTH |
146 | _lcd.H = rb.LCD_HEIGHT | 148 | _lcd.H = rb.LCD_HEIGHT |