Le Verdier, with that code I was able to fix the Zooming functionality, thank you so much

Now I can continue and get this thing working in my editor
I made something pretty fancy quick to show it working around a bunch of moving objects.
Requires Advanced2d and a mousewheel...
LMB: Scroll graph
Mouse wheel: Zoom In/Out at the mouse location
// math class
type vector2
x as float
y as float
endtype
type vector3
x as float
y as float
z as float
endtype
type rect
x as integer
y as integer
w as integer
h as integer
endtype
global _vector2 as vector2
global _vector3 as vector3
global _rect as rect
// mouse class
type inputMouse
click as integer
oldClick as integer
drag as byte
pos as vector3
dragPos as vector3
velocity as vector3
endtype
global _inputMouse as inputMouse
// graph class
type curveGraph
perPixelUnit as float
zoomFactor as float
oldZoom as float
zoomVal as float
zoom as float
wOldPos as vector2 // world position
wPos as vector2 // world position
bounds as rect
endtype
global _curveGraph as curveGraph
global _curveGraphCentre as vector2
// setup display
_curveGraph.perPixelUnit = 1
_curveGraph.zoom = 1
_curveGraph.zoomFactor = 0.001
_curveGraph.wPos.x = 0
_curveGraph.wPos.y = 0
_curveGraph.bounds.x = 128
_curveGraph.bounds.y = 128
_curveGraph.bounds.w = screen width() - 128
_curveGraph.bounds.h = screen height() - 128
_curveGraphCentre.x = .5*(_curveGraph.bounds.w-_curveGraph.bounds.x) + _curveGraph.bounds.x
_curveGraphCentre.y = .5*(_curveGraph.bounds.h-_curveGraph.bounds.y) + _curveGraph.bounds.y
// *************************
// just for display
type shape
n as byte
size as float
angle as float
origin as vector2
offset as vector2
rotFactor as integer
rotVelocity as float
color as dword
endtype
global maxShapes as integer = 400
global dim _shape(maxShapes) as shape
global offset as vector2
global origin as vector2
for n = 0 to maxShapes
_shape(n).n = rnd(1)
_shape(n).size = 4+rnd(32)
_shape(n).angle = rnd(359)
_shape(n).rotFactor = rnd(1) // not implimented
_shape(n).rotVelocity = rndFloat(0.01,0.05,3)
_shape(n).color = rgb(64+rnd(191),0,0)
// origin
setVector2( 0, 0 ) : _shape(n).origin = _vector2
// offset
setVector2( 600-rnd(1200), 600-rnd(1200) ) : _shape(n).offset = _vector2
next
// *************************
sync on : sync rate 0
do : cls rgb(56,56,56)
updateInput()
updateCurveGraph()
// draw graph
a2box _curveGraph.bounds.x,_curveGraph.bounds.y,_curveGraph.bounds.w,_curveGraph.bounds.h, rgb(255,0,0) // bounds
a2SetClip _curveGraph.bounds.x,_curveGraph.bounds.y,_curveGraph.bounds.w,_curveGraph.bounds.h
globalToLocalVector( 0, 0 )
a2fillbox _vector2.x-1, 0, _vector2.x+1, _curveGraph.bounds.h, rgb(162,162,162)
a2fillbox 0, _vector2.y-1, _curveGraph.bounds.w, _vector2.y+1, rgb(0,0,0)
for n = 0 to maxShapes
_shape(n).angle = wrapvalue(_shape(n).angle+_shape(n).rotVelocity)
offset = _shape(n).offset : origin = _shape(n).origin
vector2_rotateAboutOrigin( offset, origin, _shape(n).angle )
if _shape(n).n = 0 then drawGraphCircle( _vector2.x, _vector2.y, _shape(n).size, _shape(n).color )
if _shape(n).n = 1 then drawGraphBox( _vector2.x, _vector2.y, _shape(n).size, _shape(n).color )
next
a2ResetClip
sync
loop
// input functions
function updateInput()
// mouse input
_inputMouse.oldClick = _inputMouse.click
_inputMouse.click = mouseclick()
setVector3( mousex(), mousey(), mousez() )
_inputMouse.pos = _vector3
setVector3( mousemovex(), mousemovey(), mousemovez() )
_inputMouse.velocity = _vector3
endfunction
// display client function
function updateCurveGraph()
local delta as vector2
local worldToScreen as vector2 // or screenToWorld (can't remember which it is, will sort out later)
if (_inputMouse.velocity.z)
_curveGraph.oldZoom = _curveGraph.zoom
_curveGraph.zoomVal = clamp(_curveGraph.zoomVal+(_inputMouse.velocity.z * _curveGraph.zoomFactor), -3.9,6.0)
_curveGraph.zoom = _curveGraph.perPixelUnit * (2 ^ _curveGraph.zoomVal)
delta.x = _inputMouse.pos.x - _curveGraphCentre.x
delta.y = _inputMouse.pos.y - _curveGraphCentre.y
worldToScreen.x = _curveGraph.wPos.x + delta.x / _curveGraph.oldZoom
worldToScreen.y = _curveGraph.wPos.y - delta.y / _curveGraph.oldZoom
_curveGraph.wPos.x = worldToScreen.x - delta.x / _curveGraph.zoom
_curveGraph.wPos.y = worldToScreen.y + delta.y / _curveGraph.zoom
endif
// this is for draging the position of the 2d display, so panning
if not _inputMouse.click
_inputMouse.drag = 0
_inputMouse.dragPos.x = 0
_inputMouse.dragPos.y = 0
endif
if _inputMouse.drag = 0
if _inputMouse.click = 1
_inputMouse.drag = 1
_inputMouse.dragPos.x = _inputMouse.pos.x
_inputMouse.dragPos.y = _inputMouse.pos.y
_curveGraph.wOldPos = _curveGraph.wPos
endif
endif
if _inputMouse.drag
_curveGraph.wPos.x = _curveGraph.wOldPos.x - (_inputMouse.pos.x - _inputMouse.dragPos.x) / _curveGraph.zoom
_curveGraph.wPos.y = _curveGraph.wOldPos.y + (_inputMouse.pos.y - _inputMouse.dragPos.y) / _curveGraph.zoom
endif
endfunction
function globalToLocalVector( x as float, y as float )
_vector2.x = _curveGraphCentre.x + (x - _curveGraph.wpos.x) * _curveGraph.zoom
_vector2.y = _curveGraphCentre.y - (y - _curveGraph.wpos.y) * _curveGraph.zoom
endfunction
// drawing functions
function drawGraphCircle( x as float, y as float, size as float, color as dword )
globalToLocalVector( x, y )
a2circle _vector2.x,_vector2.y,size* _curveGraph.zoom,color
endfunction
function drawGraphBox( x as float, y as float, size as float, color as dword )
local r as rect : size = .5*size
globalToLocalVector( x-size, y-size )
r.x = _vector2.x : r.y = _vector2.y
globalToLocalVector( x+size, y+size )
r.w = _vector2.x : r.h = _vector2.y
a2box r.x,r.y,r.w,r.h,color
endfunction
// vector functions
function setVector2( x as float, y as float )
_vector2.x = x : _vector2.y = y
endfunction
function vector2_Add( v1 as vector2, v2 as vector2 )
setVector2( v1.x + v2.x, v1.y + v2.y )
endfunction
function vector2_Subtraction( v1 as vector2, v2 as vector2 )
setVector2( v1.x - v2.x, v1.y - v2.y )
endfunction
function vector2_Mul( v as vector2, scaleFactor as float )
setVector2( v.x * scaleFactor, v.y * scaleFactor )
endfunction
function vector2_Length( v as vector2 )
local out as float
out = sqrt((v.x * v.x) + (v.y * v.y))
endfunction out
function vector2_Distance( v1 as vector2, v2 as vector2 )
local out as float
vector2_Subtraction( v1, v2 ) : out = vector2_Length( _vector2 )
endfunction out
function vector2_rotateAboutOrigin( pt as vector2, origin as vector2, angleInDegrees as float )
local rotationVector as vector2
local angle as float
vector2_Subtraction( pt, origin ) : rotationVector = _vector2
if (rotationVector.x = 0.0 && rotationVector.y = 0.0)
_vector2 = pt : exitfunction
endif
angle = atanfull(rotationVector.y, rotationVector.x)
inc angle, angleInDegrees
setVector2( cos(angle), sin(angle) )
vector2_Mul( _vector2, vector2_Length( rotationVector ) ) : rotationVector = _vector2
vector2_Add( rotationVector, origin )
endfunction
function setVector3( x as float, y as float, z as float )
_vector3.x = x : _vector3.y = y : _vector3.z = z
endfunction
// mis
function rndFloat( lower as float, upper as float, precision as byte )
local power as float : power = 10^precision
local out as float : out = (rnd(int((upper*power)-(lower*power)))/power)+lower
endfunction out
"Get in the Van!" - Van B