2014-12-23 20:55:54 +01:00
|
|
|
local setmetatable = setmetatable
|
2016-03-06 09:30:30 +01:00
|
|
|
local color = require( "gears.color" )
|
2014-12-23 20:55:54 +01:00
|
|
|
|
|
|
|
local module = {
|
|
|
|
margins = {
|
|
|
|
TOP = 0 ,
|
|
|
|
BOTTOM = 0 ,
|
|
|
|
LEFT = 0 ,
|
2016-06-24 22:53:47 +02:00
|
|
|
RIGHT = 0 ,
|
2014-12-23 20:55:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 09:30:30 +01:00
|
|
|
local function rounded_rect(cr,x,y,w,h,radius) --TODO port to shape API
|
2014-12-23 20:55:54 +01:00
|
|
|
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
|
|
|
|
|
2015-12-29 11:19:23 +01:00
|
|
|
local function draw2(self, context, cr, width, height)
|
2014-12-23 20:55:54 +01:00
|
|
|
cr:save()
|
|
|
|
local mx,my = self.left or 0, self.top or 0
|
|
|
|
local mw,mh = width - mx - (self.right or 0), height - my - (self.bottom or 0)
|
|
|
|
rounded_rect(cr,mx,my,mw,mh,6)
|
2015-01-01 08:08:40 +01:00
|
|
|
local path = cr:copy_path()
|
2014-12-23 20:55:54 +01:00
|
|
|
cr:clip()
|
2015-12-29 11:19:23 +01:00
|
|
|
|
|
|
|
if self.___draw then
|
|
|
|
self.___draw(self, context, cr, width, height)
|
|
|
|
end
|
|
|
|
|
2015-01-01 08:08:40 +01:00
|
|
|
cr:append_path(path)
|
|
|
|
cr:set_source(color(self.data.border_color))
|
|
|
|
cr:stroke()
|
2014-12-23 20:55:54 +01:00
|
|
|
cr:restore()
|
|
|
|
end
|
|
|
|
|
2015-12-29 11:19:23 +01:00
|
|
|
--TODO unported
|
2014-12-23 20:55:54 +01:00
|
|
|
local function draw(data)
|
|
|
|
if not data._internal then return end
|
|
|
|
|
|
|
|
local m = data._internal.margin
|
|
|
|
if m then
|
|
|
|
m.___draw = m.draw
|
|
|
|
m.draw = draw2
|
2015-01-01 08:08:40 +01:00
|
|
|
m.data = data
|
2014-12-23 20:55:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return draw(...) end })
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|