// Quick and Dirty X graphics for math applications. // Copyright (C) 1996 Eleftherios Gkioulekas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #ifndef __defined_qx #define __defined_qx // Streams #include #include #include // Xlib #include #include #include #include #include #include // Dealing with colors XColor QxColor(double r,double g,double b); int QxColorRed(XColor col); int QxColorGreen(XColor col); int QxColorBlue(XColor col); void QxError(char *error); // Colormap generators XColor *QxMakeGreyscaleColormap(int N,double cor); XColor *QxMakeRainbowColormap(int N,double cor); // Dealing with coordinate systems class QxCoords { public: int ox,oy; // Where is the center in pixel coordinates double scale; // How many pixels is one unit of length? double x(int ix) { return (double(ix)-ox)/scale; } double y(int iy) { return (double(iy)-oy)/scale; } int x(double dx) { return ox+int(scale*dx); } int y(double dy) { return oy+int(scale*dy); } }; // Some class declarations for stuff to follow class QxServer; class QxImageWindow; // Class definitions class QxServer { protected: Display *display; // The X Display structure GC gc; // The default graphics context int screen; // The screen Visual *visual; // The visual Window rtwin; // Handle to the root window int rtwidth,rtheight; // Size of the root window Colormap cmap; // The default colormap int Ncols; // How many colors is this application requesting? long unsigned int *pixels; // Pixelvalues we got XColor *cols; // Current colors stuck in those pixel-values public: QxServer(); virtual ~QxServer(); // Color management routines bool ColorRequest(int N); int SuckAllColors(void); QxServer *SetColor(int pxl,XColor col); QxServer *SetColor(int start,XColor *col,int n); QxServer *SetColor(XColor *col,int n); QxServer *FlushColors(void); }; class QxImageWindow: public QxServer { private: int SzX,SzY; // The size of the window char *name; // The name of the window Window win; // The window XImage *Im; // An XImage that corresponds to the window char *ImD; // The image data themselves public: QxImageWindow(int width,int height,char *n); ~QxImageWindow(); // Accessors int GetSzX(void) const { return SzX; } int GetSzY(void) const { return SzY; } // Main methods QxImageWindow *SetPixel(int x, int y, int color); QxImageWindow *SetPixel(QxCoords c,double dx,double dy,int color); QxImageWindow *DrawLine(int x0,int y0,int x1,int y1,int color); QxImageWindow *DrawLine (QxCoords c,double dx0,double dy0,double dx1,double dy1,int color); QxImageWindow *FillWindow(int color); QxImageWindow *FlushWindow(void); QxImageWindow *FlushPartOfWindow(int ux,int uy,int lx,int ly); QxImageWindow *WaitMouseClick(void); // Useful stuff QxImageWindow *WritePPM(ostream &output); QxImageWindow *WritePPM(char *filename); QxImageWindow *PutDataOnWindow(double **data,double min,double max); QxImageWindow *PutDataOnWindow(int i,int j,double data,double min,double max); QxImageWindow *PutDataOnWindow (int i,int j,double data,double min,double max,int b); QxImageWindow *PutDataOnWindow(double **data,int ratio,double min,double max); }; #endif