Cairo__Examples1.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 25 Feb 2016 20:55:41 +0000
changeset 50 239120c68187
child 51 5293f2b851ab
permissions -rw-r--r--
Added classes with examples and example viewers * Cairo::Examples1 (and viewer Cairo::Examples1Viewer) contains some examples of using Cairo API for drawing. * Cairo::Examples2 (and viewer Cairo::Examples2Viewer) contains examples of using CairoGraphicsContext. The viewer application show result of the drawing on both native DeviceGraphicsContext and CairoGraphicsContext so one can easily compare results. Cairo should give better results.

"{ Package: 'stx:goodies/libcairo' }"

"{ NameSpace: Cairo }"

TestCase subclass:#Examples1
	instanceVariableNames:'view surface'
	classVariableNames:''
	poolDictionaries:''
	category:'Cairo-Examples'
!

!Examples1 class methodsFor:'accessing'!

isTestSelector:aSelector
    | method |

    aSelector isNil ifTrue:[ ^ false ].
    method := self lookupMethodFor: aSelector.
    ^ method notNil 
        and:[(method hasAnnotation: #example:) or:[ method hasAnnotation: #example:category: ] ]

    "
    Cairo::Examples1 isTestSelector: #example01:
    "

    "Created: / 26-02-2016 / 21:57:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!Examples1 class methodsFor:'private'!

testSelectors
        "The API method is allTestSelectors which now includes #shouldInheritSelectors and so handles all cases.  Unlike that method, this does not guarantee to return a sorted ordered collection."

        ^self sunitSelectors select: [:each | self isTestSelector: each ]

    "Created: / 26-02-2016 / 22:40:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!Examples1 methodsFor:'examples'!

example01: cr <example: '01 - arc'>
| xc yc radius angle1 angle2 |

xc := 128.
yc := 128.
radius := 100.
angle1 := 45 * (Float pi / 180).
angle2 := 180 * (Float pi / 180).

cr sourceR: 1.0 G: 1.0 B: 1.0.
cr lineWidth: 10.
cr arcX: xc y: yc radius: radius from: angle1 to: angle2.
cr stroke.

    "Created: / 26-02-2016 / 21:53:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!Examples1 methodsFor:'private'!

performTest
    | cr |

    cr := Cairo::GraphicsContext onSurface: surface.
    [
        self perform: testSelector sunitAsSymbol with: cr.
    ] ensure:[ 
        cr release
    ].

    "Created: / 26-02-2016 / 22:01:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!Examples1 methodsFor:'running'!

setUp
    Display notNil ifTrue:[ 
        | top |

        top := StandardSystemView new.
        top origin: 10@10 extent: 200@100.       
        view := SimpleView origin: 0.0 @ 0.0 corner: 1.0 @ 1.0 in: top.
        top openAndWait.
        surface := view cairoSurface.

    ].

    "Created: / 26-02-2016 / 22:15:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

tearDown
    view notNil ifTrue:[ 
        view topView close.
    ].
    surface notNil ifTrue:[ 
        surface release.
    ].

    "Created: / 26-02-2016 / 22:18:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !