_osd.tcl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. namespace eval osd {
  2. variable default_color "0x7090aae8 0xa0c0dde8 0x90b0cce8 0xc0e0ffe8"
  3. variable error_color "0xaa0000e8 0xdd0000e8 0xcc0000e8 0xff0000e8"
  4. variable warning_color "0xaa6600e8 0xdd9900e8 0xcc8800e8 0xffaa00e8"
  5. set_help_text show_osd \
  6. {Give an overview of all currently defined OSD elements and their properties.
  7. This is mainly useful to debug a OSD related script.}
  8. proc show_osd {{widgets ""}} {
  9. set result ""
  10. if {$widgets eq ""} {
  11. # all widgets
  12. set widgets [osd info]
  13. }
  14. foreach widget $widgets {
  15. append result "$widget\n"
  16. foreach property [osd info $widget] {
  17. if {[catch {set value [osd info $widget $property]}]} {
  18. set value "--error--"
  19. }
  20. append result " $property $value\n"
  21. }
  22. }
  23. return $result
  24. }
  25. # this can display only one message at a time, the previous message
  26. # will get overwritten by a new one
  27. proc display_message {message {category info}} {
  28. variable default_color
  29. variable error_color
  30. variable warning_color
  31. switch -- $category {
  32. "info" {set bg_color $default_color}
  33. "progress" {set bg_color $default_color}
  34. "warning" {set bg_color $warning_color}
  35. "error" {set bg_color $error_color }
  36. "default" {error "Invalid category: $category"}
  37. }
  38. osd_widgets::text_box osd_display_message \
  39. -text $message \
  40. -textrgba 0xffffffff \
  41. -textsize 6 \
  42. -rgba $bg_color \
  43. -x 3 -y 12 -z 5 -w 314 \
  44. -bordersize 0.5 \
  45. -borderrgba 0x000000ff \
  46. -clip true \
  47. -scaled true \
  48. -suppressErrors true
  49. }
  50. proc is_cursor_in {widget} {
  51. set x 2; set y 2
  52. catch {lassign [osd info $widget -mousecoord] x y}
  53. expr {0 <= $x && $x <= 1 && 0 <= $y && $y <= 1}
  54. }
  55. # only export stuff that is useful in other scripts or for the console user
  56. namespace export show_osd
  57. namespace export display_message
  58. namespace export is_cursor_in
  59. };# namespace osd
  60. # only import stuff to global that is useful outside of scripts (i.e. for the console user)
  61. namespace import osd::show_osd