Skip to content

Commit

Permalink
Button to flip the foreground and background colors (closes #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric committed Jun 5, 2018
1 parent 51e10ae commit 72c56d1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/CCAcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/views/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions src/views/icons/switch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/views/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/views/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h2>Foreground Colour</h2>
<button class="text" aria-label="Foreground text input" aria-controls="foreground-text" aria-expanded="false"></button>
<button class="rgb" aria-label="Foreground rgb sliders" aria-controls="foreground-rgb" aria-expanded="false"></button>
<button class="picker" aria-label="Foreground color picker"></button>
<button class="switch" aria-label="Switch Colors"></button>
</div>
</section>
<section id="foreground-text" hidden>
Expand Down

0 comments on commit 72c56d1

Please sign in to comment.