@@ -98,61 +98,11 @@ function debugModule(module, runtime) {
99function debuggerInit(debugModule, runtime) {
99function debuggerInit(debugModule, runtime) {
100 var Signal = Elm.Signal.make(runtime);
100 var Signal = Elm.Signal.make(runtime);
101− var List = Elm.List.make(runtime);
102 var graphicsNode = debugModule.moduleInstance.main.kids[0];
101 var graphicsNode = debugModule.moduleInstance.main.kids[0];
104− var tracePathCanvas = document.createElement('canvas');
103+ var tracePath = tracePathInit(runtime);
105− tracePathCanvas.width = window.innerWidth;
106− tracePathCanvas.height = window.innerHeight;
107− tracePathCanvas.style.position = "absolute";
108− tracePathCanvas.style.top = "0";
109− tracePathCanvas.style.left = "0";
110− runtime.node.parentNode.appendChild(tracePathCanvas);
112− function graphicsUpdate(currentScene) {
113− var ctx = tracePathCanvas.getContext('2d');
114− ctx.clearRect(0, 0, tracePathCanvas.width, tracePathCanvas.height);
115− ctx.fillText("Debugger trace path", 20, 20);
117− function drawElement(elem) {
118− if (elem.element.ctor == "Custom" && elem.element.type == "Collage")
120− List.map(drawForm)(elem.element.model.forms);
122− else if (elem.element.ctor == "Image")
127− ctx.arc(x, y, 2, 0, 2*Math.PI);
128− ctx.fillStyle = "grey";
131− ctx.strokeStype = "black";
136− function drawForm(form) {
138− ctx.scale(form.scale, form.scale);
139− ctx.rotate(form.theta);
140− ctx.translate(form.x, -form.y);
141− if (form.form.ctor == "FElement")
143− drawElement(form.form._0);
150− ctx.translate(ctx.canvas.width/2, ctx.canvas.height/2);
151− drawElement(currentScene);
155− var tracePathNode = A2(Signal.lift, graphicsUpdate, graphicsNode);
104+ var tracePathNode = A2(Signal.lift, tracePath.graphicsUpdate, graphicsNode);
105+ runtime.node.parentNode.appendChild(tracePath.canvas);
157 function resetProgram() {
107 function resetProgram() {
158 debugModule.clearAsyncEvents();
108 debugModule.clearAsyncEvents();
@@ -223,7 +173,114 @@ function debuggerInit(debugModule, runtime) {
223 return elmDebugger;
173 return elmDebugger;
176+function Point(x, y) {
180+ this.translate = function(x, y) {
181+ return new Point(this.x + x, this.y + y);
184+ this.equals = function(p) {
185+ return this.x == p.x && this.y == p.y;
189+function tracePathInit(runtime) {
190+ var List = Elm.List.make(runtime);
191+ var tracePathCanvas = createCanvas();
192+ var tracePositions = {};
194+ function findPositions(currentScene) {
196+ function processElement(elem, offset) {
197+ if (elem.element.ctor == "Custom" && elem.element.type == "Collage")
199+ List.map(F2(processForm)(offset))(elem.element.model.forms);
201+ else if (elem.element.ctor == "Image" && elem.props.debugTracePathId)
203+ positions[elem.props.debugTracePathId] = new Point(offset.x, offset.y);
207+ function processForm(offset, form) {
208+ if (form.form.ctor == "FElement")
210+ processElement(form.form._0, offset.translate(form.x, -form.y));
214+ processElement(currentScene, new Point(0, 0));
218+ function appendPositions(positions) {
219+ for (var id in positions) {
220+ var pos = positions[id];
221+ if (tracePositions.hasOwnProperty(id)) {
222+ var points = tracePositions[id];
223+ if (!pos.equals(points[points.length-1])) {
228+ tracePositions[id] = [pos];
233+ function graphicsUpdate(currentScene) {
234+ var ctx = tracePathCanvas.getContext('2d');
235+ ctx.clearRect(0, 0, tracePathCanvas.width, tracePathCanvas.height);
236+ ctx.fillText("Debugger trace path", 20, 20);
239+ ctx.translate(ctx.canvas.width/2, ctx.canvas.height/2);
240+ appendPositions(findPositions(currentScene));
241+ for (var id in tracePositions)
244+ var points = tracePositions[id];
245+ for (var i=0; i < points.length; i++)
249+ ctx.moveTo(p.x, p.y);
252+ ctx.lineTo(p.x, p.y);
257+ ctx.strokeStyle = "black";
263+ function clearTraces() {
264+ tracePositions = {};
268+ graphicsUpdate: graphicsUpdate,
269+ canvas: tracePathCanvas,
270+ clearTraces: clearTraces
275+function createCanvas() {
276+ var c = document.createElement('canvas');
277+ c.width = window.innerWidth;
278+ c.height = window.innerHeight;
279+ c.style.position = "absolute";
228function assert(bool, msg) {
285function assert(bool, msg) {
229 if (!bool) {
286 if (!bool) {