xref: /petsc/src/sys/classes/draw/impls/x/ximpl.h (revision e0877f539457ad1ce8178bc0750eac5ffa490a67)
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 PetscDrawXiSetPixVal(W,pix) do {         \
48     if ((W)->gc.cur_pix != (pix)) {              \
49       XSetForeground((W)->disp,(W)->gc.set,pix); \
50       (W)->gc.cur_pix = pix;                     \
51     }} while (0)
52 
53 #define PetscDrawXiSetColor(W,color) do {         \
54     if ((color) >= 256 || (color) < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Color value %D out of range [0..255]",(PetscInt)(color)); \
55     PetscDrawXiSetPixVal(W,(W)->cmapping[color]); \
56     } while (0)
57 
58 #endif
59