2009-05-21 19:01:41 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Dan Everton (safetydan)
|
|
|
|
* Copyright (C) 2009 Maurus Cuelenaere
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define lrocklib_c
|
|
|
|
#define LUA_LIB
|
|
|
|
|
|
|
|
#include "lua.h"
|
|
|
|
|
|
|
|
#include "lauxlib.h"
|
|
|
|
#include "rocklib.h"
|
2009-10-26 17:07:56 +00:00
|
|
|
#include "lib/helper.h"
|
2012-01-26 23:05:20 +00:00
|
|
|
#include "lib/pluginlib_actions.h"
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2009-05-21 19:42:14 +00:00
|
|
|
/*
|
|
|
|
* http://www.lua.org/manual/5.1/manual.html#lua_CFunction
|
|
|
|
*
|
|
|
|
* In order to communicate properly with Lua, a C function must use the following protocol,
|
|
|
|
* which defines the way parameters and results are passed: a C function receives its arguments
|
|
|
|
* from Lua in its stack in direct order (the first argument is pushed first). To return values to Lua,
|
|
|
|
* a C function just pushes them onto the stack, in direct order (the first result is pushed first),
|
|
|
|
* and returns the number of results. Any other value in the stack below the results will be properly
|
2018-05-31 12:15:05 +00:00
|
|
|
* discarded by Lua. Like a Lua function, a C function called by Lua can also return many results.
|
2010-06-18 12:28:34 +00:00
|
|
|
*
|
|
|
|
* When porting new functions, don't forget to check rocklib_aux.pl whether it automatically creates
|
|
|
|
* wrappers for the function and if so, add the function names to @forbidden_functions. This is to
|
|
|
|
* prevent namespace collisions and adding duplicate wrappers.
|
2009-05-21 19:42:14 +00:00
|
|
|
*/
|
2009-05-24 01:54:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* -----------------------------
|
|
|
|
*
|
|
|
|
* Rockbox wrappers start here!
|
|
|
|
*
|
|
|
|
* -----------------------------
|
|
|
|
*/
|
|
|
|
|
2018-09-17 17:28:10 +00:00
|
|
|
#define RB_WRAP(func) static int rock_##func(lua_State UNUSED_ATTR *L)
|
2009-10-26 17:07:56 +00:00
|
|
|
#define SIMPLE_VOID_WRAPPER(func) RB_WRAP(func) { (void)L; func(); return 0; }
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2009-05-25 14:21:17 +00:00
|
|
|
/* Helper function for opt_viewport */
|
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that
need to be unpacked in order to work on them at a pixel level.
This caused a few issues on 1 & 2-bit devices:
Greatly Oversized data arrays for bitmaps
Improper handling of native image data
Framebuffer data was near unusable without jumping through hoops
Conversion between native addressing and per pixel addressing
incurs extra overhead but it is much faster to do it
on the 'C' side rather than in lua.
Not to mention the advantage of a unified interface for the end programer
-------------------------------------------------------------------
Adds a sane way to access each pixel of image data
Adds:
--------------------------------------------------------------------
img:clear([color],[x1],[y1],[x2],[y2])
(set whole image or a portion to a particular value)
--------------------------------------------------------------------
img:invert([x1],[y1],[x2],[y2])
(inverts whole image or a portion)
--------------------------------------------------------------------
img:marshal([x1],[y1],[x2],[y2],[funct])
(calls funct for each point defined by rect of x1,y1 x2,y2
returns value and allows setting value of each point return
nil to terminate early)
--------------------------------------------------------------------
img:points([x1],[y1],[x2],[y2],[dx],[dy])
(returns iterator function that steps delta-x and delta-y pixels each call
returns value of pixel each call but doesn't allow setting to a new value
compare to lua pairs method)
--------------------------------------------------------------------
img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
(copies all or part of an image -- straight copy or special ops
optionally calls funct for each point defined by rect of
x1, y1, w, h and x2, y2, w, h for dest and src images
returns value of dst and src and allows setting value of
each point return nil to terminate early)
--------------------------------------------------------------------
img:line(x1, y1, x2, y2, color)
--------------------------------------------------------------------
img:ellipse(x1, y1, x2, y2, color, [fillcolor]
--------------------------------------------------------------------
Fixed handling of 2-bit vertical integrated screens
Added direct element access for saving / restoring native image etc.
Added more data to tostring() handler and a way to access individual items
Added equals method to see if two variables reference the same image address
(doesn't check if two separate images contain the same 'picture')
Optimized get and set routines
Fixed out of bound x coord access shifting to next line
Added lua include files to expose new functionality
Finished image saving routine
Static allocation of set_viewport struct faster + saves ram over dynamic
Cleaned up code
Fixed pixel get/set for 1/2 bit devices
Fixed handling for 24-bit devices (32?)
-------------------------------------------------------------------------
Example lua script to follow on forums
-------------------------------------------------------------------------
Change-Id: I8a9ff0ff72aacf4b1662767ccb2b312fc355239c
2018-07-23 00:50:22 +00:00
|
|
|
static void check_tablevalue(lua_State *L,
|
|
|
|
const char* key,
|
|
|
|
int tablepos,
|
|
|
|
void* res,
|
|
|
|
bool is_unsigned)
|
2009-05-25 14:21:17 +00:00
|
|
|
{
|
2009-05-25 19:05:53 +00:00
|
|
|
lua_getfield(L, tablepos, key); /* Find table[key] */
|
2009-05-25 14:21:17 +00:00
|
|
|
|
2018-09-17 17:28:10 +00:00
|
|
|
int val = lua_tointeger(L, -1);
|
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that
need to be unpacked in order to work on them at a pixel level.
This caused a few issues on 1 & 2-bit devices:
Greatly Oversized data arrays for bitmaps
Improper handling of native image data
Framebuffer data was near unusable without jumping through hoops
Conversion between native addressing and per pixel addressing
incurs extra overhead but it is much faster to do it
on the 'C' side rather than in lua.
Not to mention the advantage of a unified interface for the end programer
-------------------------------------------------------------------
Adds a sane way to access each pixel of image data
Adds:
--------------------------------------------------------------------
img:clear([color],[x1],[y1],[x2],[y2])
(set whole image or a portion to a particular value)
--------------------------------------------------------------------
img:invert([x1],[y1],[x2],[y2])
(inverts whole image or a portion)
--------------------------------------------------------------------
img:marshal([x1],[y1],[x2],[y2],[funct])
(calls funct for each point defined by rect of x1,y1 x2,y2
returns value and allows setting value of each point return
nil to terminate early)
--------------------------------------------------------------------
img:points([x1],[y1],[x2],[y2],[dx],[dy])
(returns iterator function that steps delta-x and delta-y pixels each call
returns value of pixel each call but doesn't allow setting to a new value
compare to lua pairs method)
--------------------------------------------------------------------
img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
(copies all or part of an image -- straight copy or special ops
optionally calls funct for each point defined by rect of
x1, y1, w, h and x2, y2, w, h for dest and src images
returns value of dst and src and allows setting value of
each point return nil to terminate early)
--------------------------------------------------------------------
img:line(x1, y1, x2, y2, color)
--------------------------------------------------------------------
img:ellipse(x1, y1, x2, y2, color, [fillcolor]
--------------------------------------------------------------------
Fixed handling of 2-bit vertical integrated screens
Added direct element access for saving / restoring native image etc.
Added more data to tostring() handler and a way to access individual items
Added equals method to see if two variables reference the same image address
(doesn't check if two separate images contain the same 'picture')
Optimized get and set routines
Fixed out of bound x coord access shifting to next line
Added lua include files to expose new functionality
Finished image saving routine
Static allocation of set_viewport struct faster + saves ram over dynamic
Cleaned up code
Fixed pixel get/set for 1/2 bit devices
Fixed handling for 24-bit devices (32?)
-------------------------------------------------------------------------
Example lua script to follow on forums
-------------------------------------------------------------------------
Change-Id: I8a9ff0ff72aacf4b1662767ccb2b312fc355239c
2018-07-23 00:50:22 +00:00
|
|
|
|
|
|
|
if(is_unsigned)
|
|
|
|
*(unsigned*)res = (unsigned) val;
|
|
|
|
else
|
|
|
|
*(int*)res = val;
|
2009-05-25 14:21:17 +00:00
|
|
|
|
|
|
|
lua_pop(L, 1); /* Pop the value off the stack */
|
|
|
|
}
|
|
|
|
|
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that
need to be unpacked in order to work on them at a pixel level.
This caused a few issues on 1 & 2-bit devices:
Greatly Oversized data arrays for bitmaps
Improper handling of native image data
Framebuffer data was near unusable without jumping through hoops
Conversion between native addressing and per pixel addressing
incurs extra overhead but it is much faster to do it
on the 'C' side rather than in lua.
Not to mention the advantage of a unified interface for the end programer
-------------------------------------------------------------------
Adds a sane way to access each pixel of image data
Adds:
--------------------------------------------------------------------
img:clear([color],[x1],[y1],[x2],[y2])
(set whole image or a portion to a particular value)
--------------------------------------------------------------------
img:invert([x1],[y1],[x2],[y2])
(inverts whole image or a portion)
--------------------------------------------------------------------
img:marshal([x1],[y1],[x2],[y2],[funct])
(calls funct for each point defined by rect of x1,y1 x2,y2
returns value and allows setting value of each point return
nil to terminate early)
--------------------------------------------------------------------
img:points([x1],[y1],[x2],[y2],[dx],[dy])
(returns iterator function that steps delta-x and delta-y pixels each call
returns value of pixel each call but doesn't allow setting to a new value
compare to lua pairs method)
--------------------------------------------------------------------
img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
(copies all or part of an image -- straight copy or special ops
optionally calls funct for each point defined by rect of
x1, y1, w, h and x2, y2, w, h for dest and src images
returns value of dst and src and allows setting value of
each point return nil to terminate early)
--------------------------------------------------------------------
img:line(x1, y1, x2, y2, color)
--------------------------------------------------------------------
img:ellipse(x1, y1, x2, y2, color, [fillcolor]
--------------------------------------------------------------------
Fixed handling of 2-bit vertical integrated screens
Added direct element access for saving / restoring native image etc.
Added more data to tostring() handler and a way to access individual items
Added equals method to see if two variables reference the same image address
(doesn't check if two separate images contain the same 'picture')
Optimized get and set routines
Fixed out of bound x coord access shifting to next line
Added lua include files to expose new functionality
Finished image saving routine
Static allocation of set_viewport struct faster + saves ram over dynamic
Cleaned up code
Fixed pixel get/set for 1/2 bit devices
Fixed handling for 24-bit devices (32?)
-------------------------------------------------------------------------
Example lua script to follow on forums
-------------------------------------------------------------------------
Change-Id: I8a9ff0ff72aacf4b1662767ccb2b312fc355239c
2018-07-23 00:50:22 +00:00
|
|
|
static inline struct viewport* opt_viewport(lua_State *L,
|
|
|
|
int narg,
|
|
|
|
struct viewport* vp,
|
|
|
|
struct viewport* alt)
|
2009-05-25 14:21:17 +00:00
|
|
|
{
|
|
|
|
if(lua_isnoneornil(L, narg))
|
|
|
|
return alt;
|
|
|
|
|
|
|
|
luaL_checktype(L, narg, LUA_TTABLE);
|
|
|
|
|
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that
need to be unpacked in order to work on them at a pixel level.
This caused a few issues on 1 & 2-bit devices:
Greatly Oversized data arrays for bitmaps
Improper handling of native image data
Framebuffer data was near unusable without jumping through hoops
Conversion between native addressing and per pixel addressing
incurs extra overhead but it is much faster to do it
on the 'C' side rather than in lua.
Not to mention the advantage of a unified interface for the end programer
-------------------------------------------------------------------
Adds a sane way to access each pixel of image data
Adds:
--------------------------------------------------------------------
img:clear([color],[x1],[y1],[x2],[y2])
(set whole image or a portion to a particular value)
--------------------------------------------------------------------
img:invert([x1],[y1],[x2],[y2])
(inverts whole image or a portion)
--------------------------------------------------------------------
img:marshal([x1],[y1],[x2],[y2],[funct])
(calls funct for each point defined by rect of x1,y1 x2,y2
returns value and allows setting value of each point return
nil to terminate early)
--------------------------------------------------------------------
img:points([x1],[y1],[x2],[y2],[dx],[dy])
(returns iterator function that steps delta-x and delta-y pixels each call
returns value of pixel each call but doesn't allow setting to a new value
compare to lua pairs method)
--------------------------------------------------------------------
img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
(copies all or part of an image -- straight copy or special ops
optionally calls funct for each point defined by rect of
x1, y1, w, h and x2, y2, w, h for dest and src images
returns value of dst and src and allows setting value of
each point return nil to terminate early)
--------------------------------------------------------------------
img:line(x1, y1, x2, y2, color)
--------------------------------------------------------------------
img:ellipse(x1, y1, x2, y2, color, [fillcolor]
--------------------------------------------------------------------
Fixed handling of 2-bit vertical integrated screens
Added direct element access for saving / restoring native image etc.
Added more data to tostring() handler and a way to access individual items
Added equals method to see if two variables reference the same image address
(doesn't check if two separate images contain the same 'picture')
Optimized get and set routines
Fixed out of bound x coord access shifting to next line
Added lua include files to expose new functionality
Finished image saving routine
Static allocation of set_viewport struct faster + saves ram over dynamic
Cleaned up code
Fixed pixel get/set for 1/2 bit devices
Fixed handling for 24-bit devices (32?)
-------------------------------------------------------------------------
Example lua script to follow on forums
-------------------------------------------------------------------------
Change-Id: I8a9ff0ff72aacf4b1662767ccb2b312fc355239c
2018-07-23 00:50:22 +00:00
|
|
|
check_tablevalue(L, "x", narg, &vp->x, false);
|
|
|
|
check_tablevalue(L, "y", narg, &vp->y, false);
|
|
|
|
check_tablevalue(L, "width", narg, &vp->width, false);
|
|
|
|
check_tablevalue(L, "height", narg, &vp->height, false);
|
2009-05-25 14:21:17 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that
need to be unpacked in order to work on them at a pixel level.
This caused a few issues on 1 & 2-bit devices:
Greatly Oversized data arrays for bitmaps
Improper handling of native image data
Framebuffer data was near unusable without jumping through hoops
Conversion between native addressing and per pixel addressing
incurs extra overhead but it is much faster to do it
on the 'C' side rather than in lua.
Not to mention the advantage of a unified interface for the end programer
-------------------------------------------------------------------
Adds a sane way to access each pixel of image data
Adds:
--------------------------------------------------------------------
img:clear([color],[x1],[y1],[x2],[y2])
(set whole image or a portion to a particular value)
--------------------------------------------------------------------
img:invert([x1],[y1],[x2],[y2])
(inverts whole image or a portion)
--------------------------------------------------------------------
img:marshal([x1],[y1],[x2],[y2],[funct])
(calls funct for each point defined by rect of x1,y1 x2,y2
returns value and allows setting value of each point return
nil to terminate early)
--------------------------------------------------------------------
img:points([x1],[y1],[x2],[y2],[dx],[dy])
(returns iterator function that steps delta-x and delta-y pixels each call
returns value of pixel each call but doesn't allow setting to a new value
compare to lua pairs method)
--------------------------------------------------------------------
img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
(copies all or part of an image -- straight copy or special ops
optionally calls funct for each point defined by rect of
x1, y1, w, h and x2, y2, w, h for dest and src images
returns value of dst and src and allows setting value of
each point return nil to terminate early)
--------------------------------------------------------------------
img:line(x1, y1, x2, y2, color)
--------------------------------------------------------------------
img:ellipse(x1, y1, x2, y2, color, [fillcolor]
--------------------------------------------------------------------
Fixed handling of 2-bit vertical integrated screens
Added direct element access for saving / restoring native image etc.
Added more data to tostring() handler and a way to access individual items
Added equals method to see if two variables reference the same image address
(doesn't check if two separate images contain the same 'picture')
Optimized get and set routines
Fixed out of bound x coord access shifting to next line
Added lua include files to expose new functionality
Finished image saving routine
Static allocation of set_viewport struct faster + saves ram over dynamic
Cleaned up code
Fixed pixel get/set for 1/2 bit devices
Fixed handling for 24-bit devices (32?)
-------------------------------------------------------------------------
Example lua script to follow on forums
-------------------------------------------------------------------------
Change-Id: I8a9ff0ff72aacf4b1662767ccb2b312fc355239c
2018-07-23 00:50:22 +00:00
|
|
|
check_tablevalue(L, "font", narg, &vp->font, false);
|
|
|
|
check_tablevalue(L, "drawmode", narg, &vp->drawmode, false);
|
2009-05-25 14:21:17 +00:00
|
|
|
#endif
|
|
|
|
#if LCD_DEPTH > 1
|
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that
need to be unpacked in order to work on them at a pixel level.
This caused a few issues on 1 & 2-bit devices:
Greatly Oversized data arrays for bitmaps
Improper handling of native image data
Framebuffer data was near unusable without jumping through hoops
Conversion between native addressing and per pixel addressing
incurs extra overhead but it is much faster to do it
on the 'C' side rather than in lua.
Not to mention the advantage of a unified interface for the end programer
-------------------------------------------------------------------
Adds a sane way to access each pixel of image data
Adds:
--------------------------------------------------------------------
img:clear([color],[x1],[y1],[x2],[y2])
(set whole image or a portion to a particular value)
--------------------------------------------------------------------
img:invert([x1],[y1],[x2],[y2])
(inverts whole image or a portion)
--------------------------------------------------------------------
img:marshal([x1],[y1],[x2],[y2],[funct])
(calls funct for each point defined by rect of x1,y1 x2,y2
returns value and allows setting value of each point return
nil to terminate early)
--------------------------------------------------------------------
img:points([x1],[y1],[x2],[y2],[dx],[dy])
(returns iterator function that steps delta-x and delta-y pixels each call
returns value of pixel each call but doesn't allow setting to a new value
compare to lua pairs method)
--------------------------------------------------------------------
img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
(copies all or part of an image -- straight copy or special ops
optionally calls funct for each point defined by rect of
x1, y1, w, h and x2, y2, w, h for dest and src images
returns value of dst and src and allows setting value of
each point return nil to terminate early)
--------------------------------------------------------------------
img:line(x1, y1, x2, y2, color)
--------------------------------------------------------------------
img:ellipse(x1, y1, x2, y2, color, [fillcolor]
--------------------------------------------------------------------
Fixed handling of 2-bit vertical integrated screens
Added direct element access for saving / restoring native image etc.
Added more data to tostring() handler and a way to access individual items
Added equals method to see if two variables reference the same image address
(doesn't check if two separate images contain the same 'picture')
Optimized get and set routines
Fixed out of bound x coord access shifting to next line
Added lua include files to expose new functionality
Finished image saving routine
Static allocation of set_viewport struct faster + saves ram over dynamic
Cleaned up code
Fixed pixel get/set for 1/2 bit devices
Fixed handling for 24-bit devices (32?)
-------------------------------------------------------------------------
Example lua script to follow on forums
-------------------------------------------------------------------------
Change-Id: I8a9ff0ff72aacf4b1662767ccb2b312fc355239c
2018-07-23 00:50:22 +00:00
|
|
|
check_tablevalue(L, "fg_pattern", narg, &vp->fg_pattern, true);
|
|
|
|
check_tablevalue(L, "bg_pattern", narg, &vp->bg_pattern, true);
|
2009-05-25 14:21:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return vp;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_WRAP(set_viewport)
|
|
|
|
{
|
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that
need to be unpacked in order to work on them at a pixel level.
This caused a few issues on 1 & 2-bit devices:
Greatly Oversized data arrays for bitmaps
Improper handling of native image data
Framebuffer data was near unusable without jumping through hoops
Conversion between native addressing and per pixel addressing
incurs extra overhead but it is much faster to do it
on the 'C' side rather than in lua.
Not to mention the advantage of a unified interface for the end programer
-------------------------------------------------------------------
Adds a sane way to access each pixel of image data
Adds:
--------------------------------------------------------------------
img:clear([color],[x1],[y1],[x2],[y2])
(set whole image or a portion to a particular value)
--------------------------------------------------------------------
img:invert([x1],[y1],[x2],[y2])
(inverts whole image or a portion)
--------------------------------------------------------------------
img:marshal([x1],[y1],[x2],[y2],[funct])
(calls funct for each point defined by rect of x1,y1 x2,y2
returns value and allows setting value of each point return
nil to terminate early)
--------------------------------------------------------------------
img:points([x1],[y1],[x2],[y2],[dx],[dy])
(returns iterator function that steps delta-x and delta-y pixels each call
returns value of pixel each call but doesn't allow setting to a new value
compare to lua pairs method)
--------------------------------------------------------------------
img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
(copies all or part of an image -- straight copy or special ops
optionally calls funct for each point defined by rect of
x1, y1, w, h and x2, y2, w, h for dest and src images
returns value of dst and src and allows setting value of
each point return nil to terminate early)
--------------------------------------------------------------------
img:line(x1, y1, x2, y2, color)
--------------------------------------------------------------------
img:ellipse(x1, y1, x2, y2, color, [fillcolor]
--------------------------------------------------------------------
Fixed handling of 2-bit vertical integrated screens
Added direct element access for saving / restoring native image etc.
Added more data to tostring() handler and a way to access individual items
Added equals method to see if two variables reference the same image address
(doesn't check if two separate images contain the same 'picture')
Optimized get and set routines
Fixed out of bound x coord access shifting to next line
Added lua include files to expose new functionality
Finished image saving routine
Static allocation of set_viewport struct faster + saves ram over dynamic
Cleaned up code
Fixed pixel get/set for 1/2 bit devices
Fixed handling for 24-bit devices (32?)
-------------------------------------------------------------------------
Example lua script to follow on forums
-------------------------------------------------------------------------
Change-Id: I8a9ff0ff72aacf4b1662767ccb2b312fc355239c
2018-07-23 00:50:22 +00:00
|
|
|
static struct viewport vp;
|
2009-05-25 14:21:17 +00:00
|
|
|
int screen = luaL_optint(L, 2, SCREEN_MAIN);
|
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that
need to be unpacked in order to work on them at a pixel level.
This caused a few issues on 1 & 2-bit devices:
Greatly Oversized data arrays for bitmaps
Improper handling of native image data
Framebuffer data was near unusable without jumping through hoops
Conversion between native addressing and per pixel addressing
incurs extra overhead but it is much faster to do it
on the 'C' side rather than in lua.
Not to mention the advantage of a unified interface for the end programer
-------------------------------------------------------------------
Adds a sane way to access each pixel of image data
Adds:
--------------------------------------------------------------------
img:clear([color],[x1],[y1],[x2],[y2])
(set whole image or a portion to a particular value)
--------------------------------------------------------------------
img:invert([x1],[y1],[x2],[y2])
(inverts whole image or a portion)
--------------------------------------------------------------------
img:marshal([x1],[y1],[x2],[y2],[funct])
(calls funct for each point defined by rect of x1,y1 x2,y2
returns value and allows setting value of each point return
nil to terminate early)
--------------------------------------------------------------------
img:points([x1],[y1],[x2],[y2],[dx],[dy])
(returns iterator function that steps delta-x and delta-y pixels each call
returns value of pixel each call but doesn't allow setting to a new value
compare to lua pairs method)
--------------------------------------------------------------------
img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
(copies all or part of an image -- straight copy or special ops
optionally calls funct for each point defined by rect of
x1, y1, w, h and x2, y2, w, h for dest and src images
returns value of dst and src and allows setting value of
each point return nil to terminate early)
--------------------------------------------------------------------
img:line(x1, y1, x2, y2, color)
--------------------------------------------------------------------
img:ellipse(x1, y1, x2, y2, color, [fillcolor]
--------------------------------------------------------------------
Fixed handling of 2-bit vertical integrated screens
Added direct element access for saving / restoring native image etc.
Added more data to tostring() handler and a way to access individual items
Added equals method to see if two variables reference the same image address
(doesn't check if two separate images contain the same 'picture')
Optimized get and set routines
Fixed out of bound x coord access shifting to next line
Added lua include files to expose new functionality
Finished image saving routine
Static allocation of set_viewport struct faster + saves ram over dynamic
Cleaned up code
Fixed pixel get/set for 1/2 bit devices
Fixed handling for 24-bit devices (32?)
-------------------------------------------------------------------------
Example lua script to follow on forums
-------------------------------------------------------------------------
Change-Id: I8a9ff0ff72aacf4b1662767ccb2b312fc355239c
2018-07-23 00:50:22 +00:00
|
|
|
rb->screens[screen]->set_viewport(opt_viewport(L, 1, &vp, NULL));
|
2009-05-25 14:21:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_WRAP(clear_viewport)
|
|
|
|
{
|
2009-05-25 14:56:59 +00:00
|
|
|
int screen = luaL_optint(L, 1, SCREEN_MAIN);
|
2009-05-25 14:21:17 +00:00
|
|
|
rb->screens[screen]->clear_viewport();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
RB_WRAP(current_tick)
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, *rb->current_tick);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_WRAP(kbd_input)
|
|
|
|
{
|
2009-05-22 22:44:34 +00:00
|
|
|
luaL_Buffer b;
|
|
|
|
luaL_buffinit(L, &b);
|
|
|
|
|
2018-09-17 17:28:10 +00:00
|
|
|
const char *input = lua_tostring(L, 1);
|
2009-05-22 22:44:34 +00:00
|
|
|
char *buffer = luaL_prepbuffer(&b);
|
|
|
|
|
2009-07-23 00:54:35 +00:00
|
|
|
if(input != NULL)
|
2018-10-23 05:57:41 +00:00
|
|
|
luaL_addstring(&b, input);
|
2009-07-23 00:54:35 +00:00
|
|
|
else
|
|
|
|
buffer[0] = '\0';
|
|
|
|
|
|
|
|
if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE))
|
|
|
|
{
|
2018-10-23 05:57:41 +00:00
|
|
|
luaL_addstring(&b, buffer);
|
2009-07-23 00:54:35 +00:00
|
|
|
luaL_pushresult(&b);
|
|
|
|
}
|
|
|
|
else
|
2018-10-23 05:57:41 +00:00
|
|
|
return 0;
|
2009-07-23 00:54:35 +00:00
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:31:32 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_WRAP(action_get_touchscreen_press)
|
|
|
|
{
|
|
|
|
short x, y;
|
|
|
|
int result = rb->action_get_touchscreen_press(&x, &y);
|
|
|
|
|
|
|
|
lua_pushinteger(L, result);
|
|
|
|
lua_pushinteger(L, x);
|
|
|
|
lua_pushinteger(L, y);
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:31:32 +00:00
|
|
|
RB_WRAP(touchscreen_set_mode)
|
|
|
|
{
|
|
|
|
enum touchscreen_mode mode = luaL_checkint(L, 1);
|
|
|
|
rb->touchscreen_set_mode(mode);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-09-17 17:28:10 +00:00
|
|
|
|
2012-01-26 22:37:27 +00:00
|
|
|
RB_WRAP(touchscreen_get_mode)
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, rb->touchscreen_get_mode());
|
|
|
|
return 1;
|
|
|
|
}
|
2009-06-01 22:31:32 +00:00
|
|
|
#endif
|
|
|
|
|
2009-05-24 01:54:15 +00:00
|
|
|
RB_WRAP(font_getstringsize)
|
|
|
|
{
|
|
|
|
const unsigned char* str = luaL_checkstring(L, 1);
|
|
|
|
int fontnumber = luaL_checkint(L, 2);
|
|
|
|
int w, h;
|
|
|
|
|
2018-05-31 12:15:05 +00:00
|
|
|
if (fontnumber == FONT_UI)
|
2011-09-24 13:19:34 +00:00
|
|
|
fontnumber = rb->global_status->font_id[SCREEN_MAIN];
|
|
|
|
else
|
|
|
|
fontnumber = FONT_SYSFIXED;
|
|
|
|
|
2009-05-24 01:54:15 +00:00
|
|
|
int result = rb->font_getstringsize(str, &w, &h, fontnumber);
|
|
|
|
lua_pushinteger(L, result);
|
|
|
|
lua_pushinteger(L, w);
|
|
|
|
lua_pushinteger(L, h);
|
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:31:32 +00:00
|
|
|
RB_WRAP(current_path)
|
|
|
|
{
|
2018-10-13 17:35:01 +00:00
|
|
|
return get_current_path(L, 1);
|
2009-06-01 22:31:32 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 05:57:41 +00:00
|
|
|
static const char ** get_table_items(lua_State *L, int pos, int *count)
|
2009-07-05 16:41:16 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
luaL_checktype(L, pos, LUA_TTABLE);
|
2018-10-23 05:57:41 +00:00
|
|
|
*count = lua_objlen(L, pos);
|
|
|
|
int n = *count;
|
2018-09-17 17:28:10 +00:00
|
|
|
|
2018-10-23 05:57:41 +00:00
|
|
|
/* newuserdata will be pushed onto stack after args*/
|
|
|
|
const char **items = (const char**) lua_newuserdata(L, n * sizeof(const char*));
|
2018-09-17 17:28:10 +00:00
|
|
|
|
2018-10-23 05:57:41 +00:00
|
|
|
for(i=1; i<= n; i++)
|
2009-07-05 16:41:16 +00:00
|
|
|
{
|
2018-10-23 05:57:41 +00:00
|
|
|
lua_rawgeti(L, pos, i); /* Push item on the stack */
|
|
|
|
items[i-1] = lua_tostring(L, -1);
|
|
|
|
lua_pop(L, 1); /* Pop it */
|
2009-07-05 16:41:16 +00:00
|
|
|
}
|
2018-10-23 05:57:41 +00:00
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void fill_text_message(lua_State *L, struct text_message * message,
|
|
|
|
int pos)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
/* newuserdata will be pushed onto stack after args*/
|
|
|
|
message->message_lines = get_table_items(L, pos, &n);
|
2009-07-05 16:41:16 +00:00
|
|
|
message->nb_lines = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_WRAP(gui_syncyesno_run)
|
|
|
|
{
|
|
|
|
struct text_message main_message, yes_message, no_message;
|
|
|
|
struct text_message *yes = NULL, *no = NULL;
|
|
|
|
|
2018-09-17 17:28:10 +00:00
|
|
|
lua_settop(L, 3); /* newuserdata will be pushed onto stack after args*/
|
2009-07-05 16:41:16 +00:00
|
|
|
fill_text_message(L, &main_message, 1);
|
|
|
|
if(!lua_isnoneornil(L, 2))
|
|
|
|
fill_text_message(L, (yes = &yes_message), 2);
|
|
|
|
if(!lua_isnoneornil(L, 3))
|
|
|
|
fill_text_message(L, (no = &no_message), 3);
|
|
|
|
|
|
|
|
enum yesno_res result = rb->gui_syncyesno_run(&main_message, yes, no);
|
|
|
|
|
|
|
|
lua_pushinteger(L, result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-10-23 10:38:20 +00:00
|
|
|
RB_WRAP(do_menu)
|
|
|
|
{
|
|
|
|
struct menu_callback_with_desc menu_desc = {NULL, NULL, Icon_NOICON};
|
|
|
|
struct menu_item_ex menu = {MT_RETURN_ID | MENU_HAS_DESC, {.strings = NULL},
|
|
|
|
{.callback_and_desc = &menu_desc}};
|
2018-10-23 05:57:41 +00:00
|
|
|
int n, start_selected;
|
2009-10-23 10:38:20 +00:00
|
|
|
const char **items, *title;
|
|
|
|
|
|
|
|
title = luaL_checkstring(L, 1);
|
|
|
|
|
2018-10-23 05:57:41 +00:00
|
|
|
start_selected = lua_tointeger(L, 3);
|
2018-09-17 17:28:10 +00:00
|
|
|
|
|
|
|
/* newuserdata will be pushed onto stack after args*/
|
2018-10-23 05:57:41 +00:00
|
|
|
items = get_table_items(L, 2, &n);
|
2009-10-23 10:38:20 +00:00
|
|
|
|
|
|
|
menu.strings = items;
|
|
|
|
menu.flags |= MENU_ITEM_COUNT(n);
|
|
|
|
menu_desc.desc = (unsigned char*) title;
|
|
|
|
|
|
|
|
int result = rb->do_menu(&menu, &start_selected, NULL, false);
|
|
|
|
|
|
|
|
lua_pushinteger(L, result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-10-25 01:40:01 +00:00
|
|
|
RB_WRAP(playlist)
|
Add playlist wrappers for lua
adds wrappers for the functions playlist_sync, playlist_remove_all_tracks, and playlist_insert_track, playlist_insert_directory
playlist_{sync,remove_all_tracks} take no arguments
playlist_insert_{track,directory} only have one required argument (either the filename or directory name)
They take as optional arguments position, queue, and either sync or recurse
They all just pass NULL to work with the current playlist
also adds constants for:
PLAYLIST_PREPEND,
PLAYLIST_INSERT,
PLAYLIST_INSERT_LAST,
PLAYLIST_INSERT_FIRST,
PLAYLIST_INSERT_SHUFFLED,
PLAYLIST_REPLACE, and
PLAYLIST_INSERT_LAST_SHUFFLED
Change-Id: Ib7464cba50e7a250edf092e50668f11010f2b737
Reviewed-on: http://gerrit.rockbox.org/109
Reviewed-by: Thomas Martitz <kugel@rockbox.org>
2012-02-16 13:20:41 +00:00
|
|
|
{
|
2018-10-25 01:40:01 +00:00
|
|
|
/* just passes NULL to work with the current playlist */
|
|
|
|
enum e_playlist {PLAYL_AMOUNT = 0, PLAYL_ADD, PLAYL_CREATE,
|
|
|
|
PLAYL_START, PLAYL_RESUMETRACK, PLAYL_RESUME,
|
|
|
|
PLAYL_SHUFFLE, PLAYL_SYNC, PLAYL_REMOVEALLTRACKS,
|
|
|
|
PLAYL_INSERTTRACK, PLAYL_INSERTDIRECTORY, PLAYL_ECOUNT};
|
|
|
|
|
|
|
|
const char *playlist_option[] = {"amount", "add", "create", "start", "resumetrack",
|
|
|
|
"resume", "shuffle", "sync", "removealltracks",
|
|
|
|
"inserttrack", "insertdirectory", NULL};
|
|
|
|
|
|
|
|
const char *filename, *dir;
|
|
|
|
int result = 0;
|
|
|
|
bool queue, recurse, sync;
|
|
|
|
int pos, crc, index, random_seed;
|
|
|
|
unsigned long elapsed, offset;
|
|
|
|
|
|
|
|
int option = luaL_checkoption (L, 1, NULL, playlist_option);
|
|
|
|
switch(option)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case PLAYL_AMOUNT:
|
|
|
|
result = rb->playlist_amount();
|
|
|
|
break;
|
|
|
|
case PLAYL_ADD:
|
|
|
|
filename = luaL_checkstring(L, 2);
|
|
|
|
result = rb->playlist_add(filename);
|
|
|
|
break;
|
|
|
|
case PLAYL_CREATE:
|
|
|
|
dir = luaL_checkstring(L, 2);
|
|
|
|
filename = luaL_checkstring(L, 3);
|
|
|
|
result = rb->playlist_create(dir, filename);
|
|
|
|
break;
|
|
|
|
case PLAYL_START:
|
|
|
|
index = luaL_checkint(L, 2);
|
|
|
|
elapsed = luaL_checkint(L, 3);
|
|
|
|
offset = luaL_checkint(L, 4);
|
|
|
|
rb->playlist_start(index, elapsed, offset);
|
|
|
|
break;
|
|
|
|
case PLAYL_RESUMETRACK:
|
|
|
|
index = luaL_checkint(L, 2);
|
|
|
|
crc = luaL_checkint(L, 3);
|
|
|
|
elapsed = luaL_checkint(L, 4);
|
|
|
|
offset = luaL_checkint(L, 5);
|
|
|
|
rb->playlist_resume_track(index, (unsigned) crc, elapsed, offset);
|
|
|
|
break;
|
|
|
|
case PLAYL_RESUME:
|
|
|
|
result = rb->playlist_resume();
|
|
|
|
break;
|
|
|
|
case PLAYL_SHUFFLE:
|
|
|
|
random_seed = luaL_checkint(L, 2);
|
|
|
|
index = luaL_checkint(L, 3);
|
|
|
|
result = rb->playlist_shuffle(random_seed, index);
|
|
|
|
break;
|
|
|
|
case PLAYL_SYNC:
|
|
|
|
rb->playlist_sync(NULL);
|
|
|
|
break;
|
|
|
|
case PLAYL_REMOVEALLTRACKS:
|
|
|
|
result = rb->playlist_remove_all_tracks(NULL);
|
|
|
|
break;
|
|
|
|
case PLAYL_INSERTTRACK:
|
|
|
|
filename = luaL_checkstring(L, 2); /* only required parameter */
|
|
|
|
pos = luaL_optint(L, 3, PLAYLIST_INSERT);
|
|
|
|
queue = lua_toboolean(L, 4); /* default to false */
|
|
|
|
sync = lua_toboolean(L, 5); /* default to false */
|
|
|
|
result = rb->playlist_insert_track(NULL, filename, pos, queue, sync);
|
|
|
|
break;
|
|
|
|
case PLAYL_INSERTDIRECTORY:
|
|
|
|
dir = luaL_checkstring(L, 2); /* only required parameter */
|
|
|
|
pos = luaL_optint(L, 3, PLAYLIST_INSERT);
|
|
|
|
queue = lua_toboolean(L, 4); /* default to false */
|
|
|
|
recurse = lua_toboolean(L, 5); /* default to false */
|
|
|
|
result = rb->playlist_insert_directory(NULL, dir, pos, queue, recurse);
|
|
|
|
break;
|
|
|
|
}
|
Add playlist wrappers for lua
adds wrappers for the functions playlist_sync, playlist_remove_all_tracks, and playlist_insert_track, playlist_insert_directory
playlist_{sync,remove_all_tracks} take no arguments
playlist_insert_{track,directory} only have one required argument (either the filename or directory name)
They take as optional arguments position, queue, and either sync or recurse
They all just pass NULL to work with the current playlist
also adds constants for:
PLAYLIST_PREPEND,
PLAYLIST_INSERT,
PLAYLIST_INSERT_LAST,
PLAYLIST_INSERT_FIRST,
PLAYLIST_INSERT_SHUFFLED,
PLAYLIST_REPLACE, and
PLAYLIST_INSERT_LAST_SHUFFLED
Change-Id: Ib7464cba50e7a250edf092e50668f11010f2b737
Reviewed-on: http://gerrit.rockbox.org/109
Reviewed-by: Thomas Martitz <kugel@rockbox.org>
2012-02-16 13:20:41 +00:00
|
|
|
|
2018-10-25 01:40:01 +00:00
|
|
|
rb->yield();
|
Add playlist wrappers for lua
adds wrappers for the functions playlist_sync, playlist_remove_all_tracks, and playlist_insert_track, playlist_insert_directory
playlist_{sync,remove_all_tracks} take no arguments
playlist_insert_{track,directory} only have one required argument (either the filename or directory name)
They take as optional arguments position, queue, and either sync or recurse
They all just pass NULL to work with the current playlist
also adds constants for:
PLAYLIST_PREPEND,
PLAYLIST_INSERT,
PLAYLIST_INSERT_LAST,
PLAYLIST_INSERT_FIRST,
PLAYLIST_INSERT_SHUFFLED,
PLAYLIST_REPLACE, and
PLAYLIST_INSERT_LAST_SHUFFLED
Change-Id: Ib7464cba50e7a250edf092e50668f11010f2b737
Reviewed-on: http://gerrit.rockbox.org/109
Reviewed-by: Thomas Martitz <kugel@rockbox.org>
2012-02-16 13:20:41 +00:00
|
|
|
lua_pushinteger(L, result);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-10-24 14:49:52 +00:00
|
|
|
RB_WRAP(audio)
|
|
|
|
{
|
|
|
|
enum e_audio {AUDIO_STATUS = 0, AUDIO_PLAY, AUDIO_STOP, AUDIO_PAUSE,
|
|
|
|
AUDIO_RESUME, AUDIO_NEXT, AUDIO_PREV, AUDIO_FFREWIND,
|
|
|
|
AUDIO_FLUSHANDRELOADTRACKS, AUDIO_GETPOS, AUDIO_ECOUNT};
|
|
|
|
const char *audio_option[] = {"status", "play", "stop", "pause",
|
|
|
|
"resume", "next", "prev", "ffrewind",
|
|
|
|
"flushandreloadtracks", "getfilepos", NULL};
|
|
|
|
long elapsed, offset, newtime;
|
|
|
|
int status = rb->audio_status();
|
|
|
|
|
|
|
|
int option = luaL_checkoption (L, 1, NULL, audio_option);
|
|
|
|
switch(option)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case AUDIO_STATUS:
|
|
|
|
break;
|
|
|
|
case AUDIO_PLAY:
|
|
|
|
elapsed = luaL_checkint(L, 2);
|
|
|
|
offset = luaL_checkint(L, 3);
|
|
|
|
|
|
|
|
if (status == (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE))
|
|
|
|
{
|
|
|
|
/* not perfect but provides a decent compromise */
|
|
|
|
rb->audio_ff_rewind(elapsed + offset);
|
|
|
|
rb->audio_resume();
|
|
|
|
}
|
|
|
|
else if (status != AUDIO_STATUS_PLAY)
|
|
|
|
rb->audio_play((unsigned long) elapsed, (unsigned long) offset);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case AUDIO_STOP:
|
|
|
|
rb->audio_stop();
|
|
|
|
break;
|
|
|
|
case AUDIO_PAUSE:
|
|
|
|
rb->audio_pause();
|
|
|
|
break;
|
|
|
|
case AUDIO_RESUME:
|
|
|
|
rb->audio_resume();
|
|
|
|
break;
|
|
|
|
case AUDIO_NEXT:
|
|
|
|
rb->audio_next();
|
|
|
|
break;
|
|
|
|
case AUDIO_PREV:
|
|
|
|
rb->audio_prev();
|
|
|
|
break;
|
|
|
|
case AUDIO_FFREWIND:
|
|
|
|
newtime = (long) luaL_checkint(L, 2);
|
|
|
|
rb->audio_ff_rewind(newtime);
|
|
|
|
break;
|
|
|
|
case AUDIO_FLUSHANDRELOADTRACKS:
|
|
|
|
rb->audio_flush_and_reload_tracks();
|
|
|
|
break;
|
|
|
|
case AUDIO_GETPOS:
|
|
|
|
lua_pushinteger(L, rb->audio_get_file_pos());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->yield();
|
|
|
|
lua_pushinteger(L, status); /* return previous (or current) audio status */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-10-26 17:07:56 +00:00
|
|
|
SIMPLE_VOID_WRAPPER(backlight_force_on);
|
|
|
|
SIMPLE_VOID_WRAPPER(backlight_use_settings);
|
2018-09-17 17:28:10 +00:00
|
|
|
|
2009-10-26 17:07:56 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
SIMPLE_VOID_WRAPPER(remote_backlight_force_on);
|
|
|
|
SIMPLE_VOID_WRAPPER(remote_backlight_use_settings);
|
|
|
|
#endif
|
2018-09-17 17:28:10 +00:00
|
|
|
|
2009-10-26 17:07:56 +00:00
|
|
|
#ifdef HAVE_BUTTON_LIGHT
|
|
|
|
SIMPLE_VOID_WRAPPER(buttonlight_force_on);
|
|
|
|
SIMPLE_VOID_WRAPPER(buttonlight_use_settings);
|
|
|
|
#endif
|
2018-09-17 17:28:10 +00:00
|
|
|
|
2009-10-26 17:07:56 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT_BRIGHTNESS
|
|
|
|
RB_WRAP(backlight_brightness_set)
|
|
|
|
{
|
|
|
|
int brightness = luaL_checkint(L, 1);
|
|
|
|
backlight_brightness_set(brightness);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SIMPLE_VOID_WRAPPER(backlight_brightness_use_setting);
|
|
|
|
#endif
|
|
|
|
|
2012-01-26 23:05:20 +00:00
|
|
|
RB_WRAP(get_plugin_action)
|
|
|
|
{
|
|
|
|
static const struct button_mapping *m1[] = { pla_main_ctx };
|
|
|
|
int timeout = luaL_checkint(L, 1);
|
|
|
|
int btn;
|
2018-09-17 17:28:10 +00:00
|
|
|
|
2012-01-26 23:05:20 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
static const struct button_mapping *m2[] = { pla_main_ctx, pla_remote_ctx };
|
|
|
|
bool with_remote = luaL_optint(L, 2, 0);
|
2018-05-31 12:15:05 +00:00
|
|
|
if (with_remote)
|
2012-01-26 23:05:20 +00:00
|
|
|
btn = pluginlib_getaction(timeout, m2, 2);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
btn = pluginlib_getaction(timeout, m1, 1);
|
|
|
|
|
|
|
|
lua_pushinteger(L, btn);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-10-23 04:11:34 +00:00
|
|
|
RB_WRAP(strip_extension)
|
|
|
|
{
|
|
|
|
const char* filename = luaL_checkstring(L, -1);
|
|
|
|
const char* pos = rb->strrchr(filename, '.');
|
|
|
|
if(pos != NULL)
|
|
|
|
lua_pushlstring (L, filename, pos - filename);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_WRAP(create_numbered_filename)
|
|
|
|
{
|
|
|
|
luaL_Buffer b;
|
|
|
|
luaL_buffinit(L, &b);
|
|
|
|
char *buffer = luaL_prepbuffer(&b);
|
|
|
|
buffer[0] = '\0';
|
|
|
|
|
|
|
|
const char * path = luaL_checkstring(L, 1);
|
|
|
|
const char * prefix = luaL_checkstring(L, 2);
|
|
|
|
const char * suffix = luaL_checkstring(L, 3);
|
2018-10-24 15:09:17 +00:00
|
|
|
int numberlen = luaL_checkint(L, 4);
|
|
|
|
int num = luaL_optint(L, 5, -1);
|
|
|
|
(void) num;
|
2018-10-23 04:11:34 +00:00
|
|
|
|
2018-10-24 15:09:17 +00:00
|
|
|
if(rb->create_numbered_filename(buffer, path, prefix, suffix, numberlen
|
|
|
|
IF_CNFN_NUM_(, &num)))
|
2018-10-23 04:11:34 +00:00
|
|
|
{
|
|
|
|
luaL_addstring(&b, buffer);
|
|
|
|
luaL_pushresult(&b);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-09-17 17:28:10 +00:00
|
|
|
#define RB_FUNC(func) {#func, rock_##func}
|
2009-05-21 19:42:14 +00:00
|
|
|
static const luaL_Reg rocklib[] =
|
|
|
|
{
|
2009-05-21 19:01:41 +00:00
|
|
|
/* Kernel */
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_FUNC(current_tick),
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
/* Buttons */
|
2009-05-22 22:44:34 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_FUNC(action_get_touchscreen_press),
|
|
|
|
RB_FUNC(touchscreen_set_mode),
|
|
|
|
RB_FUNC(touchscreen_get_mode),
|
2009-05-22 22:44:34 +00:00
|
|
|
#endif
|
2018-09-17 17:28:10 +00:00
|
|
|
|
|
|
|
RB_FUNC(kbd_input),
|
|
|
|
|
|
|
|
RB_FUNC(font_getstringsize),
|
|
|
|
RB_FUNC(set_viewport),
|
|
|
|
RB_FUNC(clear_viewport),
|
|
|
|
RB_FUNC(current_path),
|
|
|
|
RB_FUNC(gui_syncyesno_run),
|
|
|
|
RB_FUNC(do_menu),
|
2009-05-24 01:54:15 +00:00
|
|
|
|
2009-10-26 17:07:56 +00:00
|
|
|
/* Backlight helper */
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_FUNC(backlight_force_on),
|
|
|
|
RB_FUNC(backlight_use_settings),
|
|
|
|
|
2009-10-26 17:07:56 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_FUNC(remote_backlight_force_on),
|
|
|
|
RB_FUNC(remote_backlight_use_settings),
|
2009-10-26 17:07:56 +00:00
|
|
|
#endif
|
2018-09-17 17:28:10 +00:00
|
|
|
|
2009-10-26 17:07:56 +00:00
|
|
|
#ifdef HAVE_BUTTON_LIGHT
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_FUNC(buttonlight_force_on),
|
|
|
|
RB_FUNC(buttonlight_use_settings),
|
2009-10-26 17:07:56 +00:00
|
|
|
#endif
|
2018-09-17 17:28:10 +00:00
|
|
|
|
2009-10-26 17:07:56 +00:00
|
|
|
#ifdef HAVE_BACKLIGHT_BRIGHTNESS
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_FUNC(backlight_brightness_set),
|
|
|
|
RB_FUNC(backlight_brightness_use_setting),
|
2009-10-26 17:07:56 +00:00
|
|
|
#endif
|
2018-09-17 17:28:10 +00:00
|
|
|
|
|
|
|
RB_FUNC(get_plugin_action),
|
2009-10-26 17:07:56 +00:00
|
|
|
|
2018-10-23 04:11:34 +00:00
|
|
|
RB_FUNC(strip_extension),
|
|
|
|
RB_FUNC(create_numbered_filename),
|
|
|
|
|
2018-10-24 14:49:52 +00:00
|
|
|
RB_FUNC(audio),
|
2018-10-25 01:40:01 +00:00
|
|
|
RB_FUNC(playlist),
|
2018-10-24 14:49:52 +00:00
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
{NULL, NULL}
|
|
|
|
};
|
2018-09-17 17:28:10 +00:00
|
|
|
#undef RB_FUNC
|
|
|
|
|
2009-07-05 15:33:08 +00:00
|
|
|
extern const luaL_Reg rocklib_aux[];
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Open Rockbox library
|
|
|
|
*/
|
|
|
|
LUALIB_API int luaopen_rock(lua_State *L)
|
|
|
|
{
|
2014-04-02 18:46:06 +00:00
|
|
|
luaL_register(L, LUA_ROCKLIBNAME, rocklib);
|
|
|
|
luaL_register(L, LUA_ROCKLIBNAME, rocklib_aux);
|
2018-10-22 18:00:58 +00:00
|
|
|
|
2018-09-13 23:13:22 +00:00
|
|
|
static const struct lua_int_reg rlib_const_int[] =
|
|
|
|
{
|
|
|
|
/* useful integer constants */
|
|
|
|
RB_CONSTANT(HZ),
|
2009-05-22 00:06:45 +00:00
|
|
|
|
2018-09-13 23:13:22 +00:00
|
|
|
RB_CONSTANT(LCD_DEPTH),
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_CONSTANT(LCD_HEIGHT),
|
|
|
|
RB_CONSTANT(LCD_WIDTH),
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2018-09-13 23:13:22 +00:00
|
|
|
RB_CONSTANT(FONT_SYSFIXED),
|
|
|
|
RB_CONSTANT(FONT_UI),
|
2009-05-22 00:06:45 +00:00
|
|
|
|
2018-09-13 23:13:22 +00:00
|
|
|
RB_CONSTANT(PLAYLIST_INSERT),
|
|
|
|
RB_CONSTANT(PLAYLIST_INSERT_LAST),
|
|
|
|
RB_CONSTANT(PLAYLIST_INSERT_FIRST),
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_CONSTANT(PLAYLIST_INSERT_LAST_SHUFFLED),
|
2018-09-13 23:13:22 +00:00
|
|
|
RB_CONSTANT(PLAYLIST_INSERT_SHUFFLED),
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_CONSTANT(PLAYLIST_PREPEND),
|
2018-09-13 23:13:22 +00:00
|
|
|
RB_CONSTANT(PLAYLIST_REPLACE),
|
Add playlist wrappers for lua
adds wrappers for the functions playlist_sync, playlist_remove_all_tracks, and playlist_insert_track, playlist_insert_directory
playlist_{sync,remove_all_tracks} take no arguments
playlist_insert_{track,directory} only have one required argument (either the filename or directory name)
They take as optional arguments position, queue, and either sync or recurse
They all just pass NULL to work with the current playlist
also adds constants for:
PLAYLIST_PREPEND,
PLAYLIST_INSERT,
PLAYLIST_INSERT_LAST,
PLAYLIST_INSERT_FIRST,
PLAYLIST_INSERT_SHUFFLED,
PLAYLIST_REPLACE, and
PLAYLIST_INSERT_LAST_SHUFFLED
Change-Id: Ib7464cba50e7a250edf092e50668f11010f2b737
Reviewed-on: http://gerrit.rockbox.org/109
Reviewed-by: Thomas Martitz <kugel@rockbox.org>
2012-02-16 13:20:41 +00:00
|
|
|
|
2009-06-01 22:31:32 +00:00
|
|
|
|
2018-09-13 23:13:22 +00:00
|
|
|
RB_CONSTANT(SCREEN_MAIN),
|
2009-07-08 11:59:05 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2018-09-13 23:13:22 +00:00
|
|
|
RB_CONSTANT(SCREEN_REMOTE),
|
2009-07-08 11:59:05 +00:00
|
|
|
#endif
|
2018-09-17 17:28:10 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
RB_CONSTANT(TOUCHSCREEN_POINT),
|
|
|
|
RB_CONSTANT(TOUCHSCREEN_BUTTON),
|
|
|
|
#endif
|
|
|
|
|
2018-09-13 23:13:22 +00:00
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct lua_int_reg* rlci = rlib_const_int;
|
|
|
|
for (; rlci->name; rlci++) {
|
|
|
|
lua_pushinteger(L, rlci->value);
|
|
|
|
lua_setfield(L, -2, rlci->name);
|
|
|
|
}
|
2009-07-08 11:59:05 +00:00
|
|
|
|
2018-09-13 23:13:22 +00:00
|
|
|
static const struct lua_str_reg rlib_const_str[] =
|
|
|
|
{
|
|
|
|
/* some useful paths constants */
|
|
|
|
RB_STRING_CONSTANT(HOME_DIR),
|
|
|
|
RB_STRING_CONSTANT(PLUGIN_DIR),
|
|
|
|
RB_STRING_CONSTANT(PLUGIN_APPS_DATA_DIR),
|
|
|
|
RB_STRING_CONSTANT(PLUGIN_GAMES_DATA_DIR),
|
|
|
|
RB_STRING_CONSTANT(PLUGIN_DATA_DIR),
|
2018-09-17 17:28:10 +00:00
|
|
|
RB_STRING_CONSTANT(ROCKBOX_DIR),
|
2018-09-13 23:13:22 +00:00
|
|
|
RB_STRING_CONSTANT(VIEWERS_DATA_DIR),
|
|
|
|
{NULL,NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct lua_str_reg* rlcs = rlib_const_str;
|
|
|
|
for (; rlcs->name; rlcs++) {
|
|
|
|
lua_pushstring(L, rlcs->value);
|
|
|
|
lua_setfield(L, -2, rlcs->name);
|
|
|
|
}
|
2012-01-29 20:55:26 +00:00
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
return 1;
|
|
|
|
}
|
Rocklua -- Extend / Fix rliImage
Some devices(1-bit / 2-bit displays) have packed bit formats that
need to be unpacked in order to work on them at a pixel level.
This caused a few issues on 1 & 2-bit devices:
Greatly Oversized data arrays for bitmaps
Improper handling of native image data
Framebuffer data was near unusable without jumping through hoops
Conversion between native addressing and per pixel addressing
incurs extra overhead but it is much faster to do it
on the 'C' side rather than in lua.
Not to mention the advantage of a unified interface for the end programer
-------------------------------------------------------------------
Adds a sane way to access each pixel of image data
Adds:
--------------------------------------------------------------------
img:clear([color],[x1],[y1],[x2],[y2])
(set whole image or a portion to a particular value)
--------------------------------------------------------------------
img:invert([x1],[y1],[x2],[y2])
(inverts whole image or a portion)
--------------------------------------------------------------------
img:marshal([x1],[y1],[x2],[y2],[funct])
(calls funct for each point defined by rect of x1,y1 x2,y2
returns value and allows setting value of each point return
nil to terminate early)
--------------------------------------------------------------------
img:points([x1],[y1],[x2],[y2],[dx],[dy])
(returns iterator function that steps delta-x and delta-y pixels each call
returns value of pixel each call but doesn't allow setting to a new value
compare to lua pairs method)
--------------------------------------------------------------------
img:copy(src,[x1],[y1],[x2],[y2],[w],[h],[clip][operation][clr/funct])
(copies all or part of an image -- straight copy or special ops
optionally calls funct for each point defined by rect of
x1, y1, w, h and x2, y2, w, h for dest and src images
returns value of dst and src and allows setting value of
each point return nil to terminate early)
--------------------------------------------------------------------
img:line(x1, y1, x2, y2, color)
--------------------------------------------------------------------
img:ellipse(x1, y1, x2, y2, color, [fillcolor]
--------------------------------------------------------------------
Fixed handling of 2-bit vertical integrated screens
Added direct element access for saving / restoring native image etc.
Added more data to tostring() handler and a way to access individual items
Added equals method to see if two variables reference the same image address
(doesn't check if two separate images contain the same 'picture')
Optimized get and set routines
Fixed out of bound x coord access shifting to next line
Added lua include files to expose new functionality
Finished image saving routine
Static allocation of set_viewport struct faster + saves ram over dynamic
Cleaned up code
Fixed pixel get/set for 1/2 bit devices
Fixed handling for 24-bit devices (32?)
-------------------------------------------------------------------------
Example lua script to follow on forums
-------------------------------------------------------------------------
Change-Id: I8a9ff0ff72aacf4b1662767ccb2b312fc355239c
2018-07-23 00:50:22 +00:00
|
|
|
|