-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoolsmanager.go
93 lines (86 loc) · 2.47 KB
/
toolsmanager.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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import "log"
type ToolsManager struct {
toolSelect *ToolSelect
toolPencil *ToolPencil
toolBucket *ToolBucket
toolText *ToolText
toolEraser *ToolEraser
toolPickColor *ToolPickColor
toolBrush *ToolBrush
// Shape tools
toolShapeLine *ToolShape
toolShapeRect *ToolShape
toolShapeRoundRect *ToolShape
toolShapeEllipse *ToolShape
toolShapeTriangle *ToolShape
toolShapeDiamond *ToolShape
currentTool Tool
}
func NewToolsManager() *ToolsManager {
mgr := &ToolsManager{}
mgr.init()
return mgr
}
func (tools *ToolsManager) init() {
tools.toolPencil = &ToolPencil{}
tools.toolPencil.initialize()
tools.toolBrush = &ToolBrush{}
tools.toolBrush.initialize()
tools.toolPickColor = &ToolPickColor{}
tools.toolPickColor.initialize()
tools.toolEraser = &ToolEraser{}
tools.toolEraser.initialize()
tools.toolBucket = &ToolBucket{}
tools.toolBucket.initialize()
tools.toolText = &ToolText{}
tools.toolText.initialize()
tools.toolSelect = &ToolSelect{}
tools.toolSelect.initialize()
// Shape tools
tools.toolShapeLine = &ToolShape{ShapeDrawer: &LineDrawer{}}
tools.toolShapeLine.initialize()
tools.toolShapeRect = &ToolShape{ShapeDrawer: &RectangleDrawer{}}
tools.toolShapeRect.initialize()
tools.toolShapeRoundRect = &ToolShape{ShapeDrawer: &RoundRectDrawer{}}
tools.toolShapeRoundRect.initialize()
tools.toolShapeEllipse = &ToolShape{ShapeDrawer: &EllipseDrawer{}}
tools.toolShapeEllipse.initialize()
tools.toolShapeTriangle = &ToolShape{ShapeDrawer: &TriangleDrawer{}}
tools.toolShapeTriangle.initialize()
tools.toolShapeDiamond = &ToolShape{ShapeDrawer: &DiamondDrawer{}}
tools.toolShapeDiamond.initialize()
}
func (tools *ToolsManager) Dispose() {
logInfo("Disposing ToolsManager...")
tools.toolPencil.Dispose()
tools.toolBrush.Dispose()
tools.toolPickColor.Dispose()
tools.toolEraser.Dispose()
tools.toolBucket.Dispose()
tools.toolText.Dispose()
tools.toolSelect.Dispose()
// Shape tools
tools.toolShapeLine.Dispose()
tools.toolShapeRect.Dispose()
tools.toolShapeRoundRect.Dispose()
tools.toolShapeEllipse.Dispose()
tools.toolShapeTriangle.Dispose()
tools.toolShapeDiamond.Dispose()
}
func (tools *ToolsManager) SetCurrentTool(tool Tool) {
if tool == nil {
log.Panicln("tool is nil !!!!")
}
if tools.currentTool == tool {
return
}
if tools.currentTool != nil {
tools.currentTool.leave()
}
tools.currentTool = tool
tool.prepare()
}
func (tools *ToolsManager) GetCurrentTool() Tool {
return tools.currentTool
}