tabbed_machine_view.tcl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # This script visualizes with 'tabs' in the OSD the different running
  2. # machines in openMSX.
  3. # It only shows when there is more than one machine currently running.
  4. # Because of that, it shouldn't be necessary to turn it off.
  5. #
  6. # Feel free to tune/improve the color scheme :)
  7. # TODO:
  8. # - needs events to know when a machine got deleted or created... now only
  9. # updates when there was a switch...
  10. # (Luckily, that is very often... but not enough!)
  11. namespace eval tabbed_machine_view {
  12. variable curtab_bgcolor 0x4040D0C0
  13. variable curtab_text_color 0xFFFFFF
  14. variable inactive_tab_bgcolor 0x202040A0
  15. variable inactive_tab_text_color 0xA0A0A0
  16. variable background_color 0x00000060
  17. variable text_size 12
  18. variable tab_margin 2
  19. variable tab_main_spacing 3 ;# the width of the space between tab-row and main content
  20. variable total_height 20
  21. variable top_spacing 2
  22. proc update {} {
  23. variable curtab_bgcolor
  24. variable curtab_text_color
  25. variable inactive_tab_bgcolor
  26. variable inactive_tab_text_color
  27. variable background_color
  28. variable tab_margin
  29. variable tab_main_spacing
  30. variable total_height
  31. variable top_spacing
  32. variable text_size
  33. osd destroy tabbed_machine_view
  34. if {[llength [list_machines]] > 1} {
  35. # init
  36. osd create rectangle tabbed_machine_view \
  37. -relw 1 \
  38. -h $total_height \
  39. -rgba $background_color \
  40. -x 0 \
  41. -y 0
  42. # create new ones
  43. set rel_width [expr {1.0 / [llength [list_machines]]}]
  44. set tab_count 0
  45. foreach machine [utils::get_ordered_machine_list] {
  46. if {$machine eq [activate_machine]} {
  47. set bg_color $curtab_bgcolor
  48. set text_color $curtab_text_color
  49. set display_text [utils::get_machine_display_name $machine]
  50. } else {
  51. set bg_color $inactive_tab_bgcolor
  52. set text_color $inactive_tab_text_color
  53. set display_text [format "%s (%s)" [utils::get_machine_display_name $machine] [utils::get_machine_time $machine]]
  54. }
  55. osd create rectangle tabbed_machine_view.${machine}_rect \
  56. -relx [expr {$tab_count * $rel_width}] \
  57. -x [expr { 2 * $tab_margin}] \
  58. -relw $rel_width \
  59. -w [expr {-2 * $tab_margin}] \
  60. -y $top_spacing \
  61. -h [expr {$total_height - $top_spacing + -$tab_main_spacing}] \
  62. -rgba $bg_color \
  63. -clip true
  64. osd create text tabbed_machine_view.${machine}_rect.text \
  65. -text $display_text \
  66. -size $text_size \
  67. -rgb $text_color \
  68. -x 1
  69. incr tab_count
  70. }
  71. # create the bottom 'line' for the visual tab effect
  72. osd create rectangle tabbed_machine_view.bottom_rect \
  73. -x 0 \
  74. -relw 1 \
  75. -rely 1 \
  76. -y [expr {-$tab_main_spacing}] \
  77. -h $tab_main_spacing \
  78. -rgba $curtab_bgcolor
  79. }
  80. after machine_switch [namespace code update]
  81. }
  82. proc on_mouse_click {} {
  83. set x 2; set y 2
  84. if {[osd exists tabbed_machine_view]} {
  85. catch {lassign [osd info "tabbed_machine_view" -mousecoord] x y}
  86. if {$x > 0 && 1 > $x && $y > 0 && 1 > $y} {
  87. set machine_index [expr int($x * [llength [list_machines]])]
  88. set machine [lindex [list_machines] $machine_index]
  89. activate_machine $machine
  90. }
  91. }
  92. after "mouse button1 up" [namespace code on_mouse_click]
  93. }
  94. after realtime 0.01 [namespace code update]
  95. after "mouse button1 up" [namespace code on_mouse_click]
  96. } ;# namespace tabbed_machine_view