Refactoring tooltip code + display CMD on mac

This commit is contained in:
jdescottes
2014-07-10 01:32:16 +02:00
parent a6d70920e2
commit 982a5ab048
11 changed files with 38 additions and 16 deletions

View File

@@ -192,7 +192,7 @@ module.exports = function(grunt) {
{src: ['src/js/lib/iframeLoader-0.1.0.js'], dest: 'dest/js/lib/iframeLoader-0.1.0.js'}, {src: ['src/js/lib/iframeLoader-0.1.0.js'], dest: 'dest/js/lib/iframeLoader-0.1.0.js'},
{expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'}, {expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'},
{expand: true, src: ['css/fonts/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'}, {expand: true, src: ['css/fonts/**'], cwd: 'src/', dest: 'dest/', filter: 'isFile'},
{expand: true, src: ['**/*.html'], cwd: 'src/templates/', dest: 'dest/templates' + version + '/', filter: 'isFile'} {expand: true, src: ['**/*.html'], cwd: 'src/templates/', dest: 'dest/templates/', filter: 'isFile'}
] ]
} }
}, },

View File

@@ -10,7 +10,7 @@
toDescriptor('simplePen', 'P', new pskl.drawingtools.SimplePen()), toDescriptor('simplePen', 'P', new pskl.drawingtools.SimplePen()),
toDescriptor('verticalMirrorPen', 'V', new pskl.drawingtools.VerticalMirrorPen()), toDescriptor('verticalMirrorPen', 'V', new pskl.drawingtools.VerticalMirrorPen()),
toDescriptor('paintBucket', 'B', new pskl.drawingtools.PaintBucket()), toDescriptor('paintBucket', 'B', new pskl.drawingtools.PaintBucket()),
toDescriptor('colorSwap', 'F', new pskl.drawingtools.ColorSwap()), toDescriptor('colorSwap', 'A', new pskl.drawingtools.ColorSwap()),
toDescriptor('eraser', 'E', new pskl.drawingtools.Eraser()), toDescriptor('eraser', 'E', new pskl.drawingtools.Eraser()),
toDescriptor('stroke', 'L', new pskl.drawingtools.Stroke()), toDescriptor('stroke', 'L', new pskl.drawingtools.Stroke()),
toDescriptor('rectangle', 'R', new pskl.drawingtools.Rectangle()), toDescriptor('rectangle', 'R', new pskl.drawingtools.Rectangle()),

View File

@@ -58,6 +58,18 @@
}); });
}; };
ns.BaseTool.prototype.getShortHelpText = function() {
return this.shortHelpText || this.helpText;
};
ns.BaseTool.prototype.getModifierHelpText = function(modifier, helptext) {
var tpl = "<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>{{modifier}}</span>{{helptext}}</span><br/>";
modifier = modifier.toUpperCase();
if (pskl.utils.UserAgent.isMac) {
modifier = modifier.replace('CTRL', 'CMD');
}
return pskl.utils.Template.replace(tpl, {modifier : modifier, helptext : helptext});
};
ns.BaseTool.prototype.releaseToolAt = function(col, row, color, frame, overlay, event) {}; ns.BaseTool.prototype.releaseToolAt = function(col, row, color, frame, overlay, event) {};

View File

@@ -11,10 +11,11 @@
this.toolId = "tool-circle"; this.toolId = "tool-circle";
this.shortHelpText = "Circle tool";
this.helpText = [ this.helpText = [
"<div class='tools-tooltip-container'>", "<div class='tools-tooltip-container'>",
"Circle tool {{shortcut}}<br/>", "Circle tool {{shortcut}}<br/>",
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>SHIFT</span>Keep 1 to 1 ratio</span><br/>", this.getModifierHelpText('shift', 'Keep 1 to 1 ratio'),
"</div>" "</div>"
].join(""); ].join("");
}; };

View File

@@ -7,11 +7,13 @@
ns.ColorSwap = function() { ns.ColorSwap = function() {
this.toolId = "tool-colorswap"; this.toolId = "tool-colorswap";
this.shortHelpText = "Paint all";
this.helpText = [ this.helpText = [
"<div class='tools-tooltip-container'>", "<div class='tools-tooltip-container'>",
"Paint all pixels of the same color {{shortcut}}<br/>", "Paint all pixels of the same color {{shortcut}}<br/>",
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>CTRL</span>Apply to all layers</span><br/>", this.getModifierHelpText('ctrl', 'Apply to all layers'),
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>SHIFT</span>Apply to all frames</span><br/>", this.getModifierHelpText('shift', 'Apply to all frames'),
"</div>" "</div>"
].join(""); ].join("");
}; };

View File

@@ -12,11 +12,12 @@
this.superclass.constructor.call(this); this.superclass.constructor.call(this);
this.toolId = "tool-lighten"; this.toolId = "tool-lighten";
this.shortHelpText = "Lighten / Darken";
this.helpText = [ this.helpText = [
"<div class='tools-tooltip-container'>", "<div class='tools-tooltip-container'>",
"Lighten {{shortcut}}<br/>", "Lighten {{shortcut}}<br/>",
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>CTRL</span>Darken</span><br/>", this.getModifierHelpText('ctrl', 'Darken'),
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>SHIFT</span>Apply only once per pixel</span><br/>", this.getModifierHelpText('shift', 'Apply only once per pixel'),
"</div>" "</div>"
].join(""); ].join("");

