Advertisement
Guest User

kings valley 2 openmsx tcl scrip

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