--- a/CairoGraphicsContext.st Mon Mar 28 00:19:56 2016 +0100
+++ b/CairoGraphicsContext.st Fri Mar 25 22:05:01 2016 +0000
@@ -135,9 +135,19 @@
"Modified: / 21-02-2016 / 15:38:52 / jv"
!
+cairo
+ "Return a Cairo context for drawing onto this GC"
+ | ncr |
+
+ ncr := Cairo::GraphicsContext onSurface: super cairoSurface.
+ ^ ncr.
+
+ "Created: / 31-03-2016 / 00:13:07 / jv"
+!
+
cairoSurface
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
cr isNil ifTrue:[
^ super cairoSurface
@@ -255,6 +265,17 @@
].
"Created: / 05-03-2016 / 16:35:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+width: width height: height
+ device isX11Platform ifTrue:[
+ cr surface width: width height: height
+ ] ifFalse:[
+ self destroyCR.
+ ].
+
+ "Created: / 02-04-2016 / 15:37:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 02-04-2016 / 15:55:29 / jv"
! !
!CairoGraphicsContext methodsFor:'accessing-transformation'!
@@ -281,8 +302,8 @@
displayArcX:x y:y width:w height:h from:start angle:angle
| angle1 angle2 |
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
cr save.
[
@@ -313,8 +334,8 @@
displayLineFromX:x0 y:y0 toX:x1 y:y1
"draw a line from x0/y0 to x1/y1"
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
x0 = x1 ifTrue:[
cr moveToX: x0 + 0.5 y: y0.
@@ -339,8 +360,8 @@
"draw a polygon
- this could be recoded to draw using displayLine"
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
cr moveToX: points first x asFloat y: points first y asFloat.
2 to: points size do:[:i |
@@ -357,8 +378,8 @@
"draw a rectangle
- this could be recoded to draw using displayLine"
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
(w > 0 and:[h > 0]) ifTrue:[
cr rectangleX: x + 0.5 y: y + 0.5 width: w - 0.5 height: h - 0.5.
@@ -387,7 +408,7 @@
opaque := false.
].
- gcId isNil ifTrue:[
+ cr isNil ifTrue:[
self initGC
].
@@ -419,8 +440,8 @@
fillArcX:x y:y width:w height:h from:start angle:angle
| angle1 angle2 |
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
cr save.
[
@@ -458,8 +479,8 @@
fillPolygon:points
"fill a polygon with current paint color"
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
cr moveToX: points first x asFloat y: points first y asFloat.
2 to: points size do:[:i |
@@ -476,8 +497,8 @@
fillRectangleX:x y:y width:w height:h
"fill a rectangle with current paint color"
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
(w > 0 and:[h > 0]) ifTrue:[
| savedWidth |
@@ -563,6 +584,43 @@
"Modified: / 24-02-2016 / 18:19:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!CairoGraphicsContext methodsFor:'change & update'!
+
+update: aspect with: param from: sender
+ aspect == #sizeOfView ifTrue:[
+ self updateCR.
+ ^ self.
+ ].
+ super update: aspect with: param from: sender
+
+ "Created: / 29-03-2016 / 23:00:56 / jv"
+!
+
+updateCR
+ "Called when view associated with given context
+ changes its size"
+
+ cr notNil ifTrue:[
+ device isWindowsPlatform ifTrue:[
+ | surface blocked |
+
+ blocked := OperatingSystem blockInterrupts.
+
+ surface := cr surface.
+ cr release.
+ surface release.
+ device dcUnlockForGC: gcId.
+ cr := nil.
+ blocked ifFalse:[
+ OperatingSystem unblockInterrupts.
+ ]
+ ]].
+
+ "Created: / 29-03-2016 / 22:58:49 / jv"
+ "Modified: / 31-03-2016 / 00:39:48 / jv"
+ "Modified: / 02-04-2016 / 15:38:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!CairoGraphicsContext methodsFor:'drawing'!
displayForm:aFormOrImage x:x y:y
@@ -590,8 +648,8 @@
[
image bitsARGB32Into: imageSurface data startingAt: 1 stride: imageSurface stride.
imageSurface markDirty.
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
cr sourceSurface: imageSurface x: x y: y.
@@ -632,8 +690,8 @@
displayRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
| r pi |
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
wCorn ~~ hCorn ifTrue:[
self notYetImplemented.
@@ -817,8 +875,8 @@
fillRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
| r pi |
- gcId isNil ifTrue:[
- self initGC.
+ cr isNil ifTrue:[
+ self initCR.
].
wCorn ~~ hCorn ifTrue:[
self notYetImplemented.
@@ -909,17 +967,24 @@
this instance should be treated as invalid."
cr notNil ifTrue:[
- | surfaceToDestroy crToDestroy |
+ | wasBlocked surfaceToDestroy crToDestroy |
+
+ wasBlocked := OperatingSystem unblockInterrupts.
crToDestroy := cr.
surfaceToDestroy := cr surface.
cr := nil.
crToDestroy release.
surfaceToDestroy release.
+ device dcUnlockForGC: gcId.
+ wasBlocked ifFalse:[
+ OperatingSystem unblockInterrupts.
+ ]
].
"Created: / 12-02-2016 / 16:59:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 26-02-2016 / 22:50:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (format): / 02-04-2016 / 16:07:22 / jv"
!
destroyGC
@@ -934,12 +999,25 @@
!
initCR
- | f |
+ | view f |
+ gcId isNil ifTrue:[
+ self initGC.
+ ].
cr isNil ifTrue:[
self createCR.
Lobby registerChange: self.
].
+ device isWindowsPlatform ifTrue:[
+ view := cr surface view.
+ view notNil ifTrue:[
+ view addDependent: self.
+ view container notNil ifTrue:[
+ view container addDependent: self.
+ ].
+ ].
+ ].
+
cr antialias: CAIRO_ANTIALIAS_NONE.
cr lineWidth: (lineWidth == 0 ifTrue:[ 1 ] ifFalse:[ lineWidth ]).
cr source: paint.
@@ -951,14 +1029,8 @@
self basicFont: f.
"Created: / 18-02-2016 / 22:48:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 21-03-2016 / 21:31:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-initGC
- super initGC.
- self initCR.
-
- "Created: / 18-02-2016 / 22:48:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 29-03-2016 / 23:57:30 / jv"
+ "Modified: / 02-04-2016 / 15:39:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
releaseCR
@@ -1030,6 +1102,20 @@
cr source: sourcePattern.
"Created: / 08-03-2016 / 21:21:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+subViewChangedSizeOrOrigin
+ "Internal. Called whenever one of the owner's
+ subview changes size or origin (i.e., when moved)
+ See SimpleView>>pixelOrigin:extent:.
+ Can be used to adjust internal state."
+
+ device isX11Platform ifFalse:[
+ self destroyGC.
+ ].
+ "/ Nothing by default
+
+ "Created: / 02-04-2016 / 16:04:55 / jv"
! !
!CairoGraphicsContext class methodsFor:'documentation'!