xref: /petsc/src/sys/classes/draw/impls/x/ximpl.h (revision 5fd668637986a8d8518383a9159eebc368e1d5b4)
1 
2 /*
3       Defines the internal data structures for the X-windows
4    implementation of the graphics functionality in PETSc.
5 */
6 
7 #include <petsc-private/drawimpl.h>
8 
9 #if !defined(_XIMPL_H)
10 #define _XIMPL_H
11 
12 #include <sys/types.h>
13 #include <X11/Xlib.h>
14 #include <X11/Xutil.h>
15 
16 typedef unsigned long PetscDrawXiPixVal;
17 
18 typedef struct {
19   GC                set;
20   PetscDrawXiPixVal cur_pix;
21 } PetscDrawXiGC;
22 
23 typedef struct {
24   Font              fnt;
25   int               font_w,font_h;
26   int               font_descent;
27   PetscDrawXiPixVal font_pix;
28 } PetscDrawXiFont;
29 
30 typedef struct {
31   Display           *disp;
32   int               screen;
33   Window            win;
34   Visual            *vis;            /* Graphics visual */
35   PetscDrawXiGC     gc;
36   PetscDrawXiFont   *font;
37   int               depth;           /* Depth of visual */
38   int               numcolors,      /* Number of available colors */
39                     maxcolors;       /* Current number in use */
40   Colormap          cmap;
41   PetscDrawXiPixVal foreground,background;
42   PetscDrawXiPixVal cmapping[256];
43   int               x,y,w,h;      /* Size and location of window */
44   Drawable          drw;
45 } PetscDraw_X;
46 
47 #define PetscDrawXiDrawable(w) ((w)->drw ? (w)->drw : (w)->win)
48 
49 #define PetscDrawXiSetColor(Win,icolor)\
50   { if (icolor >= 256 || icolor < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Color value out of range");\
51     if ((Win)->gc.cur_pix != (Win)->cmapping[icolor]) {                  \
52       XSetForeground((Win)->disp,(Win)->gc.set,(Win)->cmapping[icolor]); \
53       (Win)->gc.cur_pix   = (Win)->cmapping[icolor];\
54   }}
55 
56 #define PetscDrawXiSetPixVal(Win,pix)\
57   { if ((PetscDrawXiPixVal) (Win)->gc.cur_pix != pix) { \
58       XSetForeground((Win)->disp,(Win)->gc.set,pix);    \
59       (Win)->gc.cur_pix   = pix;\
60   }}
61 
62 #endif
63