collision/util.lua

50 lines
1.2 KiB
Lua
Raw Normal View History

2014-11-05 05:56:30 +01:00
local math = math
local color = require( "gears.color" )
local beautiful = require( "beautiful" )
2014-12-16 06:36:48 +01:00
local glib = require("lgi").GLib
local module = {settings={}}
local rr,rg,rb
function module.get_rgb()
if not rr then
local pat = color(beautiful.fg_normal)
local s,r,g,b,a = pat:get_rgba()
rr,rg,rb = r,g,b
end
return rr,rg,rb
end
function module.draw_round_rect(cr,x,y,w,h,radius)
cr:save()
cr:translate(x,y)
cr:move_to(0,radius)
cr:arc(radius,radius,radius,math.pi,3*(math.pi/2))
cr:arc(w-radius,radius,radius,3*(math.pi/2),math.pi*2)
cr:arc(w-radius,h-radius,radius,math.pi*2,math.pi/2)
cr:arc(radius,h-radius,radius,math.pi/2,math.pi)
cr:close_path()
cr:restore()
end
2014-12-16 06:36:48 +01:00
local function refresh_dt(last_sec,last_usec,callback,delay)
local tv = glib.TimeVal()
glib.get_current_time(tv)
local dt = (tv.tv_sec*1000000+tv.tv_usec)-(last_sec*1000000+last_usec)
if dt < delay then
callback()
end
return tv.tv_sec,tv.tv_usec
end
function module.double_click(callback,delay)
delay = delay or 250000
local ds,du = 0,0
return function()
ds,du = refresh_dt(ds,du,callback,delay)
end
end
return module
-- kate: space-indent on; indent-width 2; replace-tabs on;