diff --git a/src/App.js b/src/App.js index a937175..b6c1baa 100644 --- a/src/App.js +++ b/src/App.js @@ -29,6 +29,7 @@ class App extends Component { originY: 0, isLoading: true, intro: true, + eyedropper: false, palette: [ '247a23', '30bf2e', @@ -72,12 +73,14 @@ class App extends Component { this._updatePixel = this._updatePixel.bind(this); this._updateOffscreenCanvas = this._updateOffscreenCanvas.bind(this); this._getDrawLocation = this._getDrawLocation.bind(this); - this.onClick = this.onClick.bind(this); + this.onPaletteClick = this.onPaletteClick.bind(this); this._addColor = this._addColor.bind(this); this._rgbToHex = this._rgbToHex.bind(this); this.clearPalette = this.clearPalette.bind(this); this._checkPickerVisibility = this._checkPickerVisibility.bind(this); this.onIntroClick = this.onIntroClick.bind(this); + this.onEyedropperClick = this.onEyedropperClick.bind(this); + this._getColor = this._getColor.bind(this); } _init() { @@ -223,11 +226,15 @@ class App extends Component { let { doc, col } = this._getDocumentLocation(pixelX, pixelY); if(pixelX >= 0 && pixelX < 500 && pixelY >= 0 && pixelY < 500) { - this._updatePixel(doc, col); + if(this.state.eyedropper) { + this._getColor(doc, col); + }else { + this._updatePixel(doc, col); - this._updateOffscreenCanvas(b, row, col); + this._updateOffscreenCanvas(b, row, col); - socket.emit('clientUpdate', doc, b, row, col, this.state.quilt[doc].color); + socket.emit('clientUpdate', doc, b, row, col, this.state.quilt[doc].color); + } } } @@ -385,7 +392,7 @@ class App extends Component { return { x, y }; } - onClick(event) { + onPaletteClick(event) { if(event.target.style.backgroundColor) this.setState({ color: this._rgbToHex(event.target.style.backgroundColor) }); } @@ -450,6 +457,31 @@ class App extends Component { this.setState({ intro: false }); } + onEyedropperClick() { + let eyedropper = document.getElementById('eyedropper'); + + eyedropper.className = eyedropper.className === 'eyedropper' ? 'eyedropper_down' : 'eyedropper'; + + document.body.style.cursor = document.body.style.cursor !== 'copy' ? 'copy' : 'auto'; + + this.setState(prevState => { + let eyedropper = this.state.eyedropper ? false : true; + + return { eyedropper }; + }); + } + + _getColor(doc, col) { + let quilt = this.state.quilt; + let colors = quilt[doc].color; + let getCol = col * 7; + + let color = colors.substr(getCol, 7).slice(0, -1); + + this.setState({ color }); + this.onEyedropperClick(); + } + componentDidMount() { this._init() .then(this._getCanvas) @@ -468,7 +500,7 @@ class App extends Component { : null }
Pixel
Share
Pixel
Share
0.1.0