Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Quote:
Originally Posted by Edgemeal
Looks good Julian!
Question, How do you move a borderless window with mouse? In Windows I simply do something like this, but we dont have a way to release mouse capture do we?
I tried saving mouse pos but doesn't work well if you move the mouse just a little too fast, maybe just needs better logic?
|
Maybe there are other (better) ways, but I'm doing it more or less like this:
Code:
wx, wy = -1, -1
lmb_drag = false
mouse = {ox = -1, oy = -1}
title = "Test"
btnX,btnY,btnW,btnH,txt = 30,30,120,33,"Drag Window"
winW,winH=300,200
window = reaper.JS_Window_Create(title, "myClass", 120, 120, winW, winH,"POPUP")
bm = reaper.JS_LICE_CreateBitmap(true, winW, winH)
reaper.JS_Composite(window, 0, 0, winW, winH, bm, 0, 0, winW, winH)
reaper.JS_LICE_Clear(bm, 0xFFFFFF00)
reaper.JS_LICE_FillRect(bm, btnX, btnY, btnW, btnH, 0xFABB00FF, 1, "COPY")
reaper.JS_Window_InvalidateRect(window, 0, 0, winW, winH, true)
function loop()
if reaper.ValidatePtr(window, "HWND") then
local lmb_state = reaper.JS_Mouse_GetState(1) == 1
hDC = reaper.JS_GDI_GetWindowDC(window)
reaper.JS_GDI_SetTextBkColor(hDC, 0xFABB00FF) -- text color
reaper.JS_GDI_DrawText(hDC, txt, string.len(txt), btnX, btnY, btnX+btnW, btnY+btnH, 'VCENTER HCENTER SINGLELINE') -- center text
reaper.JS_GDI_ReleaseDC(window, hDC)
local mX, mY = reaper.GetMousePosition()
-- Move borderless window with mouse - Doesn't work well if mouse is moved too fast!
if lmb_state then -- Left mouse button down
if not last_lmb_state then -- ...lmb was not down on previous iteration
if reaper.JS_Window_GetForeground() == window then -- me is foreground
if ContainsMouse(window, btnX,btnY,btnW,btnH) then -- mouse inside area
wx, wy = GetBounds(window) -- me window rect
mouse.ox, mouse.oy = mX, mY -- save current mouse loc.
lmb_drag = true
end
end
-- on mouse move (lmb down)
elseif mX ~= mouse.oy or mY ~= mouse.oy then
if lmb_drag then
reaper.JS_Window_Move(window, mX+wx-mouse.ox, mY+wy-mouse.oy)
end
end
end
-- on lmb release
if last_lmb_state and not lmb_state then
if lmb_drag then
lmb_drag = false
end
end
last_lmb_state = lmb_state
------
reaper.defer(loop)
end
end
function GetBounds(hwnd)
local _, left, top, right, bottom = reaper.JS_Window_GetRect(hwnd)
return left, top, right-left, bottom-top
end
function ContainsMouse(hwnd,x,y,w,h)
local mX, mY = reaper.GetMousePosition()
local cx, cy = reaper.JS_Window_ScreenToClient(hwnd, mX, mY)
if (cx >= x) and (cx <= x+w) and (cy <= y+h) and (cy >= y) then
return true
end
end
function exit()
reaper.JS_Window_Destroy(window)
reaper.JS_LICE_DestroyBitmap(bm)
end
reaper.atexit(exit)
loop()
Quote:
Originally Posted by cfillion
Fixed!
|
Thanks!
|