Advertisement
cracker64

Zoom adjust

Aug 9th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.66 KB | None | 0 0
  1. --This is a basic script for adjusting mouse by the zoom window
  2. local ZSIZE = 16
  3. local ZFACTOR = math.floor(256/ZSIZE)
  4. local zoom_en = 0
  5. local zoom_x = math.floor((612-ZSIZE)/2)
  6. local zoom_y = math.floor((384-ZSIZE)/2)
  7. local zoom_wx = 0
  8. local zoom_wy = 0
  9. local zoom_trig = 0
  10.  
  11. local function mouse_coords_window_to_sim(window_x,window_y)
  12.     if (zoom_en>0 and window_x>=zoom_wx and window_y>=zoom_wy and window_x<(zoom_wx+ZFACTOR*ZSIZE) and window_y<(zoom_wy+ZFACTOR*ZSIZE)) then
  13.         return (math.floor((window_x-zoom_wx)/ZFACTOR)+zoom_x) , (math.floor((window_y-zoom_wy)/ZFACTOR)+zoom_y)
  14.     else
  15.         return window_x,window_y
  16.     end
  17. end
  18. local function step()
  19.     tpt.drawtext(300,5,zoom_en.." "..zoom_trig.." "..ZFACTOR)
  20. end
  21. local function mouse_hook(mousex,mousey,button,event,wheel)
  22.     if zoom_trig>0 then
  23.         ZSIZE = ZSIZE+wheel
  24.         if ZSIZE>60 then ZSIZE=60 end
  25.         if ZSIZE<2 then ZSIZE=2 end
  26.         ZFACTOR = math.floor(256/ZSIZE)
  27.         if zoom_en<2 then zoom_en=1 end
  28.     end
  29.     if event==2 and zoom_trig>0 and zoom_en<2 then
  30.         local x = mousex-math.floor(ZSIZE/2) local y = mousey-math.floor(ZSIZE/2)
  31.         if x<0 then x=0 end if y<0 then y=0 end
  32.         if x>612-ZSIZE then x=612-ZSIZE end if y>384-ZSIZE then y=384-ZSIZE end
  33.         zoom_x = x
  34.         zoom_y = y
  35.         zoom_wx = (x<306) and 612-ZSIZE*ZFACTOR or 0
  36.         zoom_wy = 0
  37.         zoom_en = 2
  38.         zoom_trig=0
  39.         return true
  40.     end
  41.     if zoom_trig>0 then return true end
  42.     --coords after here are now zoom-adjusted
  43.     mousex,mousey = mouse_coords_window_to_sim(mousex,mousey)
  44.     tpt.drawtext(300,15,mousex.." "..mousey)
  45. end
  46. local function key_hook(key,nkey,modifier,event)
  47.     kmod = modifier%1024--ignore numlock and caps lock for now
  48.    
  49.     if key=="z" then
  50.         if event==1 then
  51.             if kmod==256 then zoom_trig= (zoom_trig>=1 and 0 or 2)
  52.             else zoom_trig=1 end
  53.         end
  54.         if event==2 and zoom_trig==1 then zoom_trig = 0 end
  55.         if zoom_trig==0 and zoom_en==1 then zoom_en=0 end--might go in step
  56.         if zoom_en==2 then zoom_en=1 end
  57.     end
  58.     --ignore releases
  59.     if (event==2) then return true end
  60.     if nkey == 91 then --Left bracket
  61.        if zoom_trig>0 then
  62.            ZSIZE = ZSIZE-1
  63.            if ZSIZE<2 then ZSIZE=2 end
  64.            ZFACTOR = math.floor(256/ZSIZE)
  65.        end
  66.     elseif nkey == 93 then --Right bracket
  67.        if zoom_trig>0 then
  68.            ZSIZE = ZSIZE+1
  69.            if ZSIZE>60 then ZSIZE=60 end
  70.            ZFACTOR = math.floor(256/ZSIZE)
  71.        end
  72.     end
  73. end
  74.  
  75. tpt.register_step(step)
  76. tpt.register_mouseevent(mouse_hook)
  77. tpt.register_keyevent(key_hook)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement