Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Fixed 107 #108

Merged
merged 5 commits into from
Jun 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ html, body {
border-radius: 20px;
position: relative;
}
#menu-thumbnails canvas {
#menu-thumbnails img {
width: 100%;
height: 100%;
}
Expand Down
4 changes: 2 additions & 2 deletions js/frames-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ FramesController.prototype.remove = function(frameId) {
this.frames.splice(frameId, 1);
this.canvasModel.setImageData(
this.getFrameById(nextCurrentFrameId).imageData);
eventPublisher.publish("frames", {
frames: this.frames,
eventPublisher.publish("frames", {
frames: this.frames,
action: "remove",
actionFrame: frameId
});
Expand Down
42 changes: 25 additions & 17 deletions js/view/sequence-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ SequencePanel.prototype.getFrameTemplate = function(frameId) {
let frameDeleteBtn = document.createElement("button");
let frameUpBtn = document.createElement("button");
let frameDownBtn = document.createElement("button");
let previewCanvas = document.createElement("canvas");
let previewImage = document.createElement("img");
frame.dataset.frameIndex = frameId;
frame.classList.add("thumbnail");
frame.addEventListener("mousedown", (event) => {
// 子要素のmousedownによる発生を防ぐ
if (event.target.nodeName === "CANVAS") {
// IMGタグ、DIVタグのどちらかのときに作動するようにする
// (画像がないときはDIVタグのmousedownとなるため)
if (/IMG|DIV/.test(event.target.nodeName)) {
eventPublisher.publish("currentFrameId", frame.dataset.frameIndex);
this.setCurrentFrame(frame);
}
Expand All @@ -79,7 +81,7 @@ SequencePanel.prototype.getFrameTemplate = function(frameId) {
frame.appendChild(frameDeleteBtn);
frame.appendChild(frameUpBtn);
frame.appendChild(frameDownBtn);
frame.appendChild(previewCanvas);
frame.appendChild(previewImage);
return frame;
};

Expand All @@ -102,19 +104,18 @@ SequencePanel.prototype.appendMoveFrameEffect = function(
};

SequencePanel.prototype.updateThumbnail = function(frameId) {
let canvas = this.elem.querySelector(
`.thumbnail[data-frame-index=\"${frameId}\"] canvas`);
let imageData = this.framesController.frames[frameId].imageData;
let previewImage = this.elem.querySelector(
`.thumbnail[data-frame-index=\"${frameId}\"] img`);
let imageData;
if (this.framesController.currentFrameId === frameId) {
imageData = this.framesController.canvasModel.getImageData();
} else {
imageData = this.framesController.frames[frameId].imageData;
}
if (imageData !== null) {
canvas.width = imageData.width;
canvas.height = imageData.height;
let ctx = canvas.getContext("2d");
ctx.putImageData(imageData, 0, 0);
previewImage.width = imageData.width;
previewImage.height = imageData.height;
previewImage.src = imageDataToDataURL(imageData);
}
};

Expand Down Expand Up @@ -175,18 +176,15 @@ SequencePanel.prototype.moveDown = function(frameId) {
this.elem.querySelector(`[data-frame-index=\"${frameId}\"]`);
let moveUpFrame =
this.elem.querySelector(`[data-frame-index=\"${(frameId + 1)}\"]`);
this.elem.removeChild(moveDownFrame);
this.elem.insertBefore(moveDownFrame, moveUpFrame);
this.elem.removeChild(moveUpFrame);
this.elem.insertBefore(moveUpFrame, moveDownFrame);

this.renumber();

this.appendMoveFrameEffect(moveDownFrame, true,
this.appendMoveFrameEffect(moveDownFrame, false,
getComputedStyle(moveUpFrame).height);
this.appendMoveFrameEffect(moveUpFrame, false,
this.appendMoveFrameEffect(moveUpFrame, true,
getComputedStyle(moveDownFrame).height);

this.updateThumbnail(frameId);
this.updateThumbnail(frameId + 1);
};

SequencePanel.prototype.setCurrentFrame = function(frameIndex) {
Expand All @@ -200,4 +198,14 @@ SequencePanel.prototype.setCurrentFrame = function(frameIndex) {
}
};

function imageDataToDataURL(imageData) {
let canvas = document.createElement("canvas");
canvas.width = imageData.width;
canvas.height = imageData.height;
let ctx = canvas.getContext("2d");
ctx.putImageData(imageData, 0, 0);

return canvas.toDataURL("image/png");
}

export default SequencePanel;