add paint:getEffects to return table of bools of a given effect is present on the paint
git-svn-id: http://skia.googlecode.com/svn/trunk@9978 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 4f662ca..04dfbb1 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -111,6 +111,13 @@
#define CHECK_SETFIELD(key) do if (key) lua_setfield(fL, -2, key); while (0)
+static void setfield_bool_if(lua_State* L, const char key[], bool pred) {
+ if (pred) {
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, key);
+ }
+}
+
static void setfield_string(lua_State* L, const char key[], const char value[]) {
lua_pushstring(L, value);
lua_setfield(L, -2, key);
@@ -596,6 +603,21 @@
return 2;
}
+static int lpaint_getEffects(lua_State* L) {
+ const SkPaint* paint = get_obj<SkPaint>(L, 1);
+
+ lua_newtable(L);
+ setfield_bool_if(L, "looper", !!paint->getLooper());
+ setfield_bool_if(L, "pathEffect", !!paint->getPathEffect());
+ setfield_bool_if(L, "rasterizer", !!paint->getRasterizer());
+ setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter());
+ setfield_bool_if(L, "shader", !!paint->getShader());
+ setfield_bool_if(L, "colorFilter", !!paint->getColorFilter());
+ setfield_bool_if(L, "imageFilter", !!paint->getImageFilter());
+ setfield_bool_if(L, "xfermode", !!paint->getXfermode());
+ return 1;
+}
+
static int lpaint_gc(lua_State* L) {
get_obj<SkPaint>(L, 1)->~SkPaint();
return 0;
@@ -619,6 +641,7 @@
{ "setStrokeWidth", lpaint_setStrokeWidth },
{ "measureText", lpaint_measureText },
{ "getFontMetrics", lpaint_getFontMetrics },
+ { "getEffects", lpaint_getEffects },
{ "__gc", lpaint_gc },
{ NULL, NULL }
};