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)
|
||||
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 = {}
|
||||
for k,v in ipairs({"up","right","down","left","center"}) do
|
||||
wiboxes[v] = wibox({})
|
||||
|
|
|
@ -31,7 +31,7 @@ function module.highlight()
|
|||
cr:translate(0,-30)
|
||||
cr:move_to(50,50)
|
||||
cr:rotate(math.pi)
|
||||
col_utils.arrow_path(cr,40)
|
||||
col_utils.arrow_path(cr,40,10)
|
||||
cr:fill()
|
||||
cr:restore()
|
||||
|
||||
|
@ -39,7 +39,7 @@ function module.highlight()
|
|||
cr:translate(-30,0)
|
||||
cr:move_to(50,50)
|
||||
cr:rotate(math.pi/2)
|
||||
col_utils.arrow_path(cr,40)
|
||||
col_utils.arrow_path(cr,40,10)
|
||||
cr:fill()
|
||||
cr:restore()
|
||||
|
||||
|
@ -47,14 +47,14 @@ function module.highlight()
|
|||
cr:translate(30,0)
|
||||
cr:move_to(50,50)
|
||||
cr:rotate(-math.pi/2)
|
||||
col_utils.arrow_path(cr,40)
|
||||
col_utils.arrow_path(cr,40,10)
|
||||
cr:fill()
|
||||
cr:restore()
|
||||
|
||||
cr:save()
|
||||
cr:translate(0,30)
|
||||
cr:move_to(50,50)
|
||||
col_utils.arrow_path(cr,40)
|
||||
col_utils.arrow_path(cr,40,10)
|
||||
cr:fill()
|
||||
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 cairo,beautiful = require( "lgi").cairo , require( "beautiful" )
|
||||
local awful = require("awful")
|
||||
local col_utils = require( "collision.util" )
|
||||
local module,indicators,cur_c,auto_hide = {},nil,nil
|
||||
|
||||
local values = {"top" , "top_right" , "right" , "bottom_right" ,
|
||||
"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 img = cairo.ImageSurface(cairo.Format.ARGB32, radius,radius)
|
||||
local cr = cairo.Context(img)
|
||||
|
@ -36,8 +22,8 @@ end
|
|||
|
||||
local function create_indicators()
|
||||
indicators = {}
|
||||
local arr = create_arrow( 20, 20, 10, beautiful.bg_alternate,beautiful.fg_normal )
|
||||
local arr_focus = create_arrow( 20, 20, 10, beautiful.fg_normal,beautiful.bg_normal )
|
||||
local arr = col_utils.arrow(20, 7, 10, beautiful.bg_alternate, beautiful.fg_normal )
|
||||
local arr_focus = col_utils.arrow(20, 7, 10, beautiful.fg_normal, beautiful.bg_normal )
|
||||
local angle = 0
|
||||
local shape_bounding = gen_shape_bounding(40)
|
||||
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
|
||||
end
|
||||
|
||||
function module.arrow_path(cr,width)
|
||||
cr:rel_move_to( 0 , -width/2 )
|
||||
cr:rel_line_to( width/2 , width/2 )
|
||||
cr:rel_line_to( -10 , 0 )
|
||||
cr:rel_line_to( 0 , width/2 )
|
||||
cr:rel_line_to( (-width)+20 , 0 )
|
||||
cr:rel_line_to( 0 , -width/2 )
|
||||
cr:rel_line_to( -10 , 0 )
|
||||
cr:rel_line_to( width/2 , -width/2)
|
||||
function module.arrow_path(cr, width, sidesize)
|
||||
cr:rel_move_to( 0 , -width/2 )
|
||||
cr:rel_line_to( width/2 , width/2 )
|
||||
cr:rel_line_to( -sidesize , 0 )
|
||||
cr:rel_line_to( 0 , width/2 )
|
||||
cr:rel_line_to( (-width)+2*sidesize , 0 )
|
||||
cr:rel_line_to( 0 , -width/2 )
|
||||
cr:rel_line_to( -sidesize , 0 )
|
||||
cr:rel_line_to( width/2 , -width/2 )
|
||||
cr:close_path()
|
||||
end
|
||||
|
||||
function module.arrow(width,bg,fg)
|
||||
local img = cairo.ImageSurface(cairo.Format.ARGB32, width, width)
|
||||
function module.arrow(width, sidesize, margin, bg_color, fg_color)
|
||||
local img = cairo.ImageSurface(cairo.Format.ARGB32, width+2*margin, width+2*margin)
|
||||
local cr = cairo.Context(img)
|
||||
cr:set_source(fg)
|
||||
cr:set_source(color(bg_color))
|
||||
cr:paint()
|
||||
cr:set_source(bg)
|
||||
cr:move_to(width/2,width/2)
|
||||
module.arrow_path(cr,width)
|
||||
cr:set_source(color(fg_color))
|
||||
cr:set_antialias(cairo.Antialias.NONE)
|
||||
cr:move_to(margin+width/2, margin+width/2)
|
||||
module.arrow_path(cr, width, sidesize)
|
||||
cr:fill()
|
||||
return cairo.Pattern.create_for_surface(img)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue