summaryrefslogtreecommitdiff
path: root/src/Fl_own_colormap.cxx
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>1998-10-06 18:21:25 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>1998-10-06 18:21:25 +0000
commitf9039b2ae21988783feae9b362818e7923e82d14 (patch)
tree6d6fe3679d73448758f9794e7d4d4f6b22a4adad /src/Fl_own_colormap.cxx
parent67e89232f9ba067825a158734a09e0fa21aacbe3 (diff)
Initial revision
git-svn-id: file:///fltk/svn/fltk/trunk@2 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_own_colormap.cxx')
-rw-r--r--src/Fl_own_colormap.cxx50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/Fl_own_colormap.cxx b/src/Fl_own_colormap.cxx
new file mode 100644
index 000000000..8f4ca3524
--- /dev/null
+++ b/src/Fl_own_colormap.cxx
@@ -0,0 +1,50 @@
+// Fl_own_colormap.C
+
+// Using the default system colormap can be a bad idea on PseudoColor
+// visuals, since typically every application uses the default colormap and
+// you can run out of colormap entries easily.
+//
+// The solution is to always create a new colormap on PseudoColor displays
+// and copy the first 16 colors from the default colormap so that we won't
+// get huge color changes when switching windows.
+
+#include <config.h>
+#include <FL/Fl.H>
+#include <FL/x.H>
+
+#ifdef WIN32
+// There is probably something relevant to do on MSWindows 8-bit displays
+// but I don't know what it is
+
+void Fl::own_colormap() {}
+
+#else
+// X version
+
+void Fl::own_colormap() {
+ fl_open_display();
+#if USE_COLORMAP
+ switch (fl_visual->c_class) {
+ case GrayScale :
+ case PseudoColor :
+ case DirectColor :
+ break;
+ default:
+ return; // don't do anything for non-colormapped visuals
+ }
+ int i;
+ XColor colors[16];
+ // Get the first 16 colors from the default colormap...
+ for (i = 0; i < 16; i ++) colors[i].pixel = i;
+ XQueryColors(fl_display, fl_colormap, colors, 16);
+ // Create a new colormap...
+ fl_colormap = XCreateColormap(fl_display,
+ RootWindow(fl_display,fl_screen),
+ fl_visual->visual, AllocNone);
+ // Copy those first 16 colors to our own colormap:
+ for (i = 0; i < 16; i ++)
+ XAllocColor(fl_display, fl_colormap, colors + i);
+#endif
+}
+
+#endif