1 /* 2 Defines the internal data structures for the X-windows 3 implementation of the graphics functionality in PETSc. 4 */ 5 6 #ifndef _XIMPL_H 7 #define _XIMPL_H 8 #include <petsc/private/drawimpl.h> 9 10 #include <X11/Xlib.h> 11 #include <X11/Xutil.h> 12 13 typedef unsigned long PetscDrawXiPixVal; 14 15 typedef struct { 16 GC set; 17 PetscDrawXiPixVal cur_pix; 18 } PetscDrawXiGC; 19 20 typedef struct { 21 Font fnt; 22 int font_w, font_h; 23 int font_descent; 24 PetscDrawXiPixVal font_pix; 25 } PetscDrawXiFont; 26 27 typedef struct { 28 Display *disp; /* Display */ 29 int screen; /* Screen of display */ 30 Visual *vis; /* Graphics visual */ 31 int depth; /* Depth of visual */ 32 PetscDrawXiGC gc; /* Graphics context */ 33 PetscDrawXiFont *font; /* Current font */ 34 Window win; /* Window */ 35 Drawable drw; /* Pixmap */ 36 Colormap cmap; /* Colormap */ 37 int cmapsize; /* Number of allocated colors */ 38 PetscDrawXiPixVal foreground; /* Foreground pixel */ 39 PetscDrawXiPixVal background; /* Background pixel */ 40 PetscDrawXiPixVal cmapping[PETSC_DRAW_MAXCOLOR]; /* Map color -> pixel value */ 41 unsigned char cpalette[PETSC_DRAW_MAXCOLOR][3]; /* Map color -> RGB value*/ 42 int x, y, w, h; /* Location and size window */ 43 } PetscDraw_X; 44 45 #define PetscDrawXiDrawable(w) ((w)->drw ? (w)->drw : (w)->win) 46 47 static inline void PetscDrawXiSetPixVal(PetscDraw_X *W, PetscDrawXiPixVal pix) 48 { 49 if (W->gc.cur_pix != pix) { 50 XSetForeground(W->disp, W->gc.set, pix); 51 W->gc.cur_pix = pix; 52 } 53 } 54 55 #if defined(PETSC_USE_DEBUG) 56 #define PetscDrawXiValidColor(W, color) PetscCheck((color) >= 0 && (color) < PETSC_DRAW_MAXCOLOR, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Color value %" PetscInt_FMT " out of range [0..%d]", (PetscInt)(color), PETSC_DRAW_MAXCOLOR - 1) 57 #else 58 #define PetscDrawXiValidColor(W, color) \ 59 do { \ 60 } while (0) 61 #endif 62 63 #define PetscDrawXiSetColor(W, color) \ 64 do { \ 65 PetscDrawXiValidColor(W, color); \ 66 PetscDrawXiSetPixVal(W, (W)->cmapping[(color)]); \ 67 } while (0) 68 69 PETSC_INTERN PetscErrorCode PetscDrawXiInit(PetscDraw_X *, const char[]); 70 PETSC_INTERN PetscErrorCode PetscDrawXiClose(PetscDraw_X *); 71 PETSC_INTERN PetscErrorCode PetscDrawXiFontFixed(PetscDraw_X *, int, int, PetscDrawXiFont **); 72 PETSC_INTERN PetscErrorCode PetscDrawXiColormap(PetscDraw_X *); 73 PETSC_INTERN PetscErrorCode PetscDrawXiQuickWindow(PetscDraw_X *, char *, int, int, int, int); 74 PETSC_INTERN PetscErrorCode PetscDrawXiQuickWindowFromWindow(PetscDraw_X *, Window); 75 PETSC_INTERN PetscErrorCode PetscDrawXiQuickPixmap(PetscDraw_X *); 76 PETSC_INTERN PetscErrorCode PetscDrawXiResizeWindow(PetscDraw_X *, int, int); 77 PETSC_INTERN PetscErrorCode PetscDrawXiGetGeometry(PetscDraw_X *, int *, int *, int *, int *); 78 79 #endif 80