Feature : merge layers
Added feature to merge a layer with the layer below Done at #jsconfeu2014 :) New icon in icons : merge-icon.png TODO : reorder the icons folder, it's waaaaaaay too messy !!
This commit is contained in:
parent
90845b3a62
commit
4ed7338f25
9 changed files with 65 additions and 6 deletions
|
@ -7,4 +7,8 @@
|
|||
|
||||
.action-icon.edit-icon {
|
||||
background-image: url('../img/tools/pen.png');
|
||||
}
|
||||
|
||||
.action-icon.merge-icon {
|
||||
background-image: url('../img/merge-icon.png');
|
||||
}
|
|
@ -46,22 +46,34 @@
|
|||
cursor : pointer;
|
||||
}
|
||||
|
||||
.layer-item .edit-icon {
|
||||
.layer-item .edit-icon, .layer-item .merge-icon {
|
||||
float: right;
|
||||
width: 30px;
|
||||
background-size: 12px;
|
||||
opacity: 0;
|
||||
transition : opacity 0.2s;
|
||||
}
|
||||
|
||||
.layer-item:hover .edit-icon {
|
||||
.layer-item:hover .edit-icon, .layer-item:hover .merge-icon {
|
||||
opacity : 0.6;
|
||||
}
|
||||
|
||||
.layer-item:hover .edit-icon:hover {
|
||||
.layer-item:hover .edit-icon:hover, .layer-item:hover .merge-icon:hover {
|
||||
opacity : 1;
|
||||
}
|
||||
|
||||
.layer-item .edit-icon {
|
||||
width: 25px;
|
||||
background-size: 12px;
|
||||
}
|
||||
|
||||
.layer-item .merge-icon {
|
||||
width: 18px;
|
||||
background-size: 16px;
|
||||
}
|
||||
|
||||
.layer-item:last-child .merge-icon {
|
||||
display : none;
|
||||
}
|
||||
|
||||
.layer-item:hover {
|
||||
background : #222;
|
||||
}
|
||||
|
|
BIN
src/img/merge-icon.png
Normal file
BIN
src/img/merge-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 438 B |
|
@ -67,6 +67,9 @@
|
|||
} else if (el.classList.contains('edit-icon')) {
|
||||
index = el.parentNode.dataset.layerIndex;
|
||||
this.renameLayerAt_(index);
|
||||
} else if (el.classList.contains('merge-icon')) {
|
||||
index = el.parentNode.dataset.layerIndex;
|
||||
this.mergeDownLayerAt_(index);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -79,6 +82,11 @@
|
|||
}
|
||||
};
|
||||
|
||||
ns.LayersListController.prototype.mergeDownLayerAt_ = function (index) {
|
||||
this.piskelController.mergeDownLayerAt(index);
|
||||
this.renderLayerList_();
|
||||
};
|
||||
|
||||
ns.LayersListController.prototype.onButtonClick_ = function (button) {
|
||||
var action = button.getAttribute('data-action');
|
||||
if (action == 'up') {
|
||||
|
|
|
@ -205,6 +205,18 @@
|
|||
}
|
||||
};
|
||||
|
||||
ns.PiskelController.prototype.mergeDownLayerAt = function (index) {
|
||||
var layer = this.getLayerByIndex(index);
|
||||
var downLayer = this.getLayerByIndex(index-1);
|
||||
if (layer && downLayer) {
|
||||
var mergedLayer = pskl.utils.LayerUtils.mergeLayers(layer, downLayer);
|
||||
this.removeLayerAt(index);
|
||||
this.piskel.addLayerAt(mergedLayer, index);
|
||||
this.removeLayerAt(index-1);
|
||||
this.selectLayer(mergedLayer);
|
||||
}
|
||||
};
|
||||
|
||||
ns.PiskelController.prototype.generateLayerName_ = function () {
|
||||
var name = "Layer " + this.layerIdCounter;
|
||||
while (this.hasLayerForName_(name)) {
|
||||
|
|
|
@ -99,6 +99,12 @@
|
|||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.mergeDownLayerAt = function (index) {
|
||||
this.raiseSaveStateEvent_(this.piskelController.mergeDownLayerAt, [index]);
|
||||
this.piskelController.mergeDownLayerAt(index);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.moveLayerUp = function () {
|
||||
this.raiseSaveStateEvent_(this.piskelController.moveLayerUp, []);
|
||||
this.piskelController.moveLayerUp();
|
||||
|
|
|
@ -73,6 +73,10 @@
|
|||
this.layers.push(layer);
|
||||
};
|
||||
|
||||
ns.Piskel.prototype.addLayerAt = function (layer, index) {
|
||||
this.layers.splice(index, 0, layer);
|
||||
};
|
||||
|
||||
ns.Piskel.prototype.moveLayerUp = function (layer) {
|
||||
var index = this.layers.indexOf(layer);
|
||||
if (index > -1 && index < this.layers.length-1) {
|
||||
|
|
|
@ -25,6 +25,18 @@
|
|||
frames.push(frame);
|
||||
}
|
||||
return frames;
|
||||
},
|
||||
|
||||
mergeLayers : function (layerA, layerB) {
|
||||
var framesA = layerA.getFrames();
|
||||
var framesB = layerB.getFrames();
|
||||
var mergedFrames = [];
|
||||
framesA.forEach(function (frame, index) {
|
||||
var otherFrame = framesB[index];
|
||||
mergedFrames.push(pskl.utils.FrameUtils.merge([otherFrame, frame]));
|
||||
});
|
||||
var mergedLayer = pskl.model.Layer.fromFrames(layerA.getName(), mergedFrames);
|
||||
return mergedLayer;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
</div>
|
||||
<script type="text/template" id="layer-item-template">
|
||||
<li class="layer-item {{isselected:current-layer-item}}" data-layer-index="{{layerindex}}">{{layername}}
|
||||
<span class="action-icon edit-icon" title="edit name"> </span>
|
||||
<span class="action-icon edit-icon" title="Edit layer name" rel="tooltip" data-placement="top"> </span>
|
||||
<span class="action-icon merge-icon" title="Merge with layer below" rel="tooltip" data-placement="top"> </span>
|
||||
</li>
|
||||
</script>
|
||||
<ul class="layers-list"></ul>
|
||||
|
|
Loading…
Reference in a new issue