32671396ac548bc61ca6690255fea66cfcaa0c68
[ctsim.git] / include / sgp.h
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: sgp.h,v 1.7 2000/05/24 22:48:17 kevin Exp $
6 **  $Log: sgp.h,v $
7 **  Revision 1.7  2000/05/24 22:48:17  kevin
8 **  First functional version of SDF library for X-window
9 **
10 **  Revision 1.6  2000/05/11 14:07:00  kevin
11 **  Added support for Windows NT
12 **
13 **  Revision 1.5  2000/05/07 12:46:19  kevin
14 **  made c++ compatible
15 **
16 **  Revision 1.4  2000/04/30 19:17:35  kevin
17 **  Set up include files for conditional INTERACTIVE_GRAPHICS
18 **
19 **  Revision 1.3  2000/04/28 18:35:21  kevin
20 **  removed unused files
21 **
22 **  Revision 1.2  2000/04/28 14:14:16  kevin
23 **  *** empty log message ***
24 **
25 **
26 **  This program is free software; you can redistribute it and/or modify
27 **  it under the terms of the GNU General Public License (version 2) as
28 **  published by the Free Software Foundation.
29 **
30 **  This program is distributed in the hope that it will be useful,
31 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
32 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 **  GNU General Public License for more details.
34 **
35 **  You should have received a copy of the GNU General Public License
36 **  along with this program; if not, write to the Free Software
37 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38 ******************************************************************************/
39
40 /*----------------------------------------------------------------------*/
41 /*                 Standard Graphics Package Header File                */
42 /*----------------------------------------------------------------------*/
43
44 #ifndef __H_SGP
45 #define __H_SGP
46
47 #include "kstddef.h"
48 #include "kmath.h"
49
50 #if HAVE_CONFIG_H
51 #include "config.h"
52 #endif
53
54 #if HAVE_G2_H
55 #include "g2.h"
56 #include "g2_X11.h"
57 #endif
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif /* __cplusplus */
62
63
64 /* device names */
65
66 #define CRTDEV  1
67 #define PRTDEV  2
68 #define MEMDEV  4
69 #define FILEDEV 8
70
71 /* linestyles */
72
73 #define LS_NOLINE 0
74 #define LS_SOLID  0xffff
75 #define LS_DASH1  0xff00
76 #define LS_DASH2  0xf0f0
77 #define LS_DASH3  0xcccc
78 #define LS_DASH4  0xff3e
79 #define LS_DOTTED 0xaaaa
80
81 #define MAXDASH    4
82 #define MAXCOLOR   63
83
84 /* data structures */
85
86 struct sgp_window_st {
87     int pw_xsize;         /* Physical Window size */
88    int pw_ysize;
89    char title[256];
90    int g2_id;
91     double xw_min;    /* Window extents */
92     double yw_min;
93     double xw_max;
94     double yw_max;
95     double xv_min;    /* Viewport extents */
96     double yv_min;
97     double xv_max;
98     double yv_max;
99     double view[4];   /* Viewport array for clip_rect() */
100     double curx;      /* Current stylus position in world coords */
101     double cury;
102     int recalc_mc_to_ndc;
103     int recalc_ndc_to_mc;
104     GRFMTX_2D wc_to_ndc_x;     /* World coord to NDC matrix */
105     GRFMTX_2D mc_to_ndc_x;     /* Master to NDC */
106     GRFMTX_2D ndc_to_mc_x;     /* NDC to Master */
107     GRFMTX_2D ctm_2_x;         /* Current transfromation matrix */
108
109     int phys_curx;
110     int phys_cury;
111 };
112
113 typedef struct sgp_window_st SGP_WINDOW;
114 typedef struct sgp_window_st *SGP_ID;
115
116 struct device_st {
117         int open;                       /* TRUE if device is open for output */
118         int xsize, ysize;               /* Size of device in pixels */
119         int xmin, ymin;                 /* smallest coordinates */
120         int xmax, ymax;                 /* Maximum coordinates */
121         int colormax;                   /* Maximum color number of device */
122         int style;                      /* Current linestyle of device */
123         int width;                      /* Current width of device */
124         int color;                      /* Current color of device */
125         int icurx, icury;               /* Current position */
126         int icwidth, icheight;          /* Size of characters in pixels */
127         int cfore, cback;               /* Character foregnd & backgnd colors */
128         float asp;                      /* Aspect ratio.  Multipy x coord */
129         int (*dotfunc)(int x1, int y1, int color);              /* Dot function for device */
130         int (*linefunc)(int x1, int y1, int x2, int y2, int color);             /* Line function for device */
131         unsigned int nbytes;            /* Size of buffer in bytes */
132         char *buf;                      /* Pointer to buffer */
133         unsigned int bufseg, bufoff;    /* Buffer memory location */
134         int mode;                       /* Device mode */
135 };
136
137 struct charsp_st {
138         float width, height;            /* size of characters in NDC */
139         float textangle;                /* text angle in radians */
140         float charupangle;              /* character up angle */
141         int font;                       /* font for characters */
142         int updir, textdir;             /* text direct & character orientation */
143         int fore, back;                 /* foreground & background color */
144                                         /* if back = -1, then transparent back */
145 };
146
147 struct state_st {
148         int foregnd, backgnd;           /* current foregound & background colors */
149         int linestyle;                  /* current 16 bit linestyle */
150         int linewidth;                  /* current width of line (in pixels) */
151         int marktype;                   /* current marker type */
152         int markcolor;                  /* current marker color */
153         float xndc, yndc;               /* current position in NDC */
154 };
155
156 typedef struct device_st DEVICE;
157 typedef struct charsp_st CHARSPEC;
158 typedef struct state_st GRFSTATE;
159
160 struct point    {double x, y, z;};
161
162
163 /* Constants */
164
165 /* Flagcodes for motion directions */
166 #define XPLUS   001     /* right */
167 #define XMINUS  002     /* left */
168 #define YPLUS   004     /* up */
169 #define YMINUS  010     /* down */
170
171 /* Codes for marker symbols */
172 #define POINT    0      /* small dot */
173 #define SQUARE   1      /* empty square */
174 #define FSQUARE  2      /* filled square */
175 #define DIAMOND  3      /* empty diamond */
176 #define FDIAMOND 4      /* filled diamond */
177 #define CROSS    5      /* cross */
178 #define XCROSS   6      /* x */
179 #define CERCLE   7      /* open circle */
180 #define FCERCLE  8      /* filled circle */
181 #define BSQUARE  9      /* big open square */
182 #define BDIAMOND 10     /* big open diamond */
183
184 #define NMARKERS 11     /* Number of available symbol types */
185
186 /*-------------------------------------------------------------------------*/
187
188 #define PSET   0                /* codes for raster merging */
189 #define PRESET 1
190 #define OR     2
191 #define AND    3
192 #define XOR    4
193
194 /*-------------------------------------------------------------------------*/
195
196 /* circle.c */
197 void sgp2_draw_circle(const double r);
198 void sgp2_draw_arc(double start, double stop, const double r);
199
200 /* ctm.c */
201 void ctm_xlat_pre_2(double x, double y);
202 void ctm_xlat_post_2(double x, double y);
203 void ctm_scale_pre_2(double sx, double sy);
204 void ctm_scale_post_2(double sx, double sy);
205 void ctm_rotate_pre_2(double theta);
206 void ctm_rotate_post_2(double theta);
207 void ctm_shear_pre_2(double shrx, double shry);
208 void ctm_shear_post_2(double shrx, double shry);
209 void xlat_gmtx_2(GRFMTX_2D m, double x, double y);
210 void scale_gmtx_2(GRFMTX_2D m, double sx, double sy);
211 void shear_gmtx_2(GRFMTX_2D m, double shrx, double shry);
212 void rotate_gmtx_2(GRFMTX_2D m, double theta);
213 void ident_gmtx_2(GRFMTX_2D m);
214 void mult_gmtx_2(GRFMTX_2D a, GRFMTX_2D b, GRFMTX_2D c);
215 void invert_gmtx_2(GRFMTX_2D a, GRFMTX_2D b);
216 double determ_gmtx_2(GRFMTX_2D a);
217
218 /* drawbox.c */
219 void sgp2_draw_rect (double xmin, double ymin, double xmax, double ymax);
220
221 /* sgp.c */
222 SGP_ID sgp2_init (int xsize, int ysize, const char *title);
223 void sgp2_close (SGP_ID gid);
224 void sgp2_set_active_win (SGP_ID);
225 SGP_ID sgp2_get_active_win (void);
226 void sgp2_clear (void);
227 void sgp2_window(double xmin, double ymin, double xmax, double ymax);
228 void sgp2_viewport(double xmin, double ymin, double xmax, double ymax);
229 void sgp2_frame_vpt(void);
230 void calc_wc_to_ndc(void);
231 void calc_ndc_to_mc(void);
232 void wc_to_ndc(double xw, double yw, double *xn, double *yn);
233 void ndc_to_wc(double xn, double yn, double *xw, double *yw);
234 void sgp2_color(int icol);
235 void sgp2_line_style(int style);
236 void sgp2_line_abs(double x, double y);
237 void sgp2_move_abs(double x, double y);
238 void sgp2_line_rel(double x, double y);
239 void sgp2_move_rel(double x, double y);
240 void sgp2_draw_text(char *message);
241 void sgp2_polyline_abs(double x[], double y[], int n);
242 void sgp2_mark_abs(double x, double y);
243 void sgp2_mark_rel(double x, double y);
244 void sgp2_point_abs(double x, double y);
245 void sgp2_point_rel(double x, double y);
246 void charsize(double wid, double height);
247 void textangle(double angle);
248 void ctm_clr_2(void);
249 void ctm_get_2(GRFMTX_2D m);
250 void ctm_set_2(GRFMTX_2D m);
251 void ctm_pre_mult_2(GRFMTX_2D m);
252 void ctm_post_mult_2(GRFMTX_2D m);
253
254 /* sgpdrive.c */
255 int _sgp2_init_dev(SGP_ID gid);
256 int initdevice(int dev, int mode, int xsize, int ysize);
257 int opendevice(int dev);
258 void closedevice(int dev);
259 void termdevice(int dev);
260 void _sgp2_stylus(SGP_ID gid, double x, double y, int beam);
261 void pntndc (SGP_ID gid, double x, double y);
262 void markndc (SGP_ID gid, double x, double y);
263 GRFSTATE *inqstate(void);
264 void gp_set_aspect(int dev, double asp);
265 void setlinestyle(int style);
266 void setlinewidth(int wid);
267 DEVICE *inqdev(int dev);
268 void _sgp2_set_text(SGP_ID gid, double width, double height, double textangle, int font);
269 void settextclr(int fore, int back);
270 void setcolor(int fore);
271 void setbackg(int back);
272 int initmarker(int marker, int color);
273 int settextdir(int direction);
274 void _sgp2_dev_text(SGP_ID gid, char *message);
275 void termgrf2(void);
276 void flushdevice(int dev);
277
278 /* sgptext.c */
279 void wrtsymbol(int sym, int x, int y, DEVICE *dev);
280 void wrtchar(int ch, int x, int y, CHARSPEC *cspec, DEVICE *dev);
281 void wrttext(char txtstr[], int x, int y, CHARSPEC *cspec, DEVICE *dev);
282 void crtcolor(int mode, int *f, int *b);
283
284 #ifdef __cplusplus
285 }
286 #endif /* __cplusplus */
287
288
289 #endif