| 1 |
|
| 2 |
# generic widgets for canvas dialogs |
| 3 |
# Thorsten Renk 2018 |
| 4 |
|
| 5 |
# widget definitions ############################################################## |
| 6 |
|
| 7 |
var cdlg_widget_box = { |
| 8 |
new: func (root, width, height, color, fill_color ) { |
| 9 |
var wb = { parents: [cdlg_widget_box] }; |
| 10 |
|
| 11 |
wb.width = width; |
| 12 |
wb.height = height; |
| 13 |
wb.color = color; |
| 14 |
wb.fill_color = fill_color; |
| 15 |
|
| 16 |
wb.graph = root.createChild("group", "box_widget"); |
| 17 |
|
| 18 |
#var data = [[0.0, 0.0], [0.0, height], [width, height], [width, 0.0], [0.0, 0.0]]; |
| 19 |
|
| 20 |
var data = [[0.0, 0.0], [-0.5 * width, 0.0], [-0.5*width, -height], [0.5*width, -height], [0.5*width, 0.0], [0.0, 0.0]]; |
| 21 |
|
| 22 |
wb.frame = wb.graph.createChild("path", "") |
| 23 |
.setStrokeLineWidth(2) |
| 24 |
.setColor(color) |
| 25 |
.moveTo(data[0][0], data[0][1]); |
| 26 |
for (var i = 0; (i< size(data)-1); i=i+1) |
| 27 |
{wb.frame.lineTo(data[i+1][0], data[i+1][1]);} |
| 28 |
|
| 29 |
wb.fill = wb.graph.createChild("path", "") |
| 30 |
.setStrokeLineWidth(2) |
| 31 |
.setColor(color) |
| 32 |
.setColorFill(fill_color) |
| 33 |
.moveTo(data[0][0], data[0][1]); |
| 34 |
for (var i = 0; (i< size(data)-1); i=i+1) |
| 35 |
{wb.fill.lineTo(data[i+1][0], data[i+1][1]);} |
| 36 |
|
| 37 |
return wb; |
| 38 |
}, |
| 39 |
|
| 40 |
|
| 41 |
setTranslation: func (x,y) { |
| 42 |
me.graph.setTranslation(x,y); |
| 43 |
|
| 44 |
}, |
| 45 |
|
| 46 |
setPercentageHt: func (x) { |
| 47 |
|
| 48 |
if (x > 1.0) |
| 49 |
{x = 1.0;} |
| 50 |
else if (x < 0.0) {x = 0.0;} |
| 51 |
|
| 52 |
var red_ht = me.height * x; |
| 53 |
|
| 54 |
var cmd = [canvas.Path.VG_MOVE_TO, canvas.Path.VG_LINE_TO, |
| 55 |
canvas.Path.VG_LINE_TO,canvas.Path.VG_LINE_TO,canvas.Path.VG_LINE_TO]; |
| 56 |
|
| 57 |
var draw = [0.0, 0.0, -0.5 * me.width, 0.0, -0.5*me.width, -red_ht, 0.5*me.width, -red_ht, 0.5*me.width, 0.0, 0.0, 0.0]; |
| 58 |
|
| 59 |
|
| 60 |
me.fill.setData(cmd, draw); |
| 61 |
|
| 62 |
}, |
| 63 |
|
| 64 |
setContextHelp: func (f) { |
| 65 |
|
| 66 |
me.frame.addEventListener("mouseover", func(e) { |
| 67 |
fgcommand("set-cursor", props.Node.new({'cursor':'left-right'})); |
| 68 |
f("mouseover"); |
| 69 |
}); |
| 70 |
|
| 71 |
me.frame.addEventListener("mouseout", func(e) { |
| 72 |
fgcommand("set-cursor", props.Node.new({'cursor':'inherit'})); |
| 73 |
f("mouseout"); |
| 74 |
}); |
| 75 |
|
| 76 |
me.fill.addEventListener("mouseover", func(e) { |
| 77 |
fgcommand("set-cursor", props.Node.new({'cursor':'left-right'})); |
| 78 |
f("mouseover"); |
| 79 |
}); |
| 80 |
|
| 81 |
me.fill.addEventListener("mouseout", func(e) { |
| 82 |
fgcommand("set-cursor", props.Node.new({'cursor':'inherit'})); |
| 83 |
f("mouseout"); |
| 84 |
}); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
}, |
| 89 |
|
| 90 |
|
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
# tank gauge ############################################################## |
| 96 |
|
| 97 |
var cdlg_widget_tank = { |
| 98 |
new: func (root, radius, color, fill_color) { |
| 99 |
var wtk = { parents: [cdlg_widget_tank] }; |
| 100 |
|
| 101 |
wtk.radius = radius; |
| 102 |
wtk.color = color; |
| 103 |
wtk.fill_color = fill_color; |
| 104 |
|
| 105 |
wtk.graph = root.createChild("group", "tank_widget"); |
| 106 |
|
| 107 |
var data = []; |
| 108 |
|
| 109 |
|
| 110 |
for (var i = 0; i< 33; i=i+1) |
| 111 |
{ |
| 112 |
var phi = i * 2.0 * math.pi/32.0; |
| 113 |
|
| 114 |
var x = radius * math.cos(phi); |
| 115 |
var y = radius * math.sin(phi); |
| 116 |
|
| 117 |
append(data, [x,y]); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
wtk.frame = wtk.graph.createChild("path", "") |
| 122 |
.setStrokeLineWidth(2) |
| 123 |
.setColor(color) |
| 124 |
.moveTo(data[0][0], data[0][1]); |
| 125 |
for (var i = 0; (i< size(data)-1); i=i+1) |
| 126 |
{wtk.frame.lineTo(data[i+1][0], data[i+1][1]);} |
| 127 |
|
| 128 |
wtk.fill = wtk.graph.createChild("path", "") |
| 129 |
.setStrokeLineWidth(2) |
| 130 |
.setColor(color) |
| 131 |
.setColorFill(fill_color) |
| 132 |
.moveTo(data[0][0], data[0][1]); |
| 133 |
for (var i = 0; (i< size(data)-1); i=i+1) |
| 134 |
{wtk.fill.lineTo(data[i+1][0], data[i+1][1]);} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
return wtk; |
| 139 |
}, |
| 140 |
|
| 141 |
setTranslation: func (x,y) { |
| 142 |
me.graph.setTranslation(x,y); |
| 143 |
|
| 144 |
}, |
| 145 |
|
| 146 |
setPercentage: func (x) { |
| 147 |
|
| 148 |
if (x > 1.0) |
| 149 |
{x = 1.0;} |
| 150 |
else if (x < 0.0) {x = 0.0;} |
| 151 |
|
| 152 |
var red_ht = me.radius -2.0 * me.radius * x; |
| 153 |
var arg = me.radius * me.radius - red_ht * red_ht; |
| 154 |
if (arg < 0.0) {arg = 0.0;} |
| 155 |
|
| 156 |
var xlimit = math.sqrt(arg); |
| 157 |
|
| 158 |
var draw = []; |
| 159 |
var cmd = []; |
| 160 |
|
| 161 |
for (var i = 0; i< 33; i=i+1) |
| 162 |
{ |
| 163 |
var phi = i * 2.0 * math.pi/32.0; |
| 164 |
|
| 165 |
var x = me.radius * math.cos(phi); |
| 166 |
var y = me.radius * math.sin(phi); |
| 167 |
|
| 168 |
|
| 169 |
if (y < red_ht) { y = red_ht; if (x>0.0) {x = xlimit;} else {x=-xlimit;} } |
| 170 |
|
| 171 |
append(draw,x); |
| 172 |
append(draw,y); |
| 173 |
append(cmd, canvas.Path.VG_LINE_TO); |
| 174 |
} |
| 175 |
|
| 176 |
cmd[0] = canvas.Path.VG_MOVE_TO; |
| 177 |
|
| 178 |
me.fill.setData(cmd, draw); |
| 179 |
|
| 180 |
}, |
| 181 |
|
| 182 |
|
| 183 |
setContextHelp: func (f) { |
| 184 |
|
| 185 |
me.frame.addEventListener("mouseover", func(e) { |
| 186 |
fgcommand("set-cursor", props.Node.new({'cursor':'left-right'})); |
| 187 |
f("mouseover"); |
| 188 |
}); |
| 189 |
|
| 190 |
me.frame.addEventListener("mouseout", func(e) { |
| 191 |
fgcommand("set-cursor", props.Node.new({'cursor':'inherit'})); |
| 192 |
f("mouseout"); |
| 193 |
}); |
| 194 |
|
| 195 |
me.fill.addEventListener("mouseover", func(e) { |
| 196 |
fgcommand("set-cursor", props.Node.new({'cursor':'left-right'})); |
| 197 |
f("mouseover"); |
| 198 |
}); |
| 199 |
|
| 200 |
me.fill.addEventListener("mouseout", func(e) { |
| 201 |
fgcommand("set-cursor", props.Node.new({'cursor':'inherit'})); |
| 202 |
f("mouseout"); |
| 203 |
}); |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
}, |
| 208 |
|
| 209 |
|
| 210 |
}; |
| 211 |
|
| 212 |
|
| 213 |
# property display labels ############################################################## |
| 214 |
|
| 215 |
var cdlg_widget_property_label = { |
| 216 |
new: func (root, text, text_color = nil, color = nil, fill_color = nil ) { |
| 217 |
var pl = { parents: [cdlg_widget_property_label] }; |
| 218 |
|
| 219 |
pl.text_string = text; |
| 220 |
pl.unit_string = ""; |
| 221 |
pl.unit_set = 0; |
| 222 |
pl.size = utf8.size(text); |
| 223 |
pl.limits = 0; |
| 224 |
pl.limit_upper = 1e6; |
| 225 |
pl.limit_lower = -1e6; |
| 226 |
pl.limit_violation = 0; |
| 227 |
|
| 228 |
if (text_color == nil) {text_color = [0.0, 0.0, 0.0];} |
| 229 |
pl.text_color = text_color; |
| 230 |
|
| 231 |
pl.font_scale_factor = 1.0; |
| 232 |
|
| 233 |
if (color == nil) |
| 234 |
{pl.box_mode = 0;} |
| 235 |
else |
| 236 |
{ |
| 237 |
pl.color = color; |
| 238 |
pl.box_mode = 1; |
| 239 |
} |
| 240 |
|
| 241 |
if (fill_color == nil) |
| 242 |
{ |
| 243 |
pl.box_fill = 0; |
| 244 |
} |
| 245 |
else |
| 246 |
{ |
| 247 |
pl.box_fill = 1; |
| 248 |
pl.fill_color = fill_color; |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
pl.graph = root.createChild("group", "property_label"); |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
if (pl.box_mode == 1) |
| 258 |
{ |
| 259 |
var height = 25.0; |
| 260 |
var width = 10.0 * pl.size; |
| 261 |
var data = [[0.0, -0.8 * height], [-0.5 * width, -0.8 * height], [-0.5 * width, 0.2 * height], [0.5 * width, 0.2 * height], [0.5 * width, -0.8 * height],[0.0, -0.8 * height]]; |
| 262 |
pl.box = pl.graph.createChild("path", "") |
| 263 |
.setStrokeLineWidth(2) |
| 264 |
.setColor(color) |
| 265 |
.moveTo(data[0][0], data[0][1]); |
| 266 |
for (var i = 0; (i< size(data)-1); i=i+1) |
| 267 |
{pl.box.lineTo(data[i+1][0], data[i+1][1]);} |
| 268 |
|
| 269 |
if (pl.box_fill == 1) |
| 270 |
{ |
| 271 |
pl.box.setColorFill(fill_color); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
pl.text = pl.graph.createChild("text") |
| 277 |
.setText(text) |
| 278 |
.setColor(text_color) |
| 279 |
.setFontSize(15) |
| 280 |
#.setFont("LiberationFonts/LiberationMono-Bold.ttf") |
| 281 |
.setFont("LiberationFonts/LiberationSans-Bold.ttf") |
| 282 |
.setAlignment("center-bottom") |
| 283 |
.setRotation(0.0); |
| 284 |
|
| 285 |
pl.text.enableUpdate(); |
| 286 |
|
| 287 |
pl.text.setTranslation(0.0, pl.getOffset(text)); |
| 288 |
if (pl.box_mode == 1) |
| 289 |
{ |
| 290 |
pl.box.setTranslation(0.0, -pl.getOffset(text)); |
| 291 |
} |
| 292 |
|
| 293 |
return pl; |
| 294 |
}, |
| 295 |
|
| 296 |
setTranslation: func (x,y) { |
| 297 |
me.graph.setTranslation(x,y); |
| 298 |
|
| 299 |
}, |
| 300 |
|
| 301 |
updateText: func (text) { |
| 302 |
|
| 303 |
me.text.updateText(text); |
| 304 |
}, |
| 305 |
|
| 306 |
setText: func (text) { |
| 307 |
|
| 308 |
me.text.setText(text); |
| 309 |
}, |
| 310 |
|
| 311 |
|
| 312 |
setValue: func (value) { |
| 313 |
|
| 314 |
if (me.limits == 1) |
| 315 |
{ |
| 316 |
me.check_limits(value); |
| 317 |
} |
| 318 |
me.text.updateText(me.formatValue(value)); |
| 319 |
}, |
| 320 |
|
| 321 |
formatValue: func (value) { |
| 322 |
|
| 323 |
var textString = me.formatFunction(value); |
| 324 |
return textString~me.unit_text; |
| 325 |
}, |
| 326 |
|
| 327 |
|
| 328 |
formatFunction: func (value) { |
| 329 |
|
| 330 |
return sprintf("%0.0f", value); |
| 331 |
}, |
| 332 |
|
| 333 |
|
| 334 |
setUnit: func (unit) { |
| 335 |
|
| 336 |
me.unit_text = unit; |
| 337 |
me.unit_set = 1; |
| 338 |
|
| 339 |
}, |
| 340 |
|
| 341 |
setLimits: func (lLower, lUpper) { |
| 342 |
me.limits = 1; |
| 343 |
me.limit_upper = lUpper; |
| 344 |
me.limit_lower = lLower; |
| 345 |
|
| 346 |
}, |
| 347 |
|
| 348 |
check_limits: func (value) { |
| 349 |
|
| 350 |
if ((value < me.limit_lower) or (value > me.limit_upper)) |
| 351 |
{ |
| 352 |
if (me.limit_violation == 0) |
| 353 |
{ |
| 354 |
me.text.setColor(1.0, 0.0, 0.0); |
| 355 |
me.limit_violation = 1; |
| 356 |
} |
| 357 |
} |
| 358 |
else |
| 359 |
{ |
| 360 |
if (me.limit_violation == 1) |
| 361 |
{ |
| 362 |
me.text.setColor(me.text_color); |
| 363 |
me.limit_violation = 0; |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
}, |
| 368 |
|
| 369 |
setFont: func (font) { |
| 370 |
|
| 371 |
me.text.setFont(font); |
| 372 |
}, |
| 373 |
|
| 374 |
setFontSize: func (size) { |
| 375 |
|
| 376 |
me.font_scale_factor = size/15.0; |
| 377 |
me.text.setFontSize(size); |
| 378 |
}, |
| 379 |
|
| 380 |
setScale: func (x,y = nil) { |
| 381 |
|
| 382 |
me.graph.setScale(x,y); |
| 383 |
}, |
| 384 |
|
| 385 |
setBoxScale: func (x,y = nil) { |
| 386 |
|
| 387 |
if (me.box_mode == 0) {return;} |
| 388 |
me.box.setScale(x,y); |
| 389 |
}, |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
getOffset: func (string) { |
| 394 |
return 0.0; |
| 395 |
var flag = 0; |
| 396 |
for (var i = 0; i < utf8.size(string); i=i+1) |
| 397 |
{ |
| 398 |
var char = utf8.strc(string, i); |
| 399 |
|
| 400 |
if ((char == "y") or (char == "g") or (char == "j") or (char == "p") or (char == "q")) |
| 401 |
{ |
| 402 |
flag == 1; break; |
| 403 |
} |
| 404 |
} |
| 405 |
if (flag == 0) {return -2.0;} |
| 406 |
else {return 0.0;} |
| 407 |
}, |
| 408 |
|
| 409 |
}; |
| 410 |
|
| 411 |
# infobox ############################################################## |
| 412 |
|
| 413 |
var cdlg_widget_infobox = { |
| 414 |
new: func (root, width, title, texts, corner_radius = 0.0, frame_color = nil, title_color = nil, title_fill = nil, text_color = nil, text_fill = nil) { |
| 415 |
|
| 416 |
var ib = { parents: [cdlg_widget_infobox] }; |
| 417 |
|
| 418 |
ib.width = width; |
| 419 |
ib.title = title; |
| 420 |
ib.texts = texts; |
| 421 |
|
| 422 |
ib.unit = ""; |
| 423 |
|
| 424 |
if (title_color == nil) {title_color = [0.0, 0.0, 0.0];} |
| 425 |
if (text_color == nil) {text_color = [0.0, 0.0, 0.0];} |
| 426 |
if (frame_color == nil) {frame_color = [0.0, 0.0, 0.0];} |
| 427 |
|
| 428 |
ib.title_color = title_color; |
| 429 |
ib.title_fill = title_fill; |
| 430 |
ib.text_color = text_color; |
| 431 |
ib.text_fill = text_fill; |
| 432 |
ib.frame_color = frame_color; |
| 433 |
|
| 434 |
ib.font_size = 15; |
| 435 |
ib.num_lines = size(texts); |
| 436 |
ib.num_columns = size(texts[0]); |
| 437 |
ib.font_height = 25.0; |
| 438 |
|
| 439 |
ib.height = (ib.num_lines + 1) * ib.font_height; |
| 440 |
ib.corner_radius = corner_radius; |
| 441 |
|
| 442 |
|
| 443 |
ib.graph = root.createChild("group", "infobox"); |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
var data = []; |
| 448 |
var point = [0.0, -0.7* ib.font_height]; append(data, point); |
| 449 |
|
| 450 |
point = [ib.width * 0.5 - ib.corner_radius, - 0.7* ib.font_height]; append(data, point); |
| 451 |
point = [ib.width * 0.5 - ib.corner_radius * 0.617, - 0.7* ib.font_height + ib.corner_radius * 0.076]; append(data, point); |
| 452 |
point = [ib.width * 0.5 - ib.corner_radius * 0.293, - 0.7* ib.font_height + ib.corner_radius * 0.293]; append(data, point); |
| 453 |
point = [ib.width * 0.5 - ib.corner_radius * 0.076, - 0.7* ib.font_height + ib.corner_radius * 0.617]; append(data, point); |
| 454 |
point = [ib.width * 0.5, - 0.7* ib.font_height + ib.corner_radius]; append(data, point); |
| 455 |
|
| 456 |
point = [ib.width * 0.5, 0.3 * ib.font_height]; append(data, point); |
| 457 |
point = [-ib.width * 0.5, 0.3 * ib.font_height]; append(data, point); |
| 458 |
|
| 459 |
point = [-ib.width * 0.5, -0.7* ib.font_height + ib.corner_radius]; append(data, point); |
| 460 |
point = [-ib.width * 0.5 + ib.corner_radius * 0.076, -0.7* ib.font_height + ib.corner_radius * 0.617]; append(data, point); |
| 461 |
point = [-ib.width * 0.5 + ib.corner_radius * 0.293, -0.7* ib.font_height + ib.corner_radius * 0.293]; append(data, point); |
| 462 |
point = [-ib.width * 0.5 + ib.corner_radius * 0.617, -0.7* ib.font_height + ib.corner_radius * 0.076]; append(data, point); |
| 463 |
point = [-ib.width * 0.5 + ib.corner_radius, -0.7* ib.font_height]; append(data, point); |
| 464 |
point = [0.0, - 0.7 * ib.font_height]; append(data, point); |
| 465 |
|
| 466 |
ib.title_frame = ib.graph.createChild("path", "") |
| 467 |
.setStrokeLineWidth(2) |
| 468 |
.setColor(ib.frame_color) |
| 469 |
.moveTo(data[0][0], data[0][1]); |
| 470 |
for (var i = 0; (i< size(data)-1); i=i+1) |
| 471 |
{ib.title_frame.lineTo(data[i+1][0], data[i+1][1]);} |
| 472 |
|
| 473 |
if (ib.title_fill != nil) |
| 474 |
{ |
| 475 |
ib.title_frame.setColorFill(ib.title_fill); |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
data = []; |
| 480 |
|
| 481 |
|
| 482 |
point = [0.0, 0.3* ib.font_height]; append(data, point); |
| 483 |
point = [ib.width * 0.5, 0.3 * ib.font_height]; append(data, point); |
| 484 |
|
| 485 |
point = [ib.width * 0.5, 10.0 + ib.num_lines * ib.font_height - ib.corner_radius]; append(data, point); |
| 486 |
point = [ib.width * 0.5 - ib.corner_radius * 0.293, 10.0 + ib.num_lines * ib.font_height - ib.corner_radius * 0.293]; append(data, point); |
| 487 |
point = [ib.width * 0.5 - ib.corner_radius, 10.0 + ib.num_lines * ib.font_height]; append(data, point); |
| 488 |
|
| 489 |
|
| 490 |
point = [-ib.width * 0.5 + ib.corner_radius, 10.0 + ib.num_lines * ib.font_height]; append(data, point); |
| 491 |
point = [-ib.width * 0.5 + ib.corner_radius * 0.293, 10.0 + ib.num_lines * ib.font_height - ib.corner_radius * 0.293]; append(data, point); |
| 492 |
point = [-ib.width * 0.5, 10.0 + ib.num_lines * ib.font_height - ib.corner_radius]; append(data, point); |
| 493 |
|
| 494 |
point = [-ib.width * 0.5, 0.3 * ib.font_height]; append(data, point); |
| 495 |
point = [0.0, 0.3 * ib.font_height]; append(data, point); |
| 496 |
|
| 497 |
ib.text_frame = ib.graph.createChild("path", "") |
| 498 |
.setStrokeLineWidth(2) |
| 499 |
.setColor(ib.frame_color) |
| 500 |
.moveTo(data[0][0], data[0][1]); |
| 501 |
for (var i = 0; (i< size(data)-1); i=i+1) |
| 502 |
{ib.text_frame.lineTo(data[i+1][0], data[i+1][1]);} |
| 503 |
|
| 504 |
if (ib.text_fill != nil) |
| 505 |
{ |
| 506 |
ib.text_frame.setColorFill(ib.text_fill); |
| 507 |
} |
| 508 |
|
| 509 |
var offset = me.getOffset(title); |
| 510 |
|
| 511 |
ib.title_text = ib.graph.createChild("text") |
| 512 |
.setText(title) |
| 513 |
.setColor(text_color) |
| 514 |
.setFontSize(15) |
| 515 |
.setFont("LiberationFonts/LiberationSans-Bold.ttf") |
| 516 |
.setAlignment("center-bottom") |
| 517 |
.setTranslation(0, offset) |
| 518 |
.setRotation(0.0); |
| 519 |
|
| 520 |
ib.texts = []; |
| 521 |
ib.values = []; |
| 522 |
|
| 523 |
for (var i = 0; i< ib.num_lines; i=i+1) |
| 524 |
{ |
| 525 |
|
| 526 |
var translation = 0.0; |
| 527 |
var alignment = "center-bottom"; |
| 528 |
|
| 529 |
if (ib.num_columns == 2) |
| 530 |
{ |
| 531 |
translation = -0.45 * ib.width; |
| 532 |
alignment = "left-bottom"; |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
var tmp_text = ib.graph.createChild("text") |
| 538 |
.setText(texts[i][0]) |
| 539 |
.setColor(text_color) |
| 540 |
.setFontSize(15) |
| 541 |
.setFont("LiberationFonts/LiberationSans-Bold.ttf") |
| 542 |
.setAlignment(alignment) |
| 543 |
.setTranslation(translation, 5.0 + (i+1) * ib.font_height) |
| 544 |
.setRotation(0.0); |
| 545 |
|
| 546 |
tmp_text.enableUpdate(); |
| 547 |
|
| 548 |
if (ib.num_columns == 2) |
| 549 |
{ |
| 550 |
append (ib.texts, tmp_text); |
| 551 |
} |
| 552 |
else |
| 553 |
{ |
| 554 |
append (ib.values, tmp_text); |
| 555 |
} |
| 556 |
|
| 557 |
if (ib.num_columns == 2) |
| 558 |
{ |
| 559 |
var tmp_value = ib.graph.createChild("text") |
| 560 |
.setText(texts[i][1]) |
| 561 |
.setColor(text_color) |
| 562 |
.setFontSize(15) |
| 563 |
.setFont("LiberationFonts/LiberationSans-Bold.ttf") |
| 564 |
.setAlignment("left-bottom") |
| 565 |
.setTranslation(0.05 * ib.width, 5.0 + (i+1) * ib.font_height) |
| 566 |
.setRotation(0.0); |
| 567 |
|
| 568 |
tmp_value.enableUpdate(); |
| 569 |
|
| 570 |
append (ib.values, tmp_value); |
| 571 |
|
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
return ib; |
| 580 |
|
| 581 |
}, |
| 582 |
|
| 583 |
setTranslation: func (x,y) { |
| 584 |
|
| 585 |
me.graph.setTranslation(x,y); |
| 586 |
|
| 587 |
}, |
| 588 |
|
| 589 |
|
| 590 |
setText: func (i, text) { |
| 591 |
|
| 592 |
me.texts[i].updateText(text); |
| 593 |
|
| 594 |
}, |
| 595 |
|
| 596 |
setValueText: func (i, text) { |
| 597 |
|
| 598 |
me.values[i].updateText(text); |
| 599 |
|
| 600 |
}, |
| 601 |
|
| 602 |
setUnit: func (unit) { |
| 603 |
|
| 604 |
me.unit = unit; |
| 605 |
|
| 606 |
}, |
| 607 |
|
| 608 |
setValue: func (i, value) { |
| 609 |
|
| 610 |
var text = me.formatFunction(value)~me.unit; |
| 611 |
|
| 612 |
me.values[i].updateText(text); |
| 613 |
|
| 614 |
|
| 615 |
}, |
| 616 |
|
| 617 |
formatFunction: func (value) { |
| 618 |
|
| 619 |
return sprintf("%d", value); |
| 620 |
|
| 621 |
}, |
| 622 |
|
| 623 |
getOffset: func (string) { |
| 624 |
var flag = 0; |
| 625 |
for (var i = 0; i < utf8.size(string); i=i+1) |
| 626 |
{ |
| 627 |
var char = utf8.strc(string, i); |
| 628 |
#print (char); |
| 629 |
|
| 630 |
if ((char == 112) or (char == 121) or (char == 106) or (char == 103) or (char == 113)) |
| 631 |
{ |
| 632 |
flag = 1; break; |
| 633 |
} |
| 634 |
} |
| 635 |
if (flag == 1) {return 4.0;} |
| 636 |
else {return 0.0;} |
| 637 |
}, |
| 638 |
|
| 639 |
|
| 640 |
}; |
| 641 |
|
| 642 |
# image stack ############################################################## |
| 643 |
|
| 644 |
var cdlg_widget_img_stack = { |
| 645 |
|
| 646 |
new: func (root, stack, width, height, button_flag = 0) { |
| 647 |
var is = { parents: [cdlg_widget_img_stack] }; |
| 648 |
|
| 649 |
is.root = root; |
| 650 |
is.width = width; |
| 651 |
is.height = height; |
| 652 |
is.index = 0; |
| 653 |
is.button_flag = button_flag; |
| 654 |
|
| 655 |
is.n_elements = size(stack); |
| 656 |
|
| 657 |
is.stack = []; |
| 658 |
is.graph = root.createChild("group", "stack"); |
| 659 |
|
| 660 |
for (var i = 0; i< is.n_elements; i = i+1) |
| 661 |
{ |
| 662 |
|
| 663 |
|
| 664 |
var tmp_image = is.graph.createChild("image") |
| 665 |
.setFile(stack[i]); |
| 666 |
|
| 667 |
tmp_image.setVisible(0); |
| 668 |
|
| 669 |
append(is.stack, tmp_image); |
| 670 |
} |
| 671 |
|
| 672 |
is.stack[0].setVisible(1); |
| 673 |
|
| 674 |
|
| 675 |
is.graph.addEventListener("click", func() { |
| 676 |
|
| 677 |
if (is.button_flag == 0) |
| 678 |
{is.increment();} |
| 679 |
else if (is.button_flag == 1) |
| 680 |
{is.depress();} |
| 681 |
|
| 682 |
is.f(); |
| 683 |
}); |
| 684 |
|
| 685 |
return is; |
| 686 |
|
| 687 |
}, |
| 688 |
|
| 689 |
setTranslation: func (x,y) { |
| 690 |
|
| 691 |
|
| 692 |
me.graph.setTranslation(x,y); |
| 693 |
|
| 694 |
}, |
| 695 |
|
| 696 |
|
| 697 |
increment: func { |
| 698 |
|
| 699 |
me.index += 1; |
| 700 |
|
| 701 |
if (me.index == me.n_elements) {me.index = 0;} |
| 702 |
|
| 703 |
for (var i=0; i< me.n_elements; i=i+1) |
| 704 |
{ |
| 705 |
if (me.index == i) |
| 706 |
{ |
| 707 |
me.stack[i].setVisible(1); |
| 708 |
} |
| 709 |
else |
| 710 |
{ |
| 711 |
me.stack[i].setVisible(0); |
| 712 |
} |
| 713 |
|
| 714 |
} |
| 715 |
|
| 716 |
}, |
| 717 |
|
| 718 |
set_index: func (index) { |
| 719 |
|
| 720 |
me.index = index; |
| 721 |
|
| 722 |
if ((me.index > me.n_elements) or (me.index < 0)) {return;} |
| 723 |
|
| 724 |
for (var i=0; i< me.n_elements; i=i+1) |
| 725 |
{ |
| 726 |
if (me.index == i) |
| 727 |
{ |
| 728 |
me.stack[i].setVisible(1); |
| 729 |
} |
| 730 |
else |
| 731 |
{ |
| 732 |
me.stack[i].setVisible(0); |
| 733 |
} |
| 734 |
|
| 735 |
} |
| 736 |
|
| 737 |
}, |
| 738 |
|
| 739 |
depress: func { |
| 740 |
|
| 741 |
me.index = 1; |
| 742 |
me.stack[1].setVisible(1); |
| 743 |
me.stack[0].setVisible(0); |
| 744 |
|
| 745 |
settimer ( func { |
| 746 |
me.index = 0; |
| 747 |
me.stack[1].setVisible(0); |
| 748 |
me.stack[0].setVisible(1); |
| 749 |
|
| 750 |
}, 0.2); |
| 751 |
|
| 752 |
}, |
| 753 |
|
| 754 |
setContextHelp: func (f) { |
| 755 |
|
| 756 |
me.graph.addEventListener("mouseover", func(e) { |
| 757 |
fgcommand("set-cursor", props.Node.new({'cursor':'left-right'})); |
| 758 |
f("mouseover"); |
| 759 |
}); |
| 760 |
|
| 761 |
me.graph.addEventListener("mouseout", func(e) { |
| 762 |
fgcommand("set-cursor", props.Node.new({'cursor':'inherit'})); |
| 763 |
f("mouseout"); |
| 764 |
}); |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
}, |
| 769 |
|
| 770 |
f: func { |
| 771 |
|
| 772 |
|
| 773 |
return; |
| 774 |
|
| 775 |
}, |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
}; |
| 780 |
|
| 781 |
# analog gauge ############################################################## |
| 782 |
|
| 783 |
var cdlg_widget_analog_gauge = { |
| 784 |
new: func (root, gauge_bg, gauge_needle , width, height) { |
| 785 |
var ag = { parents: [cdlg_widget_analog_gauge] }; |
| 786 |
|
| 787 |
ag.graph = root.createChild("group", "analog gauge"); |
| 788 |
|
| 789 |
ag.gauge_background = ag.graph.createChild("image") |
| 790 |
.setFile(gauge_bg); |
| 791 |
|
| 792 |
ag.gauge_needle = ag.graph.createChild("image") |
| 793 |
.setFile(gauge_needle); |
| 794 |
|
| 795 |
ag.gauge_needle.setCenter(127,127); |
| 796 |
|
| 797 |
return ag; |
| 798 |
}, |
| 799 |
|
| 800 |
setTranslation: func (x,y) { |
| 801 |
|
| 802 |
me.graph.setTranslation(x,y); |
| 803 |
|
| 804 |
}, |
| 805 |
|
| 806 |
|
| 807 |
setAngle: func (angle) { |
| 808 |
|
| 809 |
me.gauge_needle.setRotation(angle); |
| 810 |
|
| 811 |
}, |
| 812 |
|
| 813 |
}; |
| 814 |
|
| 815 |
|
| 816 |
# clickspots ############################################################## |
| 817 |
|
| 818 |
var cdlg_clickspot = { |
| 819 |
|
| 820 |
new: func (x,y,rw,rh,tab,type) { |
| 821 |
var cs = { parents: [cdlg_clickspot] }; |
| 822 |
|
| 823 |
cs.x = x; |
| 824 |
cs.y = y; |
| 825 |
cs.rw = rw; |
| 826 |
cs.rh = rh; |
| 827 |
cs.fraction_up = 0.0; |
| 828 |
cs.fraction_right = 0.0; |
| 829 |
cs.tab = tab; |
| 830 |
cs.type = type; |
| 831 |
|
| 832 |
return cs; |
| 833 |
}, |
| 834 |
|
| 835 |
check_event : func (click_x, click_y) { |
| 836 |
|
| 837 |
if (me.type = "rect") |
| 838 |
{ |
| 839 |
if ((math.abs(click_x - me.x) < me.rw) and (math.abs(click_y - me.y) < me.rh)) { |
| 840 |
me.update_fractions (click_x, click_y); |
| 841 |
me.f(); |
| 842 |
return 1; |
| 843 |
} |
| 844 |
} |
| 845 |
else if (me.type = "circle") |
| 846 |
{ |
| 847 |
var click_r = math.sqrt((click_x - me.x) * (click_x - me.x) + (click_y - me.y) * (click_y - me.y)); |
| 848 |
|
| 849 |
if (click_r < me.rw) |
| 850 |
{ |
| 851 |
me.update_fractions (click_x, click_y); |
| 852 |
me.f(); |
| 853 |
return 1; |
| 854 |
} |
| 855 |
} |
| 856 |
return 0; |
| 857 |
}, |
| 858 |
|
| 859 |
update_fractions: func (click_x, click_y) { |
| 860 |
|
| 861 |
var y_rel = (click_y - me.y); |
| 862 |
var x_rel = (click_x - me.x); |
| 863 |
me.fraction_up = (-y_rel + me.rw)/(2.0 * me.rw); |
| 864 |
me.fraction_right = (x_rel + me.rw)/(2.0 * me.rw); |
| 865 |
|
| 866 |
}, |
| 867 |
|
| 868 |
get_fraction_up: func { |
| 869 |
|
| 870 |
return me.fraction_up; |
| 871 |
|
| 872 |
}, |
| 873 |
|
| 874 |
get_fraction_right: func { |
| 875 |
|
| 876 |
return me.fraction_right; |
| 877 |
|
| 878 |
}, |
| 879 |
|
| 880 |
f: func { |
| 881 |
|
| 882 |
return; |
| 883 |
|
| 884 |
}, |
| 885 |
|
| 886 |
}; |
| 887 |
|