----------------------------------------------------------------------------------------------------
local msg = function(M) reaper.ShowConsoleMsg(tostring(M).."\n") end
----------------------------------------------------------------------------------------------------
function get_script_path() -- script_path and name from reaper function
local filename = select(2, reaper.get_action_context())
local script_path, script_name = filename:match("^(.*)[\\/](.+)")
return script_path, script_name
end
local script_path, script_name = get_script_path()
----------------------------------------
function SetRGB(RGB, a) -- функция задания цвета прям копированием из фотошопа
gfx.r = (RGB & 0xFF0000) / 16711680 -- 256*256*255
gfx.g = (RGB & 0x00FF00) / 65280 -- 256*255
gfx.b = (RGB & 0x0000FF) / 255 -- 255
gfx.a = a or 1
end
function InitMouse()
mouse_last_cap = 0
mouse_down_x, mouse_down_y = 0, 0
mouse_last_x, mouse_last_y = 0, 0
mouse_captimer = 0
end
function Init()
gfx.init("GUI", 120, 120, 0, 600, 200)
SetRGB(0x0f0f0f, 0.7) -- 0f0f0f можно копи пастить из фотошопа
gfx.rect(x, y, w, h, 1) -- зарисовываем прямоугольник под мышкой
img_fn = gfx.loadimg(0, script_path .. "/Images/PlayStop_60x60x3.png")
InitMouse()
mainloop () -- основная функция дефера
end
function GetMouse()
-- mouse state -----------------------
mouse_down = gfx.mouse_cap&1==1 and mouse_last_cap&1==0
mouse_up = gfx.mouse_cap&1==0 and mouse_last_cap&1==1
if mouse_down then mouse_down_x, mouse_down_y = gfx.mouse_x, gfx.mouse_y end
if mouse_up then mouse_up_x, mouse_up_y = gfx.mouse_x, gfx.mouse_y end
mouse_move = (mouse_last_x ~= gfx.mouse_x) or (mouse_last_y ~= gfx.mouse_y)
end
function UpdateMouse()
-- update mouse last state -----------
mouse_last_cap = gfx.mouse_cap
mouse_last_x = gfx.mouse_x
mouse_last_y = gfx.mouse_y
gfx.mouse_wheel = 0
gfx.mouse_hwheel = 0
end
----------------------------------------------------------------------------------------------------
function pointIN(px, py, x,y,w,h)
return px >= x and px <= x + w and py >= y and py <= y + h
end
----------------------------------------
function mouseIN(x,y,w,h)
return pointIN(gfx.mouse_x, gfx.mouse_y, x,y,w,h)
end
----------------------------------------
function mouseDown(x,y,w,h)
return mouse_down and mouseIN(x,y,w,h)
end
----------------------------------------
function mouseUp(x,y,w,h)
return mouse_up and mouseIN(x,y,w,h)
end
----------------------------------------
function mouseClick(x,y,w,h)
return mouseUp(x,y,w,h) and pointIN(mouse_down_x,mouse_down_y, x,y,w,h)
end
----------------------------------------------------------------------------------------------------
curfrm = 0
function Draw ()
x, y, w, h = 30, 30, 60, 60
frmw, frmh, nfrms = w, h, 3
if mouseClick(x,y,w,h) then
curfrm = curfrm + 1
if curfrm == 3 then
curfrm = 0
end
end
gfx.blit(img_fn, 1, 0, 0, curfrm * frmh, frmw, frmh, x,y,w,h)
end
function mainloop ()
GetMouse()
Draw()
UpdateMouse()
local char = gfx.getchar() -- символ с клавиатуры, а если =-1 - окно gfx закрыто
if char~=-1 then reaper.defer(mainloop) end -- defer(пока окно открыто)
gfx.update() -- обновляет кадр
end
----------------------------------------------------------------------------------------------------
Init() -- Инициализируем окно