use macro to encapsulate building get_mtname() specializations
BUG= Review URL: https://codereview.chromium.org/15773002 git-svn-id: http://skia.googlecode.com/svn/trunk@9248 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
3597b73bc6
commit
fd3458750d
@ -19,6 +19,8 @@ extern "C" {
|
||||
static const char gDrawName[] = "onDrawContent";
|
||||
|
||||
static const char gCode[] = ""
|
||||
"require \"math\" "
|
||||
""
|
||||
"local r = { left = 10, top = 10, right = 100, bottom = 80 } "
|
||||
"local x = 0;"
|
||||
""
|
||||
@ -27,7 +29,30 @@ static const char gCode[] = ""
|
||||
""
|
||||
"local color = {a = 1, r = 1, g = 0, b = 0};"
|
||||
""
|
||||
"function rnd(range) "
|
||||
" return math.random() * range;"
|
||||
"end "
|
||||
""
|
||||
"rndX = function () return rnd(640) end "
|
||||
"rndY = function () return rnd(480) end "
|
||||
""
|
||||
"function draw_rand_path(canvas);"
|
||||
" if not path_paint then "
|
||||
" path_paint = Sk.newPaint();"
|
||||
" path_paint:setAntiAlias(true);"
|
||||
" end "
|
||||
" path_paint:setColor({a = 1, r = math.random(), g = math.random(), b = math.random() });"
|
||||
""
|
||||
" local path = Sk.newPath();"
|
||||
" path:moveTo(rndX(), rndY());"
|
||||
" for i = 0, 50 do "
|
||||
" path:quadTo(rndX(), rndY(), rndX(), rndY());"
|
||||
" end "
|
||||
" canvas:drawPath(path, path_paint);"
|
||||
"end "
|
||||
""
|
||||
"function onDrawContent(canvas) "
|
||||
" draw_rand_path(canvas);"
|
||||
" color.g = x / 100;"
|
||||
" paint:setColor(color) "
|
||||
" canvas:translate(x, 0);"
|
||||
@ -60,10 +85,6 @@ protected:
|
||||
}
|
||||
SkUnichar uni;
|
||||
if (SampleCode::CharQ(*evt, &uni)) {
|
||||
switch (uni) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return this->INHERITED::onQuery(evt);
|
||||
}
|
||||
|
@ -19,12 +19,18 @@ extern "C" {
|
||||
#include "lauxlib.h"
|
||||
}
|
||||
|
||||
// return the metatable name for a given class
|
||||
template <typename T> const char* get_mtname();
|
||||
template <> const char* get_mtname<SkCanvas>() { return "SkCanvas_LuaMetaTableName"; }
|
||||
template <> const char* get_mtname<SkMatrix>() { return "SkMatrix_LuaMetaTableName"; }
|
||||
template <> const char* get_mtname<SkRRect>() { return "SkSkRRect_LuaMetaTableName"; }
|
||||
template <> const char* get_mtname<SkPath>() { return "SkPath_LuaMetaTableName"; }
|
||||
template <> const char* get_mtname<SkPaint>() { return "SkPaint_LuaMetaTableName"; }
|
||||
#define DEF_MTNAME(T) \
|
||||
template <> const char* get_mtname<T>() { \
|
||||
return #T "_LuaMetaTableName"; \
|
||||
}
|
||||
|
||||
DEF_MTNAME(SkCanvas)
|
||||
DEF_MTNAME(SkMatrix)
|
||||
DEF_MTNAME(SkRRect)
|
||||
DEF_MTNAME(SkPath)
|
||||
DEF_MTNAME(SkPaint)
|
||||
|
||||
template <typename T> T* push_new(lua_State* L) {
|
||||
T* addr = (T*)lua_newuserdata(L, sizeof(T));
|
||||
@ -247,6 +253,12 @@ static int lcanvas_drawCircle(lua_State* L) {
|
||||
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));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lcanvas_getSaveCount(lua_State* L) {
|
||||
lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount());
|
||||
return 1;
|
||||
@ -272,6 +284,7 @@ static const struct luaL_Reg gSkCanvas_Methods[] = {
|
||||
{ "drawRect", lcanvas_drawRect },
|
||||
{ "drawOval", lcanvas_drawOval },
|
||||
{ "drawCircle", lcanvas_drawCircle },
|
||||
{ "drawPath", lcanvas_drawPath },
|
||||
{ "getSaveCount", lcanvas_getSaveCount },
|
||||
{ "getTotalMatrix", lcanvas_getTotalMatrix },
|
||||
{ "translate", lcanvas_translate },
|
||||
|
Loading…
Reference in New Issue
Block a user