added:
authorClaus Gittinger <cg@exept.de>
Sun, 23 Jan 2011 14:41:35 +0100
changeset 5688 0fec2a60ad63
parent 5687 d4ab14b6cf0a
child 5689 474d50f11653
added: #direction #direction: changed: #fillRectangleX:y:width:height:in:
GradientBackground.st
--- a/GradientBackground.st	Sun Jan 23 12:53:48 2011 +0100
+++ b/GradientBackground.st	Sun Jan 23 14:41:35 2011 +0100
@@ -58,6 +58,32 @@
     color2 := aColor.
 
     "Created: / 23-01-2011 / 02:01:55 / cg"
+!
+
+direction
+    "possible values:
+        #northSouth
+        #eastWest
+
+     others are not yet supported
+    "
+
+    ^ direction
+
+    "Modified: / 23-01-2011 / 14:36:36 / cg"
+!
+
+direction:something
+    "possible values:
+        #northSouth
+        #eastWest
+
+     others are not yet supported
+    "
+
+    direction := something.
+
+    "Modified: / 23-01-2011 / 14:36:44 / cg"
 ! !
 
 !GradientBackground methodsFor:'drawing'!
@@ -65,9 +91,13 @@
 fillRectangleX:x y:y width:w height:h in:aView
     "this is a first (very inefficient) try"
 
-    |hAll r1 r2 g1 g2 b1 b2 dR r dG g dB b xRight rC gC bC lastR lastG lastB|
+    |hAll wAll r1 r2 g1 g2 b1 b2 dR r dG g dB b 
+     xRight yBot rC gC bC lastR lastG lastB|
 
-    hAll := 1000. "/ aView height.
+    "/ always take the full-screen as reference
+    "/ (so we do not have to care for changed gradient, when view changes size)
+    hAll := Display height. "/ aView height.
+    wAll := Display width.  "/ aView width.
 
     r1 := color1 redByte.
     r2 := color2 redByte.
@@ -76,9 +106,8 @@
     b1 := color1 blueByte.
     b2 := color2 blueByte.
 
-    direction = #horizontal ifTrue:[
-        self halt
-    ] ifFalse:[
+    "/ individual lines; from top to bottom
+    (direction == #northSouth or:[direction == #vertical]) ifTrue:[
         dR := (r2 - r1) / hAll.
         r := r1 + (dR * y).
         dG := (g2 - g1) / hAll.
@@ -100,14 +129,41 @@
             g := g + dG.
             b := b + dB.
         ].
+        ^ self.
+    ].
+
+    "/ individual lines; from left to right
+    (direction == #eastWest or:[direction == #horizontal]) ifTrue:[
+        dR := (r2 - r1) / wAll.
+        r := r1 + (dR * y).
+        dG := (g2 - g1) / wAll.
+        g := g1 + (dG * y).
+        dB := (b2 - b1) / wAll.
+        b := b1 + (dB * y).
+
+        yBot := y+h-1.
+        0 to:w-1 do:[:xP |
+            rC := r asInteger.
+            gC := g asInteger.
+            bC := b asInteger.
+            (rC ~~ lastR or:[gC ~~ lastG or:[bC ~~ lastB]]) ifTrue:[
+                aView foreground:(Color redByte:rC greenByte:gC blueByte:bC).
+                lastR := rC. lastG := gC. lastB := bC.
+            ].
+            aView displayLineFromX:x+xP y:y toX:x+xP y:yBot.
+            r := r + dR.
+            g := g + dG.
+            b := b + dB.
+        ].
+        ^ self.
     ]
 
     "Created: / 23-01-2011 / 01:59:29 / cg"
-    "Modified: / 23-01-2011 / 12:53:36 / cg"
+    "Modified: / 23-01-2011 / 14:41:12 / cg"
 ! !
 
 !GradientBackground class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.3 2011-01-23 11:53:48 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.4 2011-01-23 13:41:35 cg Exp $'
 ! !