diff --git a/src/CCAcontroller.js b/src/CCAcontroller.js index d66c661..244c73b 100644 --- a/src/CCAcontroller.js +++ b/src/CCAcontroller.js @@ -20,6 +20,7 @@ class CCAController { ipcMain.on('changeRGBComponent', this.updateRGBComponent.bind(this)) ipcMain.on('changeForeground', this.updateForegroundFromString.bind(this)) ipcMain.on('changeBackground', this.updateBackgroundFromString.bind(this)) + ipcMain.on('switchColors', this.switchColors.bind(this)) } updateRGBComponent(event, group, component, value, synced = false) { @@ -112,6 +113,19 @@ class CCAController { this.sendEventToAll('backgroundColorChanged') } + switchColors(event) { + let background = this.sharedObject.normal.backgroundColor + this.sharedObject.normal.backgroundColor = this.sharedObject.normal.foregroundColorMixed + this.sharedObject.normal.foregroundColor = background + this.sharedObject.normal.foregroundColorMixed = this.sharedObject.normal.foregroundColor.mixed(this.sharedObject.normal.backgroundColor) + this.updateDeficiencyForeground() + this.updateDeficiencyBackground() + this.updateContrastRatio() + this.updateAdvanced() + this.sendEventToAll('foregroundColorChanged') + this.sendEventToAll('backgroundColorChanged') + } + updateDeficiencyForeground() { this.sharedObject.protanopia.foregroundColor = this.sharedObject.normal.foregroundColorMixed.protanopia() this.sharedObject.deuteranopia.foregroundColor = this.sharedObject.normal.foregroundColorMixed.deuteranopia() diff --git a/src/views/css/main.css b/src/views/css/main.css index 00fb379..12c2bde 100644 --- a/src/views/css/main.css +++ b/src/views/css/main.css @@ -107,6 +107,10 @@ section#background-color button.text { background-image: url('../icons/text.svg'); } +section#foreground-color button.switch { + background-image: url('../icons/switch.svg'); +} + /* Text input sections */ section#foreground-text input, section#background-text input { diff --git a/src/views/icons/switch.svg b/src/views/icons/switch.svg new file mode 100644 index 0000000..06c4c00 --- /dev/null +++ b/src/views/icons/switch.svg @@ -0,0 +1,13 @@ + + + diff --git a/src/views/js/main.js b/src/views/js/main.js index 630ec9d..96af94a 100644 --- a/src/views/js/main.js +++ b/src/views/js/main.js @@ -50,6 +50,8 @@ function initEvents () { document.querySelector('#background-color .text').onclick = function() {showHide(this)} document.querySelector('#foreground-text input').oninput = function() {validateForegroundText(this.value)} document.querySelector('#background-text input').oninput = function() {validateBackgroundText(this.value)} + document.querySelector('#foreground-color .switch').onclick = function() {ipcRenderer.send('switchColors')} + // initDetails document.querySelectorAll('details').forEach(function(details) { details.ontoggle = function() { diff --git a/src/views/main.html b/src/views/main.html index 8d68676..d050169 100644 --- a/src/views/main.html +++ b/src/views/main.html @@ -22,6 +22,7 @@