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