diff options
| -rw-r--r-- | js/api/gallery.js | 3 | ||||
| -rw-r--r-- | js/api/set.js | 2 | ||||
| -rw-r--r-- | js/gallery.js | 1 | ||||
| -rw-r--r-- | js/image.js | 12 | ||||
| -rw-r--r-- | js/render.js | 40 | ||||
| -rw-r--r-- | js/shader.js | 6 | ||||
| -rw-r--r-- | shader-combo.html | 11 |
7 files changed, 58 insertions, 17 deletions
diff --git a/js/api/gallery.js b/js/api/gallery.js index c1a779d..0404009 100644 --- a/js/api/gallery.js +++ b/js/api/gallery.js @@ -68,7 +68,7 @@ function load_shaders(err, shaders){ var $shader = display_shader(shaders[i]) $el.append( $shader ) } - if (firsttime) { + if (false && firsttime) { firsttime = false run_shader(shaders[0]) } @@ -81,5 +81,6 @@ function display_shader(shader_object){ html = html.replace("{" + field + "}", shader_object[field]) } $shader.html(html) + shader_object.id && $shader.data("id", shader_object.id) return $shader; } diff --git a/js/api/set.js b/js/api/set.js index 461f3e3..16e60fe 100644 --- a/js/api/set.js +++ b/js/api/set.js @@ -59,7 +59,7 @@ function save_thumbnail(id, thumb){ status('') var data = JSON.parse(resp) if (data.success) { - $shader.find("img").attr("src", data.url) + $(".shader[data-id="+id+"]").find("img").attr("src", data.url) } }); } diff --git a/js/gallery.js b/js/gallery.js index b9acfc0..839316c 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -14,7 +14,6 @@ gallery.bind = function(){ $("#gallery-random").click(asdf.random) $("#gallery-search").submit(dumpfm.search) $(document).on("click", "#gallery-images canvas", gallery.click) - status("ready") } gallery.load = function(ims){ diff --git a/js/image.js b/js/image.js index 7a5240f..4de7fd9 100644 --- a/js/image.js +++ b/js/image.js @@ -1,15 +1,23 @@ +var gif, img + function loadImage(imageURL, callback) { var imageURL = proxify( imageURL ); window.gif = window.img = null - if (imageURL.substr(-3) === "gif") { + if (! imageURL) { + window.gif = null + window.img = null + callback() + } + else if (imageURL.substr(-3) === "gif") { window.gif = GIF(imageURL); // gif.on("error", tryToLoadNextImage); // gif.on("rendered", trackLoadTime); gif.on("rendered", callback); return gif.render(); - } else { + } + else { window.img = new Image(); // img.addEventListener("error", tryToLoadNextImage); img.addEventListener("load", callback); diff --git a/js/render.js b/js/render.js index a22c9fe..f6684d7 100644 --- a/js/render.js +++ b/js/render.js @@ -9,9 +9,10 @@ function choose (){ $("#url").val(imageURL) loadImage(imageURL, ready) } + function load(){ - loading = true var imageURL = $("#url").val() + loading = true loadImage(imageURL, ready) } @@ -25,7 +26,7 @@ function ready(){ f.cloneData = f.ctx.getImageData(0,0,w,h) } } - else { + else if (window.img) { fc = cq(img.width, img.height) fc.drawImage(img, 0, 0) frame = img_frame = { ctx: fc.context } @@ -33,25 +34,52 @@ function ready(){ h = cc.canvas.height = frame.ctx.canvas.height frame.cloneData = frame.ctx.getImageData(0,0,w,h) } + else { + cc.canvas.width = w + cc.canvas.height = h + shader_build() + } + displayWidthHeight(w, h) } +function displayWidthHeight(width, height){ + $("#width").val(width) + $("#height").val(height) +} +$("#width").change(function(){ + w = abs(parseInt(this.value,10)) || 1 + cc.canvas.width = w + cc.canvas.height = h +}) +$("#height").change(function(){ + h = abs(parseInt(this.value,10)) || 1 + cc.canvas.width = w + cc.canvas.height = h +}) function giveFrame(t){ if (window.gif) { if (gif.currentFrame) { return gif.frames[gif.currentFrame(t)] } - else { + else if (gif.frames) { return gif.frames[0] } } - else if (window.img) { + if (window.img) { return img_frame } else { - return cq(w, h) + return empty_frame() } } +function empty_frame(){ + w = w || 400 + h = h || 266 + var cx = cq(w, h).fillStyle("rgba(255,255,255,255)").fillRect(0,0,w,h) + return { ctx: cx.context, cloneData: cx.getImageData(0,0,w,h) } +} + function reset(){ start_t = old_t pause_t = 0 @@ -76,7 +104,7 @@ function animate(t){ var step_t = t - old_t old_t = t - + if (paused || dragging || rendering || scrolling || deferring) { pause_t += step_t if (scrolling) { diff --git a/js/shader.js b/js/shader.js index 4a6e950..7773b89 100644 --- a/js/shader.js +++ b/js/shader.js @@ -1,3 +1,5 @@ +function shader (x,y,t,d) {} + var shader_build = function(){ var fn_str = document.getElementById('shader').value if (!fn_str.length) fn_str = "" @@ -46,7 +48,7 @@ var firefox_stack_regexp = /:([0-9]+)$/; function shade_error_handling(frame, t){ if (! t || isNaN(t)) throw Error ("No time specified") - if (! frame) throw Error ("No frame specified") + if (! frame || ! frame.ctx || ! frame.cloneData) throw Error ("No frame specified") var imgData = frame.ctx.getImageData(0,0,w,h) var data = imgData.data @@ -77,7 +79,7 @@ function shade_error_handling(frame, t){ } else if (lines.length > 1) { // attempt chrome match var matches = lines[1].match(chrome_stack_regexp) - if (matches.length > 1) + if (matches && matches.length > 1) error_highlight.on(parseInt(matches[1]) - 3) } diff --git a/shader-combo.html b/shader-combo.html index 6d402da..e61beee 100644 --- a/shader-combo.html +++ b/shader-combo.html @@ -3,7 +3,8 @@ <head> <style type="text/css"> #url { width: 250px; } -#width,#height,#framecount,#framedelay,#frameinterval,#background { width: 30px; } +#width,#height,#framecount,#framedelay,#frameinterval,#background { width: 30px; text-align: right; } +#background { text-align: left; } #username { width: 55px; } #shader-name { width: 75px; } #shader-id { width: 40px; } @@ -89,7 +90,7 @@ form { display: inline-block; } </div> <div id="controls"> - <input type="text" id="url" value="img/1376516658960-dumpfm-DoritoWitch-TimeFLyTrans0001.png"> + <input type="text" id="url"> <input type="text" id="username" placeholder="username"> <input type="text" id="shader-name" placeholder="shader name"> <br> @@ -100,6 +101,8 @@ form { display: inline-block; } <button id="save-shader"><b>save shader</b></button> <button id="pause">pause</button> <button id="reset">reset</button> + <input type="text" id="width" placeholder="width" value="0"> + <input type="text" id="height" placeholder="height" value="0"> <span class="status"></span> <!--<button id="step-forward">>></button>--> <br> @@ -154,7 +157,7 @@ form { display: inline-block; } <script type="text/javascript"> var cc = cq(0,0).appendTo("#workspace") -var w, h +var w = 400, h = 266 var lastGif var mousex, mousey @@ -194,7 +197,7 @@ function init(){ frame_editor.init() help.init() load() - + user.init() help.init() shader_gallery.init() |
