generated from roman-mazur/architecture-lab-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uistate.go
92 lines (78 loc) · 2.14 KB
/
uistate.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
package lang
import (
"github.com/NikitaSutulov/software-architecture-lab3/painter"
"image"
)
type Uistate struct {
backgroundColor painter.Operation
backgroundRectangle *painter.BackgroundRectangle
figuresArray []*painter.CrossFigure
moveOperations []painter.Operation
updateOperation painter.Operation
}
func (u *Uistate) Reset() {
u.backgroundColor = nil
u.backgroundRectangle = nil
u.figuresArray = nil
u.moveOperations = nil
u.updateOperation = nil
}
func (u *Uistate) GetOperations() []painter.Operation {
var ops []painter.Operation
if u.backgroundColor != nil {
ops = append(ops, u.backgroundColor)
}
if u.backgroundRectangle != nil {
ops = append(ops, u.backgroundRectangle)
}
if len(u.moveOperations) != 0 {
ops = append(ops, u.moveOperations...)
u.moveOperations = nil
}
if len(u.figuresArray) != 0 {
for _, figure := range u.figuresArray {
ops = append(ops, figure)
}
}
if u.updateOperation != nil {
ops = append(ops, u.updateOperation)
}
return ops
}
func (u *Uistate) ResetOperations() {
if u.backgroundColor == nil {
u.backgroundColor = painter.OperationFunc(painter.Reset)
}
if u.updateOperation != nil {
u.updateOperation = nil
}
}
func (u *Uistate) GreenBackground() {
u.backgroundColor = painter.OperationFunc(painter.GreenFill)
}
func (u *Uistate) WhiteBackground() {
u.backgroundColor = painter.OperationFunc(painter.WhiteFill)
}
func (u *Uistate) BackgroundRectangle(firstPoint image.Point, secondPoint image.Point) {
u.backgroundRectangle = &painter.BackgroundRectangle{
FirstPoint: firstPoint,
SecondPoint: secondPoint,
}
}
func (u *Uistate) AddFigure(centralPoint image.Point) {
figure := painter.CrossFigure{
CentralPoint: centralPoint,
}
u.figuresArray = append(u.figuresArray, &figure)
}
func (u *Uistate) AddMoveOperation(x int, y int) {
moveOp := painter.MoveOperation{X: x, Y: y, FiguresArray: u.figuresArray}
u.moveOperations = append(u.moveOperations, &moveOp)
}
func (u *Uistate) ResetStateAndBackground() {
u.Reset()
u.backgroundColor = painter.OperationFunc(painter.Reset)
}
func (u *Uistate) SetUpdateOperation() {
u.updateOperation = painter.UpdateOp
}