1 /* 2 Defines the internal data structures for the X-windows 3 implementation of the graphics functionality in PETSc. 4 */ 5 6 #if !defined(_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 if (W->gc.cur_pix != pix) { 49 XSetForeground(W->disp, W->gc.set, pix); 50 W->gc.cur_pix = pix; 51 } 52 } 53 54 #if defined(PETSC_USE_DEBUG) 55 #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) 56 #else 57 #define PetscDrawXiValidColor(W, color) \ 58 do { \ 59 } while (0) 60 #endif 61 62 #define PetscDrawXiSetColor(W, color) \ 63 do { \ 64 PetscDrawXiValidColor(W, color); \ 65 PetscDrawXiSetPixVal(W, (W)->cmapping[(color)]); \ 66 } while (0) 67 68 PETSC_INTERN PetscErrorCode PetscDrawXiInit(PetscDraw_X *, const char[]); 69 PETSC_INTERN PetscErrorCode PetscDrawXiClose(PetscDraw_X *); 70 PETSC_INTERN PetscErrorCode PetscDrawXiFontFixed(PetscDraw_X *, int, int, PetscDrawXiFont **); 71 PETSC_INTERN PetscErrorCode PetscDrawXiColormap(PetscDraw_X *); 72 PETSC_INTERN PetscErrorCode PetscDrawXiQuickWindow(PetscDraw_X *, char *, int, int, int, int); 73 PETSC_INTERN PetscErrorCode PetscDrawXiQuickWindowFromWindow(PetscDraw_X *, Window); 74 PETSC_INTERN PetscErrorCode PetscDrawXiQuickPixmap(PetscDraw_X *); 75 PETSC_INTERN PetscErrorCode PetscDrawXiResizeWindow(PetscDraw_X *, int, int); 76 PETSC_INTERN PetscErrorCode PetscDrawXiGetGeometry(PetscDraw_X *, int *, int *, int *, int *); 77 78 #endif 79