Chromium Code Reviews| Index: src/utils/SkLua.cpp |
| diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp |
| index a3a1685eae897625dc22b0f722ca081ffe98374d..0736301748011688e1ff6e0942ac5ae9015b8e35 100644 |
| --- a/src/utils/SkLua.cpp |
| +++ b/src/utils/SkLua.cpp |
| @@ -221,6 +221,11 @@ static void setarray_scalar(lua_State* L, int index, SkScalar value) { |
| setarray_number(L, index, SkScalarToLua(value)); |
| } |
| +static void setarray_string(lua_State* L, int index, const char str[]) { |
| + lua_pushstring(L, str); |
| + lua_rawseti(L, -2, index); |
| +} |
| + |
| void SkLua::pushBool(bool value, const char key[]) { |
| lua_pushboolean(fL, value); |
| CHECK_SETFIELD(key); |
| @@ -1159,6 +1164,19 @@ static int lpaint_getPathEffect(lua_State* L) { |
| return 0; |
| } |
| +static int lpaint_getFillPath(lua_State* L) { |
| + const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| + const SkPath* path = get_obj<SkPath>(L, 2); |
| + |
| + SkPath fillpath; |
| + paint->getFillPath(*path, &fillpath); |
| + |
| + SkLua lua(L); |
| + lua.pushPath(fillpath); |
| + |
| + return 1; |
| +} |
| + |
| static int lpaint_gc(lua_State* L) { |
| get_obj<SkPaint>(L, 1)->~SkPaint(); |
| return 0; |
| @@ -1217,6 +1235,7 @@ static const struct luaL_Reg gSkPaint_Methods[] = { |
| { "getShader", lpaint_getShader }, |
| { "setShader", lpaint_setShader }, |
| { "getPathEffect", lpaint_getPathEffect }, |
| + { "getFillPath", lpaint_getFillPath }, |
| { "__gc", lpaint_gc }, |
| { nullptr, nullptr } |
| }; |
| @@ -1586,6 +1605,45 @@ static int lpath_countPoints(lua_State* L) { |
| return 1; |
| } |
| +static int lpath_getVerbs(lua_State* L) { |
| + const SkPath* path = get_obj<SkPath>(L, 1); |
| + SkPath::Iter iter(*path, false); |
| + SkPoint pts[4]; |
| + |
| + lua_newtable(L); |
| + |
| + bool done = false; |
| + int i = 1; |
| + do { |
| + switch (iter.next(pts, true)) { |
|
reed1
2016/08/01 19:36:29
this indent looks too big. "switch" should be 4 sp
Harry Stern
2016/08/01 20:58:23
Done.
|
| + case SkPath::kMove_Verb: |
| + setarray_string(L, i, "move"); i++; |
|
reed1
2016/08/01 19:36:29
different option to consider
int i = 0;
seta
Harry Stern
2016/08/01 20:58:23
Any time I can index starting at 0 is a good time.
|
| + break; |
| + case SkPath::kClose_Verb: |
| + setarray_string(L, i, "close"); i++; |
| + break; |
| + case SkPath::kLine_Verb: |
| + setarray_string(L, i, "line"); i++; |
| + break; |
| + case SkPath::kQuad_Verb: |
| + setarray_string(L, i, "quad"); i++; |
| + break; |
| + case SkPath::kConic_Verb: |
| + setarray_string(L, i, "conic"); i++; |
| + break; |
| + case SkPath::kCubic_Verb: |
| + setarray_string(L, i, "cubic"); i++; |
| + break; |
| + case SkPath::kDone_Verb: |
| + setarray_string(L, i, "done"); i++; |
| + done = true; |
| + break; |
| + } |
| + } while (!done); |
| + |
| + return 1; |
| +} |
| + |
| static int lpath_reset(lua_State* L) { |
| get_obj<SkPath>(L, 1)->reset(); |
| return 0; |
| @@ -1628,6 +1686,7 @@ static const struct luaL_Reg gSkPath_Methods[] = { |
| { "getBounds", lpath_getBounds }, |
| { "getFillType", lpath_getFillType }, |
| { "getSegmentTypes", lpath_getSegmentTypes }, |
| + { "getVerbs", lpath_getVerbs }, |
| { "isConvex", lpath_isConvex }, |
| { "isEmpty", lpath_isEmpty }, |
| { "isRect", lpath_isRect }, |