From a89b21ba2f2070948c36018f4100f352729e3c77 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 26 Jan 2016 02:35:35 -0500 Subject: [PATCH] gears.shape: Add arrow shape --- lib/gears/shape.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/gears/shape.lua b/lib/gears/shape.lua index cc7dc605..3858c0f4 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