Skip to content

Commit e6e4594

Browse files
committed
board: eraser and highlighter
1 parent eb02e49 commit e6e4594

File tree

1 file changed

+53
-30
lines changed
  • src/packages/frontend/frame-editors/whiteboard-editor/tools

1 file changed

+53
-30
lines changed

src/packages/frontend/frame-editors/whiteboard-editor/tools/pen.tsx

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,23 @@ http: const COLORS = [
2929
];
3030
const RADS = [1, 7];
3131

32+
const HIGHLIGHTER = -1;
33+
const ERASER = -2;
34+
3235
export const minRadius = 0.5;
3336
export const maxRadius = 15;
3437
const numBrushes = COLORS.length * RADS.length;
3538
const DEFAULT_PEN = { radius: 1, color: "black" };
3639

3740
export default function Pen() {
3841
const frame = useFrameContext();
39-
const [selected, setSelected] = useState<number>(
42+
const [selected, setSelected0] = useState<number>(
4043
frame.desc.get("penId") ?? 0
4144
);
45+
const setSelected = (id) => {
46+
setSelected0(id);
47+
frame.actions.set_frame_tree({ id: frame.id, penId: id });
48+
};
4249
const [paramControls, setParamControls] = useState<boolean>(false);
4350
const [presets, setPresets0] = useState<Presets>(loadPresets());
4451

@@ -50,26 +57,27 @@ export default function Pen() {
5057
function BrushButton({ id }) {
5158
const { radius, color } = presets[id] ?? DEFAULT_PEN;
5259
return (
53-
<Button
54-
style={{ paddingLeft: "3px", marginTop: "-15px" }}
55-
type="text"
56-
onClick={() => {
57-
if (id == selected) {
58-
// show color selector
59-
setParamControls(!paramControls);
60-
} else {
61-
// select this one
62-
setSelected(id);
63-
frame.actions.set_frame_tree({ id: frame.id, penId: id });
64-
}
65-
}}
66-
>
67-
<BrushPreset
68-
radius={radius}
69-
color={color}
70-
selectedColor={id == selected ? "#ccc" : undefined}
71-
/>
72-
</Button>
60+
<Tooltip title={`Color: ${color}, Radius: ${radius}px`} placement="right">
61+
<Button
62+
style={{ paddingLeft: "3px", marginTop: "-15px" }}
63+
type="text"
64+
onClick={() => {
65+
if (id == selected) {
66+
// show color selector
67+
setParamControls(!paramControls);
68+
} else {
69+
// select this one
70+
setSelected(id);
71+
}
72+
}}
73+
>
74+
<BrushPreset
75+
radius={radius}
76+
color={color}
77+
selectedColor={id == selected ? "#ccc" : undefined}
78+
/>
79+
</Button>
80+
</Tooltip>
7381
);
7482
}
7583

@@ -94,19 +102,28 @@ export default function Pen() {
94102
paddingBottom: "10px",
95103
}}
96104
>
97-
<Tooltip title="Pen">
98-
<Button type="text">
99-
<Icon style={{ color: "blue" }} name="pencil" />
105+
<Tooltip title="Pen" placement="right">
106+
<Button type="text" onClick={() => setSelected(0)}>
107+
<Icon
108+
style={{ color: selected >= 0 ? "blue" : undefined }}
109+
name="pencil"
110+
/>
100111
</Button>
101112
</Tooltip>
102-
<Tooltip title="Highlighter">
103-
<Button type="text">
104-
<Icon name="blog" />
113+
<Tooltip title="Highlighter" placement="right">
114+
<Button type="text" onClick={() => setSelected(HIGHLIGHTER)}>
115+
<Icon
116+
style={{ color: selected == HIGHLIGHTER ? "blue" : undefined }}
117+
name="blog"
118+
/>
105119
</Button>
106120
</Tooltip>
107-
<Tooltip title="Erase">
108-
<Button type="text">
109-
<Icon name="eraser" />
121+
<Tooltip title="Erase" placement="right">
122+
<Button type="text" onClick={() => setSelected(ERASER)}>
123+
<Icon
124+
style={{ color: selected == ERASER ? "blue" : undefined }}
125+
name="eraser"
126+
/>
110127
</Button>
111128
</Tooltip>
112129
<div
@@ -305,5 +322,11 @@ const savePresets = debounce((presets) => {
305322
}, 250);
306323

307324
export function penParams(id: number) {
325+
if (id == HIGHLIGHTER) {
326+
return { color: "#ffff00", opacity: 0.4, radius: 15 };
327+
}
328+
if (id == ERASER) {
329+
return { color: "#ffffff", radius: 15 };
330+
}
308331
return loadPresets()[id] ?? DEFAULT_PEN;
309332
}

0 commit comments

Comments
 (0)