gears.shape: Add unit tests / examples / SVG generator

This commit is contained in:
Emmanuel Lepage Vallee 2016-03-09 23:44:00 -05:00
parent 9bd150f39a
commit ac15475c58
17 changed files with 201 additions and 0 deletions

10
tests/shape/arrow.lua Normal file
View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.arrow(cr, 70, 70)
show(cr) --DOC_HIDE
shape.arrow(cr,70,70, 30, 10, 60)
show(cr) --DOC_HIDE
shape.transform(shape.arrow) : rotate_at(35,35,math.pi/2)(cr,70,70)
show(cr) --DOC_HIDE

10
tests/shape/circle.lua Normal file
View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.circle(cr, 70, 70)
show(cr) --DOC_HIDE
shape.circle(cr,20,70)
show(cr) --DOC_HIDE
shape.transform(shape.circle) : scale(0.5, 1)(cr,70,70)
show(cr) --DOC_HIDE

10
tests/shape/cross.lua Normal file
View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.cross(cr, 70, 70)
show(cr) --DOC_HIDE
shape.cross(cr,20,70)
show(cr) --DOC_HIDE
shape.transform(shape.cross) : scale(0.5, 1)(cr,70,70)
show(cr) --DOC_HIDE

10
tests/shape/hexagon.lua Normal file
View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.hexagon(cr, 70, 70)
show(cr) --DOC_HIDE
shape.transform(shape.hexagon) : translate(0,15)(cr,70,20)
show(cr) --DOC_HIDE
shape.transform(shape.hexagon) : rotate_at(35,35,math.pi/2)(cr,70,40)
show(cr) --DOC_HIDE

View File

@ -0,0 +1,12 @@
local shape,cr,show = ... --DOC_HIDE
shape.infobubble(cr, 70, 70)
show(cr) --DOC_HIDE
shape.transform(shape.infobubble) : translate(0, 20)
: rotate_at(35,35,math.pi) (cr,70,20,10, 5, 35 - 5)
show(cr) --DOC_HIDE
shape.transform(shape.infobubble)
: rotate_at(35,35,3*math.pi/2) (cr,70,70, nil, nil, 40)
show(cr) --DOC_HIDE

View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.isosceles_triangle(cr, 70, 70)
show(cr) --DOC_HIDE
shape.isosceles_triangle(cr,20,70)
show(cr) --DOC_HIDE
shape.transform(shape.isosceles_triangle) : rotate_at(35, 35, math.pi/2)(cr,70,70)
show(cr) --DOC_HIDE

10
tests/shape/losange.lua Normal file
View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.losange(cr, 70, 70)
show(cr) --DOC_HIDE
shape.losange(cr,20,70)
show(cr) --DOC_HIDE
shape.transform(shape.losange) : scale(0.5, 1)(cr,70,70)
show(cr) --DOC_HIDE

10
tests/shape/octogon.lua Normal file
View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.octogon(cr, 70, 70)
show(cr) --DOC_HIDE
shape.octogon(cr,70,70,70/2.5)
show(cr) --DOC_HIDE
shape.transform(shape.octogon) : translate(0, 25) (cr,70,20)
show(cr) --DOC_HIDE

View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.parallelogram(cr, 70, 70)
show(cr) --DOC_HIDE
shape.parallelogram(cr,70,20)
show(cr) --DOC_HIDE
shape.transform(shape.parallelogram) : scale(0.5, 1)(cr,70,70)
show(cr) --DOC_HIDE

View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.partially_rounded_rect(cr, 70, 70)
show(cr) --DOC_HIDE
shape.partially_rounded_rect(cr, 70, 70, true)
show(cr) --DOC_HIDE
shape.partially_rounded_rect(cr, 70, 70, true, true, false, true, 30)
show(cr) --DOC_HIDE

10
tests/shape/powerline.lua Normal file
View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.powerline(cr, 70, 70)
show(cr) --DOC_HIDE
shape.transform(shape.powerline) : translate(0, 25) (cr,70,20)
show(cr) --DOC_HIDE
shape.transform(shape.powerline) : translate(0, 25) (cr,70,20, -20)
show(cr) --DOC_HIDE

View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.radial_progress(cr, 70, 20, .3)
show(cr, true) --DOC_HIDE
shape.radial_progress(cr, 70, 20, .6)
show(cr, true) --DOC_HIDE
shape.radial_progress(cr, 70, 20, .9)
show(cr, true) --DOC_HIDE

10
tests/shape/rectangle.lua Normal file
View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.rectangle(cr, 70, 70)
show(cr) --DOC_HIDE
shape.rectangle(cr,20,70)
show(cr) --DOC_HIDE
shape.transform(shape.rectangle) : scale(0.5, 1)(cr,70,70)
show(cr) --DOC_HIDE

View File

@ -0,0 +1,13 @@
local shape,cr,show = ... --DOC_HIDE
shape.rectangular_tag(cr, 70, 70)
show(cr) --DOC_HIDE
-- shape.rectangular_tag(cr,20,70) --TODO broken --DOC_HIDE
-- show(cr) --DOC_HIDE
shape.transform(shape.rectangular_tag) : translate(0, 30) (cr, 70, 10, 10)
show(cr) --DOC_HIDE
shape.transform(shape.rectangular_tag) : translate(0, 30) (cr, 70, 10, -10)
show(cr) --DOC_HIDE

View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.rounded_bar(cr, 70, 70)
show(cr) --DOC_HIDE
shape.rounded_bar(cr, 20, 70)
show(cr) --DOC_HIDE
shape.rounded_bar(cr, 70, 20)
show(cr) --DOC_HIDE

View File

@ -0,0 +1,10 @@
local shape,cr,show = ... --DOC_HIDE
shape.rounded_rect(cr, 70, 70, 10)
show(cr) --DOC_HIDE
shape.rounded_rect(cr,20,70, 5)
show(cr) --DOC_HIDE
shape.transform(shape.rounded_rect) : translate(0,25) (cr,70,20, 5)
show(cr) --DOC_HIDE

View File

@ -0,0 +1,36 @@
-- Test if shape crash when called
-- Also generate some SVG to be used by the documentation
-- it also "prove" that the code examples are all working
local cairo = require( "lgi" ).cairo
local shape = require( "gears.shape" )
local filepath, svgpath = ...
-- This is normal when running test, it will run twice
if (not filepath) or (not svgpath) or key then
os.exit(0)
end
local function get_surface(p)
local img = cairo.SvgSurface.create(p, 288, 76)
return cairo.Context(img)
end
local function show(cr, skip_fill)
if not skip_fill then
cr:set_source_rgba(0.380392156863,0.505882352941,1,0.5)
cr:fill_preserve()
end
cr:set_source_rgba(0.380392156863,0.505882352941,1,1)
cr:stroke()
cr:translate(96, 0)
cr:reset_clip()
cr:rectangle(-3,-3,76,76)
cr:clip()
end
local cr = get_surface(svgpath)
cr:translate(3,3)
loadfile(filepath)(shape, cr, show)