GraphColumnView3D.st
changeset 804 ad94311c8698
parent 803 5ff79f80245e
child 805 ea53b7181b00
--- a/GraphColumnView3D.st	Fri Mar 06 10:30:58 1998 +0100
+++ b/GraphColumnView3D.st	Fri Mar 06 12:22:28 1998 +0100
@@ -471,6 +471,12 @@
 
 ! !
 
+!GraphColumnView3D::GLXGraph class methodsFor:'constants'!
+
+maxColors
+    ^ 256
+! !
+
 !GraphColumnView3D::GLXGraph methodsFor:'event handling'!
 
 buttonPress:button x:x y:y
@@ -498,10 +504,9 @@
     "
     super initialize.
 
-    type     := #colorIndexDoubleBuffer.      "/ works on any device
-    colorMap := Dictionary new.
-    maxY     :=  1.0.
-    minY     := -1.0.
+    type := #colorIndexDoubleBuffer.            "/ works on any device
+    maxY :=  1.0.
+    minY := -1.0.
 
     removeFunc := false.
     removeRefs := false.
@@ -736,17 +741,37 @@
         self redrawInBackBuffer.
         self swapBuffers.
     ] ifFalse:[
-        colorMap := Dictionary new
+        colorMap := nil
     ].
 
 
 !
 
+initializeColorMap
+    "setup colors
+    "
+    colorMap := Dictionary new.
+
+    colorMap at:(Color black)   put:Black.
+    colorMap at:(Color white)   put:White.
+    colorMap at:(Color blue)    put:Blue.
+    colorMap at:(Color cyan)    put:Cyan.
+    colorMap at:(Color magenta) put:Magenta.
+    colorMap at:(Color red)     put:Red.
+    colorMap at:(Color yellow)  put:Yellow.
+    colorMap at:(Color green)   put:Green.
+
+!
+
 redrawInBackBuffer
     "redraw in back
     "
     |sY sX sZ noCols dY winSize w2 showRefs showGrid showFunc showAxis|
 
+    colorMap isNil ifTrue:[
+        self initializeColorMap
+    ].
+
     self setColor:(graph backgroundColor).
     self clear.
 
@@ -816,19 +841,29 @@
     |index useCol|
 
     useCol := aColor ? graph foregroundColor.
-
-    index := colorMap at:useCol ifAbsent:nil.
+    index  := colorMap at:useCol ifAbsent:nil.
 
     index isNil ifTrue:[
         index := colorMap size + self class numberOfStandardColors.
-        colorMap at:(useCol on:device) put:index.
 
-        self colorRed:(useCol red) green:(useCol green) blue:(useCol blue).
+        (    (index > self class maxColors)
+         or:[(useCol := useCol on:device) colorId isNil]
+        ) ifTrue:[
+            Transcript showCR:'cannot allocate more colors'.
+            index := (useCol brightness > 0.5) ifTrue:[White]
+                                              ifFalse:[Black]
+        ] ifFalse:[
+            colorMap at:useCol put:index.
 
-        self mapColor:index
-                  red:(useCol redByte)
-                green:(useCol greenByte)
-                 blue:(useCol blueByte).
+            self colorRed:(useCol red)
+                    green:(useCol green)
+                     blue:(useCol blue).
+
+            self mapColor:index
+                      red:(useCol redByte)
+                    green:(useCol greenByte)
+                     blue:(useCol blueByte)
+        ]
     ].
     self color:index.
 
@@ -901,5 +936,5 @@
 !GraphColumnView3D class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/GraphColumnView3D.st,v 1.5 1998-03-06 09:30:58 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/GraphColumnView3D.st,v 1.6 1998-03-06 11:22:28 ca Exp $'
 ! !