Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is a basic script for adjusting mouse by the zoom window
- local ZSIZE = 16
- local ZFACTOR = math.floor(256/ZSIZE)
- local zoom_en = 0
- local zoom_x = math.floor((612-ZSIZE)/2)
- local zoom_y = math.floor((384-ZSIZE)/2)
- local zoom_wx = 0
- local zoom_wy = 0
- local zoom_trig = 0
- local function mouse_coords_window_to_sim(window_x,window_y)
- 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
- return (math.floor((window_x-zoom_wx)/ZFACTOR)+zoom_x) , (math.floor((window_y-zoom_wy)/ZFACTOR)+zoom_y)
- else
- return window_x,window_y
- end
- end
- local function step()
- tpt.drawtext(300,5,zoom_en.." "..zoom_trig.." "..ZFACTOR)
- end
- local function mouse_hook(mousex,mousey,button,event,wheel)
- if zoom_trig>0 then
- ZSIZE = ZSIZE+wheel
- if ZSIZE>60 then ZSIZE=60 end
- if ZSIZE<2 then ZSIZE=2 end
- ZFACTOR = math.floor(256/ZSIZE)
- if zoom_en<2 then zoom_en=1 end
- end
- if event==2 and zoom_trig>0 and zoom_en<2 then
- local x = mousex-math.floor(ZSIZE/2) local y = mousey-math.floor(ZSIZE/2)
- if x<0 then x=0 end if y<0 then y=0 end
- if x>612-ZSIZE then x=612-ZSIZE end if y>384-ZSIZE then y=384-ZSIZE end
- zoom_x = x
- zoom_y = y
- zoom_wx = (x<306) and 612-ZSIZE*ZFACTOR or 0
- zoom_wy = 0
- zoom_en = 2
- zoom_trig=0
- return true
- end
- if zoom_trig>0 then return true end
- --coords after here are now zoom-adjusted
- mousex,mousey = mouse_coords_window_to_sim(mousex,mousey)
- tpt.drawtext(300,15,mousex.." "..mousey)
- end
- local function key_hook(key,nkey,modifier,event)
- kmod = modifier%1024--ignore numlock and caps lock for now
- if key=="z" then
- if event==1 then
- if kmod==256 then zoom_trig= (zoom_trig>=1 and 0 or 2)
- else zoom_trig=1 end
- end
- if event==2 and zoom_trig==1 then zoom_trig = 0 end
- if zoom_trig==0 and zoom_en==1 then zoom_en=0 end--might go in step
- if zoom_en==2 then zoom_en=1 end
- end
- --ignore releases
- if (event==2) then return true end
- if nkey == 91 then --Left bracket
- if zoom_trig>0 then
- ZSIZE = ZSIZE-1
- if ZSIZE<2 then ZSIZE=2 end
- ZFACTOR = math.floor(256/ZSIZE)
- end
- elseif nkey == 93 then --Right bracket
- if zoom_trig>0 then
- ZSIZE = ZSIZE+1
- if ZSIZE>60 then ZSIZE=60 end
- ZFACTOR = math.floor(256/ZSIZE)
- end
- end
- end
- tpt.register_step(step)
- tpt.register_mouseevent(mouse_hook)
- tpt.register_keyevent(key_hook)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement