Quote: Any suggestions on how to go about measuring mouse movement in order to tell the difference between dragging up or down etc..? The moving around problem was solved for you a long time ago by the movewindow.lua file.
require "movewindow" at the top of your plugin and then see http://www.gammon.com.au/forum/bbshowpost.php?id=9594&page=2
The lines containing "movewindow" and "windowinfo" are the important ones.
Though if you want to get adventurous and start adding things like resizing, you can try something like...
Add a drag handler to a small hotspot in the lower-right corner like so:
-- Add handler for resizing
WindowAddHotspot(win, "resize", width-10, height-10, width, height, "MouseOver", "CancelMouseOver", "MouseDown", "", "MouseUp", "", 6, 0)
WindowDragHandler(win, "resize", "ResizeMoveCallback", "ResizeReleaseCallback", 0)
and then use callbacks like the following:
MIN_SIZE = 50
-- called when the resize drag widget is moved
function ResizeMoveCallback()
posx, posy = WindowInfo (win, 17), WindowInfo (win, 18)
width = width + posx - startx
startx = posx
if (width < MIN_SIZE) then
width = MIN_SIZE
startx = windowinfo.window_left+width
elseif (windowinfo.window_left+width > GetInfo(281)) then
width = GetInfo(281)-windowinfo.window_left
startx = GetInfo(281)
end
height = height + posy - starty
starty = posy
if (height < MIN_SIZE) then
height = MIN_SIZE
starty = windowinfo.window_top+height
elseif (windowinfo.window_top+height > GetInfo(280)) then
height = GetInfo(280)-windowinfo.window_top
starty = GetInfo(280)
end
if (utils.timer() - lastRefresh > 0.0333) then
--- RECONSTRUCT AND DRAW THE WINDOW WITH THE NEW HEIGHT AND WIDTH HERE
lastRefresh = utils.timer()
end
end
lastRefresh = 0
-- Called after the resize widget is released.
function ResizeReleaseCallback()
--- RECONSTRUCT AND DRAW THE WINDOW WITH THE NEW HEIGHT AND WIDTH HERE
end
-- Called when mouse button is pressed on hotspot.
function MouseDown(flags, hotspot_id)
if (hotspot_id == "resize") then
startx, starty = WindowInfo (win, 17), WindowInfo (win, 18)
end
end
Quote: Also, will hotspot creation keep up with repaint() or is it linked to redraw() somehow
Repaint is just like Redraw but with greater conviction (NOW! instead of SOON). To my knowledge neither is required for hotspot creation. |