/
ui_div_dialog.go
executable file
·143 lines (112 loc) · 3.08 KB
/
ui_div_dialog.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
143
/*
Copyright 2023 Milan Suk
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this db except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import "errors"
func (ui *Ui) Dialog_close() {
ui.CloseAndAbove(ui.GetCall())
}
func (ui *Ui) Dialog_closeName(name string) {
ui.CloseName(name)
}
func (ui *Ui) Dialog_end() {
lv := ui.GetCall()
//close dialog
if lv.call.enableInput && !ui.touch.IsScrollOrResizeActive() {
winRect, _ := ui.win.GetScreenCoord()
outside := winRect.Inside(ui.win.io.touch.pos) && !lv.base.canvas.Inside(ui.win.io.touch.pos)
if (ui.win.io.touch.end && outside) || ui.win.io.keys.esc {
ui.touch.Reset()
ui.CloseAndAbove(lv)
ui.win.io.keys.esc = false
}
}
ui.renderEnd(true)
ui.buff.DialogEnd()
err := ui.EndCall()
if err != nil {
lv.call.data.app.AddLogErr(err)
}
lv = ui.GetCall()
ui.buff.AddCrop(lv.call.CropWithScroll(ui.win))
}
func (ui *Ui) Dialog_open(name string, tp uint8) bool {
lv := ui.GetCall()
//name
if len(name) == 0 {
return false
}
//find
act := ui.FindDialog(name)
if act != nil {
lv.call.data.app.AddLogErr(errors.New("dialog already opened"))
return false //already open
}
//coord
var src_coordMoveCut OsV4
switch tp {
case 1:
if lv.call.lastChild != nil {
src_coordMoveCut = lv.call.lastChild.crop
} else {
src_coordMoveCut = lv.call.crop
}
case 2:
src_coordMoveCut = OsV4{Start: ui.win.io.touch.pos, Size: OsV2{1, 1}}
}
//add
ui.AddDialog(name, src_coordMoveCut, ui.win)
ui.touch.Reset()
ui.drag.group = ""
ui.win.io.ResetTouchAndKeys()
ui.edit.setFirstEditbox = true
return true
}
func (ui *Ui) Dialog_startEx(name string, drawBack bool, greySurround bool) bool {
lv := ui.GetCall()
//name
if len(name) == 0 {
return false
}
//find
lev := ui.FindDialog(name)
if lev == nil {
return false //dialog not open, which is NOT error
}
if lev.use == 1 {
lv.call.data.app.AddLogErr(errors.New("dialog already drawn into"))
return false
}
lev.use = 1
/*if lev.src_coordMoveCut.Size.X > 1 || lev.src_coordMoveCut.Size.Y > 1 { //for tp==1
if lv.call.lastChild != nil {
lev.src_coordMoveCut = lv.call.lastChild.crop
} else {
lev.src_coordMoveCut = lv.call.crop
}
}*/
//coord
winRect, _ := ui.win.GetScreenCoord()
coord := lev.base.GetLevelSize(winRect, ui.win)
coord = lev.GetCoord(coord, winRect)
lev.base.canvas = coord
lev.base.crop = coord
lev.greySurround = greySurround
ui.StartCall(lev)
ui.renderStart(0, 0, 1, 1)
//a = OsTime()
ui.buff.DialogStart(coord, drawBack, ui.FindDialogPos(name)) //rewrite buffer with background
return true //active/open
}
func (ui *Ui) Dialog_start(name string) bool {
return ui.Dialog_startEx(name, true, true)
}