-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtoolpencil.go
98 lines (83 loc) · 2.32 KB
/
toolpencil.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
94
95
96
97
98
package main
import (
. "gopaint/reza"
"github.com/lxn/win"
)
type ToolPencil struct {
ToolBasic
size int
//cursor win.HCURSOR
}
func (tool *ToolPencil) initialize() {
tool.size = 1
//utf16, _ := syscall.UTF16PtrFromString(".\\cursors\\PencilToolCursor.cur")
//tool.cursor = LoadCursorFromFile(utf16)
}
func (tool *ToolPencil) Dispose() {
}
func (tool *ToolPencil) getCursor(ptMouse *Point) win.HCURSOR {
return mainWindow.hCursorArrow
}
func (tool *ToolPencil) prepare() {
mainWindow.bsize.SetEnabled(true)
menu := mainWindow.bsizeMenu
items := menu.GetItems()
for _, item := range items {
(item.(PopupSizeMenuItem)).SetToggled(false)
}
(items[0].(PopupSizeMenuItem)).SetSize(1)
(items[1].(PopupSizeMenuItem)).SetSize(2)
(items[2].(PopupSizeMenuItem)).SetSize(3)
(items[3].(PopupSizeMenuItem)).SetSize(4)
switch tool.size {
case 1:
(items[0].(PopupSizeMenuItem)).SetToggled(true)
case 2:
(items[1].(PopupSizeMenuItem)).SetToggled(true)
case 3:
(items[2].(PopupSizeMenuItem)).SetToggled(true)
case 4:
(items[3].(PopupSizeMenuItem)).SetToggled(true)
default:
(items[3].(PopupSizeMenuItem)).SetToggled(true)
}
}
func (tool *ToolPencil) changeSize(size int) {
tool.size = size
}
func (tool *ToolPencil) draw(e *ToolDrawEvent) {
}
func (tool *ToolPencil) mouseMoveEvent(e *ToolMouseEvent) {
mbutton := e.mbutton
gc := e.image.context2
x := float64(e.pt.X)
y := float64(e.pt.Y)
lastX := float64(e.lastPt.X)
lastY := float64(e.lastPt.Y)
if mbutton == MouseButtonLeft || mbutton == MouseButtonRight {
color := GetColorForeBack(mbutton)
gc.SetRGBA255(int(color.GetB()), int(color.GetG()), int(color.GetR()), int(color.GetA()))
gc.SetLineWidth(float64(tool.size))
gc.MoveTo(lastX+0.5, lastY+0.5)
gc.LineTo(x+0.5, y+0.5)
gc.Stroke()
}
}
func (tool *ToolPencil) mouseDownEvent(e *ToolMouseEvent) {
mbutton := e.mbutton
gc := e.image.context2
x := float64(e.pt.X)
y := float64(e.pt.Y)
lastX := float64(e.lastPt.X)
lastY := float64(e.lastPt.Y)
if mbutton == MouseButtonLeft || mbutton == MouseButtonRight {
color := GetColorForeBack(mbutton)
gc.SetRGBA255(int(color.GetB()), int(color.GetG()), int(color.GetR()), int(color.GetA()))
gc.SetLineWidth(float64(tool.size))
gc.MoveTo(lastX+0.5, lastY+0.5)
gc.LineTo(x+0.5, y+0.5)
gc.Stroke()
}
}
func (tool *ToolPencil) mouseUpEvent(e *ToolMouseEvent) {
}