comment/format in: #initializeAllPluginClasses
authorClaus Gittinger <cg@exept.de>
Thu, 03 Feb 2011 20:31:46 +0100
changeset 5705 56318de85b68
parent 5704 d7c401801223
child 5706 5423e6c0a69a
comment/format in: #initializeAllPluginClasses
GradientBackground.st
--- a/GradientBackground.st	Thu Feb 03 20:31:44 2011 +0100
+++ b/GradientBackground.st	Thu Feb 03 20:31:46 2011 +0100
@@ -12,7 +12,7 @@
 "{ Package: 'stx:libview' }"
 
 AbstractBackground subclass:#GradientBackground
-	instanceVariableNames:'color1 color2 direction'
+	instanceVariableNames:'color1 color2 direction cachedForm usedLength'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Graphics-Support'
@@ -32,6 +32,17 @@
  other person.  No title to or ownership of the software is
  hereby transferred.
 "
+!
+
+examples
+"
+    |bg v|
+
+    bg := GradientBackground new color1:Color red color2:Color yellow.
+    v := View new extent:300@300.
+    v viewBackground:bg.
+    v open.
+"
 ! !
 
 !GradientBackground methodsFor:'accessing'!
@@ -44,8 +55,18 @@
 
 color1:aColor
     color1 := aColor.
+    cachedForm := nil.
 
     "Created: / 23-01-2011 / 02:01:50 / cg"
+    "Modified: / 03-02-2011 / 19:49:18 / cg"
+!
+
+color1:aColor1 color2:aColor2
+    color1 := aColor1.
+    color2 := aColor2.
+    cachedForm := nil.
+
+    "Created: / 03-02-2011 / 19:52:59 / cg"
 !
 
 color2
@@ -56,8 +77,10 @@
 
 color2:aColor
     color2 := aColor.
+    cachedForm := nil.
 
     "Created: / 23-01-2011 / 02:01:55 / cg"
+    "Modified: / 03-02-2011 / 19:49:23 / cg"
 !
 
 direction
@@ -81,9 +104,41 @@
      others are not yet supported
     "
 
-    direction := something.
+    direction ~= something ifTrue:[
+        direction := something.
+        cachedForm := nil.
+    ]
+
+    "Modified: / 03-02-2011 / 19:49:41 / cg"
+! !
+
+!GradientBackground methodsFor:'converting'!
+
+asFormOn:aDevice
+    |h w|
 
-    "Modified: / 23-01-2011 / 14:36:44 / cg"
+    cachedForm isNil ifTrue:[
+        (direction == #northSouth or:[direction == nil]) ifTrue:[
+            h := usedLength ? (Display height). "/ aView height.
+            w := 8.
+        ] ifFalse:[
+            h := 8.
+            w := usedLength ? (Display width).  "/ aView width.
+        ].
+        cachedForm := Form width:w height:h depth:aDevice depth onDevice:aDevice.
+        "/ cachedForm clear.
+        self fillRectangleX:0 y:0 width:w height:h in:cachedForm
+    ].
+
+    ^ cachedForm
+
+    "Created: / 03-02-2011 / 20:05:30 / cg"
+!
+
+onDevice:device
+    ^ self asFormOn:device.
+
+    "Created: / 03-02-2011 / 19:56:06 / cg"
 ! !
 
 !GradientBackground methodsFor:'drawing'!
@@ -96,8 +151,8 @@
 
     "/ 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.
+    hAll := usedLength ? (Display height). "/ aView height.
+    wAll := usedLength ? (Display width).  "/ aView width.
 
     r1 := color1 redByte.
     r2 := color2 redByte.
@@ -107,7 +162,7 @@
     b2 := color2 blueByte.
 
     "/ individual lines; from top to bottom
-    (direction == #northSouth or:[direction == #vertical]) ifTrue:[
+    (direction == #northSouth or:[direction == #vertical or:[direction == nil]]) ifTrue:[
         dR := (r2 - r1) / hAll.
         r := r1 + (dR * y).
         dG := (g2 - g1) / hAll.
@@ -116,7 +171,7 @@
         b := b1 + (dB * y).
 
         xRight := x+w-1.
-        0 to:h-1 do:[:yP |
+        0 to:hAll-1 do:[:yP |
             rC := r asInteger.
             gC := g asInteger.
             bC := b asInteger.
@@ -129,6 +184,7 @@
             g := (g + dG) min:g2.
             b := (b + dB) min:b2.
         ].
+        aView fillRectangleX:x y:hAll width:(xRight-x+1) height:(h-hAll+1).
         ^ self.
     ].
 
@@ -142,7 +198,7 @@
         b := b1 + (dB * y).
 
         yBot := y+h-1.
-        0 to:w-1 do:[:xP |
+        0 to:wAll-1 do:[:xP |
             rC := r asInteger.
             gC := g asInteger.
             bC := b asInteger.
@@ -155,15 +211,16 @@
             g := (g + dG) min:g2.
             b := (b + dB) min:b2.
         ].
+        aView fillRectangleX:wAll y:y width:(w-wAll+1) height:(yBot-y+1).
         ^ self.
     ]
 
     "Created: / 23-01-2011 / 01:59:29 / cg"
-    "Modified: / 31-01-2011 / 17:28:53 / cg"
+    "Modified: / 03-02-2011 / 20:26:55 / cg"
 ! !
 
 !GradientBackground class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.5 2011-01-31 16:29:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.6 2011-02-03 19:31:46 cg Exp $'
 ! !