-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesktop.go
142 lines (118 loc) · 3.18 KB
/
desktop.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package tulip
import (
"github.com/gdamore/tcell/v2"
)
type TDesktop struct {
region TRegion
bkgColor tcell.Color
bkgPattern rune
foreColor tcell.Color
statusbar *StatusBar
menubar *MenuBar
}
// func (d *TDesktop) erase(screenX1, screenY1, screenX2, screenY2 int, st tcell.Style, bk rune) {
// for x := screenX1; x <= screenX2; x++ {
// for y := screenY1; y <= screenY2; y++ {
// Screen.SetContent(x, y, bk, nil, st)
// }
// }
// }
func (d *TDesktop) Paint(parentScreenX1, parentScreenY1, parentScreenX2, parentScreenY2 int) {
screenX1, screenY1 := parentScreenX1+d.region.left, parentScreenY1+d.region.top
screenX2 := screenX1 + d.region.w - 1
screenY2 := screenY1 + d.region.h - 1
if screenX2 > parentScreenX2 {
screenX2 = parentScreenX2
}
if screenY2 > parentScreenY2 {
screenY2 = parentScreenY2
}
st := tcell.StyleDefault
st = st.Bold(false)
st = st.Background(d.bkgColor)
st = st.Foreground(d.foreColor)
erase(screenX1, screenY1, screenX2, screenY2, st, d.bkgPattern)
if d.menubar != nil {
d.menubar.Paint(screenX1, screenY1, screenX2, screenY2)
}
if d.statusbar != nil {
d.statusbar.Paint(screenX1, screenY1, screenX2, screenY2)
}
// d.Window.Paint()
// for _, win := range d.childWindows {
// win.Paint()
// }
}
func (d *TDesktop) resize(w, h int) {
d.region.w, d.region.h = w, h
if d.menubar != nil {
d.menubar.resize(w, h)
}
if d.statusbar != nil {
d.statusbar.resize(w, h)
}
App.repaint = true
}
// HandleEvent processes system level events and delegates them to the appropriate widget for further processing.
// Keys reserved for the desktop only:
// Alt-F10 : activate and deactivate the desktop's menubar
// Alt-x : exit the application
// Ctrl-Tab : move to the next window
// Other keystrokes: will be delegate to the currently active window or decktop's menubar (if active)
func (d *TDesktop) HandleEvent(ev IEvent) {
switch ev.(type) {
case *EventTypedCommand:
event := ev.(*EventTypedCommand)
switch event.Command {
case typedCommandAppMenu:
if d.menubar != nil {
d.menubar.ToggleActive()
event.processed = true
}
case typedCommandUnknown:
if d.menubar != nil && d.menubar.active {
d.menubar.HandleEvent(ev)
}
}
case *EventKey:
if d.menubar != nil && d.menubar.active {
d.menubar.HandleEvent(ev)
}
}
}
func (d *TDesktop) AddStatusBar() *StatusBar {
_statusBar := StatusBar{
region: TRegion{
top: 0, // actually it will be always calculated for the status bar
left: 0,
w: -1, // actually it will be always calculated for the status bar
h: 1,
},
bkgColor: tcell.ColorWhite,
bkgPattern: ' ',
foreColor: tcell.ColorBlack,
}
d.statusbar = &_statusBar
return &_statusBar
}
func (d *TDesktop) SetCommandLabelText(s string) {
if d.statusbar != nil {
d.statusbar.SetCommandLabelText(s)
}
}
func (d *TDesktop) AddMenuBar() *MenuBar {
_menuBar := MenuBar{
region: TRegion{
top: 0,
left: 0,
w: -1, // actually it will be always calculated for the status bar
h: 1,
},
bkgColor: tcell.ColorWhite,
bkgPattern: ' ',
foreColor: tcell.ColorBlack,
active: false,
}
d.menubar = &_menuBar
return &_menuBar
}