Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fixes #4373 - Add a TextTool
Browse files Browse the repository at this point in the history
  • Loading branch information
punamdahiya committed Jul 11, 2018
1 parent 1615d72 commit f02fac0
Show file tree
Hide file tree
Showing 6 changed files with 474 additions and 10 deletions.
14 changes: 14 additions & 0 deletions locales/en-US/server.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ annotationUndoButton =
.title = Undo
annotationRedoButton =
.title = Redo
annotationTextButton =
.title = Add text
# Note: This button reverts all the changes on the image since the start of the editing session.
annotationClearButton =
.title = Clear
Expand Down Expand Up @@ -217,6 +219,18 @@ annotationColorSeaGreen =
annotationColorGrey =
.title = Grey
# Note: annotationTextSize is a title for text size selection dropdown.
annotationTextSize =
.title = Text size
# Values shown in text size selection dropdown
textSizeSmall = Small
textSizeMedium = Medium
textSizeLarge = Large
# Confirm and Cancel button title shown when using text tool
annotationTextConfirmButton =
.title = Confirm
annotationTextCancelButton =
.title = Cancel
## Settings Page

Expand Down
8 changes: 5 additions & 3 deletions server/src/pages/shot/color-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ exports.ColorPicker = class ColorPicker extends React.Component {
this.keyMaybeClose = this.keyMaybeClose.bind(this);
this.state = {
pickerActive: false,
color: props.color || "#000"
color: props.color || "#000",
colorName: props.colorName || "black"
};
this.elRef = React.createRef();
}
Expand Down Expand Up @@ -108,8 +109,8 @@ exports.ColorPicker = class ColorPicker extends React.Component {
onClickSwatch(e) {
const color = e.target.style.backgroundColor;
const title = e.target.title.toLowerCase().replace(/\s/g, "-");
this.setState({color, pickerActive: false});
this.props.setColorCallback && this.props.setColorCallback(color);
this.setState({color, colorName: title, pickerActive: false});
this.props.setColorCallback && this.props.setColorCallback(color, title);
sendEvent(`${title}-select`, "annotation-color-board");
}

Expand All @@ -122,5 +123,6 @@ exports.ColorPicker = class ColorPicker extends React.Component {

exports.ColorPicker.propTypes = {
color: PropTypes.string,
colorName: PropTypes.string,
setColorCallback: PropTypes.func
};
53 changes: 50 additions & 3 deletions server/src/pages/shot/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const sendEvent = require("../../browser-send-event.js");
const { PenTool } = require("./pen-tool");
const { HighlighterTool } = require("./highlighter-tool");
const { CropTool } = require("./crop-tool");
const { TextTool } = require("./text-tool");
const { ColorPicker } = require("./color-picker");
const { EditorHistory, RecordType } = require("./editor-history");
const { Selection } = require("../../../shared/selection");
Expand All @@ -17,6 +18,7 @@ exports.Editor = class Editor extends React.Component {
canvasCssHeight: Math.floor(this.props.clip.image.dimensions.y),
tool: "",
color: "",
colorName: "",
lineWidth: "",
actionsDisabled: true,
canUndo: false,
Expand Down Expand Up @@ -50,6 +52,7 @@ exports.Editor = class Editor extends React.Component {
this.setState({
tool: "pen",
color: "#000",
colorName: "black",
lineWidth: 5,
actionsDisabled: true
});
Expand Down Expand Up @@ -138,6 +141,18 @@ exports.Editor = class Editor extends React.Component {
cancelCropHandler={this.onClickCancelCrop.bind(this)}
confirmCropHandler={this.onCropUpdate.bind(this)}
toolbarOverrideCallback={this.overrideToolbar.bind(this)} />;
case "textTool":
return <TextTool
ref={this.selectedTool}
color={this.state.color}
colorName={this.state.colorName}
baseCanvas={this.imageCanvas}
canvasPixelRatio={this.state.canvasPixelRatio}
canvasCssWidth={this.state.canvasCssWidth}
canvasCssHeight={this.state.canvasCssHeight}
cancelTextHandler={this.onClickCancelText.bind(this)}
confirmTextHandler={this.onClickUpdateText.bind(this)}
toolbarOverrideCallback={this.overrideToolbar.bind(this)} />;
default:
return null;
}
Expand Down Expand Up @@ -181,9 +196,12 @@ exports.Editor = class Editor extends React.Component {
<Localized id="annotationHighlighterButton">
<button className={`button transparent highlight-button ${highlighterState}`} id="highlight" onClick={this.onClickHighlight.bind(this)} title="Highlighter"></button>
</Localized>
<Localized id="annotationTextButton">
<button className={`button transparent text-button`} id="text" onClick={this.onClickText.bind(this)} title="Text"></button>
</Localized>
<ColorPicker activeTool={this.state.tool}
setColorCallback={this.setColor.bind(this)}
color={this.state.color} />
color={this.state.color} colorName = {this.state.colorName}/>
<span className="annotation-divider"></span>
<Localized id="annotationUndoButton">
<button className={`button transparent undo-button ${undoButtonState}`} id="undo"
Expand All @@ -210,8 +228,8 @@ exports.Editor = class Editor extends React.Component {
</div>;
}

setColor(color) {
this.setState({color});
setColor(color, colorName) {
this.setState({color, colorName});
}

renderShotsLoading() {
Expand Down Expand Up @@ -360,6 +378,35 @@ exports.Editor = class Editor extends React.Component {
}
}

onClickText() {
this.previousTool = this.state.tool;
this.setState({tool: "textTool"});
sendEvent("text-select", "annotation-toolbar");
}

onClickUpdateText(affectedArea, incomingCanvas) {
if (!affectedArea || !incomingCanvas) {
this.setState({tool: this.previousTool});
return;
}
this.history.pushDiff(this.imageCanvas, affectedArea);

this.imageContext.globalCompositeOperation = "source-over";
this.imageContext.drawImage(incomingCanvas,
affectedArea.left * this.state.canvasPixelRatio,
affectedArea.top * this.state.canvasPixelRatio,
affectedArea.width * this.state.canvasPixelRatio,
affectedArea.height * this.state.canvasPixelRatio,
affectedArea.left, affectedArea.top, affectedArea.width, affectedArea.height);
this.setState({tool: this.previousTool});
this.deriveButtonStates();
}

onClickCancelText() {
this.setState({tool: this.previousTool});
}


onMouseUp(e) {
// This is here so that when the user releases the mouse button outside of
// the canvas area, the drawing will stop.
Expand Down
Loading

0 comments on commit f02fac0

Please sign in to comment.