Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
...into two separate classes for cleaner responsibilities. Also, API of Smalltalk/X graphics
contexts does not play well with Cairo's save/restore semantics.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CairoGraphicsContext.st Sat Feb 13 17:10:25 2016 +0000
@@ -0,0 +1,528 @@
+"{ Package: 'stx:goodies/libcairo' }"
+
+"{ NameSpace: Smalltalk }"
+
+DeviceGraphicsContext subclass:#CairoGraphicsContext
+ instanceVariableNames:'cr crId'
+ classVariableNames:'Lobby'
+ poolDictionaries:'Cairo::FontSlant Cairo::FontWeight Cairo::Format'
+ category:'Cairo-Compatibility'
+!
+
+
+!CairoGraphicsContext class methodsFor:'initialization'!
+
+initialize
+ "Invoked at system start or when the class is dynamically loaded."
+
+ "/ please change as required (and remove this comment)
+
+ Lobby := Registry new.
+
+ "Modified: / 09-01-2015 / 15:08:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CairoGraphicsContext class methodsFor:'accessing'!
+
+dllPath
+
+ OperatingSystem isMSWINDOWSlike ifTrue:[
+ ^ #( 'C:\Windows' 'C:\Windows\System32' "Wild guess, should not harm" )
+ ].
+
+ OperatingSystem isUNIXlike ifTrue:[
+ OperatingSystem getSystemType == #linux ifTrue:[
+ | path |
+
+ path := #( '/lib' '/usr/lib' '/usr/local/lib' ).
+ (OperatingSystem getSystemInfo at:#machine) = 'x86_64' ifTrue:[
+ "If the machine is 64bit, prepend standard path for 32bit libs.
+ Leave standard paths at the end, as the system might be completely
+ 32bit but running on 64bit-capable CPU.
+
+ CAVEAT: This is bit dangerous, as on 64bit OS, if ia32 libs are
+ not installed byt 64bit sqlite libs are, then 64bit libs are found
+ and when a function is called, segfault will occur!!
+
+ Q: Is there a way how to figure out if the OS itself is 32bit,
+ regardles on CPU?"
+ path := #( '/lib32' '/usr/lib32' '/usr/local/lib32' ) , path.
+ ].
+ ^path
+
+ ].
+ ].
+
+ self error:'Unsupported operating system'
+
+ "
+ SqliteLibrary dllPath
+ "
+
+ "Created: / 31-08-2011 / 18:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+libraryName
+
+ OperatingSystem isUNIXlike ifTrue:[^'libcairo.so.2'].
+
+ OperatingSystem isMSWINDOWSlike ifTrue:[^'cairo.dll'].
+
+ self error:'Library name for host OS is not known'
+!
+
+sizeof
+ "Returns size of undelaying structure in bytes"
+
+ ^0
+! !
+
+!CairoGraphicsContext class methodsFor:'examples'!
+
+rectangleOnTranscript
+
+ "
+ Cairo::GraphicsContext rectangleOnTranscript
+ "
+
+
+ | gc |
+ gc := Transcript cairo.
+ gc paint: Color black.
+ gc moveToX: 30 y: 50.
+ gc paint: (Color red alpha: 0.5).
+ gc rectangleX: 10 y: 15 width: 150 height: 60.
+ gc fill.
+ gc paint: (Color red alpha: 0.75).
+ gc rectangleX: 10 y: 15 width: 150 height: 60.
+ gc stroke.
+
+ "Created: / 23-04-2009 / 17:33:57 / Jan Vrany <vranyj1@fel.cvut.cz>"
+! !
+
+!CairoGraphicsContext methodsFor:'accessing'!
+
+font:aFont
+ | dfont family slant psize weight |
+
+ dfont := aFont onDevice: device.
+
+ family := dfont family.
+ slant := SymbolicFontSlantToCairoFontSlantMap at: (dfont style ? 'roman').
+ weight := SymbolicFontFaceToCairoFontWeightMap at: (dfont face ? 'regular').
+
+ cr font: family slant: slant weight: weight.
+
+ psize := dfont pixelSize.
+ psize isNil ifTrue:[
+ psize := (self device verticalPixelPerInch / 72) * dfont size.
+ ].
+ cr fontSize: psize .
+
+ font := ScaledFont family: dfont family face: dfont face style: dfont style size: dfont size.
+ font handle: (CPrimitives cairo_get_scaled_font: crId).
+
+ "Modified: / 13-02-2016 / 21:17:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+function:aFunctionSymbol
+ "set the drawing function"
+
+ ^ self shouldImplement
+!
+
+lineWidth: w
+ super lineWidth: w.
+ cr lineWidth: w.
+
+ "Created: / 17-06-2012 / 21:55:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 17:38:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+mask:aForm
+ "set the drawing mask"
+
+ ^ self shouldImplement
+!
+
+paint: aColor
+ super paint: aColor.
+ cr source: paint.
+
+ "Created: / 10-07-2008 / 11:18:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 23-04-2009 / 17:31:33 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 13-02-2016 / 17:39:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CairoGraphicsContext methodsFor:'accessing-transformation'!
+
+transformation:aTransformation
+ "set the transformation"
+
+ super transformation: aTransformation.
+ cr
+ matrixReset;
+ scale: transformation scale;
+ transform: transformation translation.
+
+ "Created: / 01-01-2015 / 12:07:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 19:55:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CairoGraphicsContext methodsFor:'basic drawing'!
+
+displayArcX:x y:y width:w height:h from:start angle:angle
+
+ | angle1 angle2 |
+
+ cr save.
+ [
+ w ~~ h ifTrue:[
+ self notYetImplemented
+ ].
+
+ angle1 := (360 - start) .
+ angle2 := (360 - (start + angle)) \\ 360.
+
+ (angle2 < angle1) ifTrue:[
+ cr arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle1 * (Float pi / 180) to: angle2 * (Float pi / 180).
+ ] ifFalse:[
+ cr arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle2 * (Float pi / 180) to: angle1 * (Float pi / 180).
+ ].
+ cr stroke.
+
+ w ~~ h ifTrue:[
+ self notYetImplemented
+ ].
+ ] ensure:[
+ cr restore.
+ ]
+
+ "Modified: / 13-02-2016 / 20:05:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+displayLineFromX:x0 y:y0 toX:x1 y:y1
+ "draw a line from x0/y0 to x1/y1"
+
+ cr moveToX: x0 y: y0.
+ cr lineToX: x1 y: y1.
+ cr stroke.
+
+ "Modified: / 13-02-2016 / 20:05:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+displayOpaqueString:aString from:index1 to:index2 x:x y:y maxWitdh:maxWidth
+ "draw part of a string with both fg and bg at x/y in current font"
+
+ ^ self shouldImplement
+!
+
+displayPolygon:points
+ "draw a polygon
+ - this could be recoded to draw using displayLine"
+
+ cr moveToX: points first x asFloat y: points first y asFloat.
+ 2 to: points size do:[:i |
+ cr lineToX: (points at: i) x asFloat y: (points at: i) y asFloat
+ ].
+ cr closePath.
+ cr stroke.
+
+ "Modified: / 13-02-2016 / 20:04:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+displayRectangleX:x y:y width:w height:h
+ "draw a rectangle
+ - this could be recoded to draw using displayLine"
+
+ cr rectangleX: x y: y width: w height: h.
+ cr stroke.
+
+ "Modified: / 13-02-2016 / 20:04:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+displayString:aString from:index1 to:index2 x:x y:y
+ "draw part of a string with fg at x/y in current font"
+
+ cr save.
+ [
+ cr moveToX: x y: y.
+ (index1 == 1 and:[ index2 == aString size ]) ifTrue:[
+ cr showText: aString
+ ] ifFalse:[
+ cr showText: (aString copyFrom: index1 to: index2).
+ ].
+ ] ensure:[
+ cr restore.
+ ]
+
+ "Modified: / 13-02-2016 / 20:04:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CairoGraphicsContext methodsFor:'basic filling'!
+
+fillArcX:x y:y width:w height:h from:start angle:angle
+
+ | angle1 angle2 |
+
+ cr save.
+ [
+ w ~~ h ifTrue:[
+ self notYetImplemented
+ ].
+
+
+ angle1 := (360 - start) .
+ angle2 := (360 - (start + angle)) \\ 360.
+
+ cr moveToX: (x + (w / 2)) y: (y + (h / 2)).
+
+ (angle2 < angle1) ifTrue:[
+ cr arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle1 * (Float pi / 180) to: angle2 * (Float pi / 180).
+ ] ifFalse:[
+ cr arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle2 * (Float pi / 180) to: angle1 * (Float pi / 180).
+ ].
+ cr closePath.
+
+ cr strokeAndPreserve.
+ cr fill.
+
+ w ~~ h ifTrue:[
+ self notYetImplemented
+ ].
+ ] ensure:[
+ cr restore.
+ ]
+
+ "Modified: / 13-02-2016 / 20:03:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+fillPolygon:points
+ "fill a polygon with current paint color"
+
+ cr moveToX: points first x asFloat y: points first y asFloat.
+ 2 to: points size do:[:i |
+ cr lineToX: (points at: i) x asFloat y: (points at: i) y asFloat
+ ].
+ cr closePath.
+ cr strokeAndPreserve.
+ cr fill.
+
+ "Modified: / 13-02-2016 / 20:01:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+fillRectangleX:x y:y width:w height:h
+ "fill a rectangle with current paint color"
+
+ cr rectangleX: x y: y width: w height: h.
+ cr strokeAndPreserve.
+ cr fill.
+
+ "Modified: / 13-02-2016 / 20:01:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CairoGraphicsContext methodsFor:'bit blitting'!
+
+copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h
+ "copy from a drawable - maybe self"
+
+ ^ self shouldImplement
+! !
+
+!CairoGraphicsContext methodsFor:'drawing'!
+
+displayForm:aFormOrImage x:x y:y
+ "draw a form (or image) at x/y;
+ if the form has depth 1, 1's in the form are
+ drawn in current paint color, 0's are ignored.
+ If the form has depth ~~ 1, the current fg color setting is ignored."
+
+ | image width height stride data image_surface |
+
+ image := aFormOrImage asImage.
+ width := image width.
+ height := image height.
+ stride := CPrimitives cairo_format_stride_for_width: CAIRO_FORMAT_ARGB32 _: width.
+ data := ExternalBytes basicNew allocateBytes: stride * height clear: false.
+ [
+ image bitsARGB32Into: data stride: stride fg: self paint bg: self backgroundPaint.
+ image_surface := CPrimitives cairo_image_surface_create_for_data: data _: CAIRO_FORMAT_ARGB32 _: width _: height _: stride.
+ CPrimitives cairo_set_source_surface: crId _: image_surface _: x asFloat _: y asFloat.
+ CPrimitives cairo_paint: crId.
+ ] ensure:[
+ data finalize.
+ image_surface release.
+ ].
+
+ "Created: / 31-12-2014 / 12:08:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 01-01-2015 / 02:48:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+displayRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
+ | r pi |
+ wCorn ~~ hCorn ifTrue:[
+ self notYetImplemented.
+ ].
+ r := wCorn / 2.
+ pi := Float pi.
+
+ "/ top-left arc
+ cr arcX: x + r y: y + r radius: r from: pi to: (3/2) * pi.
+ "/ top-right atc
+ cr arcX: x + w - r y: y + r radius: r from: (3/2) * pi to: 0.0.
+ "/ bottom-right atc
+ cr arcX: x + w - r y: y + h - r radius: r from: 0.0 to: (1/2) * pi.
+ "/ bottom-left atc
+ cr arcX: x + r y: y + h - r radius: r from: (1/2) * pi to: pi.
+ cr closePath.
+ cr stroke.
+
+ "
+ |v|
+
+ (v := View new) extent:200@200; openAndWait.
+ v cairo
+ lineWidth: 5;
+ displayRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20;
+ release
+ "
+
+ "Created: / 07-01-2015 / 20:41:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 20:00:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CairoGraphicsContext methodsFor:'filling'!
+
+fillRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
+ | r pi |
+ wCorn ~~ hCorn ifTrue:[
+ self notYetImplemented.
+ ].
+ r := wCorn / 2.
+ pi := Float pi.
+
+ "/ top-left arc
+ cr arcX: x + r y: y + r radius: r from: pi to: (3/2) * pi.
+ "/ top-right atc
+ cr arcX: x + w - r y: y + r radius: r from: (3/2) * pi to: 0.0.
+ "/ bottom-right atc
+ cr arcX: x + w - r y: y + h - r radius: r from: 0.0 to: (1/2) * pi.
+ "/ bottom-left atc
+ cr arcX: x + r y: y + h - r radius: r from: (1/2) * pi to: pi.
+ cr closePath.
+ cr fill.
+
+ "
+ |v|
+
+ (v := View new) extent:200@200; openAndWait.
+ v cairo
+ lineWidth: 5;
+ displayRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20;
+ release
+ "
+
+ "Created: / 07-01-2015 / 21:33:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 20:00:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CairoGraphicsContext methodsFor:'finalization'!
+
+executor
+ ^ super executor
+ "/^ self shallowCopy
+
+ "Created: / 12-02-2016 / 17:04:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+finalization
+ self destroy
+
+ "Created: / 09-01-2015 / 10:20:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+finalizationLobby
+ "answer a Registry used for finalization.
+ Use a generic Registry for any object.
+ Subclasses using their own Registry should redefine this"
+
+ ^ Lobby
+
+ "Created: / 09-01-2015 / 10:20:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CairoGraphicsContext methodsFor:'initialization & release'!
+
+createCR
+ "Physically create a Cairo graphics context"
+
+ cr := self cairo.
+
+ "Created: / 12-02-2016 / 16:59:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 19:56:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+createGC
+ "physically create a device GC.
+ Since we do not need a gc-object for the drawable until something is
+ really drawn, none is created up to the first draw.
+ This method is sent, when the first drawing happens"
+ super createGC.
+ self createCR
+
+ "Created: / 12-02-2016 / 16:58:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+destroyCR
+ "Tell Cairo library to destroy the corresponding C object.
+ Remember that object is physically destroyed only if internal
+ refcounter goes to zero. However, after calling destroy,
+ this instance should be treated as invalid."
+
+ cr notNil ifTrue:[
+ | surface |
+
+ surface := cr surface.
+ cr release.
+ surface release.
+ ].
+
+ "Created: / 12-02-2016 / 16:59:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 19:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+destroyGC
+ self destroyCR.
+ super destroyGC
+
+ "Created: / 12-02-2016 / 17:01:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+releaseCR
+ self destroyCR
+
+ "Created: / 12-02-2016 / 17:02:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+releaseGC
+ "destroy the associated device GC resource - can be done to be nice to the
+ display if you know that you are done with a drawable."
+
+ self releaseCR.
+ super releaseGC.
+
+ "Created: / 12-02-2016 / 17:03:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CairoGraphicsContext class methodsFor:'documentation'!
+
+version
+ ^'$Id$'
+!
+
+version_HG
+ ^ '$Changeset: <not expanded> $'
+! !
+
+
+CairoGraphicsContext initialize!
--- a/Cairo__CObject.st Fri Feb 12 16:36:39 2016 +0000
+++ b/Cairo__CObject.st Sat Feb 13 17:10:25 2016 +0000
@@ -54,12 +54,11 @@
!CObject methodsFor:'initialization & release'!
release
- self setAddress: nil.
self unregisterForFinalization.
^self destroy
"Created: / 25-12-2014 / 10:34:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 28-12-2014 / 21:41:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 16:10:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CObject methodsFor:'private'!
--- a/Cairo__CPrimitives.st Fri Feb 12 16:36:39 2016 +0000
+++ b/Cairo__CPrimitives.st Sat Feb 13 17:10:25 2016 +0000
@@ -129,8 +129,10 @@
cairo_create: target
- <cdecl: handle "cairo_create" ( Cairo::Surface ) >
+ <cdecl: Cairo::GraphicsContext "cairo_create" ( Cairo::Surface ) >
self primitiveFailed
+
+ "Modified (format): / 13-02-2016 / 16:06:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
cairo_curve_to: cr _: x1 _: y1 _: x2 _: y2 _: x3 _: y3
--- a/Cairo__ClockView.st Fri Feb 12 16:36:39 2016 +0000
+++ b/Cairo__ClockView.st Sat Feb 13 17:10:25 2016 +0000
@@ -50,26 +50,6 @@
"Modified: / 12-02-2016 / 16:40:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
-!ClockView methodsFor:'initialization & release'!
-
-initializeForDevice:aDevice
- "allocate a GraphicsContext for a device"
-
- aDevice notNil ifTrue:[
- gc := Cairo::GraphicsContext onDevice: aDevice
- ] ifFalse:[
- "should not be reached"
- GraphicsMedium superclass == DeviceGraphicsContext ifTrue:[
- gc := self.
- super device:aDevice.
- ].
- ].
-
- self initialize.
-
- "Created: / 12-02-2016 / 16:00:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
!ClockView methodsFor:'redrawing'!
redraw
@@ -96,16 +76,16 @@
"/ the center of the window
cr save.
cr scale: self extent.
- cr translateBy: (0.5 @ 0.5).
+ cr translate: (0.5 @ 0.5).
cr lineWidth: 0.05.
- cr paint: (Color red: 33 green: 61 blue: 11).
+ cr sourceR: 0.33 G: 0.61 B: 0.11.
cr paint.
cr arcX: 0 y: 0 radius: 0.42 from: 0 to: (2 * (Float pi)).
- cr paint: Color white.
+ cr sourceR: 1.0 G: 1.0 B: 1.0.
cr fillAndPreserve.
- cr paint: Color black.
+ cr sourceR: 0.0 G: 0.0 B: 0.0.
cr strokeAndPreserve.
cr clip.
@@ -148,7 +128,7 @@
"/ draw the seconds hand
cr save.
cr lineWidth: 0.016.
- cr paint: ((Color red: 70 green: 70 blue: 70) alpha: 0.8).
+ cr source: ((Color red: 70 green: 70 blue: 70) alpha: 0.8).
cr moveToX: 0.0 y: 0.0.
cr lineToX: (secs sin * (0.42 * 0.9))
y: (-1 * (secs cos * (0.42 * 0.9))).
@@ -156,14 +136,14 @@
cr restore.
"/ draw th minutes
- cr paint: ((Color red: 11 green: 33 blue: 61) alpha: 0.7).
+ cr source: ((Color red: 11 green: 33 blue: 61) alpha: 0.7).
cr moveToX: 0.0 y: 0.0.
cr lineToX: ((mins + (secs / 60)) sin * (0.42 * 0.8))
y: (-1 * ((mins + (secs / 60)) cos * (0.42 * 0.8))).
cr stroke.
"/ draw the hours hand
- cr paint: ((Color red: 33 green: 61 blue: 11) alpha: 0.6).
+ cr source: ((Color red: 33 green: 61 blue: 11) alpha: 0.6).
cr moveToX: 0.0 y: 0.0.
cr lineToX: ((hours + (mins / 12)) sin * (0.42 * 0.5))
y: (-1 * ((hours + (mins / 12)) cos * (0.42 * 0.5))).
@@ -181,7 +161,7 @@
cr restore.
"Created: / 27-12-2014 / 00:00:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 12-02-2016 / 16:45:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 17:01:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!ClockView class methodsFor:'documentation'!
--- a/Cairo__DeviceType.st Fri Feb 12 16:36:39 2016 +0000
+++ b/Cairo__DeviceType.st Sat Feb 13 17:10:25 2016 +0000
@@ -13,6 +13,7 @@
category:'Cairo-Constants'
!
+
!DeviceType class methodsFor:'initialization'!
initialize
@@ -75,5 +76,12 @@
^CAIRO_DEVICE_TYPE_XML
! !
+!DeviceType class methodsFor:'documentation'!
+
+version_HG
+
+ ^ '$Changeset: <not expanded> $'
+! !
+
DeviceType initialize!
--- a/Cairo__GraphicsContext.st Fri Feb 12 16:36:39 2016 +0000
+++ b/Cairo__GraphicsContext.st Sat Feb 13 17:10:25 2016 +0000
@@ -2,464 +2,132 @@
"{ NameSpace: Cairo }"
-DeviceGraphicsContext subclass:#GraphicsContext
- instanceVariableNames:'surface crId saved savedPos'
- classVariableNames:'Lobby'
- poolDictionaries:'Cairo::FontSlant Cairo::FontWeight Cairo::Format'
+CObject subclass:#GraphicsContext
+ instanceVariableNames:'surface'
+ classVariableNames:''
+ poolDictionaries:''
category:'Cairo-Objects'
!
-
-!GraphicsContext class methodsFor:'initialization'!
-
-initialize
- "Invoked at system start or when the class is dynamically loaded."
-
- "/ please change as required (and remove this comment)
-
- Lobby := Registry new.
-
- "Modified: / 09-01-2015 / 15:08:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
!GraphicsContext class methodsFor:'instance creation'!
onSurface: surface
- | handle |
+ | instance |
self
assert: (surface isKindOf: Cairo::Surface)
message: 'surface is not valid Cairo surface'.
- handle := CPrimitives cairo_create: surface.
- ^ self new initializeWithHandle: handle surface: surface
+ instance := CPrimitives cairo_create: surface.
+ ^ instance initializeWithSurface: surface
"Created: / 28-12-2014 / 23:45:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified (format): / 12-02-2016 / 16:19:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!GraphicsContext class methodsFor:'accessing'!
-
-dllPath
-
- OperatingSystem isMSWINDOWSlike ifTrue:[
- ^ #( 'C:\Windows' 'C:\Windows\System32' "Wild guess, should not harm" )
- ].
-
- OperatingSystem isUNIXlike ifTrue:[
- OperatingSystem getSystemType == #linux ifTrue:[
- | path |
-
- path := #( '/lib' '/usr/lib' '/usr/local/lib' ).
- (OperatingSystem getSystemInfo at:#machine) = 'x86_64' ifTrue:[
- "If the machine is 64bit, prepend standard path for 32bit libs.
- Leave standard paths at the end, as the system might be completely
- 32bit but running on 64bit-capable CPU.
-
- CAVEAT: This is bit dangerous, as on 64bit OS, if ia32 libs are
- not installed byt 64bit sqlite libs are, then 64bit libs are found
- and when a function is called, segfault will occur!!
-
- Q: Is there a way how to figure out if the OS itself is 32bit,
- regardles on CPU?"
- path := #( '/lib32' '/usr/lib32' '/usr/local/lib32' ) , path.
- ].
- ^path
-
- ].
- ].
-
- self error:'Unsupported operating system'
-
- "
- SqliteLibrary dllPath
- "
-
- "Created: / 31-08-2011 / 18:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-libraryName
-
- OperatingSystem isUNIXlike ifTrue:[^'libcairo.so.2'].
-
- OperatingSystem isMSWINDOWSlike ifTrue:[^'cairo.dll'].
-
- self error:'Library name for host OS is not known'
-!
-
-sizeof
- "Returns size of undelaying structure in bytes"
-
- ^0
-! !
-
-!GraphicsContext class methodsFor:'examples'!
-
-rectangleOnTranscript
-
- "
- Cairo::GraphicsContext rectangleOnTranscript
- "
-
-
- | gc |
- gc := Transcript cairo.
- gc paint: Color black.
- gc moveToX: 30 y: 50.
- gc paint: (Color red alpha: 0.5).
- gc rectangleX: 10 y: 15 width: 150 height: 60.
- gc fill.
- gc paint: (Color red alpha: 0.75).
- gc rectangleX: 10 y: 15 width: 150 height: 60.
- gc stroke.
-
- "Created: / 23-04-2009 / 17:33:57 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 13-02-2016 / 16:07:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GraphicsContext methodsFor:'accessing'!
-cairo
- gcId isNil ifTrue:[
- self initGC.
- self assert: crId notNil
- ] ifFalse:[
- crId notNil ifTrue:[
-"/ CPrimitives cairo_destroy: crId.
-"/ crId := CPrimitives cairo_create: surface.
- ].
- ].
-
- ^ self
-
- "Created: / 12-02-2016 / 16:03:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 12-02-2016 / 17:10:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-device
- ^ device
-
- "Created: / 29-12-2014 / 18:44:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-deviceClippingBoundsOrNil
- ^ clipRect
-
- "Created: / 02-01-2015 / 12:36:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-font:aFont
- | dfont family slant psize weight |
-
- dfont := aFont onDevice: device.
-
- family := dfont family.
- slant := SymbolicFontSlantToCairoFontSlantMap at: (dfont style ? 'roman').
- weight := SymbolicFontFaceToCairoFontWeightMap at: (dfont face ? 'regular').
-
- self font: family slant: slant weight: weight.
-
- psize := dfont pixelSize.
- psize isNil ifTrue:[
- psize := (self device verticalPixelPerInch / 72) * dfont size.
- ].
- self fontSize: psize .
-
- font := ScaledFont family: dfont family face: dfont face style: dfont style size: dfont size.
- font handle: (CPrimitives cairo_get_scaled_font: crId).
-
- "Modified: / 09-01-2015 / 15:43:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-function:aFunctionSymbol
- "set the drawing function"
-
- ^ self shouldImplement
-!
-
-lineWidth: w
- lineWidth ~~ w ifTrue:[
- super lineWidth: w.
- CPrimitives cairo_set_line_width: crId _:w asFloat
- ].
-
- "Created: / 17-06-2012 / 21:55:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 02-01-2015 / 00:18:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-mask:aForm
- "set the drawing mask"
-
- ^ self shouldImplement
-!
-
-paint: aColor
-
-"/ paint ~= aColor ifTrue:[
- paint := aColor ? Black.
- CPrimitives cairo_set_source_rgba: crId _: (paint red / 100) asDouble _: (paint green / 100) asDouble _: (paint blue / 100) asDouble _: paint alpha asDouble
-"/ ].
-
- "Created: / 10-07-2008 / 11:18:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
- "Modified: / 23-04-2009 / 17:31:33 / Jan Vrany <vranyj1@fel.cvut.cz>"
- "Modified: / 02-01-2015 / 00:51:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
referenceCount
"Return value or reference counter"
- ^ CPrimitives cairo_get_reference_count: crId
+ ^ CPrimitives cairo_get_reference_count: self.
- "Created: / 28-12-2014 / 22:11:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 16:13:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
surface
- ^surface
-
- "Created: / 10-07-2008 / 10:33:59 / Jan Vrany <vranyj1@fel.cvut.cz>"
- "Modified: / 10-09-2008 / 20:53:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
- "Modified: / 28-12-2014 / 23:59:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!GraphicsContext methodsFor:'accessing-path properties'!
-
-lineCap: lc
-
- ^ CPrimitives cairo_set_line_cap: crId _: lc
-
- "Created: / 17-06-2012 / 22:09:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 28-12-2014 / 21:58:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!GraphicsContext methodsFor:'accessing-transformation'!
-
-transformation:aTransformation
- "set the transformation"
-
- super transformation: aTransformation.
- CPrimitives cairo_identity_matrix: crId.
- transformation notNil ifTrue:[
- CPrimitives cairo_translate: crId _: transformation translationX asFloat _: transformation translationY asFloat.
- CPrimitives cairo_scale: crId _: transformation scaleX asFloat _: transformation scaleY asFloat.
- ] ifFalse:[
- CPrimitives cairo_translate: crId _: 0.0 _: 0.0.
- CPrimitives cairo_scale: crId _: 1.0 _: 1.0.
- ].
-
- "Created: / 01-01-2015 / 12:07:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 09-01-2015 / 16:15:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!GraphicsContext methodsFor:'basic drawing'!
-
-displayArcX:x y:y width:w height:h from:start angle:angle
-
- | angle1 angle2 |
-
- self save.
- w ~~ h ifTrue:[
- self notYetImplemented
- ].
-
- angle1 := (360 - start) .
- angle2 := (360 - (start + angle)) \\ 360.
-
- (angle2 < angle1) ifTrue:[
- self arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle1 * (Float pi / 180) to: angle2 * (Float pi / 180).
- ] ifFalse:[
- self arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle2 * (Float pi / 180) to: angle1 * (Float pi / 180).
- ].
- self stroke.
-
- w ~~ h ifTrue:[
- self notYetImplemented
- ].
- self restore.
-
- "Modified: / 07-01-2015 / 11:58:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-displayLineFromX:x0 y:y0 toX:x1 y:y1
- "draw a line from x0/y0 to x1/y1"
-
- self moveToX: x0 y: y0.
- self lineToX: x1 y: y1.
- self stroke.
-
- "Modified: / 29-12-2014 / 01:18:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-displayOpaqueString:aString from:index1 to:index2 x:x y:y maxWitdh:maxWidth
- "draw part of a string with both fg and bg at x/y in current font"
-
- ^ self shouldImplement
-!
-
-displayPolygon:points
- "draw a polygon
- - this could be recoded to draw using displayLine"
-
- self moveToX: points first x asFloat y: points first y asFloat.
- 2 to: points size do:[:i |
- self lineToX: (points at: i) x asFloat y: (points at: i) y asFloat
- ].
- self closePath.
- self stroke.
-
- "Modified: / 02-01-2015 / 01:46:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-displayRectangleX:x y:y width:w height:h
- "draw a rectangle
- - this could be recoded to draw using displayLine"
-
- self rectangleX: x y: y width: w height: h.
- self stroke.
-
- "Modified: / 29-12-2014 / 01:18:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-displayString:aString from:index1 to:index2 x:x y:y
- "draw part of a string with fg at x/y in current font"
-
- self save.
- self moveToX: x y: y.
- (index1 == 1 and:[ index2 == aString size ]) ifTrue:[
- self showText: aString
- ] ifFalse:[
- self showText: (aString copyFrom: index1 to: index2).
- ].
- self restore.
-
- "Modified: / 09-01-2015 / 15:21:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!GraphicsContext methodsFor:'basic filling'!
-
-fillArcX:x y:y width:w height:h from:start angle:angle
-
- | angle1 angle2 |
-
- self save.
- w ~~ h ifTrue:[
- self notYetImplemented
- ].
-
-
- angle1 := (360 - start) .
- angle2 := (360 - (start + angle)) \\ 360.
-
- self moveToX: (x + (w / 2)) y: (y + (h / 2)).
-
- (angle2 < angle1) ifTrue:[
- self arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle1 * (Float pi / 180) to: angle2 * (Float pi / 180).
- ] ifFalse:[
- self arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle2 * (Float pi / 180) to: angle1 * (Float pi / 180).
- ].
- self closePath.
-
- self strokeAndPreserve.
- self fill.
-
- w ~~ h ifTrue:[
-
- ].
- self restore.
-
- "Modified: / 07-01-2015 / 04:25:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-fillPolygon:points
- "fill a polygon with current paint color"
-
- self moveToX: points first x asFloat y: points first y asFloat.
- 2 to: points size do:[:i |
- self lineToX: (points at: i) x asFloat y: (points at: i) y asFloat
- ].
- self closePath.
- self strokeAndPreserve.
- self fill.
-
- "Modified: / 02-01-2015 / 01:45:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-fillRectangleX:x y:y width:w height:h
- "fill a rectangle with current paint color"
-
- self rectangleX: x y: y width: w height: h.
- self strokeAndPreserve.
- self fill.
-
- "Modified: / 02-01-2015 / 00:32:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!GraphicsContext methodsFor:'bit blitting'!
-
-copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h
- "copy from a drawable - maybe self"
-
- ^ self shouldImplement
+ ^ surface
! !
!GraphicsContext methodsFor:'cairo api - paths'!
-arcNegativeX: x y: y radius: r from: startAngle to: stopAngle
-
- ^CPrimitives cairo_arc_negative: crId _: x asDouble _: y asDouble _: r asDouble _: startAngle asDouble _: stopAngle asDouble
+arcNegativeX:x y:y radius:r from:startAngle to:stopAngle
+ ^ CPrimitives
+ cairo_arc_negative:self
+ _:x asDouble
+ _:y asDouble
+ _:r asDouble
+ _:startAngle asDouble
+ _:stopAngle asDouble
"Created: / 07-01-2015 / 02:35:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-arcX: x y: y radius: r from: startAngle to: stopAngle
-
- ^CPrimitives cairo_arc: crId _: x asDouble _: y asDouble _: r asDouble _: startAngle asDouble _: stopAngle asDouble
+arcX:x y:y radius:r from:startAngle to:stopAngle
+ ^ CPrimitives
+ cairo_arc:self
+ _:x asDouble
+ _:y asDouble
+ _:r asDouble
+ _:startAngle asDouble
+ _:stopAngle asDouble
"Created: / 17-06-2012 / 21:50:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 22:00:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
closePath
- ^CPrimitives cairo_close_path: crId.
+ ^ CPrimitives cairo_close_path:self.
"Created: / 01-01-2015 / 22:42:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-lineToX: x y: y
+lineCap: lc
+
+ ^ CPrimitives cairo_set_line_cap: self _: lc
- ^CPrimitives cairo_line_to: crId _: x asDouble _: y asDouble
+ "Created: / 17-06-2012 / 22:09:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 16:42:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+lineToX:x y:y
+ ^ CPrimitives
+ cairo_line_to:self
+ _:x asDouble
+ _:y asDouble
"Created: / 17-06-2012 / 22:15:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 22:00:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-moveToX: x y: y
+lineWidth: aNumber
+ CPrimitives cairo_set_line_width: self _:aNumber asFloat
+ .
- ^CPrimitives cairo_move_to: crId _: x asDouble _: y asDouble
+ "Created: / 13-02-2016 / 16:45:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+moveToX:x y:y
+ ^ CPrimitives
+ cairo_move_to:self
+ _:x asDouble
+ _:y asDouble
"Created: / 23-04-2009 / 17:21:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 28-12-2014 / 22:00:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-rectangleX: x y: y width: w height: h
- | rx ry rw rh |
+rectangleX:x y:y width:w height:h
+ | rx ry rw rh |
rx := x.
ry := y.
rw := w.
rh := h.
- rw < 0 ifTrue:[
+ rw < 0 ifTrue:[
rx := rx + rw.
rw := rw abs.
].
- rh < 0 ifTrue:[
+ rh < 0 ifTrue:[
ry := ry + rh.
rh := rh abs.
- ].
-
- ^CPrimitives cairo_rectangle: crId
- _: rx asDouble
- _: ry asDouble
- _: rw asDouble
- _: rh asDouble
+ ].
+ ^ CPrimitives
+ cairo_rectangle:self
+ _:rx asDouble
+ _:ry asDouble
+ _:rw asDouble
+ _:rh asDouble
"Created: / 10-07-2008 / 09:41:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 02-01-2015 / 01:21:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -473,10 +141,14 @@
"Created: / 24-12-2014 / 23:12:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-setSourceSurface: aSyrface x:x y:y
+setSourceSurface:aSyrface x:x y:y
"raise an error: this method should be implemented (TODO)"
-
- ^ CPrimitives cairo_set_source_surface: crId _: aSyrface _: x _: y
+
+ ^ CPrimitives
+ cairo_set_source_surface:self
+ _:aSyrface
+ _:x
+ _:y
"Created: / 24-12-2014 / 23:12:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 21:59:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -485,95 +157,96 @@
!GraphicsContext methodsFor:'cairo api - save & restore'!
restore
- | savedData |
- (saved isNil or:[ savedPos == 0 ]) ifTrue:[
- self error: 'Cannot restore, no save called!!'.
- ].
- savedData := saved at: savedPos.
- saved at: savedPos put: nil.
- savedPos := savedPos - 1.
-
- transformation := savedData at: 1.
-
- ^CPrimitives cairo_restore: crId
+ ^ CPrimitives cairo_restore:self
"Created: / 17-06-2012 / 21:51:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 12-02-2016 / 21:16:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 16:14:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
save
- | savedData |
- saved isNil ifTrue:[
- saved := Array new: 10.
- savedPos := 0.
- ].
- savedPos == saved size ifTrue:[
- | newSaved |
-
- newSaved := Array new: savedPos + 10.
- newSaved replaceFrom: 1 to: savedPos with: saved startingAt: 1.
- saved := newSaved.
- ].
- savedPos := savedPos + 1.
- savedData := Array new: 1.
- saved at: savedPos put: savedData.
- savedData at: 1 put: transformation.
-
- ^CPrimitives cairo_save: crId
+ ^ CPrimitives cairo_save:self
"Created: / 17-06-2012 / 21:51:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified (format): / 12-02-2016 / 21:14:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 16:15:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!GraphicsContext methodsFor:'cairo api - source'!
+
+source: aCairoPatternOrColor
+ aCairoPatternOrColor isColor ifTrue:[
+ self sourceR: (aCairoPatternOrColor red / 100)
+ G: (aCairoPatternOrColor green / 100)
+ B: (aCairoPatternOrColor blue / 100)
+ A: aCairoPatternOrColor alpha.
+ ^ self.
+ ].
+ self notYetImplemented
+
+ "Created: / 13-02-2016 / 16:52:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sourceR:r G:g B:b
+ CPrimitives cairo_set_source_rgb: self
+ _: r asDouble
+ _: g asDouble
+ _: b asDouble
+
+ "Created: / 13-02-2016 / 16:55:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+sourceR:r G:g B:b A:a
+ CPrimitives cairo_set_source_rgba: self
+ _: r asDouble
+ _: g asDouble
+ _: b asDouble
+ _: a asDouble.
+
+ "Created: / 13-02-2016 / 16:54:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GraphicsContext methodsFor:'cairo api - stroke & fill'!
-draw
- "Fills whole surface.
-
- This method calls cairo_paint(), however, #paint is defined in
- GraphicsContext as method returning current foreground color/pattern."
-
- ^ CPrimitives cairo_paint:crId.
-
- "Created: / 29-12-2014 / 11:28:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
fill
-
- ^CPrimitives cairo_fill: crId
+ ^ CPrimitives cairo_fill:self
"Created: / 10-07-2008 / 09:42:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 28-12-2014 / 22:01:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
fillAndPreserve
-
- ^CPrimitives cairo_fill_preserve: crId
+ ^ CPrimitives cairo_fill_preserve:self
"Created: / 17-06-2012 / 21:52:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 22:01:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+paint
+ "A drawing operator that paints the current source everywhere within
+ the current clip region."
+
+ ^ CPrimitives cairo_paint:self.
+
+ "Created: / 13-02-2016 / 16:59:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
showPage
"Makes sense only for PDF surfaces"
-
- ^CPrimitives cairo_show_page: crId.
+
+ ^ CPrimitives cairo_show_page:self.
"Created: / 17-06-2012 / 08:44:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 22:02:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
stroke
-
- ^CPrimitives cairo_stroke: crId
+ ^ CPrimitives cairo_stroke:self
"Created: / 10-07-2008 / 09:42:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 28-12-2014 / 22:02:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
strokeAndPreserve
-
- ^CPrimitives cairo_stroke_preserve: crId
+ ^ CPrimitives cairo_stroke_preserve:self
"Created: / 17-06-2012 / 21:52:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 22:15:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -581,27 +254,25 @@
!GraphicsContext methodsFor:'cairo api - text'!
-font: family slant: slant weight: weight
-
- ^CPrimitives cairo_select_font_face: crId
- _: family asString
- _: slant asInteger
- _: weight asInteger
+font:family slant:slant weight:weight
+ ^ CPrimitives
+ cairo_select_font_face:self
+ _:family asString
+ _:slant asInteger
+ _:weight asInteger
"Created: / 29-12-2014 / 01:08:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-fontSize: sz
-
- ^CPrimitives cairo_set_font_size: crId _: sz asFloat
+fontSize:sz
+ ^ CPrimitives cairo_set_font_size:self _:sz asFloat
"Created: / 23-04-2009 / 17:24:33 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 02-01-2015 / 01:39:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-showText: aString
-
- ^CPrimitives cairo_show_text: crId _: aString utf8Encoded
+showText:aString
+ ^ CPrimitives cairo_show_text:self _:aString utf8Encoded
"Created: / 23-04-2009 / 17:25:20 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 28-12-2014 / 22:02:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -610,216 +281,74 @@
!GraphicsContext methodsFor:'cairo api - transformations & clipping'!
clip
-
- ^CPrimitives cairo_clip: crId.
+ ^ CPrimitives cairo_clip:self.
"Created: / 17-06-2012 / 21:56:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 28-12-2014 / 22:02:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!GraphicsContext methodsFor:'drawing'!
+!
-displayForm:aFormOrImage x:x y:y
- "draw a form (or image) at x/y;
- if the form has depth 1, 1's in the form are
- drawn in current paint color, 0's are ignored.
- If the form has depth ~~ 1, the current fg color setting is ignored."
+matrix: aCairoMatrix
+ self notYetImplemented
- | image width height stride data image_surface |
+ "Created: / 13-02-2016 / 19:51:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
- image := aFormOrImage asImage.
- width := image width.
- height := image height.
- stride := CPrimitives cairo_format_stride_for_width: CAIRO_FORMAT_ARGB32 _: width.
- data := ExternalBytes basicNew allocateBytes: stride * height clear: false.
- [
- image bitsARGB32Into: data stride: stride fg: self paint bg: self backgroundPaint.
- image_surface := CPrimitives cairo_image_surface_create_for_data: data _: CAIRO_FORMAT_ARGB32 _: width _: height _: stride.
- CPrimitives cairo_set_source_surface: crId _: image_surface _: x asFloat _: y asFloat.
- CPrimitives cairo_paint: crId.
- ] ensure:[
- data finalize.
- image_surface release.
- ].
+matrixReset
+ "Resets the current transformation matrix (CTM) by setting it equal to the
+ identity matrix. That is, the user-space and device-space axes will be
+ aligned and one user-space unit will transform to one device-space unit."
+ CPrimitives cairo_identity_matrix: self.
- "Created: / 31-12-2014 / 12:08:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 01-01-2015 / 02:48:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 13-02-2016 / 19:54:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-displayRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
- | r pi |
- wCorn ~~ hCorn ifTrue:[
- self notYetImplemented.
+scale: aNumberOrPoint
+ | sx sy |
+ aNumberOrPoint isPoint ifTrue:[
+ sx := aNumberOrPoint x asFloat.
+ sy := aNumberOrPoint y asFloat.
+ ] ifFalse:[
+ sx := sy := aNumberOrPoint asFloat.
].
- r := wCorn / 2.
- pi := Float pi.
-
- "/ top-left arc
- self arcX: x + r y: y + r radius: r from: pi to: (3/2) * pi.
- "/ top-right atc
- self arcX: x + w - r y: y + r radius: r from: (3/2) * pi to: 0.0.
- "/ bottom-right atc
- self arcX: x + w - r y: y + h - r radius: r from: 0.0 to: (1/2) * pi.
- "/ bottom-left atc
- self arcX: x + r y: y + h - r radius: r from: (1/2) * pi to: pi.
- self closePath.
- self stroke.
-
- "
- |v|
-
- (v := View new) extent:200@200; openAndWait.
- v cairo
- lineWidth: 5;
- displayRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20;
- release
- "
-
- "Created: / 07-01-2015 / 20:41:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!GraphicsContext methodsFor:'filling'!
+ CPrimitives cairo_scale: self _: sx _: sy.
-fillRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
- | r pi |
- wCorn ~~ hCorn ifTrue:[
- self notYetImplemented.
- ].
- r := wCorn / 2.
- pi := Float pi.
-
- "/ top-left arc
- self arcX: x + r y: y + r radius: r from: pi to: (3/2) * pi.
- "/ top-right atc
- self arcX: x + w - r y: y + r radius: r from: (3/2) * pi to: 0.0.
- "/ bottom-right atc
- self arcX: x + w - r y: y + h - r radius: r from: 0.0 to: (1/2) * pi.
- "/ bottom-left atc
- self arcX: x + r y: y + h - r radius: r from: (1/2) * pi to: pi.
- self closePath.
- self fill.
-
- "
- |v|
-
- (v := View new) extent:200@200; openAndWait.
- v cairo
- lineWidth: 5;
- displayRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20;
- release
- "
-
- "Created: / 07-01-2015 / 21:33:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!GraphicsContext methodsFor:'finalization'!
-
-executor
- ^ super executor
- "/^ self shallowCopy
-
- "Created: / 12-02-2016 / 17:04:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 13-02-2016 / 16:40:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-finalization
- self destroy
-
- "Created: / 09-01-2015 / 10:20:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
+translate: aNumberOrPoint
+ | tx ty |
+ aNumberOrPoint isPoint ifTrue:[
+ tx := aNumberOrPoint x asFloat.
+ ty := aNumberOrPoint y asFloat.
+ ] ifFalse:[
+ tx := ty := aNumberOrPoint asFloat.
+ ].
+ CPrimitives cairo_translate: self _: tx _: ty.
-finalizationLobby
- "answer a Registry used for finalization.
- Use a generic Registry for any object.
- Subclasses using their own Registry should redefine this"
-
- ^ Lobby
-
- "Created: / 09-01-2015 / 10:20:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 13-02-2016 / 16:40:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GraphicsContext methodsFor:'initialization & release'!
-createCR
- "Physically create a Cairo graphics context"
-
- surface := device cairoSurfaceFor: (device viewFromId: drawableId).
- crId := CPrimitives cairo_create: surface.
-
- "Created: / 12-02-2016 / 16:59:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
+initializeWithSurface: aSurface
+ surface := aSurface.
+ self registerForFinalization
-createGC
- "physically create a device GC.
- Since we do not need a gc-object for the drawable until something is
- really drawn, none is created up to the first draw.
- This method is sent, when the first drawing happens"
- super createGC.
- self createCR
+ "Created: / 13-02-2016 / 16:08:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
- "Created: / 12-02-2016 / 16:58:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
+!GraphicsContext methodsFor:'private'!
-destroyCR
+destroy
"Tell Cairo library to destroy the corresponding C object.
Remember that object is physically destroyed only if internal
refcounter goes to zero. However, after calling destroy,
this instance should be treated as invalid."
- crId notNil ifTrue:[
- CPrimitives cairo_destroy: crId.
- crId := nil.
- surface destroy.
- surface := nil.
- ].
-
- "Created: / 12-02-2016 / 16:59:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-destroyGC
- self destroyCR.
- super destroyGC
-
- "Created: / 12-02-2016 / 17:01:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
+ surface := nil.
+ CPrimitives cairo_destroy: self.
+ self setAddress: nil.
-initializeWithHandle:anExternalAddress surface: aSurface
- crId := anExternalAddress.
- surface := aSurface.
- device := aSurface device.
- self lineWidth: 1.
- self initialize.
- self font: font.
- self registerForFinalization
-
- "Created: / 28-12-2014 / 23:52:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 09-01-2015 / 10:20:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-releaseCR
- self destroyCR
-
- "Created: / 12-02-2016 / 17:02:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-releaseGC
- "destroy the associated device GC resource - can be done to be nice to the
- display if you know that you are done with a drawable."
-
- self releaseCR.
- super releaseGC.
-
- "Created: / 12-02-2016 / 17:03:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 16:13:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
-!GraphicsContext class methodsFor:'documentation'!
-
-version
- ^'$Id$'
-!
-
-version_HG
- ^ '$Changeset: <not expanded> $'
-! !
-
-
-GraphicsContext initialize!
--- a/Cairo__RegionOverlap.st Fri Feb 12 16:36:39 2016 +0000
+++ b/Cairo__RegionOverlap.st Sat Feb 13 17:10:25 2016 +0000
@@ -10,6 +10,7 @@
category:'Cairo-Constants'
!
+
!RegionOverlap class methodsFor:'initialization'!
initialize
@@ -36,5 +37,12 @@
^CAIRO_REGION_OVERLAP_PART
! !
+!RegionOverlap class methodsFor:'documentation'!
+
+version_HG
+
+ ^ '$Changeset: <not expanded> $'
+! !
+
RegionOverlap initialize!
--- a/Cairo__Surface.st Fri Feb 12 16:36:39 2016 +0000
+++ b/Cairo__Surface.st Sat Feb 13 17:10:25 2016 +0000
@@ -209,9 +209,11 @@
refcounter goes to zero. However, after calling destroy,
this instance should be treated as invalid."
- ^ CPrimitives cairo_surface_destroy: self
+ CPrimitives cairo_surface_destroy: self.
+ self setAddress: nil.
"Created: / 28-12-2014 / 22:10:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 16:10:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
finish
--- a/Make.proto Fri Feb 12 16:36:39 2016 +0000
+++ b/Make.proto Sat Feb 13 17:10:25 2016 +0000
@@ -190,9 +190,10 @@
$(OUTDIR)Cairo__UserDataKey.$(O) Cairo__UserDataKey.$(H): Cairo__UserDataKey.st $(INCLUDE_TOP)/stx/libbasic/ArrayedCollection.$(H) $(INCLUDE_TOP)/stx/libbasic/Collection.$(H) $(INCLUDE_TOP)/stx/libbasic/ExternalBytes.$(H) $(INCLUDE_TOP)/stx/libbasic/ExternalStructure.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libbasic/SequenceableCollection.$(H) $(INCLUDE_TOP)/stx/libbasic/UninterpretedBytes.$(H) $(STCHDR)
$(OUTDIR)stx_goodies_libcairo.$(O) stx_goodies_libcairo.$(H): stx_goodies_libcairo.st $(INCLUDE_TOP)/stx/libbasic/LibraryDefinition.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libbasic/ProjectDefinition.$(H) $(STCHDR)
$(OUTDIR)Cairo__FontFace.$(O) Cairo__FontFace.$(H): Cairo__FontFace.st $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__CObject.$(H) $(INCLUDE_TOP)/stx/libbasic/ExternalAddress.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
-$(OUTDIR)Cairo__GraphicsContext.$(O) Cairo__GraphicsContext.$(H): Cairo__GraphicsContext.st $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__FontSlant.$(H) $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__FontWeight.$(H) $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__Format.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libview/DeviceGraphicsContext.$(H) $(INCLUDE_TOP)/stx/libview/GraphicsContext.$(H) $(STCHDR)
+$(OUTDIR)Cairo__GraphicsContext.$(O) Cairo__GraphicsContext.$(H): Cairo__GraphicsContext.st $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__CObject.$(H) $(INCLUDE_TOP)/stx/libbasic/ExternalAddress.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
$(OUTDIR)Cairo__Pattern.$(O) Cairo__Pattern.$(H): Cairo__Pattern.st $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__CObject.$(H) $(INCLUDE_TOP)/stx/libbasic/ExternalAddress.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
$(OUTDIR)Cairo__Surface.$(O) Cairo__Surface.$(H): Cairo__Surface.st $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__CObject.$(H) $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__Format.$(H) $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__SurfaceType.$(H) $(INCLUDE_TOP)/stx/libbasic/ExternalAddress.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
+$(OUTDIR)CairoGraphicsContext.$(O) CairoGraphicsContext.$(H): CairoGraphicsContext.st $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__FontSlant.$(H) $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__FontWeight.$(H) $(INCLUDE_TOP)/stx/goodies/libcairo/Cairo__Format.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libview/DeviceGraphicsContext.$(H) $(INCLUDE_TOP)/stx/libview/GraphicsContext.$(H) $(STCHDR)
$(OUTDIR)extensions.$(O): extensions.st $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(INCLUDE_TOP)/stx/libview/DeviceGraphicsContext.$(H) $(INCLUDE_TOP)/stx/libview/DeviceWorkstation.$(H) $(INCLUDE_TOP)/stx/libview/DisplaySurface.$(H) $(INCLUDE_TOP)/stx/libview/GraphicsContext.$(H) $(INCLUDE_TOP)/stx/libview/GraphicsDevice.$(H) $(INCLUDE_TOP)/stx/libview/GraphicsMedium.$(H) $(INCLUDE_TOP)/stx/libview/HostGraphicsDevice.$(H) $(INCLUDE_TOP)/stx/libview/Image.$(H) $(INCLUDE_TOP)/stx/libview/SimpleView.$(H) $(INCLUDE_TOP)/stx/libview/XGraphicsContext.$(H) $(INCLUDE_TOP)/stx/libview/XWorkstation.$(H) $(STCHDR)
# ENDMAKEDEPEND --- do not remove this line
--- a/Make.spec Fri Feb 12 16:36:39 2016 +0000
+++ b/Make.spec Sat Feb 13 17:10:25 2016 +0000
@@ -100,6 +100,7 @@
Cairo::GraphicsContext \
Cairo::Pattern \
Cairo::Surface \
+ CairoGraphicsContext \
@@ -154,6 +155,7 @@
$(OUTDIR_SLASH)Cairo__GraphicsContext.$(O) \
$(OUTDIR_SLASH)Cairo__Pattern.$(O) \
$(OUTDIR_SLASH)Cairo__Surface.$(O) \
+ $(OUTDIR_SLASH)CairoGraphicsContext.$(O) \
$(OUTDIR_SLASH)extensions.$(O) \
--- a/abbrev.stc Fri Feb 12 16:36:39 2016 +0000
+++ b/abbrev.stc Sat Feb 13 17:10:25 2016 +0000
@@ -50,3 +50,4 @@
Cairo::GraphicsContext Cairo__GraphicsContext stx:goodies/libcairo 'Cairo-Objects' 0
Cairo::Pattern Cairo__Pattern stx:goodies/libcairo 'Cairo-Objects' 0
Cairo::Surface Cairo__Surface stx:goodies/libcairo 'Cairo-Objects' 0
+CairoGraphicsContext CairoGraphicsContext stx:goodies/libcairo 'Cairo-Compatibility' 0
--- a/bc.mak Fri Feb 12 16:36:39 2016 +0000
+++ b/bc.mak Sat Feb 13 17:10:25 2016 +0000
@@ -115,9 +115,10 @@
$(OUTDIR)Cairo__UserDataKey.$(O) Cairo__UserDataKey.$(H): Cairo__UserDataKey.st $(INCLUDE_TOP)\stx\libbasic\ArrayedCollection.$(H) $(INCLUDE_TOP)\stx\libbasic\Collection.$(H) $(INCLUDE_TOP)\stx\libbasic\ExternalBytes.$(H) $(INCLUDE_TOP)\stx\libbasic\ExternalStructure.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libbasic\SequenceableCollection.$(H) $(INCLUDE_TOP)\stx\libbasic\UninterpretedBytes.$(H) $(STCHDR)
$(OUTDIR)stx_goodies_libcairo.$(O) stx_goodies_libcairo.$(H): stx_goodies_libcairo.st $(INCLUDE_TOP)\stx\libbasic\LibraryDefinition.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libbasic\ProjectDefinition.$(H) $(STCHDR)
$(OUTDIR)Cairo__FontFace.$(O) Cairo__FontFace.$(H): Cairo__FontFace.st $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__CObject.$(H) $(INCLUDE_TOP)\stx\libbasic\ExternalAddress.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
-$(OUTDIR)Cairo__GraphicsContext.$(O) Cairo__GraphicsContext.$(H): Cairo__GraphicsContext.st $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__FontSlant.$(H) $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__FontWeight.$(H) $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__Format.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libview\DeviceGraphicsContext.$(H) $(INCLUDE_TOP)\stx\libview\GraphicsContext.$(H) $(STCHDR)
+$(OUTDIR)Cairo__GraphicsContext.$(O) Cairo__GraphicsContext.$(H): Cairo__GraphicsContext.st $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__CObject.$(H) $(INCLUDE_TOP)\stx\libbasic\ExternalAddress.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
$(OUTDIR)Cairo__Pattern.$(O) Cairo__Pattern.$(H): Cairo__Pattern.st $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__CObject.$(H) $(INCLUDE_TOP)\stx\libbasic\ExternalAddress.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
$(OUTDIR)Cairo__Surface.$(O) Cairo__Surface.$(H): Cairo__Surface.st $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__CObject.$(H) $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__Format.$(H) $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__SurfaceType.$(H) $(INCLUDE_TOP)\stx\libbasic\ExternalAddress.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
+$(OUTDIR)CairoGraphicsContext.$(O) CairoGraphicsContext.$(H): CairoGraphicsContext.st $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__FontSlant.$(H) $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__FontWeight.$(H) $(INCLUDE_TOP)\stx\goodies\libcairo\Cairo__Format.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libview\DeviceGraphicsContext.$(H) $(INCLUDE_TOP)\stx\libview\GraphicsContext.$(H) $(STCHDR)
$(OUTDIR)extensions.$(O): extensions.st $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(INCLUDE_TOP)\stx\libview\DeviceGraphicsContext.$(H) $(INCLUDE_TOP)\stx\libview\DeviceWorkstation.$(H) $(INCLUDE_TOP)\stx\libview\DisplaySurface.$(H) $(INCLUDE_TOP)\stx\libview\GraphicsContext.$(H) $(INCLUDE_TOP)\stx\libview\GraphicsDevice.$(H) $(INCLUDE_TOP)\stx\libview\GraphicsMedium.$(H) $(INCLUDE_TOP)\stx\libview\HostGraphicsDevice.$(H) $(INCLUDE_TOP)\stx\libview\Image.$(H) $(INCLUDE_TOP)\stx\libview\SimpleView.$(H) $(INCLUDE_TOP)\stx\libview\XGraphicsContext.$(H) $(INCLUDE_TOP)\stx\libview\XWorkstation.$(H) $(STCHDR)
# ENDMAKEDEPEND --- do not remove this line
--- a/extensions.st Fri Feb 12 16:36:39 2016 +0000
+++ b/extensions.st Sat Feb 13 17:10:25 2016 +0000
@@ -1,5 +1,22 @@
"{ Package: 'stx:goodies/libcairo' }"!
+!DeviceGraphicsContext methodsFor:'accessing'!
+
+cairo
+ "Return a Cairo context for drawing onto this GC"
+
+ | cr |
+
+ cr := Cairo::GraphicsContext onSurface: self cairoSurface.
+ transformation notNil ifTrue:[
+ cr transformation: transformation
+ ].
+ ^ cr
+
+ "Created: / 26-12-2014 / 23:28:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 15:59:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!DeviceGraphicsContext methodsFor:'cairo support'!
drawableId
@@ -232,14 +249,14 @@
view_cr rectangleX: x y: y width: w height: h.
view_cr clip.
view_cr setSourceSurface: image_surface.
- view_cr draw.
+ view_cr paint.
] ensure:[
image_surface notNil ifTrue:[ image_surface release ].
image_cr notNil ifTrue:[ image_cr release ]
].
"Created: / 27-12-2014 / 00:28:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 29-12-2014 / 11:29:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 13-02-2016 / 17:02:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!SimpleView methodsFor:'redrawing - cairo'!
@@ -276,36 +293,21 @@
!XGraphicsContext methodsFor:'accessing'!
-cairo
- "Return a Cairo context for drawing onto this GC"
-
- | cr |
-
- cr := Cairo::GraphicsContext onSurface: self cairoSurfaceId.
- transformation notNil ifTrue:[
- cr transformation: transformation
- ].
- ^ cr
-
- "Created: / 26-12-2014 / 23:28:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 01-01-2015 / 22:30:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
-!XGraphicsContext methodsFor:'accessing'!
-
-cairoSurfaceId
+cairoSurface
| view |
- view := device viewFromId: drawableId.
- cairoSurfaceId isNil ifTrue:[
- cairoSurfaceId := device cairoSurfaceFor: view.
+ view := device viewFromId:drawableId.
+ cairoSurfaceId isNil ifTrue:[
+ cairoSurfaceId := device cairoSurfaceFor:view.
^ cairoSurfaceId
].
- "/ Adjust width and height
- cairoSurfaceId width: view width height: view height.
+
+ "/ Adjust width and height
+ cairoSurfaceId width:view width height:view height.
^ cairoSurfaceId
"Modified: / 26-12-2014 / 23:30:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 13-02-2016 / 16:20:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!XWorkstation methodsFor:'cairo support'!
--- a/libInit.cc Fri Feb 12 16:36:39 2016 +0000
+++ b/libInit.cc Sat Feb 13 17:10:25 2016 +0000
@@ -76,6 +76,7 @@
_Cairo__GraphicsContext_Init(pass,__pRT__,snd);
_Cairo__Pattern_Init(pass,__pRT__,snd);
_Cairo__Surface_Init(pass,__pRT__,snd);
+_CairoGraphicsContext_Init(pass,__pRT__,snd);
_stx_137goodies_137libcairo_extensions_Init(pass,__pRT__,snd);
__END_PACKAGE__();
--- a/stx_goodies_libcairo.st Fri Feb 12 16:36:39 2016 +0000
+++ b/stx_goodies_libcairo.st Sat Feb 13 17:10:25 2016 +0000
@@ -166,6 +166,7 @@
#'Cairo::GraphicsContext'
#'Cairo::Pattern'
#'Cairo::Surface'
+ CairoGraphicsContext
)
!
@@ -186,14 +187,16 @@
SimpleView redrawWithCairoBuffered:x:y:width:height:
SimpleView redrawWithCairoBufferedX:y:width:height:
SimpleView redrawWithCairoX:y:width:height:
- XGraphicsContext cairo
- XGraphicsContext cairoSurfaceId
+ DeviceGraphicsContext cairo
+ XGraphicsContext cairoSurface
Image bitsARGB32Into:stride:fg:bg:
Image inspector2TabImageCairo
GraphicsContext displayDeviceLineFromX:y:toX:y:
GraphicsContext displayDeviceRectangleX:y:width:height:
GraphicsContext fillDeviceRectangleX:y:width:height:
)
+
+ "Modified: / 13-02-2016 / 17:05:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!stx_goodies_libcairo class methodsFor:'description - project information'!