2013-05-11 21:02:42 +02:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
local math = math
|
2014-01-08 06:59:57 +01:00
|
|
|
local base = require( "radical.base" )
|
2013-05-11 21:02:42 +02:00
|
|
|
local color = require( "gears.color" )
|
|
|
|
local cairo = require( "lgi" ).cairo
|
|
|
|
local print = print
|
|
|
|
|
|
|
|
local module = {
|
|
|
|
margins = {
|
|
|
|
TOP = 4,
|
|
|
|
BOTTOM = 4,
|
|
|
|
RIGHT = 4,
|
|
|
|
LEFT = 4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local focussed,default = nil, nil
|
|
|
|
|
|
|
|
local function gen(item_height,bg_color,border_color)
|
|
|
|
local img = cairo.ImageSurface(cairo.Format.ARGB32, item_height,item_height)
|
|
|
|
local cr = cairo.Context(img)
|
|
|
|
local rad = corner_radius or 3
|
|
|
|
cr:set_source(color(bg_color))
|
|
|
|
cr:arc(rad,rad,rad,0,2*math.pi)
|
|
|
|
cr:arc(item_height-rad,rad,rad,0,2*math.pi)
|
|
|
|
cr:arc(rad,item_height-rad,rad,0,2*math.pi)
|
|
|
|
cr:arc(item_height-rad,item_height-rad,rad,0,2*math.pi)
|
|
|
|
cr:fill()
|
|
|
|
cr:rectangle(0,rad, item_height, item_height-2*rad)
|
|
|
|
cr:rectangle(rad,0, item_height-2*rad, item_height)
|
|
|
|
cr:fill()
|
|
|
|
return cairo.Pattern.create_for_surface(img)
|
|
|
|
end
|
|
|
|
|
2014-02-15 05:35:53 +01:00
|
|
|
local function widget_draw(self, w, cr, width, height)
|
2014-02-16 20:46:10 +01:00
|
|
|
self:_drawrounded(w, cr, width, height)
|
2014-02-15 05:35:53 +01:00
|
|
|
local overlay = self._item and self._item.overlay
|
|
|
|
if overlay then
|
|
|
|
overlay(self._item._menu,self._item,cr,width,height)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-02 22:28:30 +01:00
|
|
|
local function draw(item,args)
|
2014-02-21 04:29:40 +01:00
|
|
|
local args = args or {}
|
2014-02-15 05:35:53 +01:00
|
|
|
|
|
|
|
if not item.widget._overlay_init then
|
2014-02-16 20:46:10 +01:00
|
|
|
item.widget._drawrounded = item.widget.draw
|
2014-02-15 05:35:53 +01:00
|
|
|
item.widget.draw = widget_draw
|
|
|
|
item.widget._overlay_init = true
|
|
|
|
end
|
|
|
|
|
2014-03-02 22:28:30 +01:00
|
|
|
local ih = item.height
|
2014-07-28 01:20:04 +02:00
|
|
|
local iw = item.width
|
|
|
|
if iw and iw > ih then
|
|
|
|
ih = iw
|
|
|
|
end
|
2013-05-11 21:02:42 +02:00
|
|
|
if not focussed or not focussed[ih] then
|
|
|
|
if not focussed then
|
|
|
|
focussed,default={},{}
|
|
|
|
end
|
2014-03-02 22:28:30 +01:00
|
|
|
local bc = item.border_color
|
2014-07-28 01:20:04 +02:00
|
|
|
|
2014-03-02 22:28:30 +01:00
|
|
|
focussed[ih] = gen(ih,item.bg_focus,bc)
|
|
|
|
default [ih] = gen(ih,item.bg,bc)
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
2014-02-21 04:29:40 +01:00
|
|
|
local state = item.state or {}
|
2014-02-22 04:22:13 +01:00
|
|
|
local current_state = state._current_key or nil
|
|
|
|
local state_name = base.colors_by_id[current_state]
|
2014-02-21 04:29:40 +01:00
|
|
|
|
2014-02-22 04:22:13 +01:00
|
|
|
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
2013-05-11 21:02:42 +02:00
|
|
|
item.widget:set_bg(focussed[ih])
|
2014-03-02 22:28:30 +01:00
|
|
|
item.widget:set_fg(item["fg_focus"])
|
2014-02-22 04:22:13 +01:00
|
|
|
elseif state_name then --TODO incomplete
|
2014-03-02 22:28:30 +01:00
|
|
|
item.widget:set_bg(args.color or item["bg_"..state_name])
|
|
|
|
item.widget:set_fg( item["fg_"..state_name])
|
2013-05-11 21:02:42 +02:00
|
|
|
else
|
2014-02-22 04:22:13 +01:00
|
|
|
item.widget:set_bg(default[ih])
|
2014-03-02 22:28:30 +01:00
|
|
|
item.widget:set_fg(item["fg_normal"])
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return draw(...) end })
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|