mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
feature : allow to delete current selection
* Users can now use DEL to delete the current selection * Cheatsheet has been updated accordingly * Cheatsheet has been refactored to mutualize markup creation code
This commit is contained in:
parent
4b608e98a9
commit
903f6817cf
@ -17,7 +17,7 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
padding: 20px 10%;
|
padding: 20px 3%;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
background: rgba(0,0,0,0.9);
|
background: rgba(0,0,0,0.9);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
.cheatsheet-section {
|
.cheatsheet-section {
|
||||||
float: left;
|
float: left;
|
||||||
width : 50%;
|
width : 33%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cheatsheet-shortcut {
|
.cheatsheet-shortcut {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
pskl.app.shortcutService.addShortcut('ctrl+V', this.paste.bind(this));
|
pskl.app.shortcutService.addShortcut('ctrl+V', this.paste.bind(this));
|
||||||
pskl.app.shortcutService.addShortcut('ctrl+X', this.cut.bind(this));
|
pskl.app.shortcutService.addShortcut('ctrl+X', this.cut.bind(this));
|
||||||
pskl.app.shortcutService.addShortcut('ctrl+C', this.copy.bind(this));
|
pskl.app.shortcutService.addShortcut('ctrl+C', this.copy.bind(this));
|
||||||
|
pskl.app.shortcutService.addShortcut('del', this.erase.bind(this));
|
||||||
|
|
||||||
$.subscribe(Events.TOOL_SELECTED, $.proxy(this.onToolSelected_, this));
|
$.subscribe(Events.TOOL_SELECTED, $.proxy(this.onToolSelected_, this));
|
||||||
};
|
};
|
||||||
@ -46,11 +47,7 @@
|
|||||||
this.cleanSelection_();
|
this.cleanSelection_();
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.SelectionManager.prototype.cut = function() {
|
ns.SelectionManager.prototype.erase = function () {
|
||||||
if(this.currentSelection) {
|
|
||||||
// Put cut target into the selection:
|
|
||||||
this.currentSelection.fillSelectionFromFrame(this.piskelController.getCurrentFrame());
|
|
||||||
|
|
||||||
var pixels = this.currentSelection.pixels;
|
var pixels = this.currentSelection.pixels;
|
||||||
var currentFrame = this.piskelController.getCurrentFrame();
|
var currentFrame = this.piskelController.getCurrentFrame();
|
||||||
for(var i=0, l=pixels.length; i<l; i++) {
|
for(var i=0, l=pixels.length; i<l; i++) {
|
||||||
@ -60,6 +57,13 @@
|
|||||||
// Catching out of frame's bound pixels without testing
|
// Catching out of frame's bound pixels without testing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.SelectionManager.prototype.cut = function() {
|
||||||
|
if(this.currentSelection) {
|
||||||
|
// Put cut target into the selection:
|
||||||
|
this.currentSelection.fillSelectionFromFrame(this.piskelController.getCurrentFrame());
|
||||||
|
this.erase();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw "Bad state for CUT callback in SelectionManager";
|
throw "Bad state for CUT callback in SelectionManager";
|
||||||
|
@ -47,58 +47,70 @@
|
|||||||
ns.CheatsheetService.prototype.initMarkup_ = function () {
|
ns.CheatsheetService.prototype.initMarkup_ = function () {
|
||||||
this.initMarkupForTools_();
|
this.initMarkupForTools_();
|
||||||
this.initMarkupForMisc_();
|
this.initMarkupForMisc_();
|
||||||
|
this.initMarkupForSelection_();
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.CheatsheetService.prototype.toDescriptor_ = function (shortcut, description, icon) {
|
||||||
|
return {
|
||||||
|
'shortcut' : shortcut,
|
||||||
|
'description' : description,
|
||||||
|
'icon' : icon
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.CheatsheetService.prototype.getDomFromDescriptor_ = function (descriptor) {
|
||||||
|
var shortcutTemplate = pskl.utils.Template.get('cheatsheet-shortcut-template');
|
||||||
|
var markup = pskl.utils.Template.replace(shortcutTemplate, {
|
||||||
|
shortcutIcon : descriptor.icon,
|
||||||
|
shortcutDescription : descriptor.description,
|
||||||
|
shortcutKey : descriptor.shortcut
|
||||||
|
});
|
||||||
|
|
||||||
|
return pskl.utils.Template.createFromHTML(markup);
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.CheatsheetService.prototype.initMarkupAbstract_ = function (descriptors, containerSelector) {
|
||||||
|
var container = $(containerSelector, this.cheatsheetEl_).get(0);
|
||||||
|
for (var i = 0 ; i < descriptors.length ; i++) {
|
||||||
|
var descriptor = descriptors[i];
|
||||||
|
var shortcutEl = this.getDomFromDescriptor_(descriptor);
|
||||||
|
container.appendChild(shortcutEl);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.CheatsheetService.prototype.initMarkupForTools_ = function () {
|
ns.CheatsheetService.prototype.initMarkupForTools_ = function () {
|
||||||
var shortcutTemplate = pskl.utils.Template.get('cheatsheet-shortcut-template');
|
var descriptors = pskl.app.toolController.tools.map(function (tool) {
|
||||||
|
return this.toDescriptor_(tool.shortcut, tool.instance.helpText, 'tool-icon ' + tool.instance.toolId);
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
var toolShortcutsContainer = $('.cheatsheet-tool-shortcuts', this.cheatsheetEl_).get(0);
|
this.initMarkupAbstract_(descriptors, '.cheatsheet-tool-shortcuts');
|
||||||
var tools = pskl.app.toolController.tools;
|
|
||||||
for (var i = 0 ; i < tools.length ; i++) {
|
|
||||||
var tool = tools[i];
|
|
||||||
var shortcutEl = pskl.utils.Template.createFromHTML(
|
|
||||||
pskl.utils.Template.replace(shortcutTemplate, {
|
|
||||||
shortcutIcon : 'tool-icon ' + tool.instance.toolId,
|
|
||||||
shortcutDescription : tool.instance.helpText,
|
|
||||||
shortcutKey : tool.shortcut
|
|
||||||
})
|
|
||||||
);
|
|
||||||
toolShortcutsContainer.appendChild(shortcutEl);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.CheatsheetService.prototype.initMarkupForMisc_ = function () {
|
ns.CheatsheetService.prototype.initMarkupForMisc_ = function () {
|
||||||
var shortcutTemplate = pskl.utils.Template.get('cheatsheet-shortcut-template');
|
var descriptors = [
|
||||||
|
this.toDescriptor_('X', 'Swap primary/secondary colors'),
|
||||||
var miscShortcutsContainer = $('.cheatsheet-misc-shortcuts', this.cheatsheetEl_).get(0);
|
this.toDescriptor_('D', 'Reset default colors'),
|
||||||
var toDescriptor = function (shortcut, description) {
|
this.toDescriptor_('ctrl + Z', 'Undo'),
|
||||||
return {shortcut:shortcut, description:description};
|
this.toDescriptor_('ctrl + Y', 'Redo'),
|
||||||
};
|
this.toDescriptor_('↑', 'Select previous frame'), /* ASCII for up-arrow */
|
||||||
var miscKeys = [
|
this.toDescriptor_('↓', 'Select next frame'), /* ASCII for down-arrow */
|
||||||
toDescriptor('X', 'Swap primary/secondary colors'),
|
this.toDescriptor_('N', 'Create new frame'),
|
||||||
toDescriptor('D', 'Reset default colors'),
|
this.toDescriptor_('shift + N', 'Duplicate selected frame'),
|
||||||
toDescriptor('ctrl + X', 'Cut selection'),
|
this.toDescriptor_('shift + ?', 'Open/Close this popup')
|
||||||
toDescriptor('ctrl + C', 'Copy selection'),
|
|
||||||
toDescriptor('ctrl + V', 'Paste selection'),
|
|
||||||
toDescriptor('ctrl + Z', 'Undo'),
|
|
||||||
toDescriptor('ctrl + Y', 'Redo'),
|
|
||||||
toDescriptor('↑', 'Select previous frame'), /* ASCII for up-arrow */
|
|
||||||
toDescriptor('↓', 'Select next frame'), /* ASCII for down-arrow */
|
|
||||||
toDescriptor('N', 'Create new frame'),
|
|
||||||
toDescriptor('shift + N', 'Duplicate selected frame'),
|
|
||||||
toDescriptor('shift + ?', 'Open/Close this popup')
|
|
||||||
];
|
];
|
||||||
for (var i = 0 ; i < miscKeys.length ; i++) {
|
|
||||||
var key = miscKeys[i];
|
this.initMarkupAbstract_(descriptors, '.cheatsheet-misc-shortcuts');
|
||||||
var shortcutEl = pskl.utils.Template.createFromHTML(
|
};
|
||||||
pskl.utils.Template.replace(shortcutTemplate, {
|
|
||||||
shortcutIcon : '',
|
ns.CheatsheetService.prototype.initMarkupForSelection_ = function () {
|
||||||
shortcutDescription : key.description,
|
var descriptors = [
|
||||||
shortcutKey : key.shortcut
|
this.toDescriptor_('ctrl + X', 'Cut selection'),
|
||||||
})
|
this.toDescriptor_('ctrl + C', 'Copy selection'),
|
||||||
);
|
this.toDescriptor_('ctrl + V', 'Paste selection'),
|
||||||
miscShortcutsContainer.appendChild(shortcutEl);
|
this.toDescriptor_('del', 'Delete selection')
|
||||||
}
|
];
|
||||||
|
|
||||||
|
this.initMarkupAbstract_(descriptors, '.cheatsheet-selection-shortcuts');
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
191 : "?",
|
191 : "?",
|
||||||
27 : "esc",
|
27 : "esc",
|
||||||
38 : "up",
|
38 : "up",
|
||||||
40 : "down"
|
40 : "down",
|
||||||
|
46 : "del"
|
||||||
};
|
};
|
||||||
|
|
||||||
var ns = $.namespace('pskl.service.keyboard');
|
var ns = $.namespace('pskl.service.keyboard');
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
<h3>Misc shortcuts</h3>
|
<h3>Misc shortcuts</h3>
|
||||||
<ul class="cheatsheet-misc-shortcuts"></ul>
|
<ul class="cheatsheet-misc-shortcuts"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="cheatsheet-section">
|
||||||
|
<h3>Selection shortcuts</h3>
|
||||||
|
<ul class="cheatsheet-selection-shortcuts"></ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/template" id="cheatsheet-shortcut-template">
|
<script type="text/template" id="cheatsheet-shortcut-template">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user