Using Colors

There are five different ways you can use color in ProXL, in approximate order of increasing difficulty:

  1. You can use the black_pixel and white_pixel of your screen. black_pixel is the default foreground color, so if you don't change your drawable's foreground graphics attribute, you will be drawing in black. And the default window background is its screen's white_pixel, so if you don't change that, you will be drawing in black on a white background, which is often good enough.
  2. You can allocate colors. If you want to have color images, this is usually the best approach. Allocating a color never fails, even on a monochrome screen, it just gives you the closest color it can. So if you ask for yellow and navy blue, you will get white and black, respectively. This allows your application to run on monochrome (or grayscale) screens, as well as color.

    When you allocate colors, you share these colors with other applications, too. This means that if you ask for blue, and another application is already using blue, you will get the same pixel value. Obviously this is good citizenship on a color screen with a limited number of pixel values available. It also means that you cannot change the color of a pixel value you get this way, because it would confound the other applications using this pixel value.

  3. You can allocate color cells and planes. This gives you private pixel values for you to play with. You can set these pixel values to any colors you like, and change them as often as you like. Allocating color planes also allows you to control the actual bit patterns of the pixels you use, allowing you to do sophisticated tricks with images.

  4. You can use a standard colormap. Standard colormaps provide a number of pre-selected colors, and can be shared with other applications. You must rely on your window manager to create standard colormaps for you, and, unfortunately, not all window managers do this.

  5. You can allocate a colormap. While this might seem harmless enough, since your color table is yours alone, and doesn't affect the colormaps used by other applications, in practice few screens can support more than one colormap at a time. This means that when you colormap is installed, all the other windows on the screen may display the wrong colors. Also, if you use a private colormap, you must make sure that your colormap is installed. In theory, your window manager is responsible for installing your colormap when the pointer is in your window. In practice, few window managers do this now. This will probably change, but at the moment, this is a serious problem.