View File

@@ -11,10 +11,11 @@
this.toolId = "tool-rectangle"; this.toolId = "tool-rectangle";
this.shortHelpText = "Rectangle tool";
this.helpText = [ this.helpText = [
"<div class='tools-tooltip-container'>", "<div class='tools-tooltip-container'>",
"Rectangle tool {{shortcut}}<br/>", "Rectangle tool {{shortcut}}<br/>",
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>SHIFT</span>Keep 1 to 1 ratio</span><br/>", this.getModifierHelpText('shift', 'Keep 1 to 1 ratio'),
"</div>" "</div>"
].join(""); ].join("");
}; };

View File

@@ -5,13 +5,13 @@
this.superclass.constructor.call(this); this.superclass.constructor.call(this);
this.toolId = "tool-vertical-mirror-pen"; this.toolId = "tool-vertical-mirror-pen";
this.helpText = "Vertical Mirror pen (CTRL for Horizontal, SHIFT for both)"; this.shortHelpText = "Vertical Mirror pen";
this.helpText = [ this.helpText = [
"<div class='tools-tooltip-container'>", "<div class='tools-tooltip-container'>",
"Vertical Mirror pen {{shortcut}}<br/>", "Vertical Mirror pen {{shortcut}}<br/>",
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>CTRL</span>Use horizontal axis</span><br/>", this.getModifierHelpText('ctrl', 'Use horizontal axis'),
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>SHIFT</span>Use horizontal and vertical axis</span><br/>", this.getModifierHelpText('shift', 'Use horizontal and vertical axis'),
"</div>" "</div>"
].join(""); ].join("");
}; };

View File

@@ -9,12 +9,13 @@
ns.RectangleSelect = function() { ns.RectangleSelect = function() {
this.toolId = "tool-rectangle-select"; this.toolId = "tool-rectangle-select";
this.shortHelpText = "Rectangle selection";
this.helpText = [ this.helpText = [
"<div class='tools-tooltip-container'>", "<div class='tools-tooltip-container'>",
"Rectangle selection {{shortcut}}<br/>", "Rectangle selection {{shortcut}}<br/>",
"<span class='tools-tooltip-modifier'>Drag the selection to move it. You may switch to other layers and frames.</span><br/>", "<span class='tools-tooltip-modifier'>Drag the selection to move it. You may switch to other layers and frames.</span><br/>",
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>CTRL+C</span>Copy the selected area</span><br/>", this.getModifierHelpText('ctrl+c', 'Copy the selected area'),
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>CTRL+V</span>Paste the copied area</span><br/>", this.getModifierHelpText('ctrl+v', 'Paste the copied area'),
"</div>" "</div>"
].join(""); ].join("");

View File

@@ -9,12 +9,13 @@
ns.ShapeSelect = function() { ns.ShapeSelect = function() {
this.toolId = "tool-shape-select"; this.toolId = "tool-shape-select";
this.shortHelpText = "Shape selection";
this.helpText = [ this.helpText = [
"<div class='tools-tooltip-container'>", "<div class='tools-tooltip-container'>",
"Shape selection {{shortcut}}<br/>", "Shape selection {{shortcut}}<br/>",
"<span class='tools-tooltip-modifier'>Drag the selection to move it. You may switch to other layers and frames.</span><br/>", "<span class='tools-tooltip-modifier'>Drag the selection to move it. You may switch to other layers and frames.</span><br/>",
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>CTRL+C</span>Copy the selected area</span><br/>", this.getModifierHelpText('ctrl+c', 'Copy the selected area'),
"<span class='tools-tooltip-modifier'><span class='tools-tooltip-modifier-button'>CTRL+V</span>Paste the copied area</span><br/>", this.getModifierHelpText('ctrl+v', 'Paste the copied area'),
"</div>" "</div>"
].join(""); ].join("");

View File

@@ -55,6 +55,9 @@
}; };
ns.CheatsheetService.prototype.toDescriptor_ = function (shortcut, description, icon) { ns.CheatsheetService.prototype.toDescriptor_ = function (shortcut, description, icon) {
if (pskl.utils.UserAgent.isMac) {
shortcut = shortcut.replace('ctrl', 'cmd');
}
return { return {
'shortcut' : shortcut, 'shortcut' : shortcut,
'description' : description, 'description' : description,
@@ -84,7 +87,7 @@
ns.CheatsheetService.prototype.initMarkupForTools_ = function () { ns.CheatsheetService.prototype.initMarkupForTools_ = function () {
var descriptors = pskl.app.toolController.tools.map(function (tool) { var descriptors = pskl.app.toolController.tools.map(function (tool) {
return this.toDescriptor_(tool.shortcut, tool.instance.helpText, 'tool-icon ' + tool.instance.toolId); return this.toDescriptor_(tool.shortcut, tool.instance.getShortHelpText(), 'tool-icon ' + tool.instance.toolId);
}.bind(this)); }.bind(this));
this.initMarkupAbstract_(descriptors, '.cheatsheet-tool-shortcuts'); this.initMarkupAbstract_(descriptors, '.cheatsheet-tool-shortcuts');