summaryrefslogtreecommitdiff
path: root/js/frames.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/frames.js')
-rw-r--r--js/frames.js60
1 files changed, 49 insertions, 11 deletions
diff --git a/js/frames.js b/js/frames.js
index 0ae256c..fc6ee24 100644
--- a/js/frames.js
+++ b/js/frames.js
@@ -1,3 +1,40 @@
+var frame_thumb_size = 93
+
+var frame_editor = {}
+
+frame_editor.init = function(){
+ frame_editor.bind()
+}
+
+frame_editor.bind = function(){
+ $("#add-frame").click(add_frame)
+ $("#frames").sortable({
+ start: drag_start,
+ stop: drag_stop
+ });
+ $(document).on("click","#frames .remove",remove_frame)
+ $("#framecount").change(function(){
+ var val = $(this).int()
+ if (val < 1 || isNaN(val)) $(this).val(val = 1)
+ if (val == 1) $("#add-frame").html("+add frame")
+ else $("#add-frame").html("+add frames")
+ })
+
+ $("#frames").disableSelection();
+ $("#remove-all-frames").click(remove_all_frames)
+ $("#weave-frames").click(weave_frames)
+ $("#shuffle-frames").click(shuffle_frames)
+ $("#reverse-frames").click(reverse_frames)
+ $("#sort-frames").click(sort_frames)
+
+ $("#render").click(render)
+ $("#save").click(save)
+ $("#upload").click(upload)
+
+ $("#background").change(function(){
+ document.body.style.backgroundColor = $("#background").string()
+ })
+}
function add_frame(){
var frame_count = $("#framecount").int()
@@ -15,14 +52,13 @@ function add_single_frame(){
var frame = cc.clone().appendTo($el.find(".frame")[0])
frame.canvas.className = "fullsize"
frame.canvas.style.display = "none"
- var thumb = cc.clone().resize(100,100).appendTo($el.find(".frame")[0])
+ var thumb = cc.clone().resize(frame_thumb_size,frame_thumb_size).appendTo($el.find(".frame")[0])
$("#frames").append($el)
- $("#render").enable()
}
function add_frames(frame_count){
rendering = true
var t = old_t - start_t - pause_t
- var frame_delay = $("#frameinterval").float() * 1000
+ var frame_delay = ($("#frameinterval").float() || $("#framedelay").float()) * 1000
var frame
for (var i = 0; i < frame_count; i++) {
frame = giveFrame(t)
@@ -34,9 +70,6 @@ function add_frames(frame_count){
}
function remove_frame(){
$(this).closest("div").remove()
- if ($("#frames div").length == 0) {
- $("#render").disable()
- }
}
function remove_all_frames(){
$("#frames").empty()
@@ -64,6 +97,10 @@ function sort_frames(){
function render (){
if (rendering) return
+ if ($("#frames canvas.fullsize").length == 0) {
+ add_frame()
+ }
+
rendering = true
encoder.reset()
var delay = $("#framedelay").float() * 1000 || 100
@@ -72,7 +109,7 @@ function render (){
encoder.addFrame(frame.canvas, delay)
})
$("#pause,#render,#add-frame").disable()
- $("#rendered").find("img").remove()
+ $("#workspace").find("img").remove()
$("#rendered").show()
// really bad results with neuquant?
// status("quantizing")
@@ -89,8 +126,6 @@ function render (){
$("#render").html("rendering")
}
-function status(s){ $(".status").html(s) }
-
var encoder = new GifEncoder()
encoder.on("quantized", function(url){
@@ -109,11 +144,13 @@ encoder.on("rendered", function(bytes){
encoder.on("rendered-url", function(url){
var image = new Image ()
lastGif = image.src = url
- $("#rendered").append(image)
+ $("#workspace canvas").hide()
+ $("#workspace").append(image)
$("#uploaded-url").hide().val("")
+ $("#uploaded-url + br").hide()
$("#save,#upload,#rendered").show()
$("#pause,#render,#add-frame,#save,#upload").enable()
- $("#render").html("render")
+ $("#render").html("render gif")
rendering = false
pause(true)
})
@@ -161,6 +198,7 @@ function upload(){
console.log(data);
status("uploaded");
$("#uploaded-url").show().focus().val(data.url)
+ $("#uploaded-url + br").show()
},
error: function(data){
console.log(data)