mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Fix : Zoom level : reduce zoom step on mac os + added keyboard shortcuts
This commit is contained in:
parent
c98d25ab66
commit
a3108225f6
@ -1,5 +1,9 @@
|
|||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
var ns = $.namespace("pskl.controller");
|
var ns = $.namespace("pskl.controller");
|
||||||
|
|
||||||
|
var MAC_TOUCHPAD_SKIP = 8;
|
||||||
|
|
||||||
ns.DrawingController = function (piskelController, paletteController, container) {
|
ns.DrawingController = function (piskelController, paletteController, container) {
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
@ -43,6 +47,8 @@
|
|||||||
this.previousMousemoveTime = 0;
|
this.previousMousemoveTime = 0;
|
||||||
this.currentToolBehavior = null;
|
this.currentToolBehavior = null;
|
||||||
|
|
||||||
|
this.skipMouseWheelCounter_ = 0;
|
||||||
|
|
||||||
// State of clicked button (need to be stateful here, see comment in getCurrentColor_)
|
// State of clicked button (need to be stateful here, see comment in getCurrentColor_)
|
||||||
this.currentMouseButton_ = Constants.LEFT_BUTTON;
|
this.currentMouseButton_ = Constants.LEFT_BUTTON;
|
||||||
};
|
};
|
||||||
@ -60,6 +66,10 @@
|
|||||||
$.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this));
|
$.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this));
|
||||||
$.subscribe(Events.FRAME_SIZE_CHANGED, $.proxy(this.onFrameSizeChanged_, this));
|
$.subscribe(Events.FRAME_SIZE_CHANGED, $.proxy(this.onFrameSizeChanged_, this));
|
||||||
|
|
||||||
|
pskl.app.shortcutService.addShortcut('0', this.resetZoom_.bind(this));
|
||||||
|
pskl.app.shortcutService.addShortcut('+', this.increaseZoom_.bind(this));
|
||||||
|
pskl.app.shortcutService.addShortcut('-', this.decreaseZoom_.bind(this));
|
||||||
|
|
||||||
window.setTimeout(this.afterWindowResize_.bind(this), 100);
|
window.setTimeout(this.afterWindowResize_.bind(this), 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -179,20 +189,43 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.DrawingController.prototype.resetZoom_ = function () {
|
||||||
|
this.setZoom_(this.calculateZoom_());
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.DrawingController.prototype.increaseZoom_ = function () {
|
||||||
|
this.setZoom_(this.renderer.getZoom() + this.getZoomStep_());
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.DrawingController.prototype.decreaseZoom_ = function () {
|
||||||
|
this.setZoom_(this.renderer.getZoom() - this.getZoomStep_());
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.DrawingController.prototype.getZoomStep_ = function () {
|
||||||
|
return this.calculateZoom_() / 10;
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.DrawingController.prototype.setZoom_ = function (zoom) {
|
||||||
|
this.compositeRenderer.setZoom(zoom);
|
||||||
|
$.publish(Events.ZOOM_CHANGED);
|
||||||
|
};
|
||||||
|
|
||||||
ns.DrawingController.prototype.onMousewheel_ = function (jQueryEvent) {
|
ns.DrawingController.prototype.onMousewheel_ = function (jQueryEvent) {
|
||||||
var event = jQueryEvent.originalEvent;
|
var event = jQueryEvent.originalEvent;
|
||||||
var delta = event.wheelDeltaY || (-2 * event.deltaY);
|
var delta = event.wheelDeltaY || (-2 * event.deltaY);
|
||||||
var currentZoom = this.renderer.getZoom();
|
|
||||||
|
|
||||||
var perfectZoom = this.calculateZoom_();
|
var isMacTouchpad = typeof event.webkitDirectionInvertedFromDevice === 'boolean';
|
||||||
var step = perfectZoom / 10;
|
if (isMacTouchpad) {
|
||||||
|
if ((++this.skipMouseWheelCounter_%MAC_TOUCHPAD_SKIP)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
this.compositeRenderer.setZoom(currentZoom + step);
|
this.increaseZoom_();
|
||||||
} else if (delta < 0) {
|
} else if (delta < 0) {
|
||||||
this.compositeRenderer.setZoom(currentZoom - step);
|
this.decreaseZoom_();
|
||||||
}
|
}
|
||||||
$.publish(Events.ZOOM_CHANGED);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,6 +92,8 @@
|
|||||||
|
|
||||||
ns.CheatsheetService.prototype.initMarkupForMisc_ = function () {
|
ns.CheatsheetService.prototype.initMarkupForMisc_ = function () {
|
||||||
var descriptors = [
|
var descriptors = [
|
||||||
|
this.toDescriptor_('0', 'Reset zoom level'),
|
||||||
|
this.toDescriptor_('+/-', 'Zoom in/Zoom out'),
|
||||||
this.toDescriptor_('X', 'Swap primary/secondary colors'),
|
this.toDescriptor_('X', 'Swap primary/secondary colors'),
|
||||||
this.toDescriptor_('D', 'Reset default colors'),
|
this.toDescriptor_('D', 'Reset default colors'),
|
||||||
this.toDescriptor_('ctrl + Z', 'Undo'),
|
this.toDescriptor_('ctrl + Z', 'Undo'),
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
27 : "esc",
|
27 : "esc",
|
||||||
38 : "up",
|
38 : "up",
|
||||||
40 : "down",
|
40 : "down",
|
||||||
46 : "del"
|
46 : "del",
|
||||||
|
189 : "-",
|
||||||
|
187 : "+"
|
||||||
};
|
};
|
||||||
|
|
||||||
var ns = $.namespace('pskl.service.keyboard');
|
var ns = $.namespace('pskl.service.keyboard');
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
ctrl : key.indexOf('ctrl+') != -1
|
ctrl : key.indexOf('ctrl+') != -1
|
||||||
});
|
});
|
||||||
|
|
||||||
var parts = key.split('+');
|
var parts = key.split(/\+(?!$)/);
|
||||||
key = parts[parts.length-1];
|
key = parts[parts.length-1];
|
||||||
return {meta : meta, key : key};
|
return {meta : meta, key : key};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user