diff --git a/lib/gears/shape.lua b/lib/gears/shape.lua index cc7dc605a..3858c0f4e 100644 --- a/lib/gears/shape.lua +++ b/lib/gears/shape.lua @@ -101,6 +101,30 @@ function module.rectangular_tag(cr, width, height) cr:close_path() end +--- A simple arrow shape +-- @param cr A cairo context +-- @tparam number width The shape with +-- @tparam number height The shape height +-- @tparam[opt=head_width] number head_width The width of the head (/\) of the arrow +-- @tparam[opt=width /2] number shaft_width The width of the shaft of the arrow +-- @tparam[opt=height/2] number shaft_length The head_length of the shaft (the rest is the head) +function module.arrow(cr, width, height, head_width, shaft_width, shaft_length) + local shaft_length = shaft_length or height / 2 + local shaft_width = shaft_width or width / 2 + local head_width = head_width or width + local head_length = height - shaft_length + + cr:move_to ( width/2 , 0 ) + cr:rel_line_to( head_width/2 , head_length ) + cr:rel_line_to( -(head_width-shaft_width)/2 , 0 ) + cr:rel_line_to( 0 , shaft_length ) + cr:rel_line_to( -shaft_width , 0 ) + cr:rel_line_to( 0 , -shaft_length ) + cr:rel_line_to( -(head_width-shaft_width)/2 , 0 ) + + cr:close_path() +end + --- Ajust the shape using a transformation object -- -- Apply various transformations to the shape