00001 #ifndef PALETTE_CLASS 00002 #define PALETTE_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : palette * 00007 * Author : Chris Koeritz * 00008 * * 00009 * Purpose: * 00010 * * 00011 * Provides methods for adding colors and manipulating the color map. * 00012 * * 00013 ******************************************************************************* 00014 * Copyright (c) 1991-$now By Author. This program is free software; you can * 00015 * redistribute it and/or modify it under the terms of the GNU General Public * 00016 * License as published by the Free Software Foundation; either version 2 of * 00017 * the License or (at your option) any later version. This is online at: * 00018 * http://www.fsf.org/copyleft/gpl.html * 00019 * Please send any updates to: fred@gruntose.com * 00020 \*****************************************************************************/ 00021 00022 #include "color.h" 00023 #include "definitions_passive.h" 00024 #include "nub.h" 00025 00026 class WP_PASSIVE_CLASS_STYLE palette 00027 { 00028 public: 00029 palette(window_handle parent, int gray_colors = 0); 00030 // constructs a colormap for the windowing system object "parent". if the 00031 // number of "gray_colors" is greater than 0 (and less than a system 00032 // defined maximum), then the colormap is given that many gray scale values 00033 // to start. 00034 00035 virtual ~palette(); 00036 00037 IMPLEMENT_CLASS_NAME("palette"); 00038 00039 bool add(color &to_add); 00040 // Allocates a colormap entry for "to_add". If it could be added to the 00041 // colormap, then true is returned. Otherwise, false is returned and the 00042 // "to_add" is set to a close match to the original request. 00043 00044 void install_gray_colormap(int number_of_colors); 00045 // adds "number_of_colors" grayscaled colors to the colormap. this method 00046 // can currently only be invoked once per palette, and the possible 00047 // invocation by the constructor (if "gray_colors" is greater than zero) 00048 // counts as an invocation. 00049 00050 void make_map(Pixel *map); 00051 // installs a gray color map and stuffs it in "map". Note that "map" 00052 // must be as large as the "size_of_colormap()". If the graymap is not 00053 // installed yet, then this does nothing. 00054 00055 window_color translate(color &to_add_or_find); 00056 // this returns the type of color used by the underlying window system 00057 // and can be used for direct interaction with that system. 00058 00059 color lookup(const char *color_name); 00060 color lookup(const istring &color_name); 00061 // searches for a color with the name specified and returns it if found. 00062 // if it is found, it is added to the colormap so that it can be used. 00063 // if it is not found, BLACK is returned. 00064 00065 int size_of_colormap() const; 00066 // returns the number of colors the display can show simultaneously. 00067 00068 void apply(window_handle to_apply_to); 00069 // Uses the colormap here as the colormap for the window specified. 00070 00071 private: 00072 window_colormap _colormap; 00073 nub _parent; 00074 Pixel *graymap; // list of grayscales to be stored in the colormap. 00075 int number_in_graymap; 00076 int maximum_colors_on_screen; 00077 00078 window_color add(color &to_add, bool &success); 00079 }; 00080 00081 #endif 00082
1.5.1