Back to index

plt-scheme  4.2.1
Colour.h
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: classes to cover colours and colourmaps
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #ifndef Colour_h
00028 #define Colour_h
00029 
00030 #ifndef MZ_PRECISE_GC
00031 # ifdef __GNUG__
00032 # pragma interface
00033 # endif
00034 #endif
00035 
00036 #ifdef Have_X_Types
00037 // easier access to X-Colormap
00038 #define GETCOLORMAP(obj) (*((Colormap*)((obj)->GetHandle())))
00039 #endif
00040 
00041 class wxColour_Xintern;
00042 class wxColourMap_Xintern;
00043 
00044 class wxColourMap;
00045 
00046 class wxColour : public wxObject { // colour representation
00047 public:
00048     wxColour(void);
00049     wxColour(unsigned char r, unsigned char g, unsigned char b);
00050     wxColour(wxColour* col);
00051     wxColour(const char *col);
00052     ~wxColour(void);
00053 
00054     wxColour* CopyFrom(wxColour*);
00055     wxColour* CopyFrom(const char*);
00056 
00057 #ifndef MZ_PRECISE_GC
00058     wxColour& operator =(wxColour& x) { 
00059       printf("Error: shouldn't use = on color objects anymore\n");
00060       CopyFrom(&x);
00061       return *this;
00062     }
00063 #endif
00064 
00065     Bool Ok(void) { return (X!=NULL); }
00066 
00067     void Get(unsigned char *r, unsigned char *b, unsigned char *g);
00068     void Set(unsigned char r, unsigned char b, unsigned char g);
00069 
00070     unsigned char Red(void);
00071     unsigned char Green(void);
00072     unsigned char Blue(void);
00073 
00074     // alloc and free X pixel value
00075     unsigned long GetPixel(wxColourMap* cmap=wxAPP_COLOURMAP, Bool is_color=1, Bool fg=1);
00076     void FreePixel(Bool del);
00077 
00078     inline Bool  IsMutable(void) { return !locked; } 
00079     inline void  Lock(int d) { locked += d; }
00080 
00081 private:
00082     friend class wxColourMap;
00083 
00084     wxColour_Xintern* X; // the encapsulated X representation
00085     int locked;
00086 };
00087 
00088 class wxColourMap : public wxObject { // colourmap representation
00089 public:
00090     wxColourMap(Bool priv=TRUE);
00091     ~wxColourMap(void);
00092 
00093     void *GetHandle(void); // return Colormap*
00094 
00095     Bool Ok(void) { return (X!=NULL); }
00096 private:
00097     friend class wxColour;
00098     friend class wxColourDatabase;
00099 
00100     wxColourMap_Xintern* X; // the encapsulated X representation
00101 };
00102 
00103 class wxColourDatabase : public wxList { // colour database representation
00104 public:
00105     wxColourDatabase(void);
00106     ~wxColourDatabase(void);
00107 
00108     wxColour *FindColour(const char *colour);
00109     char *FindName(wxColour* colour);
00110 };
00111 
00112 #endif // Colour_h