Consolidate arrow drawing
This commit is contained in:
parent
80160740ad
commit
77b26ff142
|
@ -23,7 +23,7 @@ local function init()
|
||||||
col_utils.draw_round_rect(cr,0,0,75,75,10)
|
col_utils.draw_round_rect(cr,0,0,75,75,10)
|
||||||
cr:fill()
|
cr:fill()
|
||||||
|
|
||||||
local bounding,arrow = img._native,col_utils.arrow(55,color(beautiful.fg_normal),color(beautiful.bg_normal))
|
local bounding,arrow = img._native,col_utils.arrow(55,10,0,beautiful.bg_normal,beautiful.fg_normal)
|
||||||
wiboxes = {}
|
wiboxes = {}
|
||||||
for k,v in ipairs({"up","right","down","left","center"}) do
|
for k,v in ipairs({"up","right","down","left","center"}) do
|
||||||
wiboxes[v] = wibox({})
|
wiboxes[v] = wibox({})
|
||||||
|
|
|
@ -31,7 +31,7 @@ function module.highlight()
|
||||||
cr:translate(0,-30)
|
cr:translate(0,-30)
|
||||||
cr:move_to(50,50)
|
cr:move_to(50,50)
|
||||||
cr:rotate(math.pi)
|
cr:rotate(math.pi)
|
||||||
col_utils.arrow_path(cr,40)
|
col_utils.arrow_path(cr,40,10)
|
||||||
cr:fill()
|
cr:fill()
|
||||||
cr:restore()
|
cr:restore()
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ function module.highlight()
|
||||||
cr:translate(-30,0)
|
cr:translate(-30,0)
|
||||||
cr:move_to(50,50)
|
cr:move_to(50,50)
|
||||||
cr:rotate(math.pi/2)
|
cr:rotate(math.pi/2)
|
||||||
col_utils.arrow_path(cr,40)
|
col_utils.arrow_path(cr,40,10)
|
||||||
cr:fill()
|
cr:fill()
|
||||||
cr:restore()
|
cr:restore()
|
||||||
|
|
||||||
|
@ -47,14 +47,14 @@ function module.highlight()
|
||||||
cr:translate(30,0)
|
cr:translate(30,0)
|
||||||
cr:move_to(50,50)
|
cr:move_to(50,50)
|
||||||
cr:rotate(-math.pi/2)
|
cr:rotate(-math.pi/2)
|
||||||
col_utils.arrow_path(cr,40)
|
col_utils.arrow_path(cr,40,10)
|
||||||
cr:fill()
|
cr:fill()
|
||||||
cr:restore()
|
cr:restore()
|
||||||
|
|
||||||
cr:save()
|
cr:save()
|
||||||
cr:translate(0,30)
|
cr:translate(0,30)
|
||||||
cr:move_to(50,50)
|
cr:move_to(50,50)
|
||||||
col_utils.arrow_path(cr,40)
|
col_utils.arrow_path(cr,40,10)
|
||||||
cr:fill()
|
cr:fill()
|
||||||
cr:restore()
|
cr:restore()
|
||||||
|
|
||||||
|
|
20
resize.lua
20
resize.lua
|
@ -3,26 +3,12 @@ local ipairs,print = ipairs,print
|
||||||
local wibox,color = require( "wibox" ) , require( "gears.color" )
|
local wibox,color = require( "wibox" ) , require( "gears.color" )
|
||||||
local cairo,beautiful = require( "lgi").cairo , require( "beautiful" )
|
local cairo,beautiful = require( "lgi").cairo , require( "beautiful" )
|
||||||
local awful = require("awful")
|
local awful = require("awful")
|
||||||
|
local col_utils = require( "collision.util" )
|
||||||
local module,indicators,cur_c,auto_hide = {},nil,nil
|
local module,indicators,cur_c,auto_hide = {},nil,nil
|
||||||
|
|
||||||
local values = {"top" , "top_right" , "right" , "bottom_right" ,
|
local values = {"top" , "top_right" , "right" , "bottom_right" ,
|
||||||
"bottom" , "bottom_left", "left" , "top_left" }
|
"bottom" , "bottom_left", "left" , "top_left" }
|
||||||
|
|
||||||
local function create_arrow(width, height,margin,bg_color,fg_color)
|
|
||||||
local img = cairo.ImageSurface(cairo.Format.ARGB32, width+2*margin, height+2*margin)
|
|
||||||
local cr = cairo.Context(img)
|
|
||||||
cr:set_source(color(bg_color))
|
|
||||||
cr:paint()
|
|
||||||
cr:set_source(color(fg_color))
|
|
||||||
cr:set_antialias(1)
|
|
||||||
cr:rectangle((margin*2+width)/2-(width/8), (width/2)+margin, width/4, height-margin)
|
|
||||||
for i=0,(width/2) do
|
|
||||||
cr:rectangle(margin+i, (width/2)+margin-i, width-i*2, 1)
|
|
||||||
end
|
|
||||||
cr:fill()
|
|
||||||
return cairo.Pattern.create_for_surface(img)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function gen_shape_bounding(radius)
|
local function gen_shape_bounding(radius)
|
||||||
local img = cairo.ImageSurface(cairo.Format.ARGB32, radius,radius)
|
local img = cairo.ImageSurface(cairo.Format.ARGB32, radius,radius)
|
||||||
local cr = cairo.Context(img)
|
local cr = cairo.Context(img)
|
||||||
|
@ -36,8 +22,8 @@ end
|
||||||
|
|
||||||
local function create_indicators()
|
local function create_indicators()
|
||||||
indicators = {}
|
indicators = {}
|
||||||
local arr = create_arrow( 20, 20, 10, beautiful.bg_alternate,beautiful.fg_normal )
|
local arr = col_utils.arrow(20, 7, 10, beautiful.bg_alternate, beautiful.fg_normal )
|
||||||
local arr_focus = create_arrow( 20, 20, 10, beautiful.fg_normal,beautiful.bg_normal )
|
local arr_focus = col_utils.arrow(20, 7, 10, beautiful.fg_normal, beautiful.bg_normal )
|
||||||
local angle = 0
|
local angle = 0
|
||||||
local shape_bounding = gen_shape_bounding(40)
|
local shape_bounding = gen_shape_bounding(40)
|
||||||
for k,v in ipairs(values) do
|
for k,v in ipairs(values) do
|
||||||
|
|
31
util.lua
31
util.lua
|
@ -17,26 +17,27 @@ function module.get_rgb()
|
||||||
return rr,rg,rb
|
return rr,rg,rb
|
||||||
end
|
end
|
||||||
|
|
||||||
function module.arrow_path(cr,width)
|
function module.arrow_path(cr, width, sidesize)
|
||||||
cr:rel_move_to( 0 , -width/2 )
|
cr:rel_move_to( 0 , -width/2 )
|
||||||
cr:rel_line_to( width/2 , width/2 )
|
cr:rel_line_to( width/2 , width/2 )
|
||||||
cr:rel_line_to( -10 , 0 )
|
cr:rel_line_to( -sidesize , 0 )
|
||||||
cr:rel_line_to( 0 , width/2 )
|
cr:rel_line_to( 0 , width/2 )
|
||||||
cr:rel_line_to( (-width)+20 , 0 )
|
cr:rel_line_to( (-width)+2*sidesize , 0 )
|
||||||
cr:rel_line_to( 0 , -width/2 )
|
cr:rel_line_to( 0 , -width/2 )
|
||||||
cr:rel_line_to( -10 , 0 )
|
cr:rel_line_to( -sidesize , 0 )
|
||||||
cr:rel_line_to( width/2 , -width/2)
|
cr:rel_line_to( width/2 , -width/2 )
|
||||||
cr:close_path()
|
cr:close_path()
|
||||||
end
|
end
|
||||||
|
|
||||||
function module.arrow(width,bg,fg)
|
function module.arrow(width, sidesize, margin, bg_color, fg_color)
|
||||||
local img = cairo.ImageSurface(cairo.Format.ARGB32, width, width)
|
local img = cairo.ImageSurface(cairo.Format.ARGB32, width+2*margin, width+2*margin)
|
||||||
local cr = cairo.Context(img)
|
local cr = cairo.Context(img)
|
||||||
cr:set_source(fg)
|
cr:set_source(color(bg_color))
|
||||||
cr:paint()
|
cr:paint()
|
||||||
cr:set_source(bg)
|
cr:set_source(color(fg_color))
|
||||||
cr:move_to(width/2,width/2)
|
cr:set_antialias(cairo.Antialias.NONE)
|
||||||
module.arrow_path(cr,width)
|
cr:move_to(margin+width/2, margin+width/2)
|
||||||
|
module.arrow_path(cr, width, sidesize)
|
||||||
cr:fill()
|
cr:fill()
|
||||||
return cairo.Pattern.create_for_surface(img)
|
return cairo.Pattern.create_for_surface(img)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue