1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 
7 /*
8     This file contains a basic X11 data structure that may be used within
9     other structures for basic graphics operations.
10  */
11 
12 #if !defined(_BASEX11)
13 #define _BASEX11
14 
15 /* AIX assumes that sys/types is included before Xutil is (when it defines
16    function prototypes) */
17 #include <sys/types.h>
18 #include <X11/Xlib.h>
19 #include <X11/Xutil.h>
20 
21 typedef unsigned long PixVal;
22 
23 /* Our rule on GC is that the current pixel value is remembered so that
24    we don't contsantly call a routine to change it when it is already the
25    value that we want. */
26 typedef struct {
27     GC       set;
28     PixVal   cur_pix;
29     } GCCache;
30 
31 /*
32    Many routines need the display, window, and a GC;
33    occasionally, routines need the visual and the colormap (particularly
34    those doing scientific imaging).  For scaling information, the
35    region of the window is also needed (note that many XBWindow
36    structures can use the same Window)
37  */
38 typedef struct {
39     Display  *disp;
40     int      screen;
41     Window   win;
42     GCCache  gc;
43     Visual   *vis;            /* Graphics visual */
44     int      depth;           /* Depth of visual */
45     int      numcolors,       /* Number of available colors */
46              maxcolors;       /* Current number in use */
47     Colormap cmap;
48     PixVal   foreground, background;
49     PixVal   cmapping[256];
50     int      x, y, w, h;      /* Size and location of window */
51     /* The following permit double buffering; by making this part of the
52        XBWindow structure, everyone can utilize double buffering without
53        any special arrangements.  If buf is not null, all routines draw
54        to it instead, and XBFlush does a copyarea. NOT YET IMPLEMENTED */
55     Drawable drw;
56     } XBWindow;
57 
58 /* This definition picks the drawable to use for an X operation.  This
59    should be used for all drawing routines (note that some routines need
60    a Window, not just a drawable). */
61 #define XBDrawable(w) ((w)->drw ? (w)->drw : (w)->win)
62 
63 /* There are a number of properties that we'd like to have on hand about
64    a font; in particular, a bound on the size of a character */
65 typedef struct {
66     Font     fnt;
67     int      font_w, font_h;
68     int      font_descent;
69     PixVal   font_pix;
70     } XBFont;
71 
72 /* This is a user-defined coordinates region */
73 typedef struct {
74     double  xmin,xmax,ymin,ymax,zmin,zmax ;
75     } XBAppRegion;
76 
77 typedef struct {
78     int      x, y, xh, yh, w, h;
79     } XBRegion;
80 
81 /* This is the "decoration" structure.  This could later involve
82    patterns to be used outside the frame, as well as a "background"
83    (interior) decoration */
84 typedef struct {
85     XBRegion Box;
86     int      width, HasColor, is_in;
87     PixVal   Hi, Lo;
88     } XBDecoration;
89 
90 #define XBSetPixVal( xbwin, pixval ) \
91 if (xbwin->gc.cur_pix != pixval) { \
92     XSetForeground( xbwin->disp, xbwin->gc.set, pixval ); \
93     xbwin->gc.cur_pix   = pixval;\
94     }
95 
96 /* Error returns */
97 #define ERR_CAN_NOT_OPEN_DISPLAY 0x10001
98 #define ERR_NO_DISPLAY           0x10002
99 #define ERR_CAN_NOT_OPEN_WINDOW  0x10003
100 #define ERR_ILLEGAL_SIZE         0x10004
101 
102 /* Routines */
103 
104 extern PixVal    XBGetColor (XBWindow *, char *, int);
105 
106 /* xwmap */
107 extern int XB_wait_map ( XBWindow *,
108 			       void (*)( XBWindow *, int, int, int, int ) );
109 extern void XBSync ( XBWindow * );
110 
111 /* xinit */
112 extern XBWindow *XBWinCreate (void);
113 extern void      XBWinDestroy (XBWindow *);
114 extern int XBOpenDisplay ( XBWindow *, char * );
115 extern int XBSetVisual   ( XBWindow *, int, Colormap, int );
116 extern int XBSetGC       ( XBWindow *, PixVal );
117 extern int XBOpenWindow  ( XBWindow * );
118 extern int XBDisplayWindow ( XBWindow *, char *, int, int, int, int, PixVal );
119 extern void XBGetArgs    ( int *, char **, int, int *, int *, int *, int * );
120 extern void XBGetArgsDisplay ( int *, char **, int, int, char * );
121 extern int XBiQuickWindow ( XBWindow *, char *, char *,
122 				      int, int, int, int, int );
123 extern int XBQuickWindow (XBWindow *, char *, char *,
124 				    int,int,int,int);
125 extern int XBQuickWindowFromWindow ( XBWindow *, char *, Window );
126 extern void XBFlush      ( XBWindow * );
127 extern void XBSetWindowLabel ( XBWindow *, char * );
128 extern void XBCaptureWindowToFile ( XBWindow *, char * );
129 
130 /* xframe */
131 extern int XBFrameColors ( XBWindow *, XBDecoration *, char *, char * );
132 extern int XBDrawFrame ( XBWindow *, XBDecoration * );
133 extern void XBClearWindow ( XBWindow *, int, int, int, int );
134 extern void XBFrameColorsByName ( XBWindow *, char *, char * );
135 
136 /* xcolor */
137 extern void XBInitColors ( XBWindow *, Colormap, int );
138 extern int XBInitCmap    ( XBWindow * );
139 extern int XBCmap        ( unsigned char [], unsigned char [],
140 				     unsigned char [], int, XBWindow * );
141 extern int XBSetVisualClass ( XBWindow * );
142 extern int XBGetVisualClass ( XBWindow * );
143 extern Colormap XBCreateColormap ( Display *, int, Visual * );
144 extern int XBSetColormap ( XBWindow * );
145 extern int XBAllocBW     ( XBWindow *, PixVal *, PixVal * );
146 extern int XBGetBaseColor ( XBWindow *, PixVal *, PixVal * );
147 extern int XBSetGamma     ( double );
148 extern int XBSetCmapHue   ( unsigned char *, unsigned char *,
149 				      unsigned char *, int );
150 extern int XBFindColor    ( XBWindow *, char *, PixVal * );
151 extern int XBAddCmap      ( unsigned char [], unsigned char [],
152 				      unsigned char [], int, XBWindow * );
153 extern PixVal XBGetColor  ( XBWindow *, char *, int );
154 extern PixVal XBSimColor  ( XBWindow *, PixVal, int, int );
155 extern void XBUniformHues ( XBWindow *, int );
156 extern void XBSetCmapLight ( unsigned char *, unsigned char *,
157 				       unsigned char *, int );
158 #endif
159