| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkLua.h" | 8 #include "SkLua.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkClipStack.h" | 10 #include "SkClipStack.h" |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 { NULL, NULL } | 969 { NULL, NULL } |
| 970 }; | 970 }; |
| 971 | 971 |
| 972 /////////////////////////////////////////////////////////////////////////////// | 972 /////////////////////////////////////////////////////////////////////////////// |
| 973 | 973 |
| 974 static int lpath_getBounds(lua_State* L) { | 974 static int lpath_getBounds(lua_State* L) { |
| 975 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds()); | 975 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds()); |
| 976 return 1; | 976 return 1; |
| 977 } | 977 } |
| 978 | 978 |
| 979 static const char* fill_type_to_str(SkPath::FillType fill) { |
| 980 switch (fill) { |
| 981 case SkPath::kEvenOdd_FillType: |
| 982 return "even-odd"; |
| 983 case SkPath::kWinding_FillType: |
| 984 return "winding"; |
| 985 case SkPath::kInverseEvenOdd_FillType: |
| 986 return "inverse-even-odd"; |
| 987 case SkPath::kInverseWinding_FillType: |
| 988 return "inverse-winding"; |
| 989 } |
| 990 return "unknown"; |
| 991 } |
| 992 |
| 993 static int lpath_getFillType(lua_State* L) { |
| 994 SkPath::FillType fill = get_obj<SkPath>(L, 1)->getFillType(); |
| 995 SkLua(L).pushString(fill_type_to_str(fill)); |
| 996 return 1; |
| 997 } |
| 998 |
| 999 static SkString segment_masks_to_str(uint32_t segmentMasks) { |
| 1000 SkString result; |
| 1001 bool first = true; |
| 1002 if (SkPath::kLine_SegmentMask & segmentMasks) { |
| 1003 result.append("line"); |
| 1004 first = false; |
| 1005 SkDEBUGCODE(segmentMasks &= ~SkPath::kLine_SegmentMask;) |
| 1006 } |
| 1007 if (SkPath::kQuad_SegmentMask & segmentMasks) { |
| 1008 if (!first) { |
| 1009 result.append(" "); |
| 1010 } |
| 1011 result.append("quad"); |
| 1012 first = false; |
| 1013 SkDEBUGCODE(segmentMasks &= ~SkPath::kQuad_SegmentMask;) |
| 1014 } |
| 1015 if (SkPath::kConic_SegmentMask & segmentMasks) { |
| 1016 if (!first) { |
| 1017 result.append(" "); |
| 1018 } |
| 1019 result.append("conic"); |
| 1020 first = false; |
| 1021 SkDEBUGCODE(segmentMasks &= ~SkPath::kConic_SegmentMask;) |
| 1022 } |
| 1023 if (SkPath::kCubic_SegmentMask & segmentMasks) { |
| 1024 if (!first) { |
| 1025 result.append(" "); |
| 1026 } |
| 1027 result.append("cubic"); |
| 1028 SkDEBUGCODE(segmentMasks &= ~SkPath::kCubic_SegmentMask;) |
| 1029 } |
| 1030 SkASSERT(0 == segmentMasks); |
| 1031 return result; |
| 1032 } |
| 1033 |
| 1034 static int lpath_getSegementTypes(lua_State* L) { |
| 1035 uint32_t segMasks = get_obj<SkPath>(L, 1)->getSegmentMasks(); |
| 1036 SkLua(L).pushString(segment_masks_to_str(segMasks)); |
| 1037 return 1; |
| 1038 } |
| 1039 |
| 1040 static int lpath_isConvex(lua_State* L) { |
| 1041 bool isConvex = SkPath::kConvex_Convexity == get_obj<SkPath>(L, 1)->getConve
xity(); |
| 1042 SkLua(L).pushBool(isConvex); |
| 1043 return 1; |
| 1044 } |
| 1045 |
| 979 static int lpath_isEmpty(lua_State* L) { | 1046 static int lpath_isEmpty(lua_State* L) { |
| 980 lua_pushboolean(L, get_obj<SkPath>(L, 1)->isEmpty()); | 1047 lua_pushboolean(L, get_obj<SkPath>(L, 1)->isEmpty()); |
| 981 return 1; | 1048 return 1; |
| 982 } | 1049 } |
| 983 | 1050 |
| 984 static int lpath_isRect(lua_State* L) { | 1051 static int lpath_isRect(lua_State* L) { |
| 985 SkRect r; | 1052 SkRect r; |
| 986 bool pred = get_obj<SkPath>(L, 1)->isRect(&r); | 1053 bool pred = get_obj<SkPath>(L, 1)->isRect(&r); |
| 987 int ret_count = 1; | 1054 int ret_count = 1; |
| 988 lua_pushboolean(L, pred); | 1055 lua_pushboolean(L, pred); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 return 0; | 1118 return 0; |
| 1052 } | 1119 } |
| 1053 | 1120 |
| 1054 static int lpath_gc(lua_State* L) { | 1121 static int lpath_gc(lua_State* L) { |
| 1055 get_obj<SkPath>(L, 1)->~SkPath(); | 1122 get_obj<SkPath>(L, 1)->~SkPath(); |
| 1056 return 0; | 1123 return 0; |
| 1057 } | 1124 } |
| 1058 | 1125 |
| 1059 static const struct luaL_Reg gSkPath_Methods[] = { | 1126 static const struct luaL_Reg gSkPath_Methods[] = { |
| 1060 { "getBounds", lpath_getBounds }, | 1127 { "getBounds", lpath_getBounds }, |
| 1128 { "getFillType", lpath_getFillType }, |
| 1129 { "getSegmentTypes", lpath_getSegementTypes }, |
| 1130 { "isConvex", lpath_isConvex }, |
| 1061 { "isEmpty", lpath_isEmpty }, | 1131 { "isEmpty", lpath_isEmpty }, |
| 1062 { "isRect", lpath_isRect }, | 1132 { "isRect", lpath_isRect }, |
| 1063 { "isNestedRects", lpath_isNestedRects }, | 1133 { "isNestedRects", lpath_isNestedRects }, |
| 1064 { "reset", lpath_reset }, | 1134 { "reset", lpath_reset }, |
| 1065 { "moveTo", lpath_moveTo }, | 1135 { "moveTo", lpath_moveTo }, |
| 1066 { "lineTo", lpath_lineTo }, | 1136 { "lineTo", lpath_lineTo }, |
| 1067 { "quadTo", lpath_quadTo }, | 1137 { "quadTo", lpath_quadTo }, |
| 1068 { "cubicTo", lpath_cubicTo }, | 1138 { "cubicTo", lpath_cubicTo }, |
| 1069 { "close", lpath_close }, | 1139 { "close", lpath_close }, |
| 1070 { "__gc", lpath_gc }, | 1140 { "__gc", lpath_gc }, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 REG_CLASS(L, SkShader); | 1366 REG_CLASS(L, SkShader); |
| 1297 REG_CLASS(L, SkTypeface); | 1367 REG_CLASS(L, SkTypeface); |
| 1298 REG_CLASS(L, SkMatrix); | 1368 REG_CLASS(L, SkMatrix); |
| 1299 } | 1369 } |
| 1300 | 1370 |
| 1301 extern "C" int luaopen_skia(lua_State* L); | 1371 extern "C" int luaopen_skia(lua_State* L); |
| 1302 extern "C" int luaopen_skia(lua_State* L) { | 1372 extern "C" int luaopen_skia(lua_State* L) { |
| 1303 SkLua::Load(L); | 1373 SkLua::Load(L); |
| 1304 return 0; | 1374 return 0; |
| 1305 } | 1375 } |
| OLD | NEW |