* @param {Number} newHeight The new height to assign to this Layer.
*/
function resize(newWidth, newHeight) {
+
+
+ // Only preserve old data if width/height are both non-zero
+ var oldData = null;
+ if (width != 0 && height != 0) {
+
+ // Create canvas and context for holding old data
+ oldData = document.createElement("canvas");
+ oldData.width = width;
+ oldData.height = height;
+
+ var oldDataContext = oldData.getContext("2d");
+
+ // Copy image data from current
+ oldDataContext.drawImage(display,
+ 0, 0, width, height,
+ 0, 0, width, height);
+
+ }
+
+ // Resize canvas
display.width = newWidth;
display.height = newHeight;
+ // Redraw old data, if any
+ if (oldData)
+ displayContext.drawImage(oldData,
+ 0, 0, width, height,
+ 0, 0, width, height);
+
width = newWidth;
height = newHeight;
}
}
+ var tasksInProgress = false;
+
/**
* Run any Tasks which were pending but are now ready to run and are not
* blocked by other Tasks.
*/
function handlePendingTasks() {
+ if (tasksInProgress)
+ return;
+
+ tasksInProgress = true;
+
// Draw all pending tasks.
var task;
while ((task = tasks[0]) != null && task.handler) {
task.handler();
}
+ tasksInProgress = false;
+
}
/**
};
// Initialize canvas dimensions
- resize(width, height);
+ display.width = width;
+ display.height = height;
};