This commit is contained in:
jdescottes 2014-03-30 20:58:00 +02:00
parent 13ea6514f8
commit 5c44830746
2 changed files with 33 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -16150,6 +16150,9 @@ if (typeof Function.prototype.bind !== "function") {
this.isClicked = false; this.isClicked = false;
this.previousMousemoveTime = 0; this.previousMousemoveTime = 0;
this.currentToolBehavior = null; this.currentToolBehavior = null;
// State of clicked button (need to be stateful here, see comment in getCurrentColor_)
this.currentMouseButton_ = Constants.LEFT_BUTTON;
}; };
ns.DrawingController.prototype.init = function () { ns.DrawingController.prototype.init = function () {
@ -16248,12 +16251,13 @@ if (typeof Function.prototype.bind !== "function") {
} }
} else { } else {
this.isClicked = true; this.isClicked = true;
this.setCurrentButton(event);
this.currentToolBehavior.hideHighlightedPixel(this.overlayFrame); this.currentToolBehavior.hideHighlightedPixel(this.overlayFrame);
this.currentToolBehavior.applyToolAt( this.currentToolBehavior.applyToolAt(
coords.x, coords.x,
coords.y, coords.y,
this.getCurrentColor_(event), this.getCurrentColor_(),
frame, frame,
this.overlayFrame, this.overlayFrame,
event event
@ -16274,7 +16278,8 @@ if (typeof Function.prototype.bind !== "function") {
var coords = this.renderer.getCoordinates(event.clientX, event.clientY); var coords = this.renderer.getCoordinates(event.clientX, event.clientY);
if (this.isClicked) { if (this.isClicked) {
// Warning : do not call setCurrentButton here
// mousemove do not have the correct mouse button information on all browsers
this.currentToolBehavior.moveToolAt( this.currentToolBehavior.moveToolAt(
coords.x, coords.x,
coords.y, coords.y,
@ -16330,12 +16335,13 @@ if (typeof Function.prototype.bind !== "function") {
// of the drawing canvas. // of the drawing canvas.
this.isClicked = false; this.isClicked = false;
this.setCurrentButton(event);
var coords = this.renderer.getCoordinates(event.clientX, event.clientY); var coords = this.renderer.getCoordinates(event.clientX, event.clientY);
this.currentToolBehavior.releaseToolAt( this.currentToolBehavior.releaseToolAt(
coords.x, coords.x,
coords.y, coords.y,
this.getCurrentColor_(event), this.getCurrentColor_(),
this.piskelController.getCurrentFrame(), this.piskelController.getCurrentFrame(),
this.overlayFrame, this.overlayFrame,
event event
@ -16352,13 +16358,23 @@ if (typeof Function.prototype.bind !== "function") {
return this.renderer.getCoordinates(event.clientX, event.clientY); return this.renderer.getCoordinates(event.clientX, event.clientY);
}; };
ns.DrawingController.prototype.setCurrentButton = function (event) {
this.currentMouseButton_ = event.button;
};
/** /**
* @private * @private
*/ */
ns.DrawingController.prototype.getCurrentColor_ = function (event) { ns.DrawingController.prototype.getCurrentColor_ = function () {
if(event.button == Constants.RIGHT_BUTTON) { // WARNING : Do not rely on the current event to get the current color!
// It might seem like a good idea, and works perfectly fine on Chrome
// Sadly Firefox and IE found clever, for some reason, to set event.button to 0
// on a mouse move event
// This always matches a LEFT mouse button which is __really__ not helpful
if(this.currentMouseButton_ == Constants.RIGHT_BUTTON) {
return this.paletteController.getSecondaryColor(); return this.paletteController.getSecondaryColor();
} else if(event.button == Constants.LEFT_BUTTON) { } else if(this.currentMouseButton_ == Constants.LEFT_BUTTON) {
return this.paletteController.getPrimaryColor(); return this.paletteController.getPrimaryColor();
} else { } else {
return Constants.DEFAULT_PEN_COLOR; return Constants.DEFAULT_PEN_COLOR;
@ -17264,7 +17280,14 @@ if (typeof Function.prototype.bind !== "function") {
ns.PalettesListController.prototype.onColorUpdated = function (type, event, color) { ns.PalettesListController.prototype.onColorUpdated = function (type, event, color) {
console.log('[PalettesListController] >>> ', arguments); console.log('[PalettesListController] >>> ', arguments);
var colorContainer = this.colorListContainer_.querySelector('.palettes-list-color[data-color="'+color+'"]'); var colorContainer = this.colorListContainer_.querySelector('.palettes-list-color[data-color="'+color+'"]');
// Color is not in the currently selected palette
if (!colorContainer) {
return;
}
if (type === 'primary') { if (type === 'primary') {
this.removeClass_('primary', '.palettes-list-color'); this.removeClass_('primary', '.palettes-list-color');
colorContainer.classList.add('primary'); colorContainer.classList.add('primary');