mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Feature : color palette
- Fixed : manager UI is redrawn after save - the Selected palette is saved as a user preference - default background is now the dark one - the selected palette is not reset after closing palette manager
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
.palettes-list-container {
|
.palettes-list-container {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.palettes-list-select {
|
||||||
|
float:right;
|
||||||
|
max-width:90px;
|
||||||
|
margin-top: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
.palettes-title {
|
.palettes-title {
|
||||||
background-size: 22px;
|
background-size: 22px;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
|
@@ -19,6 +19,8 @@ var Constants = {
|
|||||||
DEFAULT_PEN_COLOR : '#000000',
|
DEFAULT_PEN_COLOR : '#000000',
|
||||||
TRANSPARENT_COLOR : 'rgba(0, 0, 0, 0)',
|
TRANSPARENT_COLOR : 'rgba(0, 0, 0, 0)',
|
||||||
|
|
||||||
|
NO_PALETTE_ID : '__no-palette',
|
||||||
|
|
||||||
// Used for Spectrum input
|
// Used for Spectrum input
|
||||||
PREFERRED_COLOR_FORMAT : 'rgb',
|
PREFERRED_COLOR_FORMAT : 'rgb',
|
||||||
|
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
(function () {
|
(function () {
|
||||||
var ns = $.namespace('pskl.controller');
|
var ns = $.namespace('pskl.controller');
|
||||||
|
|
||||||
var NO_PALETTE_ID = '__no-palette';
|
|
||||||
|
|
||||||
ns.PalettesListController = function () {
|
ns.PalettesListController = function () {
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -10,8 +8,8 @@
|
|||||||
ns.PalettesListController.prototype.init = function () {
|
ns.PalettesListController.prototype.init = function () {
|
||||||
this.paletteColorTemplate_ = pskl.utils.Template.get('palette-color-template');
|
this.paletteColorTemplate_ = pskl.utils.Template.get('palette-color-template');
|
||||||
this.colorListContainer_ = document.querySelector('.palettes-list-colors');
|
this.colorListContainer_ = document.querySelector('.palettes-list-colors');
|
||||||
this.colorPaletteSelect_ = document.querySelector('.palette-picker');
|
this.colorPaletteSelect_ = document.querySelector('.palettes-list-select');
|
||||||
this.paletteListOptGroup_ = document.querySelector('.palette-picker-group');
|
this.paletteListOptGroup_ = document.querySelector('.palettes-list-select-group');
|
||||||
|
|
||||||
this.colorPaletteSelect_.addEventListener('change', this.onPaletteSelected_.bind(this));
|
this.colorPaletteSelect_.addEventListener('change', this.onPaletteSelected_.bind(this));
|
||||||
this.colorListContainer_.addEventListener('mouseup', this.onColorContainerMouseup.bind(this));
|
this.colorListContainer_.addEventListener('mouseup', this.onColorContainerMouseup.bind(this));
|
||||||
@@ -22,12 +20,13 @@
|
|||||||
$.subscribe(Events.SECONDARY_COLOR_SELECTED, this.onColorUpdated.bind(this, 'secondary'));
|
$.subscribe(Events.SECONDARY_COLOR_SELECTED, this.onColorUpdated.bind(this, 'secondary'));
|
||||||
|
|
||||||
this.fillPaletteList();
|
this.fillPaletteList();
|
||||||
|
this.selectPaletteFromUserSettings();
|
||||||
this.fillColorListContainer();
|
this.fillColorListContainer();
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.PalettesListController.prototype.fillPaletteList = function () {
|
ns.PalettesListController.prototype.fillPaletteList = function () {
|
||||||
var palettes = [{
|
var palettes = [{
|
||||||
id : NO_PALETTE_ID,
|
id : Constants.NO_PALETTE_ID,
|
||||||
name : 'No palette'
|
name : 'No palette'
|
||||||
}];
|
}];
|
||||||
palettes = palettes.concat(this.retrievePalettes());
|
palettes = palettes.concat(this.retrievePalettes());
|
||||||
@@ -58,17 +57,28 @@
|
|||||||
return palette;
|
return palette;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.PalettesListController.prototype.selectPalette = function (paletteId) {
|
||||||
|
this.colorPaletteSelect_.value = paletteId;
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.PalettesListController.prototype.selectPaletteFromUserSettings = function () {
|
||||||
|
this.selectPalette(pskl.UserSettings.get(pskl.UserSettings.SELECTED_PALETTE));
|
||||||
|
};
|
||||||
|
|
||||||
ns.PalettesListController.prototype.onPaletteSelected_ = function (evt) {
|
ns.PalettesListController.prototype.onPaletteSelected_ = function (evt) {
|
||||||
var paletteId = this.colorPaletteSelect_.value;
|
var paletteId = this.colorPaletteSelect_.value;
|
||||||
if (paletteId === '__manage-palettes') {
|
if (paletteId === '__manage-palettes') {
|
||||||
console.log('DISPLAY DIALOG');
|
|
||||||
$.publish(Events.DIALOG_DISPLAY, 'manage-palettes');
|
$.publish(Events.DIALOG_DISPLAY, 'manage-palettes');
|
||||||
this.colorPaletteSelect_.value = NO_PALETTE_ID;
|
this.selectPaletteFromUserSettings();
|
||||||
|
} else {
|
||||||
|
pskl.UserSettings.set(pskl.UserSettings.SELECTED_PALETTE, paletteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fillColorListContainer();
|
this.fillColorListContainer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ns.PalettesListController.prototype.onColorContainerContextMenu = function (event) {
|
ns.PalettesListController.prototype.onColorContainerContextMenu = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
};
|
};
|
||||||
@@ -109,6 +119,8 @@
|
|||||||
|
|
||||||
ns.PalettesListController.prototype.onPaletteListUpdated = function () {
|
ns.PalettesListController.prototype.onPaletteListUpdated = function () {
|
||||||
this.fillPaletteList();
|
this.fillPaletteList();
|
||||||
|
this.selectPaletteFromUserSettings();
|
||||||
|
this.fillColorListContainer();
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.PalettesListController.prototype.getPaletteById = function (paletteId, palettes) {
|
ns.PalettesListController.prototype.getPaletteById = function (paletteId, palettes) {
|
||||||
|
@@ -173,7 +173,7 @@
|
|||||||
} else if (target.classList.contains('palette-manager-palette-button')) {
|
} else if (target.classList.contains('palette-manager-palette-button')) {
|
||||||
var action = target.dataset.action;
|
var action = target.dataset.action;
|
||||||
if (action === 'save') {
|
if (action === 'save') {
|
||||||
this.savePalette(this.getSelectedPalette().id);
|
this.savePaletteAndRedraw(this.getSelectedPalette().id);
|
||||||
} else if (action === 'revert') {
|
} else if (action === 'revert') {
|
||||||
this.revertChanges();
|
this.revertChanges();
|
||||||
} else if (action === 'delete') {
|
} else if (action === 'delete') {
|
||||||
|
@@ -4,10 +4,12 @@
|
|||||||
ns.UserSettings = {
|
ns.UserSettings = {
|
||||||
GRID_WIDTH : 'GRID_WIDTH',
|
GRID_WIDTH : 'GRID_WIDTH',
|
||||||
CANVAS_BACKGROUND : 'CANVAS_BACKGROUND',
|
CANVAS_BACKGROUND : 'CANVAS_BACKGROUND',
|
||||||
|
SELECTED_PALETTE : 'SELECTED_PALETTE',
|
||||||
|
|
||||||
KEY_TO_DEFAULT_VALUE_MAP_ : {
|
KEY_TO_DEFAULT_VALUE_MAP_ : {
|
||||||
'GRID_WIDTH' : 0,
|
'GRID_WIDTH' : 0,
|
||||||
'CANVAS_BACKGROUND' : 'medium-canvas-background'
|
'CANVAS_BACKGROUND' : 'lowcont-dark-canvas-background',
|
||||||
|
'SELECTED_PALETTE' : Constants.NO_PALETTE_ID
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
<div class="toolbox-container palettes-list-container">
|
<div class="toolbox-container palettes-list-container">
|
||||||
<h3 class="toolbox-title palettes-title" style="overflow:hidden">
|
<h3 class="toolbox-title palettes-title" style="overflow:hidden">
|
||||||
<span style="line-height:24px ">Palettes</span>
|
<span style="line-height:24px ">Palettes</span>
|
||||||
<select class="palette-picker" style="float:right; max-width:90px;">
|
<select class="palettes-list-select">
|
||||||
<optgroup class="palette-picker-group" label="Available palettes">
|
<optgroup class="palettes-list-select-group" label="Available palettes">
|
||||||
<option value="__no-palette">No palette</option>
|
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="Admin">
|
<optgroup label="Admin">
|
||||||
<option value="__manage-palettes">Create and Manage palettes</option>
|
<option value="__manage-palettes">Create and Manage palettes</option>
|
||||||
@@ -19,7 +18,3 @@
|
|||||||
<div data-color="{{color}}" style="background:{{color}}"></div>
|
<div data-color="{{color}}" style="background:{{color}}"></div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/template" id="no-palette-selected-template">
|
|
||||||
<div class="palette-not-selected">No palette selected</div>
|
|
||||||
</script>
|
|
||||||
|
Reference in New Issue
Block a user