-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
266 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// extends src/nodes/image.js which extends src/node-box-native-view.js | ||
|
||
$(function(){ | ||
|
||
var template = | ||
'<div class="layers" style="z-index:1" />'+ | ||
'<div class="info" style="position:absolute; left:0; bottom:0; z-index:2" />'; | ||
|
||
Iframework.NativeNodes["view-layers"] = Iframework.NativeNodes["view"].extend({ | ||
|
||
info: { | ||
title: "layers", | ||
description: "can get any of the canvases in the graph and make a stack of them" | ||
}, | ||
template: _.template(template), | ||
events: { | ||
"change .vis": "setVis" | ||
}, | ||
initializeModule: function(){ | ||
// Hide old | ||
$(this.canvas).hide(); | ||
// Make list | ||
var list = $('<ul class="list" style="list-style-type:none; margin:0; padding:0;"></ul>'); | ||
$("canvas").each(function(i, canvas){ | ||
var li = $('<li class="ui-state-default" style="padding:5px;" />') | ||
.text(canvas.id); | ||
var vis = $('<input type="checkbox" id="vis-'+canvas.id+'" class="vis" title="visible" />') | ||
.data({ | ||
"canvas": canvas, | ||
"id": canvas.id.split("-")[1] | ||
}); | ||
li.append(vis); | ||
list.append(li); | ||
}); | ||
list.sortable(); | ||
this.$(".info").html(list); | ||
}, | ||
setVis: function(event){ | ||
if (!this.visible) { | ||
this.visible = {}; | ||
} | ||
var id = $(event.target).data("id"); | ||
if (event.target.checked) { | ||
// Show canvas to copy | ||
if (!this.visible[id]) { | ||
var vis = {}; | ||
this.visible[id] = vis; | ||
vis.nativeView = this.model.graph.get("nodes").get(id).view.Native; | ||
vis.original = $(event.target).data("canvas"); | ||
vis.copy = document.createElement("canvas"); | ||
vis.copy.width = vis.original.width; | ||
vis.copy.height = vis.original.height; | ||
vis.copy.style.position = "absolute"; | ||
vis.copy.style.top = 0; | ||
vis.copy.style.left = 0; | ||
vis.context = vis.copy.getContext("2d"); | ||
vis.context.drawImage(vis.original, 0, 0); | ||
vis.last = vis.nativeView._lastRedraw; | ||
this.$(".layers").append(vis.copy); | ||
} | ||
} else { | ||
// Kill canvas | ||
if (this.visible[id]) { | ||
this.$(this.visible[id].copy).remove(); | ||
this.visible[id] = null; | ||
} | ||
} | ||
console.log(this.visible); | ||
}, | ||
redraw: function(){ | ||
// Called from NodeBoxNativeView.renderAnimationFrame() | ||
}, | ||
renderAnimationFrame: function (timestamp) { | ||
// Get a tick from GraphView.renderAnimationFrame() | ||
// this._valueChanged is set by NodeBox.receive() | ||
if (this._triggerRedraw) { | ||
this._triggerRedraw = false; | ||
this.redraw(timestamp); | ||
this._lastRedraw = timestamp; | ||
} | ||
for (var i in this.visible) { | ||
var layer = this.visible[i]; | ||
if (layer) { | ||
if (layer.last !== layer.nativeView._lastRedraw) { | ||
layer.context.drawImage(layer.original, 0, 0); | ||
layer.last = layer.nativeView._lastRedraw; | ||
} | ||
} | ||
} | ||
}, | ||
inputs: { | ||
}, | ||
outputs: { | ||
} | ||
|
||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// extends src/node-box-native-view.js | ||
|
||
$(function(){ | ||
|
||
var template = | ||
// '<canvas id="canvas-<%= id %>" class="canvas" width="500" height="500" style="max-width:100%;" />'+ | ||
'<div class="info" />'; | ||
|
||
Iframework.NativeNodes["view"] = Iframework.NodeBoxNativeView.extend({ | ||
|
||
template: _.template(template), | ||
initializeCategory: function() { | ||
// Add popout button to box | ||
var self = this; | ||
this.model.view.$("button.remove") | ||
.after( | ||
$('<button type="button" class="popout">popout</button>') | ||
.button({ icons: { primary: "icon-popup" }, text: false }) | ||
.click(function(){ | ||
self.popout(); | ||
}) | ||
); | ||
|
||
this.canvas = document.createElement("canvas"); | ||
this.canvas.width = 500; | ||
this.canvas.height = 500; | ||
this.context = this.canvas.getContext('2d'); | ||
this.showCanvas(); | ||
}, | ||
scale: function(){ | ||
// canvas is shown at this scaling factor | ||
// useful for absolute positioning other elements over the canvas | ||
return this.$(".canvas").width() / this.canvas.width; | ||
}, | ||
outputs: { | ||
image: { | ||
type: "image" | ||
} | ||
}, | ||
showCanvas: function(){ | ||
$(this.canvas).attr({ | ||
"class": "canvas", | ||
"id": "canvas-"+this.model.id, | ||
"style": "max-width:100%" | ||
}); | ||
this.$el.prepend(this.canvas); | ||
}, | ||
_smoothing: true, | ||
inputsmoothing: function (s) { | ||
this._smoothing = s; | ||
// HACK browser-specific stuff | ||
this.context.webkitImageSmoothingEnabled = s; | ||
this.context.mozImageSmoothingEnabled = s; | ||
}, | ||
popout: function() { | ||
if (this.w) { | ||
// Toggle | ||
this.popin(); | ||
return false; | ||
} | ||
|
||
// Cache local canvas | ||
this.localCanvas = this.canvas; | ||
this.localContext = this.context; | ||
$(this.localCanvas).hide(); | ||
|
||
// Open new window to about:blank | ||
this.w = window.open("", "meemooRemoteWindow", "menubar=no,location=no,resizable=yes,scrollbars=no,status=no"); | ||
var self = this; | ||
this.w.addEventListener("unload", function(){ | ||
self.popin(); | ||
}); | ||
|
||
// Popin other | ||
if (Iframework.popoutModule && Iframework.popoutModule !== this) { | ||
Iframework.popoutModule.popin(); | ||
} | ||
Iframework.popoutModule = this; | ||
// TODO: fade out other canvas? | ||
this.w.document.body.innerHTML = ""; | ||
|
||
// Make new canvas | ||
this.canvas = this.w.document.createElement("canvas"); | ||
this.canvas.width = this.localCanvas.width; | ||
this.canvas.height = this.localCanvas.height; | ||
this.context = this.canvas.getContext('2d'); | ||
this.w.document.body.appendChild(this.canvas); | ||
|
||
// Full-screen styling | ||
this.w.document.body.style.backgroundColor="black"; | ||
this.w.document.body.style.margin="0px"; | ||
this.w.document.body.style.padding="0px"; | ||
this.canvas.style.position="absolute"; | ||
this.canvas.style.top="0px"; | ||
this.canvas.style.left="0px"; | ||
this.canvas.style.width="100%"; | ||
this.canvas.style.height="100%"; | ||
|
||
// Smoothing on new canvas | ||
this.inputsmoothing(this._smoothing); | ||
|
||
return false; | ||
}, | ||
popin: function() { | ||
if (this.w) { | ||
this.w = null; | ||
} | ||
this.canvas = this.localCanvas; | ||
this.context = this.localContext; | ||
$(this.canvas).show(); | ||
|
||
// Smoothing on canvas (only matters if it changed while out) | ||
this.inputsmoothing(this._smoothing); | ||
|
||
return false; | ||
} | ||
// showResizer: function(translateX, translateY, scale, rotate){ | ||
// if (!this.resizer) { | ||
// this.resizer = $('<div class="resizer">'); | ||
// this.$el.append(this.resizer); | ||
// } | ||
// var sizedScale = this.scale(); | ||
// this.resizer | ||
// .css({ | ||
// position: "absolute", | ||
// border: "1px solid black", | ||
// top: translateX * sizedScale, | ||
// left: translateY * sizedScale, | ||
// width: 20, | ||
// height: 20 | ||
// }); | ||
// // .hide(); | ||
// var self = this; | ||
// // $(this.canvas) | ||
// // .mouseover(function(){ | ||
// // self.resizer.show(); | ||
// // }) | ||
// // .mouseout(function(){ | ||
// // self.resizer.hide(); | ||
// // }); | ||
// if (translateX || translateY) { | ||
// this.resizer.draggable({}); | ||
// } | ||
// if (scale) { | ||
// this.resizer.resizable({}); | ||
// } | ||
// } | ||
// togglePreview: function(e){ | ||
// if (e.target.checked) { | ||
// this.$el.prepend(this.canvas); | ||
// } else { | ||
// this.$("canvas").remove(); | ||
// } | ||
// } | ||
|
||
}); | ||
|
||
|
||
}); |