2013-05-11 21:02:42 +02:00
|
|
|
local setmetatable = setmetatable
|
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
|
2013-07-07 06:39:17 +02:00
|
|
|
local beautiful = require( "beautiful" )
|
2013-05-11 21:02:42 +02:00
|
|
|
local print = print
|
|
|
|
|
|
|
|
local module = {
|
|
|
|
margins = {
|
|
|
|
TOP = 2,
|
|
|
|
BOTTOM = 2,
|
|
|
|
RIGHT = 0,
|
|
|
|
LEFT = 4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-08 00:18:55 +02:00
|
|
|
local focussed,default,alt = nil, nil,{}
|
2013-05-11 21:02:42 +02:00
|
|
|
|
|
|
|
local function gen(item_height,bg_color,border_color)
|
|
|
|
local img = cairo.ImageSurface(cairo.Format.ARGB32, 800,item_height)
|
|
|
|
local cr = cairo.Context(img)
|
|
|
|
cr:set_source( color(bg_color) )
|
|
|
|
cr:paint()
|
|
|
|
cr:set_source( color(border_color) )
|
|
|
|
cr:rectangle(0,item_height-1,800,1)
|
|
|
|
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)
|
|
|
|
self:_draw2(w, cr, width, height)
|
|
|
|
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-01-08 06:59:57 +01:00
|
|
|
local col = args.color
|
2014-02-15 05:35:53 +01:00
|
|
|
|
|
|
|
if not item.widget._overlay_init then
|
|
|
|
item.widget._draw2 = item.widget.draw
|
|
|
|
item.widget.draw = widget_draw
|
|
|
|
item.widget._overlay_init = true
|
|
|
|
end
|
|
|
|
|
2014-03-27 04:21:42 +01:00
|
|
|
local ih = item.height or 1
|
2013-05-11 21:02:42 +02:00
|
|
|
if not focussed or not focussed[ih] then
|
|
|
|
if not focussed then
|
2013-07-07 06:39:17 +02:00
|
|
|
focussed,default,alt={},{},{}
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
2015-01-11 05:59:51 +01:00
|
|
|
local bc = item.item_border_color or item.border_color
|
2014-03-02 22:28:30 +01:00
|
|
|
focussed[ih] = gen(ih,item.bg_focus,bc)
|
|
|
|
default [ih] = gen(ih,item.bg,bc)
|
2013-07-08 00:18:55 +02:00
|
|
|
end
|
|
|
|
if col and (not alt[col] or not alt[col][ih]) then
|
|
|
|
alt[col] = alt[col] or {}
|
|
|
|
alt[col][ih] = gen(ih,color(col),bc)
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
2014-02-21 04:29:40 +01:00
|
|
|
local state = item.state or {}
|
2014-03-02 22:28:30 +01:00
|
|
|
local current_state = state._current_key or nil
|
2014-08-08 08:02:37 +02:00
|
|
|
local state_name = current_state and base.colors_by_id[current_state] or "normal"
|
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"])
|
2013-07-08 00:18:55 +02:00
|
|
|
elseif col then
|
|
|
|
item.widget:set_bg(alt[col][ih])
|
2014-03-02 22:28:30 +01:00
|
|
|
item.widget:set_fg(item["fg_"..state_name])
|
2013-05-11 21:02:42 +02:00
|
|
|
else
|
2013-07-07 06:39:17 +02:00
|
|
|
item.widget:set_bg(default[ih])
|
2014-03-13 06:14:52 +01:00
|
|
|
item.widget:set_fg(item["fg"])
|
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;
|