Skip to content
This repository was archived by the owner on Aug 1, 2022. It is now read-only.

Commit c6eb9f6

Browse files
committed
Re-add drawing of ui & add hideInterface prop
1 parent de66577 commit c6eb9f6

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ These are the defaultProps of CanvasDraw. You can pass along any of these props
5757
disabled: false,
5858
imgSrc: "",
5959
saveData: null,
60-
immediateLoading: false
60+
immediateLoading: false,
61+
hideInterface: false
6162
};
6263
```
6364

demo/src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class Demo extends Component {
3838
default values.
3939
</p>
4040
<p>Try it out! Draw on this white canvas:</p>
41-
<CanvasDraw
42-
onChange={() => console.log('onChange') }
43-
/>
41+
<CanvasDraw onChange={() => console.log("onChange")} />
4442
<h2>Custom Brush-Color</h2>
4543
<p>
4644
Let's spice things up by using custom brush colors{" "}
@@ -71,6 +69,9 @@ class Demo extends Component {
7169
brushColor="rgba(155,12,60,0.3)"
7270
imgSrc="https://upload.wikimedia.org/wikipedia/commons/a/a1/Nepalese_Mhapuja_Mandala.jpg"
7371
/>
72+
<h2>Hide UI</h2>
73+
<p>To hide the UI elements, set the `hideInterface` prop. You can also hide the grid with the `hideGrid` prop.</p>
74+
<CanvasDraw hideInterface hideGrid />
7475
<h2>Save & Load</h2>
7576
<p>
7677
This part got me most excited. Very easy to use saving and loading of

src/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export default class extends PureComponent {
5959
disabled: PropTypes.bool,
6060
imgSrc: PropTypes.string,
6161
saveData: PropTypes.string,
62-
immediateLoading: PropTypes.bool
62+
immediateLoading: PropTypes.bool,
63+
hideInterface: PropTypes.bool
6364
};
6465

6566
static defaultProps = {
@@ -77,7 +78,8 @@ export default class extends PureComponent {
7778
disabled: false,
7879
imgSrc: "",
7980
saveData: "",
80-
immediateLoading: false
81+
immediateLoading: false,
82+
hideInterface: false
8183
};
8284

8385
constructor(props) {
@@ -175,7 +177,7 @@ export default class extends PureComponent {
175177
const lines = this.lines.slice(0, -1);
176178
this.clear();
177179
this.simulateDrawingLines({ lines, immediate: true });
178-
this.triggerOnChange()
180+
this.triggerOnChange();
179181
};
180182

181183
getSaveData = () => {
@@ -440,12 +442,12 @@ export default class extends PureComponent {
440442
// Clear the temporary line-drawing canvas
441443
this.ctx.temp.clearRect(0, 0, width, height);
442444

443-
this.triggerOnChange()
445+
this.triggerOnChange();
444446
};
445447

446448
triggerOnChange = () => {
447-
this.props.onChange && this.props.onChange(this)
448-
}
449+
this.props.onChange && this.props.onChange(this);
450+
};
449451

450452
clear = () => {
451453
this.lines = [];
@@ -469,7 +471,7 @@ export default class extends PureComponent {
469471
const pointer = this.lazy.getPointerCoordinates();
470472
const brush = this.lazy.getBrushCoordinates();
471473

472-
// this.drawInterface(this.ctx.interface, pointer, brush);
474+
this.drawInterface(this.ctx.interface, pointer, brush);
473475
this.mouseHasMoved = false;
474476
this.valuesChanged = false;
475477
}
@@ -512,6 +514,8 @@ export default class extends PureComponent {
512514
};
513515

514516
drawInterface = (ctx, pointer, brush) => {
517+
if (this.props.hideInterface) return;
518+
515519
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
516520

517521
// Draw brush preview

0 commit comments

Comments
 (0)