add canvas scale and rotate
git-svn-id: http://skia.googlecode.com/svn/trunk@9564 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 6754746..aabb236 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -228,6 +228,14 @@
return SkLuaToScalar(lua_tonumber(L, index));
}
+static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) {
+ if (lua_isnumber(L, index)) {
+ return SkLuaToScalar(lua_tonumber(L, index));
+ } else {
+ return defaultValue;
+ }
+}
+
static SkScalar getfield_scalar(lua_State* L, int index, const char key[]) {
SkASSERT(lua_istable(L, index));
lua_pushstring(L, key);
@@ -365,8 +373,23 @@
return 0;
}
+static int lcanvas_scale(lua_State* L) {
+ SkScalar sx = lua2scalar_def(L, 2, 1);
+ SkScalar sy = lua2scalar_def(L, 3, sx);
+ get_ref<SkCanvas>(L, 1)->scale(sx, sy);
+ return 0;
+}
+
static int lcanvas_translate(lua_State* L) {
- get_ref<SkCanvas>(L, 1)->translate(lua2scalar(L, 2), lua2scalar(L, 3));
+ SkScalar tx = lua2scalar_def(L, 2, 0);
+ SkScalar ty = lua2scalar_def(L, 3, 0);
+ get_ref<SkCanvas>(L, 1)->translate(tx, ty);
+ return 0;
+}
+
+static int lcanvas_rotate(lua_State* L) {
+ SkScalar degrees = lua2scalar_def(L, 2, 0);
+ get_ref<SkCanvas>(L, 1)->rotate(degrees);
return 0;
}
@@ -387,7 +410,9 @@
{ "getTotalMatrix", lcanvas_getTotalMatrix },
{ "save", lcanvas_save },
{ "restore", lcanvas_restore },
+ { "scale", lcanvas_scale },
{ "translate", lcanvas_translate },
+ { "rotate", lcanvas_rotate },
{ "__gc", lcanvas_gc },
{ NULL, NULL }
};