2012-09-04 16:10:16 +04:00
|
|
|
(function () {
|
2014-05-15 01:52:32 +04:00
|
|
|
|
2012-09-14 02:33:46 +04:00
|
|
|
var ns = $.namespace("pskl.controller");
|
2014-05-15 01:52:32 +04:00
|
|
|
|
2013-12-06 01:12:48 +04:00
|
|
|
ns.DrawingController = function (piskelController, paletteController, container) {
|
2012-09-14 02:33:46 +04:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2013-09-22 23:02:43 +04:00
|
|
|
this.piskelController = piskelController;
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2013-11-19 10:40:35 +04:00
|
|
|
this.paletteController = paletteController;
|
|
|
|
|
2014-11-23 23:37:34 +03:00
|
|
|
this.dragHandler = new ns.drawing.DragHandler(this);
|
|
|
|
|
2012-09-14 02:33:46 +04:00
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
*/
|
2013-09-22 23:02:43 +04:00
|
|
|
this.overlayFrame = pskl.model.Frame.createEmptyFromFrame(piskelController.getCurrentFrame());
|
2012-09-14 02:33:46 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.container = container;
|
2012-09-16 20:48:32 +04:00
|
|
|
|
|
|
|
var renderingOptions = {
|
2013-11-01 18:39:42 +04:00
|
|
|
"zoom": this.calculateZoom_(),
|
2013-10-30 01:16:39 +04:00
|
|
|
"supportGridRendering" : true,
|
|
|
|
"height" : this.getContainerHeight_(),
|
|
|
|
"width" : this.getContainerWidth_(),
|
2013-11-01 18:39:42 +04:00
|
|
|
"xOffset" : 0,
|
|
|
|
"yOffset" : 0
|
2012-09-16 20:48:32 +04:00
|
|
|
};
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2013-11-01 18:39:42 +04:00
|
|
|
this.overlayRenderer = new pskl.rendering.frame.CachedFrameRenderer(this.container, renderingOptions, ["canvas-overlay"]);
|
|
|
|
this.renderer = new pskl.rendering.frame.CachedFrameRenderer(this.container, renderingOptions, ["drawing-canvas"]);
|
2014-12-27 17:02:41 +03:00
|
|
|
this.onionSkinRenderer = pskl.rendering.OnionSkinRenderer.createInContainer(this.container, renderingOptions, piskelController);
|
2013-11-01 20:12:59 +04:00
|
|
|
this.layersRenderer = new pskl.rendering.layer.LayersRenderer(this.container, renderingOptions, piskelController);
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2013-11-01 20:12:59 +04:00
|
|
|
this.compositeRenderer = new pskl.rendering.CompositeRenderer();
|
|
|
|
this.compositeRenderer
|
2013-11-01 18:39:42 +04:00
|
|
|
.add(this.overlayRenderer)
|
|
|
|
.add(this.renderer)
|
2014-06-20 01:33:57 +04:00
|
|
|
.add(this.layersRenderer)
|
|
|
|
.add(this.onionSkinRenderer);
|
2012-09-14 02:33:46 +04:00
|
|
|
|
|
|
|
// State of drawing controller:
|
|
|
|
this.isClicked = false;
|
|
|
|
this.previousMousemoveTime = 0;
|
|
|
|
this.currentToolBehavior = null;
|
2014-03-30 22:39:00 +04:00
|
|
|
|
|
|
|
// State of clicked button (need to be stateful here, see comment in getCurrentColor_)
|
|
|
|
this.currentMouseButton_ = Constants.LEFT_BUTTON;
|
2013-08-06 01:34:11 +04:00
|
|
|
};
|
2012-09-14 02:33:46 +04:00
|
|
|
|
2013-08-06 01:34:11 +04:00
|
|
|
ns.DrawingController.prototype.init = function () {
|
2012-09-14 02:33:46 +04:00
|
|
|
this.initMouseBehavior();
|
|
|
|
|
|
|
|
$.subscribe(Events.TOOL_SELECTED, $.proxy(function(evt, toolBehavior) {
|
2012-09-11 01:26:12 +04:00
|
|
|
this.currentToolBehavior = toolBehavior;
|
2013-08-06 01:34:11 +04:00
|
|
|
this.overlayFrame.clear();
|
2012-09-11 01:26:12 +04:00
|
|
|
}, this));
|
2013-12-06 01:12:48 +04:00
|
|
|
|
2013-11-01 18:39:42 +04:00
|
|
|
$(window).resize($.proxy(this.startResizeTimer_, this));
|
2012-09-16 20:48:32 +04:00
|
|
|
|
2013-06-19 21:01:12 +04:00
|
|
|
$.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this));
|
2015-02-17 04:06:52 +03:00
|
|
|
$.subscribe(Events.FRAME_SIZE_CHANGED, $.proxy(this.onFrameSizeChange_, this));
|
2013-06-19 21:01:12 +04:00
|
|
|
|
2014-05-15 01:52:32 +04:00
|
|
|
pskl.app.shortcutService.addShortcut('0', this.resetZoom_.bind(this));
|
2014-05-18 19:32:20 +04:00
|
|
|
pskl.app.shortcutService.addShortcut('+', this.increaseZoom_.bind(this, 1));
|
|
|
|
pskl.app.shortcutService.addShortcut('-', this.decreaseZoom_.bind(this, 1));
|
2014-05-15 01:52:32 +04:00
|
|
|
|
2014-12-18 23:42:03 +03:00
|
|
|
window.setTimeout(function () {
|
|
|
|
this.afterWindowResize_();
|
|
|
|
this.resetZoom_();
|
|
|
|
}.bind(this), 100);
|
2012-09-14 02:33:46 +04:00
|
|
|
};
|
2012-09-08 17:08:00 +04:00
|
|
|
|
2012-09-14 02:33:46 +04:00
|
|
|
ns.DrawingController.prototype.initMouseBehavior = function() {
|
|
|
|
var body = $('body');
|
2013-08-10 14:11:16 +04:00
|
|
|
this.container.mousedown($.proxy(this.onMousedown_, this));
|
2013-11-15 03:32:18 +04:00
|
|
|
|
2015-01-24 02:00:08 +03:00
|
|
|
if (pskl.utils.UserAgent.isChrome || pskl.utils.UserAgent.isIE11) {
|
2013-11-15 03:32:18 +04:00
|
|
|
this.container.on('mousewheel', $.proxy(this.onMousewheel_, this));
|
|
|
|
} else {
|
|
|
|
this.container.on('wheel', $.proxy(this.onMousewheel_, this));
|
|
|
|
}
|
2013-10-30 01:16:39 +04:00
|
|
|
|
2014-04-03 00:37:01 +04:00
|
|
|
window.addEventListener('mouseup', this.onMouseup_.bind(this));
|
|
|
|
window.addEventListener('mousemove', this.onMousemove_.bind(this));
|
2014-05-17 00:36:23 +04:00
|
|
|
window.addEventListener('keyup', this.onKeyup_.bind(this));
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
// Deactivate right click:
|
|
|
|
body.contextmenu(this.onCanvasContextMenu_);
|
2014-12-18 23:42:03 +03:00
|
|
|
|
2012-09-14 02:33:46 +04:00
|
|
|
};
|
2012-09-08 20:44:06 +04:00
|
|
|
|
2013-11-01 18:39:42 +04:00
|
|
|
ns.DrawingController.prototype.startResizeTimer_ = function () {
|
|
|
|
if (this.resizeTimer) {
|
|
|
|
window.clearInterval(this.resizeTimer);
|
2013-08-10 14:11:16 +04:00
|
|
|
}
|
2013-11-01 18:39:42 +04:00
|
|
|
this.resizeTimer = window.setTimeout($.proxy(this.afterWindowResize_, this), 200);
|
2013-12-19 02:37:17 +04:00
|
|
|
};
|
2013-11-01 18:39:42 +04:00
|
|
|
|
|
|
|
ns.DrawingController.prototype.afterWindowResize_ = function () {
|
2013-12-06 01:12:48 +04:00
|
|
|
var initialWidth = this.compositeRenderer.getDisplaySize().width;
|
2014-12-18 23:42:03 +03:00
|
|
|
|
2013-11-01 20:12:59 +04:00
|
|
|
this.compositeRenderer.setDisplaySize(this.getContainerWidth_(), this.getContainerHeight_());
|
2013-12-06 01:12:48 +04:00
|
|
|
this.centerColumnWrapperHorizontally_();
|
|
|
|
var ratio = this.compositeRenderer.getDisplaySize().width / initialWidth;
|
|
|
|
var newZoom = ratio * this.compositeRenderer.getZoom();
|
|
|
|
this.compositeRenderer.setZoom(newZoom);
|
|
|
|
|
|
|
|
$.publish(Events.ZOOM_CHANGED);
|
2013-12-19 02:37:17 +04:00
|
|
|
};
|
2012-09-16 20:48:32 +04:00
|
|
|
|
2013-06-17 22:24:27 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ns.DrawingController.prototype.onUserSettingsChange_ = function (evt, settingsName, settingsValue) {
|
|
|
|
if(settingsName == pskl.UserSettings.SHOW_GRID) {
|
2013-11-01 18:39:42 +04:00
|
|
|
console.warn('DrawingController:onUserSettingsChange_ not implemented !');
|
2014-07-04 21:17:02 +04:00
|
|
|
} else if (settingsName == pskl.UserSettings.ONION_SKIN || settingsName == pskl.UserSettings.LAYER_PREVIEW) {
|
2014-06-20 01:33:57 +04:00
|
|
|
this.onionSkinRenderer.clear();
|
|
|
|
this.onionSkinRenderer.flush();
|
|
|
|
this.layersRenderer.clear();
|
|
|
|
this.layersRenderer.flush();
|
|
|
|
this.render();
|
2013-06-17 22:24:27 +04:00
|
|
|
}
|
2013-12-19 02:37:17 +04:00
|
|
|
};
|
2013-06-17 22:24:27 +04:00
|
|
|
|
2015-02-17 04:06:52 +03:00
|
|
|
ns.DrawingController.prototype.onFrameSizeChange_ = function () {
|
2013-11-02 03:00:38 +04:00
|
|
|
this.compositeRenderer.setDisplaySize(this.getContainerWidth_(), this.getContainerHeight_());
|
2014-05-08 22:45:05 +04:00
|
|
|
this.centerColumnWrapperHorizontally_();
|
2013-12-06 01:12:48 +04:00
|
|
|
this.compositeRenderer.setZoom(this.calculateZoom_());
|
|
|
|
this.compositeRenderer.setOffset(0, 0);
|
|
|
|
$.publish(Events.ZOOM_CHANGED);
|
2013-11-02 03:00:38 +04:00
|
|
|
};
|
|
|
|
|
2012-09-14 02:33:46 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ns.DrawingController.prototype.onMousedown_ = function (event) {
|
2014-08-21 02:50:59 +04:00
|
|
|
$.publish(Events.MOUSE_EVENT, [event, this]);
|
2013-12-06 01:12:48 +04:00
|
|
|
var frame = this.piskelController.getCurrentFrame();
|
2014-08-21 02:50:59 +04:00
|
|
|
var coords = this.getSpriteCoordinates(event.clientX, event.clientY);
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2014-11-23 23:37:34 +03:00
|
|
|
this.isClicked = true;
|
|
|
|
this.setCurrentButton(event);
|
|
|
|
|
2013-12-06 01:12:48 +04:00
|
|
|
if (event.button === Constants.MIDDLE_BUTTON) {
|
2014-11-23 23:37:34 +03:00
|
|
|
this.dragHandler.startDrag(event.clientX, event.clientY);
|
2013-12-06 01:12:48 +04:00
|
|
|
} else {
|
2013-12-19 02:37:17 +04:00
|
|
|
this.currentToolBehavior.hideHighlightedPixel(this.overlayFrame);
|
2014-12-19 01:57:34 +03:00
|
|
|
$.publish(Events.TOOL_PRESSED);
|
2013-12-06 01:12:48 +04:00
|
|
|
this.currentToolBehavior.applyToolAt(
|
|
|
|
coords.x,
|
|
|
|
coords.y,
|
2014-03-30 22:39:00 +04:00
|
|
|
this.getCurrentColor_(),
|
2013-12-06 01:12:48 +04:00
|
|
|
frame,
|
|
|
|
this.overlayFrame,
|
|
|
|
event
|
|
|
|
);
|
|
|
|
}
|
2013-08-10 14:11:16 +04:00
|
|
|
};
|
2012-09-08 20:44:06 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
2012-09-14 02:33:46 +04:00
|
|
|
* @private
|
|
|
|
*/
|
2013-08-10 14:11:16 +04:00
|
|
|
ns.DrawingController.prototype.onMousemove_ = function (event) {
|
2014-05-17 00:36:23 +04:00
|
|
|
this._clientX = event.clientX;
|
|
|
|
this._clientY = event.clientY;
|
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
var currentTime = new Date().getTime();
|
|
|
|
// Throttling of the mousemove event:
|
2013-12-06 01:12:48 +04:00
|
|
|
|
2013-11-01 19:27:23 +04:00
|
|
|
if ((currentTime - this.previousMousemoveTime) > Constants.MOUSEMOVE_THROTTLING ) {
|
2014-05-17 00:36:23 +04:00
|
|
|
this.moveTool_(this._clientX, this._clientY, event);
|
2013-08-10 14:11:16 +04:00
|
|
|
this.previousMousemoveTime = currentTime;
|
|
|
|
}
|
|
|
|
};
|
2012-09-08 20:44:06 +04:00
|
|
|
|
2014-05-17 00:36:23 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ns.DrawingController.prototype.onKeyup_ = function (event) {
|
|
|
|
this.moveTool_(this._clientX, this._clientY, event);
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.DrawingController.prototype.moveTool_ = function (x, y, event) {
|
2014-08-21 02:50:59 +04:00
|
|
|
var coords = this.getSpriteCoordinates(x, y);
|
2014-05-17 00:36:23 +04:00
|
|
|
var currentFrame = this.piskelController.getCurrentFrame();
|
|
|
|
|
|
|
|
if (this.isClicked) {
|
2014-11-23 23:37:34 +03:00
|
|
|
if(this.currentMouseButton_ == Constants.MIDDLE_BUTTON) {
|
|
|
|
this.dragHandler.updateDrag(x, y);
|
|
|
|
} else {
|
|
|
|
$.publish(Events.MOUSE_EVENT, [event, this]);
|
|
|
|
// Warning : do not call setCurrentButton here
|
|
|
|
// mousemove do not have the correct mouse button information on all browsers
|
|
|
|
this.currentToolBehavior.moveToolAt(
|
|
|
|
coords.x | 0,
|
|
|
|
coords.y | 0,
|
|
|
|
this.getCurrentColor_(),
|
|
|
|
currentFrame,
|
|
|
|
this.overlayFrame,
|
|
|
|
event
|
|
|
|
);
|
|
|
|
}
|
2014-05-17 00:36:23 +04:00
|
|
|
} else {
|
|
|
|
this.currentToolBehavior.moveUnactiveToolAt(
|
|
|
|
coords.x,
|
|
|
|
coords.y,
|
|
|
|
this.getCurrentColor_(),
|
|
|
|
currentFrame,
|
|
|
|
this.overlayFrame,
|
|
|
|
event
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$.publish(Events.CURSOR_MOVED, [coords.x, coords.y]);
|
2014-05-17 00:40:09 +04:00
|
|
|
};
|
2014-05-17 00:36:23 +04:00
|
|
|
|
2013-10-30 01:16:39 +04:00
|
|
|
ns.DrawingController.prototype.onMousewheel_ = function (jQueryEvent) {
|
2014-05-18 18:33:01 +04:00
|
|
|
var event = jQueryEvent.originalEvent;
|
2014-11-01 16:00:35 +03:00
|
|
|
// Ratio between wheelDeltaY (mousewheel event) and deltaY (wheel event) is -40
|
2015-01-24 02:00:08 +03:00
|
|
|
var delta;
|
|
|
|
if (pskl.utils.UserAgent.isChrome) {
|
|
|
|
delta = event.wheelDeltaY;
|
|
|
|
} else if (pskl.utils.UserAgent.isIE11) {
|
|
|
|
delta = event.wheelDelta;
|
|
|
|
} else if (pskl.utils.UserAgent.isFirefox) {
|
|
|
|
delta = -40 * event.deltaY;
|
|
|
|
}
|
2014-05-18 18:33:01 +04:00
|
|
|
var modifier = Math.abs(delta/120);
|
|
|
|
if (delta > 0) {
|
|
|
|
this.increaseZoom_(modifier);
|
|
|
|
} else if (delta < 0) {
|
|
|
|
this.decreaseZoom_(modifier);
|
2014-05-15 01:52:32 +04:00
|
|
|
}
|
2013-10-30 01:16:39 +04:00
|
|
|
};
|
|
|
|
|
2015-01-24 02:00:08 +03:00
|
|
|
ns.DrawingController.prototype.increaseZoom_ = function (zoomMultiplier) {
|
|
|
|
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
|
|
|
this.setZoom_(this.renderer.getZoom() + step);
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.DrawingController.prototype.decreaseZoom_ = function (zoomMultiplier) {
|
|
|
|
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
|
|
|
this.setZoom_(this.renderer.getZoom() - step);
|
|
|
|
};
|
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ns.DrawingController.prototype.onMouseup_ = function (event) {
|
2014-11-23 23:37:34 +03:00
|
|
|
var frame = this.piskelController.getCurrentFrame();
|
|
|
|
var coords = this.getSpriteCoordinates(event.clientX, event.clientY);
|
2013-12-06 01:12:48 +04:00
|
|
|
if(this.isClicked) {
|
2014-08-21 02:50:59 +04:00
|
|
|
$.publish(Events.MOUSE_EVENT, [event, this]);
|
2013-08-10 14:11:16 +04:00
|
|
|
// A mouse button was clicked on the drawing canvas before this mouseup event,
|
|
|
|
// the user was probably drawing on the canvas.
|
|
|
|
// Note: The mousemove movement (and the mouseup) may end up outside
|
|
|
|
// of the drawing canvas.
|
2013-04-09 09:24:07 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
this.isClicked = false;
|
2014-03-30 22:39:00 +04:00
|
|
|
this.setCurrentButton(event);
|
2012-09-08 20:44:06 +04:00
|
|
|
|
2014-11-23 23:37:34 +03:00
|
|
|
if (event.button === Constants.MIDDLE_BUTTON) {
|
|
|
|
if (this.dragHandler.isDragging()) {
|
|
|
|
this.dragHandler.stopDrag();
|
|
|
|
} else if (frame.containsPixel(coords.x, coords.y)) {
|
|
|
|
$.publish(Events.SELECT_PRIMARY_COLOR, [frame.getPixel(coords.x, coords.y)]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.currentToolBehavior.releaseToolAt(
|
|
|
|
coords.x,
|
|
|
|
coords.y,
|
|
|
|
this.getCurrentColor_(),
|
|
|
|
this.piskelController.getCurrentFrame(),
|
|
|
|
this.overlayFrame,
|
|
|
|
event
|
|
|
|
);
|
|
|
|
|
|
|
|
$.publish(Events.TOOL_RELEASED);
|
|
|
|
}
|
2013-08-10 14:11:16 +04:00
|
|
|
}
|
|
|
|
};
|
2012-09-08 20:44:06 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
2014-07-13 02:21:36 +04:00
|
|
|
* Translate absolute x,y screen coordinates into sprite coordinates
|
|
|
|
* @param {Number} screenX
|
|
|
|
* @param {Number} screenY
|
|
|
|
* @return {Object} {x:Number, y:Number}
|
2013-08-10 14:11:16 +04:00
|
|
|
*/
|
2014-07-13 02:21:36 +04:00
|
|
|
ns.DrawingController.prototype.getSpriteCoordinates = function(screenX, screenY) {
|
|
|
|
return this.renderer.getCoordinates(screenX, screenY);
|
2013-08-10 14:11:16 +04:00
|
|
|
};
|
|
|
|
|
2014-08-21 02:50:59 +04:00
|
|
|
ns.DrawingController.prototype.getScreenCoordinates = function(spriteX, spriteY) {
|
|
|
|
return this.renderer.reverseCoordinates(spriteX, spriteY);
|
|
|
|
};
|
|
|
|
|
2014-03-30 22:39:00 +04:00
|
|
|
ns.DrawingController.prototype.setCurrentButton = function (event) {
|
|
|
|
this.currentMouseButton_ = event.button;
|
|
|
|
};
|
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2014-03-30 22:39:00 +04:00
|
|
|
ns.DrawingController.prototype.getCurrentColor_ = function () {
|
|
|
|
// 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) {
|
2013-11-19 10:40:35 +04:00
|
|
|
return this.paletteController.getSecondaryColor();
|
2014-03-30 22:39:00 +04:00
|
|
|
} else if(this.currentMouseButton_ == Constants.LEFT_BUTTON) {
|
2013-11-19 10:40:35 +04:00
|
|
|
return this.paletteController.getPrimaryColor();
|
2013-12-06 01:12:48 +04:00
|
|
|
} else {
|
|
|
|
return Constants.DEFAULT_PEN_COLOR;
|
2013-08-10 14:11:16 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
ns.DrawingController.prototype.onCanvasContextMenu_ = function (event) {
|
|
|
|
if ($(event.target).closest('#drawing-canvas-container').length) {
|
|
|
|
// Deactivate right click on drawing canvas only.
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
event.cancelBubble = true;
|
|
|
|
return false;
|
2013-09-29 01:52:51 +04:00
|
|
|
}
|
2013-08-10 14:11:16 +04:00
|
|
|
};
|
2012-09-04 16:10:16 +04:00
|
|
|
|
2012-09-09 02:40:05 +04:00
|
|
|
ns.DrawingController.prototype.render = function () {
|
2013-11-01 18:39:42 +04:00
|
|
|
var currentFrame = this.piskelController.getCurrentFrame();
|
|
|
|
if (!currentFrame.isSameSize(this.overlayFrame)) {
|
|
|
|
this.overlayFrame = pskl.model.Frame.createEmptyFromFrame(currentFrame);
|
2012-09-09 03:12:54 +04:00
|
|
|
}
|
2012-09-04 16:10:16 +04:00
|
|
|
|
2014-07-04 21:17:02 +04:00
|
|
|
if (pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN)) {
|
2014-06-20 01:33:57 +04:00
|
|
|
this.onionSkinRenderer.render();
|
2014-07-04 21:17:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pskl.UserSettings.get(pskl.UserSettings.LAYER_PREVIEW)) {
|
2014-06-20 01:33:57 +04:00
|
|
|
this.layersRenderer.render();
|
|
|
|
}
|
|
|
|
|
2013-11-01 20:12:59 +04:00
|
|
|
this.renderer.render(currentFrame);
|
|
|
|
this.overlayRenderer.render(this.overlayFrame);
|
2012-09-14 02:33:46 +04:00
|
|
|
};
|
|
|
|
|
2012-09-16 20:48:32 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2013-10-30 01:16:39 +04:00
|
|
|
ns.DrawingController.prototype.calculateZoom_ = function() {
|
|
|
|
var frameHeight = this.piskelController.getCurrentFrame().getHeight(),
|
|
|
|
frameWidth = this.piskelController.getCurrentFrame().getWidth();
|
2013-09-26 09:47:11 +04:00
|
|
|
|
2013-10-30 01:16:39 +04:00
|
|
|
return Math.min(this.getAvailableWidth_()/frameWidth, this.getAvailableHeight_()/frameHeight);
|
2013-09-26 09:47:11 +04:00
|
|
|
};
|
|
|
|
|
2013-10-30 01:16:39 +04:00
|
|
|
ns.DrawingController.prototype.getAvailableHeight_ = function () {
|
|
|
|
return $('#main-wrapper').height();
|
2013-09-26 09:47:11 +04:00
|
|
|
};
|
|
|
|
|
2013-10-30 01:16:39 +04:00
|
|
|
ns.DrawingController.prototype.getAvailableWidth_ = function () {
|
|
|
|
var leftSectionWidth = $('.left-column').outerWidth(true),
|
|
|
|
rightSectionWidth = $('.right-column').outerWidth(true),
|
2013-12-06 01:12:48 +04:00
|
|
|
toolsContainerWidth = $('#tool-section').outerWidth(true),
|
|
|
|
settingsContainerWidth = $('#application-action-section').outerWidth(true),
|
|
|
|
availableWidth = $('#main-wrapper').width() - leftSectionWidth - rightSectionWidth - toolsContainerWidth - settingsContainerWidth;
|
|
|
|
|
2014-03-30 23:55:29 +04:00
|
|
|
var comfortMargin = 10;
|
|
|
|
return availableWidth - comfortMargin;
|
2013-10-30 01:16:39 +04:00
|
|
|
};
|
2013-06-19 21:01:12 +04:00
|
|
|
|
2013-10-30 01:16:39 +04:00
|
|
|
ns.DrawingController.prototype.getContainerHeight_ = function () {
|
2014-12-18 23:42:03 +03:00
|
|
|
return this.getAvailableHeight_();
|
2012-09-16 20:48:32 +04:00
|
|
|
};
|
2013-06-14 15:17:20 +04:00
|
|
|
|
2013-10-30 01:16:39 +04:00
|
|
|
ns.DrawingController.prototype.getContainerWidth_ = function () {
|
2014-12-18 23:42:03 +03:00
|
|
|
return this.getAvailableWidth_();
|
2012-09-16 20:48:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2013-11-01 18:39:42 +04:00
|
|
|
ns.DrawingController.prototype.centerColumnWrapperHorizontally_ = function() {
|
|
|
|
var containerHeight = this.getContainerHeight_();
|
|
|
|
var verticalGapInPixel = Math.floor(($('#main-wrapper').height() - containerHeight) / 2);
|
2013-06-19 21:01:12 +04:00
|
|
|
$('#column-wrapper').css({
|
2013-11-01 18:39:42 +04:00
|
|
|
'top': verticalGapInPixel + 'px'
|
2013-06-19 21:01:12 +04:00
|
|
|
});
|
2012-09-16 20:48:32 +04:00
|
|
|
};
|
2013-10-30 01:16:39 +04:00
|
|
|
|
2013-11-02 02:11:11 +04:00
|
|
|
ns.DrawingController.prototype.getRenderer = function () {
|
|
|
|
return this.compositeRenderer;
|
|
|
|
};
|
|
|
|
|
2014-11-23 23:37:34 +03:00
|
|
|
ns.DrawingController.prototype.getOffset = function () {
|
|
|
|
return this.compositeRenderer.getOffset();
|
|
|
|
};
|
|
|
|
|
2013-11-02 02:11:11 +04:00
|
|
|
ns.DrawingController.prototype.setOffset = function (x, y) {
|
|
|
|
this.compositeRenderer.setOffset(x, y);
|
2013-12-06 01:12:48 +04:00
|
|
|
$.publish(Events.ZOOM_CHANGED);
|
2013-10-30 01:16:39 +04:00
|
|
|
};
|
2014-11-23 23:37:34 +03:00
|
|
|
|
|
|
|
ns.DrawingController.prototype.resetZoom_ = function () {
|
|
|
|
this.setZoom_(this.calculateZoom_());
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.DrawingController.prototype.getZoomStep_ = function () {
|
|
|
|
return this.calculateZoom_() / 10;
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.DrawingController.prototype.setZoom_ = function (zoom) {
|
|
|
|
this.compositeRenderer.setZoom(zoom);
|
|
|
|
$.publish(Events.ZOOM_CHANGED);
|
|
|
|
};
|
|
|
|
|
2012-09-04 16:10:16 +04:00
|
|
|
})();
|