GradientBackground.st
changeset 5684 c6029a2cf7c0
parent 5461 2451688b8d25
child 5687 d4ab14b6cf0a
--- a/GradientBackground.st	Sun Jan 23 02:43:13 2011 +0100
+++ b/GradientBackground.st	Sun Jan 23 02:45:47 2011 +0100
@@ -34,8 +34,77 @@
 "
 ! !
 
+!GradientBackground methodsFor:'accessing'!
+
+color1
+    ^ color1
+
+    "Created: / 23-01-2011 / 02:01:29 / cg"
+!
+
+color1:aColor
+    color1 := aColor.
+
+    "Created: / 23-01-2011 / 02:01:50 / cg"
+!
+
+color2
+    ^ color2
+
+    "Created: / 23-01-2011 / 02:01:32 / cg"
+!
+
+color2:aColor
+    color2 := aColor.
+
+    "Created: / 23-01-2011 / 02:01:55 / cg"
+! !
+
+!GradientBackground methodsFor:'drawing'!
+
+fillRectangleX:x y:y width:w height:h in:aView
+    "this is a first (very inefficient) try"
+
+    |r1 r2 g1 g2 b1 b2 dR r dG g dB b xRight rC gC bC lastR lastG lastB|
+
+    r1 := color1 redByte.
+    r2 := color2 redByte.
+    g1 := color1 greenByte.
+    g2 := color2 greenByte.
+    b1 := color1 blueByte.
+    b2 := color2 blueByte.
+
+    direction = #horizontal ifTrue:[
+        self halt
+    ] ifFalse:[
+        dR := (r2 - r1) / (aView height).
+        r := r1 + (dR * y).
+        dG := (g2 - g1) / (aView height).
+        g := g1 + (dG * y).
+        dB := (b2 - b1) / (aView height).
+        b := b1 + (dB * y).
+
+        xRight := x+w-1.
+        0 to:h-1 do:[:yP |
+            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 y:y+yP toX:xRight y:y+yP.
+            r := r + dR.
+            g := g + dG.
+            b := b + dB.
+        ].
+    ]
+
+    "Created: / 23-01-2011 / 01:59:29 / cg"
+! !
+
 !GradientBackground class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.1 2009-11-04 14:31:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.2 2011-01-23 01:45:47 cg Exp $'
 ! !