summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/lua/rocklib.c73
-rw-r--r--apps/plugins/test_viewports.c2
-rw-r--r--apps/plugins/test_viewports.lua116
3 files changed, 189 insertions, 2 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c
index 4dc7081711..506fc6163d 100644
--- a/apps/plugins/lua/rocklib.c
+++ b/apps/plugins/lua/rocklib.c
@@ -181,6 +181,73 @@ static inline void rli_init(lua_State *L)
181 181
182#define RB_WRAP(M) static int rock_##M(lua_State *L) 182#define RB_WRAP(M) static int rock_##M(lua_State *L)
183 183
184/* Helper function for opt_viewport */
185static void check_tablevalue(lua_State *L, const char* key, int tablepos, void* res, bool unsigned_val)
186{
187 lua_pushstring(L, key); /* Push the key on the stack */
188 lua_gettable(L, tablepos); /* Find table[key] (pops key off the stack) */
189
190 if(!lua_isnoneornil(L, -1))
191 {
192 if(unsigned_val)
193 *(unsigned*)res = luaL_checkint(L, -1);
194 else
195 *(int*)res = luaL_checkint(L, -1);
196 }
197
198 lua_pop(L, 1); /* Pop the value off the stack */
199}
200
201static struct viewport* opt_viewport(lua_State *L, int narg, struct viewport* alt)
202{
203 if(lua_isnoneornil(L, narg))
204 return alt;
205
206 int tablepos = lua_gettop(L);
207
208 lua_pushliteral(L, "vp"); /* push 'vp' on the stack */
209 struct viewport *vp = (struct viewport*)lua_newuserdata(L, sizeof(struct viewport)); /* allocate memory and push it as udata on the stack */
210 memset(vp, 0, sizeof(struct viewport)); /* Init viewport values to 0 */
211 lua_settable(L, tablepos); /* table['vp'] = vp (pops key & value off the stack) */
212
213 luaL_checktype(L, narg, LUA_TTABLE);
214
215 check_tablevalue(L, "x", tablepos, &vp->x, false);
216 check_tablevalue(L, "y", tablepos, &vp->y, false);
217 check_tablevalue(L, "width", tablepos, &vp->width, false);
218 check_tablevalue(L, "height", tablepos, &vp->height, false);
219#ifdef HAVE_LCD_BITMAP
220 check_tablevalue(L, "font", tablepos, &vp->font, false);
221 check_tablevalue(L, "drawmode", tablepos, &vp->drawmode, false);
222#endif
223#if LCD_DEPTH > 1
224 check_tablevalue(L, "fg_pattern", tablepos, &vp->fg_pattern, true);
225 check_tablevalue(L, "bg_pattern", tablepos, &vp->bg_pattern, true);
226#ifdef HAVE_LCD_COLOR
227 check_tablevalue(L, "lss_pattern", tablepos, &vp->lss_pattern, true);
228 check_tablevalue(L, "lse_pattern", tablepos, &vp->lse_pattern, true);
229 check_tablevalue(L, "lst_pattern", tablepos, &vp->lse_pattern, true);
230#endif
231#endif
232
233 return vp;
234}
235
236RB_WRAP(set_viewport)
237{
238 struct viewport *vp = opt_viewport(L, 1, NULL);
239 int screen = luaL_optint(L, 2, SCREEN_MAIN);
240 rb->screens[screen]->set_viewport(vp);
241 return 0;
242}
243
244RB_WRAP(clear_viewport)
245{
246 int screen = luaL_optint(L, 2, SCREEN_MAIN);
247 rb->screens[screen]->clear_viewport();
248 return 0;
249}
250
184RB_WRAP(splash) 251RB_WRAP(splash)
185{ 252{
186 int ticks = luaL_checkint(L, 1); 253 int ticks = luaL_checkint(L, 1);
@@ -837,6 +904,8 @@ static const luaL_Reg rocklib[] =
837 904
838 R(font_getstringsize), 905 R(font_getstringsize),
839 R(read_bmp_file), 906 R(read_bmp_file),
907 R(set_viewport),
908 R(clear_viewport),
840 909
841 {"new_image", rli_new}, 910 {"new_image", rli_new},
842 911
@@ -866,9 +935,11 @@ LUALIB_API int luaopen_rock(lua_State *L)
866 RB_CONSTANT(SEEK_SET); 935 RB_CONSTANT(SEEK_SET);
867 RB_CONSTANT(SEEK_CUR); 936 RB_CONSTANT(SEEK_CUR);
868 RB_CONSTANT(SEEK_END); 937 RB_CONSTANT(SEEK_END);
938
939 RB_CONSTANT(FONT_SYSFIXED);
940 RB_CONSTANT(FONT_UI);
869 941
870 rli_init(L); 942 rli_init(L);
871 943
872 return 1; 944 return 1;
873} 945}
874
diff --git a/apps/plugins/test_viewports.c b/apps/plugins/test_viewports.c
index 5a2ec542cc..08c23a91c8 100644
--- a/apps/plugins/test_viewports.c
+++ b/apps/plugins/test_viewports.c
@@ -5,7 +5,7 @@
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id: helloworld.c 12807 2007-03-16 21:56:08Z amiconn $ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2007 Dave Chapman 10 * Copyright (C) 2007 Dave Chapman
11 * 11 *
diff --git a/apps/plugins/test_viewports.lua b/apps/plugins/test_viewports.lua
new file mode 100644
index 0000000000..5af1ef4fb9
--- /dev/null
+++ b/apps/plugins/test_viewports.lua
@@ -0,0 +1,116 @@
1--[[
2 __________ __ ___.
3 Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 \/ \/ \/ \/ \/
8 $Id$
9
10 Port of test_viewports.c to Lua
11
12 Copyright (C) 2009 by Maurus Cuelenaere
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License
16 as published by the Free Software Foundation; either version 2
17 of the License, or (at your option) any later version.
18
19 This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 KIND, either express or implied.
21
22]]--
23
24-- TODO: outsource this
25rb.DRMODE_SOLID = 3
26rb.LCD_BLACK = rb.lcd_rgbpack(0, 0, 0)
27rb.LCD_WHITE = rb.lcd_rgbpack(255, 255, 255)
28rb.LCD_DEFAULT_FG = rb.LCD_WHITE
29rb.LCD_DEFAULT_BG = rb.LCD_BLACK
30
31BGCOLOR_1 = rb.lcd_rgbpack(255,255,0)
32BGCOLOR_2 = rb.lcd_rgbpack(0,255,0)
33FGCOLOR_1 = rb.lcd_rgbpack(0,0,255)
34
35local vp0 =
36{
37 x = 0,
38 y = 0,
39 width = rb.LCD_WIDTH,
40 height = 20,
41 font = rb.FONT_UI,
42 drawmode = rb.DRMODE_SOLID,
43 fg_pattern = rb.LCD_DEFAULT_FG,
44 bg_pattern = BGCOLOR_1
45}
46
47local vp1 =
48{
49 x = rb.LCD_WIDTH / 10,
50 y = 20,
51 width = rb.LCD_WIDTH / 3,
52 height = rb.LCD_HEIGHT / 2,
53 font = rb.FONT_SYSFIXED,
54 drawmode = rb.DRMODE_SOLID,
55 fg_pattern = rb.LCD_DEFAULT_FG,
56 bg_pattern = rb.LCD_DEFAULT_BG
57};
58
59local vp2 =
60{
61 x = rb.LCD_WIDTH / 2,
62 y = 40,
63 width = rb.LCD_WIDTH / 3,
64 height = (rb.LCD_HEIGHT / 2),
65 font = rb.FONT_UI,
66 drawmode = rb.DRMODE_SOLID,
67 fg_pattern = FGCOLOR_1,
68 bg_pattern = BGCOLOR_2
69};
70
71
72local vp3 =
73{
74 x = rb.LCD_WIDTH / 4,
75 y = (5 * rb.LCD_HEIGHT) / 8,
76 width = rb.LCD_WIDTH / 2,
77 height = (rb.LCD_HEIGHT / 4),
78 font = rb.FONT_SYSFIXED,
79 drawmode = rb.DRMODE_SOLID,
80 fg_pattern = rb.LCD_BLACK,
81 bg_pattern = rb.LCD_WHITE
82};
83
84rb.set_viewport(vp0)
85rb.clear_viewport()
86rb.lcd_puts_scroll(0,0,"Viewport testing plugin - this is a scrolling title")
87
88rb.set_viewport(vp1);
89rb.clear_viewport();
90
91for i = 0, 3 do
92 rb.lcd_puts_scroll(0,i,string.format("Left text, scrolling_line %d",i));
93end
94
95rb.set_viewport(vp2);
96rb.clear_viewport();
97for i = 0, 3 do
98 rb.lcd_puts_scroll(1,i,string.format("Right text, scrolling line %d",i));
99end
100
101local y = -10
102for i = -10, vp2.width + 10, 5 do
103 rb.lcd_drawline(i, y, i, vp2.height - y);
104end
105
106rb.set_viewport(vp3);
107rb.clear_viewport();
108for i = 1, 2 do
109 rb.lcd_puts_scroll(2,i,string.format("Bottom text, a scrolling line %d",i));
110end
111rb.lcd_puts_scroll(4,3,"Short line")
112rb.lcd_update()
113
114rb.button_get(true)
115
116rb.set_viewport() \ No newline at end of file