Skip to content

Instantly share code, notes, and snippets.

@stuartpb
Created October 3, 2011 20:21
Show Gist options
  • Save stuartpb/1260133 to your computer and use it in GitHub Desktop.
Save stuartpb/1260133 to your computer and use it in GitHub Desktop.
grab, drag, and release handler framework for IUPLua
do
local dox, doy
local function drag(x, y)
end
local function grab(x, y)
dox, doy = x, y
drag(x, y)
end
local function release(x, y)
dox, doy = nil, nil
end
function cnv:button_cb(but, pressed, x, y, status)
if but == iup.BUTTON1 then
if pressed == 1 then
grab(x, y)
elseif dox then
release(x, y)
end
end
end
function cnv:motion_cb(x, y, status)
if dox then
if iup.isbutton1(status) then
drag(x, y)
else --mouse has been released without triggering button_cb
release(x, y)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment