Skip to content

Commit 77f8f66

Browse files
committed
Adds pressure, fading.
1 parent 3ce3b5a commit 77f8f66

File tree

8 files changed

+256
-92
lines changed

8 files changed

+256
-92
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
## 0.3.0
2+
3+
- Adds pressure strokes (`perfect-freehand`).
4+
- Makes all strokes fade after a certain time has passed since the last stroke.
5+
16
## 0.2.1
27

38
- Notarized / signed mac app.
49

510
## 0.2.0
611

7-
- Adds changelog.
12+
- Adds change log.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2+
"version": "0.3.0",
23
"private": true,
34
"name": "telestrator",
45
"description": "A drawing app for streaming.",
5-
"version": "0.2.1",
66
"author": "Steve Ruiz @steveruizok",
77
"homepage": "https://github.com/steveruizok/telestrator",
88
"main": "app/background.js",
@@ -20,13 +20,15 @@
2020
"dependencies": {
2121
"@state-designer/react": "^1.4.5",
2222
"@types/lodash": "^4.14.168",
23+
"@types/lodash-es": "^4.17.4",
2324
"@types/react": "^17.0.1",
2425
"@types/styled-components": "^5.1.7",
2526
"cardinal-spline": "^0.0.1",
2627
"electron-serve": "^1.0.0",
2728
"electron-store": "^6.0.1",
2829
"framer-motion": "^3.3.0",
2930
"lodash-es": "^4.17.20",
31+
"perfect-freehand": "^0.2.3",
3032
"react-feather": "^2.0.9",
3133
"styled-components": "^5.2.1"
3234
},

renderer/components/canvas.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ export default function App() {
77
const rCanvasFrame = React.useRef<HTMLDivElement>()
88
const rMarksCanvas = React.useRef<HTMLCanvasElement>()
99
const rCurrentCanvas = React.useRef<HTMLCanvasElement>()
10-
11-
const showCursor = useSelector((state) => state.isInAny("active"))
10+
const showCursor = useSelector((state) => {
11+
console.log(state.isIn("active"))
12+
console.log(state.isIn("cursorVisible"))
13+
return state.isIn("active", "cursorVisible")
14+
})
1215

1316
React.useEffect(() => {
1417
state.send("LOADED", {

renderer/components/controls.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import {
1010
ArrowDownLeft,
1111
Lock,
1212
Unlock,
13+
PenTool,
1314
} from "react-feather"
1415

1516
export default function Controls() {
1617
const hideActive = useSelector((state) => state.isIn("drawing"))
1718
const isFading = useSelector((state) => state.data.isFading)
1819
const selectedSize = useSelector((state) => state.data.size)
1920
const selectedColor = useSelector((state) => state.data.color)
21+
const isPressure = useSelector((state) => state.data.pressure)
2022
const selectedTool = useSelector((state) =>
2123
state.isIn("pencil")
2224
? "pencil"
@@ -59,9 +61,16 @@ export default function Controls() {
5961
))}
6062
<ToolButton
6163
isSelected={selectedTool === "pencil"}
62-
onClick={() => state.send("SELECTED_PENCIL")}
64+
onDoubleClick={() => state.send("TOGGLED_PRESSURE")}
65+
onClick={(e) => {
66+
if (e.shiftKey) {
67+
state.send("TOGGLED_PRESSURE")
68+
} else {
69+
state.send("SELECTED_PENCIL")
70+
}
71+
}}
6372
>
64-
<Edit2 size={24} />
73+
{isPressure ? <PenTool size={24} /> : <Edit2 size={24} />}
6574
</ToolButton>
6675
<ToolButton
6776
isSelected={selectedTool === "arrow"}

renderer/hooks/useKeyboardEvents.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ export default function useKeyboardEvents() {
55
useEffect(() => {
66
function releaseControl(e: KeyboardEvent) {
77
switch (e.key) {
8-
case "Shift": {
9-
state.send("TOGGLED_ASPECT_LOCK")
10-
break
11-
}
12-
case "Meta": {
13-
state.send("TOGGLED_FILL")
14-
}
158
case "1":
169
case "2":
1710
case "3":
@@ -30,10 +23,17 @@ export default function useKeyboardEvents() {
3023
if (e.metaKey) {
3124
state.send("TOGGLED_FADING")
3225
}
26+
break
27+
}
28+
case "D":
29+
case "P": {
30+
state.send("TOGGLED_PRESSURE")
31+
break
3332
}
3433
case "d":
3534
case "p": {
3635
state.send("SELECTED_PENCIL")
36+
3737
break
3838
}
3939
case "a": {
@@ -70,6 +70,13 @@ export default function useKeyboardEvents() {
7070
state.send("DEACTIVATED")
7171
break
7272
}
73+
case "Shift": {
74+
state.send("TOGGLED_ASPECT_LOCK")
75+
break
76+
}
77+
case "Meta": {
78+
state.send("TOGGLED_FILL")
79+
}
7380
}
7481
}
7582

renderer/hooks/usePointer.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ interface MotionPointer {
66
y: MotionValue<number>
77
dx: MotionValue<number>
88
dy: MotionValue<number>
9+
p: MotionValue<number>
10+
pointerType: string
911
}
1012
export const mvPointer: MotionPointer = {
1113
x: motionValue(0),
1214
y: motionValue(0),
1315
dx: motionValue(0),
1416
dy: motionValue(0),
17+
p: motionValue(0),
18+
pointerType: "mouse",
1519
}
1620

1721
interface PointerInfo {
@@ -32,14 +36,12 @@ export default function usePointer(
3236
const dx = x - mvPointer.x.get()
3337
const dy = y - mvPointer.y.get()
3438

35-
// if (Math.hypot(dx, dy) < 8) {
36-
// return
37-
// }
38-
3939
mvPointer.x.set(x)
4040
mvPointer.y.set(y)
4141
mvPointer.dx.set(dx)
4242
mvPointer.dy.set(dy)
43+
mvPointer.p.set(e.pressure)
44+
mvPointer.pointerType = e.pointerType
4345

4446
if (onMove) {
4547
onMove({ x, y, dx, dy })

0 commit comments

Comments
 (0)