/
ui_div_info.go
executable file
·308 lines (250 loc) · 8.16 KB
/
ui_div_info.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
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 "math"
const (
SA_DIV_GET_uid = 0
SA_DIV_GET_cell = 1
SA_DIV_GET_layoutWidth = 2
SA_DIV_GET_layoutHeight = 3
SA_DIV_GET_screenWidth = 4
SA_DIV_GET_screenHeight = 5
SA_DIV_GET_layoutStartX = 6
SA_DIV_GET_layoutStartY = 7
SA_DIV_GET_touch = 8
SA_DIV_GET_touchX = 9
SA_DIV_GET_touchY = 10
SA_DIV_GET_touchOver = 11
SA_DIV_GET_touchOverScroll = 12
SA_DIV_GET_touchInside = 13
SA_DIV_GET_touchStart = 14
SA_DIV_GET_touchWheel = 15
SA_DIV_GET_touchClicks = 16
SA_DIV_GET_touchForce = 17
SA_DIV_GET_touchActive = 18
SA_DIV_GET_touchEnd = 19
SA_DIV_GET_touchCol = 20
SA_DIV_GET_touchRow = 21
SA_DIV_GET_startCol = 22
SA_DIV_GET_startRow = 23
SA_DIV_GET_endCol = 24
SA_DIV_GET_endRow = 25
SA_DIV_GET_scrollVpos = 26
SA_DIV_GET_scrollHpos = 27
SA_DIV_GET_scrollVshow = 28
SA_DIV_GET_scrollHshow = 29
SA_DIV_GET_scrollVnarrow = 30
SA_DIV_GET_scrollHnarrow = 31
)
const (
SA_DIV_SET_touch_enable = 0
SA_DIV_SET_scrollOnScreen = 1
SA_DIV_SET_copyCols = 2
SA_DIV_SET_copyRows = 3
SA_DIV_SET_attachScrollH = 4
SA_DIV_SET_attachScrollV = 5
SA_DIV_SET_scrollVpos = 26
SA_DIV_SET_scrollHpos = 27
SA_DIV_SET_scrollVshow = 28
SA_DIV_SET_scrollHshow = 29
SA_DIV_SET_scrollVnarrow = 30
SA_DIV_SET_scrollHnarrow = 31
)
func (ui *Ui) DivInfo_get(cmd uint8, uid float64) float64 {
lv := ui.GetCall()
div := lv.call.FindUid(uid)
if div == nil {
return -1
}
switch cmd {
case SA_DIV_GET_uid:
return math.Float64frombits(div.GetHash())
case SA_DIV_GET_cell:
return float64(ui.win.Cell())
case SA_DIV_GET_layoutWidth:
return float64(div.canvas.Size.X) / float64(ui.win.Cell())
case SA_DIV_GET_layoutHeight:
return float64(div.canvas.Size.Y) / float64(ui.win.Cell())
case SA_DIV_GET_screenWidth:
return float64(div.crop.Size.X) / float64(ui.win.Cell())
case SA_DIV_GET_screenHeight:
return float64(div.crop.Size.Y) / float64(ui.win.Cell())
case SA_DIV_GET_layoutStartX:
return float64(div.data.scrollH.GetWheel()) / float64(ui.win.Cell())
//return float64(div.crop.Start.X-div.canvas.Start.X) / float64(ui.win.Cell())
case SA_DIV_GET_layoutStartY:
return float64(div.data.scrollV.GetWheel()) / float64(ui.win.Cell())
//return float64(div.crop.Start.Y-div.canvas.Start.Y) / float64(ui.win.Cell())
case SA_DIV_GET_touch:
return OsTrnFloat(div.enableInput, 1, 0)
case SA_DIV_GET_touchX:
rpos := div.GetRelativePos(ui.win.io.touch.pos)
return float64(rpos.X) / float64(div.canvas.Size.X)
case SA_DIV_GET_touchY:
rpos := div.GetRelativePos(ui.win.io.touch.pos)
return float64(rpos.Y) / float64(div.canvas.Size.Y)
case SA_DIV_GET_touchOver:
return OsTrnFloat(div.IsOver(ui), 1, 0)
case SA_DIV_GET_touchOverScroll:
return OsTrnFloat(div.IsOverScroll(ui), 1, 0)
case SA_DIV_GET_touchInside:
return OsTrnFloat(div.IsTouchInside(ui), 1, 0)
case SA_DIV_GET_touchStart:
if div.enableInput {
return OsTrnFloat(ui.win.io.touch.start, 1, 0)
} else {
return 0
}
case SA_DIV_GET_touchWheel:
if div.enableInput {
return float64(ui.win.io.touch.wheel)
} else {
return 0
}
case SA_DIV_GET_touchClicks:
if div.enableInput {
return float64(ui.win.io.touch.numClicks)
} else {
return 0
}
case SA_DIV_GET_touchForce:
if div.enableInput {
return OsTrnFloat(ui.win.io.touch.rm, 1, 0)
} else {
return 0
}
case SA_DIV_GET_touchActive:
return OsTrnFloat(div.IsTouchActive(ui), 1, 0)
case SA_DIV_GET_touchEnd:
return OsTrnFloat(div.IsTouchEnd(ui), 1, 0)
case SA_DIV_GET_touchCol:
return float64(div.data.cols.GetCloseCell(div.GetRelativePos(ui.win.io.touch.pos).X))
case SA_DIV_GET_touchRow:
return float64(div.data.rows.GetCloseCell(div.GetRelativePos(ui.win.io.touch.pos).Y))
case SA_DIV_GET_startCol:
return float64(div.data.cols.GetCloseCell(div.GetRelativePos(div.crop.Start).X))
case SA_DIV_GET_startRow:
return float64(div.data.rows.GetCloseCell(div.GetRelativePos(div.crop.Start).Y))
case SA_DIV_GET_endCol:
return float64(div.data.cols.GetCloseCell(div.GetRelativePos(div.crop.End()).X))
case SA_DIV_GET_endRow:
return float64(div.data.rows.GetCloseCell(div.GetRelativePos(div.crop.End()).Y))
case SA_DIV_GET_scrollVpos:
return float64(div.data.scrollV.GetWheel()) / float64(ui.win.Cell())
case SA_DIV_GET_scrollHpos:
return float64(div.data.scrollH.GetWheel()) / float64(ui.win.Cell())
case SA_DIV_GET_scrollVshow:
return OsTrnFloat(div.data.scrollV.show, 1, 0)
case SA_DIV_GET_scrollHshow:
return OsTrnFloat(div.data.scrollH.show, 1, 0)
case SA_DIV_GET_scrollVnarrow:
return OsTrnFloat(div.data.scrollV.narrow, 1, 0)
case SA_DIV_GET_scrollHnarrow:
return OsTrnFloat(div.data.scrollH.narrow, 1, 0)
}
return -1
}
func (ui *Ui) DivInfo_set(cmd uint8, val float64, uid float64) float64 {
lv := ui.GetCall()
div := lv.call.FindUid(uid)
if div == nil {
return -1
}
switch cmd {
case SA_DIV_SET_touch_enable:
bck := div.touch_enabled
div.touch_enabled = OsTrnBool(val > 0, true, false)
return OsTrnFloat(bck, 1, 0)
case SA_DIV_SET_scrollVpos:
bck := float64(div.data.scrollV.GetWheel()) / float64(ui.win.Cell())
div.data.scrollV.wheel = int(val * float64(ui.win.Cell()))
return bck
case SA_DIV_SET_scrollHpos:
bck := float64(div.data.scrollH.GetWheel()) / float64(ui.win.Cell())
div.data.scrollH.wheel = int(val * float64(ui.win.Cell()))
return bck
case SA_DIV_SET_scrollVshow:
bck := div.data.scrollV.show
div.data.scrollV.show = OsTrnBool(val > 0, true, false)
return OsTrnFloat(bck, 1, 0)
case SA_DIV_SET_scrollHshow:
bck := div.data.scrollH.show
div.data.scrollH.show = OsTrnBool(val > 0, true, false)
return OsTrnFloat(bck, 1, 0)
case SA_DIV_SET_scrollVnarrow:
bck := div.data.scrollV.narrow
div.data.scrollV.narrow = OsTrnBool(val > 0, true, false)
return OsTrnFloat(bck, 1, 0)
case SA_DIV_SET_scrollHnarrow:
bck := div.data.scrollH.narrow
div.data.scrollH.narrow = OsTrnBool(val > 0, true, false)
return OsTrnFloat(bck, 1, 0)
case SA_DIV_SET_scrollOnScreen:
bck := div.data.scrollOnScreen
div.data.scrollOnScreen = OsTrnBool(val > 0, true, false)
return OsTrnFloat(bck, 1, 0)
case SA_DIV_SET_copyCols:
src := div.FindUid(val)
if src != nil {
div.data.cols.CopySub(&src.data.cols, 0, len(src.data.cols.outputs), ui.win.Cell())
return 1
}
return -1
case SA_DIV_SET_copyRows:
src := div.FindUid(val)
if src != nil {
div.data.rows.CopySub(&src.data.rows, 0, len(src.data.rows.outputs), ui.win.Cell())
return 1
}
return -1
case SA_DIV_SET_attachScrollH:
src := div.FindUid(val)
if src != nil {
div.data.scrollH.attach = &src.data.scrollH
src.data.scrollH.attach = &div.data.scrollH
return 1
}
return -1
case SA_DIV_SET_attachScrollV:
src := div.FindUid(val)
if src != nil {
div.data.scrollV.attach = &src.data.scrollV
src.data.scrollV.attach = &div.data.scrollV
return 1
}
return -1
}
return -1
}
func (ui *Ui) DivRange_Hor(itemSize float64) (int, int) {
div := ui.GetCall().call
wheel := float64(div.data.scrollH.GetWheel()) / float64(ui.win.Cell())
screen := float64(div.crop.Size.X) / float64(ui.win.Cell())
s := wheel / itemSize
e := (wheel + screen) / itemSize
if e > float64(int(e)) {
e++
}
return int(s), int(e)
}
func (ui *Ui) DivRange_Ver(itemSize float64) (int, int) {
div := ui.GetCall().call
wheel := float64(div.data.scrollV.GetWheel()) / float64(ui.win.Cell())
screen := float64(div.crop.Size.Y) / float64(ui.win.Cell())
s := wheel / itemSize
e := (wheel + screen) / itemSize
if e > float64(int(e)) {
e++
}
return int(s), int(e)
}