-
Notifications
You must be signed in to change notification settings - Fork 584
/
breakpointIcon.ts
64 lines (49 loc) · 1.69 KB
/
breakpointIcon.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import * as Blockly from "blockly";
export class BreakpointIcon extends Blockly.icons.Icon {
static readonly type = new Blockly.icons.IconType("breakpoint");
protected isSet_ = false;
protected breakpointSvg: SVGCircleElement;
constructor(sourceBlock: Blockly.Block, protected readonly onStateChange: (block: Blockly.Block, isSet: boolean) => void) {
super(sourceBlock);
}
override getType(): Blockly.icons.IconType<Blockly.IIcon> {
return BreakpointIcon.type;
}
override initView(pointerdownListener: (e: PointerEvent) => void): void {
super.initView(pointerdownListener);
if (this.breakpointSvg) return;
// Red/Grey filled circle, for Set/Unset breakpoint respectively.
this.breakpointSvg = Blockly.utils.dom.createSvgElement(
'circle',
{
'class': 'blocklyBreakpointSymbol',
'stroke': 'white',
'stroke-width': 2,
'cx': 7,
'cy': 11.5,
'r': 8,
},
this.svgRoot
);
this.updateColor();
}
override getSize(): Blockly.utils.Size {
return new Blockly.utils.Size(25, 25);
}
override onClick(): void {
this.isSet_ = !this.isSet_;
this.updateColor();
this.onStateChange(this.sourceBlock, this.isSet_);
}
isEnabled(): boolean {
return this.isSet_;
}
setEnabled(enabled: boolean) {
this.isSet_ = enabled;
this.updateColor();
}
protected updateColor() {
if (!this.breakpointSvg) return;
this.breakpointSvg.setAttribute("fill", this.isSet_ ? "#FF0000" : "#CCCCCC")
}
}