From 81a8c7fddc300451e7223845f1ddbc0a3bf16f20 Mon Sep 17 00:00:00 2001 From: Niharika Khanna Date: Mon, 4 Dec 2017 16:37:55 +0000 Subject: [PATCH] add color picker --- server/src/pages/shot/editor.js | 75 ++++++++++++++++++++++++++++----- static/css/frame.scss | 35 +++++++++++++++ 2 files changed, 100 insertions(+), 10 deletions(-) diff --git a/server/src/pages/shot/editor.js b/server/src/pages/shot/editor.js index 7b758d6cf3..55bcd1b6c3 100644 --- a/server/src/pages/shot/editor.js +++ b/server/src/pages/shot/editor.js @@ -22,9 +22,10 @@ exports.Editor = class Editor extends React.Component {
- - - + + + +
@@ -36,12 +37,16 @@ exports.Editor = class Editor extends React.Component {
this.canvasContainer = canvasContainer}> { this.imageCanvas = image }} height={ canvasHeight } width={ canvasWidth } style={{height: canvasHeight, width: canvasWidth}}> { this.highlighter = highlighter }} height={canvasHeight} width={canvasWidth}> - { this.editor = editor }} height={canvasHeight} width={canvasWidth}> + { this.editor = editor }} height={canvasHeight} width={canvasWidth}>
} + setColor(color) { + this.setState({color}); + } + componentDidUpdate() { this.edit(); } @@ -49,7 +54,7 @@ exports.Editor = class Editor extends React.Component { onClickClear() { this.setState({tool: this.state.tool}); sendEvent("clear-select", "annotation-toolbar"); - this.drawContext.clearRect(0, 0, this.editor.width, this.editor.height); + this.penContext.clearRect(0, 0, this.editor.width, this.editor.height); this.highlightContext.clearRect(0, 0, this.editor.width, this.editor.height); } @@ -82,7 +87,7 @@ exports.Editor = class Editor extends React.Component { } componentDidMount() { - this.context = this.editor.getContext('2d'); + this.penContext = this.editor.getContext('2d'); this.highlightContext = this.highlighter.getContext('2d'); let imageContext = this.imageCanvas.getContext('2d'); let img = new Image(); @@ -100,12 +105,14 @@ exports.Editor = class Editor extends React.Component { edit() { this.pos = { x: 0, y: 0 }; if (this.state.tool == 'highlighter') { + this.drawContext = this.highlightContext; this.highlightContext.lineWidth = 20; - this.highlightContext.strokeStyle = '#ff0'; + this.highlightContext.strokeStyle = this.state.color; } else if (this.state.tool == 'pen') { - this.context.strokeStyle = this.state.color; + this.drawContext = this.penContext; + this.penContext.strokeStyle = this.state.color; + this.penContext.lineWidth = this.state.size; } - this.context.lineWidth = this.state.size; if (this.state.tool == 'none') { this.canvasContainer.removeEventListener("mousemove", this.draw); this.canvasContainer.removeEventListener("mousedown", this.setPosition); @@ -127,7 +134,6 @@ exports.Editor = class Editor extends React.Component { if (e.buttons !== 1) { return null; } - this.drawContext = this.state.tool == 'highlighter' ? this.highlightContext : this.context; this.drawContext.beginPath(); this.drawContext.lineCap = this.state.tool == 'highlighter' ? 'square' : 'round'; @@ -140,3 +146,52 @@ exports.Editor = class Editor extends React.Component { this.drawContext.stroke(); } } + +class ColorPicker extends React.Component { + + constructor(props) { + super(props); + this.state = { + pickerActive: false, + color: '#000' + }; + } + + render() { + let border = this.state.color == 'rgb(255, 255, 255)' ? '#000' : this.state.color; + return
+ {this.state.pickerActive ? this.renderColorBoard() : null} +
+ } + + renderColorBoard() { + return
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ } + + onClickSwatch(e) { + let color = e.target.style.backgroundColor + this.setState({color, pickerActive: false}); + this.props.setColor(color); + } + + onClickColorPicker() { + let pickerActive = !this.state.pickerActive; + this.setState({pickerActive}); + } +} diff --git a/static/css/frame.scss b/static/css/frame.scss index 8ea9991449..b303550e03 100644 --- a/static/css/frame.scss +++ b/static/css/frame.scss @@ -421,3 +421,38 @@ body { overflow: hidden; margin-bottom: 20px; } + +.color-button { + height: 25px; + width: 25px; + border-radius: 12.5px; + margin: 12px 5px 0 5px; +} + +.color-board { + margin-top: $grid-unit/2; + width: 160px; + height: 160px; + position: absolute; + background: $light-default; + border: 1px solid $light-border; + padding: 20px; +} + +.color-board .row { + display: flex; +} + +.swatch { + margin: 5px; + flex-direction: row; + flex-wrap: wrap; + width: 30px; + height: 30px; + border-radius: 15px; + + &:hover + { + border: 2px solid $light-border-active !important; + } +}