--- a/CairoGraphicsContext.st Mon Mar 21 22:28:05 2016 +0000
+++ b/CairoGraphicsContext.st Wed Mar 16 09:56:21 2016 +0000
@@ -6,7 +6,7 @@
instanceVariableNames:'cr'
classVariableNames:''
poolDictionaries:'Cairo::FontSlant Cairo::FontWeight Cairo::Format Cairo::Status
- Cairo::Antialias'
+ Cairo::Antialias Cairo::Extend'
category:'Cairo-Compatibility'
!
@@ -169,10 +169,25 @@
mask:aForm
"set the drawing mask"
- #todo.
super mask: aForm.
+ cr notNil ifTrue:[
+ self maskSet.
+ ].
- "Modified: / 27-02-2016 / 15:20:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (format): / 08-03-2016 / 21:22:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+maskOrigin:aPoint
+ "set the origin of the mask-pattern"
+
+ super maskOrigin: aPoint.
+ gcId notNil ifTrue:[
+ mask notNil ifTrue:[
+ self maskSet.
+ ].
+ ].
+
+ "Created: / 08-03-2016 / 21:23:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
paint: aColor
@@ -923,6 +938,46 @@
aBlock ensure:[ self transformation: savedTransformation ].
"Created: / 26-02-2016 / 09:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+maskSet
+ "Either mask or markOrigin changed. Update Cairo's source pattern"
+
+ | maskImage w h maskSurface maskPattern sourceSurface sourceContext sourcePattern |
+
+ mask isNil ifTrue:[
+ cr source: paint.
+ ^ self.
+ ].
+
+ maskImage := mask asImage.
+ w := maskImage width.
+ h := maskImage height.
+ [
+ sourceSurface := Cairo::Surface newImageWithFormat: CAIRO_FORMAT_ARGB32 width: w height: h similarTo: cr surface.
+ maskImage depth == 1 ifTrue:[
+ maskSurface := maskImage asSurfaceWithFormat: CAIRO_FORMAT_A1 similarTo: sourceSurface.
+ maskPattern := Cairo::Pattern surface: maskSurface.
+ maskPattern extend: CAIRO_EXTEND_REPEAT.
+ ] ifFalse:[
+ self error: 'Not yet supported'
+ ].
+ sourceContext := sourceSurface cairo.
+ maskOrigin notNil ifTrue:[
+ maskPattern matrix: (Cairo::Matrix translate: maskOrigin negated).
+ ].
+ sourceContext source: cr source.
+ sourceContext mask: maskPattern.
+ ] ensure:[
+ sourceContext notNil ifTrue:[sourceContext release].
+ maskPattern notNil ifTrue:[maskPattern release].
+ maskSurface notNil ifTrue:[maskSurface release].
+ ].
+ sourcePattern := Cairo::Pattern surface: sourceSurface.
+ sourcePattern extend: CAIRO_EXTEND_REPEAT.
+ cr source: sourcePattern.
+
+ "Created: / 08-03-2016 / 21:21:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CairoGraphicsContext class methodsFor:'documentation'!