Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit c7fddf6

Browse files
feat(#625): use new remote-utils v1.0.0-rc.1
Signed-off-by: peterpeterparker <[email protected]>
1 parent c29a3ac commit c7fddf6

File tree

3 files changed

+10
-117
lines changed

3 files changed

+10
-117
lines changed

remote/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

remote/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@deckdeckgo/highlight-code": "^1.0.0-rc.2-1",
2323
"@deckdeckgo/lazy-img": "^1.0.0-rc.3-2",
2424
"@deckdeckgo/qrcode": "^1.0.0-rc.1-1",
25+
"@deckdeckgo/remote-utils": "^1.0.0-rc.1",
2526
"@deckdeckgo/slide-aspect-ratio": "^1.0.0-beta.1",
2627
"@deckdeckgo/slide-author": "^1.0.0-rc.3-2",
2728
"@deckdeckgo/slide-big-img": "^1.0.0-rc.1",

remote/src/app/components/app-draw/app-draw.tsx

Lines changed: 4 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,15 @@
11
import {Component, Element, h, Method, Prop, State, Watch} from '@stencil/core';
22

33
import {unifyEvent} from '@deckdeckgo/utils';
4+
5+
import {Arrow, Circle, Drawable, Pencil} from '@deckdeckgo/remote-utils';
6+
47
// Types
58
import {DeckdeckgoDrawAction, DeckdeckgoEventEmitter, DeckdeckgoEventType} from '@deckdeckgo/types';
9+
610
// Services
711
import {CommunicationService} from '../../services/communication/communication.service';
812

9-
interface Point {
10-
x: number;
11-
y: number;
12-
}
13-
14-
interface Drawable {
15-
draw(ctx: CanvasRenderingContext2D);
16-
}
17-
18-
class Circle implements Drawable {
19-
private readonly from: Point;
20-
private readonly to: Point;
21-
private readonly color: string;
22-
23-
constructor(from: Point, to: Point, color: string) {
24-
this.from = from;
25-
this.to = to;
26-
this.color = color;
27-
}
28-
29-
draw(ctx: CanvasRenderingContext2D) {
30-
ctx.beginPath();
31-
32-
ctx.moveTo(this.from.x, this.from.y + (this.to.y - this.from.y) / 2);
33-
ctx.bezierCurveTo(this.from.x, this.from.y, this.to.x, this.from.y, this.to.x, this.from.y + (this.to.y - this.from.y) / 2);
34-
ctx.bezierCurveTo(this.to.x, this.to.y, this.from.x, this.to.y, this.from.x, this.from.y + (this.to.y - this.from.y) / 2);
35-
36-
ctx.strokeStyle = this.color;
37-
ctx.lineWidth = 3;
38-
39-
ctx.stroke();
40-
ctx.closePath();
41-
}
42-
}
43-
44-
class Pencil implements Drawable {
45-
private readonly from: Point;
46-
private readonly to: Point;
47-
private readonly color: string;
48-
49-
constructor(from: Point, to: Point, color: string) {
50-
this.from = from;
51-
this.to = to;
52-
this.color = color;
53-
}
54-
55-
draw(ctx: CanvasRenderingContext2D) {
56-
ctx.beginPath();
57-
58-
ctx.moveTo(this.from.x, this.from.y);
59-
ctx.lineTo(this.to.x, this.to.y);
60-
ctx.strokeStyle = this.color;
61-
ctx.lineWidth = 3;
62-
63-
ctx.stroke();
64-
ctx.closePath();
65-
}
66-
}
67-
68-
class Arrow implements Drawable {
69-
private readonly from: Point;
70-
private readonly to: Point;
71-
private readonly color: string;
72-
73-
constructor(from: Point, to: Point, color: string) {
74-
this.from = from;
75-
this.to = to;
76-
this.color = color;
77-
}
78-
79-
draw(ctx: CanvasRenderingContext2D) {
80-
ctx.beginPath();
81-
82-
ctx.moveTo(this.from.x, this.from.y);
83-
ctx.lineTo(this.to.x, this.to.y);
84-
ctx.strokeStyle = this.color;
85-
ctx.lineWidth = 3;
86-
87-
ctx.stroke();
88-
ctx.closePath();
89-
90-
this.drawTriangle(ctx);
91-
}
92-
93-
private drawTriangle(ctx: CanvasRenderingContext2D) {
94-
ctx.beginPath();
95-
96-
const length: number = Math.sqrt(Math.pow(this.to.y - this.from.y, 2) + Math.pow(this.to.x - this.from.x, 2));
97-
const size: number = Math.min(length, 20);
98-
99-
// https://stackoverflow.com/a/36805543/5404186
100-
101-
let angle: number = Math.atan2(this.to.y - this.from.y, this.to.x - this.from.x);
102-
let x: number = size * Math.cos(angle) + this.to.x;
103-
let y: number = size * Math.sin(angle) + this.to.y;
104-
105-
ctx.moveTo(x, y);
106-
107-
angle += (1 / 3) * (2 * Math.PI);
108-
x = size * Math.cos(angle) + this.to.x;
109-
y = size * Math.sin(angle) + this.to.y;
110-
111-
ctx.lineTo(x, y);
112-
113-
angle += (1 / 3) * (2 * Math.PI);
114-
x = size * Math.cos(angle) + this.to.x;
115-
y = size * Math.sin(angle) + this.to.y;
116-
117-
ctx.lineTo(x, y);
118-
119-
ctx.fillStyle = this.color;
120-
ctx.fill();
121-
122-
ctx.closePath();
123-
}
124-
}
125-
12613
@Component({
12714
tag: 'app-draw',
12815
styleUrl: 'app-draw.scss'

0 commit comments

Comments
 (0)