Cairo__GraphicsContext.st
changeset 32 fb983be8d2c0
parent 31 26070c1e480e
child 33 8a2e438b4363
--- a/Cairo__GraphicsContext.st	Fri Jan 02 12:46:59 2015 +0100
+++ b/Cairo__GraphicsContext.st	Wed Jan 07 12:02:09 2015 +0100
@@ -234,16 +234,36 @@
     ].
 
     "Created: / 01-01-2015 / 12:07:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 02-01-2015 / 01:12:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 07-01-2015 / 11:58:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GraphicsContext methodsFor:'basic drawing'!
 
-displayArcX:x y:y width:width height:height from:startAngle angle:angle
-    "draw an arc in a box
-     - this could be recoded to draw using displayLine"
+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.
 
-    ^ self shouldImplement
+    (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
@@ -314,9 +334,36 @@
 !GraphicsContext methodsFor:'basic filling'!
 
 fillArcX:x y:y width:w height:h from:start angle:angle
-    "fill an arc with current paint color"
+
+    | 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)).
 
-    ^ self shouldImplement
+    (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
@@ -353,6 +400,13 @@
 
 !GraphicsContext methodsFor:'cairo api - paths'!
 
+arcNegativeX: x y: y radius: r from: startAngle to: stopAngle
+
+    ^CPrimitives cairo_arc_negative: handle _: 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: handle _: x asDouble _: y asDouble _: r asDouble _: startAngle asDouble _: stopAngle asDouble