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