aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2014-10-10 15:28:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-10 15:28:19 -0700
commitba5fb932a1b5666a861043735cfb055cc1b600c7 (patch)
treeab540052f70b11f69b0cd4fe1b640f22f90c8304 /src/utils
parent89c7a2ec3e9f7e1b9705214f450bb12288799da9 (diff)
add drawImageRect to lua, update sample
BUG=skia: TBR= Review URL: https://codereview.chromium.org/642353005
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/SkLua.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 9880fe4408..1336404d8c 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -460,6 +460,30 @@ static int lcanvas_drawImage(lua_State* L) {
return 0;
}
+static int lcanvas_drawImageRect(lua_State* L) {
+ SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
+ SkImage* image = get_ref<SkImage>(L, 2);
+ if (NULL == image) {
+ return 0;
+ }
+
+ SkRect srcR, dstR;
+ SkRect* srcRPtr = NULL;
+ if (!lua_isnil(L, 3)) {
+ srcRPtr = lua2rect(L, 3, &srcR);
+ }
+ lua2rect(L, 4, &dstR);
+
+ SkPaint paint;
+ const SkPaint* paintPtr = NULL;
+ if (lua_isnumber(L, 5)) {
+ paint.setAlpha(SkScalarRoundToInt(lua2scalar(L, 5) * 255));
+ paintPtr = &paint;
+ }
+ canvas->drawImageRect(image, srcRPtr, dstR, paintPtr);
+ return 0;
+}
+
static int lcanvas_drawPath(lua_State* L) {
get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2),
*get_obj<SkPaint>(L, 3));
@@ -576,6 +600,7 @@ const struct luaL_Reg gSkCanvas_Methods[] = {
{ "drawOval", lcanvas_drawOval },
{ "drawCircle", lcanvas_drawCircle },
{ "drawImage", lcanvas_drawImage },
+ { "drawImageRect", lcanvas_drawImageRect },
{ "drawPath", lcanvas_drawPath },
{ "drawText", lcanvas_drawText },
{ "getSaveCount", lcanvas_getSaveCount },