@@ -29,16 +29,23 @@ http: const COLORS = [
29
29
] ;
30
30
const RADS = [ 1 , 7 ] ;
31
31
32
+ const HIGHLIGHTER = - 1 ;
33
+ const ERASER = - 2 ;
34
+
32
35
export const minRadius = 0.5 ;
33
36
export const maxRadius = 15 ;
34
37
const numBrushes = COLORS . length * RADS . length ;
35
38
const DEFAULT_PEN = { radius : 1 , color : "black" } ;
36
39
37
40
export default function Pen ( ) {
38
41
const frame = useFrameContext ( ) ;
39
- const [ selected , setSelected ] = useState < number > (
42
+ const [ selected , setSelected0 ] = useState < number > (
40
43
frame . desc . get ( "penId" ) ?? 0
41
44
) ;
45
+ const setSelected = ( id ) => {
46
+ setSelected0 ( id ) ;
47
+ frame . actions . set_frame_tree ( { id : frame . id , penId : id } ) ;
48
+ } ;
42
49
const [ paramControls , setParamControls ] = useState < boolean > ( false ) ;
43
50
const [ presets , setPresets0 ] = useState < Presets > ( loadPresets ( ) ) ;
44
51
@@ -50,26 +57,27 @@ export default function Pen() {
50
57
function BrushButton ( { id } ) {
51
58
const { radius, color } = presets [ id ] ?? DEFAULT_PEN ;
52
59
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 >
73
81
) ;
74
82
}
75
83
@@ -94,19 +102,28 @@ export default function Pen() {
94
102
paddingBottom : "10px" ,
95
103
} }
96
104
>
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
+ />
100
111
</ Button >
101
112
</ 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
+ />
105
119
</ Button >
106
120
</ 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
+ />
110
127
</ Button >
111
128
</ Tooltip >
112
129
< div
@@ -305,5 +322,11 @@ const savePresets = debounce((presets) => {
305
322
} , 250 ) ;
306
323
307
324
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
+ }
308
331
return loadPresets ( ) [ id ] ?? DEFAULT_PEN ;
309
332
}
0 commit comments