Cairo__ClockView.st
changeset 28 1bd3d147cd77
parent 26 7f07a8c31e6d
child 29 6ba06265e543
--- a/Cairo__ClockView.st	Thu Dec 25 10:47:49 2014 +0100
+++ b/Cairo__ClockView.st	Sat Dec 27 00:45:13 2014 +0100
@@ -3,7 +3,7 @@
 "{ NameSpace: Cairo }"
 
 SimpleView subclass:#ClockView
-	instanceVariableNames:'cr updater'
+	instanceVariableNames:'updater'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Cairo-Examples'
@@ -51,32 +51,41 @@
 !ClockView methodsFor:'redrawing'!
 
 redraw
+    self redrawWithCairo
 
-    | image image_cr time hours mins secs |
+    "Created: / 16-06-2012 / 23:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 27-12-2014 / 00:32:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+redrawX: x y: y width: w height: h
+    self redrawWithCairoX: x y: y width: w height: h
 
-    self clippingRectangle: 
-        (Smalltalk::Rectangle left:1 top:1 width:self width height:self height).
-    cr isNil ifTrue:[
-        cr := self cairo.
-    ].
-    image_cr := Cairo::GraphicsContext on: (image := Cairo::Surface forImageFormatARGB32width: self width  height: self height). 
+    "Created: / 17-06-2012 / 21:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 27-12-2014 / 00:32:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!ClockView methodsFor:'redrawing - cairo'!
+
+redrawWithCairo: cr
+
+    |   time hours mins secs |
 
     "/ scale to unit square and translate (0, 0) to be (0.5, 0.5), i.e.
     "/ the center of the window
-    image_cr save.
-    image_cr scale: self extent.
-    image_cr translate: (0.5 @ 0.5).
-    image_cr lineWidth: 0.05.
+    cr save.
+    cr scale: self extent.
+    cr translate: (0.5 @ 0.5).
+    cr lineWidth: 0.05.
 
-    image_cr paint: (Color red: 33 green: 61 blue: 11).
-    image_cr paint.
+    cr paint: (Color red: 33 green: 61 blue: 11).
+    cr paint.
 
-    image_cr arcX: 0 y: 0 radius: 0.42 from: 0 to: (2 * (Float pi)).
-    image_cr paint: Color white.
-    image_cr fillAndPreserve.
-    image_cr paint: Color black.
-    image_cr strokeAndPreserve.
-    image_cr clip.
+    cr arcX: 0 y: 0 radius: 0.42 from: 0 to: (2 * (Float pi)).
+    cr paint: Color white.
+    cr fillAndPreserve.
+    cr paint: Color black.
+    cr strokeAndPreserve.
+    cr clip.
 
     "Now, clock ticks"
 
@@ -84,23 +93,23 @@
         | inset |
 
         inset := 0.05.
-        image_cr save.
+        cr save.
 
-        image_cr lineCap: Cairo::LineCap LINE_CAP_ROUND.
+        cr lineCap: Cairo::LineCap LINE_CAP_ROUND.
         (i \\ 3) ~~ 0 ifTrue:[
             inset := inset * 0.8.
-            image_cr lineWidth: 0.03.
+            cr lineWidth: 0.03.
         ].
 
-        image_cr moveToX: (0.42 - inset) * ( i * (Float pi / 6)) cos
+        cr moveToX: (0.42 - inset) * ( i * (Float pi / 6)) cos
                  y: (0.42 - inset) * ( i * (Float pi / 6)) sin.
 
-        image_cr lineToX: (0.42 ) * ( i * (Float pi / 6)) cos
+        cr lineToX: (0.42 ) * ( i * (Float pi / 6)) cos
                  y: (0.42 ) * ( i * (Float pi / 6)) sin.
 
-        image_cr stroke.
+        cr stroke.
 
-        image_cr restore.
+        cr restore.
     ].
 
     "/ Not, the current time"
@@ -111,56 +120,45 @@
     mins := time minutes * (Float pi / 30).
     secs := time seconds * (Float pi / 30).
 
-    image_cr save.
-    image_cr lineCap: Cairo::LineCap LINE_CAP_ROUND.
+    cr save.
+    cr lineCap: Cairo::LineCap LINE_CAP_ROUND.
 
     "/ draw the seconds hand
-    image_cr save.
-    image_cr lineWidth: 0.016.
-    image_cr paint: ((Color red: 70 green: 70 blue: 70) alpha: 0.8).
-    image_cr moveToX: 0.0 y: 0.0.
-    image_cr lineToX: (secs sin * (0.42 * 0.9))
+    cr save.
+    cr lineWidth: 0.016.
+    cr paint: ((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))).
-    image_cr stroke.
-    image_cr restore.
+    cr stroke.
+    cr restore.
 
     "/ draw th minutes
-    image_cr paint: ((Color red: 11 green: 33 blue: 61) alpha: 0.7).
-    image_cr moveToX: 0.0 y: 0.0.
-    image_cr lineToX: ((mins + (secs / 60)) sin * (0.42 * 0.8))
+    cr paint: ((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))).
-    image_cr stroke.
+    cr stroke.
 
     "/ draw the hours hand
-    image_cr paint: ((Color red: 33 green: 61 blue: 11) alpha: 0.6).
-    image_cr moveToX: 0.0 y: 0.0.
-    image_cr lineToX: ((hours + (mins / 12)) sin * (0.42 * 0.5))
+    cr paint: ((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))).
-    image_cr stroke.
+    cr stroke.
 
 
-    image_cr restore.
-    image_cr arcX: 0 y: 0 radius: 0.01 from: 0 to: (2 * (Float pi)).
-    image_cr fill.
+    cr restore.
+    cr arcX: 0 y: 0 radius: 0.01 from: 0 to: (2 * (Float pi)).
+    cr fill.
 
 
 
 
 
-    image_cr restore.
-
-    cr setSourceSurface: image. 
-    cr paint.
+    cr restore.
 
-    "Created: / 16-06-2012 / 23:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 24-12-2014 / 23:56:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-redrawX: x y: y width: w height: h
-
-    self redraw
-
-    "Created: / 17-06-2012 / 21:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 27-12-2014 / 00:00:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !ClockView class methodsFor:'documentation'!