11 Commits

15 changed files with 152 additions and 42 deletions

View File

@ -47,16 +47,13 @@ module.exports = function(grunt) {
var integrationTestPaths = require('./test/casperjs/integration/IntegrationSuite.js').tests; var integrationTestPaths = require('./test/casperjs/integration/IntegrationSuite.js').tests;
var integrationTests = prefixPaths(integrationTestPaths, "test/casperjs/integration/"); var integrationTests = prefixPaths(integrationTestPaths, "test/casperjs/integration/");
var getConnectConfig = function (base, port, host) { var getConnectConfig = function (base, port, host, open) {
if (typeof base === 'string') {
base = [base];
}
return { return {
options: { options: {
port: port, port: port,
hostname : host, hostname : host,
base: base base: base,
open: open
} }
}; };
}; };
@ -98,18 +95,9 @@ module.exports = function(grunt) {
*/ */
connect: { connect: {
prod: getConnectConfig('dest/prod', PORT.PROD, hostname), prod: getConnectConfig('dest/prod', PORT.PROD, hostname, true),
test: getConnectConfig(['dest/dev', 'test'], PORT.TEST, hostname), test: getConnectConfig(['dest/dev', 'test'], PORT.TEST, hostname, false),
dev: getConnectConfig(['dest/dev', 'test'], PORT.DEV, hostname) dev: getConnectConfig(['dest/dev', 'test'], PORT.DEV, hostname, 'http://' + hostname + ':' + PORT.DEV + '/?debug')
},
open : {
prod : {
path : 'http://' + hostname + ':' + PORT.PROD + '/'
},
dev : {
path : 'http://' + hostname + ':' + PORT.DEV + '/?debug'
}
}, },
watch: { watch: {
@ -343,9 +331,9 @@ module.exports = function(grunt) {
// SERVER TASKS // SERVER TASKS
// Start webserver and watch for changes // Start webserver and watch for changes
grunt.registerTask('serve', ['build', 'connect:prod', 'open:prod', 'watch:prod']); grunt.registerTask('serve', ['build', 'connect:prod', 'watch:prod']);
// Start webserver on src folder, in debug mode // Start webserver on src folder, in debug mode
grunt.registerTask('play', ['build-dev', 'connect:dev', 'open:dev', 'watch:dev']); grunt.registerTask('play', ['build-dev', 'connect:dev', 'watch:dev']);
// ALIASES, kept for backward compatibility // ALIASES, kept for backward compatibility
grunt.registerTask('serve-debug', ['play']); grunt.registerTask('serve-debug', ['play']);

View File

@ -1,6 +1,6 @@
{ {
"name": "piskel", "name": "piskel",
"version": "0.13.0", "version": "0.14.0",
"description": "Pixel art editor", "description": "Pixel art editor",
"author": "Julian Descottes <julian.descottes@gmail.com>", "author": "Julian Descottes <julian.descottes@gmail.com>",
"contributors": [ "contributors": [
@ -45,7 +45,6 @@
"grunt-karma": "1.0.0", "grunt-karma": "1.0.0",
"grunt-leading-indent": "0.2.0", "grunt-leading-indent": "0.2.0",
"grunt-nw-builder": "3.1.0", "grunt-nw-builder": "3.1.0",
"grunt-open": "0.2.3",
"grunt-replace": "1.0.1", "grunt-replace": "1.0.1",
"grunt-spritesmith": "6.4.0", "grunt-spritesmith": "6.4.0",
"jasmine-core": "2.6.1", "jasmine-core": "2.6.1",

View File

@ -80,10 +80,16 @@
} }
.cursor-coordinates { .cursor-coordinates {
color:#888; color: var(--highlight-color);
font-size:12px; font-size: 12px;
font-weight:bold; font-weight: bold;
font-family:monospace; font-family: monospace;
}
.cursor-coordinates .drawing-zoom {
position: absolute;
top: -20px;
left: 1px;
} }
/** /**

View File

@ -60,22 +60,48 @@
} }
.settings-item-grid-size, .settings-item-grid-size,
.settings-item-grid-spacing,
.settings-item-grid-color { .settings-item-grid-color {
display: flex; display: flex;
align-items: center; align-items: center;
} }
.settings-item-grid-size > label, .settings-item-grid-size > label,
.settings-item-grid-spacing > label,
.settings-item-grid-color > label { .settings-item-grid-color > label {
width: 65px; width: 65px;
flex-shrink: 0; flex-shrink: 0;
} }
.settings-item-grid-size .size-picker-option { .grid-spacing-container .size-picker-option[data-size='1'] {
padding: 7px;
}
.grid-spacing-container .size-picker-option[data-size='2'] {
padding: 6px;
}
.grid-spacing-container .size-picker-option[data-size='4'] {
padding: 5px;
}
.grid-spacing-container .size-picker-option[data-size='8'] {
padding: 4px;
}
.grid-spacing-container .size-picker-option[data-size='16'] {
padding: 3px;
}
.grid-spacing-container .size-picker-option[data-size='32'] {
padding: 2px;
}
.grid-spacing-container .size-picker-option[data-size='64'] {
padding: 1px;
}
.settings-item-grid-size .size-picker-option,
.settings-item-grid-spacing .size-picker-option {
border-color: #888; border-color: #888;
} }
.settings-item-grid-size .size-picker-option:not(.selected):hover { .settings-item-grid-size .size-picker-option:not(.selected):hover,
.settings-item-grid-spacing .size-picker-option:not(.selected):hover {
border-color: white; border-color: white;
} }
@ -131,4 +157,4 @@
.settings-version:hover { .settings-version:hover {
color: white !important; color: white !important;
text-decoration: none !important; text-decoration: none !important;
} }

View File

@ -17,6 +17,7 @@
$.subscribe(Events.DRAG_START, this.onDragStart_.bind(this)); $.subscribe(Events.DRAG_START, this.onDragStart_.bind(this));
$.subscribe(Events.DRAG_END, this.onDragEnd_.bind(this)); $.subscribe(Events.DRAG_END, this.onDragEnd_.bind(this));
$.subscribe(Events.FRAME_SIZE_CHANGED, this.redraw.bind(this)); $.subscribe(Events.FRAME_SIZE_CHANGED, this.redraw.bind(this));
$.subscribe(Events.ZOOM_CHANGED, this.redraw.bind(this));
this.redraw(); this.redraw();
}; };
@ -39,6 +40,11 @@
} }
} }
if (pskl.app.drawingController) {
var zoom = pskl.app.drawingController.compositeRenderer.getZoom().toFixed(2);
html += '<div class="drawing-zoom">x' + zoom + '</div>';
}
this.coordinatesContainer.innerHTML = this.getFrameSizeHTML_() + html; this.coordinatesContainer.innerHTML = this.getFrameSizeHTML_() + html;
}; };

View File

@ -113,7 +113,7 @@
width: width * zoom, width: width * zoom,
height: height * zoom, height: height * zoom,
preserveColors : preserveColors, preserveColors : preserveColors,
repeat: this.getRepeatSetting_() ? 0 : 1, repeat: this.getRepeatSetting_() ? 0 : -1,
transparent : transparent transparent : transparent
}); });

View File

@ -12,12 +12,25 @@
this.pngFilePrefixInput = document.querySelector('.zip-prefix-name'); this.pngFilePrefixInput = document.querySelector('.zip-prefix-name');
this.pngFilePrefixInput.value = 'sprite_'; this.pngFilePrefixInput.value = 'sprite_';
this.splitByLayersCheckbox = document.querySelector('.zip-split-layers-checkbox'); this.splitByLayersCheckbox = document.querySelector('.zip-split-layers-checkbox');
this.addEventListener(this.splitByLayersCheckbox, 'change', this.onSplitLayersClick_);
this.useLayerNamesContainer = document.querySelector('.use-layer-names-container');
this.useLayerNamesCheckbox = document.querySelector('.zip-use-layer-names-checkbox');
this.toggleHideUseLayerNamesCheckbox();
var zipButton = document.querySelector('.zip-generate-button'); var zipButton = document.querySelector('.zip-generate-button');
this.addEventListener(zipButton, 'click', this.onZipButtonClick_); this.addEventListener(zipButton, 'click', this.onZipButtonClick_);
}; };
ns.ZipExportController.prototype.toggleHideUseLayerNamesCheckbox = function () {
this.useLayerNamesContainer.style.display = (this.splitByLayersCheckbox.checked ? 'block' : 'none');
};
ns.ZipExportController.prototype.onSplitLayersClick_ = function () {
this.toggleHideUseLayerNamesCheckbox();
};
ns.ZipExportController.prototype.onZipButtonClick_ = function () { ns.ZipExportController.prototype.onZipButtonClick_ = function () {
var zip = new window.JSZip(); var zip = new window.JSZip();
@ -63,6 +76,9 @@
var basename = this.pngFilePrefixInput.value; var basename = this.pngFilePrefixInput.value;
var frameid = pskl.utils.StringUtils.leftPad(i + 1, framePaddingLength, '0'); var frameid = pskl.utils.StringUtils.leftPad(i + 1, framePaddingLength, '0');
var filename = 'l' + layerid + '_' + basename + frameid + '.png'; var filename = 'l' + layerid + '_' + basename + frameid + '.png';
if (this.useLayerNamesCheckbox.checked) {
filename = layer.getName() + '_' + basename + frameid + '.png';
}
zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true}); zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true});
} }
} }

View File

@ -22,6 +22,7 @@
this.piskelController = piskelController; this.piskelController = piskelController;
this.preferencesController = preferencesController; this.preferencesController = preferencesController;
this.sizePicker = new pskl.widgets.SizePicker(this.onSizePickerChanged_.bind(this)); this.sizePicker = new pskl.widgets.SizePicker(this.onSizePickerChanged_.bind(this));
this.spacingPicker = new pskl.widgets.SizePicker(this.onSpacingPickerChanged_.bind(this));
}; };
pskl.utils.inherit(ns.GridPreferencesController, pskl.controller.settings.AbstractSettingController); pskl.utils.inherit(ns.GridPreferencesController, pskl.controller.settings.AbstractSettingController);
@ -40,6 +41,11 @@
this.sizePicker.init(document.querySelector('.grid-size-container')); this.sizePicker.init(document.querySelector('.grid-size-container'));
this.sizePicker.setSize(gridWidth); this.sizePicker.setSize(gridWidth);
//Grid Spacing
var gridSpacing = pskl.UserSettings.get(pskl.UserSettings.GRID_SPACING);
this.spacingPicker.init(document.querySelector('.grid-spacing-container'));
this.spacingPicker.setSize(gridSpacing);
// Grid color // Grid color
var colorListItemTemplate = pskl.utils.Template.get('color-list-item-template'); var colorListItemTemplate = pskl.utils.Template.get('color-list-item-template');
@ -68,6 +74,7 @@
ns.GridPreferencesController.prototype.destroy = function () { ns.GridPreferencesController.prototype.destroy = function () {
this.sizePicker.destroy(); this.sizePicker.destroy();
this.spacingPicker.destroy();
this.superclass.destroy.call(this); this.superclass.destroy.call(this);
}; };
@ -75,6 +82,10 @@
pskl.UserSettings.set(pskl.UserSettings.GRID_WIDTH, size); pskl.UserSettings.set(pskl.UserSettings.GRID_WIDTH, size);
}; };
ns.GridPreferencesController.prototype.onSpacingPickerChanged_ = function (size) {
pskl.UserSettings.set(pskl.UserSettings.GRID_SPACING, size);
};
ns.GridPreferencesController.prototype.onEnableGridChange_ = function (evt) { ns.GridPreferencesController.prototype.onEnableGridChange_ = function (evt) {
pskl.UserSettings.set(pskl.UserSettings.GRID_ENABLED, evt.currentTarget.checked); pskl.UserSettings.set(pskl.UserSettings.GRID_ENABLED, evt.currentTarget.checked);
}; };

View File

@ -34,6 +34,7 @@
var serializedFrame = [ var serializedFrame = [
this.getZoom(), this.getZoom(),
this.getGridWidth(), this.getGridWidth(),
this.getGridSpacing(),
this.getGridColor(), this.getGridColor(),
pskl.UserSettings.get('SEAMLESS_MODE'), pskl.UserSettings.get('SEAMLESS_MODE'),
pskl.UserSettings.get('SEAMLESS_OPACITY'), pskl.UserSettings.get('SEAMLESS_OPACITY'),

View File

@ -56,6 +56,7 @@
this.setDisplaySize(renderingOptions.width, renderingOptions.height); this.setDisplaySize(renderingOptions.width, renderingOptions.height);
this.setGridWidth(this.getUserGridWidth_()); this.setGridWidth(this.getUserGridWidth_());
this.setGridSpacing(this.getUserGridSpacing_());
$.subscribe(Events.USER_SETTINGS_CHANGED, this.onUserSettingsChange_.bind(this)); $.subscribe(Events.USER_SETTINGS_CHANGED, this.onUserSettingsChange_.bind(this));
}; };
@ -146,6 +147,10 @@
this.gridWidth_ = value; this.gridWidth_ = value;
}; };
ns.FrameRenderer.prototype.setGridSpacing = function (value) {
this.gridSpacing_ = value;
};
ns.FrameRenderer.prototype.getGridWidth = function () { ns.FrameRenderer.prototype.getGridWidth = function () {
if (!this.supportGridRendering) { if (!this.supportGridRendering) {
return 0; return 0;
@ -154,15 +159,29 @@
return this.gridWidth_; return this.gridWidth_;
}; };
ns.FrameRenderer.prototype.getGridSpacing = function () {
if (!this.supportGridRendering) {
return 0;
}
return this.gridSpacing_;
};
/** /**
* Compute a grid width value best suited to the current display context, * Compute a grid width value best suited to the current display context,
* particularly for the current zoom level * particularly for the current zoom level
*/ */
ns.FrameRenderer.prototype.computeGridWidthForDisplay_ = function () { ns.FrameRenderer.prototype.computeGridWidthForDisplay_ = function () {
var gridSpacing = this.getGridSpacing();
if (this.zoom * gridSpacing < 6) {
return 0;
}
var gridWidth = this.getGridWidth(); var gridWidth = this.getGridWidth();
while (this.zoom < 6 * gridWidth) { while (gridWidth > 1 && this.zoom < 6 * gridWidth) {
gridWidth--; gridWidth--;
} }
return gridWidth; return gridWidth;
}; };
@ -185,8 +204,11 @@
ns.FrameRenderer.prototype.onUserSettingsChange_ = function (evt, settingName, settingValue) { ns.FrameRenderer.prototype.onUserSettingsChange_ = function (evt, settingName, settingValue) {
var settings = pskl.UserSettings; var settings = pskl.UserSettings;
if (settingName == settings.GRID_WIDTH || settingName == settings.GRID_ENABLED) { if (settingName == settings.GRID_WIDTH ||
settingName == settings.GRID_SPACING ||
settingName == settings.GRID_ENABLED) {
this.setGridWidth(this.getUserGridWidth_()); this.setGridWidth(this.getUserGridWidth_());
this.setGridSpacing(this.getUserGridSpacing_());
} }
}; };
@ -196,6 +218,12 @@
return gridEnabled ? width : 0; return gridEnabled ? width : 0;
}; };
ns.FrameRenderer.prototype.getUserGridSpacing_ = function () {
var gridEnabled = pskl.UserSettings.get(pskl.UserSettings.GRID_ENABLED);
var spacing = pskl.UserSettings.get(pskl.UserSettings.GRID_SPACING);
return gridEnabled ? spacing : 0;
};
/** /**
* Transform a screen pixel-based coordinate (relative to the top-left corner of the rendered * Transform a screen pixel-based coordinate (relative to the top-left corner of the rendered
* frame) into a sprite coordinate in column and row. * frame) into a sprite coordinate in column and row.
@ -298,6 +326,7 @@
// Draw grid. // Draw grid.
var gridWidth = this.computeGridWidthForDisplay_(); var gridWidth = this.computeGridWidthForDisplay_();
var gridSpacing = this.getGridSpacing();
if (gridWidth > 0) { if (gridWidth > 0) {
var gridColor = this.getGridColor(); var gridColor = this.getGridColor();
// Scale out before drawing the grid. // Scale out before drawing the grid.
@ -313,11 +342,15 @@
// Draw or clear vertical lines. // Draw or clear vertical lines.
for (var i = 1 ; i < frame.getWidth() ; i++) { for (var i = 1 ; i < frame.getWidth() ; i++) {
drawOrClear((i * z) - (gridWidth / 2), 0, gridWidth, h * z); if (i % gridSpacing == 0) {
drawOrClear((i * z) - (gridWidth / 2), 0, gridWidth, h * z);
}
} }
// Draw or clear horizontal lines. // Draw or clear horizontal lines.
for (var j = 1 ; j < frame.getHeight() ; j++) { for (var j = 1 ; j < frame.getHeight() ; j++) {
drawOrClear(0, (j * z) - (gridWidth / 2), w * z, gridWidth); if (j % gridSpacing == 0) {
drawOrClear(0, (j * z) - (gridWidth / 2), w * z, gridWidth);
}
} }
} }

View File

@ -5,6 +5,7 @@
GRID_COLOR : 'GRID_COLOR', GRID_COLOR : 'GRID_COLOR',
GRID_ENABLED : 'GRID_ENABLED', GRID_ENABLED : 'GRID_ENABLED',
GRID_WIDTH : 'GRID_WIDTH', GRID_WIDTH : 'GRID_WIDTH',
GRID_SPACING : 'GRID_SPACING',
MAX_FPS : 'MAX_FPS', MAX_FPS : 'MAX_FPS',
DEFAULT_SIZE : 'DEFAULT_SIZE', DEFAULT_SIZE : 'DEFAULT_SIZE',
CANVAS_BACKGROUND : 'CANVAS_BACKGROUND', CANVAS_BACKGROUND : 'CANVAS_BACKGROUND',
@ -27,6 +28,7 @@
'GRID_COLOR' : Constants.TRANSPARENT_COLOR, 'GRID_COLOR' : Constants.TRANSPARENT_COLOR,
'GRID_ENABLED' : false, 'GRID_ENABLED' : false,
'GRID_WIDTH' : 1, 'GRID_WIDTH' : 1,
'GRID_SPACING' : 1,
'MAX_FPS' : 24, 'MAX_FPS' : 24,
'DEFAULT_SIZE' : { 'DEFAULT_SIZE' : {
width : Constants.DEFAULT.WIDTH, width : Constants.DEFAULT.WIDTH,

View File

@ -27,10 +27,9 @@
pskl.utils.Dom.removeClass('labeled', this.container); pskl.utils.Dom.removeClass('labeled', this.container);
pskl.utils.Dom.removeClass('selected', this.container); pskl.utils.Dom.removeClass('selected', this.container);
var selectedOption; var selectedOption;
if (size <= 4) { selectedOption = this.container.querySelector('[data-size="' + size + '"]');
selectedOption = this.container.querySelector('[data-size="' + size + '"]'); if (typeof selectedOption === 'undefined') {
} else { selectedOption = this.container.querySelector('[data-size]:last-child');
selectedOption = this.container.querySelector('[data-size="4"]');
selectedOption.classList.add('labeled'); selectedOption.classList.add('labeled');
selectedOption.setAttribute('real-size', size); selectedOption.setAttribute('real-size', size);
} }

View File

@ -42,4 +42,4 @@
"css/widgets-size-picker.css", "css/widgets-size-picker.css",
"css/widgets-tabs.css", "css/widgets-tabs.css",
"css/widgets-wizard.css" "css/widgets-wizard.css"
]; ];

View File

@ -11,7 +11,11 @@
<input id="zip-split-layers" class="zip-split-layers-checkbox checkbox-fix" type="checkbox" /> <input id="zip-split-layers" class="zip-split-layers-checkbox checkbox-fix" type="checkbox" />
<label for="zip-split-layers">Split by layers</label> <label for="zip-split-layers">Split by layers</label>
</div> </div>
<div class="checkbox-container use-layer-names-container" style="margin: 5px 0;">
<input id="zip-use-layer-names" class="zip-use-layer-names-checkbox checkbox-fix" type="checkbox" />
<label for="zip-use-layer-names">Index by layer names</label>
</div>
<button type="button" class="button button-primary zip-generate-button"/>Download ZIP</button> <button type="button" class="button button-primary zip-generate-button"/>Download ZIP</button>
</div> </div>
</div> </div>
</script> </script>

View File

@ -19,6 +19,25 @@
title="4px" rel="tooltip" data-placement="top" data-size="4"></div> title="4px" rel="tooltip" data-placement="top" data-size="4"></div>
</div> </div>
</div> </div>
<div class="settings-item settings-item-grid-spacing">
<label>Grid spacing</label>
<div class="grid-spacing-container size-picker-container">
<div class="size-picker-option"
title="1px" rel="tooltip" data-placement="top" data-size="1"></div>
<div class="size-picker-option"
title="2px" rel="tooltip" data-placement="top" data-size="2"></div>
<div class="size-picker-option"
title="4px" rel="tooltip" data-placement="top" data-size="4"></div>
<div class="size-picker-option"
title="8px" rel="tooltip" data-placement="top" data-size="8"></div>
<div class="size-picker-option"
title="16px" rel="tooltip" data-placement="top" data-size="16"></div>
<div class="size-picker-option"
title="32px" rel="tooltip" data-placement="top" data-size="32"></div>
<div class="size-picker-option"
title="64px" rel="tooltip" data-placement="top" data-size="64"></div>
</div>
</div>
<div class="settings-item settings-item-grid-color"> <div class="settings-item settings-item-grid-color">
<label>Grid color</label> <label>Grid color</label>
<div class="grid-colors-list"></div> <div class="grid-colors-list"></div>
@ -31,4 +50,4 @@
</script> </script>
</div> </div>
</div> </div>
</script> </script>