Tiled preview : mutualize canvas background update

When user changes canvas background, css class now applied on document
body.

Created new controller listening to Events.USER_SETTINGS_CHANGED to handle
this.
This commit is contained in:
jdescottes
2014-05-08 20:57:31 +02:00
parent 6ad5bde5d1
commit 59195c9fb6
6 changed files with 34 additions and 248 deletions

View File

@@ -78,6 +78,9 @@
this.notificationController = new pskl.controller.NotificationController();
this.notificationController.init();
this.canvasBackgroundController = new pskl.controller.CanvasBackgroundController();
this.canvasBackgroundController.init();
this.localStorageService = new pskl.service.LocalStorageService(this.piskelController);
this.localStorageService.init();
@@ -90,6 +93,7 @@
this.savedStatusService = new pskl.service.SavedStatusService(this.piskelController);
this.savedStatusService.init();
if (this.isAppEngineVersion) {
this.storageService = new pskl.service.AppEngineStorageService(this.piskelController);
} else {

View File

@@ -0,0 +1,28 @@
(function () {
var ns = $.namespace('pskl.controller');
ns.CanvasBackgroundController = function () {
this.body = document.body;
};
ns.CanvasBackgroundController.prototype.init = function () {
$.subscribe(Events.USER_SETTINGS_CHANGED, this.onUserSettingsChange_.bind(this));
this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));
};
ns.CanvasBackgroundController.prototype.onUserSettingsChange_ = function (evt, settingName, settingValue) {
if (settingName == pskl.UserSettings.CANVAS_BACKGROUND) {
this.updateBackgroundClass_(settingValue);
}
};
ns.CanvasBackgroundController.prototype.updateBackgroundClass_ = function (newClass) {
var currentClass = this.body.dataset.currentBackgroundClass;
if (currentClass) {
this.body.classList.remove(currentClass);
}
this.body.classList.add(newClass);
this.body.dataset.currentBackgroundClass = newClass;
};
})();

View File

@@ -57,7 +57,6 @@
this.setGridWidth(pskl.UserSettings.get(pskl.UserSettings.GRID_WIDTH));
this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));
$.subscribe(Events.USER_SETTINGS_CHANGED, this.onUserSettingsChange_.bind(this));
};
@@ -162,22 +161,11 @@
};
ns.FrameRenderer.prototype.onUserSettingsChange_ = function (evt, settingName, settingValue) {
if (settingName == pskl.UserSettings.CANVAS_BACKGROUND) {
this.updateBackgroundClass_(settingValue);
} else if (settingName == pskl.UserSettings.GRID_WIDTH) {
if (settingName == pskl.UserSettings.GRID_WIDTH) {
this.setGridWidth(settingValue);
}
};
ns.FrameRenderer.prototype.updateBackgroundClass_ = function (newClass) {
var currentClass = this.container.data('current-background-class');
if (currentClass) {
this.container.removeClass(currentClass);
}
this.container.addClass(newClass);
this.container.data('current-background-class', newClass);
};
ns.FrameRenderer.prototype.renderPixel_ = function (color, x, y, context) {
if(color != Constants.TRANSPARENT_COLOR) {
context.fillStyle = color;

View File

@@ -8,11 +8,6 @@
this.displayContainer = document.createElement('div');
this.displayContainer.classList.add('tiled-frame-container');
container.get(0).appendChild(this.displayContainer);
this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));
this.onUserSettingsChange_listener = this.onUserSettingsChange_.bind(this);
$.subscribe(Events.USER_SETTINGS_CHANGED, this.onUserSettingsChange_listener);
};
ns.TiledFrameRenderer.prototype.render = function (frame) {
@@ -33,19 +28,4 @@
ns.TiledFrameRenderer.prototype.getZoom = function () {
return this.zoom;
};
ns.TiledFrameRenderer.prototype.onUserSettingsChange_ = function (evt, settingName, settingValue) {
if (settingName == pskl.UserSettings.CANVAS_BACKGROUND) {
this.updateBackgroundClass_(settingValue);
}
};
ns.TiledFrameRenderer.prototype.updateBackgroundClass_ = function (newClass) {
var currentClass = this.container.data('current-background-class');
if (currentClass) {
this.container.removeClass(currentClass);
}
this.container.addClass(newClass);
this.container.data('current-background-class', newClass);
};
})();

View File

@@ -78,6 +78,7 @@
"js/controller/PaletteController.js",
"js/controller/PalettesListController.js",
"js/controller/NotificationController.js",
"js/controller/CanvasBackgroundController.js",
// Settings sub-controllers
"js/controller/settings/ApplicationSettingsController.js",