mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Merge pull request #308 from juliandescottes/dithering
Introduce basic dithering tool
This commit is contained in:
@ -114,6 +114,12 @@
|
|||||||
background-size: 30px;
|
background-size: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tool-icon.tool-dithering {
|
||||||
|
background-image: url(../img/tools/dithering.png);
|
||||||
|
background-position: 8px 9px;
|
||||||
|
background-size: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tool cursors:
|
* Tool cursors:
|
||||||
*/
|
*/
|
||||||
@ -128,7 +134,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tool-pen .drawing-canvas-container:hover,
|
.tool-pen .drawing-canvas-container:hover,
|
||||||
.tool-lighten .drawing-canvas-container:hover {
|
.tool-lighten .drawing-canvas-container:hover,
|
||||||
|
.tool-dithering .drawing-canvas-container:hover {
|
||||||
cursor: url(../img/icons/pen.png) 0 15, pointer;
|
cursor: url(../img/icons/pen.png) 0 15, pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
src/img/tools/dithering.png
Normal file
BIN
src/img/tools/dithering.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 642 B |
@ -38,6 +38,9 @@
|
|||||||
this.paletteService = new pskl.service.palette.PaletteService();
|
this.paletteService = new pskl.service.palette.PaletteService();
|
||||||
this.paletteService.addDynamicPalette(new pskl.service.palette.CurrentColorsPalette());
|
this.paletteService.addDynamicPalette(new pskl.service.palette.CurrentColorsPalette());
|
||||||
|
|
||||||
|
this.selectedColorsService = new pskl.service.SelectedColorsService();
|
||||||
|
this.selectedColorsService.init();
|
||||||
|
|
||||||
this.paletteController = new pskl.controller.PaletteController();
|
this.paletteController = new pskl.controller.PaletteController();
|
||||||
this.paletteController.init();
|
this.paletteController.init();
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
var ns = $.namespace('pskl.controller');
|
var ns = $.namespace('pskl.controller');
|
||||||
|
|
||||||
ns.PaletteController = function () {
|
ns.PaletteController = function () {
|
||||||
|
// TODO(grosbouddha): Reuse default colors from SelectedColorsService.
|
||||||
this.primaryColor = Constants.DEFAULT_PEN_COLOR;
|
this.primaryColor = Constants.DEFAULT_PEN_COLOR;
|
||||||
this.secondaryColor = Constants.TRANSPARENT_COLOR;
|
this.secondaryColor = Constants.TRANSPARENT_COLOR;
|
||||||
};
|
};
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
toDescriptor('rectangleSelect', 'S', new pskl.tools.drawing.RectangleSelect()),
|
toDescriptor('rectangleSelect', 'S', new pskl.tools.drawing.RectangleSelect()),
|
||||||
toDescriptor('shapeSelect', 'Z', new pskl.tools.drawing.ShapeSelect()),
|
toDescriptor('shapeSelect', 'Z', new pskl.tools.drawing.ShapeSelect()),
|
||||||
toDescriptor('lighten', 'U', new pskl.tools.drawing.Lighten()),
|
toDescriptor('lighten', 'U', new pskl.tools.drawing.Lighten()),
|
||||||
|
toDescriptor('dithering', 'T', new pskl.tools.drawing.DitheringTool()),
|
||||||
toDescriptor('colorPicker', 'O', new pskl.tools.drawing.ColorPicker())
|
toDescriptor('colorPicker', 'O', new pskl.tools.drawing.ColorPicker())
|
||||||
];
|
];
|
||||||
|
|
||||||
|
28
src/js/service/SelectedColorsService.js
Normal file
28
src/js/service/SelectedColorsService.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
(function () {
|
||||||
|
var ns = $.namespace('pskl.service');
|
||||||
|
|
||||||
|
ns.SelectedColorsService = function () {
|
||||||
|
this.primaryColor_ = Constants.DEFAULT_PEN_COLOR;
|
||||||
|
this.secondaryColor_ = Constants.TRANSPARENT_COLOR;
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.SelectedColorsService.prototype.init = function () {
|
||||||
|
$.subscribe(Events.PRIMARY_COLOR_SELECTED, this.onPrimaryColorUpdate_.bind(this));
|
||||||
|
$.subscribe(Events.SECONDARY_COLOR_SELECTED, this.onSecondaryColorUpdate_.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.SelectedColorsService.prototype.getColors = function () {
|
||||||
|
if (this.primaryColor_ === null || this.secondaryColor_ === null) {
|
||||||
|
throw 'SelectedColorsService not properly initialized.';
|
||||||
|
}
|
||||||
|
return [this.primaryColor_, this.secondaryColor_];
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.SelectedColorsService.prototype.onPrimaryColorUpdate_ = function (evt, color) {
|
||||||
|
this.primaryColor_ = color;
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.SelectedColorsService.prototype.onSecondaryColorUpdate_ = function (evt, color) {
|
||||||
|
this.secondaryColor_ = color;
|
||||||
|
};
|
||||||
|
})();
|
36
src/js/tools/drawing/DitheringTool.js
Normal file
36
src/js/tools/drawing/DitheringTool.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* @provide pskl.tools.drawing.DitheringTool
|
||||||
|
*
|
||||||
|
* @require pskl.utils
|
||||||
|
*/
|
||||||
|
(function() {
|
||||||
|
var ns = $.namespace('pskl.tools.drawing');
|
||||||
|
|
||||||
|
ns.DitheringTool = function() {
|
||||||
|
ns.SimplePen.call(this);
|
||||||
|
this.toolId = 'tool-dithering';
|
||||||
|
this.helpText = 'Dithering tool';
|
||||||
|
};
|
||||||
|
pskl.utils.inherit(ns.DitheringTool, ns.SimplePen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
ns.DitheringTool.prototype.applyToolAt = function(col, row, color, frame, overlay, event) {
|
||||||
|
// On Firefox/IE, the clicked button type is not part of the mousemove event.
|
||||||
|
// Ensure we record the pressed button on the initial mousedown only.
|
||||||
|
if (event.type == 'mousedown') {
|
||||||
|
this.invertColors_ = event.button === Constants.RIGHT_BUTTON;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use primary selected color on cell with either an odd col or row.
|
||||||
|
// Use secondary color otherwise.
|
||||||
|
// When using the right mouse button, invert the above behavior to allow quick corrections.
|
||||||
|
var usePrimaryColor = (col + row) % 2;
|
||||||
|
usePrimaryColor = this.invertColors_ ? !usePrimaryColor : usePrimaryColor;
|
||||||
|
|
||||||
|
var selectedColors = pskl.app.selectedColorsService.getColors();
|
||||||
|
var ditheringColor = usePrimaryColor ? selectedColors[0] : selectedColors[1];
|
||||||
|
this.superclass.applyToolAt.call(this, col, row, ditheringColor, frame, overlay, event);
|
||||||
|
};
|
||||||
|
})();
|
@ -161,6 +161,7 @@
|
|||||||
"js/service/ImageUploadService.js",
|
"js/service/ImageUploadService.js",
|
||||||
"js/service/CurrentColorsService.js",
|
"js/service/CurrentColorsService.js",
|
||||||
"js/service/FileDropperService.js",
|
"js/service/FileDropperService.js",
|
||||||
|
"js/service/SelectedColorsService.js",
|
||||||
|
|
||||||
// Tools
|
// Tools
|
||||||
"js/tools/ToolsHelper.js",
|
"js/tools/ToolsHelper.js",
|
||||||
@ -182,6 +183,7 @@
|
|||||||
"js/tools/drawing/selection/ShapeSelect.js",
|
"js/tools/drawing/selection/ShapeSelect.js",
|
||||||
"js/tools/drawing/ColorPicker.js",
|
"js/tools/drawing/ColorPicker.js",
|
||||||
"js/tools/drawing/ColorSwap.js",
|
"js/tools/drawing/ColorSwap.js",
|
||||||
|
"js/tools/drawing/DitheringTool.js",
|
||||||
"js/tools/transform/Transform.js",
|
"js/tools/transform/Transform.js",
|
||||||
"js/tools/transform/Clone.js",
|
"js/tools/transform/Clone.js",
|
||||||
"js/tools/transform/Flip.js",
|
"js/tools/transform/Flip.js",
|
||||||
|
Reference in New Issue
Block a user