still chasing canvas issues

This commit is contained in:
Danny Yoo 2011-07-19 14:25:52 -04:00
parent 90b836ef12
commit 62bee7804c
2 changed files with 22 additions and 21 deletions

View File

@ -27,14 +27,14 @@ var bigBang = function(MACHINE, initW, handlers) {
var oldArgcount = MACHINE.argcount; var oldArgcount = MACHINE.argcount;
var toplevelNode = $('<div/>').css('border', '2').appendTo(document.body); var toplevelNode = $('<div/>').css('border', '1px solid black').appendTo(document.body).get(0);
var configs = []; var configs = [];
var isOutputConfigSeen = false; var isOutputConfigSeen = false;
for (var i = 0 ; i < handlers.length; i++) { for (var i = 0 ; i < handlers.length; i++) {
if (isWorldConfigOption(handlers[i])) { if (isWorldConfigOption(handlers[i])) {
configs.push(handlers[i].toRawHandler(MACHINE)); configs.push(handlers[i].toRawHandler(MACHINE, toplevelNode));
} }
else { else {
configs.push(handlers[i]); configs.push(handlers[i]);
@ -44,7 +44,7 @@ var bigBang = function(MACHINE, initW, handlers) {
// If we haven't seen an onDraw function, use the default one. // If we haven't seen an onDraw function, use the default one.
if (! isOutputConfigSeen) { if (! isOutputConfigSeen) {
configs.push(new DefaultDrawingOutput(toplevelNode.get(0)).toRawHandler(MACHINE)); configs.push(new DefaultDrawingOutput().toRawHandler(MACHINE, toplevelNode));
} }
@ -56,7 +56,7 @@ var bigBang = function(MACHINE, initW, handlers) {
// state.addBreakRequestedListener(onBreak); // state.addBreakRequestedListener(onBreak);
var bigBangController = rawJsworld.bigBang( var bigBangController = rawJsworld.bigBang(
toplevelNode.get(0), toplevelNode,
initW, initW,
configs, configs,
{}, {},
@ -151,7 +151,7 @@ var OnTick = function(handler, aDelay) {
OnTick.prototype = plt.baselib.heir(WorldConfigOption.prototype); OnTick.prototype = plt.baselib.heir(WorldConfigOption.prototype);
OnTick.prototype.toRawHandler = function(MACHINE) { OnTick.prototype.toRawHandler = function(MACHINE, toplevelNode) {
var that = this; var that = this;
var worldFunction = adaptWorldFunction(that.handler); var worldFunction = adaptWorldFunction(that.handler);
return rawJsworld.on_tick(this.delay, worldFunction); return rawJsworld.on_tick(this.delay, worldFunction);
@ -181,11 +181,10 @@ var ToDraw = function(handler) {
ToDraw.prototype = plt.baselib.heir(OutputConfig.prototype); ToDraw.prototype = plt.baselib.heir(OutputConfig.prototype);
ToDraw.prototype.toRawHandler = function(MACHINE) { ToDraw.prototype.toRawHandler = function(MACHINE, toplevelNode) {
var that = this; var that = this;
var reusableCanvas; var reusableCanvas;
var reusableCanvasNode; var reusableCanvasNode;
var toplevelNode = this.toplevelNode;
var adaptedWorldFunction = adaptWorldFunction(this.handler); var adaptedWorldFunction = adaptWorldFunction(this.handler);
var worldFunction = function(world, success) { var worldFunction = function(world, success) {
@ -214,9 +213,9 @@ ToDraw.prototype.toRawHandler = function(MACHINE) {
reusableCanvas.height = height; reusableCanvas.height = height;
var ctx = reusableCanvas.getContext("2d"); var ctx = reusableCanvas.getContext("2d");
v.render(ctx, 0, 0); v.render(ctx, 0, 0);
success(rawJsworld.node_to_tree(reusableCanvasNode)); success([toplevelNode, rawJsworld.node_to_tree(reusableCanvasNode)]);
} else { } else {
success(rawJsworld.node_to_tree(plt.baselib.format.toDomNode(v))); success([toplevelNode, rawJsworld.node_to_tree(plt.baselib.format.toDomNode(v))]);
} }
}); });
}; };
@ -240,21 +239,20 @@ ToDraw.prototype.toRawHandler = function(MACHINE) {
var DefaultDrawingOutput = function(toplevelNode) { var DefaultDrawingOutput = function() {
WorldConfigOption.call(this, 'to-draw'); WorldConfigOption.call(this, 'to-draw');
// this.toplevelNode = toplevelNode;
}; };
DefaultDrawingOutput.prototype = plt.baselib.heir(WorldConfigOption.prototype); DefaultDrawingOutput.prototype = plt.baselib.heir(WorldConfigOption.prototype);
DefaultDrawingOutput.prototype.toRawHandler = function(MACHINE) { DefaultDrawingOutput.prototype.toRawHandler = function(MACHINE, toplevelNode) {
var that = this; var that = this;
var worldFunction = function(world, k) { var worldFunction = function(world, success) {
// k([that.toplevelNode, success([toplevelNode,
// rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world))]); rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world))]);
k(rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world))); //k(rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world)));
}; };
var cssFunction = function(w, k) { k([]); } var cssFunction = function(w, success) { success([]); }
return rawJsworld.on_draw(worldFunction, cssFunction); return rawJsworld.on_draw(worldFunction, cssFunction);
}; };
@ -272,7 +270,7 @@ var StopWhen = function(handler) {
StopWhen.prototype = plt.baselib.heir(WorldConfigOption.prototype); StopWhen.prototype = plt.baselib.heir(WorldConfigOption.prototype);
StopWhen.prototype.toRawHandler = function(MACHINE) { StopWhen.prototype.toRawHandler = function(MACHINE, toplevelNode) {
var that = this; var that = this;
var worldFunction = adaptWorldFunction(that.handler); var worldFunction = adaptWorldFunction(that.handler);
return rawJsworld.stop_when(worldFunction); return rawJsworld.stop_when(worldFunction);

View File

@ -1071,12 +1071,12 @@ var rawJsworld = {};
function isTextNode(n) { function isTextNode(n) {
return (n.nodeType == Node.TEXT_NODE); return (n.nodeType == Node.TEXT_NODE);
} };
function isElementNode(n) { function isElementNode(n) {
return (n.nodeType == Node.ELEMENT_NODE); return (n.nodeType == Node.ELEMENT_NODE);
} };
var throwDomError = function(thing, topThing) { var throwDomError = function(thing, topThing) {
@ -1098,6 +1098,7 @@ var rawJsworld = {};
throwDomError(thing, topThing); throwDomError(thing, topThing);
} }
// Check that the first element is a Text or an element. // Check that the first element is a Text or an element.
if (isTextNode(thing[0])) { if (isTextNode(thing[0])) {
if (thing.length > 1) { if (thing.length > 1) {
@ -1110,6 +1111,8 @@ var rawJsworld = {};
checkDomSexp(thing[i], thing); checkDomSexp(thing[i], thing);
} }
} else { } else {
console.log(thing[0]);
throw new JsworldDomError( throw new JsworldDomError(
plt.baselib.format.format( plt.baselib.format.format(
"expected a Text or an Element, received ~s within ~s", "expected a Text or an Element, received ~s within ~s",
@ -1123,7 +1126,7 @@ var rawJsworld = {};
this.elt = elt; this.elt = elt;
} }
JsworldDomError.prototype.toString = function() { JsworldDomError.prototype.toString = function() {
return "on-draw: " + this.msg; return "JsworldDomError: " + this.msg;
} }