radical/style/grouped_3d.lua

58 lines
1.3 KiB
Lua
Raw Normal View History

2014-12-23 20:55:54 +01:00
local setmetatable = setmetatable
local base = require( "radical.base" )
local color = require( "gears.color" )
local module = {
margins = {
TOP = 0 ,
BOTTOM = 0 ,
LEFT = 0 ,
BOTTOM = 0 ,
}
}
local function rounded_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
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()
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
--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;