Advertisement
Guest User

Untitled

a guest
May 25th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.55 KB | None | 0 0
  1. namespace eval kv_overlay {
  2. #grid part
  3.  
  4.     proc drawgrid {} {
  5.         osd_widgets::msx_init grid
  6.         #                   rrggbbaa
  7.         variable color [list "0xffffff50" "0x0000ff50"]
  8.  
  9.         #setup grid y
  10.         for {set y 0} {$y < 25} {incr y} {
  11.         osd create rectangle grid.liney$y -scaled true -rely [expr {($y*8)} ] -x 0 -h 1 -relw 257 -rgba [lindex $color [expr {$y % 2}]]
  12.         }
  13.        
  14.         #setup grid x
  15.         for {set x 0} {$x < 33} {incr x} {
  16.         osd create rectangle grid.linex$x -scaled true -relx [expr {($x*8)} ] -y   0 -relh 193 -w 1 -rgba [lindex $color [expr {$x % 2}]]
  17.         }
  18.  
  19.         #setup coordinates
  20.         osd create text grid.coords -relx 0 -rely -10 -text "Coordinates" -rgba 0xffffff80 -size 6
  21.         osd create text grid.snap   -relx 180 -rely -10 -text "Coordinates" -rgba 0xffffff80 -size 6
  22.  
  23.         #call update procedure
  24.         updatecoords
  25.     }
  26.  
  27.     proc updatecoords {} {
  28.  
  29.         osd_widgets::msx_update grid
  30.  
  31.         set gridsize 8
  32.  
  33.         lassign [osd info "grid" -mousecoord] x y
  34.         # make sure you register only on the MSX screen
  35.  
  36.         if ($x=="Inf") {set x 0}
  37.         if ($y=="Inf") {set y 0}
  38.  
  39.         set x [utils::clip 0 255 [expr {int($x)}]]
  40.         set y [utils::clip 0 191 [expr {int($y)}]]
  41.  
  42.         # put coordinates on screen
  43.         osd configure  grid.coords -text "[expr {int($x)}] - [expr {int($y)}]"
  44.  
  45.         osd configure  grid.snap -text "Snap to $gridsize x $gridsize grid - [expr {int($x / $gridsize)*$gridsize}] - [expr {int($y / $gridsize)*$gridsize}]"
  46.  
  47.         #call self after frame
  48.         after frame kv_overlay::updatecoords
  49.     }
  50.  
  51. #editor part
  52.     proc activate_kv2_editor {} {
  53.  
  54.         osd_widgets::msx_init kv
  55.         activate_input_layer kv
  56.  
  57.         bind -layer kv "mouse button1 down" {keymatrixdown 8 0x01}
  58.         bind -layer kv "mouse button1 up" {keymatrixup 8 0x01}
  59.  
  60.         bind -layer kv "mouse button3 down" {keymatrixdown 4 0x04}
  61.         bind -layer kv "mouse button3 up" {keymatrixup 4 0x04}
  62.  
  63.         FollowMouse
  64.     }
  65.  
  66.     proc FollowMouse {} {
  67.         osd_widgets::msx_update kv
  68.        
  69.         lassign [osd info "kv" -mousecoord] x y
  70.         # make sure you register only on the MSX screen
  71.  
  72.         if ($x=="Inf") {set x 0}
  73.         if ($y=="Inf") {set y 0}
  74.  
  75.         set x [utils::clip 0 255 [expr {int($x)}]]
  76.         set y [utils::clip 0 191 [expr {int($y)}]]
  77.  
  78.         # value 28 == in editor
  79.         if {[peek 0xe802] == 28} {
  80.             set ::speed 400
  81.             set ::mute on  
  82.             poke 0xe265  [expr {int($x / 8)}]
  83.             poke 0xe264  [expr {int($y / 8)}]
  84.         }
  85.         if {[peek 0xe802] != 28} {
  86.             set ::speed 100
  87.             set ::mute off
  88.         }
  89.        
  90.         after frame kv_overlay::FollowMouse
  91.     }
  92.  
  93.     #export the following 2 commands
  94.     namespace export activate_kv2_editor
  95.     namespace export drawgrid
  96. }
  97.  
  98. namespace import kv_overlay::*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement