osd_menu.tcl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. namespace eval osd_menu {
  2. # default colors defined here, for easy global tweaking
  3. variable default_bg_color "0x7090aae8 0xa0c0dde8 0x90b0cce8 0xc0e0ffe8"
  4. variable default_text_color 0x000000ff
  5. variable default_select_color "0x0044aa80 0x2266dd80 0x0055cc80 0x44aaff80"
  6. variable default_header_text_color 0xff9020ff
  7. # drop handler
  8. bind_default filedrop osd_menu::drop_handler -event
  9. # button stuff
  10. variable button_fade_timeout 8
  11. variable button_fadeout_time 4
  12. # TODO: make this a generic proc with osd element as input?
  13. proc is_cursor_on_button {} {
  14. set x 2; set y 2
  15. catch {lassign [osd info "main_menu_pop_up_button" -mousecoord] x y}
  16. return [expr {0 <= $x && $x <= 1 && 0 <= $y && $y <= 1}]
  17. }
  18. proc check_button_clicked {} {
  19. if {[is_cursor_on_button]} {
  20. main_menu_toggle
  21. }
  22. after "mouse button1 down" [namespace code check_button_clicked]
  23. }
  24. variable start_fadeout_button_id 0
  25. proc update_button_fade {} {
  26. variable start_fadeout_button_id
  27. if {[is_cursor_on_button]} {
  28. if {$start_fadeout_button_id ne "0"} {
  29. after cancel $start_fadeout_button_id
  30. osd configure "main_menu_pop_up_button" -fadeCurrent 1 -fadeTarget 1
  31. set start_fadeout_button_id 0
  32. }
  33. } else {
  34. if {$start_fadeout_button_id eq "0"} {
  35. variable button_fade_timeout
  36. set start_fadeout_button_id [after realtime $button_fade_timeout {
  37. osd configure "main_menu_pop_up_button" -fadeTarget 0
  38. }]
  39. }
  40. }
  41. after "mouse motion" [namespace code update_button_fade]
  42. }
  43. if {![regexp dingux "[openmsx_info platform]"]} {
  44. # add a button to pop up the menu
  45. osd create rectangle main_menu_pop_up_button -z 0 -x 0 -y 0 -w 35 -h 16 -rgba $default_bg_color -fadePeriod $button_fadeout_time
  46. osd create text main_menu_pop_up_button.text -z 0 -x 0 -y 0 -rgba $default_text_color -text "menu"
  47. after "mouse button1 down" [namespace code check_button_clicked]
  48. update_button_fade
  49. }
  50. } ;# namespace osd_menu