-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcanvas.go
39 lines (31 loc) · 1.72 KB
/
canvas.go
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
package washeet
func (sheet *Sheet) setupCanvas(width, height float64) {
sheet.container.Call("setAttribute", "style", "position:relative;margin:0;padding:0;")
sheet.canvasStore = canvasStoreType{
sheetCanvasElement: sheet.document.Call("createElement", "canvas"),
selectionCanvasElement: sheet.document.Call("createElement", "canvas"),
}
// TODO: avoid following code duplication
// Background canvas :- the sheet canvas
sheetCanvasElement := sheet.canvasStore.sheetCanvasElement
sheetCanvasElement.Set("width", width)
sheetCanvasElement.Set("height", height)
sheet.container.Call("appendChild", sheetCanvasElement)
// Set style to control positioning and z-index.
sheetCanvasElement.Call("setAttribute", "style", "position:absolute;left:0;top:0;z-index:1;margin:0;padding:0;outline:none;")
selectionCanvasElement := sheet.canvasStore.selectionCanvasElement
selectionCanvasElement.Set("width", width)
selectionCanvasElement.Set("height", height)
sheet.container.Call("appendChild", selectionCanvasElement)
// Set style to control positioning and z-index.
selectionCanvasElement.Call("setAttribute", "style", "position:absolute;left:0;top:0;z-index:2;margin:0;padding:0;outline:none;")
// Make selectionCanvasElement the default focussed element.
selectionCanvasElement.Set("tabIndex", 1)
sheet.canvasStore.sheetCanvasContext = sheetCanvasElement.Call("getContext", "2d")
sheet.canvasStore.selectionCanvasContext = selectionCanvasElement.Call("getContext", "2d")
sheet.canvasStore.foregroundCanvasElement = selectionCanvasElement
}
func (sheet *Sheet) teardownCanvas() {
sheet.container.Call("removeChild", sheet.canvasStore.selectionCanvasElement)
sheet.container.Call("removeChild", sheet.canvasStore.sheetCanvasElement)
}