1 /*
2 Defines the internal data structures for the X-windows
3 implementation of the graphics functionality in PETSc.
4 */
5
6 #pragma once
7 #include <petsc/private/drawimpl.h>
8
9 #include <X11/Xlib.h>
10 #include <X11/Xutil.h>
11
12 typedef unsigned long PetscDrawXiPixVal;
13
14 typedef struct {
15 GC set;
16 PetscDrawXiPixVal cur_pix;
17 } PetscDrawXiGC;
18
19 typedef struct {
20 Font fnt;
21 int font_w, font_h;
22 int font_descent;
23 PetscDrawXiPixVal font_pix;
24 } PetscDrawXiFont;
25
26 typedef struct {
27 Display *disp; /* Display */
28 int screen; /* Screen of display */
29 Visual *vis; /* Graphics visual */
30 int depth; /* Depth of visual */
31 PetscDrawXiGC gc; /* Graphics context */
32 PetscDrawXiFont *font; /* Current font */
33 Window win; /* Window */
34 Drawable drw; /* Pixmap */
35 Colormap cmap; /* Colormap */
36 int cmapsize; /* Number of allocated colors */
37 PetscDrawXiPixVal foreground; /* Foreground pixel */
38 PetscDrawXiPixVal background; /* Background pixel */
39 PetscDrawXiPixVal cmapping[PETSC_DRAW_MAXCOLOR]; /* Map color -> pixel value */
40 unsigned char cpalette[PETSC_DRAW_MAXCOLOR][3]; /* Map color -> RGB value*/
41 int x, y, w, h; /* Location and size window */
42 } PetscDraw_X;
43
44 #define PetscDrawXiDrawable(w) ((w)->drw ? (w)->drw : (w)->win)
45
PetscDrawXiSetPixVal(PetscDraw_X * W,PetscDrawXiPixVal pix)46 static inline void PetscDrawXiSetPixVal(PetscDraw_X *W, PetscDrawXiPixVal pix)
47 {
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 %d out of range [0..%d]", 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