gears.shape: Add arrow shape

This commit is contained in:
Emmanuel Lepage Vallee 2016-01-26 02:35:35 -05:00
parent 1060a3487e
commit a89b21ba2f
1 changed files with 24 additions and 0 deletions

View File

@ -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