mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 1 | function tostr(t) |
| 2 | local str = "" |
| 3 | for k, v in next, t do |
mike@reedtribe.org | 0e59b79 | 2013-05-21 03:24:37 +0000 | [diff] [blame] | 4 | if #str > 0 then |
| 5 | str = str .. ", " |
| 6 | end |
| 7 | if type(k) == "number" then |
| 8 | str = str .. "[" .. k .. "] = " |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 9 | else |
mike@reedtribe.org | 0e59b79 | 2013-05-21 03:24:37 +0000 | [diff] [blame] | 10 | str = str .. tostring(k) .. " = " |
| 11 | end |
| 12 | if type(v) == "table" then |
| 13 | str = str .. "{ " .. tostr(v) .. " }" |
| 14 | else |
| 15 | str = str .. tostring(v) |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 16 | end |
| 17 | end |
| 18 | return str |
| 19 | end |
| 20 | |
reed@google.com | 2d51677 | 2013-05-21 16:05:53 +0000 | [diff] [blame] | 21 | local total = {} -- accumulate() stores its data in here |
| 22 | local canvas -- holds the current canvas (from startcanvas()) |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 23 | |
reed@google.com | 2d51677 | 2013-05-21 16:05:53 +0000 | [diff] [blame] | 24 | --[[ |
| 25 | startcanvas() is called at the start of each picture file, passing the |
| 26 | canvas that we will be drawing into, and the name of the file. |
| 27 | |
| 28 | Following this call, there will be some number of calls to accumulate(t) |
| 29 | where t is a table of parameters that were passed to that draw-op. |
| 30 | |
| 31 | t.verb is a string holding the name of the draw-op (e.g. "drawRect") |
| 32 | |
| 33 | when a given picture is done, we call endcanvas(canvas, fileName) |
| 34 | ]] |
| 35 | function sk_scrape_startcanvas(c, fileName) |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 36 | canvas = c |
| 37 | end |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 38 | |
reed@google.com | 2d51677 | 2013-05-21 16:05:53 +0000 | [diff] [blame] | 39 | --[[ |
| 40 | Called when the current canvas is done drawing. |
| 41 | ]] |
| 42 | function sk_scrape_endcanvas(c, fileName) |
| 43 | canvas = nil |
| 44 | end |
| 45 | |
| 46 | --[[ |
| 47 | Called with the parameters to each canvas.draw call, where canvas is the |
| 48 | current canvas as set by startcanvas() |
| 49 | ]] |
| 50 | function sk_scrape_accumulate(t) |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 51 | local n = total[t.verb] or 0 |
| 52 | total[t.verb] = n + 1 |
| 53 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 54 | if false and t.verb == "drawRect" and t.paint:isAntiAlias() then |
| 55 | local r = t.rect; |
| 56 | local p = t.paint; |
| 57 | local c = p:getColor(); |
| 58 | print("drawRect ", tostr(r), tostr(c), "\n") |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 59 | end |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 60 | |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame] | 61 | if false and t.verb == "drawPath" then |
| 62 | local pred, r1, r2, d1, d2 = t.path:isNestedRects() |
| 63 | |
| 64 | if pred then |
| 65 | print("drawRect_Nested", tostr(r1), tostr(r2), d1, d2) |
| 66 | else |
| 67 | print("drawPath", "isEmpty", tostring(t.path:isEmpty()), |
| 68 | "isRect", tostring(t.path:isRect()), tostr(t.path:getBounds())) |
| 69 | end |
| 70 | end |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 71 | end |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 72 | |
reed@google.com | 2d51677 | 2013-05-21 16:05:53 +0000 | [diff] [blame] | 73 | --[[ |
| 74 | lua_pictures will call this function after all of the pictures have been |
| 75 | "accumulated". |
| 76 | ]] |
| 77 | function sk_scrape_summarize() |
| 78 | io.write("\n{ ", tostr(total), " }\n") |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 79 | end |
| 80 | |